Files
incp-test/app/src/msg_buf.h

37 lines
799 B
C

#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