| 1 | /*------------------------------------------------------------\ |
|---|
| 2 | | | |
|---|
| 3 | | Tool : systemcass | |
|---|
| 4 | | | |
|---|
| 5 | | File : sc_time.h | |
|---|
| 6 | | | |
|---|
| 7 | | Author : Buchmann Richard | |
|---|
| 8 | | | |
|---|
| 9 | | Date : 09_07_2004 | |
|---|
| 10 | | | |
|---|
| 11 | \------------------------------------------------------------*/ |
|---|
| 12 | #ifndef __SC_TIME_H__ |
|---|
| 13 | #define __SC_TIME_H__ |
|---|
| 14 | |
|---|
| 15 | #include <string> |
|---|
| 16 | #include <stdint.h> |
|---|
| 17 | |
|---|
| 18 | namespace sc_core { |
|---|
| 19 | |
|---|
| 20 | // ---------------------------------------------------------------------------- |
|---|
| 21 | // ENUM : sc_time_unit |
|---|
| 22 | // |
|---|
| 23 | // Enumeration of time units. |
|---|
| 24 | // ---------------------------------------------------------------------------- |
|---|
| 25 | |
|---|
| 26 | enum sc_time_unit |
|---|
| 27 | { |
|---|
| 28 | SC_FS = 0, |
|---|
| 29 | SC_PS, |
|---|
| 30 | SC_NS, |
|---|
| 31 | SC_US, |
|---|
| 32 | SC_MS, |
|---|
| 33 | SC_SEC |
|---|
| 34 | }; |
|---|
| 35 | |
|---|
| 36 | // |
|---|
| 37 | class sc_time; |
|---|
| 38 | extern const sc_time SC_ZERO_TIME; |
|---|
| 39 | extern sc_time SC_CURRENT_TIME; |
|---|
| 40 | |
|---|
| 41 | extern uint64_t nb_cycles; |
|---|
| 42 | |
|---|
| 43 | inline double sc_simulation_time() // in default time units |
|---|
| 44 | { |
|---|
| 45 | return (double)nb_cycles; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | const sc_time& sc_time_stamp (); |
|---|
| 49 | |
|---|
| 50 | // |
|---|
| 51 | class sc_time |
|---|
| 52 | { |
|---|
| 53 | friend const sc_time &sc_time_stamp (); |
|---|
| 54 | uint64_t time; |
|---|
| 55 | enum sc_time_unit unit; |
|---|
| 56 | public: |
|---|
| 57 | sc_time (double val, sc_time_unit tu); |
|---|
| 58 | sc_time (const sc_time& = SC_ZERO_TIME); |
|---|
| 59 | |
|---|
| 60 | sc_time& operator= (const sc_time &); |
|---|
| 61 | |
|---|
| 62 | uint64_t value () const { return time;} |
|---|
| 63 | inline double to_double () const; |
|---|
| 64 | inline double to_seconds() const; |
|---|
| 65 | inline operator double () const { return to_double ();} |
|---|
| 66 | const std::string to_string () const; |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | inline const sc_time& sc_time_stamp () // in default time units |
|---|
| 70 | { |
|---|
| 71 | SC_CURRENT_TIME.time = nb_cycles; |
|---|
| 72 | return SC_CURRENT_TIME;// = sc_time (nb_cycles, SC_NS); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | double |
|---|
| 76 | sc_time::to_double () const |
|---|
| 77 | { |
|---|
| 78 | double fact = 1; |
|---|
| 79 | switch(unit) { |
|---|
| 80 | case SC_FS: fact = 1e-6; break; |
|---|
| 81 | case SC_PS: fact = 1e-3; break; |
|---|
| 82 | case SC_NS: fact = 1; break; |
|---|
| 83 | case SC_US: fact = 1e3; break; |
|---|
| 84 | case SC_MS: fact = 1e6; break; |
|---|
| 85 | case SC_SEC: fact = 1e9; break; |
|---|
| 86 | } |
|---|
| 87 | return (double)time * fact; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | double |
|---|
| 91 | sc_time::to_seconds() const |
|---|
| 92 | { |
|---|
| 93 | double fact = 1; |
|---|
| 94 | switch(unit) { |
|---|
| 95 | case SC_FS: fact = 1e-15; break; |
|---|
| 96 | case SC_PS: fact = 1e-12; break; |
|---|
| 97 | case SC_NS: fact = 1e-9; break; |
|---|
| 98 | case SC_US: fact = 1e-6; break; |
|---|
| 99 | case SC_MS: fact = 1e-3; break; |
|---|
| 100 | case SC_SEC: fact = 1; break; |
|---|
| 101 | } |
|---|
| 102 | return (double)time * fact; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | } // end of namespace sc_core |
|---|
| 106 | |
|---|
| 107 | #endif /* __SC_TIME_H__ */ |
|---|