Index: firmware/App/Services/Timers.c =================================================================== diff -u -ra303cd4258157a8fbcbd8af4dd2bbaadec1a736c -rf068446fdb7889d320ddb6ffbd58f347ce0501e7 --- firmware/App/Services/Timers.c (.../Timers.c) (revision a303cd4258157a8fbcbd8af4dd2bbaadec1a736c) +++ firmware/App/Services/Timers.c (.../Timers.c) (revision f068446fdb7889d320ddb6ffbd58f347ce0501e7) @@ -23,7 +23,7 @@ static U32 msTimerCount = 0; /************************************************************************* - * @brief initTimers + * @brief * The initTimers function initializes the Timers module. * @details * Inputs : none @@ -37,7 +37,7 @@ } /************************************************************************* - * @brief incMSTimerCount + * @brief * The incMSTimerCount function increments the ms timer count. * @details * Inputs : none @@ -51,7 +51,7 @@ } /************************************************************************* - * @brief getMSTimerCount + * @brief * The getMSTimerCount function returns the current ms timer count. * @details * Inputs : msTimerCount @@ -65,7 +65,7 @@ } /************************************************************************* - * @brief didTimeout + * @brief * The didTimeout function determines whether a timeout has occurred between \n * a given start count and a given timeout period (in ms). * @details @@ -101,3 +101,60 @@ return result; } + +/************************************************************************* + * @brief + * The calcTimeSince function calculates the time (in ms) from a given start \n + * time until now. + * @details + * Inputs : msTimerCount + * Outputs : none + * @param startMSCount : the ms count at the start of the period + * @return ms since given start time + *************************************************************************/ +U32 calcTimeSince( U32 startMSCount ) +{ + U32 result; + U32 currMSCount = msTimerCount; + + // no wrap + if ( currMSCount >= startMSCount ) + { + result = currMSCount - startMSCount; + } + else + { + result = ( 0xFFFFFFFF - startMSCount ) + currMSCount + 1; + } + + return result; +} + +/************************************************************************* + * @brief + * The calcTimeBetween function calculates the time (in ms) from a given start \n + * time until a given end time. + * @details + * Inputs : none + * Outputs : none + * @param startMSCount : the ms count at the start of the period + * @param endMSCount : the ms count at the end of the period + * @return ms between two given times + *************************************************************************/ +U32 calcTimeBetween( U32 startMSCount, U32 endMSCount ) +{ + U32 result; + + // no wrap + if ( endMSCount >= startMSCount ) + { + result = endMSCount - startMSCount; + } + else + { + result = ( 0xFFFFFFFF - startMSCount ) + endMSCount + 1; + } + + return result; +} +