mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
split reset/init routines apart
this removes the initialized flag and hazard of double-calling the interrupt hook when you really meant to reset the block.
This commit is contained in:
parent
680c8b88c7
commit
6ef684fd8c
3 changed files with 21 additions and 23 deletions
|
|
@ -47,7 +47,9 @@ fn main() -> ! {
|
||||||
|
|
||||||
// Create a new ticktimer object
|
// Create a new ticktimer object
|
||||||
let mut ticktimer = XousTickTimer::new(ticktimer_client);
|
let mut ticktimer = XousTickTimer::new(ticktimer_client);
|
||||||
ticktimer.reset(); // make sure the time starts from zero; also maps interrupts (note HAL convention deviation, this combines .init() into a single call).
|
ticktimer.init(); // hooks interrupts; should be called only once.
|
||||||
|
|
||||||
|
ticktimer.reset(); // reset the time to 0
|
||||||
|
|
||||||
// register a suspend/resume listener
|
// register a suspend/resume listener
|
||||||
#[cfg(not(target_arch = "arm"))]
|
#[cfg(not(target_arch = "arm"))]
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,7 @@ impl XousTickTimer {
|
||||||
) -> Result<(), xous::Error> {
|
) -> Result<(), xous::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
pub fn init(&mut self) {}
|
||||||
pub fn suspend(&self) {}
|
pub fn suspend(&self) {}
|
||||||
pub fn resume(&self) {}
|
pub fn resume(&self) {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ use utralib::generated::*;
|
||||||
|
|
||||||
pub struct XousTickTimer {
|
pub struct XousTickTimer {
|
||||||
csr: utralib::CSR<u32>,
|
csr: utralib::CSR<u32>,
|
||||||
initialized: bool,
|
|
||||||
current_response: Option<TimerRequest>,
|
current_response: Option<TimerRequest>,
|
||||||
last_response: Option<TimerRequest>,
|
last_response: Option<TimerRequest>,
|
||||||
connection: xous::CID,
|
connection: xous::CID,
|
||||||
|
|
@ -74,7 +73,6 @@ impl XousTickTimer {
|
||||||
|
|
||||||
let mut xtt = XousTickTimer {
|
let mut xtt = XousTickTimer {
|
||||||
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
|
||||||
initialized: false,
|
|
||||||
current_response: None,
|
current_response: None,
|
||||||
last_response: None,
|
last_response: None,
|
||||||
connection,
|
connection,
|
||||||
|
|
@ -101,27 +99,24 @@ impl XousTickTimer {
|
||||||
pub fn clear_last_response(&mut self) {
|
pub fn clear_last_response(&mut self) {
|
||||||
self.last_response = None;
|
self.last_response = None;
|
||||||
}
|
}
|
||||||
/// This combines the functions normally found in .init() into the ticktimer reset routine.
|
pub fn init(&mut self) {
|
||||||
|
xous::claim_interrupt(
|
||||||
|
utra::ticktimer::TICKTIMER_IRQ,
|
||||||
|
handle_irq,
|
||||||
|
self as *mut XousTickTimer as *mut usize,
|
||||||
|
)
|
||||||
|
.expect("couldn't claim irq");
|
||||||
|
|
||||||
|
self.ticktimer_sr_manager
|
||||||
|
.push(RegOrField::Reg(utra::ticktimer::MSLEEP_TARGET0), None);
|
||||||
|
self.ticktimer_sr_manager
|
||||||
|
.push(RegOrField::Reg(utra::ticktimer::MSLEEP_TARGET1), None);
|
||||||
|
self.ticktimer_sr_manager
|
||||||
|
.push_fixed_value(RegOrField::Reg(utra::ticktimer::EV_PENDING), 0xFFFF_FFFF);
|
||||||
|
self.ticktimer_sr_manager
|
||||||
|
.push(RegOrField::Reg(utra::ticktimer::EV_ENABLE), None);
|
||||||
|
}
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
if ! self.initialized {
|
|
||||||
xous::claim_interrupt(
|
|
||||||
utra::ticktimer::TICKTIMER_IRQ,
|
|
||||||
handle_irq,
|
|
||||||
self as *mut XousTickTimer as *mut usize,
|
|
||||||
)
|
|
||||||
.expect("couldn't claim irq");
|
|
||||||
|
|
||||||
self.ticktimer_sr_manager
|
|
||||||
.push(RegOrField::Reg(utra::ticktimer::MSLEEP_TARGET0), None);
|
|
||||||
self.ticktimer_sr_manager
|
|
||||||
.push(RegOrField::Reg(utra::ticktimer::MSLEEP_TARGET1), None);
|
|
||||||
self.ticktimer_sr_manager
|
|
||||||
.push_fixed_value(RegOrField::Reg(utra::ticktimer::EV_PENDING), 0xFFFF_FFFF);
|
|
||||||
self.ticktimer_sr_manager
|
|
||||||
.push(RegOrField::Reg(utra::ticktimer::EV_ENABLE), None);
|
|
||||||
|
|
||||||
self.initialized = true;
|
|
||||||
}
|
|
||||||
self.csr.wfo(utra::ticktimer::CONTROL_RESET, 0b1);
|
self.csr.wfo(utra::ticktimer::CONTROL_RESET, 0b1);
|
||||||
self.csr.wo(utra::ticktimer::CONTROL, 0); // not paused, not reset -> free-run
|
self.csr.wo(utra::ticktimer::CONTROL, 0); // not paused, not reset -> free-run
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue