Expand description
rusty_rtos_port-cortex-m — the Kairos Cortex-M port.
rusty_rtos_port-core’s docs name this crate as the place the assembly
lives: “the first-task start and the context switch … the only crates
in the family with a fenced unsafe block.” This is that crate for
ARMv7-M (Cortex-M3, M4, M7) and ARMv8-M mainline.
§What a Cortex-M port is
Five things, and FreeRTOS’s port.c has exactly the same five:
| FreeRTOS | here |
|---|---|
portENTER_CRITICAL / portEXIT_CRITICAL | CortexMPort::enter_critical / CortexMPort::exit_critical |
portYIELD() | CortexMPort::yield_now — sets PendSV pending |
xPortSysTickHandler | tick |
pxPortInitialiseStack | init_stack |
xPortPendSVHandler | the PendSV symbol in [switch] |
§The stack belongs to the port, not the kernel
A Kairos TCB has no stack pointer, and that is deliberate: the kernel is stackless by design — a blocking call keeps its locals in the TCB rather than on a C stack, which is what lets the same kernel run the conformance corpus on a host, on a simulator and on a chip. So the task’s stack is the port’s business entirely, and this crate keeps the saved stack pointers.
The shape is FreeRTOS’s pxCurrentTCB, narrowed to the one word that
matters: CURRENT_SP_SLOT holds the address of the word that holds
the running task’s saved stack pointer. PendSV writes the outgoing
task’s SP through it, asks the installed scheduler for the next task,
and reads the incoming one back through it.
§Unsafe
The workspace denies unsafe_code; every use here is fenced with
#[expect(unsafe_code)] and a justification, and they are all of two
kinds: reading or writing a core peripheral register, and the context
switch itself. See UNSAFE.md.
Structs§
- CortexM
Port - The Cortex-M port.
Constants§
- VERSION
- Crate version, for manifests and logs.
Statics§
- CURRENT_
SP_ SLOT - The address of the word holding the running task’s saved stack pointer.
Functions§
- init_
stack ⚠ - Build a fresh task stack so that returning from an exception into it
enters
entry(arg). - pend_
switch - Request a context switch at the next opportunity: set PendSV pending.
- set_
exception_ priorities - Put PendSV and SysTick at the lowest exception priority, as the C port does, so neither ever preempts an application interrupt.
- set_
scheduler - Install the function
PendSVcalls to pick the next task. - start_
tick - Start the tick at
reload + 1processor cycles, and enable it. - stop_
tick - Stop the tick.
- suppress_
ticks_ and_ sleep - Off ARM there is no SysTick to reprogram and no
wfito wait on, so the only honest answer is to decline. See the ARM definition for the contract. - tick
- What a
SysTickhandler should call: count the tick and, if the scheduler wants a switch, pend one.