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

Subversion Repositories openrisc

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

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
 
31
SC_HAS_PROCESS( TraceSC );
32
 
33
//! Constructor for the trace module
34
 
35
//! @param name           Name of this module, passed to the parent
36
//!                       constructor.
37
//! @param _trace_target  ORPSoC module to trace
38
 
39
TraceSC::TraceSC (sc_core::sc_module_name  name,
40
                  Vorpsoc_top        *_traceTarget,
41
                  int argc,
42
                  char              *argv[]) :
43
  sc_module (name),
44
  traceTarget (_traceTarget)
45
{
46
#if VM_TRACE
47
 
48
  // Setup the name of the VCD dump file
49
 
50
  char* dumpName;
51
  char* dumpSuffix = "-vlt.vcd\0";
52
  char* dumpNameDefault = "vlt-dump.vcd\0";
53
  // We will be passed the current test-name when we're called
54
  if (argc > 1)
55
    {
56
      // Assume test name is first thing
57
      int testname_argv_index = 1;
58
      // Take the second argument as the test name and we'll 
59
      // concatendate "-vlt.vcd" on the end
60
      dumpName = (char*) malloc((strlen(argv[testname_argv_index] +
61
                                              strlen(dumpSuffix))*sizeof(char)));
62
      // Copy in the test name
63
      strcpy(dumpName, argv[testname_argv_index]);
64
      // Now add on the suffix
65
      strcat(dumpName, dumpSuffix);
66
 
67
      printf("VCD dumpfile: %s\n", dumpName);
68
    }
69
  else
70
    dumpName = dumpNameDefault;
71
 
72
  Verilated::traceEverOn (true);
73
  cout << "Enabling VCD trace" << endl;
74
 
75
  // Establish a new trace with its correct time resolution, and trace to
76
  // great depth.
77
  spTraceFile = new SpTraceVcdCFile ();
78
  setSpTimeResolution (sc_get_time_resolution ());
79
  traceTarget->trace (spTraceFile, 99);
80
  spTraceFile->open (dumpName);
81
 
82
  // Method to drive the dump on each clock edge
83
  SC_METHOD (driveTrace);
84
  sensitive << clk;
85
 
86
#endif
87
 
88
}       // TraceSC ()
89
 
90
 
91
//! Destructor for the trace module.
92
 
93
//! Used to close the tracefile
94
 
95
TraceSC::~TraceSC ()
96
{
97
#if VM_TRACE
98
  spTraceFile->close ();
99
#endif
100
 
101
}       // ~TraceSC ()
102
 
103
 
104
//! Method to drive the trace. We're called on ever clock edge, and also at
105
//! initialization (to get initial values into the dump).
106
void
107
TraceSC::driveTrace()
108
{
109
#if VM_TRACE
110
  spTraceFile->dump (sc_time_stamp().to_double());
111
#endif
112
 
113
}       // driveTrace()
114
 
115
 
116
//! Utility method to set the SystemPerl trace time resolution.
117
 
118
//! This should be automatic, but is missed in Verilator 3.700.
119
 
120
//! @param t  The desired time resolution (as a SC time)
121
 
122
void
123
TraceSC::setSpTimeResolution (sc_time  t)
124
{
125
#if VM_TRACE
126
 
127
  double      secs = t.to_seconds();
128
  int         val;                      // Integral value of the precision
129
  const char *units;                    // Units as text
130
 
131
  if (secs < 1.0e-15)
132
    {
133
      cerr << "VCD time resolution " << secs << " too small: ignored" << endl;
134
      return;
135
    }
136
  else if (secs < 1.0e-12)
137
    {
138
      val   = secs / 1.0e-15;
139
      units = "f";
140
    }
141
  else if (secs < 1.0e-9)
142
    {
143
      val   = secs / 1.0e-12;
144
      units = "p";
145
    }
146
  else if (secs < 1.0e-6)
147
    {
148
      val   = secs / 1.0e-9;
149
      units = "n";
150
    }
151
  else if (secs < 1.0e-3)
152
    {
153
      val   = secs / 1.0e-6;
154
      units = "u";
155
    }
156
  else if (secs < 1.0)
157
    {
158
      val   = secs / 1.0e-3;
159
      units = "m";
160
    }
161
  else
162
    {
163
      val   = secs;
164
      units = "s";
165
    }
166
 
167
  // Val must be a power of 10
168
  switch (val)
169
    {
170
    case 1:
171
    case 10:
172
    case 100:
173
    case 1000:
174
    case 10000:
175
    case 100000:
176
    case 1000000:
177
    case 10000000:
178
    case 100000000:
179
    case 1000000000:
180
 
181
      break;                    // OK
182
 
183
    default:
184
      cerr << "VCD time resolution " << secs << " not power of 10: ignored"
185
           << endl;
186
      return;
187
    }
188
 
189
  // Set the time resolution for the trace file
190
  char str[32];
191
  sprintf (str, "%d %s", val, units);
192
  spTraceFile->spTrace()->set_time_resolution (str);
193
 
194
#endif
195
 
196
}       // setSpTimeResolution()
197
 

powered by: WebSVN 2.1.0

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