1use crate::csr::{mstatus::mstatus, CSR};
8
9#[cfg(any(doc, all(target_arch = "riscv32", target_os = "none")))]
10#[inline(always)]
11pub 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 = "riscv32", target_os = "none")))]
20#[inline(always)]
21pub unsafe fn wfi() {
23 use core::arch::asm;
24 asm!("wfi", options(nomem, nostack));
25}
26
27pub unsafe fn with_interrupts_disabled<F, R>(f: F) -> R
29where
30 F: FnOnce() -> R,
31{
32 let original_mie: usize = CSR
38 .mstatus
39 .read_and_clear_bits(mstatus::mie.mask << mstatus::mie.shift)
40 & mstatus::mie.mask << mstatus::mie.shift;
41
42 let res = f();
45
46 CSR.mstatus.read_and_set_bits(original_mie);
49
50 res
51}
52
53#[cfg(not(any(doc, all(target_arch = "riscv32", target_os = "none"))))]
55pub fn nop() {
57 unimplemented!()
58}
59
60#[cfg(not(any(doc, all(target_arch = "riscv32", target_os = "none"))))]
61pub unsafe fn wfi() {
63 unimplemented!()
64}