There are two objects, RingBuffer and Block. The block represents a set of items in the ringbuffer. You can write single items to the ring buffer and

Bambofy / EmbeddedRingBuffer

submited by
Style Pass
2021-06-06 11:30:05

There are two objects, RingBuffer and Block. The block represents a set of items in the ringbuffer. You can write single items to the ring buffer and read many at onnce. It was designed to handle ISR routines and non-blocking devices therefore bytes can be wrote in an interrupt handler and read in large chunks to output to slower medium like SD cards. To use this in an ISR setting, the Skip parameter of read must be set to false (called autoskip), then you must manually skip it the number of reads the block contains once you are finished with the block, this is so that the writing does not corrupt the blocks data as it is being used.

It does not use malloc/free since the size is defined as a template parameter and is written in plain C++98 with no special features used.

Since the ring buffer is just an array, to return a block that overlaps the 0th index would mean having 2 regions of the array to process, however the sd card writing (DMA) only works on single arrays at a time. This means that if you have a ringbuffer of 100 items at your reading from position 98, the maximum number of elements a block can return is 2. This may sound unrealistic but this was designed for SD cards that write extremely large blocks at a time (>30KB) using buffers that are large enough to store a considerable number of elements before requiring writing to the sd card. In practice the ring buffers write position will never exceed far from the read position since the SD card is emptying it constantly. You must calculate the timing of your input data and output data carefully for the buffer.

Leave a Comment
Related Posts