cortexm/
support.rs
1use crate::scb;
8
9#[cfg(any(doc, all(target_arch = "arm", target_os = "none")))]
11#[inline(always)]
12pub fn nop() {
13 use core::arch::asm;
14 unsafe {
15 asm!("nop", options(nomem, nostack, preserves_flags));
16 }
17}
18
19#[cfg(any(doc, all(target_arch = "arm", target_os = "none")))]
21#[inline(always)]
22pub unsafe fn wfi() {
23 use core::arch::asm;
24 asm!("wfi", options(nomem, preserves_flags));
25}
26
27#[cfg(any(doc, all(target_arch = "arm", target_os = "none")))]
29pub unsafe fn atomic<F, R>(f: F) -> R
30where
31 F: FnOnce() -> R,
32{
33 use core::arch::asm;
34 asm!("cpsid i", options(nomem, nostack));
36
37 let res = f();
38
39 asm!("cpsie i", options(nomem, nostack));
41 res
42}
43
44#[cfg(not(any(doc, all(target_arch = "arm", target_os = "none"))))]
47pub fn nop() {
48 unimplemented!()
49}
50
51#[cfg(not(any(doc, all(target_arch = "arm", target_os = "none"))))]
53pub unsafe fn wfi() {
54 unimplemented!()
55}
56
57#[cfg(not(any(doc, all(target_arch = "arm", target_os = "none"))))]
59pub unsafe fn atomic<F, R>(_f: F) -> R
60where
61 F: FnOnce() -> R,
62{
63 unimplemented!()
64}
65
66pub fn reset() -> ! {
68 unsafe {
69 scb::reset();
70 }
71 loop {
72 nop();
75 }
76}