Sunday, August 25, 2019

[Study FreeRTOS-API] 2.25 vTaskResume( )

#include "FreeRTOS.h"
#include "task.h"

void vTaskResume(TaskHandle_t pxTaskToResume);

Summary
Transition a task from the Suspended state to the Ready state. The task must have previously
been placed into the Suspended state using a call to vTaskSuspend().

Parameters
pxTaskToResume  The handle of the task being resumed (transitioned out of the Suspended
state).  This is the subject task.
To obtain a task’s handle create the task using xTaskCreate() and make
use of the pxCreatedTask parameter, or create the task using xTaskCreateStatic() and store the returned value, or use the task’s name in a call to xTaskGetHandle().

Return Values
None.


Notes
A task can be blocked to wait for a queue event, specifying a timeout period. It is legitimate to
move such a Blocked task into the Suspended state using a call to vTaskSuspend(), then out
of the Suspended state and into the Ready state using a call to  vTaskResume(). Following
this scenario, the next time the task enters the Running state it will check whether or not its
timeout period has (in  the meantime) expired. If the timeout period has not expired,  the task
will once again enter the Blocked state to wait for the queue  event for the remainder of the
originally specified timeout period.


A  task  can  also  be  blocked  to  wait  for  a  temporal  event  using  the  vTaskDelay()  or
vTaskDelayUntil()  API  functions.   It  is  legitimate  to  move  such  a  Blocked  task  into  the
Suspended state using a call to vTaskSuspend(), then out of the Suspended state and into the
Ready state using a call to  vTaskResume(). Following this scenario, the next time the task
enters  the  Running state  it  will  exit  the  vTaskDelay()  or  vTaskDelayUntil() function  as  if the
specified delay period had expired, even if this is not actually the case.
vTaskResume() must only be called from an executing task and therefore must not be called
while the scheduler is in the Initialization state (prior to the scheduler being started).


Example 
void vAFunction( void )
{
TaskHandle_t xHandle;
/* Create a task, storing the handle to the created task in xHandle. */
if( xTaskCreate( vTaskCode,
"Demo task",
STACK_SIZE,
NULL,
PRIORITY,
&xHandle
) != pdPASS )
{
/* The task was not created successfully. */
}
else
{
/* Use the handle to suspend the created task. */
vTaskSuspend( xHandle );

/* The suspended task will not run during this period, unless another task
calls vTaskResume( xHandle ). */

/* Resume the suspended task again. */
vTaskResume( xHandle );

/* The created task is again available to the scheduler and can enter The Running state. */
}

No comments:

Post a Comment

Back to Top