Skip to content

Engineering Standards & Testing Practices

Developing mission-critical embedded software requires strict adherence to memory discipline, static analysis, and deterministic execution bounds.


1. Embedded C & FreeRTOS Coding Rules

A. Zero Dynamic Allocation in Polling Loops

  • Never call malloc(), calloc(), or pvPortMalloc() during steady-state Modbus polling or telemetry generation.
  • All telemetry schema builders and Modbus frame buffers must use static or task-stack allocated buffers with strict bounds checking.

B. FreeRTOS Task Stack Budgets

Every FreeRTOS task must declare an explicit stack depth with a verified high-water mark margin of at least 25%:

Task NamePriorityStack AllocationVerified High-Water Mark
vModbusTasktskIDLE_PRIORITY + 34,096 bytes2,840 bytes
vStorageTasktskIDLE_PRIORITY + 26,144 bytes4,120 bytes
vCloudTasktskIDLE_PRIORITY + 28,192 bytes5,680 bytes
vHttpTasktskIDLE_PRIORITY + 16,144 bytes3,920 bytes
vDiagTasktskIDLE_PRIORITY + 42,048 bytes1,180 bytes

C. Stack Overflow Hook

The firmware configures configCHECK_FOR_STACK_OVERFLOW = 2:

void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName) {
// Record fault in flash diagnostic log
aslandi_diag_log_fault(FAULT_STACK_OVERFLOW, pcTaskName);
// Force immediate hardware reboot via watchdog
watchdog_reboot(0, 0, 0);
}

2. Automated Regression Test Harness

The tests/ directory contains Python test harnesses simulating Modbus RTU slaves, dropping Wi-Fi packets, and verifying telemetry schema conformance:

Terminal window
# Run automated Modbus protocol and timeout simulator
python tests/test_modbus_protocol.py --port /dev/ttyUSB0 --meters 50
# Execute cloud ingestion end-to-end regression
pytest tests/cloud_e2e_test.py -v