LPCOpen Platform for LPC18XX/43XX microcontrollers: CHIP: Simple ring buffer implementation

| LPCOpen Platform for LPC18XX/43XX microcontrollers 18XX43XX LPCOpen Platform for the NXP LPC18XX/43XX family of Microcontrollers

- Main Page
- Modules
- Data Structures
- Files

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_VHEAD(rb) (*(volatile uint32_t *) &(rb)->head)
#define | RB_VTAIL(rb) (*(volatile uint32_t *) &(rb)->tail)

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

## Macro Definition Documentation

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

volatile typecasted head index

Definition at line 57 of file ring_buffer.h.

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

volatile typecasted tail index

Definition at line 63 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 83 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 103 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 113 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 93 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 55 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 133 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 123 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 134 of file ring_buffer.c.