lora_things_plus/
io.rs
1use core::fmt::Write;
6use core::panic::PanicInfo;
7use core::ptr::addr_of;
8use core::ptr::addr_of_mut;
9
10use crate::CHIP;
11use crate::PROCESSES;
12use crate::PROCESS_PRINTER;
13use kernel::debug;
14use kernel::debug::IoWrite;
15use kernel::hil::led;
16
17pub struct Writer {}
19
20pub static 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 = apollo3::uart::Uart::new_uart_0(); uart.transmit_sync(buf);
34 buf.len()
35 }
36}
37
38#[no_mangle]
40#[panic_handler]
41pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
42 let led_pin = &mut apollo3::gpio::GpioPin::new(
44 kernel::utilities::StaticRef::new(
45 apollo3::gpio::GPIO_BASE_RAW as *const apollo3::gpio::GpioRegisters,
46 ),
47 apollo3::gpio::Pin::Pin26,
48 );
49 let led = &mut led::LedLow::new(led_pin);
50 let writer = &mut *addr_of_mut!(WRITER);
51
52 debug::panic(
53 &mut [led],
54 writer,
55 info,
56 &cortexm4::support::nop,
57 &*addr_of!(PROCESSES),
58 &*addr_of!(CHIP),
59 &*addr_of!(PROCESS_PRINTER),
60 )
61}