On Mon, 10 Aug 2009, Dave Tweed wrote: > Sergio wrote: > > Ok, further to Dave's asertion that we could use a flag to allow us to > > completely fill the FIFO. I have revised the FIFO code I posted and come > > up with the following (appended to the end of this post). It uses two > > extra counts instead of the one flag proposed by Dave. > > Actually, that gives me an idea. If you simply allow the "head" and "tail" > variables to count to twice the size of the FIFO, then they can perform > both the indexing function and the counting function, with very little > additional overhead, and no added thread-safety issues. Very good! But I would have got there in another 20 years or so :-) > > If FIFO_SIZE is a power of two, then all of the '%' (modulus) operators > can become '&' (bitwise AND) operators, efficient even on tiny processors. > The only problem with this is that FIFO size needs to be a constant for the '%' to be optimised at compile time. That said all your FIFOs end up being the same size (because the size of each FIFO is not maintained per FIFO). I guess one way around that would be to declare different FIFOs each with their own predefined size (e.g. FIFO_16 has FIFO_SIZE_16 declared as its constant size). However this does mean that you'd also need special versions of fifo_add and fifo_remove for each predefined size (e.g. fifo_16_add and fifo_16_remove) Friendly Regards Sergio Masci -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist