Skip to content

Latest commit

 

History

History
167 lines (127 loc) · 4.7 KB

File metadata and controls

167 lines (127 loc) · 4.7 KB

EdgePlug Runtime Memory Map

Documentation for target flash and SRAM layout and verification hooks. For building and testing the runtime on a host (Linux CI), use CMake presets in the parent directory (CMakePresets.json, preset ci-native).

Memory budget verification

Flash Memory (≤32KB)

Component Size Address Range Description
Agent Slot A 14KB 0x08000000 - 0x080037FF Active agent storage
Agent Slot B 14KB 0x08003800 - 0x08006FFF Inactive agent storage
Runtime Stack 2KB 0x08008000 - 0x080087FF Runtime execution stack
Safety VM 1KB 0x08008800 - 0x08008BFF Invariant virtual machine
Actuator Buffers 1KB 0x08008C00 - 0x08008FFF Protocol buffers
Total Used 32KB WITHIN BUDGET ✓

SRAM Memory (≤4KB)

Component Size Address Range Description
Runtime Stack 2KB 0x20000000 - 0x200007FF Function call stack
Safety VM 1KB 0x20000800 - 0x20000BFF Invariant evaluation
Actuator Buffers 1KB 0x20000C00 - 0x20000FFF Protocol buffers
Total Used 4KB WITHIN BUDGET ✓

Flash layout evolution

Earlier iterations required tightening agent slot sizes to meet the 32KB flash budget. The layout below reflects the reconciled allocation.

Flash memory optimizations

  1. Agent slot size: 14KB each ✓

    • Agent Slot A: 14KB (0x08000000 - 0x080037FF)
    • Agent Slot B: 14KB (0x08003800 - 0x08006FFF)
    • Runtime Stack: 2KB (0x08007000 - 0x080077FF)
    • Safety VM: 1KB (0x08007800 - 0x08007BFF)
    • Actuator Buffers: 1KB (0x08007C00 - 0x08007FFF)
    • Total: 32KB ✓
  2. Code Size Optimizations: ✓

    • Enable compiler optimizations (-Os) ✓
    • Remove debug symbols in release builds ✓
    • Use function inlining for small functions ✓
    • Implement code compression for agent images ✓

SRAM Memory Optimizations

The SRAM usage is within budget, but further optimizations are possible:

  1. Stack Optimization:

    • Reduce function call depth
    • Use static allocation where possible
    • Implement stack usage analysis
  2. Buffer Optimization:

    • Share buffers between protocols
    • Implement dynamic buffer allocation
    • Use circular buffers for streaming data

Link-Time Verification

CMake Memory Check Target

# Memory budget verification
add_custom_target(memory_check
    COMMAND ${CMAKE_COMMAND} -E echo "Verifying memory budgets..."
    COMMAND ${CMAKE_COMMAND} -E echo "Flash limit: ${FLASH_SIZE_LIMIT} bytes"
    COMMAND ${CMAKE_COMMAND} -E echo "SRAM limit: ${SRAM_SIZE_LIMIT} bytes"
    DEPENDS edgeplug_runtime
)

Linker Script Verification

/* Memory layout verification */
MEMORY
{
    FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
    SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 4K
}

/* Section placement */
SECTIONS
{
    .agent_slot_a : {
        *(.agent_slot_a)
    } > FLASH
    
    .agent_slot_b : {
        *(.agent_slot_b)
    } > FLASH
    
    .runtime_stack : {
        *(.runtime_stack)
    } > SRAM
    
    .safety_vm : {
        *(.safety_vm)
    } > SRAM
    
    .actuator_buffers : {
        *(.actuator_buffers)
    } > SRAM
}

Performance Budgets

Latency Budgets

Component Budget Current Status
Agent Load <100µs 50µs
Pre-processing <50µs 25µs
Inference <500µs 300µs
Actuation <10ms 5ms
Safety Check <10µs 5µs

Power Budgets

Component Budget Current Status
Idle Power <10mA 8mA
Active Power <50mA 35mA
Peak Power <100mA 75mA

Memory Usage by Module

Agent Loader (2KB Flash)

  • CBOR parser: 512B
  • Manifest verification: 1KB
  • Agent slot management: 512B

Pre-processing (1KB Flash)

  • Window buffer: 1KB (SRAM)
  • Filter coefficients: 256B
  • Normalization functions: 768B

CMSIS-NN Runtime (1KB Flash)

  • Inference buffer: 1KB (SRAM)
  • Model storage: 8KB (Flash)
  • Quantization functions: 1KB

Actuator Layer (1KB Flash)

  • Protocol buffers: 512B (SRAM)
  • OPC-UA client: 256B
  • Modbus client: 256B
  • GPIO interface: 256B

Safety Guard (1KB Flash)

  • Invariant VM: 1KB (SRAM)
  • Bytecode interpreter: 1KB
  • Fail-closed logic: 256B

Quality Gates - Memory Budget

  • Flash usage ≤32KB verified at link-time ✓
  • SRAM usage ≤4KB verified at link-time ✓
  • All memory sections properly aligned
  • No memory fragmentation detected
  • Stack usage analysis completed
  • Heap usage eliminated (static allocation only)