New uart driver example "edma_rb_transfer" in SDK2.6.0 has EXAMPLE_GetRingBufferLengthEDMA() implementation.
Seems function will return wrong result if data length in rx ringbuffer will be same as ringbuffer size.
Ex., size of uart dma ringbuffer is 255 bytes and same amount of bytes recieved - EXAMPLE_GetRingBufferLengthEDMA will return zero.
Hi Andrey,
Could you let me know which MCU are you using?
Best Regards,
Alexis Andalon
MK60DN512, but function behavior independent of the processor:
...
receivedBytes =
EXAMPLE_RING_BUFFER_SIZE - EDMA_GetRemainingMajorLoopCount(EXAMPLE_UART_DMA_BASEADDR, UART_RX_DMA_CHANNEL);
...
in case then we was receive same amount bytes as ringbuffer length receivedBytes will be set to zerro, but we know - right answer is EXAMPLE_RING_BUFFER_SIZE
Hi Andrey,
As you mention in the SDK implementation you should always have one extra byte in the buffer for the data you want to receive, if you want to receive transmission up to 255 bytes, you should have this size + 1.
Best Regards,
Alexis Andalon
:smileyhappy: No, it's wrong disigion - if you alway know how many bytes you will receive, you just don't need ring buffer (look at "edma_transfer" uart example). When we use ring buffer it's mean - we don't know how many data we will receive and some time we may lost some bytes (ex. on heavy loaded system), but in this case we alway can get last X bytes (where X - size of ring buffer).
One moment is - as i see in "edma_rb_transfer" example every time when
EXAMPLE_RING_BUFFER_SIZE - EDMA_GetRemainingMajorLoopCount(EXAMPLE_UART_DMA_BASEADDR, UART_RX_DMA_CHANNEL) == ringBufferIndex
we can't distinguish have we empty or we have full ring buffer.
At second, does not take into account ring buffer overflow. Let's say we have 255 bytes-len ring buffer and it contain 10 bytes of data. And we receive 265 bytes. In this case EXAMPLE_GetRingBufferLengthEDMA will return 20, but ring buffer is full and contain 255 bytes.