shared-bus-rtic
Provides macros and type definitions for using a shared peripheral bus in an RTIC application
:warning: Deprecation Notice :warning:
With the release of embedded-hal
v1.0, this crate is no longer necessary. Instead, users should
migrate to using embedded-hal
v1.0 traits alongside the embedded-hal-bus
.
Description
Note that all of the drivers that use the same underlying bus must be stored within a single
resource (e.g. as one larger struct
) within the RTIC resources. This ensures that RTIC will
prevent one driver from interrupting another while they are using the same underlying bus. The crate
provides a detection mechanism that will panic if the shared bus is used in multiple task priorities
without proper locking.
Features
This crate is compatible with thumbv6 architectures. To enable support for thumbv6
devices, enable the thumbv6
feature in your Cargo.toml
:
[dependencies.shared-bus-rtic]
features = ["thumbv6"]
Usage Example
use SharedBus;
// ...
// Replace this type with the type of your bus (e.g. hal::i2c::I2c<...>).
type BusType = ;
Valid Example
// ...
In the above example, it can be seen that both devices on the bus are stored as a single resource
(in a shared struct
). Because of this, RTIC properly locks the resource when either the high or
low priority task is using the bus.
Unsound Example
The following example is unsound and should not be repeated. When a resource is interrupted, the crate will panic.
In the above incorrect example, RTIC may interrupt the low priority task to complete the high
priority task. However, the low priority task may be using the shared bus. In this case, the
communication may be corrupted by multiple devices using the bus at the same time. To detect this,
shared-bus-rtic
will detect any bus contention and panic if the bus is already in use.