firmware: config-integrity check, fault injection, verified recovery ladder; soak harness

This commit is contained in:
Lars Nolden
2026-09-01 11:20:29 +02:00
parent 26fab7202a
commit e131687264
7 changed files with 191 additions and 5 deletions
+37 -5
View File
@@ -34,6 +34,7 @@ static volatile bool s_want_radio_reset;
static volatile bool s_want_test_tx;
static volatile bool s_want_probe;
static volatile bool s_want_test_burst;
static volatile int s_inject; // 1 = standby, 2 = sleep (config loss)
static uint8_t s_test_access_nr;
static uint8_t s_test_lfield = 19;
static uint32_t s_seq;
@@ -95,20 +96,29 @@ static bool recover(const char *reason, int level)
bool ok = false;
switch (level) {
case 1:
// Cheapest step: clear IRQ state and re-arm RX. It must only report
// success if the radio really is configured and receiving, otherwise
// the ladder would stop at a deaf radio.
sx126x_clear_irq(SX126X_IRQ_ALL);
sx126x_standby();
sx126x_restore_rx_payload_len();
ok = sx126x_set_rx();
ok = sx126x_set_rx() && sx126x_config_intact();
if (ok) {
vTaskDelay(pdMS_TO_TICKS(2));
ok = (((sx126x_get_status() >> 4) & 0x7) == 0x5);
}
break;
case 2:
g_stats.radio_reinit++;
ok = radio_full_init() && sx126x_set_rx();
ok = radio_full_init() && sx126x_set_rx() && sx126x_config_intact();
break;
case 3:
g_stats.fem_reinit++;
fem_power(false);
vTaskDelay(pdMS_TO_TICKS(20));
ok = radio_full_init() && sx126x_set_rx();
fem_power(true);
vTaskDelay(pdMS_TO_TICKS(5));
ok = radio_full_init() && sx126x_set_rx() && sx126x_config_intact();
break;
default:
LOGJ("\"event\":\"radio_recovery\",\"reason\":\"%s\",\"level\":%d,"
@@ -496,6 +506,19 @@ static void repeater_task(void *arg)
s_want_probe = false;
run_probe();
}
if (s_inject) {
int what = s_inject;
s_inject = 0;
// Deliberately break the radio to exercise detection + the
// recovery ladder. The heartbeat probe is expected to notice.
if (what == 1) {
sx126x_standby();
} else {
sx126x_inject_sleep();
}
LOGJ("\"event\":\"fault_injected\",\"fault\":\"%s\"",
what == 1 ? "standby" : "sleep");
}
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)) > 0) {
uint16_t irq = sx126x_get_irq();
@@ -511,13 +534,21 @@ static void repeater_task(void *arg)
int64_t now = esp_timer_get_time();
if (now - last_heartbeat > 10000000LL) {
last_heartbeat = now;
// consistency probe: chip should be in RX (0x5)
// Consistency probe: the chip must be in RX (0x5) AND still
// hold its wM-Bus configuration. Checking the mode alone is not
// enough: a radio that lost its configuration (reset, sleep,
// glitch) can sit in RX looking healthy while deaf to C1.
uint8_t st = sx126x_get_status();
uint8_t mode = (st >> 4) & 0x7;
bool cfg_ok = sx126x_config_intact();
LOGJ("\"event\":\"heartbeat\",\"uptime_us\":%lld,\"chip_mode\":%u,"
"\"rssi_dbm\":%d", (long long)now, mode, sx126x_get_rssi_inst());
"\"config_intact\":%s,\"rssi_dbm\":%d",
(long long)now, mode, cfg_ok ? "true" : "false",
sx126x_get_rssi_inst());
if (mode != 0x5) {
recover_ladder("not_in_rx");
} else if (!cfg_ok) {
recover_ladder("config_lost");
}
}
}
@@ -533,6 +564,7 @@ void repeater_request_test_tx(void) { s_want_test_tx = true; }
void repeater_request_probe(void) { s_want_probe = true; }
void repeater_set_test_lfield(uint8_t l) { s_test_lfield = l; }
void repeater_request_test_burst(void) { s_want_test_burst = true; }
void repeater_inject_fault(int what) { s_inject = what; }
// ------------------------------------------------------------------ status