fifo.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef FIFO_H
  2. #define FIFO_H
  3. #include "hw.h"
  4. typedef struct {
  5. /* All fields are private */
  6. uint8_t *data;
  7. uint32_t capacity;
  8. uint32_t head;
  9. uint32_t num;
  10. } Fifo8;
  11. /**
  12. * fifo8_create:
  13. * @fifo: struct Fifo8 to initialise with new FIFO
  14. * @capacity: capacity of the newly created FIFO
  15. *
  16. * Create a FIFO of the specified size. Clients should call fifo8_destroy()
  17. * when finished using the fifo. The FIFO is initially empty.
  18. */
  19. void fifo8_create(Fifo8 *fifo, uint32_t capacity);
  20. /**
  21. * fifo8_destroy:
  22. * @fifo: FIFO to cleanup
  23. *
  24. * Cleanup a FIFO created with fifo8_create(). Frees memory created for FIFO
  25. *storage. The FIFO is no longer usable after this has been called.
  26. */
  27. void fifo8_destroy(Fifo8 *fifo);
  28. /**
  29. * fifo8_push:
  30. * @fifo: FIFO to push to
  31. * @data: data byte to push
  32. *
  33. * Push a data byte to the FIFO. Behaviour is undefined if the FIFO is full.
  34. * Clients are responsible for checking for fullness using fifo8_is_full().
  35. */
  36. void fifo8_push(Fifo8 *fifo, uint8_t data);
  37. /**
  38. * fifo8_pop:
  39. * @fifo: fifo to pop from
  40. *
  41. * Pop a data byte from the FIFO. Behaviour is undefined if the FIFO is empty.
  42. * Clients are responsible for checking for emptyness using fifo8_is_empty().
  43. *
  44. * Returns: The popped data byte.
  45. */
  46. uint8_t fifo8_pop(Fifo8 *fifo);
  47. /**
  48. * fifo8_reset:
  49. * @fifo: FIFO to reset
  50. *
  51. * Reset a FIFO. All data is discarded and the FIFO is emptied.
  52. */
  53. void fifo8_reset(Fifo8 *fifo);
  54. /**
  55. * fifo8_is_empty:
  56. * @fifo: FIFO to check
  57. *
  58. * Check if a FIFO is empty.
  59. *
  60. * Returns: True if the fifo is empty, false otherwise.
  61. */
  62. bool fifo8_is_empty(Fifo8 *fifo);
  63. /**
  64. * fifo8_is_full:
  65. * @fifo: FIFO to check
  66. *
  67. * Check if a FIFO is full.
  68. *
  69. * Returns: True if the fifo is full, false otherwise.
  70. */
  71. bool fifo8_is_full(Fifo8 *fifo);
  72. extern const VMStateDescription vmstate_fifo8;
  73. #define VMSTATE_FIFO8(_field, _state) { \
  74. .name = (stringify(_field)), \
  75. .size = sizeof(Fifo8), \
  76. .vmsd = &vmstate_fifo8, \
  77. .flags = VMS_STRUCT, \
  78. .offset = vmstate_offset_value(_state, _field, Fifo8), \
  79. }
  80. #endif /* FIFO_H */