mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +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 {
|
pub struct LocalTime {
|
||||||
conn: xous::CID,
|
conn: xous::CID,
|
||||||
warn_count: u32,
|
warn_count: u32,
|
||||||
|
time_init: bool,
|
||||||
}
|
}
|
||||||
impl LocalTime {
|
impl LocalTime {
|
||||||
pub fn new() -> LocalTime {
|
pub fn new() -> LocalTime {
|
||||||
|
|
@ -24,31 +25,37 @@ impl LocalTime {
|
||||||
LocalTime {
|
LocalTime {
|
||||||
conn,
|
conn,
|
||||||
warn_count: 0,
|
warn_count: 0,
|
||||||
|
time_init: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Returns the local time as milliseconds since EPOCH, assuming the time zone is set
|
/// 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`.
|
/// 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> {
|
pub fn get_local_time_ms(&mut self) -> Option<u64> {
|
||||||
match xous::send_message(self.conn,
|
if !self.time_init {
|
||||||
xous::Message::new_blocking_scalar(
|
match xous::send_message(self.conn,
|
||||||
6, // WallClockTimeInit -- this should not change because it's a libstd mapping
|
xous::Message::new_blocking_scalar(
|
||||||
0, 0, 0, 0
|
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) => {
|
).expect("couldn't get init status") {
|
||||||
if is_init == 0 {
|
xous::Result::Scalar1(is_init) => {
|
||||||
if self.warn_count < 10 || (self.warn_count & 0xff) == 0 {
|
if is_init == 0 {
|
||||||
log::warn!("Time offsets are not initialized, can't report local time");
|
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;
|
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,
|
match xous::send_message(self.conn,
|
||||||
xous::Message::new_blocking_scalar(
|
xous::Message::new_blocking_scalar(
|
||||||
4,
|
4,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue