Architecture for integrating the CYW43 driver (for the wireless on Pico W) and lwIP (for TCP/IP stack) into the SDK. It is also necessary for accessing the on-board LED on Pico W. More...
Modules | |
cyw43_driver | |
Driver used for Pico W wireless. | |
Macros | |
#define | cyw43_arch_lwip_check() cyw43_thread_lock_check() |
Checks the caller has any locks required for calling into lwIP. More... | |
Functions | |
int | cyw43_arch_init (void) |
Initialize the CYW43 architecture. More... | |
int | cyw43_arch_init_with_country (uint32_t country) |
Initialize the CYW43 architecture for use in a specific country. More... | |
void | cyw43_arch_deinit (void) |
De-initialize the CYW43 architecture. More... | |
async_context_t * | cyw43_arch_async_context (void) |
Return the current async_context currently in use by the cyw43_arch code. More... | |
void | cyw43_arch_set_async_context (async_context_t *context) |
Set the async_context to be used by the cyw43_arch_init. More... | |
async_context_t * | cyw43_arch_init_default_async_context (void) |
Initialize the default async_context for the current cyw43_arch type. More... | |
void | cyw43_arch_poll (void) |
Perform any processing required by the cyw43_driver or the TCP/IP stack. More... | |
void | cyw43_arch_wait_for_work_until (absolute_time_t until) |
Sleep until there is cyw43_driver work to be done. More... | |
uint32_t | cyw43_arch_get_country_code (void) |
Return the country code used to initialize cyw43_arch. More... | |
void | cyw43_arch_enable_sta_mode (void) |
Enables Wi-Fi STA (Station) mode. More... | |
void | cyw43_arch_enable_ap_mode (const char *ssid, const char *password, uint32_t auth) |
Enables Wi-Fi AP (Access point) mode. More... | |
int | cyw43_arch_wifi_connect_blocking (const char *ssid, const char *pw, uint32_t auth) |
Attempt to connect to a wireless access point, blocking until the network is joined or a failure is detected. More... | |
int | cyw43_arch_wifi_connect_bssid_blocking (const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth) |
Attempt to connect to a wireless access point specified by SSID and BSSID, blocking until the network is joined or a failure is detected. More... | |
int | cyw43_arch_wifi_connect_timeout_ms (const char *ssid, const char *pw, uint32_t auth, uint32_t timeout) |
Attempt to connect to a wireless access point, blocking until the network is joined, a failure is detected or a timeout occurs. More... | |
int | cyw43_arch_wifi_connect_bssid_timeout_ms (const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth, uint32_t timeout) |
Attempt to connect to a wireless access point specified by SSID and BSSID, blocking until the network is joined, a failure is detected or a timeout occurs. More... | |
int | cyw43_arch_wifi_connect_async (const char *ssid, const char *pw, uint32_t auth) |
Start attempting to connect to a wireless access point. More... | |
int | cyw43_arch_wifi_connect_bssid_async (const char *ssid, const uint8_t *bssid, const char *pw, uint32_t auth) |
Start attempting to connect to a wireless access point specified by SSID and BSSID. More... | |
void | cyw43_arch_gpio_put (uint wl_gpio, bool value) |
Set a GPIO pin on the wireless chip to a given value. More... | |
bool | cyw43_arch_gpio_get (uint wl_gpio) |
Read the value of a GPIO pin on the wireless chip. More... | |
static void | cyw43_arch_lwip_begin (void) |
Acquire any locks required to call into lwIP. More... | |
static void | cyw43_arch_lwip_end (void) |
Release any locks required for calling into lwIP. More... | |
static int | cyw43_arch_lwip_protect (int(*func)(void *param), void *param) |
sad Release any locks required for calling into lwIP More... | |
Architecture for integrating the CYW43 driver (for the wireless on Pico W) and lwIP (for TCP/IP stack) into the SDK. It is also necessary for accessing the on-board LED on Pico W.
Both the low level cyw43_driver
and the lwIP stack require periodic servicing, and have limitations on whether they can be called from multiple cores/threads.
pico_cyw43_arch
attempts to abstract these complications into several behavioral groups:
As of right now, lwIP is the only supported TCP/IP stack, however the use of pico_cyw43_arch
is intended to be independent of the particular TCP/IP stack used (and possibly Bluetooth stack used) in the future. For this reason, the integration of lwIP is handled in the base (pico_cyw43_arch
) library based on the #define CYW43_LWIP used by the cyw43_driver
.
pico_cyw43_arch
library no longer directly implements the distinct behavioral abstractions. This is now handled by the more general pico_async_context library. The user facing behavior of pico_cyw43_arch has not changed as a result of this implementation detail, however pico_cyw43_arch is now just a thin wrapper which creates an appropriate async_context and makes a simple call to add lwIP or cyw43_driver support as appropriate. You are free to perform this context creation and adding of lwIP, cyw43_driver or indeed any other additional future protocol/driver support to your async_context, however for now pico_cyw43_arch does still provide a few cyw43_ specific (i.e. Pico W) APIs for connection management, locking and GPIO interaction.cyw43_driver
and lwIP
support, please refer to the specific source files cyw43_arch_poll.c
, cyw43_arch_threadsafe_background.c
and cyw43_arch_freertos.c
.Whilst you can use the pico_cyw43_arch
library directly and specify CYW43_LWIP (and other defines) yourself, several other libraries are made available to the build which aggregate the defines and other dependencies for you:
pico_cyw43_arch_lwip_poll - For using the RAW lwIP API (in NO_SYS=1
mode) without any background processing or multi-core/thread safety.
The user must call pico_cyw43_poll periodically from their main loop.
This wrapper library:
CYW43_LWIP=1
to enable lwIP support in pico_cyw43_arch
and cyw43_driver
.PICO_CYW43_ARCH_POLL=1
to select the polling behavior.pico_lwip
as a dependency to pull in lwIP.pico_cyw43_arch_lwip_threadsafe_background - For using the RAW lwIP API (in NO_SYS=1
mode) with multi-core/thread safety, and automatic servicing of the cyw43_driver
and lwIP in background.
Calls into the cyw43_driver
high level API (cyw43.h) may be made from either core or from lwIP callbacks, however calls into lwIP (which is not thread-safe) other than those made from lwIP callbacks, must be bracketed with cyw43_arch_lwip_begin and cyw43_arch_lwip_end. It is fine to bracket calls made from within lwIP callbacks too; you just don't have to.
This wrapper library:
CYW43_LWIP=1
to enable lwIP support in pico_cyw43_arch
and cyw43_driver
PICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1
to select the thread-safe/non-polling behavior.This library can also be used under the RP2040 port of FreeRTOS with lwIP in NO_SYS=1
mode (allowing you to call cyw43_driver
APIs from any task, and to call lwIP from lwIP callbacks, or from any task if you bracket the calls with cyw43_arch_lwip_begin and cyw43_arch_lwip_end. Again, you should be careful about what you do in lwIP callbacks, as you cannot call most FreeRTOS APIs from within an IRQ context. Unless you have good reason, you should probably use the full FreeRTOS integration (with NO_SYS=0
) provided by pico_cyw43_arch_lwip_sys_freertos
.
pico_cyw43_arch_lwip_sys_freertos - For using the full lwIP API including blocking sockets in OS (NO_SYS=0
) mode, along with with multi-core/task/thread safety, and automatic servicing of the cyw43_driver
and the lwIP stack.
This wrapper library:
CYW43_LWIP=1
to enable lwIP support in pico_cyw43_arch
and cyw43_driver
.PICO_CYW43_ARCH_FREERTOS=1
to select the NO_SYS=0 lwip/FreeRTOS integrationLWIP_PROVIDE_ERRNO=1
to provide error numbers needed for compilation without an OSpico_lwip
as a dependency to pull in lwIP.Calls into the cyw43_driver
high level API (cyw43.h) may be made from any task or from lwIP callbacks, but not from IRQs. Calls into the lwIP RAW API (which is not thread safe) must be bracketed with cyw43_arch_lwip_begin and cyw43_arch_lwip_end. It is fine to bracket calls made from within lwIP callbacks too; you just don't have to.
pico_cyw43_arch_none - If you do not need the TCP/IP stack but wish to use the on-board LED.
This wrapper library:
CYW43_LWIP=0
to disable lwIP support in pico_cyw43_arch
and cyw43_driver
void cyw43_arch_lwip_check | ( | ) | cyw43_thread_lock_check() |
Checks the caller has any locks required for calling into lwIP.
The lwIP API is not thread safe. You should surround calls into the lwIP API with calls to cyw43_arch_lwip_begin and this method. Note these calls are not necessary (but harmless) when you are calling back into the lwIP API from an lwIP callback.
This method will assert in debug mode, if the above conditions are not met (i.e. it is not safe to call into the lwIP API)
async_context_t* cyw43_arch_async_context | ( | void | ) |
Return the current async_context currently in use by the cyw43_arch code.
void cyw43_arch_deinit | ( | void | ) |
De-initialize the CYW43 architecture.
This method de-initializes the cyw43_driver
code and de-initializes the lwIP stack (if it was enabled at build time). Note this method should always be called from the same core (or RTOS task, depending on the environment) as cyw43_arch_init.
Additionally if the cyw43_arch is using its own async_context instance, then that instance is de-initialized.
void cyw43_arch_enable_ap_mode | ( | const char * | ssid, |
const char * | password, | ||
uint32_t | auth | ||
) |
Enables Wi-Fi AP (Access point) mode.
This enables the Wi-Fi in Access Point mode such that connections can be made to the device by other Wi-Fi clients
ssid | the name for the access point |
password | the password to use or NULL for no password. |
auth | the authorization type to use when the password is enabled. Values are CYW43_AUTH_WPA_TKIP_PSK, CYW43_AUTH_WPA2_AES_PSK, or CYW43_AUTH_WPA2_MIXED_PSK (see CYW43_AUTH_) |
void cyw43_arch_enable_sta_mode | ( | void | ) |
Enables Wi-Fi STA (Station) mode.
This enables the Wi-Fi in \emStation mode such that connections can be made to other Wi-Fi Access Points
uint32_t cyw43_arch_get_country_code | ( | void | ) |
Return the country code used to initialize cyw43_arch.
bool cyw43_arch_gpio_get | ( | uint | wl_gpio | ) |
Read the value of a GPIO pin on the wireless chip.
wl_gpio | the GPIO number on the wireless chip |
void cyw43_arch_gpio_put | ( | uint | wl_gpio, |
bool | value | ||
) |
Set a GPIO pin on the wireless chip to a given value.
wl_gpio | the GPIO number on the wireless chip |
value | true to set the GPIO, false to clear it. |
int cyw43_arch_init | ( | void | ) |
Initialize the CYW43 architecture.
This method initializes the cyw43_driver
code and initializes the lwIP stack (if it was enabled at build time). This method must be called prior to using any other pico_cyw43_arch
, cyw43_driver
or lwIP functions.
PICO_CYW43_ARCH_DEFAULT_COUNTRY_CODE
which defaults to CYW43_COUNTRY_WORLDWIDE
. Worldwide settings may not give the best performance; consider setting PICO_CYW43_ARCH_DEFAULT_COUNTRY_CODE to a different value or calling cyw43_arch_init_with_countryBy default this method initializes the cyw43_arch code's own async_context by calling cyw43_arch_init_default_async_context, however the user can specify use of their own async_context by calling cyw43_arch_set_async_context() before calling this method
async_context_t* cyw43_arch_init_default_async_context | ( | void | ) |
Initialize the default async_context for the current cyw43_arch type.
This method initializes and returns a pointer to the static async_context associated with cyw43_arch. This method is called by cyw43_arch_init automatically if a different async_context has not been set by cyw43_arch_set_async_context
int cyw43_arch_init_with_country | ( | uint32_t | country | ) |
Initialize the CYW43 architecture for use in a specific country.
This method initializes the cyw43_driver
code and initializes the lwIP stack (if it was enabled at build time). This method must be called prior to using any other pico_cyw43_arch
, cyw43_driver
or lwIP functions.
By default this method initializes the cyw43_arch code's own async_context by calling cyw43_arch_init_default_async_context, however the user can specify use of their own async_context by calling cyw43_arch_set_async_context() before calling this method
country | the country code to use (see CYW43_COUNTRY_) |
|
inlinestatic |
Acquire any locks required to call into lwIP.
The lwIP API is not thread safe. You should surround calls into the lwIP API with calls to this method and cyw43_arch_lwip_end. Note these calls are not necessary (but harmless) when you are calling back into the lwIP API from an lwIP callback. If you are using single-core polling only (pico_cyw43_arch_poll) then these calls are no-ops anyway it is good practice to call them anyway where they are necessary.
|
inlinestatic |
Release any locks required for calling into lwIP.
The lwIP API is not thread safe. You should surround calls into the lwIP API with calls to cyw43_arch_lwip_begin and this method. Note these calls are not necessary (but harmless) when you are calling back into the lwIP API from an lwIP callback. If you are using single-core polling only (pico_cyw43_arch_poll) then these calls are no-ops anyway it is good practice to call them anyway where they are necessary.
|
inlinestatic |
sad Release any locks required for calling into lwIP
The lwIP API is not thread safe. You can use this method to wrap a function with any locking required to call into the lwIP API. If you are using single-core polling only (pico_cyw43_arch_poll) then there are no locks to required, but it is still good practice to use this function.
func | the function ta call with any required locks held |
param | parameter to pass to func |
func
void cyw43_arch_poll | ( | void | ) |
Perform any processing required by the cyw43_driver
or the TCP/IP stack.
This method must be called periodically from the main loop when using a polling style pico_cyw43_arch
(e.g. pico_cyw43_arch_lwip_poll
). It may be called in other styles, but it is unnecessary to do so.
void cyw43_arch_set_async_context | ( | async_context_t * | context | ) |
Set the async_context to be used by the cyw43_arch_init.
context | the async_context to be used |
void cyw43_arch_wait_for_work_until | ( | absolute_time_t | until | ) |
Sleep until there is cyw43_driver work to be done.
This method may be called by code that is waiting for an event to come from the cyw43_driver, and has no work to do, but would like to sleep without blocking any background work associated with the cyw43_driver.
until | the time to wait until if there is no work to do. |
int cyw43_arch_wifi_connect_async | ( | const char * | ssid, |
const char * | pw, | ||
uint32_t | auth | ||
) |
Start attempting to connect to a wireless access point.
This method tells the CYW43 driver to start connecting to an access point. You should subsequently check the status by calling cyw43_wifi_link_status.
ssid | the network name to connect to |
pw | the network password or NULL if there is no password required |
auth | the authorization type to use when the password is enabled. Values are CYW43_AUTH_WPA_TKIP_PSK, CYW43_AUTH_WPA2_AES_PSK, or CYW43_AUTH_WPA2_MIXED_PSK (see CYW43_AUTH_) |
int cyw43_arch_wifi_connect_blocking | ( | const char * | ssid, |
const char * | pw, | ||
uint32_t | auth | ||
) |
Attempt to connect to a wireless access point, blocking until the network is joined or a failure is detected.
ssid | the network name to connect to |
pw | the network password or NULL if there is no password required |
auth | the authorization type to use when the password is enabled. Values are CYW43_AUTH_WPA_TKIP_PSK, CYW43_AUTH_WPA2_AES_PSK, or CYW43_AUTH_WPA2_MIXED_PSK (see CYW43_AUTH_) |
int cyw43_arch_wifi_connect_bssid_async | ( | const char * | ssid, |
const uint8_t * | bssid, | ||
const char * | pw, | ||
uint32_t | auth | ||
) |
Start attempting to connect to a wireless access point specified by SSID and BSSID.
This method tells the CYW43 driver to start connecting to an access point. You should subsequently check the status by calling cyw43_wifi_link_status.
ssid | the network name to connect to |
bssid | the network BSSID to connect to or NULL if ignored |
password | the network password or NULL if there is no password required |
auth | the authorization type to use when the password is enabled. Values are CYW43_AUTH_WPA_TKIP_PSK, CYW43_AUTH_WPA2_AES_PSK, or CYW43_AUTH_WPA2_MIXED_PSK (see CYW43_AUTH_) |
int cyw43_arch_wifi_connect_bssid_blocking | ( | const char * | ssid, |
const uint8_t * | bssid, | ||
const char * | pw, | ||
uint32_t | auth | ||
) |
Attempt to connect to a wireless access point specified by SSID and BSSID, blocking until the network is joined or a failure is detected.
ssid | the network name to connect to |
bssid | the network BSSID to connect to or NULL if ignored |
password | the network password or NULL if there is no password required |
auth | the authorization type to use when the password is enabled. Values are CYW43_AUTH_WPA_TKIP_PSK, CYW43_AUTH_WPA2_AES_PSK, or CYW43_AUTH_WPA2_MIXED_PSK (see CYW43_AUTH_) |
int cyw43_arch_wifi_connect_bssid_timeout_ms | ( | const char * | ssid, |
const uint8_t * | bssid, | ||
const char * | pw, | ||
uint32_t | auth, | ||
uint32_t | timeout | ||
) |
Attempt to connect to a wireless access point specified by SSID and BSSID, blocking until the network is joined, a failure is detected or a timeout occurs.
ssid | the network name to connect to |
bssid | the network BSSID to connect to or NULL if ignored |
password | the network password or NULL if there is no password required |
auth | the authorization type to use when the password is enabled. Values are CYW43_AUTH_WPA_TKIP_PSK, CYW43_AUTH_WPA2_AES_PSK, or CYW43_AUTH_WPA2_MIXED_PSK (see CYW43_AUTH_) |
int cyw43_arch_wifi_connect_timeout_ms | ( | const char * | ssid, |
const char * | pw, | ||
uint32_t | auth, | ||
uint32_t | timeout | ||
) |
Attempt to connect to a wireless access point, blocking until the network is joined, a failure is detected or a timeout occurs.
ssid | the network name to connect to |
pw | the network password or NULL if there is no password required |
auth | the authorization type to use when the password is enabled. Values are CYW43_AUTH_WPA_TKIP_PSK, CYW43_AUTH_WPA2_AES_PSK, or CYW43_AUTH_WPA2_MIXED_PSK (see CYW43_AUTH_) |