Repository navigation
Conversation
Replace per-sample modulo with increment-and-wrap indexing and update the task DMA cursor once per dispatch. Preserve the existing inline buffer helpers and sample order.
Skip the write when a channel buffer is full while continuing to advance the DMA cursor. Retain buffered samples until consumption and preserve the inline count helper.
|
Hello, After some time understanding the details of the first diff, I see two main factors of improvement:
After careful checks, this diff should be functionally equivalent to the previous code. Regarding the second diff, it is an obvious buffer overflow fix (we should move to rust to avoid these 😁). However, I still see room for a very little improvement: |
cfoucher-laas
left a comment
There was a problem hiding this comment.
See comment in conversation.
| } | ||
|
|
||
| static size_t next_dma_buffer_index[ADC_COUNT] = {0}; | ||
| size_t channel_count = enabled_channels_count[adc_index]; |
There was a problem hiding this comment.
Move to the beginning of the function, and replace remaining calls to enabled_channels_count[adc_index] by channel_count.
Summary
This PR improves ADC dispatch performance and fixes an out-of-bounds write when a channel buffer is full.
Performance improvement
Replace per-sample modulo operations with increment-and-wrap indexing, and update the task-mode DMA cursor once per dispatch. Sample order and existing
__STATIC_INLINEhelpers are preserved.Buffer overflow fix
Previously, the sample count stopped increasing at
CHANNELS_BUFFERS_SIZE, but the dispatcher continued writing at that index, one element beyond the buffer.The dispatcher now skips writes when the channel buffer is full while continuing to advance through the DMA data. Buffered samples remain available until consumed.
Scope
Two commits, changing only
data_dispatch.cpp. Existing formatting and helper functions are retained.Validation