Skip to main content

Crate rusty_rtos_port_cortex_m

Crate rusty_rtos_port_cortex_m 

Source
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:

FreeRTOShere
portENTER_CRITICAL / portEXIT_CRITICALCortexMPort::enter_critical / CortexMPort::exit_critical
portYIELD()CortexMPort::yield_now — sets PendSV pending
xPortSysTickHandlertick
pxPortInitialiseStackinit_stack
xPortPendSVHandlerthe 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§

CortexMPort
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 PendSV calls to pick the next task.
start_tick
Start the tick at reload + 1 processor cycles, and enable it.
stop_tick
Stop the tick.
suppress_ticks_and_sleep
Off ARM there is no SysTick to reprogram and no wfi to wait on, so the only honest answer is to decline. See the ARM definition for the contract.
tick
What a SysTick handler should call: count the tick and, if the scheduler wants a switch, pend one.