1 /* 2 * Copyright (C) 2017-2019 Alibaba Group Holding Limited 3 */ 4 5 /****************************************************************************** 6 * @file ringbuffer.h 7 * @brief header file for ringbuffer Driver 8 * @version V1.0 9 * @date August 15. 2019 10 ******************************************************************************/ 11 #ifndef _RING_BUFFER_H_ 12 #define _RING_BUFFER_H_ 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 #include "stdint.h" 19 #include <stdbool.h> 20 21 typedef struct ringbuffer { 22 uint8_t *buffer; 23 uint32_t size; 24 uint32_t write; 25 uint32_t read; 26 uint32_t data_len; 27 } ringbuffer_t; 28 29 void ringbuffer_reset(ringbuffer_t *fifo); 30 uint32_t ringbuffer_len(ringbuffer_t *fifo); 31 uint32_t ringbuffer_avail(ringbuffer_t *fifo); 32 bool ringbuffer_is_empty(ringbuffer_t *fifo); 33 bool ringbuffer_is_full(ringbuffer_t *fifo); 34 35 /*write to ringbuffer*/ 36 uint32_t ringbuffer_in(ringbuffer_t *fifo, const void *in, uint32_t len); 37 38 /*read to ringbuffer*/ 39 uint32_t ringbuffer_out(ringbuffer_t *fifo, void *out, uint32_t len); 40 41 #ifdef __cplusplus 42 } 43 #endif 44 45 #endif /* _RING_BUFFER_H_ */ 46