source: branches/with_autoconf/src/sc_time.h

Last change on this file was 4, checked in by nipo, 19 years ago

Towards SystemC-2.2 LRM:

  • Implement sc_time with units
  • Have a systemc header with no namespace pollution
File size: 2.6 KB
Line 
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
18namespace sc_core {
19
20// ----------------------------------------------------------------------------
21// ENUM : sc_time_unit
22//
23// Enumeration of time units.
24// ----------------------------------------------------------------------------
25
26enum 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//
37class sc_time;
38extern const sc_time SC_ZERO_TIME;
39extern sc_time SC_CURRENT_TIME;
40
41extern uint64_t nb_cycles;
42
43inline double sc_simulation_time() // in default time units
44{
45 return (double)nb_cycles;
46}
47
48const sc_time& sc_time_stamp ();
49
50//
51class sc_time
52{
53 friend const sc_time &sc_time_stamp ();
54 uint64_t time;
55 enum sc_time_unit unit;
56public:
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
69inline 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
75double
76sc_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
90double
91sc_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__ */
Note: See TracBrowser for help on using the repository browser.