Skip to content

Commit 0a1b584

Browse files
committed
Removed weirdness in can interface
- removed weird transmit function - Allow one function to receive all kinds of can frames
1 parent 84a5b95 commit 0a1b584

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/can.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ pub trait Frame {
4444
}
4545

4646
/// A Can-FD Frame
47+
///
48+
/// A "ordinary" Can-Frame must also be representable by this type.
4749
#[cfg(feature = "unproven")]
4850
pub trait FdFrame {
4951
/// The Id type of this Frame
5052
type Id: Id;
5153

54+
/// Returns true if this frame would/has be(en) transmitted as a Can-Fd frame.
55+
/// Returns false if this frame would/has be(en) transmitted as a "ordinary" Can frame.
56+
fn is_fd_frame(&self) -> bool;
57+
5258
/// Returns the Can-ID
5359
fn id(&self) -> Self::Id;
5460

@@ -67,47 +73,39 @@ pub trait Interface {
6773
/// The Interface Error type
6874
type Error;
6975

70-
/// Read the available `Frame` with the highest priority (lowest ID).
76+
/// Return the available `Frame` with the highest priority (lowest ID).
7177
///
7278
/// NOTE: Can-FD Frames will not be received using this function.
7379
fn receive(&mut self) -> nb::Result<Self::Frame, Self::Error>;
7480

7581
/// Put a `Frame` in the transmit buffer (or a free mailbox).
7682
///
7783
/// If the buffer is full, this function will try to replace a lower priority `Frame`
78-
/// and return it.
84+
/// and return it. This is to avoid the priority inversion problem.
7985
fn transmit(&mut self, frame: &Self::Frame) -> nb::Result<Option<Self::Frame>, Self::Error>;
8086

81-
/// Put a `Frame` in the transmit buffer (or a free mailbox).
82-
///
83-
/// A high priority `Frame` is prone to being blocked when this function is used.
84-
fn transmit_without_priority(&mut self, frame: &Self::Frame) -> nb::Result<(), Self::Error>;
87+
/// Returns true if a call to `transmit(frame)` (and if the interface supports Can-FD)
88+
/// `transmit_fd(fd_frame)` would return a `Frame` or `WouldBlock`.
89+
fn transmit_buffer_full(&self) -> bool;
8590

8691
}
8792

88-
/// A CAN-FD interface
93+
/// A CAN interface also supporting Can-FD
8994
#[cfg(feature = "unproven")]
90-
pub trait FdInterface {
95+
pub trait FdInterface: Interface {
9196
/// The Can Frame this Interface operates on
92-
type Frame: FdFrame;
93-
94-
/// The Interface Error type
95-
type Error;
97+
type FdFrame: FdFrame;
9698

9799
/// Read the available `FdFrame` with the highest priority (lowest ID).
98-
///
99-
/// NOTE: ordinary Can Frames will not be received using this function.
100-
fn receive_fd(&mut self) -> nb::Result<Self::Frame, Self::Error>;
100+
fn receive(&mut self) -> nb::Result<Self::FdFrame, Self::Error>;
101101

102102
/// Put a `FdFrame` in the transmit buffer (or a free mailbox).
103103
///
104104
/// If the buffer is full, this function will try to replace a lower priority `FdFrame`
105-
/// and return it.
106-
fn transmit_fd(&mut self, frame: &Self::Frame) -> nb::Result<Option<Self::Frame>, Self::Error>;
107-
108-
/// Put a `FdFrame` in the transmit buffer (or a free mailbox).
109-
///
110-
/// A high priority `FdFrame` is prone to being blocked when this function is used.
111-
fn transmit_fd_without_priority(&mut self, frame: &Self::Frame) -> nb::Result<(), Self::Error>;
105+
/// and return it. This is to avoid the priority inversion problem.
106+
fn transmit(&mut self, frame: &Self::FdFrame) -> nb::Result<Option<Self::FdFrame>, Self::Error>;
112107

108+
/// Returns true if a call to `transmit(frame)` or `transmit_fd(fd_frame)`
109+
/// would return a `FdFrame` or `WouldBlock`.
110+
fn transmit_buffer_full(&self) -> bool;
113111
}

0 commit comments

Comments
 (0)