aboutsummaryrefslogtreecommitdiff
path: root/src/_arch/arm/asm.rs
blob: 5d53aa023612c6f72f970ec0e0b644fb7565a1a2 (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
41
42
43
44
45
46
//! # 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);
	}
}