summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/kernel/process_control/test03/test03.cpp
blob: 45e84c828c362b3a97d953492e0cbc99afaa0b7b (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/*****************************************************************************

  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.

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

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

  test03.cpp -- Test of disable enable on processes

  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());
        m_cthread = sc_get_current_process_handle();
        SC_METHOD(dynamic_method_and_events);

	m_dynamic_method_and_events = sc_get_current_process_handle();
        SC_METHOD(dynamic_method_negedge);
	m_dynamic_method_negedge = sc_get_current_process_handle();
        SC_METHOD(dynamic_method_posedge);
	m_dynamic_method_posedge = sc_get_current_process_handle();

        SC_THREAD(dynamic_thread_and_events);
        m_dynamic_thread_and_events = sc_get_current_process_handle();
        SC_THREAD(dynamic_thread_negedge);
        m_dynamic_thread_negedge = sc_get_current_process_handle();
        SC_THREAD(dynamic_thread_posedge);
        m_dynamic_thread_posedge = sc_get_current_process_handle();

        SC_METHOD(static_method);
        sensitive << m_clk.pos();
	dont_initialize();
        m_static_method = sc_get_current_process_handle();
        SC_THREAD(static_thread);
        sensitive << m_clk.pos();
        m_static_thread = sc_get_current_process_handle();
        SC_METHOD(stimulus_method);

        SC_CTHREAD(stimulus,m_clk.pos());
        reset_signal_is(m_reset, true);
    }

    void cthread()
    {
        for (;;)
        {
            wait();
            cout << sc_time_stamp() << ": cthread awakened" << endl;
        }
    }

    // dynamic_method_and_events - dynamic method waiting on the and of 
    // two events:

    void dynamic_method_and_events()
    {
        static int state = 0;
	switch( state )
	{
	  case 0:
	    cout << sc_time_stamp() 
	         << " dynamic_method_and_events: initialization call" << endl;
	    break;
	  case 1:
	    cout << sc_time_stamp() << " dynamic_method_and_events: awakened"
		 << endl;
	    break;
	}
	next_trigger( m_event1 & m_event2 );
	state = 1;
    }

    // dynamic_method_negedge - dynamic method waiting on negedge events:

    void dynamic_method_negedge()
    {
        static int state = 0;
	switch( state )
	{
	  case 0:
	    cout << sc_time_stamp() 
		 << " dynamic_method_negedge: initialization call" << endl;
	    break;
	  case 1:
	    cout << sc_time_stamp() << " dynamic_method_negedge: awakened"
		 << endl;
	    break;
	}
	next_trigger( m_clk.negedge_event() );
	state = 1;
    }

    // dynamic_method_posedge - dynamic method waiting on posedge events:

    void dynamic_method_posedge()
    {
        static int state = 0;
	switch( state )
	{
	  case 0:
	    cout << sc_time_stamp() 
		 << " dynamic_method_posedge: initialization call" << endl;
	    break;
	  default:
	    cout << sc_time_stamp() << " dynamic_method_posedge: awakened"
		 << endl;
	}
	next_trigger( m_clk.posedge_event() );
	state = 1;
    }

    // dynamic_thread_and_events - dynamic thread waiting on the and of 
    // two events:

    void dynamic_thread_and_events()
    {
	cout << sc_time_stamp() 
	     << " dynamic_thread_and_events: initialization call" << endl;
        for (;;)
	{
	    wait( m_event1 & m_event2 );
	    cout << sc_time_stamp() << " dynamic_thread_and_events: awakened"
	         << endl;
	}
    }

    // dynamic_thread_negedge - dynamic thread waiting on negedge events:

    void dynamic_thread_negedge()
    {
	cout << sc_time_stamp() 
	     << " dynamic_thread_negedge: initialization call" << endl;
        for (;;)
	{
	    wait( m_clk.negedge_event() );
	    cout << sc_time_stamp() << " dynamic_thread_negedge: awakened"
	         << endl;
	}
    }

    // dynamic_thread_posedge - dynamic thread waiting on posedge events:

    void dynamic_thread_posedge()
    {
	cout << sc_time_stamp() 
	     << " dynamic_thread_posedge: initialization call" << endl;
        for (;;)
	{
	    wait( m_clk.posedge_event() );
	    cout << sc_time_stamp() << " dynamic_thread_posedge: awakened"
	         << endl;
	}
    }

    void static_method()
    {
        cout << sc_time_stamp() << ": static method awakened" << endl;
    }
    void static_thread()
    {
        for (;;)
        {
            wait();
            cout << sc_time_stamp() << ": static thread awakened" << endl;
        }
    }
    void stimulus_method()
    {
	cout << "Status during sc_start(1,SC_NS) = " << sc_get_status() << endl;
	cout << sc_time_stamp() << ": stimulus ("
	     << __LINE__ << ") - disabling all processes" << endl;
	m_cthread.disable();
	m_dynamic_method_and_events.disable();
	m_dynamic_method_negedge.disable();
	m_dynamic_method_posedge.disable();
	m_dynamic_thread_and_events.disable();
	m_dynamic_thread_negedge.disable();
	m_dynamic_thread_posedge.disable();
	m_static_method.disable();
	m_static_thread.disable();
    }
    void stimulus()
    {
        for (;;)
        {
	    // START OUT BY WAITING ON THE DISABLE FROM THE stimulus_method.

            wait();
            wait();
            wait();

	    // PROCEED WITH AN ENABLE ON EVERYONE - EXPECTING posedge WAKES:

            m_cthread.enable();
            m_dynamic_method_and_events.enable();
            m_dynamic_method_negedge.enable();
            m_dynamic_method_posedge.enable();
            m_dynamic_thread_and_events.enable();
            m_dynamic_thread_negedge.enable();
            m_dynamic_thread_posedge.enable();
            m_static_method.enable();
            m_static_thread.enable();
            cout << endl << sc_time_stamp() << ": stimulus (" 
                 << __LINE__ << ") - enabling all processes" << endl;
            wait();

	    // DISABLE EVERYONE AGAIN:

            cout << endl << sc_time_stamp() << ": stimulus ("
                 << __LINE__ << ") - disabling all processes" << endl;
            m_cthread.disable();
            m_dynamic_method_and_events.disable();
            m_dynamic_method_negedge.disable();
            m_dynamic_method_posedge.disable();
            m_dynamic_thread_and_events.disable();
            m_dynamic_thread_negedge.disable();
            m_dynamic_thread_posedge.disable();
            m_static_method.disable();
            m_static_thread.disable();
            wait();

	    // PROCEED WITH AN ENABLE ON EVERYONE - EXPECTING negedge WAKES:

            cout << endl << sc_time_stamp() << ": stimulus (" 
                 << __LINE__ << ") - enabling all processes" << endl;
            m_cthread.enable();
            m_dynamic_method_and_events.enable();
            m_dynamic_method_negedge.enable();
            m_dynamic_method_posedge.enable();
            m_dynamic_thread_and_events.enable();
            m_dynamic_thread_negedge.enable();
            m_dynamic_thread_posedge.enable();
            m_static_method.enable();
            m_static_thread.enable();
            wait();

            // FIRE OFF EVENT 1:
            cout << endl << sc_time_stamp() << ": stimulus ("
                 << __LINE__ << ") - firing event1 " << endl;
            m_event1.notify(SC_ZERO_TIME);
            wait();

            cout << endl << sc_time_stamp() << ": stimulus ("
                 << __LINE__ << ") - disabling all processes" << endl;
            m_cthread.disable();
            m_dynamic_method_and_events.disable();
            m_dynamic_method_negedge.disable();
            m_dynamic_method_posedge.disable();
            m_dynamic_thread_and_events.disable();
            m_dynamic_thread_negedge.disable();
            m_dynamic_thread_posedge.disable();
            m_static_method.disable();
            m_static_thread.disable();
            wait();


	    // FIRE OFF EVENT 2: WITH EVERYONE DISABLED:

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

	    // FIRE OFF EVENT 2: WITH EVERYONE ENABLED:

            cout << endl << sc_time_stamp() << ": stimulus (" 
                 << __LINE__ << ") - enabling all processes" << endl;
            m_cthread.enable();
            m_dynamic_method_and_events.enable();
            m_dynamic_method_negedge.enable();
            m_dynamic_method_posedge.enable();
            m_dynamic_thread_and_events.enable();
            m_dynamic_thread_negedge.enable();
            m_dynamic_thread_posedge.enable();
            m_static_method.enable();
            m_static_thread.enable();
            wait();

            m_event2.notify(SC_ZERO_TIME);
            cout << endl << sc_time_stamp() << ": stimulus ("
                 << __LINE__ << ") - firing event2 " << endl;
            wait();
            wait();
            sc_stop();
        }
    }
    sc_in<bool>       m_clk;
    sc_process_handle m_cthread;
    sc_process_handle m_dynamic_method_and_events;
    sc_process_handle m_dynamic_method_negedge;
    sc_process_handle m_dynamic_method_posedge;
    sc_process_handle m_dynamic_thread_and_events;
    sc_process_handle m_dynamic_thread_negedge;
    sc_process_handle m_dynamic_thread_posedge;
    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_clock        clock;
    DUT             dut("dut");
    sc_signal<bool> reset;

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

    reset = true;
    cout << "Status before sc_start(1,SC_NS) = " << sc_get_status() << endl;
    sc_start(1, SC_NS);
    cout << "Status after sc_start(1,SC_NS) = " << sc_get_status() << endl;
    reset = false;
    sc_start();

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

// $Log: test03.cpp,v $
// Revision 1.5  2011/02/20 13:44:06  acg
//  Andy Goodrich: updates for IEEE 1666 2011.
//
// Revision 1.4  2011/02/14 17:00:00  acg
//  Andy Goodrich: updated copyright and added cvs logging information inline.
//
// Revision 1.3  2011/01/14 14:23:58  acg
//  Andy Goodrich: Fixes for 1666_2011
//
// Revision 1.2  2009/05/22 16:07:26  acg
//  Andy Goodrich: process control updates.
//
// Revision 1.1.1.1  2006/12/15 20:26:03  acg
// systemc_tests-2.3
//
// Revision 1.1  2006/12/14 21:40:10  acg
//  Andy Goodrich: moving test to new directory.
//
// Revision 1.2  2006/04/20 19:43:31  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:10:55  acg
//  Andy Goodrich: First inclusion of test for suspend and resume support.
//