1.1.6.4.8 DRV_SDMMC_Async_SDIO_Read Function

C

void DRV_SDMMC_Async_SDIO_Read (
    const DRV_HANDLE handle,
    DRV_SDMMC_COMMAND_HANDLE* commandHandle,
    uint8_t fn,
    uint32_t regAddr,
    void* rdData,
    uint32_t nBytes,
    bool isAddrInc
)

Summary

Reads single or multiple bytes of data starting from the specified regAddr of the SDIO card.

Description

This function schedules a non-blocking read operation for reading a single or multiple bytes of data (using either CMD52 or CMD53) from the given I/O function in the SDIO card. If nBytes is set to 1, then CMD52 is used to read a single byte. If nBytes is set to a value less than 511, then CMD53 is used to read multiple bytes. If nBytes is set to a value greater than 511 and is a multiple of 512 bytes, then CMD53 is used to read one or multiple blocks of data. The function returns with a valid buffer handle in the commandHandle argument if the read request was scheduled successfully. The function adds the request to the hardware instance queue and returns immediately. While the request is in the queue, the rdData is owned by the driver and should not be modified. The function returns DRV_SDMMC_COMMAND_HANDLE_INVALID in the commandHandle argument under the following circumstances:

  • if the driver handle is invalid.

  • if the rdData pointer is NULL or nBytes is 0. If nBytes is greater than 511 and is not a multiple of 512.

  • if the media is not in attached state.

  • if a buffer object could not be allocated to the request.

If the requesting client registered an event callback with the driver, the driver will issue a DRV_SDMMC_EVENT_COMMAND_COMPLETE event if the buffer was processed successfully or DRV_SDMMC_EVENT_COMMAND_ERROR event if the buffer was not processed successfully.

Precondition

The DRV_SDMMC_Initialize routine must have been called for the specified SDMMC driver instance.

DRV_SDMMC_Open routine must have been called to obtain a valid opened device handle.

Parameters

ParametersDescription
handleA valid open-instance handle, returned from the driver's open function.
commandHandlePointer to the buffer handle returned by this API.
fnThe function number within the SDIO card to read from.
regAddrStart address of I/O register to read the data from.
rdDataPointer to the application buffer where the read data will be copied into.
nBytesNumber of bytes to read.
isAddrInc

True - increment the register address after each byte is read.

False - address is not incremented.

Returns

The buffer handle is returned in the commandHandle argument. It will be DRV_SDMMC_COMMAND_HANDLE_INVALID if the request was not successful.

Example

uint8_t CACHE_ALIGN myData;

// address should be block aligned.
uint32_t reg_addr = 0x1000;
DRV_SDMMC_COMMAND_HANDLE commandHandle;

// Event is received when the buffer is processed.

void APP_SDMMCEventHandler(
    DRV_SDMMC_EVENT event,
    DRV_SDMMC_COMMAND_HANDLE commandHandle,
    uintptr_t contextHandle
)
{
    switch(event)
    {
        case DRV_SDMMC_EVENT_COMMAND_COMPLETE:
        {
            // This means the data was transferred successfully
            break;
        }

        case DRV_SDMMC_EVENT_COMMAND_ERROR:
        {
            // Error handling here
            break;
        }

        default:
        {
            break;
        }
    }
}

// mySDMMCHandle is the handle returned
// by the DRV_SDMMC_Open function.

// Client registers an event handler with driver

DRV_SDMMC_EventHandlerSet(mySDMMCHandle, APP_SDMMCEventHandler, (uintptr_t)NULL);

DRV_SDMMC_Async_SDIO_Read (
    mySDMMCHandle,
    &commandHandle,
    1,
    reg_addr,
    &myData,
    1,
    false
);

if(commandHandle == DRV_SDMMC_COMMAND_HANDLE_INVALID)
{
    // Error handling here
}

Remarks

None.