|
1 | 1 | //! D1-H, D1s, F133, F133A/B chip platforms. |
2 | 2 |
|
3 | 3 | mod clock; |
| 4 | +mod interrupt; |
| 5 | +mod peripheral; |
4 | 6 |
|
5 | 7 | pub use clock::{Clocks, UartClock}; |
| 8 | +pub use interrupt::{Interrupt, Machine, Supevisor}; |
| 9 | +pub use peripheral::*; |
6 | 10 |
|
7 | | -use allwinner_hal::{gpio::PadExt, uart::UartExt}; |
8 | | -use core::num::NonZeroU32; |
9 | 11 | use embedded_time::rate::Extensions; |
10 | 12 |
|
11 | | -/// ROM runtime peripheral ownership and configurations. |
12 | | -pub struct Peripherals { |
13 | | - /// General Purpose Input/Output peripheral. |
14 | | - pub gpio: Pads, |
15 | | - /// Clock control unit peripheral. |
16 | | - pub ccu: CCU, |
17 | | - /// Universal Asynchronous Receiver/Transmitter 0. |
18 | | - pub uart0: UART0, |
19 | | - /// Common control peripheral of DDR SDRAM. |
20 | | - pub com: COM, |
21 | | - /// Memory controller physical layer (PHY) of DDR SDRAM. |
22 | | - pub phy: PHY, |
23 | | - /// SD/MMC Host Controller peripheral 0. |
24 | | - pub smhc0: SMHC0, |
25 | | - /// SD/MMC Host Controller peripheral 1. |
26 | | - pub smhc1: SMHC1, |
27 | | - /// SD/MMC Host Controller peripheral 2. |
28 | | - pub smhc2: SMHC2, |
29 | | - /// Serial Peripheral Interface peripheral 0. |
30 | | - pub spi0: SPI0, |
31 | | - /// Platform-local Interrupt Controller. |
32 | | - pub plic: PLIC, |
33 | | -} |
34 | | - |
35 | | -soc! { |
36 | | - /// General Purpose Input/Output peripheral. |
37 | | - pub struct GPIO => 0x02000000, allwinner_hal::gpio::RegisterBlock; |
38 | | - /// Clock control unit peripheral. |
39 | | - pub struct CCU => 0x02001000, allwinner_hal::ccu::RegisterBlock; |
40 | | - /// Universal Asynchronous Receiver/Transmitter 0. |
41 | | - pub struct UART0 => 0x02500000, allwinner_hal::uart::RegisterBlock; |
42 | | - /// Common control peripheral of DDR SDRAM. |
43 | | - pub struct COM => 0x03102000, allwinner_hal::com::RegisterBlock; |
44 | | - /// Memory controller physical layer (PHY) of DDR SDRAM. |
45 | | - pub struct PHY => 0x03103000, allwinner_hal::phy::RegisterBlock; |
46 | | - /// SD/MMC Host Controller peripheral 0. |
47 | | - pub struct SMHC0 => 0x04020000, allwinner_hal::smhc::RegisterBlock; |
48 | | - /// SD/MMC Host Controller peripheral 1. |
49 | | - pub struct SMHC1 => 0x04021000, allwinner_hal::smhc::RegisterBlock; |
50 | | - /// SD/MMC Host Controller peripheral 2. |
51 | | - pub struct SMHC2 => 0x04022000, allwinner_hal::smhc::RegisterBlock; |
52 | | - /// Serial Peripheral Interface peripheral 0. |
53 | | - pub struct SPI0 => 0x04025000, allwinner_hal::spi::RegisterBlock; |
54 | | - /// Platform-local Interrupt Controller. |
55 | | - pub struct PLIC => 0x10000000, plic::Plic; |
56 | | -} |
57 | | - |
58 | | -impl_uart! { |
59 | | - 0 => UART0, |
60 | | -} |
61 | | - |
62 | | -/// Ownership of a D1 GPIO pad. |
63 | | -pub struct Pad<const P: char, const N: u8> { |
64 | | - _private: (), |
65 | | -} |
66 | | - |
67 | | -impl<const P: char, const N: u8> Pad<P, N> { |
68 | | - /// Macro internal constructor. |
69 | | - #[doc(hidden)] |
70 | | - #[inline] |
71 | | - pub const fn __new() -> Self { |
72 | | - Self { _private: () } |
73 | | - } |
74 | | -} |
75 | | - |
76 | | -impl<'a, const P: char, const N: u8> allwinner_hal::gpio::PadExt<'a, P, N> for &'a mut Pad<P, N> { |
77 | | - #[inline] |
78 | | - fn into_input(self) -> allwinner_hal::gpio::Input<'a> { |
79 | | - unsafe { allwinner_hal::gpio::Input::__new(P, N, &GPIO { _private: () }) } |
80 | | - } |
81 | | - #[inline] |
82 | | - fn into_output(self) -> allwinner_hal::gpio::Output<'a> { |
83 | | - unsafe { allwinner_hal::gpio::Output::__new(P, N, &GPIO { _private: () }) } |
84 | | - } |
85 | | - #[inline] |
86 | | - fn into_function<const F: u8>(self) -> allwinner_hal::gpio::Function<'a, P, N, F> { |
87 | | - unsafe { allwinner_hal::gpio::Function::__new(&GPIO { _private: () }) } |
88 | | - } |
89 | | - #[inline] |
90 | | - fn into_eint(self) -> allwinner_hal::gpio::EintPad<'a> { |
91 | | - unsafe { allwinner_hal::gpio::EintPad::__new(P, N, &GPIO { _private: () }) } |
92 | | - } |
93 | | -} |
94 | | - |
95 | | -impl<const P: char, const N: u8> allwinner_hal::gpio::PadExt<'static, P, N> for Pad<P, N> { |
96 | | - #[inline] |
97 | | - fn into_input(self) -> allwinner_hal::gpio::Input<'static> { |
98 | | - unsafe { allwinner_hal::gpio::Input::__new(P, N, &GPIO { _private: () }) } |
99 | | - } |
100 | | - #[inline] |
101 | | - fn into_output(self) -> allwinner_hal::gpio::Output<'static> { |
102 | | - unsafe { allwinner_hal::gpio::Output::__new(P, N, &GPIO { _private: () }) } |
103 | | - } |
104 | | - #[inline] |
105 | | - fn into_function<const F: u8>(self) -> allwinner_hal::gpio::Function<'static, P, N, F> { |
106 | | - unsafe { allwinner_hal::gpio::Function::__new(&GPIO { _private: () }) } |
107 | | - } |
108 | | - #[inline] |
109 | | - fn into_eint(self) -> allwinner_hal::gpio::EintPad<'static> { |
110 | | - unsafe { allwinner_hal::gpio::EintPad::__new(P, N, &GPIO { _private: () }) } |
111 | | - } |
112 | | -} |
113 | | - |
114 | | -impl_gpio_pins! { |
115 | | - pb0: ('B', 0); |
116 | | - pb1: ('B', 1); |
117 | | - pb2: ('B', 2); |
118 | | - pb3: ('B', 3); |
119 | | - pb4: ('B', 4); |
120 | | - pb5: ('B', 5); |
121 | | - pb6: ('B', 6); |
122 | | - pb7: ('B', 7); |
123 | | - pb8: ('B', 8); |
124 | | - pb9: ('B', 9); |
125 | | - pb10: ('B', 10); |
126 | | - pb11: ('B', 11); |
127 | | - pb12: ('B', 12); |
128 | | - pc0: ('C', 0); |
129 | | - pc1: ('C', 1); |
130 | | - pc2: ('C', 2); |
131 | | - pc3: ('C', 3); |
132 | | - pc4: ('C', 4); |
133 | | - pc5: ('C', 5); |
134 | | - pc6: ('C', 6); |
135 | | - pc7: ('C', 7); |
136 | | - pd0: ('D', 0); |
137 | | - pd1: ('D', 1); |
138 | | - pd2: ('D', 2); |
139 | | - pd3: ('D', 3); |
140 | | - pd4: ('D', 4); |
141 | | - pd5: ('D', 5); |
142 | | - pd6: ('D', 6); |
143 | | - pd7: ('D', 7); |
144 | | - pd8: ('D', 8); |
145 | | - pd9: ('D', 9); |
146 | | - pd10: ('D', 10); |
147 | | - pd11: ('D', 11); |
148 | | - pd12: ('D', 12); |
149 | | - pd13: ('D', 13); |
150 | | - pd14: ('D', 14); |
151 | | - pd15: ('D', 15); |
152 | | - pd16: ('D', 16); |
153 | | - pd17: ('D', 17); |
154 | | - pd18: ('D', 18); |
155 | | - pd19: ('D', 19); |
156 | | - pd20: ('D', 20); |
157 | | - pd21: ('D', 21); |
158 | | - pd22: ('D', 22); |
159 | | - pe0: ('E', 0); |
160 | | - pe1: ('E', 1); |
161 | | - pe2: ('E', 2); |
162 | | - pe3: ('E', 3); |
163 | | - pe4: ('E', 4); |
164 | | - pe5: ('E', 5); |
165 | | - pe6: ('E', 6); |
166 | | - pe7: ('E', 7); |
167 | | - pe8: ('E', 8); |
168 | | - pe9: ('E', 9); |
169 | | - pe10: ('E', 10); |
170 | | - pe11: ('E', 11); |
171 | | - pe12: ('E', 12); |
172 | | - pe13: ('E', 13); |
173 | | - pe14: ('E', 14); |
174 | | - pe15: ('E', 15); |
175 | | - pe16: ('E', 16); |
176 | | - pe17: ('E', 17); |
177 | | - pf0: ('F', 0); |
178 | | - pf1: ('F', 1); |
179 | | - pf2: ('F', 2); |
180 | | - pf3: ('F', 3); |
181 | | - pf4: ('F', 4); |
182 | | - pf5: ('F', 5); |
183 | | - pf6: ('F', 6); |
184 | | - pg0: ('G', 0); |
185 | | - pg1: ('G', 1); |
186 | | - pg2: ('G', 2); |
187 | | - pg3: ('G', 3); |
188 | | - pg4: ('G', 4); |
189 | | - pg5: ('G', 5); |
190 | | - pg6: ('G', 6); |
191 | | - pg7: ('G', 7); |
192 | | - pg8: ('G', 8); |
193 | | - pg9: ('G', 9); |
194 | | - pg10: ('G', 10); |
195 | | - pg11: ('G', 11); |
196 | | - pg12: ('G', 12); |
197 | | - pg13: ('G', 13); |
198 | | - pg14: ('G', 14); |
199 | | - pg15: ('G', 15); |
200 | | - pg16: ('G', 16); |
201 | | - pg17: ('G', 17); |
202 | | - pg18: ('G', 18); |
203 | | -} |
204 | | - |
205 | | -impl_uart_pads! { |
206 | | - ('B', 0, 6): IntoTransmit, into_uart_transmit, 0; |
207 | | - ('B', 0, 7): IntoTransmit, into_uart_transmit, 2; |
208 | | - ('B', 1, 6): IntoReceive, into_uart_receive, 0; |
209 | | - ('B', 1, 7): IntoReceive, into_uart_receive, 2; |
210 | | - ('B', 2, 7): IntoTransmit, into_uart_transmit, 4; |
211 | | - ('B', 3, 7): IntoReceive, into_uart_receive, 4; |
212 | | - ('B', 4, 7): IntoTransmit, into_uart_transmit, 5; |
213 | | - ('B', 5, 7): IntoReceive, into_uart_receive, 5; |
214 | | - ('B', 6, 7): IntoTransmit, into_uart_transmit, 3; |
215 | | - ('B', 7, 7): IntoReceive, into_uart_receive, 3; |
216 | | - ('B', 8, 6): IntoTransmit, into_uart_transmit, 0; |
217 | | - ('B', 8, 7): IntoTransmit, into_uart_transmit, 1; |
218 | | - ('B', 9, 6): IntoReceive, into_uart_receive, 0; |
219 | | - ('B', 9, 7): IntoReceive, into_uart_receive, 1; |
220 | | - ('C', 0, 2): IntoTransmit, into_uart_transmit, 2; |
221 | | - ('C', 1, 2): IntoReceive, into_uart_receive, 2; |
222 | | - ('C', 6, 4): IntoTransmit, into_uart_transmit, 3; |
223 | | - ('C', 7, 4): IntoReceive, into_uart_receive, 3; |
224 | | - ('D', 1, 5): IntoTransmit, into_uart_transmit, 2; |
225 | | - ('D', 2, 5): IntoReceive, into_uart_receive, 2; |
226 | | - ('D', 5, 5): IntoTransmit, into_uart_transmit, 5; |
227 | | - ('D', 6, 5): IntoReceive, into_uart_receive, 5; |
228 | | - ('D', 7, 5): IntoTransmit, into_uart_transmit, 4; |
229 | | - ('D', 8, 5): IntoReceive, into_uart_receive, 4; |
230 | | - ('D', 10, 5): IntoTransmit, into_uart_transmit, 3; |
231 | | - ('D', 11, 5): IntoReceive, into_uart_receive, 3; |
232 | | - ('D', 21, 4): IntoTransmit, into_uart_transmit, 1; |
233 | | - ('D', 22, 4): IntoReceive, into_uart_receive, 1; |
234 | | - ('E', 2, 3): IntoTransmit, into_uart_transmit, 2; |
235 | | - ('E', 2, 6): IntoTransmit, into_uart_transmit, 0; |
236 | | - ('E', 3, 3): IntoReceive, into_uart_receive, 2; |
237 | | - ('E', 3, 6): IntoReceive, into_uart_receive, 0; |
238 | | - ('E', 4, 3): IntoTransmit, into_uart_transmit, 4; |
239 | | - ('E', 5, 3): IntoReceive, into_uart_receive, 4; |
240 | | - ('E', 6, 3): IntoTransmit, into_uart_transmit, 5; |
241 | | - ('E', 7, 3): IntoReceive, into_uart_receive, 5; |
242 | | - ('E', 8, 5): IntoTransmit, into_uart_transmit, 3; |
243 | | - ('E', 9, 5): IntoReceive, into_uart_receive, 3; |
244 | | - ('E', 10, 3): IntoTransmit, into_uart_transmit, 1; |
245 | | - ('E', 11, 3): IntoReceive, into_uart_receive, 1; |
246 | | - ('G', 0, 3): IntoTransmit, into_uart_transmit, 3; |
247 | | - ('G', 1, 3): IntoReceive, into_uart_receive, 3; |
248 | | - ('G', 2, 5): IntoTransmit, into_uart_transmit, 4; |
249 | | - ('G', 3, 5): IntoReceive, into_uart_receive, 4; |
250 | | - ('G', 4, 3): IntoTransmit, into_uart_transmit, 5; |
251 | | - ('G', 5, 3): IntoReceive, into_uart_receive, 5; |
252 | | - ('G', 6, 2): IntoTransmit, into_uart_transmit, 1; |
253 | | - ('G', 7, 2): IntoReceive, into_uart_receive, 1; |
254 | | - ('G', 8, 5): IntoTransmit, into_uart_transmit, 3; |
255 | | - ('G', 9, 5): IntoReceive, into_uart_receive, 3; |
256 | | - ('G', 17, 2): IntoTransmit, into_uart_transmit, 2; |
257 | | - ('G', 18, 2): IntoReceive, into_uart_receive, 2; |
258 | | -} |
259 | | - |
260 | | -impl_spi_pads! { |
261 | | - ('B', 9, 5): IntoMiso, into_spi_miso, 1; |
262 | | - ('B', 10, 5): IntoMosi, into_spi_mosi, 1; |
263 | | - ('B', 11, 5): IntoClk, into_spi_clk, 1; |
264 | | - ('C', 2, 2): IntoClk, into_spi_clk, 0; |
265 | | - ('C', 4, 2): IntoMosi, into_spi_mosi, 0; |
266 | | - ('C', 5, 2): IntoMiso, into_spi_miso, 0; |
267 | | - ('D', 11, 4): IntoClk, into_spi_clk, 1; |
268 | | - ('D', 12, 4): IntoMosi, into_spi_mosi, 1; |
269 | | - ('D', 13, 4): IntoMiso, into_spi_miso, 1; |
270 | | -} |
271 | | - |
272 | | -// TODO constrain SMHC pads |
273 | | -// // SMHC pins |
274 | | -// impl_pins_trait! { |
275 | | -// ('F', 0, 2): smhc::Data<1>; |
276 | | -// ('F', 1, 2): smhc::Data<0>; |
277 | | -// ('F', 2, 2): smhc::Clk; |
278 | | -// ('F', 3, 2): smhc::Cmd; |
279 | | -// ('F', 4, 2): smhc::Data<3>; |
280 | | -// ('F', 5, 2): smhc::Data<2>; |
281 | | -// ('G', 0, 2): smhc::Clk; |
282 | | -// ('G', 1, 2): smhc::Cmd; |
283 | | -// ('G', 2, 2): smhc::Data<0>; |
284 | | -// ('G', 3, 2): smhc::Data<1>; |
285 | | -// ('G', 4, 2): smhc::Data<2>; |
286 | | -// ('G', 5, 2): smhc::Data<3>; |
287 | | -// ('C', 2, 3): smhc::Clk; |
288 | | -// ('C', 3, 3): smhc::Cmd; |
289 | | -// ('C', 4, 3): smhc::Data<2>; |
290 | | -// ('C', 5, 3): smhc::Data<1>; |
291 | | -// ('C', 6, 3): smhc::Data<0>; |
292 | | -// ('C', 7, 3): smhc::Data<3>; |
293 | | -// } |
294 | | - |
295 | 13 | #[doc(hidden)] |
296 | 14 | #[inline] |
297 | 15 | pub fn __rom_init_params() -> (Peripherals, Clocks) { |
298 | | - let peripherals = Peripherals { |
299 | | - gpio: Pads::__new(), |
300 | | - ccu: CCU { _private: () }, |
301 | | - uart0: UART0 { _private: () }, |
302 | | - com: COM { _private: () }, |
303 | | - phy: PHY { _private: () }, |
304 | | - smhc0: SMHC0 { _private: () }, |
305 | | - smhc1: SMHC1 { _private: () }, |
306 | | - smhc2: SMHC2 { _private: () }, |
307 | | - spi0: SPI0 { _private: () }, |
308 | | - plic: PLIC { _private: () }, |
309 | | - }; |
310 | 16 | let clocks = Clocks { |
311 | 17 | psi: 600_000_000.Hz(), |
312 | 18 | apb1: 24_000_000.Hz(), |
313 | 19 | }; |
314 | | - (peripherals, clocks) |
315 | | -} |
316 | | - |
317 | | -/// Allwinner D1 C906 hart interrupts. |
318 | | -#[derive(Clone, Copy, Debug, Eq, PartialEq)] |
319 | | -#[repr(u32)] |
320 | | -pub enum Interrupt { |
321 | | - /// Universal Asynchronous Receiver-Transmitter 0. |
322 | | - UART0 = 18, |
323 | | - /// Universal Asynchronous Receiver-Transmitter 1. |
324 | | - UART1 = 19, |
325 | | - /// Universal Asynchronous Receiver-Transmitter 2. |
326 | | - UART2 = 20, |
327 | | - /// Universal Asynchronous Receiver-Transmitter 3. |
328 | | - UART3 = 21, |
329 | | - /// Universal Asynchronous Receiver-Transmitter 4. |
330 | | - UART4 = 22, |
331 | | - /// Universal Asynchronous Receiver-Transmitter 5. |
332 | | - UART5 = 23, |
333 | | - /// Serial Peripheral Interface 0. |
334 | | - SPI0 = 31, |
335 | | - /// Serial Peripheral Interface 1. |
336 | | - SPI1 = 32, |
337 | | -} |
338 | | - |
339 | | -impl plic::InterruptSource for Interrupt { |
340 | | - fn id(self) -> NonZeroU32 { |
341 | | - // note(unwarp): self as u32 representation has no zero value. |
342 | | - NonZeroU32::new(self as u32).unwrap() |
343 | | - } |
344 | | -} |
345 | | - |
346 | | -/// Machine mode hart context for Allwinner D1 T-Head C906 core. |
347 | | -#[derive(Clone, Copy, Debug, Eq, PartialEq)] |
348 | | -pub struct Machine; |
349 | | - |
350 | | -impl plic::HartContext for Machine { |
351 | | - fn index(self) -> usize { |
352 | | - 0 |
353 | | - } |
354 | | -} |
355 | | - |
356 | | -/// Supervisor mode hart context for Allwinner D1 T-Head C906 core. |
357 | | -#[derive(Clone, Copy, Debug, Eq, PartialEq)] |
358 | | -pub struct Supevisor; |
359 | | - |
360 | | -impl plic::HartContext for Supevisor { |
361 | | - fn index(self) -> usize { |
362 | | - 1 |
363 | | - } |
| 20 | + (Peripherals::__new(), clocks) |
364 | 21 | } |
0 commit comments