fifo.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * =====================================================================================
  3. *
  4. * ________ .__ __ ________ ____ ________
  5. * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
  6. * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
  7. * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
  8. * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
  9. * \__> \/ \/ \/ \/ \/
  10. * ___.
  11. * __ __ _____\_ |__
  12. * | | \/ ___/| __ \
  13. * | | /\___ \ | \_\ \
  14. * |____//____ >|___ /
  15. * \/ \/
  16. *
  17. * www.optixx.org
  18. *
  19. *
  20. * Version: 1.0
  21. * Created: 07/21/2009 03:32:16 PM
  22. * Author: david@optixx.org
  23. *
  24. * =====================================================================================
  25. */
  26. #include "fifo.h"
  27. void fifo_init(fifo_t * f, uint8_t * buffer, const uint8_t size)
  28. {
  29. f->count = 0;
  30. f->pread = f->pwrite = buffer;
  31. f->read2end = f->write2end = f->size = size;
  32. }
  33. uint8_t fifo_put(fifo_t * f, const uint8_t data)
  34. {
  35. return _inline_fifo_put(f, data);
  36. }
  37. uint8_t fifo_get_wait(fifo_t * f)
  38. {
  39. while (!f->count);
  40. return _inline_fifo_get(f);
  41. }
  42. int fifo_get_nowait(fifo_t * f)
  43. {
  44. if (!f->count)
  45. return -1;
  46. return (int) _inline_fifo_get(f);
  47. }