0% found this document useful (0 votes)
240 views

Embedded Programming: Freertos

FreeRTOS is a real-time operating system designed for microcontrollers and other small devices. It uses preemptive or cooperative scheduling to run tasks with defined time constraints. Tasks can be created and assigned priorities. FreeRTOS includes APIs for tasks, semaphores, mutexes, and message queues to synchronize tasks and share data between tasks and interrupts.

Uploaded by

Cristian Ceruţa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
240 views

Embedded Programming: Freertos

FreeRTOS is a real-time operating system designed for microcontrollers and other small devices. It uses preemptive or cooperative scheduling to run tasks with defined time constraints. Tasks can be created and assigned priorities. FreeRTOS includes APIs for tasks, semaphores, mutexes, and message queues to synchronize tasks and share data between tasks and interrupts.

Uploaded by

Cristian Ceruţa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Embedded Programming

FreeRTOS

Student: Cristian Ceruta (crcer18)


Definition:
 RTOS: an operating system designed to provide task
executions with a strictly defined time using a
scheduler.
 FreeRTOS is a class of RTOS that is designed to be
small enough to run on a microcontroller.
 Its use is not limited to microcontroller applications
only.
Principle of work:
Tasks
Defining a function that would be assigned to a task:
 void vATaskFunction( void *pvParameters );
 portTASK_FUNCTION_PROTO( vATaskFunction, pvParameters );
 portTASK_FUNCTION( VATaskFunction, pvParameters );

Function structure:
 portTASK_FUNCTION( vATaskFunction, pvParameters )
{
While(1) //”for( ;; )” is an alternative for the super loop
{
x
}
}
Task States

 Running
 Ready
 Blocked
 Suspended
Task Scheduling
 Pre-emptive Scheduling

 Cooperative Scheduling
Task Scheduling
 Pre-emptive Scheduling
◦ Runs task with highest priority
Task Scheduling
 Cooperative Scheduling
◦ Task runs until it gives up its CPU time
◦ The task can not be pre-empted by another task
Task Priority
 Each task is assigned a priority from 0 to
( configMAX_PRIORITIES - 1 ):
◦ configMAX_PRIORITIES is defined within FreeRTOSConfig.h.
Low priority numbers denote low priority tasks

 For RAM efficiency, the number of priorities should be


kept to the minimum necessary value.
FreeRTOS API: Tasks
Can be created by calling:
 xTaskCreate() – create the task, storing the
handle

Can be deleted by calling:


 vTaskDelete() – use the handle to delete the task
FreeRTOS API: Tasks
FreeRTOS API: Semaphores
 Used for signaling/synchronization between tasks and
interrupt services routines

Semaphores can be:


 Binary – don’t include priority inheritance mechanism, good for
implementing synchronization
 Mutex – include priority inheritance mechanism, good for implementing
simple mutual exclusion
 Counting – used for counting events
FreeRTOS API: Mutexes
 Act like a token that is used to guard a resource

 A task first asks for token, when it finishes with


resources it gives the token back.

 Uses priority inheritance mechanism


FreeRTOS API: Mutexes
FreeRTOS API: Mutexes

Mutex API:
 xSemaphoreCreateMutex()
 xSemaphoreTake()
 xSemaphoreGive()
FreeRTOS API: MessageQueues
 Used to send messages between tasks/ between
interrupts and tasks

 Uses FIFO (Firs in First out) principle

 Data is copied into the queue rather than the queue


always storing just a reference to the data.
FreeRTOS API: MessageQueues
FreeRTOS API: MessageQueues

 xQueueCreate(): Creates a queue

 xQueueCreate( uxQueueLength, uxItemSize );

 /* Create a queue capable of containing 10 unsigned long values. */


xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );

You might also like