have the core spinor routines automatically retry on failure

normally we never see these failures, but, as we are seeing
flash wear-out on the CI machine the writes can take
long enough that we get some concurrent requests. As a work-around,
just automatically retry a few times before throwing the error
back to the caller.
This commit is contained in:
bunnie 2022-10-28 02:55:42 +08:00
parent d63c452fb6
commit 0c7c90fb78

View file

@ -174,6 +174,8 @@ impl Spinor {
// acquire a write lock on the unit // acquire a write lock on the unit
#[cfg(not(test))] #[cfg(not(test))]
{ {
const RETRY_LIMIT: usize = 5;
for i in 0..RETRY_LIMIT {
let response = send_message(self.conn, let response = send_message(self.conn,
Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(), Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(),
self.token[0] as usize, self.token[0] as usize,
@ -184,8 +186,14 @@ impl Spinor {
).expect("couldn't send AcquireExclusive message to Spinor hardware!"); ).expect("couldn't send AcquireExclusive message to Spinor hardware!");
if let xous::Result::Scalar1(result) = response { if let xous::Result::Scalar1(result) = response {
if result == 0 { if result == 0 {
if i == RETRY_LIMIT - 1 {
return Err(SpinorError::BusyTryAgain) return Err(SpinorError::BusyTryAgain)
} }
xous::yield_slice();
} else {
break;
}
}
} }
} }
let be = BulkErase { let be = BulkErase {
@ -235,6 +243,8 @@ impl Spinor {
// acquire a write lock on the unit // acquire a write lock on the unit
#[cfg(not(test))] #[cfg(not(test))]
{ {
const RETRY_LIMIT: usize = 5;
for i in 0..RETRY_LIMIT {
let response = send_message(self.conn, let response = send_message(self.conn,
Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(), Message::new_blocking_scalar(Opcode::AcquireExclusive.to_usize().unwrap(),
self.token[0] as usize, self.token[0] as usize,
@ -245,8 +255,14 @@ impl Spinor {
).expect("couldn't send AcquireExclusive message to Spinor hardware!"); ).expect("couldn't send AcquireExclusive message to Spinor hardware!");
if let xous::Result::Scalar1(result) = response { if let xous::Result::Scalar1(result) = response {
if result == 0 { if result == 0 {
if i == RETRY_LIMIT - 1 {
return Err(SpinorError::BusyTryAgain) return Err(SpinorError::BusyTryAgain)
} }
xous::yield_slice();
} else {
break;
}
}
} }
} }