Repository: raspberrypi/pico-sdk
File: src/rp2_common/pico_cyw43_driver/cyw43_driver.c (C)

Code before:
#include "hardware/gpio.h"
#include "hardware/irq.h"
#include "pico/unique_id.h"
#include "cyw43.h"
#include "pico/cyw43_driver.h"
#include "pico/async_context.h"

#ifndef CYW43_GPIO_IRQ_HANDLER_PRIORITY
#define CYW43_GPIO_IRQ_HANDLER_PRIORITY 0x40
#endif

#ifndef CYW43_SLEEP_CHECK_MS
#define CYW43_SLEEP_CHECK_MS 50
#endif

static async_context_t *cyw43_async_context = NULL;

#if CYW43_USE_PARTITION_FIRMWARE
    #include "pico/bootrom.h"
    #include "hardware/flash.h"
    #include "boot/picobin.h"
    #include <stdlib.h>

    // PICO_CONFIG: CYW43_WIFI_FW_PARTITION_ID, ID of Wi-Fi firmware partition, type=int, default=0x776966696669726d (wififirm), group=pico_cyw43_driver
    #ifndef CYW43_WIFI_FW_PARTITION_ID
    #define CYW43_WIFI_FW_PARTITION_ID 0x776966696669726d // wififirm
    #endif

    int32_t cyw43_wifi_fw_len;
    int32_t cyw43_clm_len;
    uintptr_t fw_data;
#endif

static void cyw43_sleep_timeout_reached(async_context_t *context, async_at_time_worker_t *worker);
static void cyw43_do_poll(async_context_t *context, async_when_pending_worker_t *worker);

static async_at_time_worker_t sleep_timeout_worker = {
        .do_work = cyw43_sleep_timeout_reached
};

static async_when_pending_worker_t cyw43_poll_worker = {
        .do_work = cyw43_do_poll
};

static void cyw43_set_irq_enabled(bool enabled) {
    gpio_set_irq_enabled(CYW43_PIN_WL_HOST_WAKE, GPIO_IRQ_LEVEL_HIGH, enabled);
}

// GPIO interrupt handler to tell us there's cyw43 has work to do
static void cyw43_gpio_irq_handler(void)
{

Review comment (suggestion):
I was humming an hah-ing about this, as i don't know whether we want

a) this to be generic (so that different WiFi chips can use the same ID)
b) non-specific with version info, so people can search for the right partition

I think for now this is OK (even though the code is cyw43_ specific) as we can always change it in the future

Code after:
#include "hardware/gpio.h"
#include "hardware/irq.h"
#include "pico/unique_id.h"
#include "cyw43.h"
#include "pico/cyw43_driver.h"
#include "pico/async_context.h"

#ifndef CYW43_GPIO_IRQ_HANDLER_PRIORITY
#define CYW43_GPIO_IRQ_HANDLER_PRIORITY 0x40
#endif

#ifndef CYW43_SLEEP_CHECK_MS
#define CYW43_SLEEP_CHECK_MS 50
#endif

static async_context_t *cyw43_async_context = NULL;

#if CYW43_USE_FIRMWARE_PARTITION
    #include "pico/bootrom.h"
    #include "hardware/flash.h"
    #include "boot/picobin.h"
    #include <stdlib.h>

    int32_t cyw43_wifi_fw_len;
    int32_t cyw43_clm_len;
    uintptr_t fw_data;
#endif

static void cyw43_sleep_timeout_reached(async_context_t *context, async_at_time_worker_t *worker);
static void cyw43_do_poll(async_context_t *context, async_when_pending_worker_t *worker);

static async_at_time_worker_t sleep_timeout_worker = {
        .do_work = cyw43_sleep_timeout_reached
};

static async_when_pending_worker_t cyw43_poll_worker = {
        .do_work = cyw43_do_poll
};

static void cyw43_set_irq_enabled(bool enabled) {
    gpio_set_irq_enabled(CYW43_PIN_WL_HOST_WAKE, GPIO_IRQ_LEVEL_HIGH, enabled);
}

// GPIO interrupt handler to tell us there's cyw43 has work to do
static void cyw43_gpio_irq_handler(void)
{
    uint32_t events = gpio_get_irq_event_mask(CYW43_PIN_WL_HOST_WAKE);
    if (events & GPIO_IRQ_LEVEL_HIGH) {
        // As we use a high level interrupt, it will go off forever until it's serviced
        // So disable the interrupt until this is done. It's re-enabled again by CYW43_POST_POLL_HOOK
        // which is called at the end of cyw43_poll_func