# SDIO - [Overview](#section574200451165623) - [Summary](#section377336368165623) - [Files](#files) - [Data Structures](#nested-classes) - [Typedefs](#typedef-members) - [Enumerations](#enum-members) - [Functions](#func-members) - [Details](#section537442735165623) - [Typedef](#section1323710923165623) - [SdioIrqHandler](#ga858bec274683a4f50d53d1f9f43d204b) - [Enumeration Type](#section811257175165623) - [SdioCommonInfoType](#ga4037437ac001a9848dd242e8aa632678) - [Function](#section1893104624165623) - [SdioClaimHost\(\)](#ga19b0ab843f82c367ce211b794371ef00) - [SdioClaimIrq\(\)](#ga690a939e327e8c5cd5186e08b1b42506) - [SdioClose\(\)](#ga2e94ff04073420086e1453f125703ec7) - [SdioDisableFunc\(\)](#ga24a4ebbf4cbad86548feb97da46549c3) - [SdioEnableFunc\(\)](#gae67329c260a546d7d92eb42adf5f4a5a) - [SdioFlushData\(\)](#gad402b23097456f1116d1ac941b0f9787) - [SdioGetCommonInfo\(\)](#ga1289cc512ba56e3e904204c15d8ae23d) - [SdioOpen\(\)](#ga8156d7f64d72145312d92e33a532ebfd) - [SdioReadBytes\(\)](#ga14752ccc5cea77cfe30cfa9ab189815f) - [SdioReadBytesFromFixedAddr\(\)](#gabc1645bc8ab9068a13ae501efdb4a9fc) - [SdioReadBytesFromFunc0\(\)](#ga52d8f25705aef184f501528faac8eaa5) - [SdioReleaseHost\(\)](#ga8645ddd7f46ae24b0476f29b281e6ebf) - [SdioReleaseIrq\(\)](#gad5e826a7ff8c15d9b46b74db2dcf9243) - [SdioSetBlockSize\(\)](#ga4a91f3d668b99b22b3263241329ceb51) - [SdioSetCommonInfo\(\)](#ga6a8eb2f6413c4685f92236dd1c8083dc) - [SdioWriteBytes\(\)](#gaa4df7c3e2cde82f5cb7255561b99cc74) - [SdioWriteBytesToFixedAddr\(\)](#ga82d6b3047bd694cdbdfb0a3711797c7b) - [SdioWriteBytesToFunc0\(\)](#ga8606506dfdcb34a83f404d13c7128d5f) ## **Overview** **Description:** Declares standard APIs of basic secure digital input and output \(SDIO\) capabilities. You can use this module to access the SDIO and enable the driver to operate an SDIO-compliant device. These capabilities include reading and writing data based on SDIO, setting the block size, applying for and releasing interrupts, enabling and disabling devices, and occupying and releasing the bus. **Since:** 1.0 ## **Summary** ## Files

File Name

Description

sdio_if.h

Declares the standard SDIO APIs.

## Data Structures

Data Structure Name

Description

SdioFuncInfo

Defines the SDIO capabilities.

SdioCommonInfo

Defines SDIO common information.

## Typedefs

Typedef Name

Description

SdioIrqHandler(void *)

typedef void

Defines the function type of an SDIO IRQ.

## Enumerations

Enumeration Name

Description

SdioCommonInfoType { SDIO_FUNC_INFO = 0, SDIO_OTHER_INFO }

Enumerates SDIO common information types.

## Functions

Function

Description

SdioOpen (int16_t busNum)

DevHandle

Opens an SDIO controller with a specified bus number.

SdioClose (DevHandle handle)

void

Closes an SDIO controller.

SdioReadBytes (DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)

int32_t

Incrementally reads a given length of data from the specified SDIO address.

SdioWriteBytes (DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)

int32_t

Incrementally writes a given length of data into the specified SDIO address.

SdioReadBytesFromFixedAddr (DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)

int32_t

Reads a given length of data from the fixed SDIO address.

SdioWriteBytesToFixedAddr (DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)

int32_t

Writes a given length of data into the fixed SDIO address.

SdioReadBytesFromFunc0 (DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)

int32_t

Reads a given length of data from the address space of SDIO function 0.

SdioWriteBytesToFunc0 (DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)

int32_t

Writes a given length of data into the address space of SDIO function 0.

SdioSetBlockSize (DevHandle handle, uint32_t blockSize)

int32_t

Sets the block size.

SdioGetCommonInfo (DevHandle handle, SdioCommonInfo *info, SdioCommonInfoType infoType)

int32_t

Obtains common information.

SdioSetCommonInfo (DevHandle handle, SdioCommonInfo *info, SdioCommonInfoType infoType)

int32_t

Sets common information.

SdioFlushData (DevHandle handle)

int32_t

Flushes data.

SdioClaimHost (DevHandle handle)

void

Claims a host exclusively.

SdioReleaseHost (DevHandle handle)

void

Releases the exclusively claimed host.

