fifo.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-25 23:54:38
  5. * @LastEditTime: 2020-06-17 15:10:03
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. #ifndef _FIFO_H_
  9. #define _FIFO_H_
  10. #include "salof_defconfig.h"
  11. #ifdef SALOF_USING_LOG
  12. #define FIFO_READ 0
  13. #define FIFO_WRITE 1
  14. #define FIFO_MAX(a,b) (((a) > (b)) ? (a) : (b))
  15. #define FIFO_MIN(a,b) (((a) < (b)) ? (a) : (b))
  16. struct salof_fifo {
  17. unsigned int size; /* fifo size */
  18. unsigned int in; /* data input pointer (in % size) */
  19. unsigned int out; /* data output pointer (out % size) */
  20. salof_mutex mutex; /* mutex */
  21. salof_sem sem; /* sem */
  22. void *buff; /* data area */
  23. };
  24. typedef struct salof_fifo * salof_fifo_t;
  25. salof_fifo_t salof_fifo_create(unsigned int size);
  26. unsigned int salof_fifo_write(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
  27. unsigned int salof_fifo_read(salof_fifo_t fifo, void *buff, unsigned int len, unsigned int timeout);
  28. unsigned int salof_fifo_read_able(salof_fifo_t fifo);
  29. unsigned int salof_fifo_write_able(salof_fifo_t fifo);
  30. #endif
  31. #endif // !_FIFO_H_