1.1.6.4.6 DRV_SDMMC_AsyncRead Function

C

void DRV_SDMMC_AsyncRead (
    const DRV_HANDLE handle,
    DRV_SDMMC_COMMAND_HANDLE* commandHandle,
    void* targetBuffer,
    uint32_t blockStart,
    uint32_t nBlock
);

Summary

Reads blocks of data from the specified block address of the SD Card.

Description

This function schedules a non-blocking read operation for reading blocks of data from the SD Card. 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 application buffer 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 target buffer pointer is NULL

  • if the number of blocks to be read is zero or more than the actual number of blocks available

  • 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 must have been called and a valid handle must have been obtained.

Parameters

ParamDescription
handleA valid open-instance handle, returned from the driver's open function
commandHandlePointer to an argument that will contain the return buffer handle
targetBufferBuffer into which the data read from the SD Card will be placed
blockStartStart block address of the SD Card from where the read should begin.
nBlockTotal number of blocks to be read.

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 myBuffer[MY_BUFFER_SIZE];

// address should be block aligned.
uint32_t blockStart = 0x00;
uint32_t nBlock = 2;
DRV_SDMMC_COMMAND_HANDLE commandHandle;
MY_APP_OBJ myAppObj;

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

DRV_SDMMC_AsyncRead(mySDMMCHandle, &commandHandle, &myBuffer[0], blockStart, nBlock);

if(commandHandle == DRV_SDMMC_COMMAND_HANDLE_INVALID)
{
    // Error handling here
}
else
{
    // Read Successfully queued
}

Remarks

None.