test2.cpp revision 12855:588919e0e4aa
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  test2.cpp -- Test use of sc_pending_activity_at_current_time()
23
24  Original Author: Andy Goodrich, Forte Design Systems, 18 August 2006
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#include "systemc.h"
39
40SC_MODULE(DUT)
41{
42    SC_CTOR(DUT)
43    {
44        SC_THREAD(thread)
45        sensitive << m_clk.pos();
46        dont_initialize();
47        SC_METHOD(cascade0_monitor);
48        sensitive << m_cascade0;
49        dont_initialize();
50        SC_METHOD(cascade1_monitor);
51        sensitive << m_cascade1;
52        dont_initialize();
53        SC_METHOD(cascade2_monitor);
54        sensitive << m_cascade2;
55        dont_initialize();
56    }
57
58    void cascade0_monitor()
59    {
60        cout << sc_time_stamp() << " " << sc_delta_count() << " cascade0"
61             << endl;
62        m_cascade1 = m_cascade0;
63    }
64
65    void cascade1_monitor()
66    {
67        cout << sc_time_stamp() << " " << sc_delta_count() << " cascade1"
68             << endl;
69        m_cascade2 = m_cascade1;
70    }
71
72    void cascade2_monitor()
73    {
74        cout << sc_time_stamp() << " " << sc_delta_count() << " cascade2"
75             << endl;
76    }
77
78    void thread()
79    {
80        for (;;)
81        {
82            cout << sc_time_stamp() << " " << sc_delta_count() << " thread"
83                 << endl;
84            m_cascade0 = !m_cascade0.read();
85            wait();
86        }
87    }
88    sc_signal<bool> m_cascade0;
89    sc_signal<bool> m_cascade1;
90    sc_signal<bool> m_cascade2;
91    sc_in<bool>     m_clk;
92};
93
94int sc_main(int argc, char* argv[])
95{
96    sc_clock        clock;
97    DUT             dut("dut");
98
99    dut.m_clk(clock);
100
101
102    do { sc_start(0, SC_NS); } while (sc_pending_activity_at_current_time());
103    cout << endl;
104    sc_start(1, SC_NS);
105    do { sc_start(0, SC_NS); } while (sc_pending_activity_at_current_time());
106    cout << endl;
107    sc_start(1, SC_NS);
108    do { sc_start(0, SC_NS); } while (sc_pending_activity_at_current_time());
109
110    cout << "Program completed" << endl;
111    return 0;
112}
113