tick 0CPU1 core1void sensor(void *p) {2 for (;;) {3 read();4 vTaskDelay(WAIT);5 }6}2priority1priority0prioritysensorpriority 2displaypriority 1loggerpriority 1idlepriority 0
Back: the tick timer, the CPU (one running task) and the Blocked trayFront: the sensor task's code and the Ready lists, one lane per priorityTokens: tasks moving between Ready, Running and Blocked, and tick pulsesA FreeRTOS scheduler on an ESP32-C3 (one core) with a 1 ms tick: the tick timer, the CPU, the Blocked tray, and the Ready lists for priorities 2, 1 and 0. The highest-priority Ready task runs; equal priorities take turns each tick; a task in vTaskDelay is Blocked and uses no CPU until its wake tick; with nothing else ready the idle task runs.

Ticks and tasks

  1. A hardware timer interrupts the CPU every tick. On our ESP32-C3 with the Arduino core the tick rate is 1000 Hz, so one tick is 1 ms. Each tick FreeRTOS adds 1 to the tick count and checks whether to switch tasks.

How it picks

Waking and preempting

What happens

;; step 1/11 · tick
tick rate   configTICK_RATE_HZ = 1000  ->  1 tick = 1 ms
tick ISR    tick count += 1
            wake tasks whose delay is over
            pick again if needed
tick count  ticks since the scheduler started

The figure starts the clock at tick 0 with all three tasks already ready. On the Arduino core, setup() itself runs inside a task called loopTask at priority 1, so sensor really starts the moment it is created; loop() then deletes loopTask so it does not share priority 1. read(), draw() and save() stand for your own code. The figure assumes they need 0.2 ms, 2.5 ms and 1.7 ms of CPU time. A real job takes as long as its code does.