libboard_zynq: add GlobalTimer::get_us(), use in libsupport_zynq::logger
This commit is contained in:
parent
fe6a058a6b
commit
aa93794632
@ -268,7 +268,11 @@ pub fn main_core0() {
|
||||
task::spawn(async move {
|
||||
loop {
|
||||
delay(&mut countdown, Milliseconds(1000)).await;
|
||||
println!("time: {} ms", timer.get_time().0);
|
||||
|
||||
let timestamp = timer.get_us();
|
||||
let seconds = timestamp / 1_000_000;
|
||||
let micros = timestamp % 1_000_000;
|
||||
println!("time: {:6}.{:06}s", seconds, micros);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -78,6 +78,14 @@ 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 {
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! A logger for the `log` crate
|
||||
|
||||
use libboard_zynq::{println, stdio};
|
||||
use libboard_zynq::{println, stdio, timer::GlobalTimer};
|
||||
|
||||
pub static LOGGER: Logger = Logger;
|
||||
|
||||
@ -17,8 +17,9 @@ impl log::Log for Logger {
|
||||
|
||||
fn log(&self, record: &log::Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
// TODO: let timestamp = clock::get_us();
|
||||
let timestamp = 0;
|
||||
let timestamp = unsafe {
|
||||
GlobalTimer::get()
|
||||
}.get_us();
|
||||
let seconds = timestamp / 1_000_000;
|
||||
let micros = timestamp % 1_000_000;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user