Skip to content

Commit

Permalink
Added SX126x REG_RX_GAIN and REG_TX_MODULATION to the radio registers…
Browse files Browse the repository at this point in the history
… retention list

Implemented the API to add a register to the radio retention list
  • Loading branch information
mluis1 committed Mar 16, 2021
1 parent d9ebdae commit ae0e452
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/radio/sx126x/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit ae0e452

Please sign in to comment.