How to manipulate a receiving buffer

SNIP!

How do you handle swtiching between the two buffers cleanly and quickly? I've written some code but it's a bit of a dogs dinner (too many if statements)!

Also what do you do when both buffers are full and are marked as OK_to_read_buffer? Just empty the data into a bin bucket until one gets freed?

Thanks.

Reply to
Michael Frederick
Loading thread data ...

You use pointers to refer to the buffers. The code is the same regardless of which buffer the pointer points to.

If you receive data faster than you can process it, you either have to have large enough buffers to hold all of the data or you have to drop messages. In general, double (or triple) buffers are used when you can process the data as fast as it arrives on the average and you won't need to continue to buffer it.

Triple buffers are used if the data is coming in at a fixed rate and the data goes out at a fixed rate, but there is some latency inbetween. The first buffer is filled and processing starts, but the processing takes nearly as long as the message rate. So as the first buffer is emptied out the second becomes full and the processor has not yet released the first buffer. A third buffer makes it all work without a hitch. I expect this is needed more often when the whole thing is being done in hardware. If your processing in software is that close to not keeping up, it is likely to not work reliably.

Reply to
rickman

Consider adding a write index and a read index. The ISR increments the write index while the reading routine increments the read index.

-- EventStudio 4.0 -

formatting link
Model in Plain Text; Generate Sequence Diagrams in PDF/Word

Reply to
EventHelix.com

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.