Skip to content

Commit 64e872d

Browse files
authored
Merge pull request ExpressLRS#3353 from pkendall64/desync+optmised-tx
Optimised TX + Continuous mode RX
2 parents 788dd8d + 17819b4 commit 64e872d

File tree

12 files changed

+146
-314
lines changed

12 files changed

+146
-314
lines changed

src/lib/LBT/LBT.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "common.h"
33
#include "logging.h"
44
#include "LBT.h"
5+
#include "POWERMGNT.h"
56
#include "config.h"
67

78
LQCALC<100> LBTSuccessCalc;
@@ -11,10 +12,10 @@ static uint32_t rxStartTime;
1112
#define LBT_RSSI_THRESHOLD_OFFSET_DB 0
1213
#endif
1314

14-
static bool LBTEnabled = false;
15+
bool LbtIsEnabled = false;
1516
static uint32_t validRSSIdelayUs = 0;
1617

17-
static uint32_t ICACHE_RAM_ATTR SpreadingFactorToRSSIvalidDelayUs(uint8_t SF, uint8_t radio_type)
18+
static uint32_t SpreadingFactorToRSSIvalidDelayUs(uint8_t SF, uint8_t radio_type)
1819
{
1920
#if defined(RADIO_LR1121)
2021
if (radio_type == RADIO_TYPE_LR1121_LORA_2G4 || radio_type == RADIO_TYPE_LR1121_LORA_DUAL)
@@ -30,7 +31,7 @@ static uint32_t ICACHE_RAM_ATTR SpreadingFactorToRSSIvalidDelayUs(uint8_t SF, ui
3031
}
3132
if (radio_type == RADIO_TYPE_LR1121_GFSK_2G4)
3233
{
33-
return 20; // 20us settling time (seems fine when testing)
34+
return 40; // 40us settling time; documentation says Twait for 467 kHz bandwidth is 30.68us
3435
}
3536
#elif defined(RADIO_SX128X)
3637
// The necessary wait time from RX start to valid instant RSSI reading
@@ -66,15 +67,14 @@ static uint32_t ICACHE_RAM_ATTR SpreadingFactorToRSSIvalidDelayUs(uint8_t SF, ui
6667
return 60 + 20; // switching time (60us) + 20us settling time (seems fine when testing)
6768
}
6869
#endif
69-
ERRLN("LBT not supported on this radio type");
7070
return 0;
7171
}
7272

73-
void EnableLBT()
73+
void LbtEnableIfRequired()
7474
{
75-
LBTEnabled = config.GetPower() > PWR_10mW;
75+
LbtIsEnabled = config.GetPower() > PWR_10mW;
7676
#if defined(RADIO_LR1121)
77-
LBTEnabled = LBTEnabled && (ExpressLRS_currAirRate_Modparams->radio_type == RADIO_TYPE_LR1121_LORA_2G4 || ExpressLRS_currAirRate_Modparams->radio_type == RADIO_TYPE_LR1121_GFSK_2G4 || ExpressLRS_currAirRate_Modparams->radio_type == RADIO_TYPE_LR1121_LORA_DUAL);
77+
LbtIsEnabled = LbtIsEnabled && (ExpressLRS_currAirRate_Modparams->radio_type == RADIO_TYPE_LR1121_LORA_2G4 || ExpressLRS_currAirRate_Modparams->radio_type == RADIO_TYPE_LR1121_GFSK_2G4 || ExpressLRS_currAirRate_Modparams->radio_type == RADIO_TYPE_LR1121_LORA_DUAL);
7878
#endif
7979
validRSSIdelayUs = SpreadingFactorToRSSIvalidDelayUs(ExpressLRS_currAirRate_Modparams->sf, ExpressLRS_currAirRate_Modparams->radio_type);
8080
}
@@ -138,36 +138,25 @@ static int8_t ICACHE_RAM_ATTR PowerEnumToLBTLimit(PowerLevels_e txPower, uint8_t
138138
}
139139
}
140140
#endif
141-
ERRLN("LBT not supported on this radio type");
142141
return 0;
143142
}
144143

