msp_exp432p401r/
io.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

use crate::CHIP;
use crate::PROCESSES;
use crate::PROCESS_PRINTER;

use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::addr_of;
use core::ptr::addr_of_mut;
use kernel::debug;
use kernel::debug::IoWrite;
use kernel::hil::led;
use msp432::gpio::IntPinNr;
use msp432::wdt::Wdt;

/// Uart is used by kernel::debug to panic message to the serial port.
pub struct Uart {}

/// Global static for debug writer
pub static mut UART: Uart = Uart {};

impl Write for Uart {
    fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
        self.write(s.as_bytes());
        Ok(())
    }
}

impl IoWrite for Uart {
    fn write(&mut self, buf: &[u8]) -> usize {
        let uart0 = msp432::uart::Uart::new(msp432::usci::USCI_A0_BASE, 0, 1, 1, 1);
        uart0.transmit_sync(buf);
        buf.len()
    }
}

/// Panic handler
#[no_mangle]
#[panic_handler]
pub unsafe fn panic_fmt(info: &PanicInfo) -> ! {
    const LED1_PIN: IntPinNr = IntPinNr::P01_0;
    let gpio_pin = msp432::gpio::IntPin::new(LED1_PIN);
    let led = &mut led::LedHigh::new(&gpio_pin);
    let writer = &mut *addr_of_mut!(UART);
    let wdt = Wdt::new();

    wdt.disable();
    debug::panic(
        &mut [led],
        writer,
        info,
        &cortexm4::support::nop,
        &*addr_of!(PROCESSES),
        &*addr_of!(CHIP),
        &*addr_of!(PROCESS_PRINTER),
    )
}