Difference between revisions of "FreeRTOS"
From uGFX Wiki
(Created page with "The FreeRTOS port works out of the box without any modifications. Simply enable the port by setting <code>GFX_USE_OS_FREERTOS</code> to <code>TRUE</code> in your Configurati...") |
(→Initialization) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The FreeRTOS port works out of the box without any modifications. Simply enable the port by setting <code>GFX_USE_OS_FREERTOS</code> to <code>TRUE</code> in your [[Configuration|configuration file]]. | The FreeRTOS port works out of the box without any modifications. Simply enable the port by setting <code>GFX_USE_OS_FREERTOS</code> to <code>TRUE</code> in your [[Configuration|configuration file]]. | ||
+ | |||
+ | == Initialization == | ||
+ | As with all ports it's important that the underlying system is initialized prior to calling <code>gfxInit()</code>. In case of FreeRTOS this means that <code>vTaskStartScheduler()</code> needs to be executed prior to <code>gfxInit()</code>. However, due to the fact that <code>vTaskStartScheduler()</code> never returns the µGFX library can't be initialized inside the main thread. To illustrate the problem: | ||
+ | <source lang="c"> | ||
+ | // Initialize FreeRTOS. This function never returns. | ||
+ | vTaskStartScheduler(); | ||
+ | |||
+ | // Initialize uGFX. We never actually arrive here. | ||
+ | gfxInit(); | ||
+ | </source> | ||
+ | Swapping the order of the two function calls won't solve the problem either: | ||
+ | |||
+ | <source lang="c"> | ||
+ | // Initialize uGFX. This requires FreeRTOS to be initialized already. As that's not | ||
+ | // the case this function call will lead to a crash. | ||
+ | gfxInit(); | ||
+ | |||
+ | // Initialize FreeRTOS. This function never returns. | ||
+ | vTaskStartScheduler(); | ||
+ | </source> | ||
+ | |||
+ | The solution to this problem is creating a thread that initializes the entire system. It's a one-time task that doesn't contain a loop: | ||
+ | <source lang="c"> | ||
+ | |||
+ | static void taskInit(void* pvParameters) | ||
+ | { | ||
+ | (void)pvParameters; | ||
+ | |||
+ | gfxInit(); | ||
+ | } | ||
+ | |||
+ | void main(void) { | ||
+ | // Create the initialization task | ||
+ | xTaskCreate(taskInit, "Initialization", stackSize, 0, priority, 0); | ||
+ | |||
+ | // Initialize FreeRTOS. This will start the scheduler. | ||
+ | vTaskStartScheduler(); | ||
+ | } | ||
+ | </source> |
Latest revision as of 14:01, 22 March 2017
The FreeRTOS port works out of the box without any modifications. Simply enable the port by setting GFX_USE_OS_FREERTOS
to TRUE
in your configuration file.
Initialization
As with all ports it's important that the underlying system is initialized prior to calling gfxInit()
. In case of FreeRTOS this means that vTaskStartScheduler()
needs to be executed prior to gfxInit()
. However, due to the fact that vTaskStartScheduler()
never returns the µGFX library can't be initialized inside the main thread. To illustrate the problem:
// Initialize FreeRTOS. This function never returns. vTaskStartScheduler(); // Initialize uGFX. We never actually arrive here. gfxInit();
Swapping the order of the two function calls won't solve the problem either:
// Initialize uGFX. This requires FreeRTOS to be initialized already. As that's not // the case this function call will lead to a crash. gfxInit(); // Initialize FreeRTOS. This function never returns. vTaskStartScheduler();
The solution to this problem is creating a thread that initializes the entire system. It's a one-time task that doesn't contain a loop:
static void taskInit(void* pvParameters) { (void)pvParameters; gfxInit(); } void main(void) { // Create the initialization task xTaskCreate(taskInit, "Initialization", stackSize, 0, priority, 0); // Initialize FreeRTOS. This will start the scheduler. vTaskStartScheduler(); }