2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
//( { file_desc:"Time cand clock related functions." kw: [ time system ] }
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// This interface is used to read the systems high resolution timer and
|
|
|
|
// calculate elapsed time.
|
|
|
|
//)
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef cwTime_H
|
|
|
|
#define cwTime_H
|
|
|
|
|
|
|
|
namespace cw
|
|
|
|
{
|
|
|
|
namespace time
|
|
|
|
{
|
|
|
|
|
|
|
|
//(
|
|
|
|
typedef struct timespec spec_t;
|
|
|
|
|
|
|
|
// Get the time
|
|
|
|
void get( spec_t& tRef );
|
2024-02-10 16:49:47 +00:00
|
|
|
spec_t current_time(); // same as get()
|
2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
// Return the elapsed time (t1 - t0) in microseconds
|
|
|
|
// t1 is assumed to be at a later time than t0.
|
2024-02-24 18:55:44 +00:00
|
|
|
unsigned long long elapsedMicros( const spec_t& t0, const spec_t& t1 );
|
|
|
|
unsigned long long elapsedMicros( const spec_t& t0 );
|
2019-12-24 15:05:24 +00:00
|
|
|
|
2020-02-01 15:13:21 +00:00
|
|
|
// Wrapper on elapsedMicros()
|
2020-04-17 15:16:21 +00:00
|
|
|
unsigned elapsedMs( const spec_t& t0, const spec_t& t1 );
|
2020-09-22 15:37:19 +00:00
|
|
|
unsigned elapsedMs( const spec_t& t0 );
|
2022-03-20 14:18:54 +00:00
|
|
|
|
|
|
|
// Wrapper on elapsedMicros()
|
|
|
|
double elapsedSecs( const spec_t& t0, const spec_t& t1 );
|
|
|
|
double elapsedSecs( const spec_t& t0 );
|
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
// Same as elapsedMicros() but the times are not assumed to be ordered.
|
|
|
|
// The function therefore begins by swapping t1 and t0 if t0 is after t1.
|
2020-04-17 15:16:21 +00:00
|
|
|
unsigned absElapsedMicros( const spec_t& t0, const spec_t& t1 );
|
2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Same as elapsedMicros() but returns a negative value if t0 is after t1.
|
2020-04-17 15:16:21 +00:00
|
|
|
int diffMicros( const spec_t& t0, const spec_t& t1 );
|
2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Returns true if t0 <= t1.
|
2020-04-17 15:16:21 +00:00
|
|
|
bool isLTE( const spec_t& t0, const spec_t& t1 );
|
2021-12-12 21:41:03 +00:00
|
|
|
|
|
|
|
// Returns true if t0 < t1.
|
|
|
|
bool isLT( const spec_t& t0, const spec_t& t1 );
|
2019-12-24 15:05:24 +00:00
|
|
|
|
|
|
|
// Return true if t0 >= t1.
|
2020-04-17 15:16:21 +00:00
|
|
|
bool isGTE( const spec_t& t0, const spec_t& t1 );
|
2021-12-12 21:41:03 +00:00
|
|
|
|
|
|
|
// Return true if t0 > t1.
|
|
|
|
bool isGT( const spec_t& t0, const spec_t& t1 );
|
2019-12-24 15:05:24 +00:00
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
bool isEqual( const spec_t& t0, const spec_t& t1 );
|
2019-12-24 15:05:24 +00:00
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
bool isZero( const spec_t& t0 );
|
2019-12-24 15:05:24 +00:00
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
void setZero( spec_t& t0 );
|
2019-12-24 15:05:24 +00:00
|
|
|
|
2024-02-10 16:49:47 +00:00
|
|
|
rc_t now( spec_t& ts ); // same as get()
|
2020-03-04 19:06:27 +00:00
|
|
|
|
2021-10-11 16:22:27 +00:00
|
|
|
void subtractMicros( spec_t& ts, unsigned us );
|
|
|
|
|
2023-01-14 22:15:55 +00:00
|
|
|
// Advance 'ts' by 'us/'ms' microseconds/milliseconds.
|
|
|
|
void advanceMicros( spec_t& ts, unsigned us );
|
2020-03-04 19:06:27 +00:00
|
|
|
void advanceMs( spec_t& ts, unsigned ms );
|
|
|
|
|
2020-04-17 15:16:21 +00:00
|
|
|
// Advance the current time by 'ms' milliseconds;
|
2020-03-04 19:06:27 +00:00
|
|
|
rc_t futureMs( spec_t& ts, unsigned ms );
|
|
|
|
|
2024-11-08 16:09:43 +00:00
|
|
|
void fracSecondsToSpec( spec_t& ts, double sec );
|
2021-10-11 16:22:27 +00:00
|
|
|
void secondsToSpec( spec_t& ts, unsigned sec );
|
2023-05-01 01:16:14 +00:00
|
|
|
double specToSeconds( const spec_t& ts );
|
|
|
|
|
2024-02-14 16:39:23 +00:00
|
|
|
unsigned long long specToMicroseconds( const spec_t& ts );
|
|
|
|
|
2021-10-11 16:22:27 +00:00
|
|
|
void millisecondsToSpec( spec_t& ts, unsigned ms );
|
2024-02-14 16:39:23 +00:00
|
|
|
void microsecondsToSpec( spec_t& ts, unsigned long long us );
|
|
|
|
spec_t microsecondsToSpec( unsigned long long us );
|
2021-10-11 16:22:27 +00:00
|
|
|
|
2023-05-20 01:21:03 +00:00
|
|
|
// Return count of bytes in in buf[]
|
|
|
|
unsigned formatDateTime( char* buf, unsigned bufN, bool includeDateFl=false );
|
|
|
|
|
2024-05-29 16:37:53 +00:00
|
|
|
rc_t test( const test::test_args_t& test );
|
2020-04-17 17:28:09 +00:00
|
|
|
|
2019-12-24 15:05:24 +00:00
|
|
|
//)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|