OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [src/] [TraceSC.cpp] - Blame information for rev 508

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 julius
// ----------------------------------------------------------------------------
2
 
3
// SystemC trace 
4
 
5
// Copyright (C) 2008  Embecosm Limited <info@embecosm.com>
6
 
7
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
// This file is part of the cycle accurate model of the OpenRISC 1000 based
10
// system-on-chip, ORPSoC, built using Verilator.
11
 
12
// This program is free software: you can redistribute it and/or modify it
13
// under the terms of the GNU Lesser General Public License as published by
14
// the Free Software Foundation, either version 3 of the License, or (at your
15
// option) any later version.
16
 
17
// This program is distributed in the hope that it will be useful, but WITHOUT
18
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
20
// License for more details.
21
 
22
// You should have received a copy of the GNU Lesser General Public License
23
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 
25
// ----------------------------------------------------------------------------
26
 
27
// $Id: TraceSC.cpp 302 2009-02-13 17:22:07Z jeremy $
28
 
29
#include "TraceSC.h"
30 49 julius
#include <systemc.h>
31 6 julius
 
32 42 julius
using namespace std;
33
 
34 49 julius
#define DEBUG_TRACESC 1
35
 
36 462 julius
SC_HAS_PROCESS(TraceSC);
37 6 julius
 
38
//! Constructor for the trace module
39
 
40
//! @param name           Name of this module, passed to the parent
41
//!                       constructor.
42
//! @param _trace_target  ORPSoC module to trace
43
 
44 462 julius
TraceSC::TraceSC(sc_core::sc_module_name name, Vorpsoc_top * _traceTarget, int argc, char *argv[]):
45
sc_module(name),
46
traceTarget(_traceTarget)
47 6 julius
{
48
#if VM_TRACE
49
 
50 462 julius
        // Setup the name of the VCD dump file
51
        string dumpNameDefault("vlt-dump.vcd");
52
        string testNameString;
53
        string vcdDumpFile;
54 44 julius
 
55 462 julius
        // Search through the command line parameters for VCD dump options
56
        dump_start_delay = 0;
57
        dump_stop_set = 0;
58
        int time_val;
59
        int cmdline_name_found = 0;
60
        if (argc > 1) {
61
                for (int i = 1; i < argc; i++) {
62
                        if ((strcmp(argv[i], "-vcd") == 0) ||
63
                            (strcmp(argv[i], "--vcd") == 0)) {
64
                                testNameString = (argv[i + 1]);
65
                                vcdDumpFile = testNameString;
66
                                cmdline_name_found = 1;
67
                        } else if ((strcmp(argv[i], "-vcdstart") == 0) ||
68
                                   (strcmp(argv[i], "--vcdstart") == 0)) {
69
                                time_val = atoi(argv[i + 1]);
70
                                sc_time dump_start_time(time_val, SC_NS);
71
                                dump_start = dump_start_time;
72
                                if (DEBUG_TRACESC)
73
                                        cout <<
74
                                            "TraceSC(): Dump start time set at "
75
                                            << dump_start.to_string() << endl;
76
                                dump_start_delay = 1;
77
                                break;
78
                        } else if ((strcmp(argv[i], "-vcdstop") == 0) ||
79
                                   (strcmp(argv[i], "--vcdstop") == 0)) {
80
                                time_val = atoi(argv[i + 1]);
81
                                sc_time dump_stop_time(time_val, SC_NS);
82
                                dump_stop = dump_stop_time;
83
                                if (DEBUG_TRACESC)
84
                                        cout <<
85
                                            "TraceSC(): Dump stop time set at "
86
                                            << dump_stop.to_string() << endl;
87
                                dump_stop_set = 1;
88
                                break;
89
                        }
90
                }
91 49 julius
        }
92 6 julius
 
93 462 julius
        if (cmdline_name_found == 0)     // otherwise use our default VCD dump file name
94
                vcdDumpFile = dumpNameDefault;
95 42 julius
 
96 462 julius
        Verilated::traceEverOn(true);
97 49 julius
 
98 462 julius
        cout << "* Enabling VCD trace";
99 6 julius
 
100 462 julius
        if (dump_start_delay)
101
                cout << ", on at time " << dump_start.to_string();
102
        if (dump_stop_set)
103
                cout << ", off at time " << dump_stop.to_string();
104 49 julius
 
105 462 julius
        cout << endl;
106 49 julius
 
107 462 julius
        printf("* VCD dumpfile: %s\n", vcdDumpFile.c_str());
108
 
109
        // Establish a new trace with its correct time resolution, and trace to
110
        // great depth.
111
        spTraceFile = new SpTraceVcdCFile();
112
        setSpTimeResolution(sc_get_time_resolution());
113
        traceTarget->trace(spTraceFile, 99);
114
        spTraceFile->open(vcdDumpFile.c_str());
115
 
116
        if (dump_start_delay == 1)
117
                dumping_now = 0; // We'll wait for the time to dump
118
        else
119
                dumping_now = 1;        // Begin with dumping turned on
120
 
121
        // Method to drive the dump on each clock edge
122
        //SC_METHOD (driveTrace);
123
        //sensitive << clk;
124
 
125 6 julius
#endif
126
 
127 462 julius
}                               // TraceSC ()
128 6 julius
 
