Skip to content

Day40 - Acquisition Mode & Control Plane Refactor

๐ŸŽฏ Goal

Refactor the control plane of the IIO ADC driver by introducing a mode-based acquisition model, replacing the previous implicit behavior driven by parameter combinations.


๐Ÿ”ง Problem Statement (Before Day40)

The driver previously relied on:

  • sampling_frequency
  • fifo_enable
  • internal config bits

to determine behavior.

Issues:

  • No clear concept of "mode"
  • DRDY / FIFO / idle behavior mixed together
  • sampling_frequency = 0 used as implicit "disable"
  • Hard to extend (e.g. one-shot)

๐Ÿง  Design Overview

Introduce acquisition modes as the primary control abstraction.

Supported Modes

Mode Description
idle Sensor disabled, no sampling
continuous Periodic sampling + DRDY IRQ
fifo Periodic sampling + FIFO + watermark IRQ
one-shot Reserved (not implemented yet)

๐Ÿงฉ Control Plane Design

Single Source of Truth

mode = acquisition behavior

Other parameters become configuration inputs, not behavior drivers.


Parameter Roles

Parameter Role
sampling_frequency staged configuration
fifo_watermark staged FIFO parameter
fifo_enable compatibility wrapper

๐Ÿ”„ Staged Parameter Model

Sampling Frequency

  • Stored in data->sample_rate_hz
  • Behavior:
IDLE mode        โ†’ staged only (no hardware write)
ACTIVE mode      โ†’ re-apply mode (update hardware)

FIFO Watermark

  • Stored in data->fifo_watermark
  • Behavior:
FIFO mode        โ†’ re-apply mode (update hardware)
Other modes      โ†’ staged only

Rollback Mechanism

If hardware apply fails:

restore previous value

Ensures driver never enters inconsistent state.


โš™๏ธ apply_mode() Design

myadc_apply_mode() is the core of Day40.

Responsibilities:

  • Map logical mode โ†’ hardware config
  • Apply staged parameters
  • Ensure deterministic state

Example Mapping

IDLE
  ENABLE = 0
  IRQ    = 0

CONTINUOUS
  ENABLE = 1
  DRDY   = 1
  FIFO   = 0
  IRQ    = 1

FIFO
  ENABLE = 1
  DRDY   = 0
  FIFO   = 1
  IRQ    = 1

Key Rule

apply_mode() must build final config explicitly
  • Do NOT depend on previous config state
  • Always generate final state from mode

๐Ÿ”Œ Data Path Refactor

Before

config bits โ†’ decide FIFO / DRDY

After

mode โ†’ decide data path

Trigger Handler

switch (mode) {
case CONTINUOUS:
    read_channel();
    break;
case FIFO:
    read_fifo();
    break;
}

๐Ÿ” Compatibility Layer

fifo_enable

Still exposed for compatibility:

echo 1 โ†’ mode = fifo
echo 0 โ†’ mode = continuous

But:

mode is the real control source

๐Ÿšซ Removed Behavior

  • sampling_frequency = 0 as "disable"
  • implicit mode via parameter combinations

๐Ÿงช Validation Rules

When buffer is enabled

All control changes are rejected:

mode change      โ†’ -EBUSY
sampling update  โ†’ -EBUSY
watermark update โ†’ -EBUSY

๐Ÿ“Œ Summary

Day40 establishes a clean architecture:

  • Mode-driven control plane
  • Staged parameter model
  • Deterministic hardware configuration
  • Clear separation of behavior vs configuration

๐Ÿš€ Next Step (Day41)

  • one-shot acquisition
  • IRQ policy separation
  • STM32 register redesign