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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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