/// Kind of exception #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Exception { /// i.e. currently not servicing an exception ThreadMode, /// Non-maskable interrupt. Nmi, /// All class of fault. HardFault, /// Memory management. MemoryManagementFault, /// Pre-fetch fault, memory access fault. BusFault, /// Undefined instruction or illegal state. UsageFault, /// System service call via SWI instruction SVCall, /// Pendable request for system service PendSV, /// System tick timer Systick, /// An interrupt Interrupt(u8), // Unreachable variant #[doc(hidden)] Reserved, } impl Exception { /// Returns the kind of exception that's currently being serviced pub fn current() -> Exception { match ::peripheral::scb().icsr.read() as u8 { 0 => Exception::ThreadMode, 2 => Exception::Nmi, 3 => Exception::HardFault, 4 => Exception::MemoryManagementFault, 5 => Exception::BusFault, 6 => Exception::UsageFault, 11 => Exception::SVCall, 14 => Exception::PendSV, 15 => Exception::Systick, n if n >= 16 => Exception::Interrupt(n - 16), _ => Exception::Reserved, } } }