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;
16
17struct Writer<'a> {
18 output: &'a mut lpuart::Lpuart<'a>,
19}
20
21const BAUD_RATE: u32 = 115_200;
22
23impl<'a> Writer<'a> {
24 pub unsafe fn new(output: &'a mut lpuart::Lpuart<'a>) -> Self {
25 let _ = output.configure(uart::Parameters {
26 baud_rate: BAUD_RATE,
27 stop_bits: uart::StopBits::One,
28 parity: uart::Parity::None,
29 hw_flow_control: false,
30 width: uart::Width::Eight,
31 });
32
33 Writer { output }
34 }
35}
36
37impl IoWrite for Writer<'_> {
38 fn write(&mut self, bytes: &[u8]) -> usize {
39 for byte in bytes {
40 self.output.send_byte(*byte);
41 }
42 bytes.len()
43 }
44}
45
46impl Write for Writer<'_> {
47 fn write_str(&mut self, s: &str) -> fmt::Result {
48 self.write(s.as_bytes());
49 Ok(())
50 }
51}
52
53#[no_mangle]
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 &*addr_of!(crate::PROCESSES),
67 &*addr_of!(crate::CHIP),
68 &*addr_of!(crate::PROCESS_PRINTER),
69 )
70}