1use core::fmt::Write;
6use core::panic::PanicInfo;
7use core::ptr::addr_of;
8use core::ptr::addr_of_mut;
9use core::str;
10use kernel::debug;
11use kernel::debug::IoWrite;
12use kernel::hil::gpio;
13use kernel::hil::led;
14
15use crate::CHIP;
16use crate::PROCESSES;
17use crate::PROCESS_PRINTER;
18
19struct Writer {}
20
21static mut WRITER: Writer = Writer {};
22
23impl Write for Writer {
24 fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
25 self.write(s.as_bytes());
26 Ok(())
27 }
28}
29
30impl IoWrite for Writer {
31 fn write(&mut self, buf: &[u8]) -> usize {
32 sifive::uart::Uart::new(arty_e21_chip::uart::UART0_BASE, 32_000_000).transmit_sync(buf);
33 buf.len()
34 }
35}
36
37#[cfg(not(test))]
39#[no_mangle]
40#[panic_handler]
41pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
42 let led_green = &sifive::gpio::GpioPin::new(
44 arty_e21_chip::gpio::GPIO0_BASE,
45 sifive::gpio::pins::pin1,
46 sifive::gpio::pins::pin1::SET,
47 sifive::gpio::pins::pin1::CLEAR,
48 );
49 gpio::Configure::make_output(led_green);
50 gpio::Output::clear(led_green);
51
52 let led_blue = &sifive::gpio::GpioPin::new(
53 arty_e21_chip::gpio::GPIO0_BASE,
54 sifive::gpio::pins::pin0,
55 sifive::gpio::pins::pin0::SET,
56 sifive::gpio::pins::pin0::CLEAR,
57 );
58 gpio::Configure::make_output(led_blue);
59 gpio::Output::clear(led_blue);
60
61 let led_red_pin = &mut sifive::gpio::GpioPin::new(
62 arty_e21_chip::gpio::GPIO0_BASE,
63 sifive::gpio::pins::pin2,
64 sifive::gpio::pins::pin2::SET,
65 sifive::gpio::pins::pin2::CLEAR,
66 );
67
68 let led_red = &mut led::LedHigh::new(led_red_pin);
69 let writer = &mut *addr_of_mut!(WRITER);
70 debug::panic(
71 &mut [led_red],
72 writer,
73 pi,
74 &rv32i::support::nop,
75 &*addr_of!(PROCESSES),
76 &*addr_of!(CHIP),
77 &*addr_of!(PROCESS_PRINTER),
78 )
79}