SdioEnableFunc (DevHandle handle)

int32_t

Enables the SDIO device so that its register can be accessed.

SdioDisableFunc (DevHandle handle)

int32_t

Disables the SDIO device.

SdioClaimIrq (DevHandle handle, SdioIrqHandler *irqHandler)

int32_t

Claims an SDIO IRQ.

SdioReleaseIrq (DevHandle handle)

int32_t

Releases an SDIO IRQ.

## **Details** ## **Typedef ** ## SdioIrqHandler ``` typedef void SdioIrqHandler(void *) ``` **Description:** Defines the function type of an SDIO IRQ. This function is registered when you call [SdioClaimIrq](SDIO.md#ga690a939e327e8c5cd5186e08b1b42506) to request the SDIO IRQ. **Parameters:**

Name

Description

data Indicates the private data passed to this IRQ (The data is specified when the IRQ is registered).
## **Enumeration Type ** ## SdioCommonInfoType ``` enum [SdioCommonInfoType](SDIO.md#ga4037437ac001a9848dd242e8aa632678) ``` **Description:** Enumerates SDIO common information types. When obtaining SDIO common information by calling [SdioGetCommonInfo](SDIO.md#ga1289cc512ba56e3e904204c15d8ae23d) or setting the information by calling [SdioSetCommonInfo](SDIO.md#ga6a8eb2f6413c4685f92236dd1c8083dc), you need to pass the information type.

Enumerator

Description

SDIO_FUNC_INFO

Functionality information

SDIO_OTHER_INFO

Other information

