msp_exp432p401r/
io.rs
1use crate::CHIP;
6use crate::PROCESSES;
7use crate::PROCESS_PRINTER;
8
9use core::fmt::Write;
10use core::panic::PanicInfo;
11use core::ptr::addr_of;
12use core::ptr::addr_of_mut;
13use kernel::debug;
14use kernel::debug::IoWrite;
15use kernel::hil::led;
16use msp432::gpio::IntPinNr;
17use msp432::wdt::Wdt;
18
19pub struct Uart {}
21
22pub static mut UART: Uart = Uart {};
24
25impl Write for Uart {
26 fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
27 self.write(s.as_bytes());
28 Ok(())
29 }
30}
31
32impl IoWrite for Uart {
33 fn write(&mut self, buf: &[u8]) -> usize {
34 let uart0 = msp432::uart::Uart::new(msp432::usci::USCI_A0_BASE, 0, 1, 1, 1);
35 uart0.transmit_sync(buf);
36 buf.len()
37 }
38}
39
40#[no_mangle]
42#[panic_handler]
43pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
44 const LED1_PIN: IntPinNr = IntPinNr::P01_0;
45 let gpio_pin = msp432::gpio::IntPin::new(LED1_PIN);
46 let led = &mut led::LedHigh::new(&gpio_pin);
47 let writer = &mut *addr_of_mut!(UART);
48 let wdt = Wdt::new();
49
50 wdt.disable();
51 debug::panic(
52 &mut [led],
53 writer,
54 info,
55 &cortexm4::support::nop,
56 &*addr_of!(PROCESSES),
57 &*addr_of!(CHIP),
58 &*addr_of!(PROCESS_PRINTER),
59 )
60}