RTOS_MSPM0  1.1
ECE445M starter code
RTOS_FIFO.h
Go to the documentation of this file.
1 
23 #ifndef __FIFO_H__
24 #define __FIFO_H__
25 
26 
31  #define TXFIFOSIZE 64 // must be a power of 2
32 
33 
42 void TxFifo_Init(void);
43 
44 
53 int TxFifo_Put(char data);
54 
55 
64 char TxFifo_Get(void);
65 
66 
75 uint32_t TxFifo_Size(void);
76 
77 
82 #define RXFIFOSIZE 16 // must be a power of 2
83 
92 void RxFifo_Init(void);
93 
102 int RxFifo_Put(char data);
103 
112 char RxFifo_Get(void);
113 
122 uint32_t RxFifo_Size(void);
123 
124 
125 
126 // macro to create an index FIFO
127 #define AddIndexFifo(NAME,SIZE,TYPE,SUCCESS,FAIL) \
128 uint32_t volatile NAME ## PutI; \
129 uint32_t volatile NAME ## GetI; \
130 TYPE static NAME ## Fifo [SIZE]; \
131 void NAME ## Fifo_Init(void){ \
132  NAME ## PutI = NAME ## GetI = 0; \
133 } \
134 int NAME ## Fifo_Put (TYPE data){ \
135  if(( NAME ## PutI - NAME ## GetI ) & ~(SIZE-1)){ \
136  return(FAIL); \
137  } \
138  NAME ## Fifo[ NAME ## PutI &(SIZE-1)] = data; \
139  NAME ## PutI++; \
140  return(SUCCESS); \
141 } \
142 int NAME ## Fifo_Get (TYPE *datapt){ \
143  if( NAME ## PutI == NAME ## GetI ){ \
144  return(FAIL); \
145  } \
146  *datapt = NAME ## Fifo[ NAME ## GetI &(SIZE-1)]; \
147  NAME ## GetI++; \
148  return(SUCCESS); \
149 } \
150 unsigned short NAME ## Fifo_Size (void){\
151  return ((unsigned short)( NAME ## PutI - NAME ## GetI )); \
152 }
153 // e.g.,
154 // AddIndexFifo(Tx,32,unsigned char, 1,0)
155 // SIZE must be a power of two
156 // creates TxFifo_Init() TxFifo_Get() and TxFifo_Put()
157 
158 #endif // __FIFO_H__
void TxFifo_Init(void)
Initialize FIFO.
char RxFifo_Get(void)
Get FIFO.
uint32_t TxFifo_Size(void)
number of elements in FIFO
void RxFifo_Init(void)
Initialize FIFO.
char TxFifo_Get(void)
Get FIFO.
uint32_t RxFifo_Size(void)
number of elements in FIFO
int RxFifo_Put(char data)
Put FIFO.
int TxFifo_Put(char data)
Put FIFO.