stm32: can: fd: introduce BusErrorMode with docs and Properties getter
This commit is contained in:
parent
6ca7e0feab
commit
521c132e34
2 changed files with 29 additions and 3 deletions
|
@ -29,6 +29,24 @@ pub enum BusError {
|
||||||
BusWarning,
|
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
|
/// Frame Create Errors
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
|
|
|
@ -859,9 +859,17 @@ impl<T: Instance> Properties<T> {
|
||||||
T::registers().regs.ecr().read().tec()
|
T::registers().regs.ecr().read().tec()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current Bus-Off state
|
/// Get the current bus error mode
|
||||||
pub fn bus_off(&self) -> bool {
|
pub fn bus_error_mode(&self) -> BusErrorMode {
|
||||||
T::registers().regs.psr().read().bo()
|
// 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…
Add table
Add a link
Reference in a new issue