feat: Framework to handle INCP messages
This commit is contained in:
36
app/src/msg_buf.h
Normal file
36
app/src/msg_buf.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef MSG_BUF_H_
|
||||
#define MSG_BUF_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define MAX_LEN (0xFFFE)
|
||||
|
||||
|
||||
typedef uint32_t err_t;
|
||||
#define ERR_OK ((err_t)0)
|
||||
#define ERR_ARGS ((err_t)1)
|
||||
#define ERR_FULL ((err_t)2)
|
||||
#define ERR_EMPTY ((err_t)3)
|
||||
|
||||
|
||||
// Message buffer
|
||||
// Variable-sized entry circular buffer
|
||||
// No modulo, contiguous memory read/write
|
||||
// Maximum message size 0xFFFE (0xFFFF is padding)
|
||||
// Minimum message size 0
|
||||
// NOT thread/task safe
|
||||
typedef struct msg_buf {
|
||||
uint8_t *storage;
|
||||
uint32_t capacity;
|
||||
uint32_t head, count;
|
||||
} msg_buf_t;
|
||||
|
||||
int msg_buf_init(msg_buf_t *buf, void *storage, uint32_t capacity);
|
||||
int msg_buf_push(msg_buf_t *buf, void *data, uint32_t len);
|
||||
int msg_buf_peek(msg_buf_t *buf, void **ptr, uint32_t *len);
|
||||
int msg_buf_pop(msg_buf_t *buf);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user