Sunday, August 25, 2019

[Study FreeRTOS-API] 2.33 vTaskSuspend ()

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

void vTaskSuspend(TaskHandle_t pxTaskToSuspend);

Summary
Places a task into the  Suspended state.  A task that is in the Suspended state will never be selected to enter the Running state.
The only way of removing a task from the Suspended state is to make it the subject of a call to
vTaskResume().


Parameters
pxTaskToSuspend  The handle of the task being suspended.
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().
A task may suspend itself by passing NULL in place of a valid task handle.


Return Values
None.

Notes
If FreeRTOS version 6.1.0 or later is being used, then  vTaskSuspend() can be  called to place
a  task  into  the  Suspended  state  before  the  scheduler  has  been  started  (before
vTaskStartScheduler() has been called). This will result in the task (effectively) starting in the
Suspended state.


Example 
void vAFunction( void )
{
TaskHandle_t xHandle;
/* Create a task, storing the handle of 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 of the created task to place the task in the Suspended state.  From FreeRTOS version 6.1.0, this can be done before the Scheduler has been started. */

vTaskSuspend( xHandle );
/* The created task will not run during this period, unless another task calls vTaskResume( xHandle ). */
/* Use a NULL parameter to suspend the calling task. */

vTaskSuspend( NULL );

/* This task can only execute past the call to vTaskSuspend( NULL ) if another task has resumed (un-suspended) it using a call to vTaskResume(). */
}

No comments:

Post a Comment

Back to Top