/********************************************************************* * @fn osalTimeUpdate * * @brief Uses the free running rollover count of the MAC backoff timer; * this timer runs freely with a constant 320 usec interval. The * count of 320-usec ticks is converted to msecs and used to update * the OSAL clock and Timers by invoking osalClockUpdate() and * osalTimerUpdate(). This function is intended to be invoked * from the background, not interrupt level. * * @param None. * * @return None. */ void osalTimeUpdate( void ) { uint16 tmp; uint16 ticks320us; uint16 elapsedMSec = 0; // Get the free-running count of 320us timer ticks tmp = macMcuPrecisionCount(); if ( tmp != previousMacTimerTick ) { // Calculate the elapsed ticks of the free-running timer. ticks320us = tmp - previousMacTimerTick; // Store the MAC Timer tick count for the next time through this function. previousMacTimerTick = tmp; /* It is necessary to loop to convert the usecs to msecs in increments so as * not to overflow the 16-bit variables. */ while ( ticks320us > MAXCALCTICKS ) { ticks320us -= MAXCALCTICKS; elapsedMSec += MAXCALCTICKS * 8 / 25; remUsTicks += MAXCALCTICKS * 8 % 25; } // update converted number with remaining ticks from loop and the // accumulated remainder from loop tmp = (ticks320us * 8) + remUsTicks; // Convert the 320 us ticks into milliseconds and a remainder elapsedMSec += tmp / 25; remUsTicks = tmp % 25; // Update OSAL Clock and Timers if ( elapsedMSec ) { osalClockUpdate( elapsedMSec ); osalTimerUpdate( elapsedMSec ); } } }
/********************************************************************* * @fn osalTimeUpdate * * @brief Uses the free running rollover count of the MAC backoff timer; * this timer runs freely with a constant 320 usec interval. The * count of 320-usec ticks is converted to msecs and used to update * the OSAL clock and Timers by invoking osalClockUpdate() and * osalTimerUpdate(). This function is intended to be invoked * from the background, not interrupt level. * * @param None. * * @return None. */ void osalTimeUpdate( void ){ halIntState_t intState; uint32 tmp; uint32 ticks320us; uint32 elapsedMSec = 0; HAL_ENTER_CRITICAL_SECTION(intState); // Get the free-running count of 320us timer ticks tmp = macMcuPrecisionCount(); HAL_EXIT_CRITICAL_SECTION(intState); if ( tmp != previousMacTimerTick ) { // Calculate the elapsed ticks of the free-running timer. ticks320us = (tmp - previousMacTimerTick) & 0xffffffffu; if (ticks320us >= TIMER_CLOCK_UPDATE ) { // Store the MAC Timer tick count for the next time through this function. previousMacTimerTick = tmp; /* * remUsTicks can have a maximum value of 24 (Since remusTicks got by mod * of 25). The value of COUNTER_TICK320US is a multiple of 25 and the * quotient of CONVERT_320US_TO_MS_ELAPSED_REMAINDER() does not exceed * 0xFFFF or 16 bit. */ while(ticks320us >= COUNTER_TICK320US) { ticks320us -= COUNTER_TICK320US; elapsedMSec += COUNTER_ELAPSEDMS; } // update converted number with remaining ticks from loop and the accumulated remainder from loop tmp = (ticks320us * 8) + remUsTicks; // Convert the 320 us ticks into milliseconds and a remainder CONVERT_320US_TO_MS_ELAPSED_REMAINDER( tmp, elapsedMSec, remUsTicks ); // Update OSAL Clock and Timers osalClockUpdate( elapsedMSec ); osalTimerUpdate( elapsedMSec ); } } }