use crate::hal::generic::timer::TimerControl;
use crate::hal::generic::timer::TimerMode::Periodic;
use crate::event::OxideEventQueue;
use crate::deviceconsts::my::{ MASTER_CLOCK_PRESCALER, MASTER_CLOCK_HZ, MASTER_TICK_PERIOD_CS };
pub struct MasterClock<T>
where
T: 'static + TimerControl
{
timer: &'static mut T,
eventq: &'static OxideEventQueue
}
impl<T> MasterClock<T>
where
T: TimerControl
{
pub fn new(timer: &'static mut T, eventq: &'static OxideEventQueue) -> Self {
const PERIPHERAL_CLOCK_HZ: u32 = MASTER_CLOCK_HZ/MASTER_CLOCK_PRESCALER as u32;
const TIMER_CLOCK_HZ: u32 = PERIPHERAL_CLOCK_HZ/2; const CYCLES_PER_CS: u16 = (TIMER_CLOCK_HZ/100) as u16;
Self {
timer: timer.mode(Periodic).count_max(CYCLES_PER_CS).interrupting(MASTER_TICK_PERIOD_CS),
eventq
}
}
pub fn run(&mut self) {
self.timer.start(Some(|_ticks:u16| {
true
}));
}
}