1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  test.cpp --
23
24  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38//
39// bug in sc_vcd_trace::cycle()
40//   in SystemC 1.2.1Beta  (also 1.0.2).
41// Simulates correctly (two clock edges at time 15).
42// But VCD is corrupt - has #0 instead of #15.
43// Also, this message should be printed but isn't:
44//   VCD Trace Warning:
45//   Multiple cycles found with same (15) time units count.
46//   Waveform viewers will only show the states of the last one.
47//   Use ((vcd_trace_file*)vcdfile)->sc_set_vcd_time_unit(int exponent10_seconds)
48//   to increase time resolution.
49//
50//
51
52#include "systemc.h"
53// #include <iostream.h>
54
55// class foo: sc_module {
56class foo: public sc_module {
57public:
58    sc_in<bool>	clk1;
59    sc_in<bool>	clk2;
60
61    SC_CTOR(foo) {
62        SC_METHOD(do_clk1);
63        sensitive << clk1.pos();
64        SC_METHOD(do_clk2);
65        sensitive << clk2.pos();
66    }
67    void do_clk1() {
68        cout << "foo: clk1 + " << sc_time_stamp() << endl;
69    }
70    void do_clk2() {
71        cout << "foo: clk2 + " << sc_time_stamp() << endl;
72    }
73};
74
75int
76sc_main(int argc, char *argv[])
77{
78    // sc_clock	clk1("clk1", 10, SC_NS, 0.5);
79    // sc_clock	clk2("clk2", 12, SC_NS, 0.5);
80    sc_signal<bool> clk1( "clk1" );
81    sc_signal<bool> clk2( "clk2" );
82
83    foo		FOO("FOO");
84
85    FOO.clk1(clk1);
86    FOO.clk2(clk2);
87
88    sc_trace_file *tf = sc_create_vcd_trace_file("test");
89    // sc_trace(tf, clk1.signal(), "clk1");
90    // sc_trace(tf, clk2.signal(), "clk2");
91    sc_trace(tf, clk1, "clk1");
92    sc_trace(tf, clk2, "clk2");
93
94    sc_start(0, SC_NS);
95
96    clk1 = 0;
97    clk2 = 0;                                          // 0 ns
98    sc_start(3, SC_NS);
99    clk2 = 1;                                          // 3 ns +
100    sc_start(2, SC_NS);
101    clk1 = 1;                                          // 5 ns +
102    sc_start(4, SC_NS);
103    clk2 = 0;                                          // 9 ns
104    sc_start(1, SC_NS);
105    clk1 = 0;                                          // 10 ns
106    sc_start(5, SC_NS);
107    clk2 = 1;                                          // 15 ns +
108    sc_start(0, SC_NS);
109    clk1 = 1;                                          // 15 ns +
110    sc_start(5, SC_NS);
111    clk1 = 0;                                          // 20 ns
112    sc_start(1, SC_NS);
113    clk2 = 0;                                          // 21 ns
114    sc_start(4, SC_NS);
115    clk1 = 1;                                          // 25 ns +
116    sc_start(2, SC_NS);
117    clk2 = 1;                                          // 27 ns +
118    sc_start(3, SC_NS);
119    clk1 = 0;                                          // 30 ns
120
121    sc_close_vcd_trace_file(tf);
122
123    return 0;
124}
125