drivers/cyw43: Fix cyw43_deinit so it can be called many times in a row.

This makes sure deinit() can be called on the interface many times without
error, and that the state of the driver is fully reset.

Fixes issue #7493.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-08-27 18:06:26 +10:00
parent 6f19b9c08d
commit 52a78e6965
1 changed files with 10 additions and 13 deletions

View File

@ -102,28 +102,25 @@ void cyw43_init(cyw43_t *self) {
} }
void cyw43_deinit(cyw43_t *self) { void cyw43_deinit(cyw43_t *self) {
if (cyw43_poll == NULL) {
return;
}
CYW_ENTER CYW_ENTER
cyw43_ll_bus_sleep(&self->cyw43_ll, true); // Stop the TCP/IP network interfaces.
cyw43_delay_ms(2);
cyw43_tcpip_deinit(self, 0); cyw43_tcpip_deinit(self, 0);
cyw43_tcpip_deinit(self, 1); cyw43_tcpip_deinit(self, 1);
self->itf_state = 0; // Turn off the SDIO bus.
#if USE_SDIOIT
// Disable async polling
sdio_enable_irq(false); sdio_enable_irq(false);
cyw43_poll = NULL;
#ifdef pyb_pin_WL_RFSW_VDD
// Turn the RF-switch off
mp_hal_pin_low(pyb_pin_WL_RFSW_VDD);
#endif #endif
// Power down the WL chip and the SDIO bus
mp_hal_pin_low(pyb_pin_WL_REG_ON);
sdio_deinit(); sdio_deinit();
// Power off the WLAN chip and make sure all state is reset.
cyw43_init(self);
CYW_EXIT CYW_EXIT
} }