Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cyw43.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef struct _cyw43_t {
bool pend_disassoc;
bool pend_rejoin;
bool pend_rejoin_wpa;
bool pend_restore_pm;

// AP settings
uint32_t ap_auth;
Expand All @@ -126,6 +127,9 @@ typedef struct _cyw43_t {

// mac from otp (or from cyw43_hal_generate_laa_mac if not set)
uint8_t mac[6];

// Power management setting, restored after connect
uint32_t saved_pm;
} cyw43_t;

extern cyw43_t cyw43_state;
Expand Down
20 changes: 20 additions & 0 deletions src/cyw43_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void cyw43_init(cyw43_t *self) {
self->pend_disassoc = false;
self->pend_rejoin = false;
self->pend_rejoin_wpa = false;
self->pend_restore_pm = false;
self->ap_channel = 3;
self->ap_ssid_len = 0;
self->ap_key_len = 0;
Expand Down Expand Up @@ -235,6 +236,14 @@ STATIC void cyw43_poll_func(void) {
self->wifi_join_state = WIFI_JOIN_STATE_ACTIVE;
}

if (self->pend_restore_pm) {
self->pend_restore_pm = false;
if (self->saved_pm) {
cyw43_wifi_pm(self, self->saved_pm);
self->saved_pm = 0;
}
}

if (cyw43_sleep == 0) {
cyw43_ll_bus_sleep(&self->cyw43_ll, true);
#if !USE_SDIOIT && !CYW43_USE_SPI
Expand Down Expand Up @@ -409,6 +418,12 @@ void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev)
self->wifi_join_state = WIFI_JOIN_STATE_ACTIVE;
cyw43_cb_tcpip_set_link_up(self, CYW43_ITF_STA);
}

// Restore power management value after wifi join
if ((self->wifi_join_state & WIFI_JOIN_STATE_KIND_MASK) != 0 && self->saved_pm) {
self->pend_restore_pm = true;
cyw43_schedule_internal_poll_dispatch(cyw43_poll_func);
}
}

/*******************************************************************************/
Expand Down Expand Up @@ -611,6 +626,11 @@ int cyw43_wifi_join(cyw43_t *self, size_t ssid_len, const uint8_t *ssid, size_t
return ret;
}

// Disable power management while connecting
if (cyw43_wifi_get_pm(self, &self->saved_pm) == 0) {
cyw43_wifi_pm(self, self->saved_pm & ~0xf);
}

ret = cyw43_ll_wifi_join(&self->cyw43_ll, ssid_len, ssid, key_len, key, auth_type, bssid, channel);

if (ret == 0) {
Expand Down