This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Ring buffer or queue for different datatype

Hi,

I want to sample ADC signals and send data when requested via BLE or UART. I set a timer that triggers every 100 ms and gets ADC data.

To store the data, I would like to use some large buffer that will store incoming data. If the buffer reaches end limit and previous data isn't pulled out, it should overwrite the first data and while reading it should start reading from first data (of course not overwritten one) simple: FIFO with first in data replaceable if size full.

I think Ring buffer should solve my issue but the problem is with its data type. The datatype of ADC values is uint16_t while ring buffer has uint8_t so I have to break values in two 8 bytes and store them.

Ring Buffer

Queue library

I read a post about the difference between ring and queue here but it is a general discussion and states both are the same.

Could you please suggest what mechanism shall I use and do I need to modify nrf ring buffer library to support the required data type?

  • Ali Rumane said:
    Is there a way I can get available length before copying so that I don't have to remove half written data or copy half data so that I can free (nrf_ringbuf_free) some data and then copy the data.

    There's no such functionality, you'll have to track the amount of data stored yourself. 
    As each call to nrf_ringbuf_cpy_put will return the length of written data you can increment a global counter variable when you write and decrement when you free. That way you can compare the counter variable to the ring buffer size and know how much space is free. 


Related