kiss_modem: add radio chip boosted RX gain control
Add SetRxBoostedGain (0x20) / GetRxBoostedGain (0x21, reply 0xA1) and capability bit 3, the KISS equivalent of the radio.rxgain CLI setting. It is separate from FEM RX gain; a board may support either or both. - Support is declared by the driver via a new RadioLibWrapper::supportsRxBoostedGain() (SX1262, SX1268, LLCC68, LR1110, LR1121, LR2021), so nothing is written to the radio at boot. - The set is refused with TxBusy during TX or while host output is backed up. Otherwise any completed RX packet is delivered first, because some drivers (LR2021) drop to standby to apply the gain. - The reply always carries the state read back from the radio. Driver fixes found along the way, which also affect the radio.rxgain CLI in regular firmware: - CustomLR2021 never updated its cached gain state, so the getter always reported off. It now tracks the applied level per RX path and rolls RadioLib's cached level back if a write fails. - CustomLR1110/LR1121 cached the requested state even when the write failed. - lr11x0ResetAGC only reapplied the gain when RX_BOOSTED_GAIN was defined, so a runtime setting was lost on the next AGC reset.
This commit is contained in:
1 parent
0d648e4a18
commit
8cefda9612
16 files changed
+245
-16
No files matched your search
@@ -149,6 +149,29 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
bool g_rx_boost = false;
|
||||
bool g_rx_boost_set_ok = true;
|
||||
int g_rx_boost_sets = 0;
|
||||
bool fakeSetRxBoost(bool en) {
|
||||
g_rx_boost_sets++;
|
||||
if (!g_rx_boost_set_ok) return false;
|
||||
g_rx_boost = en;
|
||||
return true;
|
||||
}
|
||||
bool fakeGetRxBoost() { return g_rx_boost; }
|
||||
|
||||
KissModem* g_poll_modem = nullptr;
|
||||
bool g_poll_has_packet = false;
|
||||
int g_polls = 0;
|
||||
void fakePollRx() {
|
||||
g_polls++;
|
||||
if (g_poll_has_packet && g_poll_modem) {
|
||||
static constexpr uint8_t PKT[] = {0x55};
|
||||
g_poll_has_packet = false;
|
||||
g_poll_modem->onPacketReceived(4, -80, PKT, sizeof(PKT));
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<uint8_t> ERR_UNSUPPORTED = {HW_RESP_ERROR, HW_ERR_UNSUPPORTED};
|
||||
|
||||
TEST_F(KissHwControlTest, VersionIsTwo) {
|
||||
@@ -342,4 +365,93 @@ TEST_F(KissHwControlTest, ImmediateFemReplySurvivesHostBackpressure) {
|
||||
EXPECT_EQ(board.lna_sets, 1);
|
||||
}
|
||||
|
||||
class KissRxBoostTest : public KissHwControlTest {
|
||||
protected:
|
||||
KissRxBoostTest() {
|
||||
g_rx_boost = true;
|
||||
g_rx_boost_set_ok = true;
|
||||
g_rx_boost_sets = 0;
|
||||
modem.setRxBoostedGainCallbacks(fakeSetRxBoost, fakeGetRxBoost);
|
||||
g_poll_modem = &modem;
|
||||
g_poll_has_packet = false;
|
||||
g_polls = 0;
|
||||
modem.setPollRxCallback(fakePollRx);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(KissHwControlTest, RxBoostedGainUnsupportedWithoutCallbacks) {
|
||||
EXPECT_EQ(hw1({HW_CMD_GET_RX_BOOSTED_GAIN}), ERR_UNSUPPORTED);
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 1}), ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, CapabilityAdvertised) {
|
||||
EXPECT_EQ(hw1({HW_CMD_GET_CAPABILITIES}), (std::vector<uint8_t>{0x9B, 0x09, 0x00, 0x00, 0x00}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, GetReportsCurrentState) {
|
||||
EXPECT_EQ(hw1({HW_CMD_GET_RX_BOOSTED_GAIN}), (std::vector<uint8_t>{0xA1, 0x01}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetRepliesWithEffectiveState) {
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 0}), (std::vector<uint8_t>{0xA1, 0x00}));
|
||||
EXPECT_FALSE(g_rx_boost);
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 0x7F}), (std::vector<uint8_t>{0xA1, 0x01}));
|
||||
EXPECT_TRUE(g_rx_boost);
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetFailureRepliesWithUnchangedState) {
|
||||
g_rx_boost_set_ok = false;
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 0}), (std::vector<uint8_t>{0xA1, 0x01}));
|
||||
EXPECT_TRUE(g_rx_boost);
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetDuringTxIsRejectedWithoutTouchingRadio) {
|
||||
startTxAndHold();
|
||||
serial.takeHardwareFrames();
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN, 0}), (std::vector<uint8_t>{HW_RESP_ERROR, HW_ERR_TX_BUSY}));
|
||||
EXPECT_EQ(g_rx_boost_sets, 0);
|
||||
EXPECT_EQ(hw1({HW_CMD_GET_RX_BOOSTED_GAIN}), (std::vector<uint8_t>{0xA1, 0x01}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetShortPayloadIsInvalidLength) {
|
||||
EXPECT_EQ(hw1({HW_CMD_SET_RX_BOOSTED_GAIN}), (std::vector<uint8_t>{HW_RESP_ERROR, HW_ERR_INVALID_LENGTH}));
|
||||
EXPECT_EQ(g_rx_boost_sets, 0);
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, CompletedRxPacketIsDeliveredBeforeGainChange) {
|
||||
g_poll_has_packet = true;
|
||||
auto frames = hw({HW_CMD_SET_RX_BOOSTED_GAIN, 0});
|
||||
EXPECT_EQ(g_polls, 1);
|
||||
EXPECT_FALSE(g_rx_boost);
|
||||
ASSERT_EQ(frames.size(), 2U); // RxMeta for the drained packet, then the gain reply
|
||||
EXPECT_EQ(frames[0][0], HW_RESP_RX_META);
|
||||
EXPECT_EQ(frames[1], (std::vector<uint8_t>{0xA1, 0x00}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, NoRoomForReplyAfterDrainChangesNothing) {
|
||||
serial.blocked = true;
|
||||
g_poll_has_packet = true; // data + meta fill both output slots
|
||||
serial.pushRx({KISS_FEND, KISS_CMD_SETHARDWARE, HW_CMD_SET_RX_BOOSTED_GAIN, 0, KISS_FEND});
|
||||
modem.loop();
|
||||
EXPECT_EQ(g_rx_boost_sets, 0);
|
||||
EXPECT_TRUE(g_rx_boost);
|
||||
|
||||
serial.blocked = false;
|
||||
for (int i = 0; i < 5; i++) modem.loop();
|
||||
auto frames = serial.takeHardwareFrames();
|
||||
ASSERT_EQ(frames.size(), 2U);
|
||||
EXPECT_EQ(frames[0][0], HW_RESP_RX_META);
|
||||
EXPECT_EQ(frames[1], (std::vector<uint8_t>{HW_RESP_ERROR, HW_ERR_TX_BUSY}));
|
||||
}
|
||||
|
||||
TEST_F(KissRxBoostTest, SetWhileHostOutputBackedUpIsRejected) {
|
||||
serial.blocked = true;
|
||||
static constexpr uint8_t PKT[] = {0x01};
|
||||
modem.onPacketReceived(0, 0, PKT, sizeof(PKT));
|
||||
serial.pushRx({KISS_FEND, KISS_CMD_SETHARDWARE, HW_CMD_SET_RX_BOOSTED_GAIN, 0, KISS_FEND});
|
||||
modem.loop();
|
||||
EXPECT_EQ(g_polls, 0);
|
||||
EXPECT_EQ(g_rx_boost_sets, 0);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in new issue
Block a user