Difference between revisions of "Resuming Task From ISR"
(2 intermediate revisions by the same user not shown) | |||
Line 35: | Line 35: | ||
[[FILE:ResumingTaskFromISR.png]] | [[FILE:ResumingTaskFromISR.png]] | ||
<br> | <br> | ||
− | 0. Serial port is initialised | + | 0. Serial port is initialised 3-Tasks is created with priorities 2-4. |
− | # | + | #Task4 starts executing as it has the highest priority and suspends Task2,Task3 and itself. Now Task2, Task3 and Task4 are in suspended state and will not run until they are resumed. |
− | + | ||
#Now IDLE tasks keeps running till one of the Task comes out or suspended state. In the current example, only INTO ISR can resume the tasks. | #Now IDLE tasks keeps running till one of the Task comes out or suspended state. In the current example, only INTO ISR can resume the tasks. | ||
#Once the INT0 interrupt is generated, it will resume Task2. | #Once the INT0 interrupt is generated, it will resume Task2. | ||
Line 49: | Line 48: | ||
#Only IDLE task is left and it keeps running. | #Only IDLE task is left and it keeps running. | ||
+ | =Downloads= | ||
+ | Download the complete project and libraries from [https://github.com/ExploreEmbedded/Arduino_FreeRTOS/archive/master.zip here].<br><br> | ||
− | |||
− | |||
Have an opinion, suggestion , question or feedback about the article let it out here! | Have an opinion, suggestion , question or feedback about the article let it out here! | ||
{{DISQUS}} | {{DISQUS}} |
Latest revision as of 15:57, 4 July 2016
In earlier tutorials, we saw how to Suspend and Resume the tasks from other tasks.
In this tutorial, we will how to resume a task from ISR using xTaskResumeFromISR().
For this, we will be using the external INTO interrupt of Arduino UNO. Check this link for more details on Arduino UNO external interrupt.
Contents
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.
vTaskDelete():This function is used to delete as task. We need to pass the taskHandle of the task to be deleted.
To delete the own task we should pass NULL as the parameter. Please 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.
xTaskResumeFromISR(): This function is used to resume a task from ISR.
For this, we need to pass the handle of the task to be resumed. Check this link for more details.
Example1
In this example, we will be creating four Tasks with priorities 1-4.
Task4 which has the highest priority will run for some time and suspends all the tasks. At this point, the scheduler will be left out with the Idle task. This keeps running as long as the other tasks are not resumed.
Every time Falling edge interrupt is detected, ISR will resume a task. This will cause the Cpu to preempt Idle task and run the resumed task. The resumed task will run for some time and deletes itself.
This resuming of tasks continues for 3 times after which all tasks are deleted and the idle task keeps running.
Output1
0. Serial port is initialised 3-Tasks is created with priorities 2-4.
- Task4 starts executing as it has the highest priority and suspends Task2,Task3 and itself. Now Task2, Task3 and Task4 are in suspended state and will not run until they are resumed.
- Now IDLE tasks keeps running till one of the Task comes out or suspended state. In the current example, only INTO ISR can resume the tasks.
- Once the INT0 interrupt is generated, it will resume Task2.
- Task2 will run for some time and deletes itself.
- Again IDLE task keeps running till interrupt is generated and tasks are resumed.
- Once the INT0 interrupt is generated, it will resume Task3.
- Task3 will run for some time and deletes itself.
- Again IDLE task keeps running till interrupt is generated and tasks are resumed.
- Once the INT0 interrupt is generated, it will resume Task3.
- Task3 will run for some time and deletes itself.
- Only IDLE task is left and it keeps running.
Downloads
Download the complete project and libraries from here.
Have an opinion, suggestion , question or feedback about the article let it out here!