Jump to main content

##

# 2.54.13 HSMCI_CallbackRegister Function

## C

    void HSMCI_CallbackRegister(HSMCI_CALLBACK callback, uintptr_t contextHandle)

## Summary

This function allows a HSMCI PLIB application to set an event handler.

## Description

This function allows a application to set an event handler. The application may want to receive transfer related events in cases when it submits a HSMCI 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 HSMCI PLIB. The contextHandle parameter is not modified by the PLIB and is passed as is in the application event handler.

## Precondition

HSMCI_Initialize() must have been called first.

## 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 HSMCI_TransferEventHandler(
    	HSMCI_XFER_STATUS xferStatus,
    	uintptr_t contextHandle
    )
    {
        MY_APP_OBJ* myAppObj = (MY_APP_OBJ*)contextHandle;

        if (xferStatus & HSMCI_XFER_STATUS_CMD_COMPLETED)
        {
            // Command transfer complete, read the command error status.
            cmd_error = HSMCI_CommandErrorGet();
        }
        if (xferStatus & HSMCI_XFER_STATUS_DATA_COMPLETED)
        {
            // Data transfer complete, read the data error status.
            data_error = HSMCI_DataErrorGet();
        }
    }

    // User registers an event handler with the HSMCI PLIB. This is usually done once.
    HSMCI_CallbackRegister(HSMCI_TransferEventHandler, (uintptr_t)&myAppObj);

## Remarks

None.