From b781a1b3b471c001bb2f1eb3803953a6e83524c1 Mon Sep 17 00:00:00 2001 From: Pontus Andersson Date: Wed, 29 Jan 2025 17:22:07 +0100 Subject: [PATCH] Expose method to check if bus is dominant 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 --- mcan/src/bus.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mcan/src/bus.rs b/mcan/src/bus.rs index f366ac1..0bfc130 100644 --- a/mcan/src/bus.rs +++ b/mcan/src/bus.rs @@ -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> Aux<'a, Id, D> { @@ -242,6 +245,10 @@ impl<'a, Id: mcan_core::CanId, D: mcan_core::Dependencies> 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,