AnsweredAssumed Answered

I-CUBE-LRWAN V1.1.0 Why the -1 to Unsigned Cast?

Question asked by segal.ron on May 18, 2017
Latest reply on May 21, 2017 by Clive One

In I-CUBE-LRWAN V1.1.0 RegionCommon.c there's a function that returns the next duty cycle delay as follows:

 

TimerTime_t RegionCommonUpdateBandTimeOff( bool dutyCycle, Band_t* bands, uint8_t nbBands )
{
   TimerTime_t nextTxDelay = ( TimerTime_t )( -1 );

   // Update bands Time OFF
   for( uint8_t i = 0; i < nbBands; i++ )
   {
      if( dutyCycle == true )
      {
         if( bands[i].TimeOff <= TimerGetElapsedTime( bands[i].LastTxDoneTime ) )
         {

            bands[i].TimeOff = 0;
         }
         if( bands[i].TimeOff != 0 )
         {   
            nextTxDelay = MIN( bands[i].TimeOff - TimerGetElapsedTime( bands[i].LastTxDoneTime ),
            nextTxDelay );
         }
      }
      else
      {
         nextTxDelay = 0;
         bands[i].TimeOff = 0;
      }
   }
      return nextTxDelay;

}

This compares the period between the last transmission for the band and now with the duty cycle timeoff period, returning the next transmission delay period to comply with the duty cycle.

TimerTime_t is a 32 bit unsigned integer

So the first line TimerTime_t nextTxDelay = ( TimerTime_t )( -1 );

casts a signed to an unsigned integer, effectively setting it to a very large number 0xFFFFFFFF i.e. a huge delay.

So my question is, is that intentional?  If so, for what purpose, how does it work?  I would like to understand this code better.

Many thanks in advance, Ron.

Outcomes