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(), orpvPortMalloc()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 Name | Priority | Stack Allocation | Verified High-Water Mark |
|---|---|---|---|
vModbusTask | tskIDLE_PRIORITY + 3 | 4,096 bytes | 2,840 bytes |
vStorageTask | tskIDLE_PRIORITY + 2 | 6,144 bytes | 4,120 bytes |
vCloudTask | tskIDLE_PRIORITY + 2 | 8,192 bytes | 5,680 bytes |
vHttpTask | tskIDLE_PRIORITY + 1 | 6,144 bytes | 3,920 bytes |
vDiagTask | tskIDLE_PRIORITY + 4 | 2,048 bytes | 1,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:
# Run automated Modbus protocol and timeout simulatorpython tests/test_modbus_protocol.py --port /dev/ttyUSB0 --meters 50
# Execute cloud ingestion end-to-end regressionpytest tests/cloud_e2e_test.py -v