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

Subversion Repositories openrisc

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

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 6 julius
SC_HAS_PROCESS( TraceSC );
37
 
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
TraceSC::TraceSC (sc_core::sc_module_name  name,
45
                  Vorpsoc_top        *_traceTarget,
46
                  int argc,
47
                  char              *argv[]) :
48
  sc_module (name),
49
  traceTarget (_traceTarget)
50
{
51
#if VM_TRACE
52
 
53
  // Setup the name of the VCD dump file
54 42 julius
  string dumpNameDefault("vlt-dump.vcd");
55
  string testNameString;
56
  string vcdDumpFile;
57 44 julius
 
58 49 julius
  // Search through the command line parameters for VCD dump options
59
  dump_start_delay = 0;
60
  dump_stop_set = 0;
61
  int time_val;
62 44 julius
  int cmdline_name_found=0;
63
  if (argc > 1)
64
  {
65
    for(int i=1; i<argc; i++)
66 6 julius
    {
67 49 julius
      if ((strcmp(argv[i], "-vcd")==0) ||
68
          (strcmp(argv[i], "--vcd")==0))
69 44 julius
        {
70
          testNameString = (argv[i+1]);
71
          vcdDumpFile = testNameString;
72
          cmdline_name_found=1;
73 49 julius
         }
74
      else if ( (strcmp(argv[i], "-vcdstart")==0) ||
75
           (strcmp(argv[i], "--vcdstart")==0) )
76
        {
77
          time_val = atoi(argv[i+1]);
78
          sc_time dump_start_time(time_val,SC_NS);
79
          dump_start = dump_start_time;
80
          if (DEBUG_TRACESC) cout << "TraceSC(): Dump start time set at " << dump_start.to_string() << endl;
81
          dump_start_delay = 1;
82 44 julius
          break;
83
         }
84 49 julius
      else if ( (strcmp(argv[i], "-vcdstop")==0) ||
85
           (strcmp(argv[i], "--vcdstop")==0) )
86
        {
87
          time_val = atoi(argv[i+1]);
88
          sc_time dump_stop_time(time_val,SC_NS);
89
          dump_stop = dump_stop_time;
90
          if (DEBUG_TRACESC) cout << "TraceSC(): Dump stop time set at " << dump_stop.to_string() << endl;
91
          dump_stop_set = 1;
92
          break;
93
        }
94 6 julius
    }
95 44 julius
  }
96 49 julius
 
97 44 julius
  if(cmdline_name_found==0) // otherwise use our default VCD dump file name
98
    vcdDumpFile = dumpNameDefault;
99 42 julius
 
100 6 julius
  Verilated::traceEverOn (true);
101 42 julius
 
102 49 julius
  cout << "* Enabling VCD trace";
103
 
104
  if (dump_start_delay)
105
    cout << ", on at time " << dump_start.to_string();
106
  if (dump_stop_set)
107
    cout << ", off at time " << dump_stop.to_string();
108
 
109
  cout << endl;
110 6 julius
 
111 42 julius
 
112 49 julius
  printf("* VCD dumpfile: %s\n", vcdDumpFile.c_str());
113
 
114 6 julius
  // Establish a new trace with its correct time resolution, and trace to
115
  // great depth.
116
  spTraceFile = new SpTraceVcdCFile ();
117
  setSpTimeResolution (sc_get_time_resolution ());
118
  traceTarget->trace (spTraceFile, 99);
119 42 julius
  spTraceFile->open (vcdDumpFile.c_str());
120 6 julius
 
121 49 julius
  if (dump_start_delay == 1)
122
    dumping_now = 0; // We'll wait for the time to dump
123
  else
124
    dumping_now = 1; // Begin with dumping turned on
125
 
126
 
127 6 julius
  // Method to drive the dump on each clock edge
128 49 julius
  //SC_METHOD (driveTrace);
129
  //sensitive << clk;
130 6 julius
 
131
#endif
132
 
133
}       // TraceSC ()
134
 
