@@ -52,7 +52,7 @@ use filter::{
52
52
StandardFilterSlot , EXTENDED_FILTER_MAX , STANDARD_FILTER_MAX ,
53
53
} ;
54
54
use frame:: MergeTxFrameHeader ;
55
- use frame:: { RxFrameInfo , TxFrameHeader } ;
55
+ use frame:: { FrameFormat , RxFrameInfo , TxFrameHeader } ;
56
56
use id:: { Id , IdReg } ;
57
57
use interrupt:: { Interrupt , InterruptLine , Interrupts } ;
58
58
@@ -1140,6 +1140,36 @@ where
1140
1140
// Safety: We have a `&mut self` and have unique access to the peripheral.
1141
1141
unsafe { Rx :: < I , M , Fifo1 > :: conjure ( ) . receive ( buffer) }
1142
1142
}
1143
+
1144
+ /// Returns a received Classic CAN frame of a given type from FIFO_0 if available.
1145
+ ///
1146
+ /// # Panics
1147
+ ///
1148
+ /// Panics if an `CAN-FD` frame is received, as embedded_can::Frame has no FD support.
1149
+ #[ cfg( feature = "embedded-can-04" ) ]
1150
+ #[ inline]
1151
+ pub fn receive0_frame < F > ( & mut self ) -> nb:: Result < ReceiveOverrun < F > , Infallible >
1152
+ where
1153
+ F : embedded_can:: Frame ,
1154
+ {
1155
+ // Safety: We have a `&mut self` and have unique access to the peripheral.
1156
+ unsafe { Rx :: < I , M , Fifo0 > :: conjure ( ) . receive_frame ( ) }
1157
+ }
1158
+
1159
+ /// Returns a received Classic CAN frame of a given type from FIFO_1 if available.
1160
+ ///
1161
+ /// # Panics
1162
+ ///
1163
+ /// Panics if an `CAN-FD` frame is received, as embedded_can::Frame has no FD support.
1164
+ #[ cfg( feature = "embedded-can-04" ) ]
1165
+ #[ inline]
1166
+ pub fn receive1_frame < F > ( & mut self ) -> nb:: Result < ReceiveOverrun < F > , Infallible >
1167
+ where
1168
+ F : embedded_can:: Frame ,
1169
+ {
1170
+ // Safety: We have a `&mut self` and have unique access to the peripheral.
1171
+ unsafe { Rx :: < I , M , Fifo1 > :: conjure ( ) . receive_frame ( ) }
1172
+ }
1143
1173
}
1144
1174
1145
1175
/// FdCanControl Struct
@@ -1567,8 +1597,6 @@ where
1567
1597
1568
1598
/// Returns a received frame if available.
1569
1599
///
1570
- /// Returns `Err` when a frame was lost due to buffer overrun.
1571
- ///
1572
1600
/// # Panics
1573
1601
///
1574
1602
/// Panics if `buffer` is smaller than the header length.
@@ -1607,6 +1635,33 @@ where
1607
1635
}
1608
1636
}
1609
1637
1638
+ /// Returns a received Classic CAN frame of a given type if available.
1639
+ ///
1640
+ /// # Panics
1641
+ ///
1642
+ /// Panics if an `CAN-FD` frame is received, as embedded_can::Frame has no FD support.
1643
+ #[ cfg( feature = "embedded-can-04" ) ]
1644
+ pub fn receive_frame < F > ( mut self ) -> nb:: Result < ReceiveOverrun < F > , Infallible >
1645
+ where
1646
+ F : embedded_can:: Frame ,
1647
+ {
1648
+ let mut buffer = [ 0_u8 ; 8 ] ;
1649
+ let overrun = self . receive ( & mut buffer) ?;
1650
+ let info = overrun. unwrap ( ) ;
1651
+ if info. frame_format != FrameFormat :: Standard {
1652
+ panic ! ( "Received CAN-FD frame" ) ;
1653
+ }
1654
+ let frame = if info. rtr {
1655
+ F :: new_remote ( info. id , info. len as usize )
1656
+ } else {
1657
+ F :: new ( info. id , & buffer[ ..info. len as usize ] )
1658
+ } . unwrap ( ) ;
1659
+ match overrun {
1660
+ ReceiveOverrun :: NoOverrun ( _) => Ok ( ReceiveOverrun :: NoOverrun ( frame) ) ,
1661
+ ReceiveOverrun :: Overrun ( _) => Ok ( ReceiveOverrun :: Overrun ( frame) ) ,
1662
+ }
1663
+ }
1664
+
1610
1665
#[ inline]
1611
1666
fn registers ( & self ) -> & RegisterBlock {
1612
1667
unsafe { & * I :: REGISTERS }
0 commit comments