High level interface to the Secure Digital Input Output (SDIO).
This driver allows commands to be sent over the SDIO bus; the supported commands can be found in cyhal_sdio_command_t. Bulk data transfer is also supported via cyhal_sdio_bulk_transfer().
The SDIO protocol is an extension of the SD interface for general I/O functions. Refer to the SD Specifications Part 1 SDIO Specifications Version 4.10 for more information on the SDIO protocol and specifications.
cyhal_sdio_init initializes the SDIO peripheral and passes a pointer to the SDIO block through the obj object of type cyhal_sdio_t.
The following snippet shows how to initialize the SDIO interface with a pre-defined configuration
The following snippet shows how to configure an interrupt and handle specific events. Refer cyhal_sdio_event_t for different types of events.
The following snippet shows how to send a particular command. Some steps of the card initialization have been provided for reference. Refer cyhal_sdio_command_t for different commands.
The following snippet shows how to start a bulk data transfer.
The following snippet shows how to start an async data transfer.
API Reference | |
SDIO HAL Results | |
SDIO specific return codes. | |
Data Structures | |
struct | cyhal_sdio_cfg_t |
SDIO controller initial configuration. More... | |
Macros | |
#define | CYHAL_SDIO_RET_NO_ERRORS (0x00) |
No error. | |
#define | CYHAL_SDIO_RET_NO_SP_ERRORS (0x01) |
Non-specific error code. | |
#define | CYHAL_SDIO_RET_CMD_CRC_ERROR (0x02) |
There was a CRC error on the Command/Response. | |
#define | CYHAL_SDIO_RET_CMD_IDX_ERROR (0x04) |
The index for the command didn't match. | |
#define | CYHAL_SDIO_RET_CMD_EB_ERROR (0x08) |
There was an end bit error on the command. | |
#define | CYHAL_SDIO_RET_DAT_CRC_ERROR (0x10) |
There was a data CRC Error. | |
#define | CYHAL_SDIO_RET_CMD_TIMEOUT (0x20) |
The command didn't finish before the timeout period was over. | |
#define | CYHAL_SDIO_RET_DAT_TIMEOUT (0x40) |
The data didn't finish before the timeout period was over. | |
#define | CYHAL_SDIO_RET_RESP_FLAG_ERROR (0x80) |
There was an error in the resposne flag for command 53. | |
#define | CYHAL_SDIO_CLOCK_ERROR (0x100) |
Failed to initial clock for SDIO. | |
#define | CYHAL_SDIO_BAD_ARGUMENT (0x200) |
Bad argument passed for SDIO. | |
#define | CYHAL_SDIO_SEMA_NOT_INITED (0x400) |
Semaphore is not initiated. | |
#define | CYHAL_SDIO_FUNC_NOT_SUPPORTED (0x800) |
Function is not supported. | |
#define | CYHAL_SDIO_CANCELED (0x1000) |
Operation canceled. | |
#define | CYHAL_SDIO_PM_PENDING_ERROR (0x2000) |
Transfer cannot be initiated after power mode transition allowed. More... | |
Typedefs | |
typedef void(* | cyhal_sdio_event_callback_t) (void *callback_arg, cyhal_sdio_event_t event) |
Callback for SDIO events. | |
Functions | |
cy_rslt_t | cyhal_sdio_init (cyhal_sdio_t *obj, cyhal_gpio_t cmd, cyhal_gpio_t clk, cyhal_gpio_t data0, cyhal_gpio_t data1, cyhal_gpio_t data2, cyhal_gpio_t data3) |
Initialize the SDIO peripheral. More... | |
void | cyhal_sdio_free (cyhal_sdio_t *obj) |
Release the SDIO block. More... | |
cy_rslt_t | cyhal_sdio_configure (cyhal_sdio_t *obj, const cyhal_sdio_cfg_t *config) |
Configure the SDIO block with required parameters. More... | |
cy_rslt_t | cyhal_sdio_send_cmd (const cyhal_sdio_t *obj, cyhal_transfer_t direction, cyhal_sdio_command_t command, uint32_t argument, uint32_t *response) |
Sends command to the SDIO device. More... | |
cy_rslt_t | cyhal_sdio_bulk_transfer (cyhal_sdio_t *obj, cyhal_transfer_t direction, uint32_t argument, const uint32_t *data, uint16_t length, uint32_t *response) |
Performs a bulk data transfer. More... | |
cy_rslt_t | cyhal_sdio_transfer_async (cyhal_sdio_t *obj, cyhal_transfer_t direction, uint32_t argument, const uint32_t *data, uint16_t length) |
Performs a bulk asynchronous data transfer by issuing the CYHAL_SDIO_CMD_IO_RW_EXTENDED command(CMD=53) to the SDIO block. More... | |
bool | cyhal_sdio_is_busy (const cyhal_sdio_t *obj) |
Checks if the specified SDIO is in use. More... | |
cy_rslt_t | cyhal_sdio_abort_async (const cyhal_sdio_t *obj) |
Abort an SDIO transfer. More... | |
void | cyhal_sdio_register_callback (cyhal_sdio_t *obj, cyhal_sdio_event_callback_t callback, void *callback_arg) |
Register an SDIO event callback to be invoked when the event is triggered. More... | |
void | cyhal_sdio_enable_event (cyhal_sdio_t *obj, cyhal_sdio_event_t event, uint8_t intr_priority, bool enable) |
Enables callbacks to be triggered for specified SDIO events. More... | |
struct cyhal_sdio_cfg_t |
#define CYHAL_SDIO_PM_PENDING_ERROR (0x2000) |
Transfer cannot be initiated after power mode transition allowed.
enum cyhal_sdio_command_t |
Commands that can be issued.
enum cyhal_transfer_t |
enum cyhal_sdio_event_t |
Types of events that could be asserted by SDIO.
cy_rslt_t cyhal_sdio_init | ( | cyhal_sdio_t * | obj, |
cyhal_gpio_t | cmd, | ||
cyhal_gpio_t | clk, | ||
cyhal_gpio_t | data0, | ||
cyhal_gpio_t | data1, | ||
cyhal_gpio_t | data2, | ||
cyhal_gpio_t | data3 | ||
) |
Initialize the SDIO peripheral.
[out] | obj | Pointer to an SDIO object. The caller must allocate the memory for this object but the init function will initialize its contents. |
[out] | clk | The pin connected to the clk signal |
[in] | cmd | The pin connected to the command signal |
[in] | data0 | The pin connected to the data0 signal |
[in] | data1 | The pin connected to the data1 signal |
[in] | data2 | The pin connected to the data2 signal |
[in] | data3 | The pin connected to the data3 signal |
Returns CY_RSLT_SUCCESS on successful operation. Refer Snippet1: Simple SDIO Initialization example for more information.
void cyhal_sdio_free | ( | cyhal_sdio_t * | obj | ) |
Release the SDIO block.
[in,out] | obj | The SDIO object |
cy_rslt_t cyhal_sdio_configure | ( | cyhal_sdio_t * | obj, |
const cyhal_sdio_cfg_t * | config | ||
) |
Configure the SDIO block with required parameters.
Refer cyhal_sdio_cfg_t for more information.
[in,out] | obj | The SDIO object |
[in] | config | The SDIO configuration to apply |
Returns CY_RSLT_SUCCESS on successful operation.
cy_rslt_t cyhal_sdio_send_cmd | ( | const cyhal_sdio_t * | obj, |
cyhal_transfer_t | direction, | ||
cyhal_sdio_command_t | command, | ||
uint32_t | argument, | ||
uint32_t * | response | ||
) |
Sends command to the SDIO device.
See cyhal_sdio_command_t for list of available commands.
This will block until the command is completed.
[in,out] | obj | The SDIO object |
[in] | direction | The direction of transfer (read/write) |
[in] | command | The command to send to the SDIO device |
[in] | argument | The argument to the command |
[out] | response | The response from the SDIO device |
Returns CY_RSLT_SUCCESS on successful operation. Refer Snippet3: Sending Commands for more information.
cy_rslt_t cyhal_sdio_bulk_transfer | ( | cyhal_sdio_t * | obj, |
cyhal_transfer_t | direction, | ||
uint32_t | argument, | ||
const uint32_t * | data, | ||
uint16_t | length, | ||
uint32_t * | response | ||
) |
Performs a bulk data transfer.
Sends CYHAL_SDIO_CMD_IO_RW_EXTENDED command (CMD=53) which allows writing and reading of a large number of I/O registers with a single command.
This will block until the transfer is completed.
[in,out] | obj | The SDIO object |
[in] | direction | The direction of transfer (read/write) |
[in] | argument | The argument to the command |
[in] | data | The data to send to the SDIO device. A bulk transfer is done in block size (default: 64 bytes) chunks for better performance. Therefore, the size of the data buffer passed into this function must be at least length bytes and a multiple of the block size. For example, when requesting to read 100 bytes of data with a block size 64 bytes, the data buffer needs to be at least 128 bytes. The first 100 bytes of data in the buffer will be the requested data. |
[in] | length | The number of bytes to send |
[out] | response | The response from the SDIO device |
Returns CY_RSLT_SUCCESS on successful operation. Refer Snippet4: Bulk Data Transfer for more information.
cy_rslt_t cyhal_sdio_transfer_async | ( | cyhal_sdio_t * | obj, |
cyhal_transfer_t | direction, | ||
uint32_t | argument, | ||
const uint32_t * | data, | ||
uint16_t | length | ||
) |
Performs a bulk asynchronous data transfer by issuing the CYHAL_SDIO_CMD_IO_RW_EXTENDED command(CMD=53) to the SDIO block.
After exiting this function the CYHAL_SDIO_CMD_COMPLETE and CYHAL_SDIO_XFER_COMPLETE events are not asserted.
To complete the asynchronous transfer, call cyhal_sdio_is_busy() until it returns false. The CYHAL_SDIO_CMD_COMPLETE and CYHAL_SDIO_XFER_COMPLETE events are enabled after the asynchronous transfer is complete and in the condition they were enabled in before the transfer operation started. Handle these events in the interrupt callback.
When the transfer is complete, the CYHAL_SDIO_XFER_COMPLETE event will be raised. See cyhal_sdio_register_callback and cyhal_sdio_enable_event.
[in,out] | obj | The SDIO object |
[in] | direction | The direction of transfer (read/write) |
[in] | argument | The argument to the command |
[in] | data | The data to send to the SDIO device |
[in] | length | The number of bytes to send |
Returns CY_RSLT_SUCCESS on successful operation. Refer Snippet5: Async Data Transfer for more information.
bool cyhal_sdio_is_busy | ( | const cyhal_sdio_t * | obj | ) |
Checks if the specified SDIO is in use.
[in] | obj | The SDIO peripheral to check |
cy_rslt_t cyhal_sdio_abort_async | ( | const cyhal_sdio_t * | obj | ) |
Abort an SDIO transfer.
[in] | obj | The SDIO peripheral to stop |
Returns CY_RSLT_SUCCESS on successful operation.
void cyhal_sdio_register_callback | ( | cyhal_sdio_t * | obj, |
cyhal_sdio_event_callback_t | callback, | ||
void * | callback_arg | ||
) |
Register an SDIO event callback to be invoked when the event is triggered.
This function will be called when one of the events enabled by cyhal_sdio_enable_event occurs.
[in] | obj | The SDIO object |
[in] | callback | The callback function which will be invoked when the event triggers |
[in] | callback_arg | Generic argument that will be provided to the callback when executed |
Refer Snippet2: Configure Interrupt for more implementation.
void cyhal_sdio_enable_event | ( | cyhal_sdio_t * | obj, |
cyhal_sdio_event_t | event, | ||
uint8_t | intr_priority, | ||
bool | enable | ||
) |
Enables callbacks to be triggered for specified SDIO events.
Refer cyhal_sdio_event_t for all events.
[in] | obj | The SDIO object |
[in] | event | The SDIO event type |
[in] | intr_priority | The priority for NVIC interrupt events |
[in] | enable | Set to true to enable events, or false to disable them |
Refer Snippet2: Configure Interrupt for more information.