Expand description
Zephyr application support for Rust
This crates provides the core functionality for applications written in Rust that run on top of Zephyr. The goal is to bridge the two worlds. The functionality provided here shouldn’t be too distant from how Zephyr does things. But, it should be “rusty” enough that Rust developers feel comfortable using it.
Some functionality:
time
: The time module provides aInstant
andDuration
type that are similar to those instd
, but are tailored for embedded systems. These are bridged through traits, so that most API calls that offer a timeout will accept either anInstant
or aDuration
.sync
: This crate provides various synchronization primitives that can be used to coordinate between threads. These includesync::atomic
: Provides the same functionality asstd::sync::atomic
, but on targets with limited synchronization primtives, re-exports features from the ‘portable-atomic’ crate, which can emulate atomics using critical sections.sync::channel
: Channel based synchronization built around thek_queue
channels provided by Zephyr. This provides bothalloc
-based unbounded channels, and bounded channels that pre-allocate.sync::Mutex
/sync::Condvar
:std
-style Mutexes and condition variables, where the Mutex protects some piece of data using Rust’s features.sync::SpinMutex
: A Mutex that protects a piece of data, but does so using a spinlock. This is useful where data needs to be used exclusively, but without other types of synchronization.sync::Arc
: Atomic reference counted pointers. Mostly likestd::sync::Arc
but supports all targets that support Rust on Zephyr.
sys
: More direct interfaces to Zephyr’s primitives. Most of the operations insync
are built on these. These interfaces are ‘safe’, as in they can be used without theunsafe
keyword, but the interfaces insync
are much more useful from Rust programs. Although most things here won\t typically be needed, two standout:sys::thread
: A fairly direct, but safe, interface to create Zephyr threads. At this point, this is the primary way to create threads in Rust code (see alsowork
which supports multiple contexts using Zephyr’s work queues.sys::sync::Semaphore
: The primitive Semaphore type from Zephyr. This is the one lower level operation that is still quite useful in regular code.
timer
: Rust interfaces to Zephyr timers. These timers can be used either by registering a callback, or polled or waited for for an elapsed time.work
: Zephyr work queues for Rust. Thework::WorkQueueBuilder
and resultingwork::WorkQueue
allow creation of Zephyr work queues to be used from Rust. Thework::Work
item had an action that will be invoked by the work queue, and can be manually submitted when needed.kio
: An implementation of an async executor built around triggerable work queues in Zephyr. Although there is a bit more overhead to this executor, it is compatible with many of the Zephyr synchronization types, and many of thesesys::sync::Semaphore
, andsync::channel
will provide_async
variants of most of the blocking operations. These will return aFuture
, and can be used from async code started by thespawn
function. In addition, because Zephyr’s work queues do not work well with Zephyr’s Mutex type, this is also akio::sync::Mutex
type that works with async.logging
: A logging backend for Rust on Zephyr. This will log to eitherprintk
or through Zephyr’s logging framework.
In addition to the above, the kconfig
and devicetree
provide a reflection of the kconfig
settings and device tree that were used for a specific build. As such, the documentation
provided online is not likely to be that useful, and for these, it is best to generate the
documentation for a specific build:
$ west rustdoc
Note, however, that the kconfig
module only provides Kconfig values, and doesn’t provide a
mechanmism to base conditional compilation. For that, please see the
zephyr-build crate, which provides routines that can be
called from a build.rs
file to make these settings available.
Re-exports§
pub use error::Error;
pub use error::Result;
pub use logging::set_logger;
Modules§
- Alignment
- A Rust global allocator that uses the stdlib allocator in Zephyr
- Device wrappers
- Zephyr device tree
- Support for Embassy on Rust+Zephyr
- Zephyr errors
- Zephyr Kconfig values.
- Async IO for Zephyr
- Rust logging in Zephyr
- Zephyr Kernel Objects
- Printk implementation for Rust.
- Re-export of zephyr-sys as
zephyr::raw
. - A simple TLS helping tool.
- Higher level synchronization primitives.
- Zephyr ‘sys’ module.
- Provides the portable-atomic version of
alloc::task::Wake
, which uses the compatible versionm of Arc. - Time types designed for Zephyr, inspired by
std::time
. - Zephyr timers
- Zephyr Work Queues
Macros§
- Wait loop, as a macro.
- Declare a static kernel object. This helps declaring static values of Zephyr objects.
- Re-exported for local macro use.
- Print to Zephyr’s console, without a newline.
- Print to Zephyr’s console, with a newline.