Skip to main content

system

Macro system 

Source
macro_rules! system {
    (
        $(#[$meta:meta])*
        $vis:vis mod $name:ident use $cfg:ty;
        tasks { $($task:ident : $prio:expr),* $(,)? }
        queues { $($queue:ident : $qty:ty ; $qlen:expr),* $(,)? }
    ) => { ... };
}
Expand description

Declare a system: its tasks, its queues, and the geometry they imply.

See the module docs for what the expansion contains and why.

The config is named in the header because the number of lists depends on Config::MAX_PRIORITIES, and a const may read an associated const of a concrete type — which is why this is a declaration and not a generic parameter.

§What a declaration refuses, that a hand-sized kernel cannot

Each of these is paired with the working line it is one character from, so neither can pass for the wrong reason.

A priority the config has no ready list for. In C this is a configASSERT on the bench, if configASSERT is compiled in, on the day that task first runs. Here it is a build failure:

ⓘ
rusty_rtos_kernel_core::system! {
    mod bad use Cfg;
    tasks { spinner: 4 }
    queues { }
}

The control arm — the same declaration, one priority lower, which is the highest MAX_PRIORITIES = 4 actually has:

rusty_rtos_kernel_core::system! {
    mod good use Cfg;
    tasks { spinner: 3 }
    queues { }
}

A queue told to carry what it was not declared for. The declaration named data as a queue of u16, so the field is a Queue<u16, 4> and a u32 is not a u16:

ⓘ
rusty_rtos_kernel_core::system! {
    mod app use Cfg;
    tasks { worker: 1 }
    queues { data: u16; 4 }
}
fn wrong<P, T, H>(k: &mut app::Kernel<P, T, H>, s: &mut app::System)
where
    P: rusty_rtos_core::port::Port,
    T: rusty_rtos_core::trace::Trace,
    H: rusty_rtos_kernel_core::TickHook<app::Kernel<P, T, H>>,
{
    let _ = s.data.send(k, 70_000u32, 0);
}

The control arm, one type name different:

rusty_rtos_kernel_core::system! {
    mod app use Cfg;
    tasks { worker: 1 }
    queues { data: u16; 4 }
}
fn right<P, T, H>(k: &mut app::Kernel<P, T, H>, s: &mut app::System)
where
    P: rusty_rtos_core::port::Port,
    T: rusty_rtos_core::trace::Trace,
    H: rusty_rtos_kernel_core::TickHook<app::Kernel<P, T, H>>,
{
    let _ = s.data.send(k, 7_000u16, 0);
}

And there is no third way in. A System has no public constructor but [System::build], and a Queue<T, N> has none but create, so no application can hold a handle it invented — which is what makes the symbolic-handle proofs unwritable against this face rather than merely slow.