xRingbufferSendAcquire with byte buffer

simon48
Posts: 3
Joined: Tue Aug 29, 2023 3:02 pm

xRingbufferSendAcquire with byte buffer

Postby simon48 » Tue Aug 29, 2023 3:10 pm

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
Best,
Simon

ESP_Sprite
Posts: 9739
Joined: Thu Nov 26, 2015 4:08 am

Re: xRingbufferSendAcquire with byte buffer

Postby ESP_Sprite » Wed Aug 30, 2023 2:50 am

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.

simon48
Posts: 3
Joined: Tue Aug 29, 2023 3:02 pm

Re: xRingbufferSendAcquire with byte buffer

Postby simon48 » Wed Aug 30, 2023 1:34 pm

Thanks Sprite for the reply! That makes perfect sense.

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

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: xRingbufferSendAcquire with byte buffer

Postby MicroController » 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...

simon48
Posts: 3
Joined: Tue Aug 29, 2023 3:02 pm

Re: xRingbufferSendAcquire with byte buffer

Postby simon48 » Mon Sep 04, 2023 1:39 pm

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.
Best,
Simon

Who is online

Users browsing this forum: No registered users and 102 guests