ccci_ringbuf.h 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #ifndef __CCCI_RINGBUF_H__
  2. #define __CCCI_RINGBUF_H__
  3. #include "ccci_core.h"
  4. typedef enum {
  5. CCCI_RINGBUF_OK = 0,
  6. CCCI_RINGBUF_PARAM_ERR,
  7. CCCI_RINGBUF_NOT_ENOUGH,
  8. CCCI_RINGBUF_BAD_HEADER,
  9. CCCI_RINGBUF_BAD_FOOTER,
  10. CCCI_RINGBUF_NOT_COMPLETE,
  11. CCCI_RINGBUF_EMPTY,
  12. } ccci_ringbuf_error;
  13. struct ccci_ringbuf {
  14. struct {
  15. unsigned int read;
  16. unsigned int write;
  17. unsigned int length;
  18. } rx_control, tx_control;
  19. unsigned char buffer[0];
  20. };
  21. #define CCCI_RINGBUF_CTL_LEN (8+sizeof(struct ccci_ringbuf)+8)
  22. int ccci_ringbuf_readable(int md_id, struct ccci_ringbuf *ringbuf);
  23. int ccci_ringbuf_writeable(int md_id, struct ccci_ringbuf *ringbuf, unsigned int write_size);
  24. struct ccci_ringbuf *ccci_create_ringbuf(int md_id, unsigned char *buf, int buf_size, int rx_size, int tx_size);
  25. int ccci_ringbuf_read(int md_id, struct ccci_ringbuf *ringbuf, unsigned char *buf, int read_size);
  26. int ccci_ringbuf_write(int md_id, struct ccci_ringbuf *ringbuf, unsigned char *data, int data_len);
  27. void ccci_ringbuf_move_rpointer(int md_id, struct ccci_ringbuf *ringbuf, int read_size);
  28. void ccci_ringbuf_reset(int md_id, struct ccci_ringbuf *ringbuf, int dir);
  29. #endif /* __CCCI_RINGBUF_H__ */