try to trace down issue #61

This commit is contained in:
bunnie 2021-05-02 16:39:08 +08:00
parent a35392f35b
commit abf308e82d
2 changed files with 34 additions and 19 deletions

View file

@ -116,7 +116,6 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi
let mut rtc = rtc::Rtc::new(&xns).unwrap(); let mut rtc = rtc::Rtc::new(&xns).unwrap();
// TODO: debug why this is unreliable
rtc.clear_wakeup_alarm().unwrap(); // clear any wakeup alarm state, if it was set rtc.clear_wakeup_alarm().unwrap(); // clear any wakeup alarm state, if it was set
rtc.hook_rtc_callback(dt_callback).unwrap(); rtc.hook_rtc_callback(dt_callback).unwrap();

View file

@ -22,6 +22,8 @@ mod implementation {
use xous_ipc::Buffer; use xous_ipc::Buffer;
use num_traits::ToPrimitive; use num_traits::ToPrimitive;
const BLOCKING_I2C_TIMEOUT_MS: u64 = 50;
const ABRTCMC_I2C_ADR: u8 = 0x68; const ABRTCMC_I2C_ADR: u8 = 0x68;
const ABRTCMC_CONTROL1: u8 = 0x00; const ABRTCMC_CONTROL1: u8 = 0x00;
bitflags! { bitflags! {
@ -245,6 +247,7 @@ mod implementation {
llio: Llio, llio: Llio,
rtc_alarm_enabled: bool, rtc_alarm_enabled: bool,
wakeup_alarm_enabled: bool, wakeup_alarm_enabled: bool,
ticktimer: ticktimer_server::Ticktimer,
} }
impl Rtc { impl Rtc {
@ -256,6 +259,7 @@ mod implementation {
llio, llio,
rtc_alarm_enabled: false, rtc_alarm_enabled: false,
wakeup_alarm_enabled: false, wakeup_alarm_enabled: false,
ticktimer: ticktimer_server::Ticktimer::new().expect("can't connect to ticktimer"),
} }
} }
@ -342,28 +346,40 @@ mod implementation {
transaction.txbuf = Some(txbuf); transaction.txbuf = Some(txbuf);
transaction.txlen = 2; transaction.txlen = 2;
transaction.status = I2cStatus::RequestIncoming; transaction.status = I2cStatus::RequestIncoming;
transaction.timeout_ms = 50;
while self.llio.poll_i2c_busy().unwrap() {
xous::yield_slice();
}
let mut sent = false; let mut sent = false;
while !sent { let max_retries = 2;
match self.llio.send_i2c_request(transaction) { let mut retries = 0;
Ok(status) => { while (retries < max_retries) && !sent {
match status { while self.llio.poll_i2c_busy().unwrap() {
I2cStatus::ResponseInProgress => sent = true, xous::yield_slice();
I2cStatus::ResponseBusy => sent = false,
_ => {log::error!("try_send_i2c unhandled response"); return false;},
}
}
_ => {log::error!("try_send_i2c unhandled error"); return false;}
} }
xous::yield_slice(); let start = self.ticktimer.elapsed_ms();
while !sent {
match self.llio.send_i2c_request(transaction) {
Ok(status) => {
match status {
I2cStatus::ResponseInProgress => sent = true,
I2cStatus::ResponseBusy => sent = false,
_ => {log::error!("try_send_i2c unhandled response"); return false;},
}
}
_ => {log::error!("try_send_i2c unhandled error"); return false;}
}
if (self.ticktimer.elapsed_ms() - start > BLOCKING_I2C_TIMEOUT_MS) && !sent {
log::error!("I2C blocking write timed out, try {}/{}", retries+1, max_retries);
break;
}
xous::yield_slice();
}
while self.llio.poll_i2c_busy().unwrap() {
xous::yield_slice();
}
retries += 1;
} }
while self.llio.poll_i2c_busy().unwrap() {
xous::yield_slice(); sent
}
true
} }
/// wakeup self after designated number of seconds /// wakeup self after designated number of seconds