Industry Standard RTOS/FreeRTOS

According to the AspenCore EE|Times/embedded.com 2017 Embedded Markets Study, 22% of applications running on an operating system, RTOS, kernel, software executive, scheduler, or similar use Embedded Linux. Since the focus of this paper is 8-bit microcontrollers, Embedded Linux is somewhat out of the scope due to the lack of support for 8-bit microcontrollers, and also the hardware required to run Embedded Linux is not generally available in 8-bit microcontrollers.

In the same survey, 20% stated that they use FreeRTOS. FreeRTOS supports the 8-bit AVR® MCU and has done so for many years. FreeRTOS offers preemptive multitasking out of the box, together with many other features associated with RTOS functionality, e.g., semaphores, Mutexes, queues, software timers, etc. All of these features greatly simplify development of software components. The RTOS takes care of inter-task timing requirements, which means the tasks will be more or less independent of each other. This, in turn, implies that software built for one application can be, with little or no alteration, re-used in other applications.

Using FreeRTOS is as simple as adding the software library/source code to the project, as one would add any driver or middleware to any application. Once the required source files have been added to the project, tasks are created as separate never returning functions:
void my_task(void *pvParams)
{
    /* Task init code, if any, here */
    for ( ;; ) {
        /* Task application code here */
    }
}
The task is added to the scheduler task queue by:
xTaskCreate(my_task, "My Task", [stack size for task], NULL, [priority], NULL);
When all tasks are added to the queue the RTOS is started by calling:
vTaskStartScheduler();

The scheduler now takes care of all task priorities. Each task can be viewed as single executables.