# Getting Started with Real-time Operating Systems Video link: https://atollic.wistia.com/medias/gwgee6ev93 ## RTOS Introduction microcontroller * before , 4~16K RAM, 8MHz CPU * now, 16~32K RAM we can build really cool stuff. ## Bare-metal scheduling technique ### Round-Robin Scheduling ```c= int main(void) { System_Init(); while (1) { Task1(); Task2(); Task3(); } return 1; } ``` * pros * easy to implement * cons * Adding new task will change the real-time attribute (need to tune again) * not the best for RTOS #### Round-Robin scheduling improvement With interrupts, we can change the current task. ### Cooperative Scheduling * Read system time * Run task1? yes: Task1, no: check next task * Run task2? yes: Task2, no: read system time * procs * only need to check all task end with the deadline * can have interrupt * can have hard real-time * cons * Can't preemptive ## Task Concurrency * Sequential Tasks * Task 1 * Task 2 * Task 3 * Task 1 * ... * Concurrent Tasks * Task 1 * Task 3 * Task 1 * Task 2 * Task 1 * ... ## RTOS Characteristics A **Real-Time Operating System (RTOS)** is an operating system designed to manage hardware resources of an embedded system with very precise timing and a high degree of reliability. * Example 6 characteristics * Reliability * Predictability * Performance * Compactness * Scalability * Multi-Tasking ## Bara-metal or RTOS * 7 Reason to choose an RTOS * Concurrency * Preemption * a task to be interrupt by higher priority to run on the CPU * In bare-metal, using preemption will make code too complex. * Available RAM * Available flash * Sync tools * 3rd party software * Ease of use ## FreeRTOS ![](https://i.imgur.com/0lOnUTI.png) ## Task Fundamentals ![](https://i.imgur.com/lRiWHju.png) ### Create Task ```c= xTaskCreate( Led_BlueBlink, /* Task Pointer */ (const char *const) "led_blue", /* Task Name */ configMINIMAL_STACK_SIZE, /* Stack Depth */ 0, /* Parameters to Pass to task */ 1, /* Task Priority */ 0 /* Pass handle to create task */ ); ``` ### Task States ![](https://i.imgur.com/cSnN1zr.png) ## FreeRTOS Resource ![](https://i.imgur.com/kqcVFLG.png)