fix: TCXO XOSC_START_ERR handling, always apply config, register DIO1 ISR callback; TX proof of life confirmed by SDR
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_timer.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_task_wdt.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
@@ -31,6 +32,7 @@ static TaskHandle_t s_task;
|
||||
static volatile int64_t s_irq_ts;
|
||||
static volatile bool s_want_radio_reset;
|
||||
static volatile bool s_want_test_tx;
|
||||
static volatile bool s_want_probe;
|
||||
static uint8_t s_test_access_nr;
|
||||
static uint32_t s_seq;
|
||||
|
||||
@@ -62,9 +64,13 @@ static void irq_cb(int64_t ts)
|
||||
static bool radio_full_init(void)
|
||||
{
|
||||
sx126x_diag_t diag;
|
||||
bool ok = sx126x_init(&diag);
|
||||
bool cfg_ok = ok && sx126x_config_wmbus_c1(868950000u, RX_PAYLOAD_LEN)
|
||||
&& sx126x_set_tx_power(g_cfg.tx_power_dbm);
|
||||
bool init_ok = sx126x_init(&diag);
|
||||
// Apply the wM-Bus configuration even when init reports soft failures:
|
||||
// an unconfigured radio in RX is worse than a partially degraded one,
|
||||
// and the recovery ladder judges the combined result anyway.
|
||||
bool cfg_ok = sx126x_config_wmbus_c1(868950000u, RX_PAYLOAD_LEN)
|
||||
& sx126x_set_tx_power(g_cfg.tx_power_dbm);
|
||||
cfg_ok = init_ok && cfg_ok;
|
||||
LOGJ("\"event\":\"radio_init\",\"spi\":%s,\"reset\":%s,\"busy_low\":%s,"
|
||||
"\"tcxo\":%s,\"device_errors\":%u,\"chip_mode\":%u,"
|
||||
"\"fem_power\":true,\"fem_mode\":\"rx\",\"frequency_hz\":868950000,"
|
||||
@@ -181,12 +187,33 @@ static const char *do_tx(const uint8_t *payload, int payload_len,
|
||||
}
|
||||
// airtime: 48 bit preamble + 16 bit sync + payload -> ~80us/byte + 640
|
||||
uint32_t airtime_ms = (payload_len * US_PER_BYTE + 640) / 1000;
|
||||
uint16_t irq = wait_irq(airtime_ms + 200);
|
||||
*tx_done_us = s_irq_ts;
|
||||
// Instrumented wait: poll IRQ flags, DIO1 level and chip mode while
|
||||
// also honoring the ISR notification. Gives ground truth about the
|
||||
// TX sequence even when the interrupt path is broken.
|
||||
int64_t deadline = esp_timer_get_time() + (airtime_ms + 200) * 1000LL;
|
||||
uint16_t irq = 0;
|
||||
bool notify_seen = false, dio1_seen = false;
|
||||
uint8_t max_mode = 0;
|
||||
while (esp_timer_get_time() < deadline) {
|
||||
if (ulTaskNotifyTake(pdTRUE, 0) > 0) notify_seen = true;
|
||||
if (gpio_get_level(BOARD_LORA_DIO1)) dio1_seen = true;
|
||||
uint8_t st = sx126x_get_status();
|
||||
uint8_t mode = (st >> 4) & 0x7;
|
||||
if (mode > max_mode) max_mode = mode;
|
||||
irq = sx126x_get_irq();
|
||||
if (irq) break;
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
}
|
||||
*tx_done_us = notify_seen ? s_irq_ts : esp_timer_get_time();
|
||||
fem_set_tx(false);
|
||||
sx126x_clear_irq(SX126X_IRQ_ALL);
|
||||
LOGJ("\"event\":\"tx_diag\",\"irq\":%u,\"notify\":%s,\"dio1_high_seen\":%s,"
|
||||
"\"max_chip_mode\":%u,\"device_errors\":%u",
|
||||
irq, notify_seen ? "true" : "false", dio1_seen ? "true" : "false",
|
||||
max_mode, sx126x_get_device_errors());
|
||||
if (irq & SX126X_IRQ_TX_DONE) {
|
||||
g_stats.tx_success++;
|
||||
return "ok";
|
||||
return notify_seen ? "ok" : "ok_polled";
|
||||
}
|
||||
if (irq & SX126X_IRQ_TIMEOUT) {
|
||||
g_stats.tx_timeout++;
|
||||
@@ -231,6 +258,62 @@ static void run_test_tx(void)
|
||||
sx126x_restore_rx_payload_len();
|
||||
if (!sx126x_set_rx()) recover_ladder("test_tx_rx_restore");
|
||||
}
|
||||
// ---------------------------------------------------------------- probe
|
||||
|
||||
static void hexdump_json(const char *key, const uint8_t *d, int n)
|
||||
{
|
||||
printf("\"%s\":\"", key);
|
||||
print_hex(d, n);
|
||||
printf("\",");
|
||||
}
|
||||
|
||||
// Scripted low-level diagnostic with raw SPI response dumps.
|
||||
static void run_probe(void)
|
||||
{
|
||||
uint8_t r[16];
|
||||
|
||||
printf("{\"event\":\"probe\",");
|
||||
|
||||
sx126x_standby();
|
||||
sx126x_raw(0xC0, NULL, 0, r, 2); // GetStatus
|
||||
hexdump_json("status0", r, 2);
|
||||
|
||||
// SetDioIrqParams: all IRQs, all on DIO1
|
||||
uint8_t di[8] = {0x03, 0xFF, 0x03, 0xFF, 0, 0, 0, 0};
|
||||
sx126x_raw(0x08, di, 8, r, 9);
|
||||
hexdump_json("setirq_resp", r, 9);
|
||||
sx126x_raw(0xC0, NULL, 0, r, 2); // status after SetDioIrqParams
|
||||
hexdump_json("status_after_setirq", r, 2);
|
||||
|
||||
sx126x_raw(0x02, (uint8_t[]){0x03, 0xFF}, 2, NULL, 0); // ClearIrq
|
||||
sx126x_raw(0x12, NULL, 0, r, 4); // GetIrqStatus raw
|
||||
hexdump_json("irq_cleared", r, 4);
|
||||
|
||||
// small TX: 8 byte payload
|
||||
uint8_t pkt[8] = {0x54, 0xCD, 0xAA, 0x55, 0xDE, 0xAD, 0xBE, 0xEF};
|
||||
sx126x_start_tx(pkt, 8);
|
||||
printf("\"txpoll\":[");
|
||||
for (int i = 0; i < 12; i++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(2));
|
||||
uint8_t s2[2], q[4];
|
||||
sx126x_raw(0xC0, NULL, 0, s2, 2);
|
||||
sx126x_raw(0x12, NULL, 0, q, 4);
|
||||
printf("\"%02X-%02X%02X%02X%02X\"%s", s2[1], q[0], q[1], q[2], q[3],
|
||||
i < 11 ? "," : "");
|
||||
}
|
||||
printf("],");
|
||||
fem_set_tx(false);
|
||||
|
||||
sx126x_raw(0x17, NULL, 0, r, 4); // GetDeviceErrors
|
||||
hexdump_json("dev_errors", r, 4);
|
||||
|
||||
sx126x_clear_irq(SX126X_IRQ_ALL);
|
||||
sx126x_restore_rx_payload_len();
|
||||
sx126x_set_rx();
|
||||
printf("\"done\":true}\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------ RX path
|
||||
|
||||
@@ -333,6 +416,7 @@ static void repeater_task(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
s_task = xTaskGetCurrentTaskHandle();
|
||||
sx126x_set_irq_callback(irq_cb);
|
||||
esp_task_wdt_add(NULL);
|
||||
|
||||
if (!radio_full_init()) {
|
||||
@@ -354,6 +438,10 @@ static void repeater_task(void *arg)
|
||||
s_want_test_tx = false;
|
||||
run_test_tx();
|
||||
}
|
||||
if (s_want_probe) {
|
||||
s_want_probe = false;
|
||||
run_probe();
|
||||
}
|
||||
|
||||
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)) > 0) {
|
||||
uint16_t irq = sx126x_get_irq();
|
||||
@@ -388,6 +476,7 @@ void repeater_start(void)
|
||||
|
||||
void repeater_request_radio_reset(void) { s_want_radio_reset = true; }
|
||||
void repeater_request_test_tx(void) { s_want_test_tx = true; }
|
||||
void repeater_request_probe(void) { s_want_probe = true; }
|
||||
|
||||
// ------------------------------------------------------------------ status
|
||||
|
||||
|
||||
Reference in New Issue
Block a user