Chapter 4. API Guides
Tick Interrupts
Vanilla FreeRTOS requires that a periodic tick interrupt occurs. The tick interrupt is responsible for:
• Incrementing the scheduler’s tick count
• Unblocking any blocked tasks that have timed out
• Checking if time slicing is required (i.e., triggering a context switch)
• Executing the application tick hook
In ESP-IDF FreeRTOS, each core will receive a periodic interrupt and independently run the tick interrupt. The tick
interrupts on each core are of the same period but can be out of phase. Furthermore, the tick interrupt responsibilities
listed above are not run by all cores:
• CPU0 will execute all of the tick interrupt responsibilities listed above
• CPU1 will only check for time slicing and execute the application tick hook
Note: CPU0 is solely responsible for keeping time in ESP-IDF FreeRTOS. Therefore anything that prevents CPU0
from incrementing the tick count (such as suspending the scheduler on CPU0) will cause the entire schedulers time
keeping to lag behind.
Idle Tasks
Vanilla FreeRTOS will implicitly create an idle task of priority 0 when the scheduler is started. The idle task runs
when no other task is ready to run, and it has the following responsibilities:
• Freeing the memory of deleted tasks
• Executing the application idle hook
In ESP-IDF FreeRTOS, a separate pinned idle task is created for each core. The idle tasks on each core have the
same responsibilities as their vanilla counterparts.
Scheduler Suspension
Vanilla FreeRTOS allows the scheduler to be suspended/resumed by calling vTaskSuspendAll() and
xTaskResumeAll() respectively. While the scheduler is suspended:
• Task switching is disabled but interrupts are left enabled.
• Calling any blocking/yielding function is forbidden, and time slicing is disabled.
• The tick count is frozen (but the tick interrupt will still occur to execute the application tick hook)
On scheduler resumption, xTaskResumeAll() will catch up all of the lost ticks and unblock any timed out tasks.
In ESP-IDF FreeRTOS, suspending the scheduler across multiple cores is not possible. Therefore when vTaskSus-
pendAll() is called:
• Task switching is disabled only on the current core but interrupts for the current core are left enabled
• Calling any blocking/yielding function on the current core is forbidden. Time slicing is disabled on the current
core.
• If suspending on CPU0, the tick count is frozen. The tick interrupt will still occur to execute the application
tick hook.
When resuming the scheduler on CPU0, xTaskResumeAll() will catch up all of the lost ticks and unblock any
timed out tasks.
Warning: Given that scheduler suspension on ESP-IDF FreeRTOS will only suspend scheduling on a particular
core, scheduler suspension is NOT a valid method ensuring mutual exclusion between tasks when accessing shared
data. Users should use proper locking primitives such as mutexes or spinlocks if they require mutual exclusion.
Espressif Systems 1363
Submit Document Feedback
Release v4.4