Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to check if bus is dominant #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mcan/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Tagging in git follows a pattern: `mcan/<version>`.

## [Unreleased]
- Add method to check if bus is dominant (#51)

## [0.5.0] - 2024-03-04

Expand Down
11 changes: 9 additions & 2 deletions mcan/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,18 @@ 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> {
impl<Id: mcan_core::CanId, D: mcan_core::Dependencies<Id>> Aux<'_, Id, D> {
fn configuration_mode(&self) {
self.reg.configuration_mode()
}
}

impl<'a, Id: mcan_core::CanId, D: mcan_core::Dependencies<Id>> DynAux for Aux<'a, Id, D> {
impl<Id: mcan_core::CanId, D: mcan_core::Dependencies<Id>> DynAux for Aux<'_, Id, D> {
type Id = Id;
type Deps = 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
1 change: 1 addition & 0 deletions mcan/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct TxConfig {
/// - the time quantum `t_q`, which is a fraction of the peripheral clock
/// - the number of time quanta in a bit time, determined by `phase_seg_1` and
/// `phase_seg_2`
///
/// The configurable ranges of the parameters depend on which timing is changed.
///
/// This struct expects *real* values, extra subtractions and additions expected
Expand Down
2 changes: 1 addition & 1 deletion mcan/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl<Id: mcan_core::CanId, State> OwnedInterruptSet<Id, State> {
///
/// # Safety
/// - Each interrupt of a CAN peripheral can only be contained in one
/// `OwnedInterruptSet`, otherwise registers will be mutably aliased.
/// `OwnedInterruptSet`, otherwise registers will be mutably aliased.
/// - The reserved bits must not be included.
/// - `State` type parameter must match the state in runtime.
unsafe fn new(interrupts: InterruptSet) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion mcan/src/message/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub struct MessageBuilder<'a> {
pub store_tx_event: Option<u8>,
}

impl<'a> MessageBuilder<'a> {
impl MessageBuilder<'_> {
/// Create the message in the format required by the peripheral.
pub fn build<const N: usize>(self) -> Result<Message<N>, TooMuchData> {
let mut data = [0; N];
Expand Down
6 changes: 6 additions & 0 deletions mcan/src/messageram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ impl<C: Capacities> SharedMemory<C> {
eligible_message_ram_start <= start && end_exclusive - eligible_message_ram_start <= 1 << 16
}
}

impl<C: Capacities> Default for SharedMemory<C> {
fn default() -> Self {
Self::new()
}
}
6 changes: 2 additions & 4 deletions mcan/src/rx_dedicated_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ impl<'a, P: mcan_core::CanId, M: rx::AnyMessage> RxDedicatedBuffer<'a, P, M> {
}
}

impl<'a, P: mcan_core::CanId, M: rx::AnyMessage> DynRxDedicatedBuffer
for RxDedicatedBuffer<'a, P, M>
{
impl<P: mcan_core::CanId, M: rx::AnyMessage> DynRxDedicatedBuffer for RxDedicatedBuffer<'_, P, M> {
type Id = P;
type Message = M;

Expand All @@ -138,7 +136,7 @@ impl<'a, P: mcan_core::CanId, M: rx::AnyMessage> DynRxDedicatedBuffer
}
}

impl<'a, P: mcan_core::CanId, M: rx::AnyMessage> Iterator for RxDedicatedBuffer<'a, P, M> {
impl<P: mcan_core::CanId, M: rx::AnyMessage> Iterator for RxDedicatedBuffer<'_, P, M> {
type Item = M;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
8 changes: 4 additions & 4 deletions mcan/src/rx_fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ pub trait GetRxFifoRegs {
unsafe fn registers(&self) -> &reg::RxFifoRegs;
}

impl<'a, P: mcan_core::CanId, M: rx::AnyMessage> GetRxFifoRegs for RxFifo<'a, Fifo0, P, M> {
impl<P: mcan_core::CanId, M: rx::AnyMessage> GetRxFifoRegs for RxFifo<'_, Fifo0, P, M> {
unsafe fn registers(&self) -> &reg::RxFifoRegs {
&(*P::register_block()).rxf0
}
}
impl<'a, P: mcan_core::CanId, M: rx::AnyMessage> GetRxFifoRegs for RxFifo<'a, Fifo1, P, M> {
impl<P: mcan_core::CanId, M: rx::AnyMessage> GetRxFifoRegs for RxFifo<'_, Fifo1, P, M> {
unsafe fn registers(&self) -> &reg::RxFifoRegs {
&(*P::register_block()).rxf1
}
Expand Down Expand Up @@ -90,7 +90,7 @@ where
}
}

impl<'a, F, P: mcan_core::CanId, M: rx::AnyMessage> DynRxFifo for RxFifo<'a, F, P, M>
impl<F, P: mcan_core::CanId, M: rx::AnyMessage> DynRxFifo for RxFifo<'_, F, P, M>
where
Self: GetRxFifoRegs,
{
Expand Down Expand Up @@ -128,7 +128,7 @@ where
}
}

impl<'a, F, P: mcan_core::CanId, M: rx::AnyMessage> Iterator for RxFifo<'a, F, P, M>
impl<F, P: mcan_core::CanId, M: rx::AnyMessage> Iterator for RxFifo<'_, F, P, M>
where
Self: GetRxFifoRegs,
{
Expand Down
2 changes: 1 addition & 1 deletion mcan/src/tx_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl<'a, P: mcan_core::CanId, C: Capacities> Tx<'a, P, C> {
}
}

impl<'a, P: mcan_core::CanId, C: Capacities> DynTx for Tx<'a, P, C> {
impl<P: mcan_core::CanId, C: Capacities> DynTx for Tx<'_, P, C> {
type Id = P;
type Message = C::TxMessage;

Expand Down
2 changes: 1 addition & 1 deletion mcan/src/tx_event_fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a, P: mcan_core::CanId> TxEventFifo<'a, P> {
}
}

impl<'a, P: mcan_core::CanId> DynTxEventFifo for TxEventFifo<'a, P> {
impl<P: mcan_core::CanId> DynTxEventFifo for TxEventFifo<'_, P> {
type Id = P;

fn len(&self) -> usize {
Expand Down
Loading