1.9.4.2 DMA_ChannelCallbackRegister Function

C

void DMA_ChannelCallbackRegister( DMA_CHANNEL channel, const DMA_CHANNEL_CALLBACK callback, const uintptr_t context )

Summary

This function allows a DMA 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 DMA 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 context 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 DMA channel.

Precondition

DMA should have been initialized by calling DMA_Initialize.

Parameters

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

Returns

None.

Example

MY_APP_OBJ myAppObj;

void APP_DMATransferEventHandler(DMA_TRANSFER_EVENT event, uintptr_t contextHandle)
{
    switch(event)
    {
        case DMA_TRANSFER_EVENT_BLOCK_TRANSFER_COMPLETE:
        // This means the data was transferred.
        break;
        
        case DMA_TRANSFER_EVENT_ERROR:
        // Error handling here.
        break;
        
        default:
        break;
    }
}

// User registers an event handler with DMA channel. This is done once.
DMA_ChannelCallbackRegister(DMA_CHANNEL_1, APP_DMATransferEventHandler, (uintptr_t)&myAppObj);

Remarks

None.