stm32: can: fd: introduce BusErrorMode with docs and Properties getter

This commit is contained in:
Torin Cooper-Bennun 2024-04-23 12:33:27 +01:00
parent 6ca7e0feab
commit 521c132e34
2 changed files with 29 additions and 3 deletions

View File

@ -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))]

View File

@ -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,
}
}
}