Skip to content

Commit 02eac20

Browse files
committed
Issue #935 - Updated behavior of SX126xSetLoRaSymbNumTimeout to round up the timeout to the nearest possible number of symbol.
1 parent acdf522 commit 02eac20

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/radio/sx126x/sx126x.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#include "sx126x.h"
2929
#include "sx126x-board.h"
3030

31+
/*!
32+
* \brief Maximum value for parameter symbNum in \ref SX126xSetLoRaSymbNumTimeout
33+
*/
34+
#define SX126X_MAX_LORA_SYMB_NUM_TIMEOUT 248
35+
3136
/*!
3237
* \brief Radio registers definition
3338
*/
@@ -326,23 +331,23 @@ void SX126xSetStopRxTimerOnPreambleDetect( bool enable )
326331

327332
void SX126xSetLoRaSymbNumTimeout( uint8_t symbNum )
328333
{
329-
SX126xWriteCommand( RADIO_SET_LORASYMBTIMEOUT, &symbNum, 1 );
334+
uint8_t mant = ( ( ( symbNum > SX126X_MAX_LORA_SYMB_NUM_TIMEOUT ) ?
335+
SX126X_MAX_LORA_SYMB_NUM_TIMEOUT :
336+
symbNum ) + 1 ) >> 1;
337+
uint8_t exp = 0;
338+
uint8_t reg = 0;
330339

331-
if( symbNum >= 64 )
340+
while( mant > 31 )
332341
{
333-
uint8_t mant = symbNum >> 1;
334-
uint8_t exp = 0;
335-
uint8_t reg = 0;
342+
mant = ( mant + 3 ) >> 2;
343+
exp++;
344+
}
336345

337-
while( mant > 31 )
338-
{
339-
mant >>= 2;
340-
exp++;
341-
}
346+
reg = mant << ( 2 * exp + 1 );
347+
SX126xWriteCommand( RADIO_SET_LORASYMBTIMEOUT, &reg, 1 );
342348

343-
reg = exp + ( mant << 3 );
344-
SX126xWriteRegister( REG_LR_SYNCH_TIMEOUT, reg );
345-
}
349+
reg = exp + ( mant << 3 );
350+
SX126xWriteRegister( REG_LR_SYNCH_TIMEOUT, reg );
346351
}
347352

348353
void SX126xSetRegulatorMode( RadioRegulatorMode_t mode )

0 commit comments

Comments
 (0)