From ee695d018139ba343027fa0fea9d1fa23d6c7672 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 27 Mar 2022 17:08:16 +0800 Subject: [PATCH] turn off time init check after it returns true this reduces a bit of message chatter for a call that may be called quite frequently. --- services/llio/src/lib.rs | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/services/llio/src/lib.rs b/services/llio/src/lib.rs index 8c5ff92f4..4909093e4 100644 --- a/services/llio/src/lib.rs +++ b/services/llio/src/lib.rs @@ -16,6 +16,7 @@ static TIME_REFCOUNT: AtomicU32 = AtomicU32::new(0); pub struct LocalTime { conn: xous::CID, warn_count: u32, + time_init: bool, } impl LocalTime { pub fn new() -> LocalTime { @@ -24,31 +25,37 @@ impl LocalTime { LocalTime { conn, warn_count: 0, + time_init: false, } } /// Returns the local time as milliseconds since EPOCH, assuming the time zone is set /// This is provided because we don't have a `libc` to do time zone lookups with `Chrono`. pub fn get_local_time_ms(&mut self) -> Option { - match xous::send_message(self.conn, - xous::Message::new_blocking_scalar( - 6, // WallClockTimeInit -- this should not change because it's a libstd mapping - 0, 0, 0, 0 - ) - ).expect("couldn't get init status") { - xous::Result::Scalar1(is_init) => { - if is_init == 0 { - if self.warn_count < 10 || (self.warn_count & 0xff) == 0 { - log::warn!("Time offsets are not initialized, can't report local time"); + if !self.time_init { + match xous::send_message(self.conn, + xous::Message::new_blocking_scalar( + 6, // WallClockTimeInit -- this should not change because it's a libstd mapping + 0, 0, 0, 0 + ) + ).expect("couldn't get init status") { + xous::Result::Scalar1(is_init) => { + if is_init == 0 { + if self.warn_count < 10 || (self.warn_count & 0xff) == 0 { + log::warn!("Time offsets are not initialized, can't report local time"); + } + self.warn_count += 1; + return None; } - self.warn_count += 1; + } + _ => { + log::error!("error retrieving time"); return None; } } - _ => { - log::error!("error retrieving time"); - return None; - } } + // if we got here, time was initialized. Set a flag so we don't check again in the future. + // this reduces the chatter of messages that may routinely happen, e.g. for getting seconds updates on the RTC. + self.time_init = true; match xous::send_message(self.conn, xous::Message::new_blocking_scalar( 4,