Page 1 of 1

xRingbufferSendAcquire with byte buffer

Posted: Tue Aug 29, 2023 3:10 pm
by simon48
Hi,

I am experimenting with ring buffers for transmitting SPI data between tasks.
I first create a contiguous, DMA-capable and 32-bit aligned memory region; then use that memory region to create a ring buffer.

Code: Select all

    StaticRingbuffer_t *buffer_struct = (StaticRingbuffer_t *)heap_caps_malloc(sizeof(StaticRingbuffer_t), MALLOC_CAP_DEFAULT);
    uint8_t *buffer_storage= (uint8_t *)heap_caps_malloc(sizeof(uint8_t)*1024, MALLOC_CAP_DMA);

    // Then create ring buffers with manually allocated memory
    afe1_ring_buffer_handle = xRingbufferCreateStatic(1024, RINGBUF_TYPE_BYTEBUF, buffer_storage, buffer_struct);
    if (afe1_ring_buffer_handle == NULL) 
        ESP_LOGE(TAG, "Failed to create ring buffer\n");
When I try to take out a chunk of memory from the ring buffer to use as the SPI RX buffer,

Code: Select all

BaseType_t ret = xRingbufferSendAcquire(in_args->ringBufHandle, &fifo_buffer, 3*128, portMAX_DELAY);
it seems that xRingbufferSendAcquire does not work on byte buffers? Is there a workaround for this issue? Any help would be much appreciated.

Best,
Simon

Re: xRingbufferSendAcquire with byte buffer

Posted: Wed Aug 30, 2023 2:50 am
by ESP_Sprite
It cannot work for byte buffers (docs say it only works with no-split buffers) as there's no clean way to do this in an instance when the buffer 'wraps around'. For instance, when there's 8 bytes available at the end of the buffer and 8 at the beginning, you can put 16 bytes in the buffer, but xRingbufferSendAcquire wouldn't be able to give you an 16-byte buffer to put your things in as the memory available is not contiguous.

Re: xRingbufferSendAcquire with byte buffer

Posted: Wed Aug 30, 2023 1:34 pm
by simon48
Thanks Sprite for the reply! That makes perfect sense.

I guess I will use two queues to pass memory pointers between tasks.

Re: xRingbufferSendAcquire with byte buffer

Posted: Thu Aug 31, 2023 11:51 am
by MicroController
simon48 wrote:
Tue Aug 29, 2023 3:10 pm
Is there a workaround for this issue?
If your buffers always are of a specific size (e.g. "3*128" bytes?) you can of course create a no-split ringbuffer of n items of this specific size...

Re: xRingbufferSendAcquire with byte buffer

Posted: Mon Sep 04, 2023 1:39 pm
by simon48
MicroController wrote:
Thu Aug 31, 2023 11:51 am
simon48 wrote:
Tue Aug 29, 2023 3:10 pm
Is there a workaround for this issue?
If your buffers always are of a specific size (e.g. "3*128" bytes?) you can of course create a no-split ringbuffer of n items of this specific size...
Thanks for the reply! That could work as well.