From 539c6d00fffabaf7c3f61f2f8c1aaefa661fa500 Mon Sep 17 00:00:00 2001 From: Adam Greig Date: Sun, 15 Mar 2020 19:40:37 +0000 Subject: Add UDF instruction. Closes #199. --- src/asm.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/asm.rs b/src/asm.rs index 7b1a9ce..593aeac 100644 --- a/src/asm.rs +++ b/src/asm.rs @@ -81,6 +81,30 @@ pub fn nop() { } } + +/// Generate an Undefined Instruction exception. +/// +/// Can be used as a stable alternative to `core::intrinsics::abort`. +#[inline] +pub fn udf() { + match () { + #[cfg(all(cortex_m, feature = "inline-asm"))] + () => unsafe { asm!("udf" :::: "volatile") }, + + #[cfg(all(cortex_m, not(feature = "inline-asm")))] + () => unsafe { + extern "C" { + fn __udf(); + } + + __udf() + }, + + #[cfg(not(cortex_m))] + () => unimplemented!(), + } +} + /// Wait For Event #[inline] pub fn wfe() { -- cgit v1.2.3