145-
void ICACHE_RAM_ATTR SetClearChannelAssessmentTime(void)
144+
void ICACHE_RAM_ATTR LbtCcaTimerStart(void)
146145
{
147-
if (!LBTEnabled)
146+
if (!LbtIsEnabled)
148147
return;
149148

150-
#if defined(TARGET_TX)
151-
#if defined(RADIO_LR1121)
152-
Radio.RXnb(LR1121_MODE_RX, validRSSIdelayUs);
153-
#elif defined(RADIO_SX128X)
154-
Radio.RXnb(SX1280_MODE_RX, validRSSIdelayUs);
155-
#else
156-
#error No continuous receive mode defined for this radio type
157-
#endif
158-
#endif
159-
160149
rxStartTime = micros();
161150
}
162151

163-
SX12XX_Radio_Number_t ICACHE_RAM_ATTR ChannelIsClear(SX12XX_Radio_Number_t radioNumber)
152+
SX12XX_Radio_Number_t ICACHE_RAM_ATTR LbtChannelIsClear(SX12XX_Radio_Number_t radioNumber)
164153
{
165154
if (radioNumber == SX12XX_Radio_NONE)
166155
return SX12XX_Radio_NONE;
167156

168157
LBTSuccessCalc.inc(); // Increment count for every channel check
169158

170-
if (!LBTEnabled)
159+
if (!LbtIsEnabled)
171160
{
172161
LBTSuccessCalc.add();
173162
return radioNumber;
@@ -218,7 +207,7 @@ SX12XX_Radio_Number_t ICACHE_RAM_ATTR ChannelIsClear(SX12XX_Radio_Number_t radio
218207
if (radioNumber & SX12XX_Radio_2)
219208
{
220209
rssiInst2 = Radio.GetRssiInst(SX12XX_Radio_2);
221-
210+
222211
if(rssiInst2 < rssiCutOff)
223212
{
224213
clearChannelsMask |= SX12XX_Radio_2;

src/lib/LBT/LBT.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
#if defined(Regulatory_Domain_EU_CE_2400)
21
#pragma once
2+
#include "SX12xxDriverCommon.h"
33

4-
#include "POWERMGNT.h"
4+
#if defined(Regulatory_Domain_EU_CE_2400)
55
#include "LQCALC.h"
6-
#include "SX12xxDriverCommon.h"
76

87
extern LQCALC<100> LBTSuccessCalc;
8+
extern bool LbtIsEnabled;
99

10-
void EnableLBT();
11-
void ICACHE_RAM_ATTR SetClearChannelAssessmentTime(void);
12-
SX12XX_Radio_Number_t ICACHE_RAM_ATTR ChannelIsClear(SX12XX_Radio_Number_t radioNumber);
10+
void LbtEnableIfRequired();
11+
void ICACHE_RAM_ATTR LbtCcaTimerStart();
12+
SX12XX_Radio_Number_t ICACHE_RAM_ATTR LbtChannelIsClear(SX12XX_Radio_Number_t radioNumber);
1313
#else
14-
inline void EnableLBT() {}
14+
static constexpr bool LbtIsEnabled = false;
15+
static inline void LbtEnableIfRequired() {}
16+
static inline void LbtCcaTimerStart() {}
17+
static inline SX12XX_Radio_Number_t LbtChannelIsClear(SX12XX_Radio_Number_t radioNumber) { return radioNumber; }
1518
#endif

src/lib/LR1121Driver/LR1121.cpp

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ static uint32_t beginTX;
1818
static uint32_t endTX;
1919
#endif
2020

21-
// RxTimeout is expressed in periods of the 32.768kHz RTC
22-
#define RX_TIMEOUT_PERIOD_BASE_NANOS 1000000000 / 32768 // TODO check for LR1121
23-
2421
LR1121Driver::LR1121Driver(): SX12xxDriverCommon()
2522
{
2623
useFSK = false;
2724
instance = this;
28-
timeout = 0xFFFFFF;
2925
lastSuccessfulPacketRadio = SX12XX_Radio_1;
3026
fallBackMode = LR1121_MODE_FS;
3127
useFEC = false;
@@ -131,12 +127,12 @@ transitioning from FS mode and the other from Standby mode. This causes the tx d
131127
void LR1121Driver::startCWTest(uint32_t freq, SX12XX_Radio_Number_t radioNumber)
132128
{
133129
// Set a basic Config that can be used for both 2.4G and SubGHz bands.
134-
Config(LR11XX_RADIO_LORA_BW_62, LR11XX_RADIO_LORA_SF6, LR11XX_RADIO_LORA_CR_4_8, freq, 12, false, 8, 0, false, 0, 0, radioNumber);
130+
Config(LR11XX_RADIO_LORA_BW_62, LR11XX_RADIO_LORA_SF6, LR11XX_RADIO_LORA_CR_4_8, freq, 12, false, 8, false, 0, 0, radioNumber);
135131
hal.WriteCommand(LR11XX_RADIO_SET_TX_CW_OC, radioNumber);
136132
}
137133

138134
void LR1121Driver::Config(uint8_t bw, uint8_t sf, uint8_t cr, uint32_t regfreq,
139-
uint8_t PreambleLength, bool InvertIQ, uint8_t _PayloadLength, uint32_t rxtimeout,
135+
uint8_t PreambleLength, bool InvertIQ, uint8_t _PayloadLength,
140136
bool setFSKModulation, uint8_t fskSyncWord1, uint8_t fskSyncWord2,
141137
SX12XX_Radio_Number_t radioNumber)
142138
{
@@ -158,8 +154,6 @@ void LR1121Driver::Config(uint8_t bw, uint8_t sf, uint8_t cr, uint32_t regfreq,
158154
inverted = LR11XX_RADIO_LORA_IQ_STANDARD;
159155
}
160156

161-
SetRxTimeoutUs(rxtimeout);
162-
163157
SetMode(LR1121_MODE_STDBY_RC, radioNumber);
164158

165159
useFSK = setFSKModulation;
@@ -201,7 +195,7 @@ void LR1121Driver::Config(uint8_t bw, uint8_t sf, uint8_t cr, uint32_t regfreq,
201195
SetPacketParamsLoRa(PreambleLength, packetLengthType, PayloadLength, inverted, radioNumber);
202196
}
203197

204-
SetFrequencyHz(regfreq, radioNumber);
198+
SetFrequencyReg(regfreq, radioNumber, false);
205199

206200
ClearIrqStatus(radioNumber);
207201

@@ -282,15 +276,6 @@ void LR1121Driver::SetDioAsRfSwitch()
282276
hal.WriteCommand(LR11XX_SYSTEM_SET_DIO_AS_RF_SWITCH_OC, switchbuf, sizeof(switchbuf), SX12XX_Radio_All);
283277
}
284278

285-
void LR1121Driver::SetRxTimeoutUs(uint32_t interval)
286-
{
287-
timeout = 0xFFFFFF; // no timeout, continuous mode
288-
if (interval)
289-
{
290-
timeout = interval * 1000 / RX_TIMEOUT_PERIOD_BASE_NANOS;
291-
}
292-
}
293-
294279
void LR1121Driver::CorrectRegisterForSF6(uint8_t sf, SX12XX_Radio_Number_t radioNumber)
295280
{
296281
// 8.3.1 SetModulationParams
@@ -431,10 +416,9 @@ void ICACHE_RAM_ATTR LR1121Driver::SetPaConfig(bool isSubGHz, SX12XX_Radio_Numbe
431416
hal.WriteCommand(LR11XX_RADIO_SET_PA_CFG_OC, Pabuf, sizeof(Pabuf), radioNumber);
432417
}
433418

434-
void LR1121Driver::SetMode(lr11xx_RadioOperatingModes_t OPmode, SX12XX_Radio_Number_t radioNumber, uint32_t incomingTimeout)
419+
void LR1121Driver::SetMode(lr11xx_RadioOperatingModes_t OPmode, SX12XX_Radio_Number_t radioNumber)
435420
{
436421
WORD_ALIGNED_ATTR uint8_t buf[5] = {0};
437-
uint32_t tempTimeout;
438422

439423
switch (OPmode)
440424
{
@@ -460,20 +444,6 @@ void LR1121Driver::SetMode(lr11xx_RadioOperatingModes_t OPmode, SX12XX_Radio_Num
460444
hal.WriteCommand(LR11XX_SYSTEM_SET_FS_OC, radioNumber);
461445
break;
462446

463-
case LR1121_MODE_RX:
464-
// 7.2.2 SetRx
465-
tempTimeout = incomingTimeout ? (incomingTimeout * 1000 / RX_TIMEOUT_PERIOD_BASE_NANOS) : timeout;
466-
467-
// incomingTimeout is below the minimum period so lets set it to 1.
468-
if (incomingTimeout && !tempTimeout)
469-
tempTimeout = 1;
470-
471-
buf[0] = tempTimeout >> 16;
472-
buf[1] = tempTimeout >> 8;
473-
buf[2] = tempTimeout & 0xFF;
474-
hal.WriteCommand(LR11XX_RADIO_SET_RX_OC, buf, 3, radioNumber);
475-
break;
476-
477447
case LR1121_MODE_RX_CONT:
478448
// 7.2.2 SetRx
479449
buf[0] = 0xFF;
@@ -529,24 +499,31 @@ void LR1121Driver::SetPacketParamsLoRa(uint8_t PreambleLength, lr11xx_RadioLoRaP
529499
hal.WriteCommand(LR11XX_RADIO_SET_PKT_PARAM_OC, buf, sizeof(buf), radioNumber);
530500
}
531501

532-
void ICACHE_RAM_ATTR LR1121Driver::SetFrequencyHz(uint32_t freq, SX12XX_Radio_Number_t radioNumber)
502+
void ICACHE_RAM_ATTR LR1121Driver::SetFrequencyReg(uint32_t freq, SX12XX_Radio_Number_t radioNumber, bool doRx, uint32_t rxTime)
533503
{
534-
// 7.2.1 SetRfFrequency
535-
uint8_t buf[4];
536-
buf[0] = freq >> 24;
537-
buf[1] = freq >> 16;
538-
buf[2] = freq >> 8;
539-
buf[3] = freq & 0xFF;
540-
hal.WriteCommand(LR11XX_RADIO_SET_RF_FREQUENCY_OC, buf, sizeof(buf), radioNumber);
504+
uint8_t buf[7] = {
505+
(uint8_t)(freq >> 24),
506+
(uint8_t)(freq >> 16),
507+
(uint8_t)(freq >> 8),
508+
(uint8_t)(freq),
509+
0xFF,
510+
0xFF,
511+
0xFF,
512+
};
513+
if (doRx)
514+
{
515+
// SetRfFrequency_SetRX
516+
hal.WriteCommand(LR11XX_RADIO_SET_FREQ_SET_RX, buf, sizeof(buf), radioNumber);
517+
}
518+
else
519+
{
520+
// 7.2.1 SetRfFrequency
521+
hal.WriteCommand(LR11XX_RADIO_SET_RF_FREQUENCY_OC, buf, 4, radioNumber);
522+
}
541523

542524
currFreq = freq;
543525
}
544526

545-
void ICACHE_RAM_ATTR LR1121Driver::SetFrequencyReg(uint32_t freq, SX12XX_Radio_Number_t radioNumber)
546-
{
547-
SetFrequencyHz(freq, radioNumber);
548-
}
549-
550527
// 4.1.1 SetDioIrqParams
551528
void LR1121Driver::SetDioIrqParams()
552529
{
@@ -720,9 +697,9 @@ bool ICACHE_RAM_ATTR LR1121Driver::RXnbISR(SX12XX_Radio_Number_t radioNumber)
720697
return true;
721698
}
722699

723-
void ICACHE_RAM_ATTR LR1121Driver::RXnb(lr11xx_RadioOperatingModes_t rxMode, uint32_t incomingTimeout)
700+
void ICACHE_RAM_ATTR LR1121Driver::RXnb()
724701
{
725-
SetMode(rxMode, SX12XX_Radio_All, incomingTimeout);
702+
SetMode(LR1121_MODE_RX_CONT, SX12XX_Radio_All);
726703
}
727704

728705
bool ICACHE_RAM_ATTR LR1121Driver::GetFrequencyErrorbool(SX12XX_Radio_Number_t radioNumber)

src/lib/LR1121Driver/LR1121.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,15 @@ class LR1121Driver: public SX12xxDriverCommon
2222
public:
2323
static LR1121Driver *instance;
2424

25-
///////////Radio Variables////////
26-
uint32_t timeout;
27-
28-
///////////////////////////////////
29-
3025
////////////////Configuration Functions/////////////
3126
LR1121Driver();
3227
bool Begin(uint32_t minimumFrequency, uint32_t maximumFrequency);
3328
void End();
3429
void SetTxIdleMode() { SetMode(LR1121_MODE_FS, SX12XX_Radio_All); }; // set Idle mode used when switching from RX to TX
3530
void Config(uint8_t bw, uint8_t sf, uint8_t cr, uint32_t freq,
36-
uint8_t PreambleLength, bool InvertIQ, uint8_t PayloadLength, uint32_t rxtimeout, bool setFSKModulation,
31+
uint8_t PreambleLength, bool InvertIQ, uint8_t PayloadLength, bool setFSKModulation,
3732
uint8_t fskSyncWord1, uint8_t fskSyncWord2, SX12XX_Radio_Number_t radioNumber = SX12XX_Radio_All);
38-
void SetFrequencyHz(uint32_t freq, SX12XX_Radio_Number_t radioNumber);
39-
void SetFrequencyReg(uint32_t freq, SX12XX_Radio_Number_t radioNumber = SX12XX_Radio_All);
40-
void SetRxTimeoutUs(uint32_t interval);
33+
void SetFrequencyReg(uint32_t freq, SX12XX_Radio_Number_t radioNumber, bool doRx = false, uint32_t rxTime = 0);
4134
void SetOutputPower(int8_t power, bool isSubGHz = true);
4235
void startCWTest(uint32_t freq, SX12XX_Radio_Number_t radioNumber);
4336

@@ -47,7 +40,7 @@ class LR1121Driver: public SX12xxDriverCommon
4740
bool FrequencyErrorAvailable() const { return false; }
4841

4942
void TXnb(uint8_t *data, uint8_t size, bool sendGeminiBuffer, uint8_t * dataGemini, SX12XX_Radio_Number_t radioNumber);
50-
void RXnb(lr11xx_RadioOperatingModes_t rxMode = LR1121_MODE_RX, uint32_t incomingTimeout = 0);
43+
void RXnb();
5144

5245
uint32_t GetIrqStatus(SX12XX_Radio_Number_t radioNumber);
5346
void ClearIrqStatus(SX12XX_Radio_Number_t radioNumber);
@@ -86,7 +79,7 @@ class LR1121Driver: public SX12xxDriverCommon
8679

8780
bool CheckVersion(SX12XX_Radio_Number_t radioNumber);
8881

89-
void SetMode(lr11xx_RadioOperatingModes_t OPmode, SX12XX_Radio_Number_t radioNumber, uint32_t incomingTimeout = 0);
82+
void SetMode(lr11xx_RadioOperatingModes_t OPmode, SX12XX_Radio_Number_t radioNumber);
9083

9184
// LoRa functions
9285
void ConfigModParamsLoRa(uint8_t bw, uint8_t sf, uint8_t cr, SX12XX_Radio_Number_t radioNumber);

src/lib/LR1121Driver/LR1121_Regs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ typedef enum
8383
LR1121_MODE_STDBY_RC, //! The radio is in standby mode with RC oscillator
8484
LR1121_MODE_STDBY_XOSC, //! The radio is in standby mode with XOSC oscillator
8585
LR1121_MODE_FS, //! The radio is in frequency synthesis mode
86-
LR1121_MODE_RX, //! The radio is in receive mode
8786
LR1121_MODE_RX_CONT, //! The radio is in continuous receive mode
8887
LR1121_MODE_TX, //! The radio is in transmit mode
8988
LR1121_MODE_CAD //! The radio is in channel activity detection mode

0 commit comments

Comments
 (0)