| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions
CHIP: Simple ring buffer implementation
Common components used with chip drivers

## Detailed Description

## Data Structures
struct | RINGBUFF_T
| Ring buffer structure. More...

## Macros
#define | RB_SIGNATURE 0x51DEF00D
#define | RB_VHEAD(rb) (*(volatile uint32_t *) &(rb)->head)
#define | RB_VTAIL(rb) (*(volatile uint32_t *) &(rb)->tail)
#define | RingBuffer_IsValid(rb) ((rb)->valid == RB_SIGNATURE)

## Functions
int | RingBuffer_Init (RINGBUFF_T *RingBuff, void *buffer, int itemSize, int count)
| Initialize ring buffer.
STATIC INLINE void | RingBuffer_Flush (RINGBUFF_T *RingBuff)
| Resets the ring buffer to empty.
STATIC INLINE int | RingBuffer_GetSize (RINGBUFF_T *RingBuff)
| Return size the ring buffer.
STATIC INLINE int | RingBuffer_GetCount (RINGBUFF_T *RingBuff)
| Return number of items in the ring buffer.
STATIC INLINE int | RingBuffer_GetFree (RINGBUFF_T *RingBuff)
| Return number of free items in the ring buffer.
STATIC INLINE int | RingBuffer_IsFull (RINGBUFF_T *RingBuff)
| Return number of items in the ring buffer.
STATIC INLINE int | RingBuffer_IsEmpty (RINGBUFF_T *RingBuff)
| Return empty status of ring buffer.
int | RingBuffer_Insert (RINGBUFF_T *RingBuff, const void *data)
| Insert a single item into ring buffer.
int | RingBuffer_InsertMult (RINGBUFF_T *RingBuff, const void *data, int num)
| Insert an array of items into ring buffer.
int | RingBuffer_Pop (RINGBUFF_T *RingBuff, void *data)
| Pop an item from the ring buffer.
int | RingBuffer_PopMult (RINGBUFF_T *RingBuff, void *data, int num)
| Pop an array of items from the ring buffer.

## Macro Definition Documentation

#define RB_SIGNATURE 0x51DEF00D

Definition at line 56 of file ring_buffer.h.

#define RB_VHEAD | ( |  | rb | ) | (*(volatile uint32_t *) &(rb)->head)

volatile typecasted head index

Definition at line 62 of file ring_buffer.h.

#define RB_VTAIL | ( |  | rb | ) | (*(volatile uint32_t *) &(rb)->tail)

volatile typecasted tail index

Definition at line 68 of file ring_buffer.h.

#define RingBuffer_IsValid | ( |  | rb | ) | ((rb)->valid == RB_SIGNATURE)

Evaluates to 1 when the ring buffer rb is initailized with valid values, otherwise evaluates to 0

Definition at line 75 of file ring_buffer.h.

## Function Documentation

STATIC INLINE void RingBuffer_Flush | ( | RINGBUFF_T * | RingBuff | ) |

Resets the ring buffer to empty.

Parameters

  RingBuff | : Pointer to ring buffer

Returns
  Nothing

Definition at line 95 of file ring_buffer.h.

STATIC INLINE int RingBuffer_GetCount | ( | RINGBUFF_T * | RingBuff | ) |

Return number of items in the ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer

Returns
  Number of items in the ring buffer

Definition at line 115 of file ring_buffer.h.

STATIC INLINE int RingBuffer_GetFree | ( | RINGBUFF_T * | RingBuff | ) |

Return number of free items in the ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer

Returns
  Number of free items in the ring buffer

Definition at line 125 of file ring_buffer.h.

STATIC INLINE int RingBuffer_GetSize | ( | RINGBUFF_T * | RingBuff | ) |

Return size the ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer

Returns
  Size of the ring buffer in bytes

Definition at line 105 of file ring_buffer.h.

int RingBuffer_Init | ( | RINGBUFF_T * | RingBuff,
|  | void * | buffer,
|  | int | itemSize,
|  | int | count
| ) |  |

Initialize ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer to initialize
  buffer | : Pointer to buffer to associate with RingBuff
  itemSize | : Size of each buffer item size
  count | : Size of ring buffer

Note
  Memory pointed by buffer must have correct alignment of itemSize, and count must be a power of 2 and must at least be 2 or greater.

Returns
  Nothing

Definition at line 54 of file ring_buffer.c.

int RingBuffer_Insert | ( | RINGBUFF_T * | RingBuff,
|  | const void * | data
| ) |  |

Insert a single item into ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer
  data | : pointer to item

Returns
  1 when successfully inserted, 0 on error (Buffer not initialized using RingBuffer_Init() or attempted to insert when buffer is full)

Definition at line 66 of file ring_buffer.c.

int RingBuffer_InsertMult | ( | RINGBUFF_T * | RingBuff,
|  | const void * | data,
|  | int | num
| ) |  |

Insert an array of items into ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer
  data | : Pointer to first element of the item array
  num | : Number of items in the array

Returns
  number of items successfully inserted, 0 on error (Buffer not initialized using RingBuffer_Init() or attempted to insert when buffer is full)

Definition at line 82 of file ring_buffer.c.

STATIC INLINE int RingBuffer_IsEmpty | ( | RINGBUFF_T * | RingBuff | ) |

Return empty status of ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer

Returns
  1 if the ring buffer is empty, otherwise 0

Definition at line 145 of file ring_buffer.h.

STATIC INLINE int RingBuffer_IsFull | ( | RINGBUFF_T * | RingBuff | ) |

Return number of items in the ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer

Returns
  1 if the ring buffer is full, otherwise 0

Definition at line 135 of file ring_buffer.h.

int RingBuffer_Pop | ( | RINGBUFF_T * | RingBuff,
|  | void * | data
| ) |  |

Pop an item from the ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer
  data | : Pointer to memory where popped item be stored

Returns
  1 when item popped successfuly onto data, 0 When error (Buffer not initialized using RingBuffer_Init() or attempted to pop item when the buffer is empty)

Definition at line 118 of file ring_buffer.c.

int RingBuffer_PopMult | ( | RINGBUFF_T * | RingBuff,
|  | void * | data,
|  | int | num
| ) |  |

Pop an array of items from the ring buffer.

Parameters

  RingBuff | : Pointer to ring buffer
  data | : Pointer to memory where popped items be stored
  num | : Max number of items array data can hold

Returns
  Number of items popped onto data, 0 on error (Buffer not initialized using RingBuffer_Init() or attempted to pop when the buffer is empty)

Definition at line 133 of file ring_buffer.c.