Difference between revisions of "FreeRTOS"

From uGFX Wiki
Jump to: navigation, search
Line 23: Line 23:
 
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:
 
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">
 
<source lang="c">
// ToDo
+
 
 +
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>
 
</source>

Revision as of 14:00, 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();