mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
fix suspend/resume issue with RTC (forgot to mask out bits on control register)
This commit is contained in:
parent
ee695d0181
commit
ed8f4d71cf
3 changed files with 24 additions and 11 deletions
|
|
@ -217,9 +217,9 @@ pub fn rtc_to_seconds(settings: &[u8]) -> Option<u64> {
|
|||
// note 5 is skipped - this is weekdays, and is unused
|
||||
const MONTHS: usize = 6;
|
||||
const YEARS: usize = 7;
|
||||
if (settings[CTL3] != (Control3::BATT_STD_BL_EN).bits()) // power switchover setting should be initialized
|
||||
if ((settings[CTL3] & 0xE0) != (Control3::BATT_STD_BL_EN).bits()) // power switchover setting should be initialized
|
||||
|| (settings[SECS] & 0x80 != 0) { // clock integrity should be guaranteed
|
||||
log::error!("RTC is in an uninitialized state!");
|
||||
log::error!("RTC is in an uninitialized state!, {:?}", settings);
|
||||
return None;
|
||||
}
|
||||
// this is a secondary check -- I have seen RTC return non-sensical time results before
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ fn xmain() -> ! {
|
|||
let mut i2c = llio::I2c::new(&xns);
|
||||
let mut rtc_alarm_enabled = false;
|
||||
let mut wakeup_alarm_enabled = false;
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
|
||||
log::trace!("starting main loop");
|
||||
loop {
|
||||
|
|
@ -522,14 +523,26 @@ fn xmain() -> ! {
|
|||
// Note that we start the RTC at somewhere between 0-10 years, so in practice, a user can expect between 90-100 years
|
||||
// of continuous uptime service out of the RTC.
|
||||
let mut settings = [0u8; 8];
|
||||
match i2c.i2c_read(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL3, &mut settings, None) {
|
||||
Ok(llio::I2cStatus::ResponseReadOk) => {},
|
||||
_ => {
|
||||
log::error!("Couldn't read seconds from RTC!");
|
||||
xous::return_scalar2(msg.sender, 0x8000_0000, 0).expect("couldn't return to caller");
|
||||
continue;
|
||||
},
|
||||
};
|
||||
let mut success = false;
|
||||
while !success {
|
||||
// retry loop is necessary because this function can get called during "congested" periods
|
||||
match i2c.i2c_read(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL3, &mut settings, None) {
|
||||
Ok(llio::I2cStatus::ResponseReadOk) => success = true,
|
||||
Err(xous::Error::ServerQueueFull) => {
|
||||
success = false;
|
||||
// give it a short pause before trying again, to avoid hammering the I2C bus at busy times
|
||||
tt.sleep_ms(38).unwrap();
|
||||
},
|
||||
_ => {
|
||||
log::error!("Couldn't read seconds from RTC!");
|
||||
xous::return_scalar2(msg.sender, 0x8000_0000, 0).expect("couldn't return to caller");
|
||||
break;
|
||||
},
|
||||
};
|
||||
}
|
||||
if !success {
|
||||
continue
|
||||
}
|
||||
log::debug!("GetRtcValue regs: {:?}", settings);
|
||||
let total_secs = match rtc_to_seconds(&settings) {
|
||||
Some(s) => s,
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ pub fn start_time_server() {
|
|||
}
|
||||
|
||||
fn is_rtc_invalid(settings: &[u8]) -> bool {
|
||||
(settings[CTL3] != (Control3::BATT_STD_BL_EN).bits()) // power switchover setting should be initialized
|
||||
((settings[CTL3] & 0xE0) != (Control3::BATT_STD_BL_EN).bits()) // power switchover setting should be initialized
|
||||
|| ((settings[SECS] & 0x80) != 0) // clock integrity should be guaranteed
|
||||
|| (to_binary(settings[SECS]) > 59)
|
||||
|| (to_binary(settings[MINS]) > 59)
|
||||
|
|
|
|||
Loading…
Reference in a new issue