Difference between revisions of "Binary Semaphore 02: Extended Priority Inversion"
Line 1: | Line 1: | ||
[[category: Free RTOS with Arduino]] | [[category: Free RTOS with Arduino]] | ||
− | In earlier tutorials, we saw how to create | + | In earlier tutorials, we saw how to create, delete, suspend and resume the tasks.<br> |
− | In this tutorial, we will see how to | + | In this tutorial, we will see how to read the Task info(state, Stack size, priority.<br> |
Line 10: | Line 10: | ||
<b>vTaskDelay()</b>: 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 [http://www.freertos.org/a00127.html this link] for more details.<br> | <b>vTaskDelay()</b>: 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 [http://www.freertos.org/a00127.html this link] for more details.<br> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<b>vTaskSuspend():</b> This function is used to Suspend a task, the suspended remains in the same state util it is resumed.<br> | <b>vTaskSuspend():</b> This function is used to Suspend a task, the suspended remains in the same state util it is resumed.<br> | ||
Line 25: | Line 16: | ||
<b>vTaskResume():</b> 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<br> | <b>vTaskResume():</b> 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<br> | ||
For this, we need to pass the handle of the task to be resumed. Check [http://www.freertos.org/a00131.html this link] for more details. | For this, we need to pass the handle of the task to be resumed. Check [http://www.freertos.org/a00131.html this link] for more details. | ||
+ | |||
+ | <b>vTaskList():</b> 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 [http://www.freertos.org/a00021.html#vTaskList this link] for more details. | ||
=Example1= | =Example1= | ||
+ | In this example, we will be creating four tasks which run for some time and go to wait/blocked state allowing other tasks to run.<br> | ||
+ | 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. | ||
<html><script src="https://gist.github.com/SaheblalBagwan/c696f165daba3e2826cd3b9ebf33785f.js"></script></html> | <html><script src="https://gist.github.com/SaheblalBagwan/c696f165daba3e2826cd3b9ebf33785f.js"></script></html> | ||
Revision as of 09:55, 1 July 2016
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 four 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