>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. This exactly what I have done with the code that I posted the link to. Because of the way the tutorial is built up, the code presented has the data field first, but because I needed some FIFOs of different size to others, I changed it as mentioned above, and included a size field. >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. Good point, although I don't know how much code is generated for the modulus operation that this code uses. >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). Good thought, but it does require having two sets of routines. I guess IsEmpty and IsFull routines work with both, without requiring different routines. I'll be keeping a copy of your routines for future reference though. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist