1.1.5.3.8 DRV_I2S_BufferCompletedBytesGet Function

size_t DRV_I2S_BufferCompletedBytesGet

(

DRV_I2S_BUFFER_HANDLE bufferHandle

);

Summary

Returns the number of bytes that have been processed for the specified buffer request.

Description

The client can use this function, in a case where the buffer is terminated due to an error, to obtain the number of bytes that have been processed. Or in any other use case. This function can be used for non-DMA buffer transfers only. It cannot be used when the I2S driver is configured to use DMA.

Preconditions

DRV_I2S_Open must have been called to obtain a valid opened device handle.

Either the DRV_I2S_ReadBufferAdd or DRV_I2S_WriteBufferAdd function must have been called and a valid buffer handle returned.

Parameters

ParametersDescription
bufferhandleHandle for the buffer of which the processed number of bytes to be obtained.

Returns

Returns the number of bytes that have been processed for this buffer.

Returns DRV_I2S_BUFFER_HANDLE_INVALID for an invalid or an expired buffer handle.

Remarks

This function is expected to work in non-DMA mode only. This function is thread safe when used in a RTOS application. If called from the callback, it must not call an OSAL mutex or critical section.

Example

_// myAppObj is an application specific 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_I2SBufferEventHandle,

(uintptr_t)&myAppObj );

DRV_I2S_ReadBufferAdd( myI2Shandle, myBuffer, MY_BUFFER_SIZE, bufferHandle); if(DRV_I2S_BUFFER_HANDLE_INVALID == bufferHandle) { _// Error handling here_

}

_// Event Processing Technique. Event is received when // the buffer is processed._

void APP_I2SBufferEventHandler( DRV_I2S_BUFFER_EVENT event, DRV_I2S_BUFFER_HANDLE bufferHandle, uintptr_t contextHandle )

{

_// 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 *) contextHandle; size_t processedBytes; switch(event) { case DRV_I2S_BUFFER_EVENT_COMPLETE: _// This means the data was transferred._ break; case DRV_I2S_BUFFER_EVENT_ERROR: _// Error handling here._

_// We can find out how many bytes have been processed in this_ _// buffer request prior to the error._

processedBytes= DRV_I2S_BufferCompletedBytesGet(bufferHandle); break; default: break; }

}

C

size_t DRV_I2S_BufferCompletedBytesGet(DRV_I2S_BUFFER_HANDLE bufferHandle);