1 | // Note: This file is copied and modified from fdcan crate by Richard Meadows |
2 | |
3 | use volatile_register::RW; |
4 | |
5 | pub(crate) mod common; |
6 | pub(crate) mod enums; |
7 | pub(crate) mod generic; |
8 | |
9 | /// Number of Receive Fifos configured by this module |
10 | pub const RX_FIFOS_MAX: u8 = 2; |
11 | /// Number of Receive Messages per RxFifo configured by this module |
12 | pub const RX_FIFO_MAX: u8 = 3; |
13 | /// Number of Transmit Messages configured by this module |
14 | pub const TX_FIFO_MAX: u8 = 3; |
15 | /// Number of Transmit Events configured by this module |
16 | pub const TX_EVENT_MAX: u8 = 3; |
17 | /// Number of Standard Filters configured by this module |
18 | pub const STANDARD_FILTER_MAX: u8 = 28; |
19 | /// Number of Extended Filters configured by this module |
20 | pub const EXTENDED_FILTER_MAX: u8 = 8; |
21 | |
22 | /// MessageRam Overlay |
23 | #[repr (C)] |
24 | pub struct RegisterBlock { |
25 | pub(crate) filters: Filters, |
26 | pub(crate) receive: [Receive; RX_FIFOS_MAX as usize], |
27 | pub(crate) transmit: Transmit, |
28 | } |
29 | impl RegisterBlock { |
30 | pub fn reset(&mut self) { |
31 | self.filters.reset(); |
32 | self.receive[0].reset(); |
33 | self.receive[1].reset(); |
34 | self.transmit.reset(); |
35 | } |
36 | } |
37 | |
38 | #[repr (C)] |
39 | pub(crate) struct Filters { |
40 | pub(crate) flssa: [StandardFilter; STANDARD_FILTER_MAX as usize], |
41 | pub(crate) flesa: [ExtendedFilter; EXTENDED_FILTER_MAX as usize], |
42 | } |
43 | impl Filters { |
44 | pub fn reset(&mut self) { |
45 | for sf: &mut Reg in &mut self.flssa { |
46 | sf.reset(); |
47 | } |
48 | for ef: &mut Reg<[u32; 2], _ExtendedFilter> in &mut self.flesa { |
49 | ef.reset(); |
50 | } |
51 | } |
52 | } |
53 | |
54 | #[repr (C)] |
55 | pub(crate) struct Receive { |
56 | pub(crate) fxsa: [RxFifoElement; RX_FIFO_MAX as usize], |
57 | } |
58 | impl Receive { |
59 | pub fn reset(&mut self) { |
60 | for fe: &mut RxFifoElement in &mut self.fxsa { |
61 | fe.reset(); |
62 | } |
63 | } |
64 | } |
65 | |
66 | #[repr (C)] |
67 | pub(crate) struct Transmit { |
68 | pub(crate) efsa: [TxEventElement; TX_EVENT_MAX as usize], |
69 | pub(crate) tbsa: [TxBufferElement; TX_FIFO_MAX as usize], |
70 | } |
71 | impl Transmit { |
72 | pub fn reset(&mut self) { |
73 | for ee: &mut Reg<[u32; 2], _TxEventElement> in &mut self.efsa { |
74 | ee.reset(); |
75 | } |
76 | for be: &mut TxBufferElement in &mut self.tbsa { |
77 | be.reset(); |
78 | } |
79 | } |
80 | } |
81 | |
82 | pub(crate) mod standard_filter; |
83 | pub(crate) type StandardFilterType = u32; |
84 | pub(crate) type StandardFilter = generic::Reg<StandardFilterType, _StandardFilter>; |
85 | pub(crate) struct _StandardFilter; |
86 | impl generic::Readable for StandardFilter {} |
87 | impl generic::Writable for StandardFilter {} |
88 | |
89 | pub(crate) mod extended_filter; |
90 | pub(crate) type ExtendedFilterType = [u32; 2]; |
91 | pub(crate) type ExtendedFilter = generic::Reg<ExtendedFilterType, _ExtendedFilter>; |
92 | pub(crate) struct _ExtendedFilter; |
93 | impl generic::Readable for ExtendedFilter {} |
94 | impl generic::Writable for ExtendedFilter {} |
95 | |
96 | pub(crate) mod txevent_element; |
97 | pub(crate) type TxEventElementType = [u32; 2]; |
98 | pub(crate) type TxEventElement = generic::Reg<TxEventElementType, _TxEventElement>; |
99 | pub(crate) struct _TxEventElement; |
100 | impl generic::Readable for TxEventElement {} |
101 | impl generic::Writable for TxEventElement {} |
102 | |
103 | pub(crate) mod rxfifo_element; |
104 | #[repr (C)] |
105 | pub(crate) struct RxFifoElement { |
106 | pub(crate) header: RxFifoElementHeader, |
107 | pub(crate) data: [RW<u32>; 16], |
108 | } |
109 | impl RxFifoElement { |
110 | pub(crate) fn reset(&mut self) { |
111 | self.header.reset(); |
112 | for byte: &mut RW in self.data.iter_mut() { |
113 | unsafe { byte.write(0) }; |
114 | } |
115 | } |
116 | } |
117 | pub(crate) type RxFifoElementHeaderType = [u32; 2]; |
118 | pub(crate) type RxFifoElementHeader = generic::Reg<RxFifoElementHeaderType, _RxFifoElement>; |
119 | pub(crate) struct _RxFifoElement; |
120 | impl generic::Readable for RxFifoElementHeader {} |
121 | impl generic::Writable for RxFifoElementHeader {} |
122 | |
123 | pub(crate) mod txbuffer_element; |
124 | #[repr (C)] |
125 | pub(crate) struct TxBufferElement { |
126 | pub(crate) header: TxBufferElementHeader, |
127 | pub(crate) data: [RW<u32>; 16], |
128 | } |
129 | impl TxBufferElement { |
130 | pub(crate) fn reset(&mut self) { |
131 | self.header.reset(); |
132 | for byte: &mut RW in self.data.iter_mut() { |
133 | unsafe { byte.write(0) }; |
134 | } |
135 | } |
136 | } |
137 | pub(crate) type TxBufferElementHeader = generic::Reg<TxBufferElementHeaderType, _TxBufferElement>; |
138 | pub(crate) type TxBufferElementHeaderType = [u32; 2]; |
139 | pub(crate) struct _TxBufferElement; |
140 | impl generic::Readable for TxBufferElementHeader {} |
141 | impl generic::Writable for TxBufferElementHeader {} |
142 | |
143 | // Ensure the RegisterBlock is the same size as on pg 1957 of RM0440. |
144 | static_assertions::assert_eq_size!(Filters, [u32; 28 + 16]); |
145 | static_assertions::assert_eq_size!(Receive, [u32; 54]); |
146 | static_assertions::assert_eq_size!(Transmit, [u32; 6 + 54]); |
147 | static_assertions::assert_eq_size!( |
148 | RegisterBlock, |
149 | [u32; 28 /*Standard Filters*/ +16 /*Extended Filters*/ +54 /*RxFifo0*/ +54 /*RxFifo1*/ +6 /*TxEvent*/ +54 /*TxFifo */] |
150 | ); |
151 | |