summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/kernel/process_control/test02/test02.cpp
blob: d770e43a4b540c336d823dcfe9fe77ec64aecea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*****************************************************************************

  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
  more contributor license agreements.  See the NOTICE file distributed
  with this work for additional information regarding copyright ownership.
  Accellera licenses this file to you under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with the
  License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  implied.  See the License for the specific language governing
  permissions and limitations under the License.

 *****************************************************************************/

/*****************************************************************************

  test02.cpp -- Test of resume after dynamic event completion

  Original Author: Andy Goodrich

 *****************************************************************************/

/*****************************************************************************

  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
  changes you are making here.

      Name, Affiliation, Date:
  Description of Modification:

  Revision log at end of the file to let __LINE__ give the same results 
  after a check-in.
 *****************************************************************************/

#include "systemc.h"

SC_MODULE(DUT)
{
    SC_CTOR(DUT)
    {
        SC_CTHREAD(cthread,m_clk.pos());
        reset_signal_is(m_reset, true);
        m_cthread = sc_get_current_process_handle();

        SC_METHOD(dynamic_method);
	m_dynamic_method = sc_get_current_process_handle();

        SC_THREAD(dynamic_thread);
        m_dynamic_thread = sc_get_current_process_handle();

        SC_METHOD(static_method);
	sensitive << m_event1 << m_event2;
	m_static_method = sc_get_current_process_handle();

	SC_THREAD(static_thread);
	sensitive << m_event1 << m_event2;
        m_static_thread = sc_get_current_process_handle();

        SC_CTHREAD(stimulus,m_clk.pos());
        reset_signal_is(m_reset, true);
    }
    void cthread()
    {
        for (;;)
	{
	    wait();
	    cout << sc_time_stamp() << ":      clocked thread (" << __LINE__ 
		 << ") after wait on m_clk.pos() " << endl;
	}
    }
    void dynamic_method()
    {
        static int state = 0;
        switch ( state )
        {
          case 0:
            next_trigger( m_clk.posedge_event() );
            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__ 
                 << "," << state << ") initialization call " << endl;
            state = 1;
            break;
          default:
          case 1:
            next_trigger( m_event1 & m_event2 );
            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__ 
                 << "," << state << ") after wait on m_clk.posedge() " << endl;
            break;
        }
    }
    void dynamic_thread()
    {
        cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__ << ")" 
             << " initialization call " << endl;
        wait(m_clk.posedge_event());
        cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__ 
             << ") after wait on m_clk.posedge_event() " << endl;
        for (;;)
        {
            wait(m_event1 & m_event2 );
            cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__ 
                 << ") after wait on m_event1 & m_event2 " << endl;
        }
    }
    void static_method()
    {
        static bool initialized = false;
	if ( !initialized )
	{
	    initialized = true;
	    cout << sc_time_stamp() << ":      static method (" << __LINE__ 
	         << ")" << " initialization call " << endl;
	}
	else
	{
	    cout << sc_time_stamp() << ":      static method (" << __LINE__ 
		 << ") after wait on m_event1 | m_event2 " << endl;
	}
    }
    void static_thread()
    {
        cout << sc_time_stamp() << ":      static thread (" << __LINE__ << ")" 
             << " initialization call " << endl;
	for (;;)
	{
	    wait();
            cout << sc_time_stamp() << ":      static thread (" << __LINE__ 
                 << ") after wait on m_event1 | m_event2 " << endl;
	}
        
    }
    void stimulus()
    {
        for (;;)
        {
            wait();
            wait();
            cout << sc_time_stamp() << ": stimulus ("
                 << __LINE__ << ") - suspending all processes" << endl;
            m_cthread.suspend();
            m_dynamic_method.suspend();
            m_dynamic_thread.suspend();
            m_static_method.suspend();
            m_static_thread.suspend();
            wait();

            m_event1.notify(SC_ZERO_TIME);
            cout << sc_time_stamp() << ": stimulus ("
                 << __LINE__ << ") - firing event1 " << endl;
            wait();
            m_event2.notify(SC_ZERO_TIME);
            cout << sc_time_stamp() << ": stimulus ("
                 << __LINE__ << ") - firing event2 " << endl;
            wait();
            wait();

            m_cthread.resume();
            m_dynamic_method.resume();
            m_dynamic_thread.resume();
            m_static_method.resume();
            m_static_thread.resume();
            cout << endl << sc_time_stamp() << ": stimulus (" 
                 << __LINE__ << ") - resuming all processes" << endl;
            wait();
            wait();
            wait();
            sc_stop();
        }
    }
    sc_in<bool>       m_clk;
    sc_process_handle m_cthread;
    sc_process_handle m_dynamic_method;
    sc_process_handle m_dynamic_thread;
    sc_event          m_event1;
    sc_event          m_event2;
    sc_event          m_event3;
    sc_event          m_event4;
    sc_in<bool>       m_reset;
    sc_process_handle m_static_method;
    sc_process_handle m_static_thread;
};

int sc_main(int argc, char* argv[])
{
    sc_core::sc_allow_process_control_corners = true;
    sc_clock        clock;
    DUT             dut("dut");
    sc_signal<bool> reset;

    dut.m_clk(clock);
    dut.m_reset(reset);

    sc_core::sc_allow_process_control_corners = true;
    reset = true;
    sc_start(1, SC_NS);
    reset = false;
    sc_start(21, SC_NS);

    cout << "Program completed" << endl;
    return 0;
}

// $Log: test02.cpp,v $
// Revision 1.6  2011/04/02 00:08:27  acg
//  Andy Goodrich: turn off corner case error checking.
//
// Revision 1.5  2011/03/07 19:32:11  acg
//  Andy Goodrich: addition to set sc_core::sc_allow_process_control_corners
//  to true so that this test avoids corner case error messages.
//
// Revision 1.4  2011/02/20 13:43:58  acg
//  Andy Goodrich: updates for IEEE 1666 2011.
//
// Revision 1.3  2011/02/14 17:00:00  acg
//  Andy Goodrich: updated copyright and added cvs logging information inline.
//
// Revision 1.2  2011/01/20 16:55:23  acg
//  Andy Goodrich: changes for IEEE 1666 2011.
//
// Revision 1.1.1.1  2006/12/15 20:26:03  acg
// systemc_tests-2.3
//
// Revision 1.1  2006/12/14 21:40:06  acg
//  Andy Goodrich: moving test to new directory.
//
// Revision 1.2  2006/04/20 19:43:34  acg
//  Andy Goodrich: moved CVS log to end of file so that __LINE__ does not
//  change when a checkin is done.
//
// Revision 1.1  2006/04/17 20:11:02  acg
//  Andy Goodrich: First inclusion of test for suspend and resume support.
//