SDIO Slave API 参考
Macros
-
WM_DRV_SDIO_SLAVE_CIS_SIZE
Size of CIS buffer
-
WM_DRV_SDIO_SLAVE_CMD_RX_BUF_SIZE
Size of command receive buffer
-
WM_DRV_SDIO_SLAVE_TX_BUF_SIZE
Size of transmit buffer
-
WM_DRV_SDIO_SLAVE_TX_BD_NUM
Number of transmit buffer descriptors
-
WM_DRV_SDIO_SLAVE_RX_BUF_SIZE
Size of receive buffer
-
WM_DRV_SDIO_SLAVE_RX_BD_NUM
Number of receive buffer descriptors
Enumerations
-
enum wm_drv_sdio_slave_func_t
SDIO slave function enumeration.
This enumeration defines the available SDIO slave functions that can be accessed. SDIO supports multiple functions per card, with function 0 being a special function that is used for card configuration and control.
Function 0:
Used for card configuration and control
Always exists and is mandatory
Can only perform control operations, not data transfers
Accesses common card registers (CCR)
Function 1:
Used for actual data transfers
Optional function that provides data transfer capability
Can perform both control and data operations
Has its own function-specific registers (FBR)
Values:
-
enumerator WM_DRV_SDIO_SLAVE_FUNC_0
SDIO slave function 0 - Configuration and control function
-
enumerator WM_DRV_SDIO_SLAVE_FUNC_1
SDIO slave function 1 - Data transfer function
-
enumerator WM_DRV_SDIO_SLAVE_FUNC_MAX
Maximum number of supported SDIO functions
-
enum wm_drv_sdio_slave_event_t
SDIO slave event types.
Values:
-
enumerator WM_DRV_SDIO_SLAVE_EVENT_TX
Data transmit complete event
-
enumerator WM_DRV_SDIO_SLAVE_EVENT_RX
Data receive complete event
-
enumerator WM_DRV_SDIO_SLAVE_EVENT_TX_CMD
Command transmit complete event
-
enumerator WM_DRV_SDIO_SLAVE_EVENT_RX_CMD
Command receive complete event
-
enumerator WM_DRV_SDIO_SLAVE_EVENT_MAX
-
enumerator WM_DRV_SDIO_SLAVE_EVENT_TX
Type Definitions
-
typedef void (*wm_drv_sdio_slave_callback_t)(wm_device_t *dev, wm_drv_sdio_slave_event_t event, void *addr, void *priv)
SDIO slave event callback function type.
This callback function is invoked when SDIO 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 SDIO 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
Functions
-
wm_device_t *wm_drv_sdio_slave_init(char *dev_name)
Initializes the SDIO slave device.
This function initializes the SDIO slave device using the specified device name. It allocates resources, configures GPIO pins, initializes buffer descriptors, sets up CIS, registers interrupt callback and creates synchronization semaphores.
- 参数:
dev_name – [in] The name of the device to initialize, as defined in the device tree.
- 返回:
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_sdio_slave_deinit(wm_device_t *dev)
Deinitializes the SDIO slave device.
This function is used to release the resources and stop any ongoing operations of the SDIO slave device. It frees buffer descriptors, deletes semaphores, unregisters callbacks, resets GPIO pins and frees driver data structures.
- 参数:
dev – [in] Pointer to the device structure that needs to be deinitialized.
- 返回:
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_sdio_slave_register_callback(wm_device_t *dev, wm_drv_sdio_slave_callback_t cb, void *priv)
Registers event callback function for the SDIO slave device.
This function registers a callback function that will be invoked when SDIO 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.
- 参数:
dev – [in] Pointer to the device structure of the SDIO slave.
cb – [in] Callback function to be invoked when events occur.
priv – [in] User-defined data to pass to the callback function.
- 返回:
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_sdio_slave_unregister_callback(wm_device_t *dev)
Unregisters the event callback function for the SDIO slave device.
This function removes the previously registered callback function for SDIO slave events. After unregistering, no callbacks will be invoked when events occur.
- 参数:
dev – [in] Pointer to the device structure of the SDIO slave.
- 返回:
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_sdio_slave_read_cis_reg(wm_device_t *dev, wm_drv_sdio_slave_func_t func, uint32_t pos, uint32_t *reg_val)
Reads a register value from the SDIO slave device.
This function reads the value of a register at the specified position for the given SDIO function. It can access both Function 0 (common registers) and Function 1 (data transfer) registers.
备注
For Function 0/1, pos must not exceed the CIS size (128 bytes).
- 参数:
dev – [in] Pointer to the device structure of the SDIO slave.
func – [in] SDIO function number (0 or 1) to read from.
pos – [in] Register position/offset to read (0-123).
reg_val – [out] Pointer to store the read register value.
- 返回:
WM_ERR_SUCCESS if the read operation succeeds.
WM_ERR_INVALID_PARAM if any parameter is invalid.
Other error codes may be returned to reflect different failure conditions.
-
int wm_drv_sdio_slave_write_cis_reg(wm_device_t *dev, wm_drv_sdio_slave_func_t func, uint32_t pos, uint32_t reg_val)
Writes a value to a register in the SDIO slave device.
This function writes the specified value to a register at the given position for the selected SDIO function. It can access both Function 0 (common registers) and Function 1 (data transfer) registers.
备注
For Function 0/1, pos must not exceed the CIS size (128 bytes).
- 参数:
dev – [in] Pointer to the device structure of the SDIO slave.
func – [in] SDIO function number (0 or 1) to write to.
pos – [in] Register position/offset to write (0-123).
reg_val – [in] Value to write to the register.
- 返回:
WM_ERR_SUCCESS if the write operation succeeds.
WM_ERR_INVALID_PARAM if any parameter is invalid.
Other error codes may be returned to reflect different failure conditions.
-
int wm_drv_sdio_slave_tx_data_sync(wm_device_t *dev, void *addr, uint32_t len, uint32_t timeout)
Synchronously transmits data through the SDIO slave device.
This function performs a synchronous data transfer to the host using the SDIO slave device. It initiates DMA transfer and blocks until the operation is complete or the specified timeout is reached.
备注
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_SDIO_SLAVE_TX_BUF_SIZE * WM_DRV_SDIO_SLAVE_TX_BD_NUM (1024 * 8 = 8192 bytes).
- 参数:
dev – [in] Pointer to the device structure of the SDIO 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.
- 返回:
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_sdio_slave_tx_data_async(wm_device_t *dev, void *addr, uint32_t len)
Asynchronously transmits data through the SDIO slave device.
This function initiates an asynchronous data transfer to the host using the SDIO slave device. It returns immediately and the registered callback function is called when the operation completes.
备注
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_SDIO_SLAVE_TX_BUF_SIZE * WM_DRV_SDIO_SLAVE_TX_BD_NUM (1024 * 8 = 8192 bytes).
- 参数:
dev – [in] Pointer to the device structure of the SDIO slave.
addr – [in] Address of buffer containing data to transmit.
len – [in] Length of data to transmit in bytes.
- 返回:
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_sdio_slave_rx_data(wm_device_t *dev, void **addr, uint32_t timeout)
Receives data from the host through the SDIO 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.
备注
The maximum receivable data length must not exceed WM_DRV_SDIO_SLAVE_RX_BUF_SIZE * WM_DRV_SDIO_SLAVE_RX_BD_NUM (1024 * 4 = 4096 bytes).
- 参数:
dev – [in] Pointer to the device structure of the SDIO slave.
addr – [out] Pointer to store the address of received data buffer.
timeout – [in] Maximum time in milliseconds to wait for reception.
- 返回:
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_sdio_slave_rx_cmd(wm_device_t *dev, void **addr, uint32_t timeout)
Receives command from the host through the SDIO 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.
备注
The maximum receivable command length must not exceed WM_DRV_SDIO_SLAVE_CMD_RX_BUF_SIZE (256 bytes).
- 参数:
dev – [in] Pointer to the device structure of the SDIO slave.
addr – [out] Pointer to store the address of received command buffer.
timeout – [in] Maximum time in milliseconds to wait for reception.
- 返回:
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.