Learning FreeRTOS

Chapter 2

August 05, 2024

This post contains personal learning notes regarding FreeRTOS and important contents extracted from the FreeRTOS Kernel Book .

Chapter 2

Ports

  • Each supported combination of compiler and processor is called a FreeRTOS port.
  • FreeRTOS is supplied as a set of C source files. Some source files are common to all ports, while others are specific to a port. Building the source files as part of your project makes the FreeRTOS API available to your application.

Data Types

TickType_t

  • FreeRTOS configures a periodic interrupt called the tick interrupt.
  • The number of tick interrupts that have occurred since the FreeRTOS application started is called the tick count. The tick count is used as a measure of time.
  • TickType_t is the data type used to hold the tick count value, and to specify times. Its type depends on configTICK_TYPE_WIDTH_IN_BITS in FreeRTOSConfig.h.

BaseType_t

  • BaseType_t is the data type used to define the most efficient data type for the architecture.
    • 64-bit type on a 64-bit architecture
    • 32-bit type on a 32-bit architecture
    • X-bit type on a X-bit architecture
  • Generally used for return types that take only a very limited range of values, and for pdTRUE / pdFALSE type Booleans.

Variable Names

  • Variables are prefixed with their type
    • a variable of type uint8_t will be prefixed with uc
    • a variable of type char* will be prefixed with pc
Prefix Meaning
c char
s int16_t
l int32_t
x BaseType_t / non-standard types
u unsigned
p pointer

Function Names

  • Functions are prefixed with both the type they return and the file they are defined within
    • vTaskPrioritySet() returns a void and is defined within tasks.c
    • xQueueReceive() returns a variable of type BaseType_t and is defined within queue.c
    • pvTimerGetTimerID() returns a void* and is defined within timers.c.
  • File scope (private) functions are prefixed with prv.

Marco Names

  • Most macros are written in upper case, and prefixed with lower case letters that indicate where the macro is defined
  • Semaphore API is written almost entirely as a set of macros, but follows the function naming convention, rather than the macro naming convention.
Macro prefixes
Prefix Example Location of marco definition
port portMAX_DELAY portable.h / portmarco.h
task taskENTER_CRITICAL() task.h
pd pdTrue projdefs.h
config configUSE_PREEMPTION FreeRTOSConfig.h
err errQUEUE_FULL projdefs.h
Common macro definitions
Marco Value
pdTRUE / pdPASS 1
pdFALSE / pdFAIL 0