zephyr::sys

Module thread

source
Expand description

Zephyr low level threads

This is a fairly low level (but still safe) interface to Zephyr threads. This is intended to work the same way as threads are typically done on Zephyr systems, where the threads and their stacks are statically allocated, a code is called to initialize them.

In addition, there are some convenience operations available that require allocation to be available.

§Usage

Each thread needs a stack associated with it. The stack and the thread should be defined as follows:

kobj_defined! {
    static MY_THREAD: StaticThread;
    static MY_THREAD_STACK: StaticThreadStack<2048>;
}

Each of these has a init_once method that returns the single usable instance. The StaticThread takes the stack retrieved by take as its argument. This will return a ThreadStarter, where various options can be set on the thread, and then it started with one of spawn, or simple_spawn (spawn requires CONFIG_RUST_ALLOC).

Provided that CONFIG_RUST_ALLOC has been enabled (recommended): the read can be initialized as follows:

let mut thread = MY_THREAD.init_once(MY_THREAD_STACK.init_once(()).unwrap()).unwrap();
thread.set_priority(5);
let child = thread.spawn(|| move {
    // thread code...
});

Structs§

  • A single Zephyr thread.
  • The dynamic stack value, which wraps the underlying stack.

Functions§

  • Adjust the stack size for alignment. Note that, unlike the C code, we don’t include the reservation in this, as it has its own fields in the struct.

Type Aliases§