1.22.24.17 SDHCx_CallbackRegister Function

C

/* x = SDHC instance number (x is applicable only on devices with more than one instances of SDHC) */

void SDHCx_CallbackRegister(SDHC_CALLBACK callback, uintptr_t contextHandle)

Summary

This function allows a application to set an callback (event handler) with the SDHC PLIB

Description

This function allows application to set an event handler. Application may want to receive transfer related events after submitting a SDHC PLIB transfer request. The event handler should be set before the application intends to perform operations that could generate events.

This function accepts a contextHandle parameter. This parameter could be set by the application to contain (or point to) any application specific data object that should be associated with this SDHC PLIB. The contextHandle parameter is not modified by the PLIB and is passed as is in the application event handler.

Precondition

SDHC_Initialize() must have been called first for the associated instance.

Parameters

Param Description
callback Pointer to the event handler function
contextHandle The value of parameter will be passed back to the application unchanged, when the callback function is called. It can be used to identify any application specific data object that identifies the instance of the module (for example, it may be a pointer to the modules state structure)

Returns

None

Example

MY_APP_OBJ myAppObj;

static void SDHC_TransferEventHandler(
	SDHC_XFER_STATUS xferStatus,
	uintptr_t contextHandle
)
{
    MY_APP_OBJ* myAppObj = (MY_APP_OBJ*)contextHandle;
    
    if (xferStatus & SDHC_XFER_STATUS_CMD_COMPLETED)
    {
        // Command transfer complete, read the command error status.
        cmd_error = SDHC1_CommandErrorGet();
    }
    if (xferStatus & SDHC_XFER_STATUS_DATA_COMPLETED)
    {
        // Data transfer complete, read the data error status.
        data_error = SDHC1_DataErrorGet();
    }
}

// User registers an event handler with the SDHC PLIB. This is usually done once.
SDHC1_CallbackRegister(SDHC_TransferEventHandler, (uintptr_t)&myAppObj);

Remarks

None