生成代码包
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/* ================================================================
|
||||
* jb_ringbuffer.h — 环形缓冲区(UART 接收)
|
||||
* ================================================================
|
||||
*/
|
||||
#ifndef _JB_RINGBUFFER_H
|
||||
#define _JB_RINGBUFFER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* 缓冲区配置 */
|
||||
#define JB_RB_CAPACITY 256 /* 缓冲区容量(2 的幂可优化取模运算)*/
|
||||
|
||||
/* 环形缓冲区实例 */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t buf[JB_RB_CAPACITY];
|
||||
uint16_t write; /* 写索引 */
|
||||
uint16_t read; /* 读索引 */
|
||||
uint16_t count; /* 已用字节数 */
|
||||
} jb_ringbuffer_t;
|
||||
|
||||
void jbRbInit(jb_ringbuffer_t *rb);
|
||||
void jbRbPush(jb_ringbuffer_t *rb, uint8_t byte);
|
||||
uint8_t jbRbPop(jb_ringbuffer_t *rb);
|
||||
uint8_t jbRbPeek(const jb_ringbuffer_t *rb, uint16_t offset);
|
||||
uint16_t jbRbAvailable(const jb_ringbuffer_t *rb);
|
||||
void jbRbClear(jb_ringbuffer_t *rb);
|
||||
|
||||
#endif /* _JB_RINGBUFFER_H */
|
||||
Reference in New Issue
Block a user