test02.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  test02.cpp -- Test of resume after dynamic event completion
23
24  Original Author: Andy Goodrich
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  Revision log at end of the file to let __LINE__ give the same results
37  after a check-in.
38 *****************************************************************************/
39
40#include "systemc.h"
41
42SC_MODULE(DUT)
43{
44    SC_CTOR(DUT)
45    {
46        SC_CTHREAD(cthread,m_clk.pos());
47        reset_signal_is(m_reset, true);
48        m_cthread = sc_get_current_process_handle();
49
50        SC_METHOD(dynamic_method);
51	m_dynamic_method = sc_get_current_process_handle();
52
53        SC_THREAD(dynamic_thread);
54        m_dynamic_thread = sc_get_current_process_handle();
55
56        SC_METHOD(static_method);
57	sensitive << m_event1 << m_event2;
58	m_static_method = sc_get_current_process_handle();
59
60	SC_THREAD(static_thread);
61	sensitive << m_event1 << m_event2;
62        m_static_thread = sc_get_current_process_handle();
63
64        SC_CTHREAD(stimulus,m_clk.pos());
65        reset_signal_is(m_reset, true);
66    }
67    void cthread()
68    {
69        for (;;)
70	{
71	    wait();
72	    cout << sc_time_stamp() << ":      clocked thread (" << __LINE__
73		 << ") after wait on m_clk.pos() " << endl;
74	}
75    }
76    void dynamic_method()
77    {
78        static int state = 0;
79        switch ( state )
80        {
81          case 0:
82            next_trigger( m_clk.posedge_event() );
83            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__
84                 << "," << state << ") initialization call " << endl;
85            state = 1;
86            break;
87          default:
88          case 1:
89            next_trigger( m_event1 & m_event2 );
90            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__
91                 << "," << state << ") after wait on m_clk.posedge() " << endl;
92            break;
93        }
94    }
95    void dynamic_thread()
96    {
97        cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__ << ")"
98             << " initialization call " << endl;
99        wait(m_clk.posedge_event());
100        cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__
101             << ") after wait on m_clk.posedge_event() " << endl;
102        for (;;)
103        {
104            wait(m_event1 & m_event2 );
105            cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__
106                 << ") after wait on m_event1 & m_event2 " << endl;
107        }
108    }
109    void static_method()
110    {
111        static bool initialized = false;
112	if ( !initialized )
113	{
114	    initialized = true;
115	    cout << sc_time_stamp() << ":      static method (" << __LINE__
116	         << ")" << " initialization call " << endl;
117	}
118	else
119	{
120	    cout << sc_time_stamp() << ":      static method (" << __LINE__
121		 << ") after wait on m_event1 | m_event2 " << endl;
122	}
123    }
124    void static_thread()
125    {
126        cout << sc_time_stamp() << ":      static thread (" << __LINE__ << ")"
127             << " initialization call " << endl;
128	for (;;)
129	{
130	    wait();
131            cout << sc_time_stamp() << ":      static thread (" << __LINE__
132                 << ") after wait on m_event1 | m_event2 " << endl;
133	}
134
135    }
136    void stimulus()
137    {
138        for (;;)
139        {
140            wait();
141            wait();
142            cout << sc_time_stamp() << ": stimulus ("
143                 << __LINE__ << ") - suspending all processes" << endl;
144            m_cthread.suspend();
145            m_dynamic_method.suspend();
146            m_dynamic_thread.suspend();
147            m_static_method.suspend();
148            m_static_thread.suspend();
149            wait();
150
151            m_event1.notify(SC_ZERO_TIME);
152            cout << sc_time_stamp() << ": stimulus ("
153                 << __LINE__ << ") - firing event1 " << endl;
154            wait();
155            m_event2.notify(SC_ZERO_TIME);
156            cout << sc_time_stamp() << ": stimulus ("
157                 << __LINE__ << ") - firing event2 " << endl;
158            wait();
159            wait();
160
161            m_cthread.resume();
162            m_dynamic_method.resume();
163            m_dynamic_thread.resume();
164            m_static_method.resume();
165            m_static_thread.resume();
166            cout << endl << sc_time_stamp() << ": stimulus ("
167                 << __LINE__ << ") - resuming all processes" << endl;
168            wait();
169            wait();
170            wait();
171            sc_stop();
172        }
173    }
174    sc_in<bool>       m_clk;
175    sc_process_handle m_cthread;
176    sc_process_handle m_dynamic_method;
177    sc_process_handle m_dynamic_thread;
178    sc_event          m_event1;
179    sc_event          m_event2;
180    sc_event          m_event3;
181    sc_event          m_event4;
182    sc_in<bool>       m_reset;
183    sc_process_handle m_static_method;
184    sc_process_handle m_static_thread;
185};
186
187int sc_main(int argc, char* argv[])
188{
189    sc_core::sc_allow_process_control_corners = true;
190    sc_clock        clock;
191    DUT             dut("dut");
192    sc_signal<bool> reset;
193
194    dut.m_clk(clock);
195    dut.m_reset(reset);
196
197    sc_core::sc_allow_process_control_corners = true;
198    reset = true;
199    sc_start(1, SC_NS);
200    reset = false;
201    sc_start(21, SC_NS);
202
203    cout << "Program completed" << endl;
204    return 0;
205}
206
207// $Log: test02.cpp,v $
208// Revision 1.6  2011/04/02 00:08:27  acg
209//  Andy Goodrich: turn off corner case error checking.
210//
211// Revision 1.5  2011/03/07 19:32:11  acg
212//  Andy Goodrich: addition to set sc_core::sc_allow_process_control_corners
213//  to true so that this test avoids corner case error messages.
214//
215// Revision 1.4  2011/02/20 13:43:58  acg
216//  Andy Goodrich: updates for IEEE 1666 2011.
217//
218// Revision 1.3  2011/02/14 17:00:00  acg
219//  Andy Goodrich: updated copyright and added cvs logging information inline.
220//
221// Revision 1.2  2011/01/20 16:55:23  acg
222//  Andy Goodrich: changes for IEEE 1666 2011.
223//
224// Revision 1.1.1.1  2006/12/15 20:26:03  acg
225// systemc_tests-2.3
226//
227// Revision 1.1  2006/12/14 21:40:06  acg
228//  Andy Goodrich: moving test to new directory.
229//
230// Revision 1.2  2006/04/20 19:43:34  acg
231//  Andy Goodrich: moved CVS log to end of file so that __LINE__ does not
232//  change when a checkin is done.
233//
234// Revision 1.1  2006/04/17 20:11:02  acg
235//  Andy Goodrich: First inclusion of test for suspend and resume support.
236//
237
238