Kleidos API Search

In development. It changes without notice.

Topic

Main Loop & Hooks

The task that runs the firmware, and the hooks through which code calls a module above it without knowing it.

  • kleidos::platform::startMainLoop() starts the one task of the application, on core 1.
  • A hook lets a loop that waits keep the serial console of a debug build answering.
  • Another lets a wait on a worker paint meanwhile, on the task that waits.
  • Switches name the ways an unlock and a write can be made faster, so that one can be measured without another.
See also
Entry Point & State Dispatch, Platform Abstraction

Files

file src/platform/hooks/app_loop.cpp
app_main() helper that spawns the setup()/loop() task.
file src/platform/hooks/app_loop.h
Shared app_main() helper that runs the firmware setup()/loop() lifecycle.
file src/platform/hooks/debug_pump.cpp
Holds the registered console pump, the console's call on the sleep path and the knobs it set for the next deep sleep.
file src/platform/hooks/debug_pump.h
Lets the code below the serial debug console reach it without naming it.
file src/platform/hooks/perf_switches.h
The build switches that select the unlock and write performance policies, readable from any layer.
file src/platform/hooks/wait_pump.cpp
Holds the pump a task installed for its wait, and runs it for that task only.
file src/platform/hooks/wait_pump.h
Lets a task blocked on another task's work keep painting, without the code that waits naming what it paints.

Classes

struct kleidos::platform::DebugSleepKnobs
The parks a console command may ask the next deep sleep to skip, for an A/B against the production sleep. Value-initialized, every member is the production behavior. More about kleidos::platform::DebugSleepKnobs
struct kleidos::platform::WaitPumpStep
What one pump step did, and when it wants to run again. More about kleidos::platform::WaitPumpStep
class kleidos::platform::WaitPumpScope
Install a pump for the calling task for the life of this scope. More about kleidos::platform::WaitPumpScope
struct kleidos::platform::WaitPumpTally
What the pumps of the open scopes painted, for the unlock trace. More about kleidos::platform::WaitPumpTally

Macros

#defineKLEIDOS_UNLOCK_CPU_BOOST
#defineKLEIDOS_UNLOCK_IDLE_FLOOR
#defineKLEIDOS_WRITE_CPU_BOOST
#defineKLEIDOS_UNLOCK_SEGMENTED
Read the credential list one index segment per unit (1) or in one walk (0).
#defineKLEIDOS_UNLOCK_WAIT_PUMP
#defineKLEIDOS_UNLOCK_TRACE
Log the duration of every unlock unit. Debug builds only by default.

Typedefs

usingkleidos::platform::SetupFn
One-time bring-up entry point, run once before the loop body.
usingkleidos::platform::LoopFn
Loop body, called forever after setup completes.
usingkleidos::platform::WaitPumpFn
A pump: paints a frame when one is due. ctx is the scope's context.
usingkleidos::platform::WaitTaskIdFn
The task identity a pump is owned by. On target the running task's handle.

Functions

boolkleidos::platform::startMainLoop (const SetupFn &setupFn, const LoopFn &loopFn)
Spawn the setup()/loop() task pinned to Core 1 (APP_CPU, 8704-byte stack).
voidkleidos::platform::debugPump ()
No console is compiled in, so a blocking loop has nothing to service.
voidkleidos::platform::debugBeforeSleep ()
No console is compiled in, so it holds nothing the sleep path must wait for.
DebugSleepKnobskleidos::platform::takeDebugSleepKnobs ()
No console is compiled in, so every sleep is the production one.
WaitPumpTallykleidos::platform::waitPumpTally ()
The frames painted since the innermost open scope was made.
uint32_tkleidos::platform::runWaitPump ()
Run the calling task's pump once and return how long it may sleep.
voidkleidos::platform::setWaitTaskIdProvider (WaitTaskIdFn fn)
Replace how the facade reads the running task's identity.

Variables

