cb_ringbuffer.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * SPDX-License-Identifier: Apache-2.0
  3. *
  4. * Change Logs:
  5. * Date Author Notes
  6. * 2023-04-24 tyx first implementation
  7. */
  8. #include "cb_def.h"
  9. #ifndef CB_RINGBUFFER_H_
  10. #define CB_RINGBUFFER_H_
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. typedef struct cb_ringbuffer
  15. {
  16. void *buff;
  17. unsigned int size;
  18. unsigned int in;
  19. unsigned int out;
  20. unsigned int in_idx;
  21. unsigned int out_idx;
  22. }cb_ringbuffer_t;
  23. cb_ringbuffer_t *cb_ringbuffer_init(cb_ringbuffer_t *rb, void *buff, unsigned int size);
  24. unsigned int cb_ringbuffer_write(cb_ringbuffer_t *rb, const void *data, unsigned int length);
  25. unsigned int cb_ringbuffer_overwrite(cb_ringbuffer_t *rb, const void *data, unsigned int length);
  26. unsigned int cb_ringbuffer_read(cb_ringbuffer_t *rb, void *data, unsigned int length);
  27. unsigned int cb_ringbuffer_discard(cb_ringbuffer_t *rb, unsigned int length);
  28. unsigned int cb_ringbuffer_peek(const cb_ringbuffer_t *rb, void *data, unsigned int length);
  29. unsigned int cb_ringbuffer_isempty(const cb_ringbuffer_t *rb);
  30. unsigned int cb_ringbuffer_isfull(const cb_ringbuffer_t *rb);
  31. unsigned int cb_ringbuffer_free(const cb_ringbuffer_t *rb);
  32. unsigned int cb_ringbuffer_used(const cb_ringbuffer_t *rb);
  33. unsigned int cb_ringbuffer_total(const cb_ringbuffer_t *rb);
  34. #ifdef __cplusplus
  35. }
  36. #endif
  37. #endif