From ae0e452eda1becc67c394d477a7aa11aac26535b Mon Sep 17 00:00:00 2001 From: Miguel Luis Date: Tue, 16 Mar 2021 09:55:52 +0100 Subject: [PATCH] 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 --- src/radio/sx126x/radio.c | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/radio/sx126x/radio.c b/src/radio/sx126x/radio.c index e31858978..8939e4320 100644 --- a/src/radio/sx126x/radio.c +++ b/src/radio/sx126x/radio.c @@ -336,6 +336,13 @@ void RadioRxBoosted( uint32_t timeout ); */ void RadioSetRxDutyCycle( uint32_t rxTime, uint32_t sleepTime ); +/*! + * \brief Add a register to the retention list + * + * \param [in] registerAddress The address of the register to be kept in retention + */ +void RadioAddRegisterToRetentionList( uint16_t registerAddress ); + /*! * Radio driver structure initialization */ @@ -522,6 +529,10 @@ void RadioInit( RadioEvents_t *events ) SX126xSetTxParams( 0, RADIO_RAMP_200_US ); SX126xSetDioIrqParams( IRQ_RADIO_ALL, IRQ_RADIO_ALL, IRQ_RADIO_NONE, IRQ_RADIO_NONE ); + // Add registers to the retention list (4 is the maximum possible number) + RadioAddRegisterToRetentionList( REG_RX_GAIN ); + RadioAddRegisterToRetentionList( REG_TX_MODULATION ); + // Initialize driver timeout timers TimerInit( &TxTimeoutTimer, RadioOnTxTimeoutIrq ); TimerInit( &RxTimeoutTimer, RadioOnRxTimeoutIrq ); @@ -1101,6 +1112,36 @@ void RadioSetRxDutyCycle( uint32_t rxTime, uint32_t sleepTime ) SX126xSetRxDutyCycle( rxTime, sleepTime ); } +void RadioAddRegisterToRetentionList( uint16_t registerAddress ) +{ + uint8_t buffer[9]; + + // Read the address and registers already added to the list + SX126xReadRegisters( REG_RETENTION_LIST_BASE_ADDRESS, buffer, 9 ); + + const uint8_t nbOfRegisters = buffer[0]; + uint8_t* registerList = &buffer[1]; + + // Check if the register given as parameter is already added to the list + for( uint8_t i = 0; i < nbOfRegisters; i++ ) + { + if( registerAddress == ( ( uint16_t ) registerList[2 * i] << 8 ) + registerList[2 * i + 1] ) + { + return; + } + } + + if( nbOfRegisters < MAX_NB_REG_IN_RETENTION ) + { + buffer[0] += 1; + registerList[2 * nbOfRegisters] = ( uint8_t )( registerAddress >> 8 ); + registerList[2 * nbOfRegisters + 1] = ( uint8_t )( registerAddress >> 0 ); + + // Update radio with modified list + SX126xWriteRegisters( REG_RETENTION_LIST_BASE_ADDRESS, buffer, 9 ); + } +} + void RadioStartCad( void ) { SX126xSetDioIrqParams( IRQ_CAD_DONE | IRQ_CAD_ACTIVITY_DETECTED, IRQ_CAD_DONE | IRQ_CAD_ACTIVITY_DETECTED, IRQ_RADIO_NONE, IRQ_RADIO_NONE );