Type Definition shared_bus::BusManagerAtomicCheck [−][src]
type BusManagerAtomicCheck<T> = BusManager<AtomicCheckMutex<T>>;
A bus manager for safely sharing the bus when using concurrency frameworks (such as RTIC).
This manager relies on RTIC or some other concurrency framework to manage resource contention automatically. As a redundancy, this manager uses an atomic boolean to check whether or not a resource is currently in use. This is purely used as a fail-safe against misuse.
Warning
If devices on the same shared bus are not treated as a singular resource, it is possible that pre-emption may occur. In this case, the manger will panic to prevent the race condition.
Usage
In order to use this manager with a concurrency framework such as RTIC, all devices on the shared bus must be stored in the same logic resource. The concurrency framework will require a resource lock if pre-emption is possible.
In order to use this with RTIC (as an example), all devices on the shared bus must be stored in
a singular resource. Additionally, a manager with 'static
lifetime is needed which can be
created using the shared_bus::new_atomic_check!()
macro. It should
roughly look like this (there is also a full example available):
struct Device<T> { bus: T }; struct OtherDevice<T> { bus: T }; // the HAL I2C driver type type I2cType = (); type Proxy = shared_bus::I2cProxy<'static, shared_bus::AtomicCheckMutex<I2cType>>; struct SharedBusDevices { device: Device<Proxy>, other_device: OtherDevice<Proxy>, } struct Resources { shared_bus_devices: SharedBusDevices, } // in the RTIC init function fn init() -> Resources { // init the bus like usual let i2c: I2cType = (); let bus_manager: &'static _ = shared_bus::new_atomic_check!(I2cType = i2c).unwrap(); let devices = SharedBusDevices { device: Device { bus: bus_manager.acquire_i2c() }, other_device: OtherDevice { bus: bus_manager.acquire_i2c() }, }; Resources { shared_bus_devices: devices, } }
This type is only available with the cortex-m
feature (but this may change in the future!).