![]() |
Wi-Fi Host Driver (WHD) Public API Reference Guide | |
The WHD is an independent, embedded Wi-Fi Host Driver that provides a set of APIs to interact with Infineon WLAN chips. The WHD is an independent firmware product that is easily portable to any embedded software environment, including popular IOT frameworks like Mbed OS, Amazon FreeRTOS, etc. Hence, the WHD includes hooks for RTOS and TCP/IP network abstraction layers.
The WHD requires the following services:
The WHD consists of 3 different components as shown in the following architectural diagram. Blocks highlighted in red are external dependencies for the WHD, blue ones are Porting layer and black ones are WHD core.
To port the WHD, implement the following APIs or Function Pointers (shown in the the WHD Architecture section diagram), so that the WHD is functional:
The CY RTOS API provides prototypes for functions that allow the WHD to use RTOS functionality, such as threads, semaphores, and timing functions.
You must implement the appropriate functions in your code. See here for an example implementation.
Function |
Description |
cy_rtos_create_thread |
Create RTOS thread. The WHD calls this function to create the main WHD thread. |
cy_rtos_terminate_thread |
Terminate the RTOS thread. The WHD calls this function to terminate WHD main thread created using cy_rtos_create_thread. It is called after calling cy_rtos_join_thread(). |
cy_rtos_join_thread |
Join the RTOS thread. The WHD calls this function so that any resources that were allocated for it are cleaned up. It is called by WHD before cy_rtos_terminate_thread() |
cy_rtos_get_time |
To provide time in milliseconds since RTOS start The WHD uses this to get the time in milliseconds. |
cy_rtos_delay_milliseconds |
Delay for a specified number of milliseconds. The WHD calls this function to obtain the time delay. |
cy_rtos_init_semaphore |
Create a semaphore. The WHD uses only binary semaphore, this function is used to init a semaphore |
cy_rtos_get_semaphore |
Get/Acquire a semaphore |
cy_rtos_set_semaphore |
Set/Release a semaphore |
cy_rtos_deinit_semaphore |
Deletes a semaphore This function frees the resources associated with a semaphore. |
The Wi-Fi firmware, NVRAM, and CLM BLOB information are treated as resources to be downloaded onto the Wi-Fi chip. Refer to the file inc\whd_resource_api.h for a detailed description.
You must implement the appropriate function pointers in your code. See here for an example implementation.
Function |
Description |
whd_resource_size |
Gets the size of the resource for respective resource type |
whd_get_resource_block |
Gets the resource block for specified resource type |
whd_get_resource_no_of_blocks |
Gets block count for the specified resource_type |
whd_get_resource_block_size |
Gets block size for the specified resource_type |
The WHD requires packet buffers to exchange information between the host and Wi-Fi firmware. Refer to the file inc\whd_network_types.h for a detailed description.
You must implement the appropriate function pointers in your code. See here for an example implementation.
Function |
Description |
whd_host_buffer_get | Allocates a packet buffer You can implement this function by allocating a pre-existing packet from a pool, using a static buffer, or by dynamically allocating memory. The method chosen must match the way the network stack expects packet buffers to be allocated. Usually, the WHD requires a packet of size of WHD_LINK_MTU which includes the MTU and various other headers. Refer to whd_types.h to find the size of WHD_LINK_MTU. The following include expected return error codes other than WHD_SUCCESS:
|
whd_buffer_release |
Releases a packet buffer The WHD uses this function to indicate that it no longer requires a packet buffer. The buffer can then be released back into a pool for reuse, or the dynamically allocated memory can be freed, according to how the packet was allocated. |
whd_buffer_get_current_piece_data_pointer |
Retrieves the current pointer of a packet buffer Since packet buffers usually need to be created with space at the front for additional headers, this function allows the WHD to get the current 'front' location pointer. |
whd_buffer_get_current_piece_size |
Retrieves the size of a packet buffer Since packet buffers usually need to be created with space at the front for additional headers, the memory block used to contain a packet buffer will often be larger than the current size of the packet buffer data. This function allows the WHD to retrieve the current size of a packet buffer's data. |
whd_buffer_set_size |
Sets the current length of a WHD packet buffer. |
whd_buffer_add_remove_at_front |
Moves the current pointer of a packet buffer Since packet buffers usually need to be created with space at the front for additional headers, this function allows the WHD to move the current 'front' location pointer. This ensures that the WHD has space to add headers to transmit packets, and that the network stack does not see the internal WHD headers on received packets. |
The WHD calls this function pointer to pass the received TCP/IP data packet from WLAN. Refer to the file inc\whd_network_types.h for a detailed description.
You must implement the appropriate function pointers in your code. See here for an example implementation.
FUNCTION |
Description |
whd_network_process_ethernet_data |
The WHD calls this function pointer to pass received data to the network stack. You must provide the definition of the function. This function pointer is called asynchronously in the context of the WHD thread whenever new data has arrived. Packet buffers are allocated within the WHD, and ownership is transferred to the network stack. The network stack or application is thus responsible for releasing the packet buffers. Most packet buffering systems have a pointer to the 'current point' within the packet buffer. When this function is called, the pointer points to the start of the Ethernet header. There are other inconsequential data before the Ethernet header. It is preferable that you implement this function simply by putting the received packet on a queue for processing by another thread. This avoids the WHD thread being unnecessarily tied up which would delay other packets being transmitted or received. |
The WHD uses the following functions to access the host bus controller for SDIO or SPI buses.
You must implement these functions in your code. See here for an example implementation.
Based on the target environment implementation, replace and use these functions appropriately to ensure bus operations.
Function | Description |
cyhal_spi_register_irq | The SPI interrupt handler registration. |
cyhal_spi_transfer | Writes a block out and receives a value. The total number of bytes sent and received will be the maximum of tx_length and rx_length. The bytes written will be padded with the value 0xff. |
cyhal_spi_irq_enable | Configure SPI interrupt. This function is used for word-approach. |
cyhal_sdio_register_irq
| The SDIO interrupt handler registration. |
cyhal_sdio_irq_enable
| Configures the SDIO interrupt |
cyhal_sdio_send_cmd | Sends a command to the SDIO block. |
cyhal_sdio_bulk_transfer | Performs a bulk data transfer (CMD=53) to the SDIO block. |
Before starting the WHD, perform the following steps:
Toggle the WL_REG_ON pin shown in the WHD Power up sequence chart.
There are basically three modes of operation in WHD:
The following example code shows the program flow for execution in STA/AP mode:
The WHD supports STA+AP concurrent mode of operation. There is no support for STA+STA or AP+AP. For concurrent mode of operation, you need to create a secondary interface along with the primary interface. The primary interface must have an STA interface, and the secondary interface must have an AP interface. Running AP in the primary interface and running STA in the secondary interface is invalid.
The following example code shows the flow for execution in STA+AP concurrent mode:
The WHD supports WPA3/WPA2 transition mode. In this mode, if the WPA3 AP goes down and a WPA2 AP is started with the same SSID, the STA automatically transitions to join the WPA2 AP. This mode requires two security keys for the join to be completed.
The security keys can be the same or different,one key is for setting the psk passphrase, and second key is for setting WPA3 password but it is highly recommended to use different passwords.
The following example code shows the flow for execution in WPA3/WPA2 transition mode:
The WHD consists of various internal modules as shown in the following diagram and explained in the following sections. Once the WHD is powered up, the WLAN Bus specific init sequence is completed, and the WLAN chip is ready for operation.
This module downloads the WLAN Firmware, NVRAM, and CLM file using HAL Resource API. This module does not use the services of control or data path module. It directly accesses the "WHD Bus Interface" to write the resources. After download is completed, this module allows the WLAN firmware to run.
This module is responsible for obtaining the WLAN Chip logs using the WHD Debug APIs.
IOCTLs provide control access to the WLAN Chip, and this module routes all these control messages to/from the WLAN chip.
This module handles User Data received in the TCP/IP interface. It also to sends the User Data received from the WLAN Chip.
Event module handles the events generated from the WLAN chip. It also exposes a function for the application to register for limited set of events and process them.
Any packet sent to the WLAN chip needs to have a Protocol Header. Protocol Headers are of two types:
The protocol layer is bus independent and is required for either SDIO/SPI/USB.
CDC Layer The Control Module sends messages to this CDC layer, which adds a 16-byte header known as CDC header. The following shows the header details:
BDC Layer The User Data Module sends messages to the BDC Layer. It adds a 4-byte header known as the BDC header. The following shows the header details:
The Bus layer provides bus level protocol handling. For SDIO, a bus protocol known as SDPCM is used.
All the control or User Data is queued in a link list in this layer. Once the credit is available, this layer sends the data to WLAN chip. Also, this layer checks for any RX data from WLAN Chip and sends the data to host TCP/IP stack via its TCP/IP interface.
This module provides bus independent access functions to the packet engine/sdpcm layer. It is primarily used to keep the access functions common between SDIO/SPI.
Use the CY HAL interface to access the SDIO Host Controller Hardware. It is external to the WHD driver.
Use the CY HAL interface to access the SPI Host Controller Hardware. It is external to the WHD driver
The WHD provides services in the form of the WLAN API which can be used by layers above the WHD. Broadly, the WLAN API can be classified into the following:
Based on the functionality, APIs can be classified as follows: