aarch64: move function delay() into mod timer in crate bcm2837

master
equation314 6 years ago
parent 3e1d8c5827
commit 7b6173a7bd

@ -1,10 +0,0 @@
//! utility assembly instructions
/// delay for some clocks
#[inline]
pub unsafe fn delay(_clock: u32) {
#[cfg(target_arch = "aarch64")]
asm!("mov x1, x0; 1: subs x1, x1, #1; bne 1b;"
:: "{x0}"(_clock)
:: "volatile");
}

@ -1,5 +1,5 @@
use super::IO_BASE;
use super::asm::delay;
use IO_BASE;
use timer::delay;
use core::marker::PhantomData;
use volatile::{ReadOnly, Volatile, WriteOnly};
@ -84,16 +84,14 @@ impl<T> Gpio<T> {
/// Set the Gpio pull-up/pull-down state for values in `pin_value`
/// (ref: peripherals 6.1, page 101)
pub fn set_gpio_pd(&mut self, pud_value: u8) {
unsafe {
let index = if self.pin >= 32 { 1 } else { 0 };
self.registers.PUD.write(pud_value as u32);
delay(150);
self.registers.PUDCLK[index as usize].write((1 << self.pin) as u32);
delay(150);
self.registers.PUD.write(0);
self.registers.PUDCLK[index as usize].write(0);
}
let index = if self.pin >= 32 { 1 } else { 0 };
self.registers.PUD.write(pud_value as u32);
delay(150);
self.registers.PUDCLK[index as usize].write((1 << self.pin) as u32);
delay(150);
self.registers.PUD.write(0);
self.registers.PUDCLK[index as usize].write(0);
}
}

@ -1,4 +1,4 @@
use super::IO_BASE;
use IO_BASE;
use volatile::{ReadOnly, Volatile};
const INT_BASE: usize = IO_BASE + 0xB000 + 0x200;

@ -3,8 +3,6 @@
extern crate volatile;
mod asm;
pub mod gpio;
pub mod timer;
pub mod mini_uart;

@ -1,4 +1,4 @@
use super::IO_BASE;
use IO_BASE;
use gpio::{Function, Gpio};
use volatile::{ReadOnly, Volatile};

@ -24,3 +24,11 @@ pub fn current_time() -> u64 {
pub fn tick_in(us: u32) {
Timer::new().tick_in(us);
}
/// wait for `cycle` CPU cycles
#[inline(always)]
pub fn delay(cycle: u32) {
for _ in 0..cycle {
unsafe { asm!("nop") }
}
}

Loading…
Cancel
Save