Day38 - IIO Sysfs Control Interface¶
🎯 Goal¶
Implement control plane for IIO driver using sysfs interface.
Replace module parameters with runtime configurable attributes:
- sampling_frequency (standard IIO)
- fifo_enable (driver private)
- watermark (driver private)
Keep existing data path unchanged:
IRQ → trigger → pollfunc → FIFO read → unpack → iio_push_to_buffers
🧠 Design Overview¶
Control Plane vs Data Plane¶
| Type | Interface |
|---|---|
| Control | sysfs (/sys/bus/iio/devices/iio:deviceX) |
| Data | buffer device (/dev/iio:deviceX) |
🧩 Attribute Design¶
1. sampling_frequency (Standard IIO)¶
- Implemented via:
read_raw()write_raw()- Declared in channel:
- Exposed as:
2. fifo_enable (Private Attribute)¶
- Controls:
-
MYADC_CONFIG_FIFO_ENABLEbit -
Implemented via:
IIO_DEVICE_ATTR-
show/store handler
-
Exposed as:
3. watermark (Private Attribute)¶
- Controls FIFO watermark level
-
Only meaningful when FIFO is enabled
-
Exposed as:
🔧 Helper Design¶
All hardware configuration is routed through helper functions:
Design Rules¶
- Caller must hold
data->lock - Write-through cache:
- Update hardware
- Then update driver state
🔒 Concurrency Model¶
- All control paths use
mutex - Helper functions assume locked context
🚫 Runtime Protection¶
Prevent configuration changes during streaming:
Applied to: - sampling_frequency - fifo_enable - watermark
⚙️ Default Configuration¶
Driver initializes:
- FIFO disabled by default
- IRQ enabled for consistency
- FIFO mode enabled via sysfs only
📌 Design Decision¶
Why not auto-enable DRDY when FIFO is disabled?¶
fifo_enableonly controls FIFO bit- Does NOT imply mode switching
Avoid mixing:
- FIFO mode
- DRDY mode
Mode switching should be handled explicitly in future design.
🧱 Macro Simplification¶
Custom macro to reduce boilerplate:
Expands to:
✅ Summary¶
- Introduced sysfs-based control plane
- Unified configuration through helper functions
- Preserved existing FIFO data path
- Established clean driver state model