Skip to content

Commit ae0e452

Browse files
committed
Added SX126x REG_RX_GAIN and REG_TX_MODULATION to the radio registers retention list
Implemented the API to add a register to the radio retention list
1 parent d9ebdae commit ae0e452

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/radio/sx126x/radio.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,13 @@ void RadioRxBoosted( uint32_t timeout );
336336
*/
337337
void RadioSetRxDutyCycle( uint32_t rxTime, uint32_t sleepTime );
338338

339+
/*!
340+
* \brief Add a register to the retention list
341+
*
342+
* \param [in] registerAddress The address of the register to be kept in retention
343+
*/
344+
void RadioAddRegisterToRetentionList( uint16_t registerAddress );
345+
339346
/*!
340347
* Radio driver structure initialization
341348
*/
@@ -522,6 +529,10 @@ void RadioInit( RadioEvents_t *events )
522529
SX126xSetTxParams( 0, RADIO_RAMP_200_US );
523530
SX126xSetDioIrqParams( IRQ_RADIO_ALL, IRQ_RADIO_ALL, IRQ_RADIO_NONE, IRQ_RADIO_NONE );
524531

532+
// Add registers to the retention list (4 is the maximum possible number)
533+
RadioAddRegisterToRetentionList( REG_RX_GAIN );
534+
RadioAddRegisterToRetentionList( REG_TX_MODULATION );
535+
525536
// Initialize driver timeout timers
526537
TimerInit( &TxTimeoutTimer, RadioOnTxTimeoutIrq );
527538
TimerInit( &RxTimeoutTimer, RadioOnRxTimeoutIrq );
@@ -1101,6 +1112,36 @@ void RadioSetRxDutyCycle( uint32_t rxTime, uint32_t sleepTime )
11011112
SX126xSetRxDutyCycle( rxTime, sleepTime );
11021113
}
11031114

1115+
void RadioAddRegisterToRetentionList( uint16_t registerAddress )
1116+
{
1117+
uint8_t buffer[9];
1118+
1119+
// Read the address and registers already added to the list
1120+
SX126xReadRegisters( REG_RETENTION_LIST_BASE_ADDRESS, buffer, 9 );
1121+
1122+
const uint8_t nbOfRegisters = buffer[0];
1123+
uint8_t* registerList = &buffer[1];
1124+
1125+
// Check if the register given as parameter is already added to the list
1126+
for( uint8_t i = 0; i < nbOfRegisters; i++ )
1127+
{
1128+
if( registerAddress == ( ( uint16_t ) registerList[2 * i] << 8 ) + registerList[2 * i + 1] )
1129+
{
1130+
return;
1131+
}
1132+
}
1133+
1134+
if( nbOfRegisters < MAX_NB_REG_IN_RETENTION )
1135+
{
1136+
buffer[0] += 1;
1137+
registerList[2 * nbOfRegisters] = ( uint8_t )( registerAddress >> 8 );
1138+
registerList[2 * nbOfRegisters + 1] = ( uint8_t )( registerAddress >> 0 );
1139+
1140+
// Update radio with modified list
1141+
SX126xWriteRegisters( REG_RETENTION_LIST_BASE_ADDRESS, buffer, 9 );
1142+
}
1143+
}
1144+
11041145
void RadioStartCad( void )
11051146
{
11061147
SX126xSetDioIrqParams( IRQ_CAD_DONE | IRQ_CAD_ACTIVITY_DETECTED, IRQ_CAD_DONE | IRQ_CAD_ACTIVITY_DETECTED, IRQ_RADIO_NONE, IRQ_RADIO_NONE );

0 commit comments

Comments
 (0)