constexpr uint32_tkleidos::platform::kWaitIdleSliceMs
constexpr uint32_tkleidos::platform::kWaitMinSliceMs
The shortest slice a pump may ask for (ms): one scheduler tick.

Macro Definition Documentation

KLEIDOS_UNLOCK_CPU_BOOST #

#define KLEIDOS_UNLOCK_CPU_BOOST

Hold the unlock CPU boost across the transition into HOME (1) or drop it at the end of the verify callback (0).

KLEIDOS_UNLOCK_IDLE_FLOOR #

#define KLEIDOS_UNLOCK_IDLE_FLOOR

Idle the auth screen at kleidos::states::unlock::kIdleCpuMhz (1) or keep it at the 160 MHz the measured baseline used (0).

KLEIDOS_UNLOCK_WAIT_PUMP #

#define KLEIDOS_UNLOCK_WAIT_PUMP

Paint the verify wait from inside the vault dispatch's wait (1), or leave the UI task asleep there as the measured baseline did (0). See wait_pump.h.

KLEIDOS_WRITE_CPU_BOOST #

#define KLEIDOS_WRITE_CPU_BOOST

Boost the heavy vault writes — the credential save and every other write that measured over 100 ms at the base clock — to 240 MHz for the whole vault-worker round-trip (1), or leave them at the calling state's clock (0).

Function Documentation

runWaitPump() #

uint32_t kleidos::platform::runWaitPump()

Run the calling task's pump once and return how long it may sleep.

What a wait calls between slices, and once before the first.

Not re-entrant by design: a pump step that itself waits on the vault worker reaches this again from inside its own frame, and that inner call runs no pump (not even one a scope opened inside the step installed) and answers kWaitIdleSliceMs, so the inner wait sleeps as an unpumped one.

Returns
The slice to sleep in, in [kWaitMinSliceMs, kWaitIdleSliceMs]: the pump's own answer, or kWaitIdleSliceMs when the calling task installed none or is already inside a step.

setWaitTaskIdProvider() #

void kleidos::platform::setWaitTaskIdProvider(WaitTaskIdFn fn)

Replace how the facade reads the running task's identity.

For the host tests, which run every "task" on one thread.

Parameters
NameDirectionMeaning
fninThe reader, or nullptr to restore the default.

startMainLoop() #

bool kleidos::platform::startMainLoop(const SetupFn & setupFn, const LoopFn & loopFn)

Spawn the setup()/loop() task pinned to Core 1 (APP_CPU, 8704-byte stack).

Call once from app_main(). Returns after the task is created so the IDF main task can exit; the scheduler keeps running the spawned task.

Parameters
NameMeaning
setupFnOne-time bring-up, run once before the loop.
loopFnLoop body, called forever after setup completes.
Returns
True if the task was created; false on failure (already logged).
Return values
ValueMeaning
trueTask was created and is now scheduled on Core 1 (APP_CPU).
falseTask creation failed (already logged via KLEIDOS_LOG).

takeDebugSleepKnobs() #

DebugSleepKnobs kleidos::platform::takeDebugSleepKnobs()
inline

No console is compiled in, so every sleep is the production one.

Returns
Value-initialized knobs: every park runs.

waitPumpTally() #

WaitPumpTally kleidos::platform::waitPumpTally()

The frames painted since the innermost open scope was made.

A scope that closes folds its frames into the scope it nested in, so an outer scope's tally (and its trace line) counts every frame painted while it was open, an inner scope's included. Its gaps fold the same way: the outer scope's longest gap also covers the interval from its last paint before the inner scope opened to the inner scope's first paint.

Returns
The innermost open scope's tally; all zero with no scope open.

Variable Documentation

kWaitIdleSliceMs #

uint32_t kleidos::platform::kWaitIdleSliceMs
inlineconstexpr

The slice a wait sleeps in when no pump is installed (ms): the dispatch's watchdog slice.