1 | //! Non-blocking CAN API |
2 | |
3 | /// A CAN interface that is able to transmit and receive frames. |
4 | pub trait Can { |
5 | /// Associated frame type. |
6 | type Frame: crate::can::Frame; |
7 | |
8 | /// Associated error type. |
9 | type Error: crate::can::Error; |
10 | |
11 | /// Puts a frame in the transmit buffer to be sent on the bus. |
12 | /// |
13 | /// If the transmit buffer is full, this function will try to replace a pending |
14 | /// lower priority frame and return the frame that was replaced. |
15 | /// Returns `Err(WouldBlock)` if the transmit buffer is full and no frame can be |
16 | /// replaced. |
17 | /// |
18 | /// # Notes for implementers |
19 | /// |
20 | /// * Frames of equal identifier shall be transmited in FIFO fashion when more |
21 | /// than one transmit buffer is available. |
22 | /// * When replacing pending frames make sure the frame is not in the process of |
23 | /// being send to the bus. |
24 | fn transmit(&mut self, frame: &Self::Frame) -> nb::Result<Option<Self::Frame>, Self::Error>; |
25 | |
26 | /// Returns a received frame if available. |
27 | fn receive(&mut self) -> nb::Result<Self::Frame, Self::Error>; |
28 | } |
29 | |