#![cfg(feature = "panic-handler")]
use core::panic::PanicInfo;
use core::sync::atomic::{AtomicBool, Ordering};
use crate::config;
use crate::logger::ConsortiumLogger;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
arch::disable_interrupts();
static PANICKED: AtomicBool = AtomicBool::new(false);
if !PANICKED.swap(true, Ordering::SeqCst) {
defmt::error!("panic: {}", defmt::Display2Format(info));
if let Some((base, _)) = config::region() {
unsafe { ConsortiumLogger::mark_panic(base) };
}
}
arch::halt()
}
#[cfg(feature = "arch-cortex-m")]
mod arch {
pub fn disable_interrupts() {
cortex_m::interrupt::disable();
}
pub fn halt() -> ! {
cortex_m::asm::udf()
}
}
#[cfg(feature = "arch-riscv")]
mod arch {
pub fn disable_interrupts() {
riscv::interrupt::disable();
}
pub fn halt() -> ! {
loop {
riscv::asm::wfi();
}
}
}