Skip to content

Commit

Permalink
src/cyw43_ll: Add event hooks during firmware load.
Browse files Browse the repository at this point in the history
Loading the WiFi firmware can cause delays on startup which causes problems
for tasks like USB that must be executed periodically.  Add some hooks to
allow such background processes to run.

See micropython/micropython#8904.

Fixes issue #11.
  • Loading branch information
peterharperuk authored and Damien George committed Jul 19, 2022
1 parent 59f84b2 commit cd4075f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cyw43_config.h
Expand Up @@ -102,3 +102,9 @@
#ifndef CYW43_FAIL_FAST_CHECK
#define CYW43_FAIL_FAST_CHECK(res) (res)
#endif

// This should be defined by the port if needed, to let background processes
// run during long blocking operations such as WiFi initialisation.
#ifndef CYW43_EVENT_POLL_HOOK
#define CYW43_EVENT_POLL_HOOK
#endif
6 changes: 6 additions & 0 deletions src/cyw43_ll.c
Expand Up @@ -466,6 +466,8 @@ static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t raw_
#endif

for (size_t offset = 0; offset < len; offset += block_size) {
CYW43_EVENT_POLL_HOOK;

size_t sz = block_size;
if (offset + sz > len) {
sz = len - offset;
Expand Down Expand Up @@ -1416,6 +1418,8 @@ static void cyw43_clm_load(cyw43_int_t *self, const uint8_t *clm_ptr, size_t clm

const size_t clm_dload_chunk_len = CLM_CHUNK_LEN;
for (size_t off = 0; off < clm_len; off += clm_dload_chunk_len) {
CYW43_EVENT_POLL_HOOK;

uint32_t len = clm_dload_chunk_len;
uint16_t flag = 1 << 12; // DLOAD_HANDLER_VER
if (off == 0) {
Expand Down Expand Up @@ -1497,7 +1501,9 @@ int cyw43_ll_bus_init(cyw43_ll_t *self_in, const uint8_t *mac) {
}

cyw43_spi_gpio_setup();
CYW43_EVENT_POLL_HOOK;
cyw43_spi_reset();
CYW43_EVENT_POLL_HOOK;

// Check test register can be read
for (int i = 0; i < 10; ++i) {
Expand Down

0 comments on commit cd4075f

Please sign in to comment.