| 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 <iostream> |
|---|
| 16 | #include <string> |
|---|
| 17 | #include "sc_nbdefs.h" |
|---|
| 18 | #include "internal_ext.h" |
|---|
| 19 | |
|---|
| 20 | namespace sc_core { |
|---|
| 21 | |
|---|
| 22 | // ---------------------------------------------------------------------------- |
|---|
| 23 | // ENUM : sc_time_unit |
|---|
| 24 | // |
|---|
| 25 | // Enumeration of time units. |
|---|
| 26 | // ---------------------------------------------------------------------------- |
|---|
| 27 | |
|---|
| 28 | enum sc_time_unit |
|---|
| 29 | { |
|---|
| 30 | SC_FS = 0, |
|---|
| 31 | SC_PS, |
|---|
| 32 | SC_NS, |
|---|
| 33 | SC_US, |
|---|
| 34 | SC_MS, |
|---|
| 35 | SC_SEC |
|---|
| 36 | }; |
|---|
| 37 | |
|---|
| 38 | // |
|---|
| 39 | class sc_time; |
|---|
| 40 | extern const sc_time SC_ZERO_TIME; |
|---|
| 41 | extern sc_time SC_CURRENT_TIME; |
|---|
| 42 | |
|---|
| 43 | extern uint64 nb_cycles; |
|---|
| 44 | |
|---|
| 45 | inline double sc_simulation_time() // in default time units |
|---|
| 46 | { |
|---|
| 47 | return (double)nb_cycles; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | const sc_time& sc_time_stamp (); |
|---|
| 51 | |
|---|
| 52 | // |
|---|
| 53 | class sc_time |
|---|
| 54 | { |
|---|
| 55 | friend const sc_time &sc_time_stamp (); |
|---|
| 56 | long long int time; |
|---|
| 57 | public: |
|---|
| 58 | // sc_time (); LRM 2.1 |
|---|
| 59 | sc_time (double val, sc_time_unit tu); |
|---|
| 60 | sc_time (const sc_time& = SC_ZERO_TIME); |
|---|
| 61 | |
|---|
| 62 | sc_time& operator= (const sc_time &); |
|---|
| 63 | |
|---|
| 64 | /*sc_dt::*/uint64 value () const { return (/*sc_dt::*/uint64) time;} |
|---|
| 65 | double to_double () const { return time * 1000;} |
|---|
| 66 | double to_seconds() const { return time / (double)1000000000;}; |
|---|
| 67 | operator double () const { return to_double ();}; |
|---|
| 68 | const std::string to_string () const; |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | inline const sc_time& sc_time_stamp () // in default time units |
|---|
| 72 | { |
|---|
| 73 | SC_CURRENT_TIME.time = nb_cycles; |
|---|
| 74 | return SC_CURRENT_TIME;// = sc_time (nb_cycles, SC_NS); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | } // end of namespace sc_core |
|---|
| 78 | |
|---|
| 79 | using sc_core::sc_simulation_time; |
|---|
| 80 | using sc_core::sc_time; |
|---|
| 81 | using sc_core::sc_time_stamp; |
|---|
| 82 | |
|---|
| 83 | #endif /* __SC_TIME_H__ */ |
|---|