Skip to content

Commit 6c6fd5e

Browse files
committed
Implement a CAN FD interface
1 parent cd352c0 commit 6c6fd5e

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

embedded-can/src/blocking.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ pub trait Can {
1515
/// Blocks until a frame was received or an error occurred.
1616
fn receive(&mut self) -> Result<Self::Frame, Self::Error>;
1717
}
18+
19+
/// A blocking CAN FD interface that is able to transmit and receive fd frames.
20+
pub trait CanFD {
21+
/// Associated frame type.
22+
type FDFrame: crate::FDFrame;
23+
24+
/// Associated error type.
25+
type Error: crate::Error;
26+
27+
/// Puts a fd frame in the transmit buffer. Blocks until space is available in
28+
/// the transmit buffer.
29+
fn transmit_fd(&mut self, frame: &Self::FDFrame) -> Result<(), Self::Error>;
30+
31+
/// Blocks until a fd frame was received or an error occurred.
32+
fn receive_fd(&mut self) -> Result<Self::FDFrame, Self::Error>;
33+
}

embedded-can/src/nb.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,33 @@ pub trait Can {
2626
/// Returns a received frame if available.
2727
fn receive(&mut self) -> nb::Result<Self::Frame, Self::Error>;
2828
}
29+
30+
/// A CAN FD interface that is able to transmit and receive frames.
31+
pub trait CanFD {
32+
/// Associated frame type.
33+
type FDFrame: crate::FDFrame;
34+
35+
/// Associated error type.
36+
type Error: crate::Error;
37+
38+
/// Puts a fd frame in the transmit buffer to be sent on the bus.
39+
///
40+
/// If the transmit buffer is full, this function will try to replace a pending
41+
/// lower priority frame and return the frame that was replaced.
42+
/// Returns `Err(WouldBlock)` if the transmit buffer is full and no frame can be
43+
/// replaced.
44+
///
45+
/// # Notes for implementers
46+
///
47+
/// * Frames of equal identifier shall be transmitted in FIFO fashion when more
48+
/// than one transmit buffer is available.
49+
/// * When replacing pending frames make sure the frame is not in the process of
50+
/// being send to the bus.
51+
fn transmit_fd(
52+
&mut self,
53+
frame: &Self::FDFrame,
54+
) -> nb::Result<Option<Self::FDFrame>, Self::Error>;
55+
56+
/// Returns a received frame if available.
57+
fn receive_fd(&mut self) -> nb::Result<Self::FDFrame, Self::Error>;
58+
}

0 commit comments

Comments
 (0)