From c69b9e451d7bf206f0d20402107e7c44cf6b8711 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 28 Mar 2022 04:04:38 +0800 Subject: [PATCH] unbreak hosted mode --- services/llio/src/main.rs | 13 +++++++++++++ services/pddb/src/main.rs | 6 ++++++ services/status/src/main.rs | 13 ------------- services/status/src/time.rs | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 6b087636b..73b278ff1 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -513,6 +513,7 @@ fn xmain() -> ! { i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL2, &[control2]).expect("RTC access error"); xous::return_scalar(msg.sender, 0).expect("couldn't return to caller"); }), + #[cfg(any(target_os = "none", target_os = "xous"))] Some(Opcode::GetRtcValue) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { // There is a possibility that the RTC hardware is actually in an invalid state. // Thus, this will return a u64 which is formatted as follows: @@ -556,6 +557,18 @@ fn xmain() -> ! { (total_secs & 0xFFFF_FFFF) as usize, ).expect("couldn't return to caller"); }), + #[cfg(not(any(target_os = "none", target_os = "xous")))] + Some(Opcode::GetRtcValue) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { + use chrono::prelude::*; + let now = Local::now(); + let total_secs = now.timestamp_millis() - 148409348; // sets the offset to something like 1974, which is roughly where an RTC value ends up in reality + xous::return_scalar2(msg.sender, + ((total_secs >> 32) & 0xFFFF_FFFF) as usize, + (total_secs & 0xFFFF_FFFF) as usize, + ).expect("couldn't return to caller"); + // use the tt variable so we don't get a warning + let _ = tt.elapsed_ms(); + }), Some(Opcode::Quit) => { log::info!("Received quit opcode, exiting."); let dropconn = xous::connect(i2c_sid).unwrap(); diff --git a/services/pddb/src/main.rs b/services/pddb/src/main.rs index 58f651b56..470aab54d 100644 --- a/services/pddb/src/main.rs +++ b/services/pddb/src/main.rs @@ -1224,6 +1224,12 @@ fn try_mount_or_format(modals: &modals::Modals, pddb_os: &mut PddbOs, basis_cach #[cfg(not(any(target_os = "none", target_os = "xous")))] { pddb_os.pddb_format(false, Some(&modals)).expect("couldn't format PDDB"); + let _ = xous::send_message(time_resetter, + xous::Message::new_blocking_scalar( + 0, // the ID is "hard coded" using enumerated discriminants + 0, 0, 0, 0 + ) + ).expect("couldn't reset time"); pddb_os.dbg_dump(Some("full".to_string()), None); if let Some(sys_basis) = pddb_os.pddb_mount() { log::info!("PDDB mount operation finished successfully"); diff --git a/services/status/src/main.rs b/services/status/src/main.rs index bdac0c756..ea4d5783a 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -302,7 +302,6 @@ fn xmain() -> ! { let mut stats_phase: usize = 0; - let dt_pump_interval = 15; let charger_pump_interval = 180; let batt_interval; let secnotes_interval; @@ -514,18 +513,6 @@ fn xmain() -> ! { } } } - if (stats_phase % dt_pump_interval) == 2 { - // #[cfg(any(target_os = "none", target_os = "xous"))] - // TODO_RTC - // placeholder for the RTC request when it is ready - #[cfg(not(any(target_os = "none", target_os = "xous")))] - { - log::trace!("hosted request of date time - short circuiting server call"); - use chrono::prelude::*; - let now = Local::now(); - } - } - { // update the time field // have to clear the entire rectangle area, because the text has a variable width and dirty text will remain if the text is shortened gam.draw_rectangle(status_gid, time_rect).ok(); diff --git a/services/status/src/time.rs b/services/status/src/time.rs index d0a2381a7..b1031e140 100644 --- a/services/status/src/time.rs +++ b/services/status/src/time.rs @@ -41,13 +41,20 @@ const TIME_SERVER_UTC_OFFSET: &'static str = "utc_offset"; /// This is the offset from UTC to the display time zone. This can vary when the user changes time zones. pub(crate) const TIME_SERVER_TZ_OFFSET: &'static str = "tz_offset"; +#[allow(dead_code)] const CTL3: usize = 0; +#[allow(dead_code)] const SECS: usize = 1; +#[allow(dead_code)] const MINS: usize = 2; +#[allow(dead_code)] const HOURS: usize = 3; +#[allow(dead_code)] const DAYS: usize = 4; // note 5 is skipped - this is weekdays, and is unused +#[allow(dead_code)] const MONTHS: usize = 6; +#[allow(dead_code)] const YEARS: usize = 7; /// Do not modify the discriminants in this structure. They are used in `libstd` directly. @@ -293,6 +300,7 @@ pub fn start_time_server() { }); // this thread handles more sensitive operations on the RTC. + #[cfg(any(target_os = "none", target_os = "xous"))] thread::spawn({ let rtc_checked = rtc_checked.clone(); move || { @@ -359,8 +367,30 @@ pub fn start_time_server() { } } }); + + #[cfg(not(any(target_os = "none", target_os = "xous")))] + thread::spawn({ + let rtc_checked = rtc_checked.clone(); + move || { + let xns = xous_names::XousNames::new().unwrap(); + // we expect exactly one connection from the PDDB + let priv_sid = xns.register_name(pddb::TIME_SERVER_PDDB, Some(1)).expect("can't register server"); + rtc_checked.store(true, Ordering::SeqCst); + loop { + let msg = xous::receive_message(priv_sid).unwrap(); + match FromPrimitive::from_usize(msg.body.id()) { + Some(PrivTimeOp::ResetRtc) => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, { + log::warn!("RTC time reset command received. This does nothing in hosted mode"); + xous::return_scalar(msg.sender, 0).unwrap(); + }), + _ => log::error!("Time server private thread received unknown opcode: {:?}", msg), + } + } + } + }); } +#[allow(dead_code)] fn is_rtc_invalid(settings: &[u8]) -> bool { ((settings[CTL3] & 0xE0) != (Control3::BATT_STD_BL_EN).bits()) // power switchover setting should be initialized || ((settings[SECS] & 0x80) != 0) // clock integrity should be guaranteed @@ -372,9 +402,11 @@ fn is_rtc_invalid(settings: &[u8]) -> bool { || (to_binary(settings[YEARS]) > 99) } +#[allow(dead_code)] fn to_binary(bcd: u8) -> u8 { (bcd & 0xf) + ((bcd >> 4) * 10) } +#[allow(dead_code)] fn to_bcd(binary: u8) -> u8 { let mut lsd: u8 = binary % 10; if lsd > 9 {