FREERTOS

FreeRTOS Quick Reference Guide

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.

FunctionComments
**GENERAL TASK MANIPULATION** 
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").
**TASK MAINTENANCE/DEBUG** 
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 (fuction added in v7.5.0). Stores total run time into 3rd argument.
**QUEUES** 
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.
**SEMAPHORES** 
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


Tags:

    comments powered by Disqus