@@ -336,6 +336,13 @@ void RadioRxBoosted( uint32_t timeout );
336336 */
337337void 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+
11041145void 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