Skip to content

TinyMeasurement · Real-time Acquisition · DMA Double Buffer — Design notes

Actual application acquisition chain

flowchart TB
    T[Timer callback] --> N[Notify producer]
    N --> S[Read ADXL355]
    S --> B[Lock and write active buffer]
    B --> F{Buffer full?}
    F -->|Yes| R[Mark ready and switch buffer]
    R --> C[Notify consumer to process and output]
    F -->|No| N

A timer callback notifies the producer task. The awakened producer reads ADXL355 acceleration and temperature, writes samples into a buffer, and notifies the consumer. Locks coordinate buffer switching and shared state. Application sampling is not triggered by a DMA-completion interrupt; SPI driver DMA is a separate layer.

Older sketches below remain as design history. Buffering and task separation overlap acquisition and processing, while memory, buses, locks and network resources remain shared. They do not guarantee zero jitter or maximum throughput. Validate actual sample intervals, dropped/overwritten samples, buffer occupancy and transmission time.

源码 / Source

DMA + Double Buffer — Ping-Pong Buffer with DMA Offloading

DMA (Direct Memory Access) automatically transfers sensor data to memory — the underlying driver may offload byte transfers. Double buffering overlaps producer and consumer work.

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:

Historical DMA sketch (not the current trigger chain)
DMA fills A → A full → DMA switches to B → CPU processes A
DMA fills B → B full → DMA switches to A → CPU processes B

Producer and consumer work can overlap. Slow reads or processing can still cause waiting, overwrites or dropped samples.

Data Flow

Historical DMA sketch (not the current trigger chain)
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. Compare read latency and dropped samples under actual load.

DMA requires HW support

Check ADXL355 SPI bus initialization and the actual driver configuration before asserting that DMA is enabled.

Double buffer = 2 × buffer_size × 28 bytes

Two 512-sample buffers ≈ 28 KB. This is a historical estimate. Check 2 * buffer_size * sizeof(rt_process_sample_t) in the target build, plus locks, task stacks and queues.