make wf200 reset a blocking call so other status bits don't de-sync

This commit is contained in:
bunnie 2022-01-30 19:07:29 +08:00
parent 177ad38db2
commit 82a7b7ebb3
2 changed files with 21 additions and 4 deletions

View file

@ -226,10 +226,14 @@ impl Com {
send_message(self.conn, Message::new_scalar(Opcode::Wf200Disable.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ())
}
// as wifi_reset() re-initializes the wifi chip, call this after wifi_disable() to re-enable wifi
pub fn wifi_reset(&self) -> Result<(), xous::Error> {
send_message(self.conn, Message::new_scalar(Opcode::Wf200Reset.to_usize().unwrap(), 0, 0, 0, 0,)).expect("couldn't send reset opcode");
self.ticktimer.sleep_ms(2000).expect("failed in waiting for wifi chip to reset");
Ok(())
pub fn wifi_reset(&self) -> Result<usize, xous::Error> {
let ret = send_message(self.conn, Message::new_blocking_scalar(Opcode::Wf200Reset.to_usize().unwrap(), 0, 0, 0, 0,)).expect("couldn't send reset opcode");
if let xous::Result::Scalar1(time) = ret {
log::info!("WF200 reset took {}ms", time);
Ok(time)
} else {
Err(xous::Error::Timeout)
}
}
pub fn set_ssid_scanning(&self, enable: bool) -> Result<(), xous::Error> {
if enable {

View file

@ -670,8 +670,21 @@ fn xmain() -> ! {
}
}
Some(Opcode::Wf200Reset) => {
let start = ticktimer.elapsed_ms();
com.txrx(ComState::WF200_RESET.verb);
com.txrx(0);
loop {
com.txrx(ComState::LOOP_TEST.verb);
let ack = com.wait_txrx(ComState::LINK_READ.verb, Some(5000)); // should finish with 5 seconds
if (ack & 0xff) != 0x01 {
log::warn!("Wf200 reset took too long, trying to re-establish link sync...");
com.txrx(ComState::LINK_SYNC.verb);
ticktimer.sleep_ms(200).unwrap();
} else {
break;
}
}
xous::return_scalar(msg.sender, (ticktimer.elapsed_ms() - start) as usize).unwrap();
}
Some(Opcode::Wf200Disable) => {
com.txrx(ComState::WF200_RESET.verb);