Harold Hallikainen escreveu: > struct FifoStruct{ > uint8_t buffer[FifoSize]; > uint16_t IndexIn; // Put next byte at this index, then increment > uint16_t IndexOut; // take next byte from this index, then increment > uint16_t BytesInBuf;// how many bytes we have in the fifo > uint16_t BytesFree;// how many bytes we have left > }; > = I think it would be better to keep the buffer itself as the last member of the struct. This way it would be easier to make generic functions to deal with FIFOs of different physical lengths (physical length could be a field also). Just pass a pointer to the FIFO struct to the functions Insert and Remove and the same functions may work on several different FIFOs. I always try to use FIFO lengths of powers of two, it is easier to cope with wrap-around and you don't need to keep Insertion index, Remotion index and Length. For FIFOs where the interrupt inserts and the application removes I use only the Insert index and length, and for FIFOs where the interrupt removes and the application inserts I use Remove index and length. This way the interrupt code deals with the simpler (faster) operations (inserting in a FIFO with insertion index and length, or removing from a FIFO with remotion index and length). FIFO with Insertion index and Length: Insertion: if( Length < sizeof Fifo ) { Fifo[Insert++] =3D c; Insert &=3D sizeof Fifo -1; Length++; } else ... Removal: if( Length > 0 ) { c =3D Fifo[ ( Insert - Length ) & ( sizeof Fifo - 1 ) ]; Length--; } else ... FIFO with Remotion index and Length: Insertion if( Length < sizeof Fifo ) { Fifo[ ( Remove + Length ) & ( sizeof Fifo - 1 ) ] =3D c; Length++; } else ... Removal: if( Length > 0 ) { c =3D Fifo[Remove++]; Remove &=3D sizeof Fifo -1; Length--; } else ... Regards, Isaac __________________________________________________ Fa=E7a liga=E7=F5es para outros computadores com o novo Yahoo! Messenger = http://br.beta.messenger.yahoo.com/ = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist