[1] | 1 | /*------------------------------------------------------------\ |
---|
| 2 | | | |
---|
| 3 | | Tool : systemcass | |
---|
| 4 | | | |
---|
| 5 | | File : sc_time.h | |
---|
| 6 | | | |
---|
| 7 | | Author : Buchmann Richard | |
---|
| 8 | | | |
---|
| 9 | | Date : 09_07_2004 | |
---|
| 10 | | | |
---|
| 11 | \------------------------------------------------------------*/ |
---|
[52] | 12 | |
---|
[1] | 13 | #ifndef __SC_TIME_H__ |
---|
| 14 | #define __SC_TIME_H__ |
---|
| 15 | |
---|
| 16 | #include <string> |
---|
[59] | 17 | //#include <stdint.h> |
---|
[1] | 18 | |
---|
[59] | 19 | #include "sc_nbdefs.h" |
---|
| 20 | |
---|
[1] | 21 | namespace sc_core { |
---|
| 22 | |
---|
[52] | 23 | |
---|
[1] | 24 | // ---------------------------------------------------------------------------- |
---|
| 25 | // ENUM : sc_time_unit |
---|
| 26 | // |
---|
| 27 | // Enumeration of time units. |
---|
| 28 | // ---------------------------------------------------------------------------- |
---|
| 29 | |
---|
[52] | 30 | enum sc_time_unit { |
---|
[1] | 31 | SC_FS = 0, |
---|
| 32 | SC_PS, |
---|
| 33 | SC_NS, |
---|
| 34 | SC_US, |
---|
| 35 | SC_MS, |
---|
| 36 | SC_SEC |
---|
| 37 | }; |
---|
| 38 | |
---|
[52] | 39 | |
---|
[1] | 40 | class sc_time; |
---|
| 41 | extern const sc_time SC_ZERO_TIME; |
---|
| 42 | extern sc_time SC_CURRENT_TIME; |
---|
| 43 | |
---|
[59] | 44 | extern uint64 nb_cycles; |
---|
[1] | 45 | |
---|
[52] | 46 | inline double sc_simulation_time() { |
---|
| 47 | // in default time units |
---|
| 48 | return (double) nb_cycles; |
---|
[1] | 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
[52] | 52 | const sc_time & sc_time_stamp(); |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | class sc_time { |
---|
| 57 | |
---|
| 58 | friend const sc_time & sc_time_stamp(); |
---|
[59] | 59 | uint64 time; |
---|
[52] | 60 | enum sc_time_unit unit; |
---|
| 61 | |
---|
| 62 | public: |
---|
| 63 | sc_time(double val, sc_time_unit tu); |
---|
| 64 | sc_time(const sc_time & = SC_ZERO_TIME); |
---|
| 65 | |
---|
| 66 | sc_time & operator= (const sc_time &); |
---|
| 67 | |
---|
[59] | 68 | uint64 value() const { |
---|
[52] | 69 | return time; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | inline double to_double() const; |
---|
| 73 | inline double to_seconds() const; |
---|
| 74 | inline operator double() const { |
---|
| 75 | return to_double(); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | const std::string to_string() const; |
---|
| 79 | |
---|
[1] | 80 | }; |
---|
| 81 | |
---|
[52] | 82 | |
---|
| 83 | inline const sc_time & sc_time_stamp() { |
---|
| 84 | // in default time units |
---|
| 85 | SC_CURRENT_TIME.time = nb_cycles; |
---|
| 86 | return SC_CURRENT_TIME; // = sc_time (nb_cycles, SC_NS); |
---|
[1] | 87 | } |
---|
| 88 | |
---|
[52] | 89 | |
---|
| 90 | double sc_time::to_double() const { |
---|
| 91 | double fact = 1; |
---|
| 92 | switch (unit) { |
---|
| 93 | case SC_FS: |
---|
| 94 | fact = 1e-6; |
---|
| 95 | break; |
---|
| 96 | case SC_PS: |
---|
| 97 | fact = 1e-3; |
---|
| 98 | break; |
---|
| 99 | case SC_NS: |
---|
| 100 | fact = 1; |
---|
| 101 | break; |
---|
| 102 | case SC_US: |
---|
| 103 | fact = 1e3; |
---|
| 104 | break; |
---|
| 105 | case SC_MS: |
---|
| 106 | fact = 1e6; |
---|
| 107 | break; |
---|
| 108 | case SC_SEC: |
---|
| 109 | fact = 1e9; |
---|
| 110 | break; |
---|
| 111 | } |
---|
| 112 | return (double) time * fact; |
---|
[4] | 113 | } |
---|
| 114 | |
---|
[52] | 115 | |
---|
| 116 | double sc_time::to_seconds() const { |
---|
| 117 | double fact = 1; |
---|
| 118 | switch (unit) { |
---|
| 119 | case SC_FS: |
---|
| 120 | fact = 1e-15; |
---|
| 121 | break; |
---|
| 122 | case SC_PS: |
---|
| 123 | fact = 1e-12; |
---|
| 124 | break; |
---|
| 125 | case SC_NS: |
---|
| 126 | fact = 1e-9; |
---|
| 127 | break; |
---|
| 128 | case SC_US: |
---|
| 129 | fact = 1e-6; |
---|
| 130 | break; |
---|
| 131 | case SC_MS: |
---|
| 132 | fact = 1e-3; |
---|
| 133 | break; |
---|
| 134 | case SC_SEC: |
---|
| 135 | fact = 1; |
---|
| 136 | break; |
---|
| 137 | } |
---|
| 138 | return (double) time * fact; |
---|
[4] | 139 | } |
---|
| 140 | |
---|
[52] | 141 | |
---|
[1] | 142 | } // end of namespace sc_core |
---|
| 143 | |
---|
[52] | 144 | |
---|
[1] | 145 | #endif /* __SC_TIME_H__ */ |
---|
[52] | 146 | |
---|
| 147 | /* |
---|
| 148 | # Local Variables: |
---|
| 149 | # tab-width: 4; |
---|
| 150 | # c-basic-offset: 4; |
---|
| 151 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 152 | # indent-tabs-mode: nil; |
---|
| 153 | # End: |
---|
| 154 | # |
---|
| 155 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 156 | */ |
---|
| 157 | |
---|