mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +00:00
stm32: can: fd: introduce BusErrorMode with docs and Properties getter
This commit is contained in:
parent
6ca7e0feab
commit
521c132e34
@ -29,6 +29,24 @@ pub enum BusError {
|
||||
BusWarning,
|
||||
}
|
||||
|
||||
/// Bus error modes.
|
||||
///
|
||||
/// Contrary to the `BusError` enum which also includes last-seen acute protocol
|
||||
/// errors, this enum includes only the mutually exclusive bus error modes.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub enum BusErrorMode {
|
||||
/// Error active mode (default). Controller will transmit an active error
|
||||
/// frame upon protocol error.
|
||||
ErrorActive,
|
||||
/// Error passive mode. An error counter exceeded 127. Controller will
|
||||
/// transmit a passive error frame upon protocol error.
|
||||
ErrorPassive,
|
||||
/// Bus off mode. The transmit error counter exceeded 255. Controller is not
|
||||
/// participating in bus traffic.
|
||||
BusOff,
|
||||
}
|
||||
|
||||
/// Frame Create Errors
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
|
@ -859,9 +859,17 @@ impl<T: Instance> Properties<T> {
|
||||
T::registers().regs.ecr().read().tec()
|
||||
}
|
||||
|
||||
/// Get the current Bus-Off state
|
||||
pub fn bus_off(&self) -> bool {
|
||||
T::registers().regs.psr().read().bo()
|
||||
/// Get the current bus error mode
|
||||
pub fn bus_error_mode(&self) -> BusErrorMode {
|
||||
// This read will clear LEC and DLEC. This is not ideal, but protocol
|
||||
// error reporting in this driver should have a big ol' FIXME on it
|
||||
// anyway!
|
||||
let psr = T::regs().psr().read();
|
||||
match (psr.bo(), psr.ep()) {
|
||||
(false, false) => BusErrorMode::ErrorActive,
|
||||
(false, true) => BusErrorMode::ErrorPassive,
|
||||
(true, _) => BusErrorMode::BusOff,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user