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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [bench/] [sysc/] [src/] [TraceSC.cpp] - Blame information for rev 49

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

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

powered by: WebSVN 2.1.0

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