f0x.at1/Core/Inc/ringbuf.h

64 lines
1.7 KiB
C
Raw Normal View History

2022-07-15 12:44:08 +02:00
/*
* ringbuf.h
*
* Created on: Jul 12, 2022
* Author: tom
*/
#ifndef _INC_RINGBUF_H_
#define _INC_RINGBUF_H_
#define RING_STATISTICS_ENABLED 1
2022-07-16 00:30:23 +02:00
#define RINGBUF_MAX_READ_LEN 80
2022-07-15 12:44:08 +02:00
typedef enum {
RINGBUF_PARAM_NONE = 0x00,
RINGBUF_ALLOWOVERWRITE= 0x01,
} ringbuf_param_t;
2022-07-16 00:30:23 +02:00
#if !defined _SYS_ERRNO_H_ && !defined __ERRNO_H__ && !defined __AT1_ERROR_NUMBERS__
2022-07-15 12:44:08 +02:00
typedef enum {
EPERM = 1, /*!< Operation not permitted */
EIO = 5, /*!< I/O error */
ENOMEM = 12, /*!< Out of memory */
EFAULT = 14, /*!< Bad address */
EBUSY = 16, /*!< Device or resource busy */
ENODEV = 19, /*!< No such device */
EINVAL = 22, /*!< Invalid argument */
EADDRINUSE = 98,/*!< Address already in use */
ETIMEDOUT = 116,/*!< Connection timed out */
} ringbuf_errno_t;
#endif
//extern ringbuf;
#define hring struct ringbuf *
//receive callback typedef definition
typedef void (*ringbuf_rcv_cb_t)(uint16_t delimiterfound, void* cb_data);
#if !defined min
#define min(a,b) ((a < b)? a : b)
#endif
hring ringbuf_create(size_t size, ringbuf_param_t param);
void ringbuf_destroy(hring);
int ringbuf_push(hring, const uint8_t *data, size_t size);
int ringbuf_pull(hring, uint8_t *data, size_t maxsize);
int ringbuf_clear(hring);
int ringbuf_free(hring);
int ringbuf_read(hring, char *str);
int ringbuf_write(hring, char *str);
int ringbuf_callback_register(hring, ringbuf_rcv_cb_t cb_func, void *cb_data);
int ringbuf_set_max_read_len(hring, int max_read_len);
int ringbuf_get_max_read_len(hring);
int ringbuf_is_empty(hring);
int ringbuf_dump(hring);
#if RING_STATISTICS_ENABLED
int ringbuf_statistics(hring);
int ringbuf_stat_writes(hring);
int ringbuf_stat_reads(hring);
int ringbuf_stat_overflow(hring);
#endif
#endif /* _INC_RINGBUF_H_ */