Manage FreeRTOS tasks - Suspend, Delay, Resume, Delete
Once you have FreeRTOS tasks running, you might want to manage them. The scheduler can stop, suspend, and resume individual tasks. You can control tasks from within or you can use task handles to control them from anywhere in your code.
Using task handles:
// Define a task handle and initialize it to NULL
TaskHandle_t task_handle = NULL;
// Create the task, and pass the task handle as last parameter
// to xTaskCreate (pointer):
task1, // Function that should be called
"Task 1", // Name of the task (for debugging)
1000, // Stack size (bytes)
NULL, // Parameter to pass
1, // Task priority
&task1_handle // Task handle
Stopping a task
// From within the task itself:
// From the outside (with a task handle)
Suspending & resuming a single task
// Suspend a task within the task itself:
// Suspend a task from the outside
// Resume a task (only possible from the outside)
Suspend all tasks & resume all tasks
If you have time-sensitive code, you might want to temperorily pause all other tasks while executing it.
// Do something really important here
// (Code that's timing sensitive and should
// not be interrupted by FreeRTOS)
// Resume all tasks again
- FreeRTOS homepage: https://www.freertos.org
- Documentation for the FreeRTOS implementation for ESP32: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/freertos.html
💌 Subscribe to my newsletter
(related to science, technology, biology, and other nerdy things)!
Check out past editions.