📄 ringbuffer.h
字号:
/*
* ringbuffer
*
*/
#ifndef __RINGBUFFER_H__
#define __RINGBUFFER_H__
#include <stdio.h>
#include "type.h"
#include "rtos.h"
#define MAX_PID_FILTER 3
struct ringbuffer_s
{
u8 *data;
int size;
int ptr_r;
int ptr_w;
int error;
int pre_r; //前一次读
RTOS_Semaphore sem; //读写锁
u16 pid[MAX_PID_FILTER];
int need_filter; //是否过滤,1 是
FILE *fp; //测试用,从文件读
};
typedef struct ringbuffer_s RingBuffer_s;
typedef void (*handle_func)(const uint8_t *, int );
#define RB_PKTHDRSIZE 3
/* peek at byte <offs> in the buffer */
#define RB_PEEK(rbuf,offs) \
(rbuf)->data[((rbuf)->ptr_r+(offs))%(rbuf)->size]
/* advance read ptr by <num> bytes */
#define RB_SKIP(rbuf,num) \
(rbuf)->ptr_r=((rbuf)->ptr_r+(num))%(rbuf)->size
/* write single byte to ring buffer */
#define RB_WRITE_BYTE(rbuf,byte) \
{ (rbuf)->data[(rbuf)->ptr_w]=(byte); \
(rbuf)->ptr_w=((rbuf)->ptr_w+1)%(rbuf)->size; }
#ifdef __cplusplus
extern "C" {
#endif
void rb_init(struct ringbuffer_s *rbuf, void *data, int len);
void rb_fill_init(struct ringbuffer_s *rbuf, void *data, int len);
int rb_empty(struct ringbuffer_s *rbuf);
int rb_free(struct ringbuffer_s *rbuf);
int rb_avail(struct ringbuffer_s *rbuf);
void rb_flush(struct ringbuffer_s *rbuf);
int rb_read(struct ringbuffer_s *rbuf, u8 *buf, int len);
int rb_write(struct ringbuffer_s *rbuf, const u8 *buf, int len);
int rb_fill(struct ringbuffer_s *rbuf, FILE *fp, int len);
void rb_backspace(struct ringbuffer_s *s, int offset);
int rb_pkt_write(struct ringbuffer_s *rbuf, u8* buf, int len);
int rb_pkt_read(struct ringbuffer_s *rbuf, int idx,
int offset, u8* buf, int len);
void rb_pkt_dispose(struct ringbuffer_s *rbuf, int idx);
int rb_pkt_next(struct ringbuffer_s *rbuf, int idx, int* pktlen);
//filter
int rb_add_filter(struct ringbuffer_s *rbuf, u16 pid);
int rb_clr_filter(struct ringbuffer_s *rbuf, u16 pid);
void rb_set_filter(struct ringbuffer_s *rbuf, u8 yes);
void rb_clrall_filter(struct ringbuffer_s *rbuf);
int rb_filter(struct ringbuffer_s *rbuf, u8 *buf, int len);
#ifdef __cplusplus
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -