High level interface to the Secure Digital Input Output (SDIO).
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.
The host functionality of this driver allows commands to be sent over the SDIO bus; the supported commands can be found in cyhal_sdio_host_command_t. Bulk data transfer is supported via cyhal_sdio_bulk_transfer().
The device functionality of this driver allows configuring the SDIO device for receiving commands from the host. Data can be sent and received from/to application buffers.
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 host interface with a pre-defined configuration
The following snippet shows how to configure an interrupt to handle host 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 to cyhal_sdio_host_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.
The following snippet shows how to initialize the SDIO device interface with a pre-defined configuration
The following snippet shows how to configure an interrupt to handle device specific events. Refer cyhal_sdio_event_t for different types of events.
The following snippet shows how to start an async read.
The following snippet shows how to write to the mailbox.
API Reference | |
SDIO HAL Results | |
SDIO specific return codes. | |
Data Structures | |
struct | cyhal_sdio_cfg_t |
SDIO initial configuration. More... | |
Macros | |
#define | SDIO_F2_FRAME_MAX_LENGTH (0x800) |
Maximum frame length for SDIO. | |
#define | SDIO_F2_FRAME_MAX_PAYLOAD (SDIO_F2_FRAME_MAX_LENGTH - sizeof(sdiod_f2_frame_hdr_t)) |
Maximum payload for SDIO. | |
#define | SDIO_F2_DMA_BUFFER_SIZE (sizeof(sdiod_dma_descs_buf_t) + sizeof(sdiod_f2_rx_frame_hdr_t) + (2 * SDIO_F2_FRAME_MAX_PAYLOAD)) |
DMA Buffer size for SDIO. | |
Typedefs | |
typedef void(* | cyhal_sdio_event_callback_t) (void *callback_arg, cyhal_sdio_event_t event) |
Callback for SDIO events. | |
Enumerations | |
enum | cyhal_sdio_event_t { CYHAL_SDIO_DEV_HOST_INFO = 0x80001 , CYHAL_SDIO_DEV_READ_COMPLETE = 0x80002 , CYHAL_SDIO_DEV_WRITE_COMPLETE = 0x80004 , CYHAL_SDIO_DEV_READ_ERROR = 0x80008 , CYHAL_SDIO_DEV_WRITE_ERROR = 0x80010 , CYHAL_SDIO_ALL_INTERRUPTS = 0x0E1FF } |
Types of events that could be asserted by SDIO. More... | |
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. More... | |
bool | cyhal_sdio_is_busy (const cyhal_sdio_t *obj) |
Check if the specified SDIO is in use. More... | |
cy_rslt_t | cyhal_sdio_abort_async (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 handler. More... | |
void | cyhal_sdio_enable_event (cyhal_sdio_t *obj, cyhal_sdio_event_t event, uint8_t intr_priority, bool enable) |
Configure the callback event. More... | |
cy_rslt_t | cyhal_sdio_init_cfg (cyhal_sdio_t *obj, const cyhal_sdio_configurator_t *cfg) |
Initialize the SDIO peripheral using a configurator generated configuration struct. More... | |
bool | cyhal_sdio_dev_is_ready (cyhal_sdio_t *obj) |
Check if the device is initialized by the host. More... | |
cy_rslt_t | cyhal_sdio_dev_mailbox_write (cyhal_sdio_t *obj, uint32_t bits, uint32_t *data) |
Write to the mailbox and send a signal to the host. More... | |
cy_rslt_t | cyhal_sdio_dev_mailbox_read (cyhal_sdio_t *obj, uint32_t *data) |
Read mailbox data. More... | |
cy_rslt_t | cyhal_sdio_dev_read (cyhal_sdio_t *obj, uint8_t *data, size_t length, uint32_t timeout_ms) |
Synchronous read data. More... | |
cy_rslt_t | cyhal_sdio_dev_write (cyhal_sdio_t *obj, const uint8_t *data, size_t length, uint32_t timeout_ms) |
Synchronous write data. More... | |
cy_rslt_t | cyhal_sdio_dev_read_async (cyhal_sdio_t *obj, uint8_t *data, size_t length) |
Start SDIO Device asynchronous read. More... | |
cy_rslt_t | cyhal_sdio_dev_write_async (cyhal_sdio_t *obj, const uint8_t *data, size_t length) |
Start SDIO Device asynchronous write. More... | |
struct cyhal_sdio_cfg_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. |
[in] | cmd | The pin for the command signal |
[in] | clk | The pin for the clk signal |
[in] | data0 | The pin for the data0 signal |
[in] | data1 | The pin for the data1 signal |
[in] | data2 | The pin for the data2 signal |
[in] | data3 | The pin for the data3 signal |
Returns CY_RSLT_SUCCESS on successful operation. Refer to Snippet1: Simple SDIO Host Initialization example and Snippet1: Simple SDIO Device Initialization example for more information.
void cyhal_sdio_free | ( | cyhal_sdio_t * | obj | ) |
Release the SDIO block.
Return the peripheral, pins and clock owned by the SDIO object to its reset state
[in,out] | obj | The SDIO object to deinitialize |
cy_rslt_t cyhal_sdio_configure | ( | cyhal_sdio_t * | obj, |
const cyhal_sdio_cfg_t * | config | ||
) |
Configure the SDIO block.
SDIO is either a host or a device type. This function allows specifying the features for either type. Refer to 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.
bool cyhal_sdio_is_busy | ( | const cyhal_sdio_t * | obj | ) |
Check if the specified SDIO is in use.
[in] | obj | The SDIO peripheral to check |
cy_rslt_t cyhal_sdio_abort_async | ( | 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 handler.
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 to Snippet2: Configure Host Interrupt and Snippet2: Configure Device Interrupt for usage information.
void cyhal_sdio_enable_event | ( | cyhal_sdio_t * | obj, |
cyhal_sdio_event_t | event, | ||
uint8_t | intr_priority, | ||
bool | enable | ||
) |
Configure the callback event.
Callbacks will be triggered for the specified SDIO events. Refer to cyhal_sdio_event_t for the list of supported 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 to Snippet2: Configure Host Interrupt and Snippet2: Configure Device Interrupt for usage information.
cy_rslt_t cyhal_sdio_init_cfg | ( | cyhal_sdio_t * | obj, |
const cyhal_sdio_configurator_t * | cfg | ||
) |
Initialize the SDIO peripheral using a configurator generated configuration struct.
[in] | obj | The SDIO peripheral to configure |
[in] | cfg | Configuration structure generated by a configurator. |
bool cyhal_sdio_dev_is_ready | ( | cyhal_sdio_t * | obj | ) |
Check if the device is initialized by the host.
The SDIO device must be initialized by host commands. This function will return true if the sequence has completed.
[in] | obj | The SDIO device object |
cy_rslt_t cyhal_sdio_dev_mailbox_write | ( | cyhal_sdio_t * | obj, |
uint32_t | bits, | ||
uint32_t * | data | ||
) |
Write to the mailbox and send a signal to the host.
This function will send a mailbox interrupt to the host, which will inform the host to access the data available in the mailbox on the device.
[in] | obj | The SDIO device object |
[in] | bits | Mailbox signal to notify |
[in] | data | Data to send to the mailbox (NULL if nothing to send) |
cy_rslt_t cyhal_sdio_dev_mailbox_read | ( | cyhal_sdio_t * | obj, |
uint32_t * | data | ||
) |
Read mailbox data.
This function will read the mailbox data register. It should be performed after the device receives a mailbox notification from the host.
[in] | obj | The SDIO device object |
[in] | data | Data to send to the mailbox (Optional) |
cy_rslt_t cyhal_sdio_dev_read | ( | cyhal_sdio_t * | obj, |
uint8_t * | data, | ||
size_t | length, | ||
uint32_t | timeout_ms | ||
) |
Synchronous read data.
This is a blocking call that reads the data sent from the host. The read will not complete until a suitable command from the host is received.
[in] | obj | The SDIO device object |
[out] | data | The buffer for receiving |
[in,out] | length | Number of words to read, updated with the number actually read |
[in] | timeout_ms | Timeout in millisecond, set this value to 0 if you don't want to wait at all. |
cy_rslt_t cyhal_sdio_dev_write | ( | cyhal_sdio_t * | obj, |
const uint8_t * | data, | ||
size_t | length, | ||
uint32_t | timeout_ms | ||
) |
Synchronous write data.
This is a blocking call that writes the data to the host. The write will not complete until a suitable command from the host is received.
[in] | obj | The SDIO device object |
[in] | data | The buffer for sending |
[in,out] | length | Number of words to write, updated with the number actually written |
[in] | timeout_ms | Timeout in millisecond, set this value to 0 if you don't want to wait at all. |
cy_rslt_t cyhal_sdio_dev_read_async | ( | cyhal_sdio_t * | obj, |
uint8_t * | data, | ||
size_t | length | ||
) |
Start SDIO Device asynchronous read.
This is a non-blocking call. It will initiate the hardware to read from the host and then immediately return. When the requested quantity of data has been read, the CYHAL_SDIO_DEV_READ_COMPLETE event will be raised.
[in] | obj | The SDIO device object |
[out] | data | The read buffer |
[in] | length | Number of words to read |
cy_rslt_t cyhal_sdio_dev_write_async | ( | cyhal_sdio_t * | obj, |
const uint8_t * | data, | ||
size_t | length | ||
) |
Start SDIO Device asynchronous write.
This is a non-blocking call. It will initiate the hardware to write to the host and then immediately return. When the requested quantity of data has been written, the CYHAL_SDIO_DEV_WRITE_COMPLETE event will be raised.
[in] | obj | The SDIO device object |
[in] | data | The write buffer |
[in] | length | The number of words to write |