fifo.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * =====================================================================================
  3. *
  4. * .d8888b 88888b. .d88b. .d8888b 888d888 8888b. 88888b.d88b.
  5. * 88K 888 "88b d8P Y8b 88K 888P" "88b 888 "888 "88b
  6. * "Y8888b. 888 888 88888888 "Y8888b. 888 .d888888 888 888 888
  7. * X88 888 888 Y8b. X88 888 888 888 888 888 888
  8. * 88888P' 888 888 "Y8888 88888P' 888 "Y888888 888 888 888
  9. *
  10. * www.optixx.org
  11. *
  12. *
  13. * Version: 1.0
  14. * Created: 07/21/2009 03:32:16 PM
  15. * Author: david@optixx.org
  16. *
  17. * =====================================================================================
  18. */
  19. #include "fifo.h"
  20. void fifo_init(fifo_t * f, uint8_t * buffer, const uint8_t size)
  21. {
  22. f->count = 0;
  23. f->pread = f->pwrite = buffer;
  24. f->read2end = f->write2end = f->size = size;
  25. }
  26. uint8_t fifo_put(fifo_t * f, const uint8_t data)
  27. {
  28. return _inline_fifo_put(f, data);
  29. }
  30. uint8_t fifo_get_wait(fifo_t * f)
  31. {
  32. while (!f->count);
  33. return _inline_fifo_get(f);
  34. }
  35. int fifo_get_nowait(fifo_t * f)
  36. {
  37. if (!f->count)
  38. return -1;
  39. return (int) _inline_fifo_get(f);
  40. }