Hackaday log – Firmware architecture (Work in progress)
I am currently writing the firmware.
Time is limited at the moment and I am quite busy, so progress is steady but deliberately slow.
I am aligning the codebase with a new firmware “skeleton” I am developing:
https://github.com/Bertrand-selvasystems/firmware_skeleton_espidf
Architecture rules
Drivers (module_*.c) are self-contained
- No FreeRTOS includes
- No queues
- No event bits
- Clean C API only:
init/read/write/deinit
Tasks (task_*.c) orchestrate hardware access through drivers
Tasks are the only place where the system:
- uses FreeRTOS primitives (queues, event groups, notifications)
- implements retry and delay logic
- sets, clears and waits on event bits
- manages health monitoring and fault handling
APIs (API_*.c) talk to tasks, not to hardware
- They provide intent-level functions
- They hide internal queues and events from the rest of the application
Configuration is split into two layers
-
Frozen hardware configuration (
system_cfg.*): wiring, addresses, frequencies (const, never modified) - Runtime state: handles, flags, counters, queues, event groups
Layers and dependencies
app_main / initialization
→ API_* (facade, intent-level calls)
→ task_* (FreeRTOS actors, ownership and logic)
→ module_* (drivers, hardware access only)
Allowed dependencies
-
module_*may depend only on ESP-IDF drivers (I2C,UART,GPIO, etc.), never onsystem_* -
task_*may depend onsystem_types,system_queues,system_state,system_faultsandmodule_* -
API_*may depend on task-facing command queues andsystem_*but never on hardware
Design rationale
The goal is clean, stable firmware, especially by enforcing one service per critical hardware block.
This guarantees zero concurrent access to the same peripheral, even in unexpected edge cases, which is a major stability gain.
This point is absolutely central for a system designed to run unattended for five years, or close to it, such as a remote LoRa repeater deployed in the field.
At this stage, I have implemented:
- the I2C service
- the PCA (I/O expander) service
The current work-in-progress code is available here:
https://github.com/Bertrand-selvasystems/loratube_firmware
There is still a lot to do, but the foundation is now in place.
The LEDs are blinking, which is usually a good sign.
Bertrand Selva
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.