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 with_interrupts_disabled<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 with_interrupts_disabled<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}
77
78#[cfg(any(doc, all(target_arch = "arm", target_os = "none")))]
83pub fn is_interrupt_context() -> bool {
84 use core::arch::asm;
85 let mut interrupt_number: u32;
86
87 unsafe {
91 asm!(
93 "mrs r0, ipsr",
94 out("r0") interrupt_number,
95 options(nomem, nostack, preserves_flags)
96 );
97 }
98
99 (interrupt_number & 0x1FF) != 0
102}
103
104#[cfg(not(any(doc, all(target_arch = "arm", target_os = "none"))))]
105pub fn is_interrupt_context() -> bool {
106 unimplemented!()
107}