In development. It changes without notice.
Topic
RTOS Facade
Tasks and the core each runs on, queues, semaphores, critical sections, delays and the task watchdog.
The types of FreeRTOS stay inside. Core 1 runs the application's loop and the screen; core 0 runs Bluetooth, Wi-Fi, storage and crypto. A task of the application takes a priority from 1 to 6, below the radios'. The size of a stack is in bytes.
What more than one task may reach first (a queue, a mutex, a task) is built under kleidos::
The tick and the CPU clock. On the ESP32 boards the tick is counted in CPU cycles, by a number worked out for the clock the board started at. Each change of the CPU clock therefore writes that number again, in the one function that changes it; otherwise every delay and timeout would be wrong by the ratio of the two clocks. The interval already running on each core ends up to 2 ms late or early, once for each change. On the ESP32-S3 the tick comes from a timer of its own and none of this is needed. Where ESP-IDF's power management makes the changes, it does this itself.
Files | |
| file | src/ |
| Umbrella include for the platform RTOS facade. | |
| file | src/ |
| The wait step of the exactly-once guard. | |
| file | src/ |
| Exactly-once creation of an object several tasks may reach first. | |
| file | src/ |
| Raw and typed FreeRTOS queue operations. | |
| file | src/ |
| Type-safe RTOS queue facade over FreeRTOS queues. | |
| file | src/ |
| Stack fill-pattern refill implementation. | |
| file | src/ |
| Debug-only refill of a task's FreeRTOS stack fill pattern. | |
| file | src/ |
| FreeRTOS semaphore, mutex, and critical-section implementations. | |
| file | src/ |
| RTOS synchronization primitives: semaphores, mutexes, critical locks. | |
| file | src/ |
| FreeRTOS task lifecycle, introspection, and notification implementations. | |
| file | src/ |
| RTOS task lifecycle, introspection, and notification facade. | |
| file | src/ |
| FreeRTOS tick and delay implementations. | |
| file | src/ |
| RTOS timing facade: tick conversions and task delays. | |
| file | src/ |
| Shared types for the platform RTOS facade. | |
| file | src/ |
| Cycles-per-tick arithmetic for a tick generated from the CPU clock. | |
| file | src/ |
| Task watchdog (TWDT) configuration and subscription implementation. | |
| file | src/ |
| Task watchdog (TWDT) configuration and subscription facade. | |
Typedefs | |
| using | kleidos:: |
| Task priority value. | |
| using | kleidos:: |
| Queue capacity in items. | |
Functions | |
| template<typename T> | |
| QueueHandle | kleidos:: |
Create a static queue for trivially-copyable type T. | |
| template<typename T> | |
| bool | kleidos:: |
| Send a typed item onto a queue. | |
| template<typename T> | |
| bool | kleidos:: |
| Send a typed item onto a queue from ISR context. | |
| template<typename T> | |
| bool | kleidos:: |
| Receive a typed item from a queue. | |
| template<typename T> | |
| bool | kleidos:: |
| Receive a typed item from a queue in ISR context. | |
| template<size_ | |
| uint32_t | kleidos:: |
| Capture task snapshots into a fixed-size array (capacity deduced). | |
| constexpr uint32_t | kleidos:: |
| Cycles one tick lasts at a core frequency. | |
| constexpr bool | kleidos:: |
| Store the cycles-per-tick a core frequency implies, or refuse. | |
| constexpr Config | kleidos:: |
| The configuration ESP-IDF's TWDT auto-init applies at boot. | |
| bool | kleidos:: |
| Reconfigure an already-initialized task watchdog. | |
| Config | kleidos:: |
| Return the task-watchdog configuration currently in force. | |
| bool | kleidos:: |
| Reconfigure the task watchdog, initializing it first if needed. | |
| TaskSubscribeResult | kleidos:: |
| Subscribe a task to the task watchdog. | |
| bool | kleidos:: |
| Feed the task watchdog for the calling task. | |
| const char * | kleidos:: |
| Return a human-readable name for a subscribe result. | |
| bool | kleidos:: |
| Whether the task watchdog (TWDT) is compiled in and auto-initialized. | |
| bool | kleidos:: |
| Whether the interrupt watchdog (IWDT) is compiled in. | |
Variables | |
| constexpr Priority | kleidos:: |
| Lowest allowed application task priority. | |
| constexpr Priority | kleidos:: |
| Highest allowed application task priority. | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| Hertz in one megahertz, so the conversion below is not a bare literal. | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| Timeout assumed when sdkconfig does not define the TWDT period. | |
| constexpr uint32_t | kleidos:: |
| Idle-core mask bit of core 0. | |
| constexpr uint32_t | kleidos:: |
| Idle-core mask bit of core 1. | |
Diagnostics | |
| constexpr uint32_t | kleidos:: |
| Capacity of one task census: the largest snapshot this facade can take. | |
| uint32_t | kleidos:: |
| Return the minimum free stack seen for a task (high-water mark). | |
| uint32_t | kleidos:: |
| Return the minimum free stack seen for the calling task. | |
| uint32_t | kleidos:: |
| Return the total number of tasks in the system. | |
| uint32_t | kleidos:: |
Capture a snapshot of all tasks into out. | |
Raw operations | |
| QueueHandle | kleidos:: |
| Create a static queue backed by caller-provided storage. | |
| QueueHandle | kleidos:: |
| Create a dynamically-allocated queue. | |
| bool | kleidos:: |
| Send raw bytes onto a queue. | |
| bool | kleidos:: |
| Send raw bytes onto a queue from ISR context. | |
| bool | kleidos:: |
| Receive raw bytes from a queue. | |
| bool | kleidos:: |
| Receive raw bytes from a queue in ISR context. | |
| uint32_t | kleidos:: |
| Return the number of items currently held in the queue. | |
| void | kleidos:: |
| Delete a queue and clear its handle. | |
Validation | |
| bool | kleidos:: |
True when core is a real core selector (not NoAffinity). | |
| bool | kleidos:: |
True when priority falls within the application priority band. | |
| int | kleidos:: |
| Return the numeric core id for a Core value. | |
Current-context queries | |
| TaskHandle | kleidos:: |
| Return the handle of the calling task. | |
| TaskHandle | kleidos:: |
| Return the idle-task handle for a core. | |
| Core | kleidos:: |
| Return the core the caller is currently running on. | |
| int | kleidos:: |
| Return the numeric core id the caller is running on. | |
| Priority | kleidos:: |
| Return the priority of the calling task. | |
Lifecycle | |
| void | kleidos:: |
| Delete a task by handle. | |
| void | kleidos:: |
| Delete the calling task (never returns to caller). | |
| void | kleidos:: |
| Hand the core to another ready task of the caller's priority, if one waits. | |
Creation | |
| bool | kleidos:: |
| Create a dynamically-allocated task pinned to a specific core. | |
| TaskHandle | kleidos:: |
| Create a statically-allocated task pinned to a specific core. | |
Notifications | |
| bool | kleidos:: |
| Send a direct-to-task notification. | |
| bool | kleidos:: |
| Block the calling task until a notification arrives. | |
Tick constructors | |
| constexpr Ticks | kleidos:: |
| Convert a millisecond duration to RTOS ticks. | |
| constexpr Ticks | kleidos:: |
| Alias of ticksFromMs(); preferred in call sites for readability. | |
| constexpr Ticks | kleidos:: |
| Return a zero-wait (non-blocking) duration. | |
| constexpr Ticks | kleidos:: |
| Return an infinite-wait duration. | |
Delays | |
| TickCount | kleidos:: |
| Return the current absolute tick timestamp. | |
| void | kleidos:: |
| Block the caller for a relative tick duration. | |
| void | kleidos:: |
| Block the caller for a millisecond duration. | |
| void | kleidos:: |
| Block the caller indefinitely. | |
| void | kleidos:: |
| Drift-free periodic delay relative to a reference wake time. | |
Tick base | |
| bool | kleidos:: |
| Rewrite the cached cycles-per-tick the Xtensa tick ISR adds to CCOMPARE. | |
| uint32_t | kleidos:: |
| Ticks the kernel counts in one second. | |
| uint32_t | kleidos:: |
| Cycles the tick source counts per tick. | |
Enumeration Type Documentation
Core #
NotifyAction #
Action applied by a task notification.
| Value | Meaning |
|---|---|
NoAction | Wake the target without modifying the notification value. |
SetBits | OR value into the current notification value. |
Increment | Add 1 to the notification value (the value argument is ignored). |
SetValueWithOverwrite | Replace the notification value unconditionally. |
SetValueWithoutOverwrite | Replace the value only if no notification is pending. |
TaskState #
The scheduling state of a task, as taskSnapshots reports it.
FreeRTOS's own states, with a raw value that has no name here reported as Unknown.
TaskSubscribeResult #
Result of subscribing a task to the watchdog.
| Value | Meaning |
|---|---|
Subscribed | Task is now monitored. |
AlreadySubscribed | Task was already in the watchdog's set; treated as success. |
InvalidTask | The task handle was nullptr. |
Failed | The TWDT reported a non-recoverable error. |
Function Documentation
bootConfig() #
The configuration ESP-IDF's TWDT auto-init applies at boot.
Read from the CONFIG_ sdkconfig values (the period, the idle cores watched and whether a timeout panics); the fallbacks above on the native build. A caller that must not change the idle mask at runtime checks it here at compile time.
- Returns
- The boot configuration.
configure() #
Reconfigure an already-initialized task watchdog.
On success the new settings become the value reported by currentConfig().
- Parameters
-
Name Meaning config New timeout and panic settings.
- Return values
-
Value Meaning true Watchdog reconfigured with the new settings. false TWDT was not yet initialized.
configureOrInit() #
Reconfigure the task watchdog, initializing it first if needed.
- Parameters
-
Name Meaning config Timeout, idle-core mask, and panic settings.
- Return values
-
Value Meaning true Watchdog reconfigured (or initialized and configured). false Driver refused the configuration.
coreId() #
createMutex() #
Create a dynamically-allocated mutex.
- Returns
- Non-null handle on success, nullptr on allocation failure.
createPinnedTask() #
Create a dynamically-allocated task pinned to a specific core.
- Parameters
-
Name Meaning entry Task entry function. config Name, stack size, priority, core, and argument. outHandle Optional; set to the new task handle on success.
- Return values
-
Value Meaning true Task was created and pinned to the requested core. false Allocation or configuration failed.
createQueueRaw() #
Create a dynamically-allocated queue.
- Parameters
-
Name Meaning depth Maximum number of items the queue can hold. itemSize Size of each item in bytes.
- Returns
- Non-null handle on success, nullptr on allocation failure.
createRecursiveMutex() #
Create a dynamically-allocated recursive mutex.
- Returns
- Non-null handle on success, nullptr on allocation failure.
createStaticBinarySemaphore() #
Create a statically-allocated binary semaphore.
- Parameters
-
Name Meaning storage Caller-provided static control block.
- Returns
- Non-null handle on success.
createStaticMutex() #
Create a statically-allocated mutex.
- Parameters
-
Name Meaning storage Caller-provided static control block.
- Returns
- Non-null handle on success.
createStaticPinnedTask() #
Create a statically-allocated task pinned to a specific core.
- Parameters
-
Name Meaning entry Task entry function. config Name, stack size, priority, core, and argument. stackStorage Caller-provided stack memory (config.stackBytes bytes). taskStorage Caller-provided static task control block.
- Returns
- Task handle; never null (panics on invalid config).
createStaticQueue() #
Create a static queue for trivially-copyable type T.
- Template Parameters
-
Name Meaning T Element type (must be trivially copyable).
- Parameters
-
Name Meaning depth Maximum number of items the queue can hold. itemStorage Caller-provided storage (depth * sizeof(T) bytes). queueStorage Caller-provided static queue control block.
- Returns
- Non-null handle on success.
createStaticQueueRaw() #
Create a static queue backed by caller-provided storage.
- Parameters
-
Name Meaning depth Maximum number of items the queue can hold. itemSize Size of each item in bytes. itemStorage Caller-provided storage (depth * itemSize bytes). queueStorage Caller-provided static queue control block.
- Returns
- Non-null handle on success.
currentConfig() #
Return the task-watchdog configuration currently in force.
ESP-IDF exposes no getter for the live TWDT settings, so this facade is the single source of truth: the returned value starts at the boot configuration IDF's auto-init applied (the CONFIG_ sdkconfig values) and tracks every later configure() / configureOrInit() that succeeded. Code that temporarily changes the watchdog restores this value instead of rebuilding one from compile-time constants, which would discard the runtime settings.
- Returns
- The live configuration; the sdkconfig boot values on the native build.
- Note
- Reconfiguration is not concurrency-safe (the same restriction ESP-IDF documents for
esp_): only one task at a time may change the watchdog.task_ wdt_ reconfigure
currentCore() #
Return the core the caller is currently running on.
- Returns
- Core enum value for the calling task's current core.
currentCoreId() #
Return the numeric core id the caller is running on.
- Returns
- 0 or 1.
currentStackHighWaterBytes() #
Return the minimum free stack seen for the calling task.
- Returns
- Minimum free stack in bytes observed since the calling task started.
currentTask() #
Return the handle of the calling task.
- Returns
- TaskHandle of the currently executing task.
currentTaskPriority() #
Return the priority of the calling task.
- Returns
- Current task priority.
delay() #
Block the caller for a relative tick duration.
- Parameters
-
Name Meaning ticks Duration to sleep.
delayMs() #
Block the caller for a millisecond duration.
- Parameters
-
Name Meaning ms Milliseconds to sleep.
delayUntil() #
Drift-free periodic delay relative to a reference wake time.
- Parameters
-
Name Meaning previousWake Reference wake tick updated on each call; set to tickCount() before the first call. period Desired period between wakes.
deleteQueue() #
Delete a queue and clear its handle.
- Parameters
-
Name Meaning handle Queue handle; set to nullptr after deletion.
deleteTask() #
Delete a task by handle.
- Parameters
-
Name Meaning task Task handle to delete; nullptr deletes the calling task.
giveRecursiveMutex() #
Unlock a recursive mutex.
- Parameters
-
Name Meaning handle Recursive mutex handle.
- Return values
-
Value Meaning true Mutex was unlocked. false Driver refused the unlock.
giveSemaphore() #
Give (signal) a semaphore.
- Parameters
-
Name Meaning handle Semaphore or mutex handle.
- Return values
-
Value Meaning true Semaphore was given. false Driver refused the give (e.g. invalid handle).
giveSemaphoreFromIsr() #
Give a semaphore from ISR context.
- Parameters
-
Name Meaning handle Semaphore handle. yield ISR yield tracker; call yield.yieldIfNeeded() before leaving the ISR.
- Return values
-
Value Meaning true Semaphore was given from ISR. false Driver refused the give.
idleTask() #
Return the idle-task handle for a core.
- Parameters
-
Name Meaning core Core selector.
- Returns
- TaskHandle of the idle task pinned to that core.
intWdtConfigured() #
Whether the interrupt watchdog (IWDT) is compiled in.
Reflects the CONFIG_ sdkconfig option. A read-only build-configuration query with no side effects.
- Return values
-
Value Meaning true Interrupt watchdog is configured. false Interrupt watchdog is disabled, or the native build.
isAppPriority() #
True when priority falls within the application priority band.
- Parameters
-
Name Meaning priority Priority value to check.
- Return values
-
Value Meaning true kMinAppPriority<= priority <=kMaxAppPriority.false priorityis below the app band (radio) or above it.
isValidCore() #
True when core is a real core selector (not NoAffinity).
- Parameters
-
Name Meaning core Core enum value to validate.
- Return values
-
Value Meaning true coremaps to an existing core.false coreisNoAffinityor out of range.
milliseconds() #
Alias of ticksFromMs(); preferred in call sites for readability.
- Parameters
-
Name Direction Meaning ms in Duration in milliseconds.
- Returns
- Corresponding
Ticksvalue.
mutexHeldByCurrentTask() #
True when the calling task holds the mutex handle.
A mutex is not recursive: a second take from its holder waits for ever, so a caller that may re-enter asks this first.
- Parameters
-
Name Meaning handle Mutex handle (from createMutex or createStaticMutex).
- Return values
-
Value Meaning true The calling task is the holder. false Another task holds it, nobody does, or handleis null.
notify() #
Send a direct-to-task notification.
- Parameters
-
Name Meaning task Target task handle. value Value for the notification action. action How to modify the notification value (SetBits, Increment, etc.).
- Return values
-
Value Meaning true Notification was posted to task.false Driver rejected the notification request.
noWait() #
Return a zero-wait (non-blocking) duration.
- Returns
Tickswith value 0 — the call returns immediately if no item is available.
queuePending() #
Return the number of items currently held in the queue.
- Parameters
-
Name Meaning handle Queue handle.
- Returns
- Item count.
queueReceive() #
Receive a typed item from a queue.
- Template Parameters
-
Name Meaning T Element type (must be trivially copyable).
- Parameters
-
Name Meaning handle Queue handle. out Reference to store the received item. waitTicks Maximum time to block when the queue is empty.
- Returns
- True on success; false on timeout.
queueReceiveFromIsr() #
Receive a typed item from a queue in ISR context.
- Template Parameters
-
Name Meaning T Element type (must be trivially copyable).
- Parameters
-
Name Meaning handle Queue handle. out Reference to store the received item. yield ISR yield tracker; call yield.yieldIfNeeded() before leaving the ISR.
- Returns
- True on success.
queueReceiveFromIsrRaw() #
Receive raw bytes from a queue in ISR context.
- Parameters
-
Name Meaning handle Queue handle. out Destination buffer; must be at least itemSize bytes. yield ISR yield tracker; call yield.yieldIfNeeded() before leaving the ISR.
- Return values
-
Value Meaning true Item was received from ISR. false No item was available.
queueReceiveRaw() #
Receive raw bytes from a queue.
- Parameters
-
Name Meaning handle Queue handle. out Destination buffer; must be at least itemSize bytes. waitTicks Maximum time to block when the queue is empty.
- Return values
-
Value Meaning true Item was received before waitTickselapsed.false Timeout elapsed before an item arrived.
queueSend() #
Send a typed item onto a queue.
- Template Parameters
-
Name Meaning T Element type (must be trivially copyable).
- Parameters
-
Name Meaning handle Queue handle. item Item to send. waitTicks Maximum time to block when the queue is full.
- Returns
- True on success; false on timeout.
queueSendFromIsr() #
Send a typed item onto a queue from ISR context.
- Template Parameters
-
Name Meaning T Element type (must be trivially copyable).
- Parameters
-
Name Meaning handle Queue handle. item Item to send. yield ISR yield tracker; call yield.yieldIfNeeded() before leaving the ISR.
- Returns
- True on success.
queueSendFromIsrRaw() #
Send raw bytes onto a queue from ISR context.
- Parameters
-
Name Meaning handle Queue handle. item Pointer to the item to copy into the queue. yield ISR yield tracker; call yield.yieldIfNeeded() before leaving the ISR.
- Return values
-
Value Meaning true Item was queued from ISR. false Driver refused the post.
queueSendRaw() #
Send raw bytes onto a queue.
- Parameters
-
Name Meaning handle Queue handle. item Pointer to the item to copy into the queue. waitTicks Maximum time to block when the queue is full.
- Return values
-
Value Meaning true Item was queued successfully. false Timeout elapsed before the queue had space.
resetCurrentTask() #
Feed the task watchdog for the calling task.
A silent no-op when the calling task is not subscribed, so shared code paths that run on both subscribed and unsubscribed tasks may feed unconditionally without producing driver error logs.
- Return values
-
Value Meaning true Watchdog was reset for the calling task. false Calling task was not subscribed to the watchdog.
stackHighWaterBytes() #
Return the minimum free stack seen for a task (high-water mark).
- Parameters
-
Name Meaning task Task handle to query.
- Returns
- Minimum free stack in bytes observed since task creation.
storeTickBaseCycles() #
Store the cycles-per-tick a core frequency implies, or refuse.
The whole of the decision syncTickBase makes, with the one thing that cannot exist on the host — the name of the port's cached divisor — passed in instead of referenced. That split is what puts the store itself under host test: a change that computes the right number and never writes it, or writes it on the argument pair that has no answer, is visible here.
A refusal deliberately leaves cachedCycles as it was. Zero cycles per tick would make the tick interrupt re-arm the comparator on the value it just fired at, so the frequency it last described is a far better answer than a number that stops the tick.
- Parameters
-
Name Direction Meaning cachedCycles in, out Cell the tick source reads its per-tick cycle count from; written only on success. cpuMhz in Core frequency now in force, in MHz. tickRateHz in Tick rate in Hz.
- Return values
-
Value Meaning true cachedCyclesnow describescpuMhz.false The pair does not convert (see tickBaseCyclesFor) and cachedCyclesis untouched.
subscribeTask() #
Subscribe a task to the task watchdog.
- Parameters
-
Name Meaning task Task handle to monitor; nullptr results in InvalidTask.
- Return values
-
Value Meaning TaskSubscribeResult:: Subscribed Task is now monitored. TaskSubscribeResult:: AlreadySubscribed Task was already subscribed. TaskSubscribeResult:: InvalidTask taskwas null.TaskSubscribeResult:: Failed Underlying driver call failed.
syncTickBase() #
Rewrite the cached cycles-per-tick the Xtensa tick ISR adds to CCOMPARE.
Re-derive the tick period the kernel counts, for a new core frequency.
ESP-IDF computes _
The intervals this cannot reach
The tick ISR arms the comparator for the NEXT interval before it services the current one: it reads CCOMPARE, adds the divisor as it stands at that instant, and writes the sum back (FreeRTOS-Kernel/
So one interval per core comes out wrong, and it is wrong by the frequency ratio rather than by a fixed amount: an interval armed at the old frequency and elapsed at the new one lasts (old / new) tick periods. CONFIG_
- a 240 -> 80 MHz drop: one interval of 3 ms, i.e. 2 ms late;
- an 80 -> 240 MHz rise: one interval of 0.333 ms, i.e. 0.67 ms early.
Both cores pay it independently — each has its own CCOMPARE and its own interval in flight — and each re-arms from this value at its own next tick, after which every interval on both cores is a real tick again.
A tick that lands on either core in the few instructions between the frequency switch and this write arms one further interval from the stale divisor, so the honest worst case is two intervals per core, not one. Against a 1 kHz tick that window is about 10^-5 of the time between ticks.
The ISR's catch-up loop absorbs none of it. That loop re-enters only when the cycles elapsed at ISR entry already exceed the divisor (portasm.S:353-357), which is a tick serviced late; a comparator re-armed exactly one divisor ahead never produces that.
Removing the one-off means re-arming CCOMPARE on both cores, which is what esp_pm does: rescale the calling core's comparator under a spinlock, then send a cross-core interrupt and spin until the other core has rescaled its own. That machinery belongs to esp_pm and lives in IRAM. A bounded, self-correcting slip on one tick boundary per core per frequency change is the price of not having it; what it replaces is a permanent proportional error on every tick for as long as the clock stays moved.
Where the SoC has no SYSTIMER the Xtensa port generates the tick from the CPU's own CCOUNT/
Which SoC family that applies to is the platform knowledge this facade exists to hold; when to call it is not. It is called from the one function that applies a core frequency, kleidos::, with the frequency the silicon has just accepted — so no policy above that function can be the one that forgets, and a frequency that was refused never reaches it.
On a board built with ESP-IDF's power management (kleidos::: the idle floor, or automatic light sleep) ESP-IDF switches the clock instead (with the idle floor many times a second) and re-derives the period itself on every switch, rescaling the comparator already counting on both cores as well; that function then does not call this one. tickBaseCycles still reads the period back.
- Parameters
-
Name Direction Meaning cpuMhz in Core frequency now in force, in MHz.
- Return values
-
Value Meaning true The tick is CPU-derived on this SoC and the period was rewritten. false The tick runs off a fixed timer and nothing needed doing, or cpuMhzdoes not convert (see tickBaseCyclesFor).
takeRecursiveMutex() #
Lock a recursive mutex.
- Parameters
-
Name Meaning handle Recursive mutex handle. waitTicks Maximum time to block.
- Return values
-
Value Meaning true Recursive mutex was locked. false Timeout elapsed before the mutex was available.
takeSemaphore() #
Take (wait for) a semaphore.
- Parameters
-
Name Meaning handle Semaphore or mutex handle. waitTicks Maximum time to block.
- Return values
-
Value Meaning true Semaphore was taken before waitTickselapsed.false Timeout elapsed before the semaphore was available.
taskCount() #
Return the total number of tasks in the system.
- Returns
- Task count.
taskSnapshots() [1/2] #
Capture a snapshot of all tasks into out.
The census is all-or-nothing: FreeRTOS's uxTaskGetSystemState fills the array only when it can hold every live task, and otherwise writes nothing and reports zero. A return of 0 with a non-zero taskCount() therefore means the census was truncated, not that the system has no tasks — callers must report that case distinctly instead of printing an empty table.
- Parameters
-
Name Meaning out Destination array of TaskSnapshot records. capacity Maximum number of entries to write; effectively clamped to :: kMaxTaskSnapshots. totalRuntime Set to the total accumulated runtime counter; left at 0 when the census is truncated.
- Returns
- Number of entries written; 0 when the live task count exceeds the smaller of
capacityand ::kMaxTaskSnapshots.
- See also
- taskCount
taskSnapshots() [2/2] #
Capture task snapshots into a fixed-size array (capacity deduced).
- Template Parameters
-
Name Meaning Capacity Compile-time array capacity deduced from out; use ::kMaxTaskSnapshots so the array can hold a full census.
- Parameters
-
Name Meaning out Fixed-size array of TaskSnapshot records. totalRuntime Set to the total accumulated runtime counter.
- Returns
- Number of entries written; 0 when the census was truncated.
taskSubscribeResultName() #
Return a human-readable name for a subscribe result.
- Parameters
-
Name Meaning result Enum value to name.
- Returns
- Pointer to a static string.
taskWdtConfigured() #
Whether the task watchdog (TWDT) is compiled in and auto-initialized.
Reflects the CONFIG_ sdkconfig option: true when the bootloader starts the TWDT automatically. A read-only build-configuration query with no side effects.
- Return values
-
Value Meaning true Task watchdog is configured. false Task watchdog is disabled, or the native build.
tickBaseCycles() #
Cycles the tick source counts per tick.
The readback that makes syncTickBase observable: on a CPU-derived tick this and the core frequency have to move together, and the debug console's clock snapshot prints them side by side — with the value they are required to agree on — so a board can be checked rather than assumed.
- Returns
- Cycles per tick, or ::
kTickBaseCyclesUnknown where the tick is not CPU-derived and the count is therefore not a cycle count at all.
tickBaseCyclesFor() #
Cycles one tick lasts at a core frequency.
Integer division, matching the tick interrupt: the comparator is advanced by a whole number of cycles, so a tick rate that does not divide the frequency exactly leaves the tick marginally short rather than accumulating a fraction. Every combination the boards use divides exactly — 80, 160 and 240 MHz against a 1 kHz tick give 80 000, 160 000 and 240 000 cycles.
- Parameters
-
Name Direction Meaning cpuMhz in Core frequency in MHz. tickRateHz in Tick rate in Hz ( configTICK_on target).RATE_ HZ
- Returns
- Cycles per tick, or ::
kTickBaseCyclesUnknown when either argument is zero or cpuMhzexceeds ::kMaxConvertibleCpuMhz.
tickCount() #
Return the current absolute tick timestamp.
- Returns
- Current TickCount value from xTaskGetTickCount().
tickRateHz() #
Ticks the kernel counts in one second.
- Returns
CONFIG_, the rate every tick-derived duration in this firmware is expressed against.FREERTOS_ HZ
ticksFromMs() #
Convert a millisecond duration to RTOS ticks.
- Parameters
-
Name Direction Meaning ms in Duration in milliseconds.
- Returns
- Corresponding
Ticksvalue.
waitForever() #
Return an infinite-wait duration.
- Returns
Tickswith sentinel value that causes the blocking call to wait forever (until an item becomes available or the task is deleted).
waitNotification() #
Block the calling task until a notification arrives.
- Parameters
-
Name Meaning clearOnEntry Bits to clear in the notification value on entry. clearOnExit Bits to clear in the notification value on exit. value Set to the notification value when not nullptr. waitTicks Maximum time to block.
- Return values
-
Value Meaning true A notification was received before waitTickselapsed.false Timeout elapsed without a notification.
yield() #
Hand the core to another ready task of the caller's priority, if one waits.
A task that keeps its core busy at a priority it shares with others (a load generator at kMinAppPriority, the loop task's own) calls this between stretches of work, so a task of its priority that became ready runs within one stretch rather than at the next tick's time slice. Returns at once when no such task is ready. It never lets a lower-priority task run: the core's idle task gets a turn only from a block (delayMs).
Variable Documentation
kMaxConvertibleCpuMhz #
Highest core frequency whose cycles-per-second still fits in a uint32_t. The top frequency of the boards is 240 MHz, so the bound is never approached; it exists so the multiplication cannot wrap for an argument nobody checked.
kMaxTaskSnapshots #
Capacity of one task census: the largest snapshot this facade can take.
FreeRTOS fills a census array all-or-nothing, so this bound is shared by the facade's kernel-side scratch array and by every caller's destination array — declare caller arrays as TaskSnapshot[kMaxTaskSnapshots] so the two can never drift apart. Sized above the worst-case live task count (radio hosts, LittleFS, crypto/TOTP workers, logger, timers, idle tasks) with headroom.
kTickBaseCyclesUnknown #
Reported where the tick is not counted in CPU cycles at all, and returned by tickBaseCyclesFor for an argument pair it cannot convert. Zero cycles per tick is not a frequency any caller could mean, so it is unambiguous.