135
 
136
//! Destructor for the trace module.
137
 
138
//! Used to close the tracefile
139
 
140
TraceSC::~TraceSC ()
141
{
142
#if VM_TRACE
143
  spTraceFile->close ();
144
#endif
145
 
146
}       // ~TraceSC ()
147
 
148
 
149 49 julius
//! Method to drive the trace. We're called on every clock edge, and also at
150 6 julius
//! initialization (to get initial values into the dump).
151
void
152
TraceSC::driveTrace()
153
{
154
#if VM_TRACE
155 49 julius
 
156
  if (DEBUG_TRACESC) cout << "TraceSC(): " << endl;
157
  if (dumping_now == 0)
158
    {
159
      // Check the time, see if we should enable dumping
160
      if (sc_time_stamp() >=  dump_start)
161
        {
162
          // Give a message
163
          cout << "* VCD tracing turned on at time " << dump_start.to_string() << endl;
164
          dumping_now = 1;
165
        }
166
    }
167
 
168
  if (dumping_now == 1)
169
    spTraceFile->dump (sc_time_stamp().to_double());
170
 
171
 
172
  // Should we turn off tracing?
173
  if ((dumping_now == 1) && (dump_stop_set == 1))
174
    {
175
      if (sc_time_stamp() >=  dump_stop)
176
        {
177
          // Give a message
178
          cout << "* VCD tracing turned off at time " << dump_stop.to_string() << endl;
179
          dumping_now = 0; // Turn off the dump
180
        }
181
    }
182
 
183 6 julius
#endif
184
 
185
}       // driveTrace()
186
 
187
 
188
//! Utility method to set the SystemPerl trace time resolution.
189
 
190
//! This should be automatic, but is missed in Verilator 3.700.
191
 
192
//! @param t  The desired time resolution (as a SC time)
193
 
194
void
195
TraceSC::setSpTimeResolution (sc_time  t)
196
{
197
#if VM_TRACE
198
 
199
  double      secs = t.to_seconds();
200
  int         val;                      // Integral value of the precision
201
  const char *units;                    // Units as text
202
 
203
  if (secs < 1.0e-15)
204
    {
205 49 julius
      cerr << "* VCD time resolution " << secs << " too small: ignored" << endl;
206 6 julius
      return;
207
    }
208
  else if (secs < 1.0e-12)
209
    {
210
      val   = secs / 1.0e-15;
211
      units = "f";
212
    }
213
  else if (secs < 1.0e-9)
214
    {
215
      val   = secs / 1.0e-12;
216
      units = "p";
217
    }
218
  else if (secs < 1.0e-6)
219
    {
220
      val   = secs / 1.0e-9;
221
      units = "n";
222
    }
223
  else if (secs < 1.0e-3)
224
    {
225
      val   = secs / 1.0e-6;
226
      units = "u";
227
    }
228
  else if (secs < 1.0)
229
    {
230
      val   = secs / 1.0e-3;
231
      units = "m";
232
    }
233
  else
234
    {
235
      val   = secs;
236
      units = "s";
237
    }
238
 
239
  // Val must be a power of 10
240
  switch (val)
241
    {
242
    case 1:
243
    case 10:
244
    case 100:
245
    case 1000:
246
    case 10000:
247
    case 100000:
248
    case 1000000:
249
    case 10000000:
250
    case 100000000:
251
    case 1000000000:
252
 
253
      break;                    // OK
254
 
255
    default:
256
      cerr << "VCD time resolution " << secs << " not power of 10: ignored"
257
           << endl;
258
      return;
259
    }
260
 
261
  // Set the time resolution for the trace file
262
  char str[32];
263
  sprintf (str, "%d %s", val, units);
264
  spTraceFile->spTrace()->set_time_resolution (str);
265
 
266
#endif
267
 
268
}       // setSpTimeResolution()
269
 

powered by: WebSVN 2.1.0

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