# Suspend/Resume tasks in FreeRTOS using Arduino

ArduinoArduino BoardsArduino IDEArduino Programming Language

If you wish to suspend a task in FreeRTOS, there is a function vTaskSuspend() that can be used. The syntax is −

Syntax

void vTaskSuspend( TaskHandle_t xTaskToSuspend );

As you can see, it takes the handle of the task to suspend as the argument and returns nothing. A suspended task can be resumed using vTaskResume(). The syntax is −

Syntax

void vTaskResume( TaskHandle_t xTaskToResume );

This again takes the handle of the task to be resumed, and returns nothing.

In order to see an example, we will walk-through the code given in −https://exploreembedded.com/wiki/Task_Suspend_and_Resume

As you can see, four Task handles are declared initially, and the tasks are created in the setup.

/************************************************************************
***************************
*************************************************************************
***************************
* Version: 15.0
* Author: ExploreEmbedded
* Website: http://www.exploreembedded.com/wiki
* Description: File contains the free rtos example to demonstarte task Suspend and Resume.
This code has been developed and tested on ExploreEmbedded boards.
We strongly believe that the library works on any of development boards for
respective controllers.
Check this link http://www.exploreembedded.com/wiki for awesome tutorials
on 8051,PIC,AVR,ARM,Robotics,RTOS,IOT.
ExploreEmbedded invests substantial time and effort developing open source
HW and SW tools, to support consider

The ExploreEmbedded libraries and examples are licensed under the terms of
EXPLOREEMBEDDED DISCLAIMS ANY KIND OF HARDWARE FAILURE RESULTING OUT OF
USAGE OF LIBRARIES, DIRECTLY OR
INDIRECTLY. FILES MAY BE SUBJECT TO CHANGE WITHOUT PRIOR NOTICE. THE
REVISION HISTORY CONTAINS THE INFORMATION RELATED TO UPDATES.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that this copyright notices appear in all copies and that both those
copyright notices and this permission notice appear in supporting
documentation.
*************************************************************************
*************************/

#include <Arduino_FreeRTOS.h>

void setup()
{
Serial.begin(9600);
Serial.println(F("In Setup function"));

/* Create 4-tasks with priorities 1-4. Capture the Task details to respective handlers */
}

Note that Task1 has the lowest priority and Task4 has the highest priority.

The loop just contains a print statement and a delay.

void loop()
{
// Hooked to Idle Task, will run when CPU is Idle
Serial.println(F("Loop function"));
delay(50);
}

/* Task1 with priority 1 */
{

}

/* Task2 with priority 2 */
{
}

/* Task3 with priority 3 */
{
}

/* Task4 with priority 4 */
{
}