Add timeout macro to simplify timeout logic

This commit is contained in:
Jeremy Soller
2020-02-20 21:09:10 -07:00
parent 85e7225e95
commit 369a695bd9
5 changed files with 76 additions and 44 deletions

View File

@ -1,8 +1,11 @@
use hwio::{Io, Pio};
use crate::error::Error;
use crate::super_io::SuperIo;
use crate::timeout::Timeout;
use crate::{
Error,
SuperIo,
Timeout,
timeout
};
#[derive(Clone, Copy, Debug)]
#[repr(u8)]
@ -96,27 +99,8 @@ impl<T: Timeout> Ec<T> {
pub unsafe fn command(&mut self, cmd: EcCmd) -> Result<(), Error> {
self.timeout.reset();
while self.timeout.running() {
match self.command_start(cmd) {
Ok(()) => break,
Err(err) => match err {
Error::WouldBlock => (),
_ => return Err(err)
},
}
}
while self.timeout.running() {
match self.command_finish() {
Ok(ok) => return Ok(ok),
Err(err) => match err {
Error::WouldBlock => (),
_ => return Err(err)
},
}
}
Err(Error::Timeout)
timeout!(self.timeout, self.command_start(cmd))?;
timeout!(self.timeout, self.command_finish())
}
/// Probe for EC