/* ****************RxFifo.c******** Pointer implementation of the receive FIFO for the MC68HC11EVB This example accompanies the book "Embedded Microcomputer Systems: Real Time Interfacing", Brooks-Cole, copyright (c) 2000, Jonathan W. Valvano 7/6/99 Interface between the TExaS simulator running a MC68HC11 EVB with ICC11 freeware compiler TExaS Copyright 1999 by Jonathan W. Valvano for more information about ICC11 see http://www.imagecraft.com You may use this file without restrictions */ /* Number of characters in the Fifo the FIFO is full when it has FifoSize-1 characters */ char *RxPutPt; /* Pointer of where to put next */ char *RxGetPt; /* Pointer of where to get next */ /* FIFO is empty if PutPt=GetPt */ /* FIFO is full if PutPt+1=GetPt */ char RxFifo[RxFifoSize]; /* The statically allocated fifo data */ /*-----------------------RxInitFifo---------------------------- Initialize fifo to be empty Inputs: none Outputs: none */ void RxInitFifo(void){ RxPutPt=RxGetPt=&RxFifo[0]; /* Empty when PutPt=GetPt */ } /*-----------------------RxPutFifo---------------------------- Enter one character into the fifo Inputs: 8 bit data Outputs: true if data is properly saved Since this is called by interrupt handlers no sei,cli*/ int RxPutFifo(char data){ char *tempPt; tempPt=RxPutPt; *(tempPt++)=data; /* try to Put data into fifo */ if (tempPt==&RxFifo[RxFifoSize]) /* need to wrap?*/ tempPt = &RxFifo[0]; if (tempPt == RxGetPt ){ return(0); /* Failed, fifo was full */ } else{ RxPutPt=tempPt; /* Success, so update pointer */ return(1); } } /*-----------------------RxGetFifo---------------------------- Remove one character from the fifo Inputs: pointer to place to save 8 bit data Outputs: true if data is valid */ int RxGetFifo(char *datapt){ if (RxPutPt == RxGetPt ) return(0); /* Empty if PutPt=GetPt */ else{ asm(" sei"); /* make atomic, called by main thread */ *datapt=*(RxGetPt++); if (RxGetPt==&RxFifo[RxFifoSize]) RxGetPt = &RxFifo[0]; asm(" cli"); /* end critical section */ return(1); } }