diff --git a/services/com/src/lib.rs b/services/com/src/lib.rs index 396eb75ff..f05ea69ef 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -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 { + 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 { diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 0ddf83700..19928a8a9 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -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);