/*********************************************************************************
|
* Copyright: (C) 2023 LingYun IoT System Studio.
|
* All rights reserved.
|
*
|
* Filename: ringbuf.h
|
* Description: This file is common ring buffer API functions
|
*
|
* Version: 1.0.0(11/08/23)
|
* Author: Guo Wenxue <guowenxue@gmail.com>
|
* ChangeLog: 1, Release initial version on "11/08/23 16:18:43"
|
*
|
********************************************************************************/
|
|
#ifndef _RINGBUF_H_
|
#define _RINGBUF_H_
|
|
struct ring_buffer
|
{
|
unsigned char *buffer;
|
int wr_pointer;
|
int rd_pointer;
|
int size;
|
};
|
|
|
/* Initial the ring buffer */
|
void rb_init (struct ring_buffer *ring, unsigned char *buff, int size) ;
|
|
|
/* Description: Write $len bytes data in $buf into ring buffer $rb
|
* Return Value: The actual written into ring buffer data size, if ring buffer
|
* left space size small than $len, then only part of the data be written into.
|
*/
|
int rb_write (struct ring_buffer *rb, unsigned char *buf, int len) ;
|
|
|
/* Get ring buffer left free size */
|
int rb_free_size (struct ring_buffer *rb);
|
|
|
/* Read $max bytes data from ring buffer $rb to $buf */
|
int rb_read (struct ring_buffer *rb, unsigned char *buf, int max);
|
|
|
/* Read a specify $index byte data in ring buffer $rb */
|
unsigned char rb_peek(struct ring_buffer *rb, int index);
|
|
|
/* Get data size in the ring buffer */
|
int rb_data_size (struct ring_buffer *rb);
|
|
|
/* Clear the ring buffer data */
|
void rb_clear (struct ring_buffer *rb) ;
|
|
#endif /* ----- #ifndef _RINGBUF_H_ ----- */
|