#define FifoLength 32
unsigned char FifoBuffer[FifoLength];
unsigned char *FifoStart;
unsigned char *FifoEnd;
unsigned char count;
void InitFifo(void){
FifoStart=FifoBuffer;
FifoEnd=FifoBuffer;
count=0;
}
void PutFifo(unsigned char chr){
*FifoEnd++=chr;
count++;
if(FifoEnd==FifoBuffer+FifoLength) //reached end
FifoEnd=FifoBuffer; //yes so wrap
if(FifoStart==FifoEnd){ //is head eating tail?
//fifo full so deal with it!!
}
}
unsigned char GetFifo(void){
unsigned char chr;
while(FifoStart==FifoEnd); //if fifo empty then wait
chr=*FifoStart++;
count--;
if(FifoStart==FifoBuffer+FifoLength) //wrapped?
FifoStart=FifoBuffer; //yes
return(chr);
}
unsigned char FifoCount(void){
return(count);
}