Sunday, August 25, 2019

[Study FreeRTOS-API] 2.26 xTaskResumeAll ()

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

BaseType_t xTaskResumeAll(void);

Summary
Resumes  scheduler  activity,  following  a  previous  call  to  vTaskSuspendAll(),  by  transitioning
the scheduler into the Active state from the Suspended state.

Parameters
None.

Return Values
pdTRUE  The scheduler was transitioned into the Active state. The transition caused a
pending context switch to occur.
pdFALSE  Either the scheduler was transitioned into the Active state and the transition did not
cause a context switch to occur, or the scheduler was left in the Suspended state
due to nested calls to vTaskSuspendAll().


Notes
The  scheduler  can  be  suspended  by  calling  vTaskSuspendAll().   When  the  scheduler  is
suspended,  interrupts remain enabled, but a context switch  will not  occur. If a context switch
is requested while the scheduler is suspended, then the request will be held pending until such
time that the scheduler is resumed (un-suspended).
Calls  to  vTaskSuspendAll()  can  be  nested.   The  same  number  of  calls  must  be  made  to
xTaskResumeAll() as have previously been made to  vTaskSuspendAll() before the scheduler
will leave the Suspended state and re-enter the Active state.
xTaskResumeAll()  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).

Other FreeRTOS API functions should not be called while the scheduler is suspended.
Example
137
/* A function that suspends then resumes the scheduler. */
void vDemoFunction( void )
{
/* This function suspends the scheduler. When it is called from vTask1 the
scheduler is already suspended, so this call creates a nesting depth of 2. */
vTaskSuspendAll();
/* Perform an action here. */
/* As calls to vTaskSuspendAll() are now nested, resuming the scheduler here
does not cause the scheduler to re-enter the active state. */
xTaskResumeAll();
}
void vTask1( void * pvParameters )
{
for( ;; )
{
/* Perform some actions here. */
/* At some point the task wants to perform an operation during which it  does not want to get swapped out, or it wants to access data which is also accessed from another task (but not from an interrupt).  It cannot use taskENTER_CRITICAL()/taskEXIT_CRITICAL() as the length of the operation may cause interrupts to be missed. */

/* Prevent the scheduler from performing a context switch. */
vTaskSuspendAll();
/* Perform the operation here. There is no need to use critical sections as the task has all the processing time other than that utilized by interrupt service routines.*/
/* Calls to vTaskSuspendAll() can be nested, so it is safe to call a (nonAPI) function that also calls vTaskSuspendAll(). API functions should not be called while the scheduler is suspended. */
vDemoFunction();

/* The operation is complete. Set the scheduler back into the Active
state. */
if( xTaskResumeAll() == pdTRUE )
{
/* A context switch occurred within xTaskResumeAll(). */
}
else
{
/* A context switch did not occur within xTaskResumeAll(). */
}
}
}

No comments:

Post a Comment

Back to Top