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