AWS IoT for ESP32 v1.0.0
An ESP-IDF based solution
lib_ringBuffer.h
Go to the documentation of this file.
1/*******************************************************************************
2* Filename: lib_ringbuffer.h
3*
4* Author: Saheblal Bagwan
5* email: bagwan@buildstorm.com
6*
7* Description:
8* Contains wrapper functions to implement ring-buffer.
9*******************************************************************************/
10
16#ifndef _LIB_RING_BUFFER_H_
17#define _LIB_RING_BUFFER_H_
18
19#include "stdutils.h"
20
24typedef struct
25{
26 uint16_t head_u16;
27 uint16_t tail_u16;
29 uint16_t elemetSize_u16;
30 uint16_t writeCount_u16;
31 uint16_t readCount_u16;
32 uint8_t *pBuffer_u8;
33} rb_st;
34
44bool RB_init(rb_st *ps_rb, uint16_t sizeOfElement_u16, uint16_t noOfElements_u16);
45
51void RB_free(rb_st *ps_rb);
52
58void RB_clear(rb_st *ps_rb);
59
65uint16_t RB_available(rb_st *ps_rb);
66
72uint16_t RB_hasSpace(rb_st *ps_rb);
73
82bool RB_write(rb_st *ps_rb, void *pBuffer);
83
92bool RB_read(rb_st *ps_rb, void *pBuffer);
93
94#endif
bool RB_init(rb_st *ps_rb, uint16_t sizeOfElement_u16, uint16_t noOfElements_u16)
Intialize the ring buffer.
void RB_clear(rb_st *ps_rb)
Clear the ring buffer.
uint16_t RB_available(rb_st *ps_rb)
Number of bytes available in a ring buffer.
bool RB_read(rb_st *ps_rb, void *pBuffer)
Read data from ring buffer.
void RB_free(rb_st *ps_rb)
Free the memory associated with ring buffer.
uint16_t RB_hasSpace(rb_st *ps_rb)
Check if ring buffer is not full.
bool RB_write(rb_st *ps_rb, void *pBuffer)
Write data to ring buffer.
Ring buffer structure.
Definition: lib_ringBuffer.h:25
uint16_t elemetSize_u16
Definition: lib_ringBuffer.h:29
uint8_t * pBuffer_u8
Definition: lib_ringBuffer.h:32
uint16_t writeCount_u16
Definition: lib_ringBuffer.h:30
uint16_t maxRbElements_u16
Definition: lib_ringBuffer.h:28
uint16_t readCount_u16
Definition: lib_ringBuffer.h:31
uint16_t tail_u16
Definition: lib_ringBuffer.h:27
uint16_t head_u16
Definition: lib_ringBuffer.h:26