1use core::fmt::{self, Write};
6use core::ptr::addr_of;
7
8use kernel::debug::{self, IoWrite};
9use kernel::hil::{
10 led,
11 uart::{self, Configure},
12};
13
14use crate::imxrt1060::gpio;
15use crate::imxrt1060::lpuart;
16use crate::PROCESSES;
17
18struct Writer<'a> {
19 output: &'a mut lpuart::Lpuart<'a>,
20}
21
22const BAUD_RATE: u32 = 115_200;
23
24impl<'a> Writer<'a> {
25 pub unsafe fn new(output: &'a mut lpuart::Lpuart<'a>) -> Self {
26 let _ = output.configure(uart::Parameters {
27 baud_rate: BAUD_RATE,
28 stop_bits: uart::StopBits::One,
29 parity: uart::Parity::None,
30 hw_flow_control: false,
31 width: uart::Width::Eight,
32 });
33
34 Writer { output }
35 }
36}
37
38impl IoWrite for Writer<'_> {
39 fn write(&mut self, bytes: &[u8]) -> usize {
40 for byte in bytes {
41 self.output.send_byte(*byte);
42 }
43 bytes.len()
44 }
45}
46
47impl Write for Writer<'_> {
48 fn write_str(&mut self, s: &str) -> fmt::Result {
49 self.write(s.as_bytes());
50 Ok(())
51 }
52}
53
54#[panic_handler]
55unsafe fn panic_handler(panic_info: &core::panic::PanicInfo) -> ! {
56 let ccm = crate::imxrt1060::ccm::Ccm::new();
57 let pin = crate::imxrt1060::gpio::Pin::from_pin_id(gpio::PinId::B0_03);
58 let led = &mut led::LedHigh::new(&pin);
59 let mut lpuart2 = lpuart::Lpuart::new_lpuart2(&ccm);
60 let mut writer = Writer::new(&mut lpuart2);
61 debug::panic(
62 &mut [led],
63 &mut writer,
64 panic_info,
65 &cortexm7::support::nop,
66 PROCESSES.unwrap().as_slice(),
67 &*addr_of!(crate::CHIP),
68 &*addr_of!(crate::PROCESS_PRINTER),
69 )
70}