FreeRTOS Quick Reference Guide

Article by:
Date Published:
Last Modified:

FreeRTOS Quick Reference Guide

This contains examples of the most common functions, designed to jog your memory when writing FreeRTOS code.

vTaskDelay(200/portTICK_RATE_MS);Will block current task for 200ms.
vTaskSuspendAll();Stops scheduler, but not interrupts. Do not call non-interrupt FreeRTOS API from within a suspend section.
xTimerCreate();Used to create a software timer, based of the system ticks. #configUSE_TIMERS has to be set to 1 and #configTIMER_TASK_PRIORITY set before this function is available (in FreeRTOSConfig.h).
vTaskList(debugBuff);Writes a task list to a debug buffer. Recommended to have about 40 bytes of space in the buffer per task.
uxTaskGetSystemState(taskStatusArray, 5, &totalRunTime);Returns system debug information for 5 tasks (function added in v7.5.0). Stores total run time into 3rd argument.
xQueueHandle myQueue = xQueueCreate(50, 2);Creates a queue of length 50 (elements) and width 2 (bytes).
portBASE_TYPE xQueueReceive(xQueueHandle xQueue, void* pvBuffer, portTickType, xTicksToWait);
xQueueSendToBack(xQueueHandle xQueue, const void* pvItemToQueue, portTickType xTicksToWait);Puts item onto the end of the queue. Standard way of putting data onto queue.
xSemaphoreHandle xSemaphoreCreateMutex(void);Use for mutual exclusion (to prevent contention problems).
xSemaphoreHandle mySemaphore = xSemaphoreCreateRecursiveMutex();Creates a mutex.
SemaphoreCreateBinary(mySemaphoreHandle);Creates a binary semaphore. Use for interrupt-to-task synchronisation
xSemaphoreHandle mySem = xSemaphoreCreateCounting(10, 0);Creates a counting semaphore which counts to 10, and starts counting from 0 (so 10 free at creation).
xSemaphoreGive(mySem);Gives a semaphore.
xSemaphoreGiveFromISR(mySem, NULL);Interrupt safe version of xSemaphoreGive().

tskIDLE_PRIORITY - Priority of the idle task. Usually used as a way of setting the priority of other tasks relative to the idle task (e.g. tskIDLE_PRIORITY + 1).

portTICK_RATE_MS - Period of the ticks (in milli-seconds). Used when calling timing/delay functions so that you can specify a delay in ms rather than ticks


Geoffrey Hunter

Dude making stuff.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License .

Related Content

No related content found.


    comments powered by Disqus