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, RTR_R, XTD_R}; |
8 | use super::generic; |
9 | |
10 | #[doc = "Reader of register TxEventElement" ] |
11 | pub(crate) type R = generic::R<super::TxEventElementType, super::TxEventElement>; |
12 | // #[doc = "Writer for register TxEventElement"] |
13 | // pub(crate) type W = generic::W<super::TxEventElementType, super::TxEventElement>; |
14 | #[doc = "Register TxEventElement `reset()`'s" ] |
15 | impl generic::ResetValue for super::TxEventElement { |
16 | type Type = super::TxEventElementType; |
17 | #[inline (always)] |
18 | fn reset_value() -> Self::Type { |
19 | [0, 0] |
20 | } |
21 | } |
22 | |
23 | #[doc = "Reader of field `ID`" ] |
24 | pub(crate) type ID_R = generic::R<u32, u32>; |
25 | |
26 | #[doc = "Reader of field `TXTS`" ] |
27 | pub(crate) type TXTS_R = generic::R<u16, u16>; |
28 | |
29 | #[derive (Clone, Copy, Debug, PartialEq)] |
30 | pub(crate) enum DataLengthFormat { |
31 | StandardLength = 0, |
32 | FDCANLength = 1, |
33 | } |
34 | impl From<DataLengthFormat> for bool { |
35 | #[inline (always)] |
36 | fn from(dlf: DataLengthFormat) -> Self { |
37 | dlf as u8 != 0 |
38 | } |
39 | } |
40 | |
41 | #[doc = "Reader of field `EDL`" ] |
42 | pub(crate) type EDL_R = generic::R<bool, DataLengthFormat>; |
43 | impl EDL_R { |
44 | pub fn data_length_format(&self) -> DataLengthFormat { |
45 | match self.bits() { |
46 | false => DataLengthFormat::StandardLength, |
47 | true => DataLengthFormat::FDCANLength, |
48 | } |
49 | } |
50 | pub fn is_standard_length(&self) -> bool { |
51 | *self == DataLengthFormat::StandardLength |
52 | } |
53 | pub fn is_fdcan_length(&self) -> bool { |
54 | *self == DataLengthFormat::FDCANLength |
55 | } |
56 | } |
57 | |
58 | #[derive (Clone, Copy, Debug, PartialEq)] |
59 | pub(crate) enum EventType { |
60 | //_Reserved = 0b00, |
61 | TxEvent = 0b01, |
62 | TxDespiteAbort = 0b10, |
63 | //_Reserved = 0b10, |
64 | } |
65 | |
66 | #[doc = "Reader of field `EFC`" ] |
67 | pub(crate) type EFC_R = generic::R<u8, EventType>; |
68 | impl EFC_R { |
69 | pub fn event_type(&self) -> EventType { |
70 | match self.bits() { |
71 | 0b01 => EventType::TxEvent, |
72 | 0b10 => EventType::TxDespiteAbort, |
73 | _ => unimplemented!(), |
74 | } |
75 | } |
76 | pub fn is_tx_event(&self) -> bool { |
77 | self.event_type() == EventType::TxEvent |
78 | } |
79 | pub fn is_despite_abort(&self) -> bool { |
80 | self.event_type() == EventType::TxDespiteAbort |
81 | } |
82 | } |
83 | |
84 | #[doc = "Reader of field `MM`" ] |
85 | pub(crate) type MM_R = generic::R<u8, u8>; |
86 | |
87 | impl R { |
88 | #[doc = "Byte 0 - Bits 0:28 - ID" ] |
89 | #[inline (always)] |
90 | pub fn id(&self) -> ID_R { |
91 | ID_R::new(((self.bits[0]) & 0x1FFFFFFF) as u32) |
92 | } |
93 | #[doc = "Byte 0 - Bit 29 - RTR" ] |
94 | #[inline (always)] |
95 | pub fn rtr(&self) -> RTR_R { |
96 | RTR_R::new(((self.bits[0] >> 29) & 0x01) != 0) |
97 | } |
98 | #[doc = "Byte 0 - Bit 30 - XTD" ] |
99 | #[inline (always)] |
100 | pub fn xtd(&self) -> XTD_R { |
101 | XTD_R::new(((self.bits[0] >> 30) & 0x01) != 0) |
102 | } |
103 | #[doc = "Byte 0 - Bit 30 - ESI" ] |
104 | #[inline (always)] |
105 | pub fn esi(&self) -> ESI_R { |
106 | ESI_R::new(((self.bits[0] >> 31) & 0x01) != 0) |
107 | } |
108 | #[doc = "Byte 1 - Bits 0:15 - TXTS" ] |
109 | #[inline (always)] |
110 | pub fn txts(&self) -> TXTS_R { |
111 | TXTS_R::new(((self.bits[1]) & 0xFFFF) as u16) |
112 | } |
113 | #[doc = "Byte 1 - Bits 16:19 - DLC" ] |
114 | #[inline (always)] |
115 | pub fn dlc(&self) -> DLC_R { |
116 | DLC_R::new(((self.bits[1] >> 16) & 0x0F) as u8) |
117 | } |
118 | #[doc = "Byte 1 - Bits 20 - BRS" ] |
119 | #[inline (always)] |
120 | pub fn brs(&self) -> BRS_R { |
121 | BRS_R::new(((self.bits[1] >> 20) & 0x01) != 0) |
122 | } |
123 | #[doc = "Byte 1 - Bits 21 - EDL" ] |
124 | #[inline (always)] |
125 | pub fn edl(&self) -> EDL_R { |
126 | EDL_R::new(((self.bits[1] >> 21) & 0x01) != 0) |
127 | } |
128 | #[doc = "Byte 1 - Bits 22:23 - EFC" ] |
129 | #[inline (always)] |
130 | pub fn efc(&self) -> EFC_R { |
131 | EFC_R::new(((self.bits[1] >> 22) & 0x03) as u8) |
132 | } |
133 | #[doc = "Byte 1 - Bits 24:31 - MM" ] |
134 | #[inline (always)] |
135 | pub fn mm(&self) -> MM_R { |
136 | MM_R::new(((self.bits[1] >> 24) & 0xFF) as u8) |
137 | } |
138 | } |
139 | |