## **Function ** ## SdioClaimHost\(\) ``` void SdioClaimHost ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle) ``` **Description:** Claims a host exclusively. You can call this function to enable the SDIO module to exclusively claim a host and then perform operations on the devices connected to the host. After performing required operations, release the host by calling [SdioReleaseHost](SDIO.md#ga8645ddd7f46ae24b0476f29b281e6ebf). **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
## SdioClaimIrq\(\) ``` int32_t SdioClaimIrq ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, [SdioIrqHandler](SDIO.md#ga858bec274683a4f50d53d1f9f43d204b) * irqHandler ) ``` **Description:** Claims an SDIO IRQ. When there is data, commands, or events, the IRQ function is executed. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
irqHandler Indicates the pointer to the SDIO IRQ function. For details, see SdioIrqHandler.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioClose\(\) ``` void SdioClose ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle) ``` **Description:** Closes an SDIO controller. After the SDIO interface is used, you can close the SDIO controller by calling [SdioClose](SDIO.md#ga2e94ff04073420086e1453f125703ec7). This function is used in pair with [SdioOpen](SDIO.md#ga8156d7f64d72145312d92e33a532ebfd). **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller.
## SdioDisableFunc\(\) ``` int32_t SdioDisableFunc ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle) ``` **Description:** Disables the SDIO device. This function is used in pair with [SdioEnableFunc](SDIO.md#gae67329c260a546d7d92eb42adf5f4a5a). **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioEnableFunc\(\) ``` int32_t SdioEnableFunc ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle) ``` **Description:** Enables the SDIO device so that its register can be accessed. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioFlushData\(\) ``` int32_t SdioFlushData ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle) ``` **Description:** Flushes data. You can call this function when an SDIO needs to be reinitialized or an unexpected error occurs. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioGetCommonInfo\(\) ``` int32_t SdioGetCommonInfo ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, [SdioCommonInfo](SdioCommonInfo.md) * info, [SdioCommonInfoType](SDIO.md#ga4037437ac001a9848dd242e8aa632678) infoType ) ``` **Description:** Obtains common information. You can call this function to obtain the capabilities and private data of the I/O function. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
info Indicates the pointer to the common information to be obtained. For details, see SdioCommonInfo.
infoType Indicates the type of the common information to be obtained. For details, see SdioCommonInfoType.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioOpen\(\) ``` [DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) SdioOpen (int16_t busNum) ``` **Description:** Opens an SDIO controller with a specified bus number. Before using the SDIO interface, you can obtain the device handle of the SDIO controller by calling [SdioOpen](SDIO.md#ga8156d7f64d72145312d92e33a532ebfd). This function is used in pair with [SdioClose](SDIO.md#ga2e94ff04073420086e1453f125703ec7). **Parameters:**

Name

Description

busNum Indicates the bus number.
**Returns:** Returns the device handle [DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) of the SDIO controller if the operation is successful; returns **NULL** otherwise. ## SdioReadBytes\(\) ``` int32_t SdioReadBytes ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, uint8_t * data, uint32_t addr, uint32_t size, uint32_t timeOut ) ``` **Description:** Incrementally reads a given length of data from the specified SDIO address. If the length of the data to read is greater than the size of a block, the data is read by block, and the remaining data that is smaller than one block is read by byte. Otherwise, data is read by byte. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
data Indicates the pointer to the data to read.
addr Indicates the start address of the data to read.
size Indicates the length of the data to read.
timeOut Indicates the timeout duration for reading data, in milliseconds. If the value is 0,the default value is used. The default value varies according to the application. Generally, the default value is 1 second.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioReadBytesFromFixedAddr\(\) ``` int32_t SdioReadBytesFromFixedAddr ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, uint8_t * data, uint32_t addr, uint32_t size, uint32_t timeOut ) ``` **Description:** Reads a given length of data from the fixed SDIO address. If the length of the data to read is greater than the size of a block, the data is read by block, and the remaining data that is smaller than one block is read by byte. Otherwise, data is read by byte. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
data Indicates the pointer to the data to read.
addr Indicates the fixed address of the data to read.
size Indicates the length of the data to read.
timeOut Indicates the timeout duration for reading data, in milliseconds. If the value is 0, the default value is used. The default value varies according to the application. Generally, the default value is 1 second.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioReadBytesFromFunc0\(\) ``` int32_t SdioReadBytesFromFunc0 ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, uint8_t * data, uint32_t addr, uint32_t size, uint32_t timeOut ) ``` **Description:** Reads a given length of data from the address space of SDIO function 0. Currently, only one byte of data can be read. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
data Indicates the pointer to the data to read.
addr Indicates the start address of the data to read.
size Indicates the length of the data to read.
timeOut Indicates the timeout duration for reading data, in milliseconds. If the value is 0, the default value is used. The default value varies according to the application. Generally, the default value is 1 second.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioReleaseHost\(\) ``` void SdioReleaseHost ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle) ``` **Description:** Releases the exclusively claimed host. This function is used in pair with [SdioClaimHost](SDIO.md#ga19b0ab843f82c367ce211b794371ef00). **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
## SdioReleaseIrq\(\) ``` int32_t SdioReleaseIrq ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle) ``` **Description:** Releases an SDIO IRQ. This function is used in pair with [SdioClaimIrq](SDIO.md#ga690a939e327e8c5cd5186e08b1b42506). **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioSetBlockSize\(\) ``` int32_t SdioSetBlockSize ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, uint32_t blockSize ) ``` **Description:** Sets the block size. If data to read or write is performed, use this function to set the block size. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
blockSize Indicates the block size to be set. If the value is 0, the default value is used. The value ranges from 1 to 2048 bytes.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioSetCommonInfo\(\) ``` int32_t SdioSetCommonInfo ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, [SdioCommonInfo](SdioCommonInfo.md) * info, [SdioCommonInfoType](SDIO.md#ga4037437ac001a9848dd242e8aa632678) infoType ) ``` **Description:** Sets common information. You can call this function to set the maximum timeout duration and private data. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
info Indicates the pointer to the common information to be set. For details, see SdioCommonInfo.
infoType Indicates the type of the common information to be set. For details, see SdioCommonInfoType.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioWriteBytes\(\) ``` int32_t SdioWriteBytes ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, uint8_t * data, uint32_t addr, uint32_t size, uint32_t timeOut ) ``` **Description:** Incrementally writes a given length of data into the specified SDIO address. If the length of the data to write is greater than the size of a block, the data is written by block first, and the remaining data that is smaller than one block is written by byte. Otherwise, data is written by byte. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
data Indicates the pointer to the data to write.
addr Indicates the start address of the data to write.
size Indicates the length of the data to write.
timeOut Indicates the timeout duration for writing data, in milliseconds. If the value is 0, the default value is used. The default value varies according to the application. Generally, the default value is 1 second.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioWriteBytesToFixedAddr\(\) ``` int32_t SdioWriteBytesToFixedAddr ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, uint8_t * data, uint32_t addr, uint32_t size, uint32_t timeOut ) ``` **Description:** Writes a given length of data into the fixed SDIO address. If the length of the data to write is greater than the size of a block, the data is written by block first, and the remaining data that is smaller than one block is written by byte. Otherwise, data is written by byte. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
data Indicates the pointer to the data to write.
addr Indicates the fixed address of the data to write.
size Indicates the length of the data to write.
timeOut Indicates the timeout duration for writing data, in milliseconds. If the value is 0, the default value is used. The default value varies according to the application. Generally, the default value is 1 second.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails. ## SdioWriteBytesToFunc0\(\) ``` int32_t SdioWriteBytesToFunc0 ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, uint8_t * data, uint32_t addr, uint32_t size, uint32_t timeOut ) ``` **Description:** Writes a given length of data into the address space of SDIO function 0. Currently, only one byte of data can be written. **Parameters:**

Name

Description

handle Indicates the pointer to the device handle of the SDIO controller obtained by SdioOpen.
data Indicates the pointer to the data to write.
addr Indicates the start address of the data to write.
size Indicates the length of the data to write.
timeOut Indicates the timeout duration for writing data, in milliseconds. If the value is 0, the default value is used. The default value varies according to the application. Generally, the default value is 1 second.
**Returns:** Returns **0** if the operation is successful; returns a negative value if the operation fails.