Exemple #1
0
/*********************************************************************
 * @fn      osalAdjustTimer
 *
 * @brief   Updates the OSAL Clock and Timer with elapsed milliseconds.
 *
 * @param   MSec - elapsed milliseconds
 *
 * @return  none
 */
void osalAdjustTimer(uint32 Msec )
{
  /* Disable SysTick interrupts */ 
  SysTickIntDisable(); 
  
  osalClockUpdate(Msec);
  osalTimerUpdate(Msec);
  
  /* Enable SysTick interrupts */ 
  SysTickIntEnable(); 
}
/*********************************************************************
 * @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 ticks625us;
  uint16 elapsedMSec = 0;

  // Get the free-running count of 625us timer ticks
  tmp = ll_McuPrecisionCount();


 

  if ( tmp != previousLLTimerTick )
  {
    // Calculate the elapsed ticks of the free-running timer.
    ticks625us = tmp - previousLLTimerTick;

    // Store the LL Timer tick count for the next time through this function.
    previousLLTimerTick = tmp;

    /* It is necessary to loop to convert the usecs to msecs in increments so as
     * not to overflow the 16-bit variables.
     */
    while ( ticks625us > MAXCALCTICKS )
    {
      ticks625us -= MAXCALCTICKS;
      elapsedMSec += MAXCALCTICKS * 5 / 8;
      remUsTicks += MAXCALCTICKS * 5 % 8;
    }

    // update converted number with remaining ticks from loop and the
    // accumulated remainder from loop
    tmp = (ticks625us * 5) + remUsTicks;

    // Convert the 625 us ticks into milliseconds and a remainder
    elapsedMSec += tmp / 8;
    remUsTicks = tmp % 8;

    // Update OSAL Clock and Timers
    if ( elapsedMSec )
    {
      osalClockUpdate( elapsedMSec );

      

      osalTimerUpdate( elapsedMSec );
    }
  }
}
Exemple #3
0
/*********************************************************************
 * @fn      osalTimeUpdate
 *
 * @brief   Uses the free running rollover count of the ZAP timer.
 *          This function is intended to be invoked from the background, not interrupt level.
 *
 * @param   None.
 *
 * @return  None.
 */
void osalTimeUpdate(void)
{
  uint16 tmp = halBrdTmrTick;

  if (tmp != halBrdTmrTickShdw)
  {
    // Calculate the elapsed ticks of the free-running timer.
    uint16 elapsedMSec = tmp - halBrdTmrTickShdw;
  
    // Store the ZAP Timer tick count for the next time through this function.
    halBrdTmrTickShdw = tmp;
  
    osalTimerUpdate(elapsedMSec);
    osalClockUpdate(elapsedMSec);
  }
}
Exemple #4
0
/*********************************************************************
 * @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 );
    	}
  	}
}