Commit 566e698c authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add fake counter driver for arch=posix

parent ebd3e289
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
#include <stdint.h>
#include <time.h>

class Counter {
	private:
		Counter(const Counter &copy);
		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;
+3 −0
Original line number Diff line number Diff line
#include "driver/counter.h"

Counter counter;