FreeRTOS Overview
FreeRTOS Overview
1
FreeRTOS Overview
Features
● There is a choice of scheduling policy
– Pre-emptive: Always runs the highest priority
available task. Tasks of identical priority
share the CPU. (Fully pre-emptive with round
robin time slicing)
– Cooperative: Context switches only occur if a
task blocks, or explicitly calls taskYIELD()
● Message queue
● Semaphores
2
Tasks and Priorities
3
Tasks and Priorities
4
Implementing a task
5
TASKS
6
The idle task
7
Starting the kernel
8
FreeRTOS API
9
Configuration parameters
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configTICK_RATE_HZ 1000
#define configCPU_CLOCK_HZ 20000000
#define configMAX_PRIORITIES 4
#define configMINIMAL_STACK_SIZE ( 105 )
#define configTOTAL_HEAP_SIZE ( 1024 )
#define configMAX_TASK_NAME_LEN ( 4 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 1
The casts were omitted on some of the above to save space
10
Configuration parameters
11
Configuration parameters
12
Configuration parameters
13
Configuration parameters
14
Configuration parameters
● configUSE_16_BIT_TICKS: Time is
measured in 'ticks' - which is the number
of times the tick interrupt has executed
since the kernel was started. Defining it
as 1 causes portTickType to be defined
(typedef'ed) as an unsigned 16bit type.
Defining it as 0 causes portTickType to
be defined (typedef'ed) as an unsigned
32bit type.
17
Configuration parameters
18
Configuration parameters
● config_IDLE_SHOULD_YIELD: This
parameter controls the behaviour of tasks
at the idle priority. It only has an effect if
– The pre-emptive scheduler is being used.
– The users application creates tasks that run
at the idle priority.
If tasks share the same priority and none of
the tasks get pre-empted, it might be
assumed that each task at a given priority
will be allocated an equal amount of
processing time 19
Configuration parameters
and if the shared priority is above the idle
priority then this is indeed the case.
However with the idle priority, the idle
task runs before it yields thus using a part
of the time slice for the following task.
This can be avoided by
– Using an idle hook in place of separate
tasks at the idle priority.
– Creating all application tasks at a
priority greater than the idle priority.
– Setting the parameter to 0.
20
Configuration parameters
21
Configuration parameters
#define INCLUDE_vTaskPrioritySet 0
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 0
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
22
Memory management
23