IT

Embeded Combinatory Firmware

Embedded real-time firmware for optical sorting machines — Project Overview

What It Is

Embedded C firmware for an ARM-based FPGA SoC running a real-time OS. Combines detections from 4 industrial cameras on an optical sorting line. Detections arrive via serial queues, are combined across cameras in a circular buffer, evaluated through configurable boolean rules, and converted into actuator firing commands.

Also includes: a C# rule compiler library and C# host integration clients for diagnostics and logging.

Embedded RTOS 530 Tests 19,648 Lines C + C# 20 Bugs Fixed

Architecture

graph TD
    subgraph CAM["4 Industrial Cameras"]
        C1["Camera 1"] --> Q1["Detection\nQueue"]
        C2["Camera 2"] --> Q1
        C3["Camera 3"] --> Q1
        C4["Camera 4"] --> Q2["Local\nQueue"]
    end

    subgraph FW["Embedded Firmware"]
        ORCH["Orchestrator"] --> PIPE["Combinatory\nPipeline"]
        PIPE --> EVAL["Rule\nEvaluation"]
        EVAL -->|accept| OUT["Output\nQueue"]
        EVAL -->|reject| X["Discard"]
    end

    subgraph HOST["Host Software"]
        RULES["Rule\nCompiler"]
        DIAG["Diagnostics\n& Logging"]
    end

    Q1 --> ORCH
    Q2 --> ORCH
    OUT --> HW["Actuators"]
    RULES -->|"upload"| EVAL
    FW -.->|"telemetry"| DIAG
  

Our Code — Line Count

CategoryLinesTests
Embedded C firmware (7 modules)3,711
Embedded C tests11,217365
Test infrastructure1,163
C# rule compiler (lib + tests)2,327165
C# host integration clients999
Documentation231
TOTAL19,648530

Development Time Estimate

How long would a super senior embedded C + C# developer take to build this from scratch, writing all code by hand?

Why Estimates Must Account for Hidden Costs

Documented false starts & rework: ~1,277 lines of code were fully implemented, tested, and then deleted as the design evolved. Key algorithms went through multiple design iterations before reaching the final version. Estimated wasted effort: ~5 working days.

20 non-trivial bugs found & fixed: race conditions, timer overflows (found only on real hardware), serial communication timing issues, memory corruption, and type confusion bugs. Many require hardware debugging with oscilloscope.

Phase Breakdown (Realistic Estimate)

#PhaseDaysWhy
0 Architecture & Design 4 Invent core algorithms, data formats, communication protocols. Whiteboard, diagrams, edge-case analysis. Creation from scratch, not implementing a spec.
1 Environment Setup 2 Cross-compilation toolchain, RTOS simulation, test framework, build system, mock infrastructure.
2 Rule Compiler (C#) 5 Parser, AST, rule optimization, binary serializer. Compiler theory applied. 165 tests, 2,327 lines of dense algorithmic code.
3 Combinatory Pipeline 8 The hardest module. Circular buffer with multi-camera combination, multiple closure strategies, critical sections. 3 design iterations. 68 tests.
4 Rule Evaluation Engine 4 Binary rule evaluator with runtime loading, multi-phase evaluation with different strategies. 41 tests.
5 Output Processing (2 Engines) 5 Two completely separate evaluation engines with different strategies. They share almost no code. Multi-output with timing delays. Like writing the module twice. 36 tests.
6 Logging System 2.5 State machine with ring buffer and robust download protocol. 19 tests.
7 Diagnostic Capture 4 Multi-state capture system with large data download and 2D region-of-interest extraction. 51 tests.
8 Orchestration + Integration 6 Where everything must work together. Real-time scheduling, synthetic data generation for testing, architecture refactoring. Integration is always harder than individual modules. 87 tests.
9 C# Host Clients 3 Two host-side integration clients (~1,000 LOC) matching firmware protocols exactly.
10 Bug Fixing & Hardening 5 20 documented bugs. Race conditions, timer overflows, communication timing, memory corruption. Some found only with oscilloscope on factory floor.
11 False Starts & Rework 4 Multiple features implemented and removed as design evolved. Key algorithms redesigned. ~1,277 lines written, tested, deleted.
12 Documentation 1 Register maps, protocol documentation, integration guides.
TOTAL 53.5 ~10.5 weeks, ~2.5 months

Scenario Comparison

ScenarioDaysDuration
Optimistic (no HW issues, first design works) 42 ~8.5 weeks (~2 months)
Realistic (includes false starts + HW debug) 53 ~10.5 weeks (~2.5 months)
With surprises (requirement changes, HW unavailable) 60–65 ~13 weeks (~3 months)

Actual Development Timeline (with AI Coding Assistant)

The project was built with an AI coding assistant writing ~90% of the code, directed by a senior developer who designed the architecture and made all decisions. Human role: architecture, decisions, prompting, review, hardware testing.

~21 Calendar Days ~90 Hours Effective ~12 Full-Day Equivalents 19,648 Lines Delivered

Reconstructed from Git + Memory Bank

PeriodWhat Was BuiltEst. Hours
~Dec 2025 Rule compiler complete (165 tests). Core firmware modules base implementation. Mock infrastructure. Environment setup. ~30–35
Dec 20 → Jan 19 Algorithm refinements, 8 bug fixes, architecture refactoring, performance optimization, feature iterations (some later removed). ~25–30
Jan 20 → Jan 23 Logging system, cleanup and simplification, removal of experimental features. Repository created. ~15–18
Feb 2 → Feb 4 Performance optimization, bug fixes, second evaluation engine complete (plan + code + 18 tests in 2h16m!). ~8–10
Feb 6 Diagnostic capture module complete in one day: firmware + C# client + documentation + bug fix. 30 tests. ~8
Feb 9 → Feb 11 Bug fixes, host integration, region-of-interest extraction (9 new tests). ~8–10
TOTAL ~85–100h

Estimate vs Reality

PhaseEst. (manual)Actual (AI Assistant)Speedup
Architecture + Design4 days~2 days2x
Environment Setup2 days~0.5 days4x
Rule Compiler (C#)5 days~1.5 days3.3x
Combinatory Pipeline8 days~2.5 days3.2x
Rule Evaluation Engine4 days~1 day4x
Output Processing (2 engines)5 days~1 day5x
Logging System2.5 days~0.5 days5x
Diagnostic Capture4 days~1.5 days2.7x
Orchestration + Integration6 days~2 days3x
C# Host Clients3 days~0.5 days6x
Bug Fixing + Hardening5 days~2 days2.5x
False Starts + Rework4 days~0.5 days8x
Documentation1 day~0.2 days5x
TOTAL53.5 days~12 days4.5x

Key Observations

  1. Architecture & debugging = only 2–2.5x speedup. These require human reasoning that AI can assist but not replace. Understanding race conditions and hardware-specific bugs requires domain expertise and physical access to equipment.
  2. Code generation phases = 3–8x speedup. AI excels at generating tested, pattern-consistent code. The rule compiler, dual evaluation engines, and 530 tests were produced at speeds impossible by hand.
  3. Rework cost drops from days to minutes. The 1,277 deleted lines cost ~5 human-days to write. With AI, writing & deleting 500 lines is a 15-minute operation. This fundamentally changes how you approach exploratory design.
  4. Second evaluation engine complete in 2h16m. Plan + implementation + 18 tests for a complete module. This would take a human 5 full days. The clearest example of AI-augmented development being qualitatively different, not just faster.
  5. Implied productivity: 1,637 LOC/day with AI vs 370 LOC/day by hand. For embedded C with full test coverage. Industry average for safety-critical embedded: 50–150 LOC/day.

Bottom Line

Human (realistic)With AI AssistantRatio
Full-day equivalents (8h)53~124.5x
Effective hours~424h~90h4.7x
Calendar time~2.5 months~3 weeks3.5x
LOC/day3701,6374.4x