Starting the scheduler

With all of the options we have for creating tasks, you might be thinking that starting the scheduler would be a complex affair. You'll be pleasantly surprised at how easy it is:

//starts the FreeRTOS scheduler - doesn't
//return if successful
vTaskStartScheduler();

Yep, just one line of code and no input parameters!

The v in front of the function name indicates it returns void. In reality, this function never returns unless there is a problem. It is the point where vTaskStartScheduler() is called that the program transitions from a traditional single super loop to a multi-tasking RTOS.

After the scheduler is started, we'll need to think about and understand the different states the tasks are in so we can debug and tune our system properly.

For reference, here's the entirety of main() we've just built up through the various examples. This excerpt has been taken from main_taskCreation.c:

int main(void)
{
HWInit();

if (xTaskCreate(GreenTask, "GreenTask",
STACK_SIZE, NULL,
tskIDLE_PRIORITY + 2, NULL) != pdPASS)
{ while(1); }

assert_param(xTaskCreate(BlueTask, "BlueTask", STACK_SIZE,NULL,
tskIDLE_PRIORITY + 1, &blueTaskHandle) == pdPASS);

xTaskCreateStatic( RedTask, "RedTask", STACK_SIZE, NULL,
tskIDLE_PRIORITY + 1,
RedTaskStack, &RedTaskTCB);

//start the scheduler - shouldn't return unless there's a problem
vTaskStartScheduler();

while(1){}
}

Now that we've learned how to create tasks and get the scheduler up and running, the last detail to cover in this example is how to go about deleting a task.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.32.86