Is there a method to get available bytes in a byte ring buffer?

zliudr
Posts: 357
Joined: Thu Oct 03, 2019 5:15 am

Is there a method to get available bytes in a byte ring buffer?

Postby zliudr » Mon Jun 21, 2021 8:03 pm

I am using the ring buffers to buffer data from USB-UART ICs that I connected to a USB host and then ESP32. I want to emulate the IDF version of uart calls such as uart_read_bytes(), uart_write_bytes() or uart_get_buffered_data_len(). So in order to make the uart_get_buffered_data_len() I need to know how many bytes are stored in the ring buffer. Can I assume that:

available_bytes_to_read = buffer_size - xRingbufferGetMaxItemSize()

I can probably try it with a sample code but I thought I'd check to make sure this always works, not just with a simple code. Thanks.

zliudr
Posts: 357
Joined: Thu Oct 03, 2019 5:15 am

Re: Is there a method to get available bytes in a byte ring buffer?

Postby zliudr » Thu Jun 24, 2021 3:04 pm

OK correction:

available_bytes_to_read = buffer_size - xRingbufferGetCurFreeSize()

This works.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 58 guests