circle_buffer.h 927 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef _Cirule_Buffer_h__
  2. #define _Cirule_Buffer_h__
  3. #include <stdint.h>
  4. #include "os/os_types.h"
  5. #include "libs/utils.h"
  6. #define CBUFF_SUCCESS 0
  7. #define CBUFF_FULL -1
  8. #define CBUFF_EMPTY -2
  9. typedef struct {
  10. u8 * buffer;
  11. int16_t buffer_len;
  12. int16_t w_pos;
  13. int16_t r_pos;
  14. }c_buffer_t;
  15. //used by dma
  16. static __inline__ void circle_update_write_position(c_buffer_t *cbuff, int pos){
  17. cbuff->w_pos = pos;
  18. }
  19. static __inline__ int circle_get_read_position(c_buffer_t *cbuff){
  20. return cbuff->r_pos;
  21. }
  22. c_buffer_t *circle_buffer_init(c_buffer_t *cbuff, u8 *buffer, int16_t max_len);
  23. void circle_reset(c_buffer_t *cbuff);
  24. int circle_put_one_data(c_buffer_t *cbuff, u8 data);
  25. int circle_put_data(c_buffer_t *cbuff, u8 *data, int16_t len);
  26. int circle_get_one_data(c_buffer_t *cbuff, u8 *data);
  27. int circle_get_data(c_buffer_t *cbuffer, u8 *data, int16_t len);
  28. #endif /* _Cirule_Buffer_h__ */