test03.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  test03.cpp -- Test of disable enable on processes
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
41#include "systemc.h"
42
43SC_MODULE(DUT)
44{
45    SC_CTOR(DUT)
46    {
47        SC_CTHREAD(cthread,m_clk.pos());
48        m_cthread = sc_get_current_process_handle();
49        SC_METHOD(dynamic_method_and_events);
50
51	m_dynamic_method_and_events = sc_get_current_process_handle();
52        SC_METHOD(dynamic_method_negedge);
53	m_dynamic_method_negedge = sc_get_current_process_handle();
54        SC_METHOD(dynamic_method_posedge);
55	m_dynamic_method_posedge = sc_get_current_process_handle();
56
57        SC_THREAD(dynamic_thread_and_events);
58        m_dynamic_thread_and_events = sc_get_current_process_handle();
59        SC_THREAD(dynamic_thread_negedge);
60        m_dynamic_thread_negedge = sc_get_current_process_handle();
61        SC_THREAD(dynamic_thread_posedge);
62        m_dynamic_thread_posedge = sc_get_current_process_handle();
63
64        SC_METHOD(static_method);
65        sensitive << m_clk.pos();
66	dont_initialize();
67        m_static_method = sc_get_current_process_handle();
68        SC_THREAD(static_thread);
69        sensitive << m_clk.pos();
70        m_static_thread = sc_get_current_process_handle();
71        SC_METHOD(stimulus_method);
72
73        SC_CTHREAD(stimulus,m_clk.pos());
74        reset_signal_is(m_reset, true);
75    }
76
77    void cthread()
78    {
79        for (;;)
80        {
81            wait();
82            cout << sc_time_stamp() << ": cthread awakened" << endl;
83        }
84    }
85
86    // dynamic_method_and_events - dynamic method waiting on the and of
87    // two events:
88
89    void dynamic_method_and_events()
90    {
91        static int state = 0;
92	switch( state )
93	{
94	  case 0:
95	    cout << sc_time_stamp()
96	         << " dynamic_method_and_events: initialization call" << endl;
97	    break;
98	  case 1:
99	    cout << sc_time_stamp() << " dynamic_method_and_events: awakened"
100		 << endl;
101	    break;
102	}
103	next_trigger( m_event1 & m_event2 );
104	state = 1;
105    }
106
107    // dynamic_method_negedge - dynamic method waiting on negedge events:
108
109    void dynamic_method_negedge()
110    {
111        static int state = 0;
112	switch( state )
113	{
114	  case 0:
115	    cout << sc_time_stamp()
116		 << " dynamic_method_negedge: initialization call" << endl;
117	    break;
118	  case 1:
119	    cout << sc_time_stamp() << " dynamic_method_negedge: awakened"
120		 << endl;
121	    break;
122	}
123	next_trigger( m_clk.negedge_event() );
124	state = 1;
125    }
126
127    // dynamic_method_posedge - dynamic method waiting on posedge events:
128
129    void dynamic_method_posedge()
130    {
131        static int state = 0;
132	switch( state )
133	{
134	  case 0:
135	    cout << sc_time_stamp()
136		 << " dynamic_method_posedge: initialization call" << endl;
137	    break;
138	  default:
139	    cout << sc_time_stamp() << " dynamic_method_posedge: awakened"
140		 << endl;
141	}
142	next_trigger( m_clk.posedge_event() );
143	state = 1;
144    }
145
146    // dynamic_thread_and_events - dynamic thread waiting on the and of
147    // two events:
148
149    void dynamic_thread_and_events()
150    {
151	cout << sc_time_stamp()
152	     << " dynamic_thread_and_events: initialization call" << endl;
153        for (;;)
154	{
155	    wait( m_event1 & m_event2 );
156	    cout << sc_time_stamp() << " dynamic_thread_and_events: awakened"
157	         << endl;
158	}
159    }
160
161    // dynamic_thread_negedge - dynamic thread waiting on negedge events:
162
163    void dynamic_thread_negedge()
164    {
165	cout << sc_time_stamp()
166	     << " dynamic_thread_negedge: initialization call" << endl;
167        for (;;)
168	{
169	    wait( m_clk.negedge_event() );
170	    cout << sc_time_stamp() << " dynamic_thread_negedge: awakened"
171	         << endl;
172	}
173    }
174
175    // dynamic_thread_posedge - dynamic thread waiting on posedge events:
176
177    void dynamic_thread_posedge()
178    {
179	cout << sc_time_stamp()
180	     << " dynamic_thread_posedge: initialization call" << endl;
181        for (;;)
182	{
183	    wait( m_clk.posedge_event() );
184	    cout << sc_time_stamp() << " dynamic_thread_posedge: awakened"
185	         << endl;
186	}
187    }
188
189    void static_method()
190    {
191        cout << sc_time_stamp() << ": static method awakened" << endl;
192    }
193    void static_thread()
194    {
195        for (;;)
196        {
197            wait();
198            cout << sc_time_stamp() << ": static thread awakened" << endl;
199        }
200    }
201    void stimulus_method()
202    {
203	cout << "Status during sc_start(1,SC_NS) = " << sc_get_status() << endl;
204	cout << sc_time_stamp() << ": stimulus ("
205	     << __LINE__ << ") - disabling all processes" << endl;
206	m_cthread.disable();
207	m_dynamic_method_and_events.disable();
208	m_dynamic_method_negedge.disable();
209	m_dynamic_method_posedge.disable();
210	m_dynamic_thread_and_events.disable();
211	m_dynamic_thread_negedge.disable();
212	m_dynamic_thread_posedge.disable();
213	m_static_method.disable();
214	m_static_thread.disable();
215    }
216    void stimulus()
217    {
218        for (;;)
219        {
220	    // START OUT BY WAITING ON THE DISABLE FROM THE stimulus_method.
221
222            wait();
223            wait();
224            wait();
225
226	    // PROCEED WITH AN ENABLE ON EVERYONE - EXPECTING posedge WAKES:
227
228            m_cthread.enable();
229            m_dynamic_method_and_events.enable();
230            m_dynamic_method_negedge.enable();
231            m_dynamic_method_posedge.enable();
232            m_dynamic_thread_and_events.enable();
233            m_dynamic_thread_negedge.enable();
234            m_dynamic_thread_posedge.enable();
235            m_static_method.enable();
236            m_static_thread.enable();
237            cout << endl << sc_time_stamp() << ": stimulus ("
238                 << __LINE__ << ") - enabling all processes" << endl;
239            wait();
240
241	    // DISABLE EVERYONE AGAIN:
242
243            cout << endl << sc_time_stamp() << ": stimulus ("
244                 << __LINE__ << ") - disabling all processes" << endl;
245            m_cthread.disable();
246            m_dynamic_method_and_events.disable();
247            m_dynamic_method_negedge.disable();
248            m_dynamic_method_posedge.disable();
249            m_dynamic_thread_and_events.disable();
250            m_dynamic_thread_negedge.disable();
251            m_dynamic_thread_posedge.disable();
252            m_static_method.disable();
253            m_static_thread.disable();
254            wait();
255
256	    // PROCEED WITH AN ENABLE ON EVERYONE - EXPECTING negedge WAKES:
257
258            cout << endl << sc_time_stamp() << ": stimulus ("
259                 << __LINE__ << ") - enabling all processes" << endl;
260            m_cthread.enable();
261            m_dynamic_method_and_events.enable();
262            m_dynamic_method_negedge.enable();
263            m_dynamic_method_posedge.enable();
264            m_dynamic_thread_and_events.enable();
265            m_dynamic_thread_negedge.enable();
266            m_dynamic_thread_posedge.enable();
267            m_static_method.enable();
268            m_static_thread.enable();
269            wait();
270
271            // FIRE OFF EVENT 1:
272            cout << endl << sc_time_stamp() << ": stimulus ("
273                 << __LINE__ << ") - firing event1 " << endl;
274            m_event1.notify(SC_ZERO_TIME);
275            wait();
276
277            cout << endl << sc_time_stamp() << ": stimulus ("
278                 << __LINE__ << ") - disabling all processes" << endl;
279            m_cthread.disable();
280            m_dynamic_method_and_events.disable();
281            m_dynamic_method_negedge.disable();
282            m_dynamic_method_posedge.disable();
283            m_dynamic_thread_and_events.disable();
284            m_dynamic_thread_negedge.disable();
285            m_dynamic_thread_posedge.disable();
286            m_static_method.disable();
287            m_static_thread.disable();
288            wait();
289
290
291	    // FIRE OFF EVENT 2: WITH EVERYONE DISABLED:
292
293            m_event2.notify(SC_ZERO_TIME);
294            cout << endl << sc_time_stamp() << ": stimulus ("
295                 << __LINE__ << ") - firing event2 " << endl;
296            wait();
297            wait();
298            wait();
299
300	    // FIRE OFF EVENT 2: WITH EVERYONE ENABLED:
301
302            cout << endl << sc_time_stamp() << ": stimulus ("
303                 << __LINE__ << ") - enabling all processes" << endl;
304            m_cthread.enable();
305            m_dynamic_method_and_events.enable();
306            m_dynamic_method_negedge.enable();
307            m_dynamic_method_posedge.enable();
308            m_dynamic_thread_and_events.enable();
309            m_dynamic_thread_negedge.enable();
310            m_dynamic_thread_posedge.enable();
311            m_static_method.enable();
312            m_static_thread.enable();
313            wait();
314
315            m_event2.notify(SC_ZERO_TIME);
316            cout << endl << sc_time_stamp() << ": stimulus ("
317                 << __LINE__ << ") - firing event2 " << endl;
318            wait();
319            wait();
320            sc_stop();
321        }
322    }
323    sc_in<bool>       m_clk;
324    sc_process_handle m_cthread;
325    sc_process_handle m_dynamic_method_and_events;
326    sc_process_handle m_dynamic_method_negedge;
327    sc_process_handle m_dynamic_method_posedge;
328    sc_process_handle m_dynamic_thread_and_events;
329    sc_process_handle m_dynamic_thread_negedge;
330    sc_process_handle m_dynamic_thread_posedge;
331    sc_event          m_event1;
332    sc_event          m_event2;
333    sc_event          m_event3;
334    sc_event          m_event4;
335    sc_in<bool>       m_reset;
336    sc_process_handle m_static_method;
337    sc_process_handle m_static_thread;
338};
339
340int sc_main(int argc, char* argv[])
341{
342    sc_clock        clock;
343    DUT             dut("dut");
344    sc_signal<bool> reset;
345
346    dut.m_clk(clock);
347    dut.m_reset(reset);
348
349    reset = true;
350    cout << "Status before sc_start(1,SC_NS) = " << sc_get_status() << endl;
351    sc_start(1, SC_NS);
352    cout << "Status after sc_start(1,SC_NS) = " << sc_get_status() << endl;
353    reset = false;
354    sc_start();
355
356    cout << "Program completed" << endl;
357    return 0;
358}
359
360// $Log: test03.cpp,v $
361// Revision 1.5  2011/02/20 13:44:06  acg
362//  Andy Goodrich: updates for IEEE 1666 2011.
363//
364// Revision 1.4  2011/02/14 17:00:00  acg
365//  Andy Goodrich: updated copyright and added cvs logging information inline.
366//
367// Revision 1.3  2011/01/14 14:23:58  acg
368//  Andy Goodrich: Fixes for 1666_2011
369//
370// Revision 1.2  2009/05/22 16:07:26  acg
371//  Andy Goodrich: process control updates.
372//
373// Revision 1.1.1.1  2006/12/15 20:26:03  acg
374// systemc_tests-2.3
375//
376// Revision 1.1  2006/12/14 21:40:10  acg
377//  Andy Goodrich: moving test to new directory.
378//
379// Revision 1.2  2006/04/20 19:43:31  acg
380//  Andy Goodrich: moved CVS log to end of file so that __LINE__ does not
381//  change when a checkin is done.
382//
383// Revision 1.1  2006/04/17 20:10:55  acg
384//  Andy Goodrich: First inclusion of test for suspend and resume support.
385//
386