129
//! Destructor for the trace module.
130
 
131
//! Used to close the tracefile
132
 
133 462 julius
TraceSC::~TraceSC()
134 6 julius
{
135
#if VM_TRACE
136 462 julius
        spTraceFile->close();
137 6 julius
#endif
138
 
139 462 julius
}                               // ~TraceSC ()
140 6 julius
 
141 49 julius
//! Method to drive the trace. We're called on every clock edge, and also at
142 6 julius
//! initialization (to get initial values into the dump).
143
void
144 462 julius
 TraceSC::driveTrace()
145 6 julius
{
146
#if VM_TRACE
147 49 julius
 
148 462 julius
        if (DEBUG_TRACESC)
149
                cout << "TraceSC(): " << endl;
150
        if (dumping_now == 0) {
151
                // Check the time, see if we should enable dumping
152
                if (sc_time_stamp() >= dump_start) {
153
                        // Give a message
154
                        cout << "* VCD tracing turned on at time " <<
155
                            dump_start.to_string() << endl;
156
                        dumping_now = 1;
157
                }
158 49 julius
        }
159
 
160 462 julius
        if (dumping_now == 1)
161
                spTraceFile->dump(sc_time_stamp().to_double());
162 49 julius
 
163 462 julius
        // Should we turn off tracing?
164
        if ((dumping_now == 1) && (dump_stop_set == 1)) {
165
                if (sc_time_stamp() >= dump_stop) {
166
                        // Give a message
167
                        cout << "* VCD tracing turned off at time " <<
168
                            dump_stop.to_string() << endl;
169
                        dumping_now = 0; // Turn off the dump
170
                }
171 49 julius
        }
172 6 julius
#endif
173
 
174 462 julius
}                               // driveTrace()
175 6 julius
 
176
//! Utility method to set the SystemPerl trace time resolution.
177
 
178
//! This should be automatic, but is missed in Verilator 3.700.
179
 
180
//! @param t  The desired time resolution (as a SC time)
181
 
182 462 julius
void TraceSC::setSpTimeResolution(sc_time t)
183 6 julius
{
184
#if VM_TRACE
185
 
186 462 julius
        double secs = t.to_seconds();
187
        int val;                // Integral value of the precision
188
        const char *units;      // Units as text
189 6 julius
 
190 462 julius
        if (secs < 1.0e-15) {
191
                cerr << "* VCD time resolution " << secs <<
192
                    " too small: ignored" << endl;
193
                return;
194
        } else if (secs < 1.0e-12) {
195
                val = secs / 1.0e-15;
196
                units = "f";
197
        } else if (secs < 1.0e-9) {
198
                val = secs / 1.0e-12;
199
                units = "p";
200
        } else if (secs < 1.0e-6) {
201
                val = secs / 1.0e-9;
202
                units = "n";
203
        } else if (secs < 1.0e-3) {
204
                val = secs / 1.0e-6;
205
                units = "u";
206
        } else if (secs < 1.0) {
207
                val = secs / 1.0e-3;
208
                units = "m";
209
        } else {
210
                val = secs;
211
                units = "s";
212
        }
213 6 julius
 
214 462 julius
        // Val must be a power of 10
215
        switch (val) {
216
        case 1:
217
        case 10:
218
        case 100:
219
        case 1000:
220
        case 10000:
221
        case 100000:
222
        case 1000000:
223
        case 10000000:
224
        case 100000000:
225
        case 1000000000:
226 6 julius
 
227 462 julius
                break;          // OK
228 6 julius
 
229 462 julius
        default:
230
                cerr << "VCD time resolution " << secs <<
231
                    " not power of 10: ignored" << endl;
232
                return;
233
        }
234 6 julius
 
235 462 julius
        // Set the time resolution for the trace file
236
        char str[32];
237
        sprintf(str, "%d %s", val, units);
238
        spTraceFile->spTrace()->set_time_resolution(str);
239 6 julius
 
240
#endif
241
 
242 462 julius
}                               // setSpTimeResolution()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.