1 | // Note: This file is copied and modified from fdcan crate by Richard Meadows |
2 | |
3 | #![allow (non_camel_case_types)] |
4 | #![allow (non_snake_case)] |
5 | #![allow (unused)] |
6 | |
7 | use super::common::{BRS_R, DLC_R, ESI_R, FDF_R, ID_R, RTR_R, XTD_R}; |
8 | use super::enums::{DataLength, FilterFrameMatch, FrameFormat}; |
9 | use super::generic; |
10 | |
11 | #[doc = "Reader of register RxFifoElement" ] |
12 | pub(crate) type R = generic::R<super::RxFifoElementHeaderType, super::RxFifoElementHeader>; |
13 | // #[doc = "Writer for register ExtendedFilter"] |
14 | // pub(crate) type W = generic::W<super::RxFifoElementHeaderType, super::RxFifoElementHeader>; |
15 | #[doc = "Register ExtendedFilter `reset()`'s" ] |
16 | impl generic::ResetValue for super::RxFifoElementHeader { |
17 | type Type = super::RxFifoElementHeaderType; |
18 | #[inline (always)] |
19 | fn reset_value() -> Self::Type { |
20 | [0x0, 0x0] |
21 | } |
22 | } |
23 | |
24 | #[doc = "Reader of field `RXTS`" ] |
25 | pub(crate) type RXTS_R = generic::R<u16, u16>; |
26 | |
27 | #[doc = "Reader of field `FIDX`" ] |
28 | pub(crate) type FIDX_R = generic::R<u8, u8>; |
29 | |
30 | pub(crate) struct _ANMF; |
31 | #[doc = "Reader of field `ANMF`" ] |
32 | pub(crate) type ANMF_R = generic::R<bool, _ANMF>; |
33 | impl ANMF_R { |
34 | pub fn is_matching_frame(&self) -> bool { |
35 | self.bit_is_clear() |
36 | } |
37 | } |
38 | |
39 | impl R { |
40 | #[doc = "Byte 0 - Bits 0:28 - ID" ] |
41 | #[inline (always)] |
42 | pub fn id(&self) -> ID_R { |
43 | ID_R::new(((self.bits[0]) & 0x1FFFFFFF) as u32) |
44 | } |
45 | #[doc = "Byte 0 - Bit 29 - RTR" ] |
46 | #[inline (always)] |
47 | pub fn rtr(&self) -> RTR_R { |
48 | RTR_R::new(((self.bits[0] >> 29) & 0x01) != 0) |
49 | } |
50 | #[doc = "Byte 0 - Bit 30 - XTD" ] |
51 | #[inline (always)] |
52 | pub fn xtd(&self) -> XTD_R { |
53 | XTD_R::new(((self.bits[0] >> 30) & 0x01) != 0) |
54 | } |
55 | #[doc = "Byte 0 - Bit 30 - ESI" ] |
56 | #[inline (always)] |
57 | pub fn esi(&self) -> ESI_R { |
58 | ESI_R::new(((self.bits[0] >> 31) & 0x01) != 0) |
59 | } |
60 | #[doc = "Byte 1 - Bits 0:15 - RXTS" ] |
61 | #[inline (always)] |
62 | pub fn txts(&self) -> RXTS_R { |
63 | RXTS_R::new(((self.bits[1]) & 0xFFFF) as u16) |
64 | } |
65 | #[doc = "Byte 1 - Bits 16:19 - DLC" ] |
66 | #[inline (always)] |
67 | pub fn dlc(&self) -> DLC_R { |
68 | DLC_R::new(((self.bits[1] >> 16) & 0x0F) as u8) |
69 | } |
70 | #[doc = "Byte 1 - Bits 20 - BRS" ] |
71 | #[inline (always)] |
72 | pub fn brs(&self) -> BRS_R { |
73 | BRS_R::new(((self.bits[1] >> 20) & 0x01) != 0) |
74 | } |
75 | #[doc = "Byte 1 - Bits 20 - FDF" ] |
76 | #[inline (always)] |
77 | pub fn fdf(&self) -> FDF_R { |
78 | FDF_R::new(((self.bits[1] >> 21) & 0x01) != 0) |
79 | } |
80 | #[doc = "Byte 1 - Bits 24:30 - FIDX" ] |
81 | #[inline (always)] |
82 | pub fn fidx(&self) -> FIDX_R { |
83 | FIDX_R::new(((self.bits[1] >> 24) & 0xFF) as u8) |
84 | } |
85 | #[doc = "Byte 1 - Bits 31 - ANMF" ] |
86 | #[inline (always)] |
87 | pub fn anmf(&self) -> ANMF_R { |
88 | ANMF_R::new(((self.bits[1] >> 31) & 0x01) != 0) |
89 | } |
90 | pub fn to_data_length(&self) -> DataLength { |
91 | let dlc = self.dlc().bits(); |
92 | let ff = self.fdf().frame_format(); |
93 | let len = if ff == FrameFormat::Fdcan { |
94 | // See RM0433 Rev 7 Table 475. DLC coding |
95 | match dlc { |
96 | 0..=8 => dlc, |
97 | 9 => 12, |
98 | 10 => 16, |
99 | 11 => 20, |
100 | 12 => 24, |
101 | 13 => 32, |
102 | 14 => 48, |
103 | 15 => 64, |
104 | _ => panic!("DLC > 15" ), |
105 | } |
106 | } else { |
107 | match dlc { |
108 | 0..=8 => dlc, |
109 | 9..=15 => 8, |
110 | _ => panic!("DLC > 15" ), |
111 | } |
112 | }; |
113 | DataLength::new(len, ff) |
114 | } |
115 | pub fn to_filter_match(&self) -> FilterFrameMatch { |
116 | if self.anmf().is_matching_frame() { |
117 | FilterFrameMatch::DidMatch(self.fidx().bits()) |
118 | } else { |
119 | FilterFrameMatch::DidNotMatch |
120 | } |
121 | } |
122 | } |
123 | |