Jump to main content

##

# 1.1.3.4.17 DRV_MEMORY_TransferHandlerSet Function

## C

    void DRV_MEMORY_TransferHandlerSet
    (
        const DRV_HANDLE handle,
        const void * transferHandler,
        const uintptr_t context
    );

## Summary

Sets the pointer to the function (and it's context) to be called when queued operation has completed.

## Description

This function allows a client to set an event handling function for the driver to call back when queued operation has completed.

When a client calls a read, write, erase or a erasewrite function, it is provided with a handle identifying the command that was added to the driver's buffer queue. The driver will pass this handle back to the client by calling "transferHandler" function when the queued operation has completed.

The event handler should be set before the client performs any operations that could generate events. The event handler once set, persists until the client closes the driver or sets another event handler (which could be a "NULL" pointer to indicate no callback).

## Precondition

The DRV_MEMORY_Open() routine must have been called to obtain a valid opened device handle.

## Parameters

Param | Description
--- | ---
handle | A valid open-instance handle, returned from the driver's open function
transferHandler | Pointer to the event handler function implemented by the user
context | The value of parameter will be passed back to the client unchanged, when the transferHandler function is called. It can be used to identify any client specific data object that identifies the instance of the client module (for example, it may be a pointer to the client module's state structure).

## Returns

None.

## Example

    DRV_MEMORY_COMMAND_HANDLE commandHandle;

    // memoryHandle is the handle returned by the DRV_MEMORY_Open function.
    // Client registers an event handler with driver

    void appTransferHandler
    (
        DRV_MEMORY_EVENT event,
        DRV_MEMORY_COMMAND_HANDLE commandHandle,
        uintptr_t context
    )
    {
        switch(event)
        {
            case DRV_MEMORY_EVENT_COMMAND_COMPLETE:
            {
                xfer_done = true;
                break;
            }

            case DRV_MEMORY_EVENT_COMMAND_ERROR:
            {
                // Handle Error
                break;
            }

            default:
            {
                break;
            }
        }
    }

    DRV_MEMORY_TransferHandlerSet(memoryHandle, appTransferHandler, (uintptr_t)NULL);

## Remarks

If the client does not want to be notified when the queued operation has completed, it does not need to register a callback.

Used in Asynchronous Mode of operation.