circle_buffer.h 893 B

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