Binary Semaphore 02: Extended Priority Inversion
In earlier tutorials, we saw how to create, delete, suspend and resume the tasks.
In this tutorial, we will see how to read the Task info(state, Stack size, priority.
API Details
Here we will discuss some of the most frequently used APIs related to tasks.
xTaskCreate(): This interface is used to create a new Task, if the task is successfully created then it returns pdPass(1) or else errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY(-1). Check this link for more details.
vTaskDelay(): This function is used to delay/block the task for specified delay time(ticks). INCLUDE_vTaskDelay needs to be set to 1 in FreeRtosConfig.h file for using this function. Check this link for more details.
vTaskSuspend(): This function is used to Suspend a task, the suspended remains in the same state util it is resumed.
For this, we need to pass the handle of the tasks that needs to be suspended. Passing NULL will suspend own task. Check this link for more details.
vTaskResume(): This function is used to resume a suspended task. If the Resumed task has higher priority than the running task then it will preempt the running task or else stays in ready state
For this, we need to pass the handle of the task to be resumed. Check this link for more details.
vTaskList(): This function is used to read the task details(name, state, priority, num). We need to pass a string pointer(buffer) to which it copies the above task details. The buffer size should be minimum 40 bytes per task. Check this link for more details.
Example1
In this example, we will be creating 3-tasks which run for some time and go to wait/blocked state allowing other tasks to run.
We will include INT0 falling edge interrupt to read and display the current task list with all the task info. Every time interrupt is generated it takes the snap of tasks(name, state, priority, num) and displays on Serial port.
Output1
0. Serial port is initialised and Task1 and Task3 are created with priority 1&3.
- Task3 starts executing as it has higher priority. NowTask3 creates Task2 and Task4 with priorities 2 and 4. Since Task4 has higher priority compared to Task3, Task4 starts running preempting Task3