Jump to main content

##

# 2.32.2 DMAC_ChannelCallbackRegister Function

## C

    void DMAC_ChannelCallbackRegister
    (
    DMAC_CHANNEL channel,
    const DMAC_CHANNEL_CALLBACK eventHandler,
    const uintptr_t contextHandle
    )

## Summary

This function allows a DMAC PLIB client to set an event handler.

## Description

This function allows a client to set an event handler. The client may want to receive transfer related events in cases when it submits a DMAC PLIB transfer request. The event handler should be set before the client intends to perform operations that could generate events.

In case of linked transfer descriptors, the callback function will be called for every transfer in the transfer descriptor chain. The application must implement it's own logic to link the callback to the the transfer descriptor being completed.

This function accepts a contextHandle parameter. This parameter could be set by the client to contain (or point to) any client specific data object that should be associated with this DMAC channel.

## Precondition

DMAC should have been initialized by calling DMAC_Initialize.

## Parameters

Param | Description
--- | ---
channel | A specific DMAC channel from which the events are expected.
eventHandler | Pointer to the event handler function.
contextHandle | Value identifying the context of the application/driver/middleware that registered the event handling function.

## Returns

None.

## Example

    MY_APP_OBJ myAppObj;

    void APP_DMACTransferEventHandler(DMAC_TRANSFER_EVENT event,
    uintptr_t contextHandle)
    {
        switch(event)
        {
            case DMAC_TRANSFER_COMPLETE:
            // This means the data was transferred.
            break;

            case DMAC_TRANSFER_ERROR:
            // Error handling here.
            break;

            default:
            break;
        }
    }

    // User registers an event handler with DMAC channel. This is done once.
    DMAC_ChannelCallbackRegister(DMAC_CHANNEL_0, APP_DMACTransferEventHandler, (uintptr_t)&myAppObj);

## Remarks

None.