mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
convert to UTRA abstraction
This commit is contained in:
parent
fc02a3e4e1
commit
2fdc83b588
1 changed files with 13 additions and 17 deletions
|
|
@ -9,12 +9,12 @@ use utralib::generated::*;
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
fn timer_tick(_irq_no: usize, _arg: *mut usize) {
|
fn timer_tick(_irq_no: usize, _arg: *mut usize) {
|
||||||
println!(">>> Timer tick");
|
println!(">>> Timer tick");
|
||||||
let ptr = TIMER_BASE as *mut usize;
|
let mut timer = CSR::new(TIMER_BASE as *mut u32);
|
||||||
|
|
||||||
xous::rsyscall(xous::SysCall::ReturnToParentI(xous::PID::new(1).unwrap(), 0)).expect("couldn't return to parent");
|
xous::rsyscall(xous::SysCall::ReturnToParentI(xous::PID::new(1).unwrap(), 0)).expect("couldn't return to parent");
|
||||||
|
|
||||||
// acknowledge the timer
|
// acknowledge the timer
|
||||||
unsafe { ptr.add(6).write_volatile(1) };
|
timer.wfo(utra::timer0::EV_PENDING_PENDING, 0b1);
|
||||||
println!("<<< Returning from timer_tick()");
|
println!("<<< Returning from timer_tick()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,7 +23,7 @@ pub fn init() {
|
||||||
use xous::{MemoryAddress, MemorySize};
|
use xous::{MemoryAddress, MemorySize};
|
||||||
println!("Allocating timer...");
|
println!("Allocating timer...");
|
||||||
xous::rsyscall(xous::SysCall::MapMemory(
|
xous::rsyscall(xous::SysCall::MapMemory(
|
||||||
MemoryAddress::new(HW_TIMER0_BASE),
|
MemoryAddress::new(utra::timer0::HW_TIMER0_BASE),
|
||||||
MemoryAddress::new(TIMER_BASE),
|
MemoryAddress::new(TIMER_BASE),
|
||||||
MemorySize::new(4096).unwrap(),
|
MemorySize::new(4096).unwrap(),
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
|
@ -39,13 +39,13 @@ pub fn init() {
|
||||||
|
|
||||||
let ms = 100; // tick every 100 ms
|
let ms = 100; // tick every 100 ms
|
||||||
en(false);
|
en(false);
|
||||||
load(SYSTEM_CLOCK_FREQUENCY / 1_000 * ms);
|
load((SYSTEM_CLOCK_FREQUENCY / 1_000) * ms);
|
||||||
reload(SYSTEM_CLOCK_FREQUENCY / 1_000 * ms);
|
reload((SYSTEM_CLOCK_FREQUENCY / 1_000) * ms);
|
||||||
en(true);
|
en(true);
|
||||||
|
|
||||||
// Set EV_ENABLE
|
// Set EV_ENABLE
|
||||||
let mut timer = CSR::new(TIMER_BASE as *mut u32);
|
let mut timer = CSR::new(TIMER_BASE as *mut u32);
|
||||||
unsafe { timer.wfo(utra::timer0::EV_ENABLE_ENABLE, 0b1); }
|
timer.wfo(utra::timer0::EV_ENABLE_ENABLE, 0b1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(baremetal))]
|
#[cfg(not(baremetal))]
|
||||||
|
|
@ -53,26 +53,22 @@ pub fn init() {}
|
||||||
|
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
pub fn load(value: u32) {
|
pub fn load(value: u32) {
|
||||||
let ptr = TIMER_BASE as *mut usize;
|
let mut timer = CSR::new(TIMER_BASE as *mut u32);
|
||||||
unsafe {
|
timer.wfo(utra::timer0::LOAD_LOAD, value);
|
||||||
ptr.add(0).write_volatile(value as usize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
pub fn reload(value: u32) {
|
pub fn reload(value: u32) {
|
||||||
let ptr = TIMER_BASE as *mut usize;
|
let mut timer = CSR::new(TIMER_BASE as *mut u32);
|
||||||
unsafe {
|
timer.wfo(utra::timer0::RELOAD_RELOAD, value);
|
||||||
ptr.add(1).write_volatile(value as usize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
pub fn en(en: bool) {
|
pub fn en(en: bool) {
|
||||||
let ptr = TIMER_BASE as *mut usize;
|
let mut timer = CSR::new(TIMER_BASE as *mut u32);
|
||||||
if en {
|
if en {
|
||||||
unsafe { ptr.add(2).write_volatile(1) };
|
timer.wfo(utra::timer0::EN_EN, 0b1);
|
||||||
} else {
|
} else {
|
||||||
unsafe { ptr.add(2).write_volatile(0) };
|
timer.wfo(utra::timer0::EN_EN, 0b0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue