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 let uart = sifive::uart::Uart::new(e310_g002::uart::UART0_BASE, 16_000_000);
33 uart.transmit_sync(buf);
34 buf.len()
35 }
36}
37
38#[cfg(not(test))]
40#[panic_handler]
41pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
42 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}