mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
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.
This commit is contained in:
parent
a7912b6296
commit
ee695d0181
1 changed files with 22 additions and 15 deletions
|
|
@ -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<u64> {
|
||||
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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue