USBLibAPIGuide  1.00.00.01
Data Structures | Macros | Typedefs | Functions
Usblib_buffer_api

Data Structures

struct  tLPMFeature
 
struct  tUSBRingBufObject
 
struct  tUSBBufferVars
 
struct  tUSBBuffer
 

Macros

#define USB_BUFFER_FLAG_SEND_ZLP   0x00000001
 
#define USBLIB_FEATURE_LPM   0x00000001
 
#define USBLIB_FEATURE_LPM_RMT_WAKE   0x00000002
 
#define USBLIB_FEATURE_LPM_EN   0x00000001
 
#define USBLIB_FEATURE_LPM_DIS   0x00000000
 
#define USBLIB_FEATURE_CPUCLK   0x00000002
 
#define USBLIB_FEATURE_USBPLL   0x00000003
 
#define USBLIB_FEATURE_USBULPI   0x00000004
 
#define USBLIB_FEATURE_ULPI_NONE   0x00000000
 
#define USBLIB_FEATURE_ULPI_HS   0x00000010
 
#define USBLIB_FEATURE_ULPI_FS   0x00000020
 
#define USBLIB_FEATURE_POWER   0x00000005
 
#define USBLIB_FEATURE_POWER_SELF   0x00000001
 
#define USBLIB_FEATURE_POWER_BUS   0x00000000
 
#define USBLIB_FEATURE_REMOTE_WAKE   0x00000002
 
#define NULL   ((void *)0)
 

Typedefs

typedef uint32_t(* tUSBPacketTransfer) (void *pvHandle, uint8_t *pi8Data, uint32_t ui32Length, bool bLast)
 
typedef uint32_t(* tUSBPacketAvailable) (void *pvHandle)
 

Functions

const tUSBBufferUSBBufferInit (tUSBBuffer *psBuffer)
 
void USBBufferZeroLengthPacketInsert (const tUSBBuffer *psBuffer, bool bSendZLP)
 
void USBBufferInfoGet (const tUSBBuffer *psBuffer, tUSBRingBufObject *psRingBuf)
 
void USBBufferDataWritten (const tUSBBuffer *psBuffer, uint32_t ui32Length)
 
void USBBufferDataRemoved (const tUSBBuffer *psBuffer, uint32_t ui32Length)
 
void * USBBufferCallbackDataSet (tUSBBuffer *psBuffer, void *pvCBData)
 
uint32_t USBBufferWrite (const tUSBBuffer *psBuffer, const uint8_t *pui8Data, uint32_t ui32Length)
 
void USBBufferFlush (const tUSBBuffer *psBuffer)
 
uint32_t USBBufferRead (const tUSBBuffer *psBuffer, uint8_t *pui8Data, uint32_t ui32Length)
 
uint32_t USBBufferDataAvailable (const tUSBBuffer *psBuffer)
 
uint32_t USBBufferSpaceAvailable (const tUSBBuffer *psBuffer)
 
uint32_t USBBufferEventCallback (void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData)
 
bool USBRingBufFull (tUSBRingBufObject *psUSBRingBuf)
 
bool USBRingBufEmpty (tUSBRingBufObject *psUSBRingBuf)
 
void USBRingBufFlush (tUSBRingBufObject *psUSBRingBuf)
 
uint32_t USBRingBufUsed (tUSBRingBufObject *psUSBRingBuf)
 
uint32_t USBRingBufFree (tUSBRingBufObject *psUSBRingBuf)
 
uint32_t USBRingBufContigUsed (tUSBRingBufObject *psUSBRingBuf)
 
uint32_t USBRingBufContigFree (tUSBRingBufObject *psUSBRingBuf)
 
uint32_t USBRingBufSize (tUSBRingBufObject *psUSBRingBuf)
 
uint8_t USBRingBufReadOne (tUSBRingBufObject *psUSBRingBuf)
 
void USBRingBufRead (tUSBRingBufObject *psUSBRingBuf, uint8_t *pui8Data, uint32_t ui32Length)
 
void USBRingBufAdvanceRead (tUSBRingBufObject *psUSBRingBuf, uint32_t ui32NumBytes)
 
void USBRingBufAdvanceWrite (tUSBRingBufObject *psUSBRingBuf, uint32_t ui32NumBytes)
 
void USBRingBufWriteOne (tUSBRingBufObject *psUSBRingBuf, uint8_t ui8Data)
 
void USBRingBufWrite (tUSBRingBufObject *psUSBRingBuf, const uint8_t *pui8Data, uint32_t ui32Length)
 
void USBRingBufInit (tUSBRingBufObject *psUSBRingBuf, uint8_t *pui8Buf, uint32_t ui32Size)
 

Detailed Description

Macro Definition Documentation

§ USB_BUFFER_FLAG_SEND_ZLP

#define USB_BUFFER_FLAG_SEND_ZLP   0x00000001

§ USBLIB_FEATURE_LPM

#define USBLIB_FEATURE_LPM   0x00000001

This feature setting enables or disables LPM support in the USB library in either host or device mode depending on if the USBHCDFeatureSet() or USBDCDFeatureSet() is called. If no action is taken the default behavior of USB library is to not support LPM transactions. The pvFeature value is a pointer to a 32-bit value containing the a logical OR of the following values:

  • USBLIB_FEATURE_LPM_EN is used to enable LPM support in host or device mode.
  • USBLIB_FEATURE_LPM_DIS(default) is used to disable LPM support in host or device mode.
  • USBLIB_FEATURE_LPM_RMT_WAKE is used to enable remote wake from an LPM suspended state.

Referenced by USBDCDFeatureSet().

§ USBLIB_FEATURE_LPM_RMT_WAKE

#define USBLIB_FEATURE_LPM_RMT_WAKE   0x00000002

§ USBLIB_FEATURE_LPM_EN

#define USBLIB_FEATURE_LPM_EN   0x00000001

Referenced by USBDCDFeatureSet().

§ USBLIB_FEATURE_LPM_DIS

#define USBLIB_FEATURE_LPM_DIS   0x00000000

§ USBLIB_FEATURE_CPUCLK

#define USBLIB_FEATURE_CPUCLK   0x00000002

This feature setting allows an application to inform the USB library of the current processor speed that is can use for internal timing when the frame counter is not yet running. The pvFeature is a pointer to a 32-bit value that holds the processor frequency in Hz.

Referenced by USBHCDFeatureSet().

§ USBLIB_FEATURE_USBPLL

#define USBLIB_FEATURE_USBPLL   0x00000003

This feature setting allows an application to inform the USB library of the current USB PLL rate in cases where the USB library needs this information for internal configuration. If this feature is not set, then default rate for the USB PLL is 480MHz. The pvFeature is a pointer to an 32-bit value that holds the USB PLL speed in Hz. If the application needs to use an external USB clock the PLL value should be set to zero. This is used when connecting to an external USB phy which is providing the 60-MHz clock.

Referenced by USBDCDFeatureSet().

§ USBLIB_FEATURE_USBULPI

#define USBLIB_FEATURE_USBULPI   0x00000004

This feature setting allows an application to disable or configure and enable the ULPI features in the USB library. If this feature is not set, the default behavior is to not support ULPI operation. The pvFeature is a pointer to an 32-bit value that holds the USB ULPI configuration. The following are the valid settings for this feature:

  • USBLIB_FEATURE_ULPI_NONE disables all ULPI support.
  • USBLIB_FEATURE_ULPI_HS enable ULPI with high speed support.
  • USBLIB_FEATURE_ULPI_FS enable ULPI with full speed support.

Referenced by USBDBulkCompositeInit(), USBDCDCCompositeInit(), and USBDCDFeatureGet().

§ USBLIB_FEATURE_ULPI_NONE

#define USBLIB_FEATURE_ULPI_NONE   0x00000000

§ USBLIB_FEATURE_ULPI_HS

#define USBLIB_FEATURE_ULPI_HS   0x00000010

§ USBLIB_FEATURE_ULPI_FS

#define USBLIB_FEATURE_ULPI_FS   0x00000020

§ USBLIB_FEATURE_POWER

#define USBLIB_FEATURE_POWER   0x00000005

This feature setting enables or disables various power settings in the USB library in either host or device mode depending on if the USBHCDFeatureSet() or USBDCDFeatureSet() is called. The pvFeature value is a pointer to a 32-bit value containing the a logical OR of the following values:

  • USBLIB_FEATURE_POWER_BUS - USB device mode is bus powered(default).
  • USBLIB_FEATURE_POWER_SELF - USB device mode is self powered.
  • USBLIB_FEATURE_REMOTE_WAKE - Enable USB remote wake feature.

§ USBLIB_FEATURE_POWER_SELF

#define USBLIB_FEATURE_POWER_SELF   0x00000001

§ USBLIB_FEATURE_POWER_BUS

#define USBLIB_FEATURE_POWER_BUS   0x00000000

§ USBLIB_FEATURE_REMOTE_WAKE

#define USBLIB_FEATURE_REMOTE_WAKE   0x00000002

§ NULL

#define NULL   ((void *)0)

Typedef Documentation

§ tUSBPacketTransfer

typedef uint32_t(* tUSBPacketTransfer) (void *pvHandle, uint8_t *pi8Data, uint32_t ui32Length, bool bLast)

A function pointer type which describes either a class driver packet read or packet write function (both have the same prototype) to the USB buffer object.

§ tUSBPacketAvailable

typedef uint32_t(* tUSBPacketAvailable) (void *pvHandle)

A function pointer type which describes either a class driver transmit or receive packet available function (both have the same prototype) to the USB buffer object.

Parameters
pvHandleis the handle of the device.
Returns
None.

Function Documentation

§ USBBufferInit()

const tUSBBuffer* USBBufferInit ( tUSBBuffer psBuffer)

Initializes a USB buffer object to be used with a given USB controller and device or host class driver.

Parameters
psBufferpoints to a structure containing information on the buffer memory to be used and the underlying device or host class driver whose data is to be buffered. This structure must remain accessible for as long as the buffer is in use.

This function is used to initialize a USB buffer object and insert it into the function and callback interfaces between an underlying driver and the application. The caller supplies information on both the RAM to be used to buffer data, the type of buffer to be created (transmit or receive) and the functions to be called in the lower layer to transfer data to or from the USB controller.

Returns
Returns the original buffer structure pointer if successful or NULL if an error is detected.

References tUSBBuffer::pfnAvailable, tUSBBuffer::pfnCallback, tUSBBuffer::pfnTransfer, tUSBBuffer::pui8Buffer, tUSBBuffer::sPrivateData, tUSBBufferVars::sRingBuf, tUSBBuffer::ui32BufferSize, tUSBBufferVars::ui32Flags, and USBRingBufInit().

§ USBBufferZeroLengthPacketInsert()

void USBBufferZeroLengthPacketInsert ( const tUSBBuffer psBuffer,
bool  bSendZLP 
)

Enables or disables zero-length packet insertion.

Parameters
psBufferis the pointer to the buffer instance whose information is being queried.
bSendZLPis true to send zero-length packets or false to prevent them from being sent.

This function allows the use of zero-length packets to be controlled by an application. In cases where the USB buffer has sent a full (64 byte) packet and then discovers that the transmit buffer is empty, the default behavior is to do nothing. Some protocols, however, require that a zero- length packet be inserted to signal the end of the data. When using such a protocol, this function should be called with bSendZLP set to true to enable the desired behavior.

Returns
None.

References tUSBBufferVars::ui32Flags, and USB_BUFFER_FLAG_SEND_ZLP.

§ USBBufferInfoGet()

void USBBufferInfoGet ( const tUSBBuffer psBuffer,
tUSBRingBufObject psRingBuf 
)

Returns the current ring buffer indices for this USB buffer.

Parameters
psBufferis the pointer to the buffer instance whose information is being queried.
psRingBufis a pointer to storage that will be written with the current ring buffer control structure for this USB buffer.

This function is provided to aid a client wishing to write data directly into the USB buffer rather than using the USBBufferWrite() function. This may be necessary to control when the USBBuffer starts transmission of a large block of data, for example.

A transmit buffer will immediately send a new packet on any call to USBBufferWrite() if the underlying layer indicates that a transmission can be started. In some cases this is not desirable and a client may wish to wishes to write more data to the buffer in advance of starting transmission to the lower layer. In such cases, this function may be called to retrieve the current ring buffer indices and the buffer accessed directly. Once the client has written all data it wishes to send, it should call function USBBufferDataWritten() to indicate that transmission may begin.

Returns
None.

