Skip to content

Commit

Permalink
Expose method to check if bus is dominant
Browse files Browse the repository at this point in the history
Checking if the bus is dominant (i.e., the RX pin value is low) can be
particularly useful in scenarios where the transceiver is put into sleep
mode. Some transceivers (such as TCAN1043-Q1[1]) signals wake-up by
setting the RX pin (and nFAULT) to low while being in sleep mode. To
accurately tell if the transceiver requests a wake-up, the RX pin state
needs to be accessible from the application.

Fortunately MCAN provides a way to read the state of the RX pin through
its `TEST` register. Extend the `DynAux` trait with an additional method
that reads the `RX` bit from that register.

[1]: https://www.ti.com/product/TCAN1043-Q1
  • Loading branch information
epontan committed Jan 29, 2025
1 parent 5eadb2a commit b781a1b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mcan/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ pub trait DynAux {
///
/// If timestamping is disabled, its value is zero.
fn timestamp(&self) -> u16;

/// Returns `true` if the CAN bus is dominant.
fn is_dominant(&self) -> bool;
}

impl<'a, Id: mcan_core::CanId, D: mcan_core::Dependencies<Id>> Aux<'a, Id, D> {
Expand Down Expand Up @@ -242,6 +245,10 @@ impl<'a, Id: mcan_core::CanId, D: mcan_core::Dependencies<Id>> DynAux for Aux<'a
fn timestamp(&self) -> u16 {
self.reg.tscv.read().tsc().bits()
}

fn is_dominant(&self) -> bool {
self.reg.test.read().rx().bit_is_clear()
}
}

/// A CAN bus in configuration mode. Before messages can be sent and received,
Expand Down

0 comments on commit b781a1b

Please sign in to comment.