How to manipulate a receiving buffer

Apr 03, 2007 42 Replies

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.

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.

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

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required