source: sources/src/sc_time.h @ 54

Last change on this file since 54 was 52, checked in by meunier, 12 years ago

Code formatting in all source files.

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