References tUSBRingBufObject::pui8Buf, tUSBBuffer::sPrivateData, tUSBBufferVars::sRingBuf, tUSBRingBufObject::ui32ReadIndex, tUSBRingBufObject::ui32Size, and tUSBRingBufObject::ui32WriteIndex.

§ USBBufferDataWritten()

void USBBufferDataWritten ( const tUSBBuffer psBuffer,
uint32_t  ui32Length 
)

Indicates that a client has written data directly into the buffer and wishes to start transmission.

Parameters
psBufferis the pointer to the buffer instance into which data has been written.
ui32Lengthis the number of bytes of data that the client has written.

This function updates the USB buffer write pointer and starts transmission of the data in the buffer assuming the lower layer is ready to receive a new packet. The function is provided to aid a client wishing to write data directly into the USB buffer rather than using the USBBufferWrite() function. This may be necessary to control when the USB buffer starts transmission of a large block of data, for example.

A transmit buffer will immediately send a new packet on any call to USBBufferWrite() if the underlying layer indicates that a transmission can be started. In some cases this is not desirable and a client may wish to write more data to the buffer in advance of starting transmission to the lower layer. In such cases, USBBufferInfoGet() may be called to retrieve the current ring buffer indices and the buffer accessed directly. Once the client has written all data it wishes to send (taking care to handle the ring buffer wrap), it should call this function to indicate that transmission may begin.

Returns
None.

References tUSBBufferVars::sRingBuf, and USBRingBufAdvanceWrite().

§ USBBufferDataRemoved()

void USBBufferDataRemoved ( const tUSBBuffer psBuffer,
uint32_t  ui32Length 
)

Indicates that a client has read data directly out of the buffer.

Parameters
psBufferis the pointer to the buffer instance from which data has been read.
ui32Lengthis the number of bytes of data that the client has read.

This function updates the USB buffer read pointer to remove data that the client has read directly rather than via a call to USBBufferRead(). The function is provided to aid a client wishing to minimize data copying. To read directly from the buffer, a client must call USBBufferInfoGet() to retrieve the current buffer inpsBufVarsdices. With this information, the data following the current read index can be read. Once the client has processed much data as it needs, USBBufferDataRemoved() must be called to advance the read pointer past the data that has been read and free up that section of the buffer. The client must take care to correctly handle the wrap point if accessing the buffer directly.

Returns
None.

References tUSBBufferVars::sRingBuf, and USBRingBufAdvanceRead().

§ USBBufferCallbackDataSet()

void* USBBufferCallbackDataSet ( tUSBBuffer psBuffer,
void *  pvCBData 
)

Sets the callback pointer supplied to clients of this buffer.

Parameters
psBufferis the pointer to the buffer instance whose callback data is to be changed.
pvCBDatais the pointer the client wishes to receive on all future callbacks from this buffer.

This function sets the callback pointer which this buffer will supply to clients as the pvCBData parameter in all future calls to the event callback.

Note
If this function is to be used, the application must ensure that the tUSBBuffer structure used to describe this buffer is held in RAM rather than flash. The pvCBData value passed is written directly into this structure.
Returns
Returns the previous callback pointer set for the buffer.

References tUSBBuffer::pvCBData.

§ USBBufferWrite()

uint32_t USBBufferWrite ( const tUSBBuffer psBuffer,
const uint8_t *  pui8Data,
uint32_t  ui32Length 
)

Writes a block of data to the transmit buffer and queues it for transmission to the USB controller.

Parameters
psBufferpoints to the pointer instance into which data is to be written.
pui8Datapoints to the first byte of data which is to be written.
ui32Lengthis the number of bytes of data to write to the buffer.

This function copies the supplied data into the transmit buffer. The transmit buffer data will be packetized according to the constraints imposed by the lower layer in use and sent to the USB controller as soon as possible. Once a packet is transmitted and acknowledged, a USB_EVENT_TX_COMPLETE event will be sent to the application callback indicating the number of bytes that have been sent from the buffer.

Attempts to send more data than there is space for in the transmit buffer will result in fewer bytes than expected being written. The value returned by the function indicates the actual number of bytes copied to the buffer.

Returns
Returns the number of bytes actually written.

References tUSBBuffer::bTransmitBuffer, tUSBBufferVars::sRingBuf, USBRingBufFree(), and USBRingBufWrite().

§ USBBufferFlush()

void USBBufferFlush ( const tUSBBuffer psBuffer)

