From 566e698caf23dc034335cfbb05641726ec4c273b Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 13 Dec 2018 14:24:34 +0100 Subject: add fake counter driver for arch=posix --- include/arch/posix/driver/counter.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 include/arch/posix/driver/counter.h (limited to 'include/arch/posix/driver') diff --git a/include/arch/posix/driver/counter.h b/include/arch/posix/driver/counter.h new file mode 100644 index 0000000..6390d14 --- /dev/null +++ b/include/arch/posix/driver/counter.h @@ -0,0 +1,31 @@ +#include +#include + +class Counter { + private: + Counter(const Counter ©); + uint64_t start_sec, start_nsec; + + public: + uint64_t value; + volatile uint8_t overflowed; + + Counter() : overflowed(0) {} + + inline void start() { + struct timespec ts; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); + start_sec = ts.tv_sec; + start_nsec = ts.tv_nsec; + } + + inline void stop() { + struct timespec ts; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); + + value = (ts.tv_sec - start_sec) * 1000000000UL; + value += ts.tv_nsec - start_nsec; + } +}; + +extern Counter counter; -- cgit v1.2.3