# mcu_ringbuf ## 安装 ```powershell idf.py add-dependency "xkk6663/mcu_ringbuf^0.1.0" ``` 单生产/单消费无锁环形缓冲,适合串口、音频、日志的定长字节流。 ## 特性 - 只依赖 `libc`(`malloc/free` 只用于 `ringbuffer_create()`;静态池方式不分配) - 结构体由调用方持有,缓冲池由调用方提供,适合嵌入式静态分配 - 单生产/单消费场景不需要额外加锁 ## 来源与许可 `src/ringbuf.c` 文件头注明修改自 RT-Thread ringbuff。本组件按 Apache-2.0 分发,`LICENSE` 与 `NOTICE` 保留原始来源和署名;再分发时请一并保留。 ## 拖入别的工程 1. 复制 `components/mcu_ringbuf/` 2. 声明依赖: ```cmake idf_component_register(... PRIV_REQUIRES mcu_ringbuf) ``` 3. include: ```c #include "mcu_ringbuf.h" static uint8_t pool[4096]; static ringbuf_t rb; ringbuffer_init(&rb, pool, sizeof(pool)); ``` ## 测试 `test/test_ringbuf.c` 覆盖空/满/半满、覆盖写、peek、reset 和逐字节读写。根工程 host 测试直接编译 `src/ringbuf.c`。
idf.py add-dependency "xkk6663/mcu_ringbuf^0.1.0"