This is the documentation for the latest (main) development branch. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

HSPI Slave API Reference

Macros

WM_DRV_HSPI_SLAVE_CMD_RX_BUF_SIZE

Size of command receive buffer

WM_DRV_HSPI_SLAVE_TX_BUF_SIZE

Size of transmit buffer

WM_DRV_HSPI_SLAVE_TX_BD_NUM

Number of transmit buffer descriptors

WM_DRV_HSPI_SLAVE_RX_BUF_SIZE

Size of receive buffer

WM_DRV_HSPI_SLAVE_RX_BD_NUM

Number of receive buffer descriptors

Enumerations

enum wm_drv_hspi_slave_event_t

HSPI slave event types.

Values:

enumerator WM_DRV_HSPI_SLAVE_EVENT_TX

Data transmit complete event

enumerator WM_DRV_HSPI_SLAVE_EVENT_RX

Data receive complete event

enumerator WM_DRV_HSPI_SLAVE_EVENT_TX_CMD

Command transmit complete event

enumerator WM_DRV_HSPI_SLAVE_EVENT_RX_CMD

Command receive complete event

enumerator WM_DRV_HSPI_SLAVE_EVENT_MAX

Type Definitions

typedef void (*wm_drv_hspi_slave_callback_t)(wm_device_t *dev, wm_drv_hspi_slave_event_t event, void *addr, void *priv)

HSPI slave event callback function type.

This callback function is invoked when HSPI slave events occur. The events include:

  • Data transmission complete (TX)

  • Data reception complete (RX)

  • Command transmission complete (TX CMD)

  • Command reception complete (RX CMD)

Param dev:

Device handle for the HSPI slave device

Param event:

Type of event that triggered the callback (TX/RX/TX_CMD/RX_CMD)

Param addr:

Buffer address containing the transmitted/received data or command

Param priv:

Private data pointer that was passed during callback registration

struct wm_drv_hspi_slave_cfg_t

HSPI slave configuration structure.

Param cpol:

This parameter can be a value of wm_hspi_cpol_t

Param cpha:

This parameter can be a value of wm_hspi_cpha_t

Functions

wm_device_t *wm_drv_hspi_slave_init(char *dev_name)

Initializes the HSPI slave device.

This function initializes the HSPI slave device using the specified device name. It allocates resources, configures GPIO pins, initializes buffer descriptors, registers interrupt callback and creates synchronization semaphores.

Parameters:

dev_name[in] The name of the device to initialize, as defined in the device tree.

Returns:

  • A pointer to the device structure if the initialization succeeds.

  • NULL if the initialization fails or the device name is not recognized.

int wm_drv_hspi_slave_deinit(wm_device_t *dev)

Deinitializes the HSPI slave device.

This function is used to release the resources and stop any ongoing operations of the HSPI slave device. It frees buffer descriptors, deletes semaphores, unregisters callbacks, resets GPIO pins and frees driver data structures.

Parameters:

dev[in] Pointer to the device structure that needs to be deinitialized.

Returns:

  • WM_ERR_SUCCESS if the deinitialization succeeds.

  • WM_ERR_INVALID_PARAM if the provided device pointer is NULL or invalid.

  • Other error codes may be returned based on the specific failure.

int wm_drv_hspi_slave_config(wm_device_t *dev, wm_drv_hspi_slave_cfg_t *cfg)

Set hspi slave dev config.

Parameters:
Returns:

  • WM_ERR_SUCCESS: succeed

  • others: failed

int wm_drv_hspi_slave_register_callback(wm_device_t *dev, wm_drv_hspi_slave_callback_t cb, void *priv)

Registers event callback function for the HSPI slave device.

This function registers a callback function that will be invoked when HSPI slave events occur. The callback runs in interrupt context and should be kept as short as possible. Events include data/command transmission and reception completion.

Parameters:
  • dev[in] Pointer to the device structure of the HSPI slave.

  • cb[in] Callback function to be invoked when events occur.

  • priv[in] User-defined data to pass to the callback function.

Returns:

  • WM_ERR_SUCCESS if the registration succeeds.

  • WM_ERR_INVALID_PARAM if the device pointer or callback is NULL.

  • Other error codes may be returned to reflect different failure conditions.

int wm_drv_hspi_slave_unregister_callback(wm_device_t *dev)

Unregisters the event callback function for the HSPI slave device.

This function removes the previously registered callback function for HSPI slave events. After unregistering, no callbacks will be invoked when events occur.

