mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-12-06 05:14:19 +00:00
67 lines
3.4 KiB
C++
67 lines
3.4 KiB
C++
#include "test.h"
|
|
#include <cerrno>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <zephyr/drivers/lora/zc_lora_timing.h>
|
|
|
|
namespace {
|
|
// The RX-busy gate, lora_radio_zc_is_receiving() from lora_radio_zc.c, in the fake environment of
|
|
// lora_radio_zc_fakes.h: the chip is an IRQ word and a BUSY line, the radio lock a counted fake.
|
|
#include "lora_radio_zc_fakes.h"
|
|
} // namespace
|
|
|
|
TEST(sx126x_gate_dc_sleep, "UNIT-SX126X-GATE-001", "Duty-cycle sleep phase reports idle without a status read") {
|
|
Radio r(LORA_RADIO_OP_RX_DUTY_CYCLE);
|
|
chip.busy = true; chip.irq = SX126X_IRQ_PREAMBLE_DETECTED;
|
|
CHECK(!lora_radio_zc_is_receiving(&r.dev));
|
|
CHECK(chip.count("get_irq") == 0 && r.d.common.lock.locks == 1 && r.lockBalanced());
|
|
CHECK(chip.irq == SX126X_IRQ_PREAMBLE_DETECTED && r.d.zc.preamble_seen_at_ms == 0);
|
|
}
|
|
TEST(sx126x_gate_busy_outside_dc, "UNIT-SX126X-GATE-002", "BUSY outside the duty-cycle RX sleep still reads the status") {
|
|
for (bool dc : {false, true}) {
|
|
Radio r(LORA_RADIO_OP_RX);
|
|
chip.busy = true; chip.irq = SX126X_IRQ_PREAMBLE_DETECTED;
|
|
if (dc) r.d.common.op = LORA_RADIO_OP_TX;
|
|
CHECK(lora_radio_zc_is_receiving(&r.dev));
|
|
CHECK(chip.count("get_irq") == 1 && r.lockBalanced() && r.d.zc.preamble_seen_at_ms == atomic_val_t(now_ms));
|
|
}
|
|
}
|
|
TEST(sx126x_gate_dc_reception, "UNIT-SX126X-GATE-003", "Latch, contention and preamble grace still hold in duty cycle") {
|
|
Radio r(LORA_RADIO_OP_RX_DUTY_CYCLE);
|
|
chip.busy = true;
|
|
r.d.zc.rx_packet_active = true; r.d.zc.header_seen_at_ms = now_ms - 10;
|
|
CHECK(lora_radio_zc_is_receiving(&r.dev) && r.d.common.lock.locks == 0 && chip.count("get_irq") == 0);
|
|
r.d.zc.rx_packet_active = false; r.d.zc.header_seen_at_ms = 0;
|
|
r.d.common.lock.contended = true;
|
|
CHECK(lora_radio_zc_is_receiving(&r.dev) && chip.count("get_irq") == 0);
|
|
r.d.common.lock.contended = false; chip.busy = false; chip.irq = SX126X_IRQ_PREAMBLE_DETECTED;
|
|
CHECK(lora_radio_zc_is_receiving(&r.dev) && r.d.zc.preamble_seen_at_ms == atomic_val_t(now_ms));
|
|
now_ms += 50;
|
|
CHECK(lora_radio_zc_is_receiving(&r.dev));
|
|
now_ms += 60;
|
|
CHECK(!lora_radio_zc_is_receiving(&r.dev) && r.d.zc.foreign_pre_count == 1 && chip.irq == 0);
|
|
CHECK(chip.count("get_irq") == 3 && r.lockBalanced());
|
|
}
|
|
TEST(sx126x_gate_lr11xx_policy, "UNIT-SX126X-GATE-004", "No-poll radios answer a duty cycle from the latch alone") {
|
|
Radio r(LORA_RADIO_OP_RX_DUTY_CYCLE);
|
|
r.lr11xxPolicy();
|
|
chip.irq = SX126X_IRQ_PREAMBLE_DETECTED | SX126X_IRQ_HEADER_VALID;
|
|
// No bus and no lock in the duty cycle: any command in its sleep phase would end it.
|
|
CHECK(!lora_radio_zc_is_receiving(&r.dev) && chip.log.empty() && r.d.common.lock.locks == 0);
|
|
r.d.zc.rx_packet_active = true; r.d.zc.header_seen_at_ms = now_ms - 10;
|
|
CHECK(lora_radio_zc_is_receiving(&r.dev) && chip.log.empty());
|
|
// A latch past its deadline is dropped without touching the chip.
|
|
r.d.zc.header_seen_at_ms = now_ms - 600;
|
|
CHECK(!lora_radio_zc_is_receiving(&r.dev) && chip.log.empty() && !r.d.zc.rx_packet_active);
|
|
CHECK(chip.irq == (SX126X_IRQ_PREAMBLE_DETECTED | SX126X_IRQ_HEADER_VALID) && r.lockBalanced());
|
|
// Continuous RX may poll; a taken lock reads as idle on this policy.
|
|
r.d.common.op = LORA_RADIO_OP_RX;
|
|
r.d.common.lock.contended = true;
|
|
CHECK(!lora_radio_zc_is_receiving(&r.dev) && chip.log.empty());
|
|
r.d.common.lock.contended = false;
|
|
CHECK(lora_radio_zc_is_receiving(&r.dev) && chip.count("get_irq") == 1);
|
|
}
|