Flushes a USB buffer, discarding any data that it contains.

Parameters
psBufferis the pointer to the buffer instance which is to be flushed.

This function discards all data currently in the supplied buffer without processing (transmitting it via the USB controller or passing it to the client depending upon the buffer mode).

Returns
None.

References tUSBBufferVars::sRingBuf, and USBRingBufFlush().

§ USBBufferRead()

uint32_t USBBufferRead ( const tUSBBuffer psBuffer,
uint8_t *  pui8Data,
uint32_t  ui32Length 
)

Reads a block of data from a USB receive buffer into storage supplied by the caller.

Parameters
psBufferis the pointer to the buffer instance from which data is to be read.
pui8Datapoints to a buffer into which the received data will be written.
ui32Lengthis the size of the buffer pointed to by pui8Data.

This function reads up to ui32Length bytes of data received from the USB host into the supplied application buffer. If the receive buffer contains fewer than ui32Length bytes of data, the data that is present will be copied and the return code will indicate the actual number of bytes copied to pui8Data.

Returns
Returns the number of bytes of data read.

References tUSBBufferVars::sRingBuf, USBRingBufRead(), and USBRingBufUsed().

§ USBBufferDataAvailable()

uint32_t USBBufferDataAvailable ( const tUSBBuffer psBuffer)

Returns the number of bytes of data available in the buffer.

Parameters
psBufferis the pointer to the buffer instance which is to be queried.

This function may be used to determine the number of bytes of data in a buffer. For a receive buffer, this indicates the number of bytes that the client can read from the buffer using USBBufferRead(). For a transmit buffer, this indicates the amount of data that remains to be sent to the USB controller.

Returns
Returns the number of bytes of data in the buffer.

References tUSBBufferVars::sRingBuf, and USBRingBufUsed().

§ USBBufferSpaceAvailable()

uint32_t USBBufferSpaceAvailable ( const tUSBBuffer psBuffer)

Returns the number of free bytes in the buffer.

Parameters
psBufferis the pointer to the buffer instance which is to be queried.

This function returns the number of free bytes in the buffer. For a transmit buffer, this indicates the maximum number of bytes that can be passed on a call to USBBufferWrite() and accepted for transmission. For a receive buffer, it indicates the number of bytes that can be read from the USB controller before the buffer will be full.

Returns
Returns the number of free bytes in the buffer.

References tUSBBufferVars::sRingBuf, and USBRingBufFree().

§ USBBufferEventCallback()

uint32_t USBBufferEventCallback ( void *  pvCBData,
uint32_t  ui32Event,
uint32_t  ui32MsgValue,
void *  pvMsgData 
)

Called by the USB buffer to notify the client of asynchronous events.

Parameters
pvCBDatais the client-supplied callback pointer associated with this buffer instance.
ui32Eventis the identifier of the event being sent. This will be a general event identifier of the form USBD_EVENT_xxxx or a device class-dependent event of the form USBD_CDC_EVENT_xxx or USBD_HID_EVENT_xxx.
ui32MsgValueis an event-specific parameter value.
pvMsgDatais an event-specific data pointer.

This function is the USB buffer event handler that applications should register with the USB device class driver as the callback for the channel which is to be buffered using this buffer.

Note
This function will never be called by an application. It is the handler that allows the USB buffer to be inserted above the device class driver or host pipe driver and below the application to offer buffering support.
Returns
The return value is dependent upon the event being processed.

References tUSBBuffer::bTransmitBuffer, and USB_EVENT_RX_AVAILABLE.

§ USBRingBufFull()

bool USBRingBufFull ( tUSBRingBufObject psUSBRingBuf)

Determines whether a ring buffer is full or not.

Parameters
psUSBRingBufis the ring buffer object to empty.

This function is used to determine whether or not a given ring buffer is full. The structure is specifically to ensure that we do not see warnings from the compiler related to the order of volatile accesses being undefined.

Returns
Returns true if the buffer is full or false otherwise.

References NULL, tUSBRingBufObject::ui32ReadIndex, tUSBRingBufObject::ui32Size, and tUSBRingBufObject::ui32WriteIndex.

§ USBRingBufEmpty()

bool USBRingBufEmpty ( tUSBRingBufObject psUSBRingBuf)

Determines whether a ring buffer is empty or not.

