00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __chronometer_h
00009 #define __chronometer_h
00010
00011 #include <system/config.h>
00012 #include <tsc.h>
00013 #include <rtc.h>
00014
00015 __BEGIN_SYS
00016
00017 class Chronometer
00018 {
00019 private:
00020 typedef Traits<Chronometer> Traits;
00021 static const Type_Id TYPE = Type<Chronometer>::TYPE;
00022
00023 typedef TSC::Hertz Hertz;
00024 typedef TSC::Time_Stamp Time_Stamp;
00025 typedef RTC::Microseconds Microseconds;
00026
00027 public:
00028
00029
00030 Chronometer() : _start(0), _stop(0) {}
00031 ~Chronometer() {}
00032
00033
00034
00035
00036 Hertz frequency() { return tsc.frequency(); }
00037
00038 void reset() { _start = 0; _stop = 0; }
00039 void start() { if(_start == 0) _start = tsc.time_stamp(); }
00040 void lap() { if(_start != 0) _stop = tsc.time_stamp(); }
00041 void stop() { lap(); }
00042
00043 Time_Stamp ticks() {
00044 if(_start == 0)
00045 return 0;
00046 if(_stop == 0)
00047 return tsc.time_stamp() - _start;
00048 return _stop - _start;
00049 }
00050 Microseconds read() { return ticks() * 1000000 / frequency(); }
00051
00052 static int init(System_Info *si);
00053
00054 private:
00055 TSC tsc;
00056 Time_Stamp _start;
00057 Time_Stamp _stop;
00058 };
00059
00060 __END_SYS
00061
00062 #endif