Expand description
rusty_rtos_kernel-core — the FreeRTOS scheduler remade in safe Rust.
This crate is tasks.c and queue.c as a state machine over indices:
the ready lists, the two delayed lists, the pending-ready and suspended
lists, the tick, the context switch, and the queue with its two event
lists. It owns no CPU (that is rusty_rtos_core::port::Port), no
memory (that is Heap), and no stack — which is the point.
§Why there is no context switch here
A context switch is a stack swap, and a stack swap is unsafe. The
family’s law is that unsafe lives only in rusty_rtos_port-<arch>
(mission plan §2.1), so this crate never touches one. What it does
instead is decide which task should run: Kernel::switch_context
moves current and fires the same TASK_SWITCHED_OUT / _IN pair the
C kernel fires. On silicon the port acts on that decision with its
fenced assembly; on the sim the runner acts on it by calling the next
task’s step function. Both see the same decisions in the same order,
which is what the conformance diff checks.
§Geometry is const, not heap
FreeRTOS allocates TCBs and queue storage from a heap. Kairos puts them in arenas sized at compile time, so the kernel has no allocator at all and a firmware’s RAM is a number you can read off the type:
type K = Kernel<PosixDemoConfig, SimPort, SimTrace,
16, // TASKS
{ list_slots_for(8, 0, LISTS) }, // items + markers, rounded
{ lists_for(7, 8) }, // ready + 4 + two per queue
8, // QUEUES
64>; // shared queue slotsThe four helpers below compute the derived numbers, and
Kernel::new refuses a geometry that does not add up rather than
indexing out of bounds later.
forbid(unsafe). no_std (+ alloc). Every arithmetic operation is
checked, wrapping or saturating by name; every slice access is a get.
Re-exports§
pub use kernel::Kernel;pub use kernel::MAX_CORES;pub use kernel::Stall;pub use kernel::StartHandles;pub use kernel::TaskState;pub use name::NAME_CAPACITY;pub use name::Name;pub use queue::Blocked;pub use queue::Kind as QueueKind;pub use queue::Position;pub use queue::Ready;pub use queue::Wait;
Modules§
- events
- Event groups:
event_groups.c. - kernel
- The scheduler:
tasks.candqueue.cas a state machine over indices. - name
- A task’s name, stored the way the C kernel stores it.
- prelude
- The names a scenario or a port wants in scope.
- queue
queue.c: the queue, and the semaphore and mutex built on it.- stream
stream_buffer.c: a byte ring one task writes and another reads.- system
- The static face: declare the system, and the geometry is the declaration.
- timer
timers.c: software timers and the daemon task that runs them.- typed
- The Rust face: the same kernel, with the invariants in the type system.
Macros§
- system
- Declare a system: its tasks, its queues, and the geometry they imply.
Constants§
- OVERHEAD_
LISTS - The number of fixed lists that are not a ready list: the two delayed lists, pending-ready and suspended, and the two timer lists.
- OVERHEAD_
TASKS - The tasks a kernel creates for itself whatever the application asks
for:
prvIdleTaskand the timer daemon. A system that declaresntasks needs room forn + OVERHEAD_TASKS. - VERSION
- Crate version, for manifests and logs.
Traits§
- Tick
Hook vApplicationTickHook, as something that can actually reach the kernel.
Functions§
- items_
for - List items a kernel needs for
taskstasks: a state item and an event item each, exactly the twoListItem_ts in a CTCB_t. - list_
slots_ for - Slots the kernel’s list arena needs.
- lists_
for - Lists a kernel needs: one ready list per priority, the two delayed
lists, the pending-ready list and the suspended list, plus the two
event lists (
xTasksWaitingToSend,xTasksWaitingToReceive) of every queue and the one (xTasksWaitingForBits) of every event group.