1.1.5.3.4 DRV_I2S_BufferEventHandlerSet Function
void DRV_I2S_BufferEventHandlerSet ( const DRV_HANDLE handle, const DRV_I2S_BUFFER_EVENT_HANDLER eventHandler, const uintptr_t context )
Summary
Allows a client to identify a buffer event handling function for the driver to call back when queued buffer transfers have finished.
Description
This function allows a client to register a buffer event handling function with the driver to call back when queued buffer transfers have finished. When a client calls either the DRV_I2S_ReadBufferAdd or DRV_I2S_WriteBufferAdd function, it is provided with a handle identifying the buffer that was added to the driver's buffer queue. The driver will pass this handle back to the client by calling "eventHandler" function when the buffer transfer has completed.
The event handler should be set before the client performs any "buffer add" 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).
Preconditions
DRV_I2S_Open must have been called to obtain a valid opened device handle.
Parameters
Parameters | Description |
---|---|
handle | A valid open-instance handle, returned from the driver's open routine. |
eventHandler | Pointer to the event handler function. |
context | The value of parameter will be passed back to the client unchanged, when the eventHandler 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.
Remarks
If the client does not want to be notified when the queued buffer transfer has completed, it does not need to register a callback. This function is thread safe when called in a RTOS application.
Example
_// myAppObj is an application specific state data object._
MY_APP_OBJ myAppObj;
uint8_t mybuffer[MY_BUFFER_SIZE]; DRV_I2S_BUFFER_HANDLE bufferHandle;
_// myI2SHandle is the handle returned // by the DRV_I2S_Open function._
_// Client registers an event handler with driver. This is done once_
DRV_I2S_BufferEventHandlerSet( myI2SHandle, APP_I2SBufferEventHandler,
(uintptr_t)&myAppObj );
DRV_I2S_ReadBufferAdd(myI2Shandle, myBuffer, MY_BUFFER_SIZE,
&bufferHandle);
if(DRV_I2S_BUFFER_HANDLE_INVALID == bufferHandle) {
_// Error handling here_
}
_// Event is received when the buffer is processed._
void APP_I2SBufferEventHandler(DRV_I2S_BUFFER_EVENT event, DRV_I2S_BUFFER_HANDLE handle, uintptr_t context)
{
_// The context handle was set to an application specific_ _// object. It is now retrievable easily in the event handler._
MY_APP_OBJ myAppObj = (MY_APP_OBJ *) context; switch(event) { case DRV_I2S_BUFFER_EVENT_COMPLETE: _// This means the data was transferred._ break; case DRV_I2S_BUFFER_EVENT_ERROR: _// Error handling here._ break; default: break; }
}
C
void DRV_I2S_BufferEventHandlerSet(const DRV_HANDLE handle, const DRV_I2S_BUFFER_EVENT_HANDLER eventHandler, const uintptr_t context);