/* ****************TxFifo.c******** Pointer implementation of the transmit 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 */ char *TxPutPt; /* Pointer of where to put next */ char *TxGetPt; /* Pointer of where to get next */ /* FIFO is empty if PutPt=GetPt */ /* FIFO is full if PutPt+1=GetPt */ char TxFifo[TxFifoSize]; /* The statically allocated fifo data */ /*-----------------------TxInitFifo---------------------------- Initialize fifo to be empty Inputs: none Outputs: none */ void TxInitFifo(void){ TxPutPt=TxGetPt=&TxFifo[0]; /* Empty when PutPt=GetPt */ } /*-----------------------TxPutFifo---------------------------- Enter one character into the fifo Inputs: 8 bit data Outputs: true if data is properly saved */ int TxPutFifo(char data){ char *tempPt; asm(" sei"); /* make atomic, called by main thread */ tempPt=TxPutPt; *(tempPt++)=data; /* try to Put data into fifo */ if (tempPt==&TxFifo[TxFifoSize]) /* need to wrap?*/ tempPt = &TxFifo[0]; if (tempPt == TxGetPt ){ asm(" cli"); /* end critical section */ return(0); /* Failed, fifo was full */ } else{ TxPutPt=tempPt; /* Success, so update pointer */ asm(" cli"); /* end critical section */ return(1); } } /*-----------------------TxGetFifo---------------------------- Remove one character from the fifo Inputs: pointer to place to save 8 bit data Outputs: true if data is valid Since this is called by interrupt handlers no sei,cli*/ int TxGetFifo(char *datapt){ if (TxPutPt == TxGetPt ) return(0); /* Empty if PutPt=GetPt */ else{ *datapt=*(TxGetPt++); if (TxGetPt==&TxFifo[TxFifoSize]) TxGetPt = &TxFifo[0]; return(1); } }