aboutsummaryrefslogtreecommitdiff
path: root/src/_arch/arm/asm.rs
blob: f767e08d5b74c9092b4e2fa12483398fed424f3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! # Wrapping ARMv7-A Instructions
//!
//! This provides bindings for assembly instructions
//! to be used in other rust functions without `unsafe`
//! markers everywhere.

/// # Wait for event
#[inline(always)]
pub fn wfe() {
    unsafe { core::arch::asm!("wfe", options(nomem, nostack)) }
}

/// # No Operation
#[inline(always)]
pub fn nop() {
    unsafe { core::arch::asm!("nop", options(nomem, nostack)) }
}

/// # Store u32 to memory address
#[inline]
pub fn store32(addr: u32, value: u32) {
    unsafe {
        *(addr as *mut u32) = value;
    }
}

/// # Read u32 from memory address
#[inline]
pub fn load32(addr: u32) -> u32 {
    unsafe { *(addr as *mut u32) }
}

/// # Spin CPU for `n` cycles
#[inline]
pub fn spin_for_n_cycles(n: u32) {
    unsafe {
        core::arch::asm!("1: subs r1, #1
				bne 1b", in("r1") n);
    }
}