Parameters
psUSBRingBufis the ring buffer object to empty.

This function is used to determine whether or not a given ring buffer is empty. The structure is specifically to ensure that we do not see warnings from the compiler related to the order of volatile accesses being undefined.

Returns
Returns true if the buffer is empty or false otherwise.

References NULL, tUSBRingBufObject::ui32ReadIndex, and tUSBRingBufObject::ui32WriteIndex.

§ USBRingBufFlush()

void USBRingBufFlush ( tUSBRingBufObject psUSBRingBuf)

Empties the ring buffer.

Parameters
psUSBRingBufis the ring buffer object to empty.

Discards all data from the ring buffer.

Returns
None.

References NULL, tUSBRingBufObject::ui32ReadIndex, and tUSBRingBufObject::ui32WriteIndex.

Referenced by USBBufferFlush().

§ USBRingBufUsed()

uint32_t USBRingBufUsed ( tUSBRingBufObject psUSBRingBuf)

Returns number of bytes stored in ring buffer.

Parameters
psUSBRingBufis the ring buffer object to check.

This function returns the number of bytes stored in the ring buffer.

Returns
Returns the number of bytes stored in the ring buffer.

References NULL, tUSBRingBufObject::ui32ReadIndex, tUSBRingBufObject::ui32Size, and tUSBRingBufObject::ui32WriteIndex.

Referenced by USBBufferDataAvailable(), USBBufferRead(), USBRingBufAdvanceRead(), USBRingBufFree(), USBRingBufRead(), and USBRingBufReadOne().

§ USBRingBufFree()

uint32_t USBRingBufFree ( tUSBRingBufObject psUSBRingBuf)

Returns number of bytes available in a ring buffer.

Parameters
psUSBRingBufis the ring buffer object to check.

This function returns the number of bytes available in the ring buffer.

Returns
Returns the number of bytes available in the ring buffer.

References NULL, tUSBRingBufObject::ui32Size, and USBRingBufUsed().

Referenced by USBBufferSpaceAvailable(), USBBufferWrite(), USBRingBufAdvanceWrite(), USBRingBufWrite(), and USBRingBufWriteOne().

§ USBRingBufContigUsed()

uint32_t USBRingBufContigUsed ( tUSBRingBufObject psUSBRingBuf)

Returns number of contiguous bytes of data stored in ring buffer ahead of the current read pointer.

Parameters
psUSBRingBufis the ring buffer object to check.

This function returns the number of contiguous bytes of data available in the ring buffer ahead of the current read pointer. This represents the largest block of data which does not straddle the buffer wrap.

Returns
Returns the number of contiguous bytes available.

References NULL, tUSBRingBufObject::ui32ReadIndex, tUSBRingBufObject::ui32Size, and tUSBRingBufObject::ui32WriteIndex.

§ USBRingBufContigFree()

uint32_t USBRingBufContigFree ( tUSBRingBufObject psUSBRingBuf)

Returns number of contiguous free bytes available in a ring buffer.

Parameters
psUSBRingBufis the ring buffer object to check.

This function returns the number of contiguous free bytes ahead of the current write pointer in the ring buffer.

Returns
Returns the number of contiguous bytes available in the ring buffer.

References NULL, tUSBRingBufObject::ui32ReadIndex, tUSBRingBufObject::ui32Size, and tUSBRingBufObject::ui32WriteIndex.

§ USBRingBufSize()

uint32_t USBRingBufSize ( tUSBRingBufObject psUSBRingBuf)

Returns the size in bytes of a ring buffer.

Parameters
psUSBRingBufis the ring buffer object to check.

This function returns the size of the ring buffer.

Returns
Returns the size in bytes of the ring buffer.

References NULL, and tUSBRingBufObject::ui32Size.

§ USBRingBufReadOne()

uint8_t USBRingBufReadOne ( tUSBRingBufObject psUSBRingBuf)

Reads a single byte of data from a ring buffer.

Parameters
psUSBRingBufpoints to the ring buffer to be written to.

This function reads a single byte of data from a ring buffer.

Returns
The byte read from the ring buffer.

References NULL, tUSBRingBufObject::pui8Buf, tUSBRingBufObject::ui32ReadIndex, and USBRingBufUsed().

Referenced by USBRingBufRead().

