Skip to content

Commit acc810a

Browse files
committed
src: Disable PM mode during wifi join.
Had a few reports that joining wifi can be very slow. Disabling power management seems to fix the problem. The PM mode is cleared when a join is started and restored when complete on success or failure. Fixes #9
1 parent 747ffcf commit acc810a

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/cyw43.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ typedef struct _cyw43_t {
103103
bool pend_disassoc;
104104
bool pend_rejoin;
105105
bool pend_rejoin_wpa;
106+
bool pend_restore_pm;
106107

107108
// AP settings
108109
uint32_t ap_auth;
@@ -124,6 +125,9 @@ typedef struct _cyw43_t {
124125

125126
// mac from otp (or from cyw43_hal_generate_laa_mac if not set)
126127
uint8_t mac[6];
128+
129+
// Power management setting, restored after connect
130+
uint32_t saved_pm;
127131
} cyw43_t;
128132

129133
extern cyw43_t cyw43_state;

src/cyw43_ctrl.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void cyw43_init(cyw43_t *self) {
103103
self->pend_disassoc = false;
104104
self->pend_rejoin = false;
105105
self->pend_rejoin_wpa = false;
106+
self->pend_restore_pm = false;
106107
self->ap_channel = 3;
107108
self->ap_ssid_len = 0;
108109
self->ap_key_len = 0;
@@ -235,6 +236,14 @@ STATIC void cyw43_poll_func(void) {
235236
self->wifi_join_state = WIFI_JOIN_STATE_ACTIVE;
236237
}
237238

239+
if (self->pend_restore_pm) {
240+
self->pend_restore_pm = false;
241+
if (self->saved_pm) {
242+
cyw43_wifi_pm(self, self->saved_pm);
243+
self->saved_pm = 0;
244+
}
245+
}
246+
238247
if (cyw43_sleep == 0) {
239248
cyw43_ll_bus_sleep(&self->cyw43_ll, true);
240249
#if !USE_SDIOIT && !CYW43_USE_SPI
@@ -409,6 +418,12 @@ void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev)
409418
self->wifi_join_state = WIFI_JOIN_STATE_ACTIVE;
410419
cyw43_cb_tcpip_set_link_up(self, CYW43_ITF_STA);
411420
}
421+
422+
// Restore power management value after wifi join
423+
if ((self->wifi_join_state & WIFI_JOIN_STATE_KIND_MASK) != 0 && self->saved_pm) {
424+
self->pend_restore_pm = true;
425+
cyw43_schedule_internal_poll_dispatch(cyw43_poll_func);
426+
}
412427
}
413428

414429
/*******************************************************************************/
@@ -604,6 +619,11 @@ int cyw43_wifi_join(cyw43_t *self, size_t ssid_len, const uint8_t *ssid, size_t
604619
return ret;
605620
}
606621

622+
// Disable power management while connecting
623+
if (cyw43_wifi_get_pm(self, &self->saved_pm) == 0) {
624+
cyw43_wifi_pm(self, self->saved_pm & ~0xf);
625+
}
626+
607627
ret = cyw43_ll_wifi_join(&self->cyw43_ll, ssid_len, ssid, key_len, key, auth_type, bssid, channel);
608628

609629
if (ret == 0) {

0 commit comments

Comments
 (0)