/************************************************************************* * * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file Timers.c * * @date 25-Sep-2019 * @author S. Nash * * @brief Timers service module. Provides miscellaneous timer functions. * *************************************************************************/ #include "Common.h" #include "Timers.h" // ********** private definitions ********** // ********** private data ********** static U32 msTimerCount = 0; /************************************************************************* * @brief initTimers * The initTimers function initializes the Timers module. * @details * Inputs : none * Outputs : Timers module initialized. * @param none * @return none *************************************************************************/ void initTimers( void ) { msTimerCount = 0; } /************************************************************************* * @brief incMSTimerCount * The incMSTimerCount function increments the ms timer count. * @details * Inputs : none * Outputs : msTimerCount incremented * @param none * @return none *************************************************************************/ void incMSTimerCount( void ) { msTimerCount++; } /************************************************************************* * @brief getMSTimerCount * The getMSTimerCount function returns the current ms timer count. * @details * Inputs : msTimerCount * Outputs : none * @param none * @return msTimerCount *************************************************************************/ U32 getMSTimerCount( void ) { return msTimerCount; } /************************************************************************* * @brief didTimeout * The didTimeout function determines whether a timeout has occurred between \n * a given start count and a given timeout period (in ms). * @details * Inputs : msTimerCount * Outputs : none * @param startMSCount : the ms count at the start of the timeout period * @param timeoutPeriod : the period for the timeout (in ms) * @return TRUE if a timeout has occurred, FALSE if not *************************************************************************/ BOOL didTimeout( U32 startMSCount, U32 timeoutPeriod ) { BOOL result = FALSE; U32 currMSCount = msTimerCount; // no wrap if ( currMSCount >= startMSCount ) { if ( ( currMSCount - startMSCount ) >= timeoutPeriod ) { result = TRUE; } } // counter wrapped else { U32 deltaMSCount = ( 0xFFFFFFFF - startMSCount ) + currMSCount + 1; if ( deltaMSCount >= timeoutPeriod ) { result = TRUE; } } return result; }