Parameters:

dev[in] Pointer to the device structure of the HSPI slave.

Returns:

  • WM_ERR_SUCCESS if the unregistration succeeds.

  • WM_ERR_INVALID_PARAM if the device pointer is NULL.

  • Other error codes may be returned to reflect different failure conditions.

int wm_drv_hspi_slave_tx_data_sync(wm_device_t *dev, void *addr, uint32_t len, uint32_t timeout)

Synchronously transmits data through the HSPI slave device.

This function performs a synchronous data transfer to the host using the HSPI slave device. It initiates DMA transfer and blocks until the operation is complete or the specified timeout is reached.

Note

  • The addr parameter must be allocated from DRAM region using wm_heap_caps_alloc() with WM_HEAP_CAP_SHARED flags

  • The len parameter must not exceed WM_DRV_HSPI_SLAVE_TX_BUF_SIZE * WM_DRV_HSPI_SLAVE_TX_BD_NUM (1024 * 8 = 8192 bytes).

Parameters:
  • dev[in] Pointer to the device structure of the HSPI slave.

  • addr[in] Address of buffer containing data to transmit.

  • len[in] Length of data to transmit in bytes.

  • timeout[in] Maximum time in milliseconds to wait for the operation to complete.

Returns:

  • WM_ERR_SUCCESS if the transmission completes successfully.

  • WM_ERR_INVALID_PARAM if any parameter is invalid.

  • WM_ERR_TIMEOUT if the operation times out.

  • Other error codes may be returned to reflect different failure conditions.

int wm_drv_hspi_slave_tx_data_async(wm_device_t *dev, void *addr, uint32_t len)

Asynchronously transmits data through the HSPI slave device.

This function initiates an asynchronous data transfer to the host using the HSPI slave device. It returns immediately and the registered callback function is called when the operation completes.

Note

  • The addr parameter must be allocated from DRAM region using wm_heap_caps_alloc() with WM_HEAP_CAP_SHARED flags

  • The len parameter must not exceed WM_DRV_HSPI_SLAVE_TX_BUF_SIZE * WM_DRV_HSPI_SLAVE_TX_BD_NUM (1024 * 8 = 8192 bytes).

Parameters:
  • dev[in] Pointer to the device structure of the HSPI slave.

  • addr[in] Address of buffer containing data to transmit.

  • len[in] Length of data to transmit in bytes.

Returns:

  • WM_ERR_SUCCESS if the transmission is successfully initiated.

  • WM_ERR_INVALID_PARAM if any parameter is invalid.

  • Other error codes may be returned to reflect different failure conditions.

int wm_drv_hspi_slave_rx_data(wm_device_t *dev, void **addr, uint32_t timeout)

Receives data from the host through the HSPI slave device.

This function waits for data reception from the host with a specified timeout. When data is received, it updates the address pointer and invokes the registered callback.

Note

  • The maximum receivable data length must not exceed WM_DRV_HSPI_SLAVE_RX_BUF_SIZE * WM_DRV_HSPI_SLAVE_RX_BD_NUM (1024 * 4 = 4096 bytes).

Parameters:
  • dev[in] Pointer to the device structure of the HSPI slave.

  • addr[out] Pointer to store the address of received data buffer.

  • timeout[in] Maximum time in milliseconds to wait for reception.

Returns:

  • WM_ERR_SUCCESS if data is received successfully.

  • WM_ERR_INVALID_PARAM if any parameter is invalid.

  • WM_ERR_TIMEOUT if reception times out.

  • Other error codes may be returned to reflect different failure conditions.

int wm_drv_hspi_slave_rx_cmd(wm_device_t *dev, void **addr, uint32_t timeout)

Receives command from the host through the HSPI slave device.

This function waits for command reception from the host with a specified timeout. When a command is received, it updates the address pointer to the received command buffer.

Note

  • The maximum receivable command length must not exceed WM_DRV_HSPI_SLAVE_CMD_RX_BUF_SIZE (256 bytes).

Parameters:
  • dev[in] Pointer to the device structure of the HSPI slave.

  • addr[out] Pointer to store the address of received command buffer.

  • timeout[in] Maximum time in milliseconds to wait for reception.

Returns:

  • WM_ERR_SUCCESS if command is received successfully.

  • WM_ERR_INVALID_PARAM if any parameter is invalid.

  • WM_ERR_TIMEOUT if reception times out.

  • Other error codes may be returned to reflect different failure conditions.