Running to suspend and suspend to running state

I have tried running freertos on ESp32

void setup()
{
  Serial.begin(112500);
  /* Create two tasks. */
  xTaskCreate( vTask1, "Task 1", 10000, NULL, 1, NULL); 
  
}


void loop() {
  // Do nothing

}

void vTask1( void *pvParameters )
{
  /* As per most tasks, this task is implemented in an infinite loop. */
  for(;;)
  {
    Serial.println("Task 1 is running");
     vTaskDelay(1000); 
   }
}

07:38:13.822 → Task 1 is running
07:38:14.814 → Task 1 is running
07:38:15.850 → Task 1 is running
07:38:16.842 → Task 1 is running
07:38:17.832 → Task 1 is running
07:38:18.822 → Task 1 is running
07:38:19.811 → Task 1 is running
07:38:20.846 → Task 1 is running
07:38:21.840 → Task 1 is running
07:38:22.829 → Task 1 is running
07:38:23.823 → Task 1 is running
07:38:24.815 → Task 1 is running
07:38:25.852 → Task 1 is running

Task1 is highest priority task runs first, then blocks for 1000ms

https://www.freertos.org/RTOS-task-states.html

I want to experiement with running to suspend state and running suspend state
Do I have to create new task, How to do it ?

I’m not sure I really understand your question, but use the vTaskSuspend() API function if you want to suspend a task. In my experience though it is very rare to suspend tasks in real applications.

1 Like

As Richard Barry says, actually suspending a task doesn’t have much use. Before the addition of the direct-to-task notification, it had some use for a very light weight synchronization method.

The suspend state can still be used on ‘block forever’ operations , but I often find I want to put a finite timeout to have the system just be able to handle other housekeeping and check for hung systems.

But, yes, if you put the task into the suspend state, then SOMETHING need to do something to wake it up, that could be an ISR or another task.

1 Like