/* * TimingCore.h * * Created on: 13 May 2016 * Author: wentzelc */ #ifndef REDACORE_TIMINGCORE_H_ #define REDACORE_TIMINGCORE_H_ // Standard C/C++ Libraries #include #include #include // redA Libraries /* none */ //--------------------------------------------------------------------------- // Set interval (not for timer) inline void SetInterval( timeval * Time, long MilliSeconds ) { Time->tv_sec = MilliSeconds / 1000; Time->tv_usec = (MilliSeconds % 1000) * 1000; }; // Mark start time inline void SetStartTime( timeval *StartTime ) { gettimeofday( StartTime, NULL ); }; // Clear timer inline void ClearStartTime( timeval * StartTime ) { StartTime->tv_sec = 0; StartTime->tv_usec = 0; }; // Time passed since start time inline long TimePassed( timeval StartTime ) { timeval CurrTime; long Duration; gettimeofday( &CurrTime, NULL ); Duration = (CurrTime.tv_sec - StartTime.tv_sec) * (time_t)1000 + (CurrTime.tv_usec - StartTime.tv_usec) / (time_t)1000; if (Duration < 0) Duration = LONG_MAX; return Duration; }; // Time remaining from Start time to given time out inline long TimeLeft( timeval StartTime, long MilliSeconds ) { return (MilliSeconds - TimePassed(StartTime)); }; // Has give time expired after start time inline bool Timeout( timeval StartTime, long MilliSeconds ) { return ((TimePassed(StartTime) > MilliSeconds)? true : false); }; //--------------------------------------------------------------------------- #endif /* REDACORE_TIMINGCORE_H_ */