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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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