Advertisement
ST4SH3R

Untitled

Dec 9th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include "at91sam9263.h"
  2. #include "FIFO.h"
  3.  
  4. void FIFO_Init (struct FIFO *Fifo){
  5. Fifo->head=0;
  6. Fifo->tail=0;
  7. /* optional: initialize data in buffer with 0 */
  8. }
  9.  
  10. void FIFO_Empty (struct FIFO *Fifo){
  11. Fifo->head = Fifo->tail;
  12. /* now FIFO is empty*/
  13. }
  14.  
  15. int FIFO_Put (struct FIFO *Fifo, char Data){
  16. if ((Fifo->tail-Fifo->head)==1 || (Fifo->head-Fifo->tail)==BUFFERSIZE) {
  17. return -1; /* FIFO overflow */
  18. };
  19.  
  20. Fifo->buffer[Fifo->head] = Data;
  21. Fifo->head = (Fifo->head + 1) & BUFFERSIZE;
  22. return 1; /* Put 1 byte successfully */
  23. }
  24.  
  25. int FIFO_Get (struct FIFO *Fifo, char *Data){
  26. if (Fifo->head!=Fifo->tail){
  27. *Data = Fifo->buffer[Fifo->tail];
  28. Fifo->tail = (Fifo->tail + 1) & BUFFERSIZE;
  29. return 1; /* Get 1 byte successfully */
  30. }
  31. else return -1; /* No data in FIFO */
  32. }
  33.  
  34.  
  35. #define BUFFERSIZE 0xF
  36.  
  37. typedef struct FIFO {
  38. char buffer [BUFFERSIZE + 1];
  39. unsigned int head;
  40. unsigned int tail;
  41. } jebac_embedy;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement