NOTES¶
DMA + Double Buffer — Ping-Pong Buffer with DMA Offloading
DMA (Direct Memory Access) automatically transfers sensor data to memory — the CPU doesn't need to move every byte. Double buffering (ping-pong) ensures zero-gap acquisition.
Intuition¶
Why DMA is Fast¶
Normal: CPU reads sensor data byte by byte → executes instructions → occupies CPU cycles.
DMA: Configure DMA once → DMA controller reads SPI/I2C data into memory autonomously → CPU stays free to process data.
Double Buffer (Ping-Pong)¶
Two buckets A and B:
DMA fills A → A full → DMA switches to B → CPU processes A
DMA fills B → B full → DMA switches to A → CPU processes B
DMA and CPU work in parallel, never waiting. Zero-gap acquisition.
Data Flow¶
DMA transfer complete interrupt
→ Buffer A full → notify Consumer task
→ DMA auto-switches to Buffer B
Consumer reads Buffer A and processes
→ Consumer finishes → waits for next interrupt
Notes¶
When to use DMA + Double Buffer?
Upgrade here when the Producer-Consumer ring buffer drops too many samples. DMA guarantees acquisition speed is never CPU-bound.
DMA requires HW support
ESP32-S3's SPI2/I2C controllers support DMA. Verify ADXL355 is connected to a DMA-capable peripheral interface.
Double buffer = 2 × buffer_size × 28 bytes
Two 512-sample buffers ≈ 28 KB. Twice the memory of Producer-Consumer, but much higher throughput.