Compare commits

..

No commits in common. "aa9379463207a02ee7ca4e597054a447b9a90232" and "22555017fe939aa0658c3facc2b5f667929d0fd1" have entirely different histories.

4 changed files with 10 additions and 35 deletions

View File

@ -72,7 +72,7 @@ pub fn main_core0() {
}
let mut flash = flash.stop();
let timer = libboard_zynq::timer::GlobalTimer::start();
let timer = libboard_zynq::timer::GlobalTimer::new();
let mut ddr = zynq::ddr::DdrRam::new();
#[cfg(not(feature = "target_zc706"))]
@ -268,11 +268,7 @@ pub fn main_core0() {
task::spawn(async move {
loop {
delay(&mut countdown, Milliseconds(1000)).await;
let timestamp = timer.get_us();
let seconds = timestamp / 1_000_000;
let micros = timestamp % 1_000_000;
println!("time: {:6}.{:06}s", seconds, micros);
println!("time: {} ms", timer.get_time().0);
}
});

View File

@ -92,7 +92,7 @@ register!(value_register, ValueRegister, RW, u32);
register_bits!(value_register, value, u32, 0, 31);
register!(global_timer_control, GlobalTimerControl, RW, u32);
register_bits!(global_timer_control, prescaler, u8, 8, 15);
register_bits!(global_timer_control, prescaler, u16, 8, 15);
register_bit!(global_timer_control, auto_increment_mode, 3);
register_bit!(global_timer_control, irq_enable, 2);
register_bit!(global_timer_control, comp_enablea, 1);

View File

@ -13,14 +13,7 @@ pub struct GlobalTimer {
}
impl GlobalTimer {
/// Get the potentially uninitialized timer
pub unsafe fn get() -> GlobalTimer {
let mut regs = mpcore::RegisterBlock::new();
GlobalTimer { regs }
}
/// Get the timer with a reset
pub fn start() -> GlobalTimer {
pub fn new() -> GlobalTimer {
let mut regs = mpcore::RegisterBlock::new();
Self::reset(&mut regs);
GlobalTimer { regs }
@ -40,17 +33,12 @@ impl GlobalTimer {
mpcore::ValueRegister::zeroed()
);
// find a prescaler value that matches CPU speed / 2 to us
let clocks = Clocks::get();
let mut prescaler = clocks.cpu_3x2x() / 1_000_000;
while prescaler > 256 {
prescaler /= 2;
}
// Start
regs.global_timer_control.write(
mpcore::GlobalTimerControl::zeroed()
.prescaler((prescaler - 1) as u8)
// maximum prescaler is still enough for millisecond
// precision while overflowing after centuries.
.prescaler(255)
.auto_increment_mode(true)
.timer_enable(true)
);
@ -78,14 +66,6 @@ impl GlobalTimer {
Milliseconds(self.get_counter() * (prescaler + 1) / (clocks.cpu_3x2x() as u64 / 1000))
}
/// read with high precision
pub fn get_us(&self) -> u64 {
let prescaler = self.regs.global_timer_control.read().prescaler() as u64;
let clocks = Clocks::get();
1_000_000 * self.get_counter() * (prescaler + 1) / clocks.cpu_3x2x() as u64
}
/// return a handle that has implements
/// `embedded_hal::timer::CountDown`
pub fn countdown(&self) -> CountDown {

View File

@ -1,6 +1,6 @@
//! A logger for the `log` crate
use libboard_zynq::{println, stdio, timer::GlobalTimer};
use libboard_zynq::{println, stdio};
pub static LOGGER: Logger = Logger;
@ -17,9 +17,8 @@ impl log::Log for Logger {
fn log(&self, record: &log::Record) {
if self.enabled(record.metadata()) {
let timestamp = unsafe {
GlobalTimer::get()
}.get_us();
// TODO: let timestamp = clock::get_us();
let timestamp = 0;
let seconds = timestamp / 1_000_000;
let micros = timestamp % 1_000_000;