§ USBRingBufRead()

void USBRingBufRead ( tUSBRingBufObject psUSBRingBuf,
uint8_t *  pui8Data,
uint32_t  ui32Length 
)

Reads data from a ring buffer.

Parameters
psUSBRingBufpoints to the ring buffer to be read from.
pui8Datapoints to where the data should be stored.
ui32Lengthis the number of bytes to be read.

This function reads a sequence of bytes from a ring buffer.

Returns
None.

References NULL, USBRingBufReadOne(), and USBRingBufUsed().

Referenced by USBBufferRead().

§ USBRingBufAdvanceRead()

void USBRingBufAdvanceRead ( tUSBRingBufObject psUSBRingBuf,
uint32_t  ui32NumBytes 
)

Removes bytes from the ring buffer by advancing the read index.

Parameters
psUSBRingBufpoints to the ring buffer from which bytes are to be removed.
ui32NumBytesis the number of bytes to be removed from the buffer.

This function advances the ring buffer read index by a given number of bytes, removing that number of bytes of data from the buffer. If ui32NumBytes is larger than the number of bytes currently in the buffer, the buffer is emptied.

Returns
None.

References NULL, and USBRingBufUsed().

Referenced by USBBufferDataRemoved().

§ USBRingBufAdvanceWrite()

void USBRingBufAdvanceWrite ( tUSBRingBufObject psUSBRingBuf,
uint32_t  ui32NumBytes 
)

Adds bytes to the ring buffer by advancing the write index.

Parameters
psUSBRingBufpoints to the ring buffer to which bytes have been added.
ui32NumBytesis the number of bytes added to the buffer.

This function should be used by clients who wish to add data to the buffer directly rather than via calls to USBRingBufWrite() or USBRingBufWriteOne(). It advances the write index by a given number of bytes.

Note
It is considered an error if the ui32NumBytes parameter is larger than the amount of free space in the buffer and a debug build of this function will fail (ASSERT) if this condition is detected. In a release build, the buffer read pointer will be advanced if too much data is written but this will, of course, result in some of the oldest data in the buffer being discarded and also, depending upon how data is being read from the buffer, may result in a race condition which could corrupt the read pointer.
Returns
None.

References NULL, tUSBRingBufObject::ui32ReadIndex, tUSBRingBufObject::ui32Size, tUSBRingBufObject::ui32WriteIndex, and USBRingBufFree().

Referenced by USBBufferDataWritten().

§ USBRingBufWriteOne()

void USBRingBufWriteOne ( tUSBRingBufObject psUSBRingBuf,
uint8_t  ui8Data 
)

Writes a single byte of data to a ring buffer.

Parameters
psUSBRingBufpoints to the ring buffer to be written to.
ui8Datais the byte to be written.

This function writes a single byte of data into a ring buffer.

Returns
None.

References NULL, tUSBRingBufObject::pui8Buf, tUSBRingBufObject::ui32WriteIndex, and USBRingBufFree().

Referenced by USBRingBufWrite().

§ USBRingBufWrite()

void USBRingBufWrite ( tUSBRingBufObject psUSBRingBuf,
const uint8_t *  pui8Data,
uint32_t  ui32Length 
)

Writes data to a ring buffer.

Parameters
psUSBRingBufpoints to the ring buffer to be written to.
pui8Datapoints to the data to be written.
ui32Lengthis the number of bytes to be written.

This function write a sequence of bytes into a ring buffer.

Returns
None.

References NULL, USBRingBufFree(), and USBRingBufWriteOne().

Referenced by USBBufferWrite().

§ USBRingBufInit()

void USBRingBufInit ( tUSBRingBufObject psUSBRingBuf,
uint8_t *  pui8Buf,
uint32_t  ui32Size 
)

Initializes a ring buffer object.

Parameters
psUSBRingBufpoints to the ring buffer to be initialized.
pui8Bufpoints to the data buffer to be used for the ring buffer.
ui32Sizeis the size of the buffer in bytes.

This function initializes a ring buffer object, preparing it to store data.

Returns
None.

References NULL, tUSBRingBufObject::pui8Buf, tUSBRingBufObject::ui32ReadIndex, tUSBRingBufObject::ui32Size, and tUSBRingBufObject::ui32WriteIndex.

Referenced by USBBufferInit().

© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale