Interview Prep Docs
HelioVision/2. Hardware and Edge / Hardware Protocols and Execution

Edge Execution & Hardware Protocols

To build an edge-to-cloud machine vision system, you must understand how data moves at the physical layer and how the OS schedules the code reading that data.

1. Hardware Communication Protocols

As an electronics engineer, understanding the physical and data-link layers of hardware communication is crucial for connecting sensors, motor drivers, and central ECUs.

  • I2C (Inter-Integrated Circuit): A 2-wire serial bus (SDA/SCL). Half-duplex, multi-master/multi-slave with addresses. Used for short-distance slow sensors (temperature, EEPROM configs).
  • SPI (Serial Peripheral Interface): A 4-wire bus (MOSI/MISO/SCK/CS). Full-duplex, single-master. Extremely fast, used for reading raw sensor data or driving displays.
  • UART: 2-wire (TX/RX), no clock. Asynchronous, peer-to-peer. Great for simple serial consoles and GPS modules.
  • CAN (Controller Area Network): 2-wire differential. Multi-master broadcast, highly noise-resistant. Prioritizes messages (lower ID = higher priority). Standard in Automotive (Marelli).
graph LR
    subgraph i2c ["I2C Bus (2-wire, Address-based)"]
        Master["Microcontroller"] -- SDA/SCL --> S1["Sensor 0x40"]
        Master -- SDA/SCL --> S2["Sensor 0x41"]
    end
    
    subgraph spi ["SPI Bus (4-wire, Chip Select)"]
        MasterSPI["Microcontroller"] -- MOSI/MISO/SCK --> S3["Display"]
        MasterSPI -- "CS1 (Chip Select)" ---> S3
        
        MasterSPI -- MOSI/MISO/SCK --> S4["Flash Memory"]
        MasterSPI -- "CS2 (Chip Select)" ---> S4
    end

2. Real-Time OS (RTOS) vs. General OS

Linux and Windows use Time-Slicing to share the CPU fairly among hundreds of background tasks. This is terrible for robotics or high-speed manufacturing where a 50ms delay in stopping a conveyor belt ruins a product.

An RTOS (Real-Time Operating System) is explicitly designed for Determinism (guaranteeing a task completes within a strict deadline).

  • It operates on strict Priority-based Preemptive Scheduling. If an emergency stop interrupt fires, the RTOS freezes the current task instantly.
  • Examples: FreeRTOS (ESP32/STM32), AUTOSAR OS (Automotive ECUs).
gantt
    title RTOS Preemptive Scheduling (Hard Real-Time)
    dateFormat  s
    axisFormat  %S
    section Execute
    Low Priority (Logging)   :a1, 0, 3s
    High Priority (E-Stop)   :crit, active, 3, 2s
    Low Priority Resumes     :a2, 5, 2s

3. Concurrency: Threads vs. Processes

Even if you run Linux on a Raspberry Pi, you must manage concurrency correctly.

  • Processes: Completely isolated memory spaces. If one crashes, the others survive. Heavy to create, slow to switch. They communicate via IPC (Inter-Process Communication).
  • Threads: Lightweight, fast to create. They share memory within the same process.
  • The Danger (Race Conditions): Because threads share memory, if two threads edit the same variable simultaneously, it corrupts. You must synchronize them using Mutexes (Locks) or Semaphores.
  • Python's Flaw (The GIL): The Global Interpreter Lock guarantees that only one thread can execute Python byte-code at a time. If you use Python for CPU-heavy AI tasks at the edge, you cannot use threads; you must spawn entirely separate Processes (multiprocessing library).
graph TD
    subgraph proc1 ["Process 1 (Isolated Memory)"]
        T1(["Thread 1: Web Server"]) --- SharedMem[("Shared Variables")]
        T2(["Thread 2: Database"]) --- SharedMem
    end
    
    subgraph proc2 ["Process 2 (Isolated Memory)"]
        T3(["Process 2: Camera Capture"])
    end
    
    proc1 -. "IPC Socket" .-> proc2