Skip to main content

rrkernel

Attribute Macro rrkernel 

Source
#[rrkernel]
Expand description

Turn a cortex-m-rt main into the kernel’s task 0.

ⓘ
#![no_std]
#![no_main]

use rrkernel::{scheduler, thread, Slice};

const CORE_HZ: u32 = 8_000_000;

#[rrkernel]
#[cortex_m_rt::entry]           // keep the ecosystem's entry point
fn main() -> ! {
    // optional, one line: where a panic or a fault should be reported
    rrkernel::log_with(|a| { /* e.g. rtt_target::rprintln!("{}", a) */ });

    // the kernel, configured once. No `Result` to ignore: it either starts or says
    // why through the log above and then parks.
    rrkernel::configure(CORE_HZ, Slice::Millis(1), 1024);

    thread::spawn(worker);
    loop { scheduler::sleep_ticks(1000); }
}

fn worker() { /* ... */ }

What it expands to:

  • the function itself, with its attributes preserved, its signature forced to -> ! (the body is followed by the exit path, so it cannot return);
  • rrkernel::app_support::exit_main() after the body: main is task 0, so returning unlinks it and switches away for good, exactly like any other task;
  • a strong HardFault, a strong DefaultHandler and a #[panic_handler] that report through the log_with sink before parking — so a fault can never look like a hang, and the application needs no panic-halt.

Apply it once per program, above #[cortex_m_rt::entry].