Line 12: Line 12:
  
 
<b>vTaskDelete():</b>This function is used to delete as task. We need to pass the taskHandle of the task to be deleted.<br>
 
<b>vTaskDelete():</b>This function is used to delete as task. We need to pass the taskHandle of the task to be deleted.<br>
To delete the own task we should pass NULL as parameter. Please check [http://www.freertos.org/a00126.html this link] for detials. <br>
+
To delete the own task we should pass NULL as the parameter. Please check [http://www.freertos.org/a00126.html this link] for details. <br>
  
 
<b>vTaskPrioritySet():</b> This function is used to change/Set the priority of a task.<br>
 
<b>vTaskPrioritySet():</b> This function is used to change/Set the priority of a task.<br>
Line 18: Line 18:
  
 
<b>vTaskPriorityGet():</b> This function is used to get the priority of a task.<br>
 
<b>vTaskPriorityGet():</b> This function is used to get the priority of a task.<br>
For this we need to pass the handle of the task and it will return the task. Check [http://www.freertos.org/a00128.html this link] for more details.
+
For this, we need to pass the handle of the task and it will return the task. Check [http://www.freertos.org/a00128.html this link] for more details.
  
 
<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>
For this we need to pass the handle of the tasks that needs to be suspended. Passing NULL will suspend own task. Check [http://www.freertos.org/a00130.html this link] for more details.
+
For this, we need to pass the handle of the tasks that needs to be suspended. Passing NULL will suspend own task. Check [http://www.freertos.org/a00130.html this link] for more details.
  
<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 preemt 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.
  
=Example1=
+
=Example=
<html> <script src="https://gist.github.com/SaheblalBagwan/01c619f523815c268f1358c1bce32abb.js"></script></html>
+
<html><script src="https://gist.github.com/SaheblalBagwan/89ad71f71dbb9799bd6db604fa0d18d5.js"></script></html>
  
=Output1=
+
=Output=
[[FILE:TaskPriorityChange.png]]
+
[[FILE:TaskSuspendAndResume.png]]
 
<br>
 
<br>
 
0. Serial port is initialised and Task1 is created with priority 1.
 
0. Serial port is initialised and Task1 is created with priority 1.
 
#As we have only Task1 and Idle task, Task1 starts executing. Furter Task1 creates Task
 
#As we have only Task1 and Idle task, Task1 starts executing. Furter Task1 creates Task

Revision as of 16:09, 28 June 2016

In earlier tutorials, we saw how to create and use and delete the tasks.
In this tutorial, we will see how to Suspend and Resume the tasks.


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 details.

vTaskPrioritySet(): This function is used to change/Set the priority of a task.
For this we need to pass the handle of the task and new priority to vTaskPrioritySet() function. Check this link for more details.

vTaskPriorityGet(): This function is used to get the priority of a task.
For this, we need to pass the handle of the task and it will return the task. 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.

Example

Output

TaskSuspendAndResume.png
0. Serial port is initialised and Task1 is created with priority 1.

  1. As we have only Task1 and Idle task, Task1 starts executing. Furter Task1 creates Task