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  sc_wait.cpp -- Wait() and related functions.
23
24  Original Author: Stan Y. Liao, Synopsys, Inc.
25                   Martin Janssen, Synopsys, Inc.
26
27  CHANGE LOG AT THE END OF THE FILE
28 *****************************************************************************/
29
30
31#include "sysc/kernel/sc_except.h"
32#include "sysc/kernel/sc_kernel_ids.h"
33#include "sysc/kernel/sc_cthread_process.h"
34#include "sysc/kernel/sc_thread_process.h"
35#include "sysc/kernel/sc_simcontext_int.h"
36#include "sysc/kernel/sc_wait.h"
37#include "sysc/utils/sc_utils_ids.h"
38
39namespace sc_core {
40
41// static sensitivity for SC_THREADs and SC_CTHREADs
42
43void warn_cthread_wait()
44{
45    static bool warn_wait = true;
46    if ( warn_wait )
47    {
48        warn_wait = false;
49        SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_,
50	    "all waits except wait() and wait(N)\n" \
51	    "             are deprecated for SC_CTHREAD, " \
52	    "use an SC_THREAD instead");
53    }
54}
55
56void
57wait( sc_simcontext* simc )
58{
59    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
60    switch( cpi->kind ) {
61    case SC_THREAD_PROC_:
62    case SC_CTHREAD_PROC_: {
63	RCAST<sc_cthread_handle>( cpi->process_handle )->wait_cycles();
64        break;
65    }
66    default:
67	SC_REPORT_ERROR( SC_ID_WAIT_NOT_ALLOWED_, "\n        "
68			 "in SC_METHODs use next_trigger() instead" );
69        break;
70    }
71}
72
73// dynamic sensitivity for SC_THREADs and SC_CTHREADs
74
75void
76wait( const sc_event& e, sc_simcontext* simc )
77{
78    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
79    switch( cpi->kind ) {
80    case SC_THREAD_PROC_: {
81	RCAST<sc_thread_handle>( cpi->process_handle )->wait( e );
82	break;
83    }
84    case SC_CTHREAD_PROC_: {
85        warn_cthread_wait();
86	sc_cthread_handle cthread_h =
87            RCAST<sc_cthread_handle>( cpi->process_handle );
88	cthread_h->wait( e );
89	cthread_h->wait_cycles();
90	break;
91    }
92    default:
93	SC_REPORT_ERROR( SC_ID_WAIT_NOT_ALLOWED_, "\n        "
94			 "in SC_METHODs use next_trigger() instead" );
95        break;
96    }
97}
98
99void
100wait( const sc_event_or_list& el, sc_simcontext* simc )
101{
102    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
103    switch( cpi->kind ) {
104    case SC_THREAD_PROC_: {
105	RCAST<sc_thread_handle>( cpi->process_handle )->wait( el );
106	break;
107    }
108    case SC_CTHREAD_PROC_: {
109        warn_cthread_wait();
110        SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_,
111	    "wait(event_list) is deprecated for SC_CTHREAD, use SC_THREAD");
112	sc_cthread_handle cthread_h =
113            RCAST<sc_cthread_handle>( cpi->process_handle );
114	cthread_h->wait( el );
115	cthread_h->wait_cycles();
116	break;
117    }
118    default:
119	SC_REPORT_ERROR( SC_ID_WAIT_NOT_ALLOWED_, "\n        "
120			 "in SC_METHODs use next_trigger() instead" );
121        break;
122    }
123}
124
125void
126wait( const sc_event_and_list& el, sc_simcontext* simc )
127{
128    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
129    switch( cpi->kind ) {
130    case SC_THREAD_PROC_: {
131	RCAST<sc_thread_handle>( cpi->process_handle )->wait( el );
132	break;
133    }
134    case SC_CTHREAD_PROC_: {
135        warn_cthread_wait();
136	sc_cthread_handle cthread_h =
137            RCAST<sc_cthread_handle>( cpi->process_handle );
138	cthread_h->wait( el );
139	cthread_h->wait_cycles();
140	break;
141    }
142    default:
143	SC_REPORT_ERROR( SC_ID_WAIT_NOT_ALLOWED_, "\n        "
144			 "in SC_METHODs use next_trigger() instead" );
145        break;
146    }
147}
148
149void
150wait( const sc_time& t, sc_simcontext* simc )
151{
152    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
153    switch( cpi->kind ) {
154    case SC_THREAD_PROC_: {
155	RCAST<sc_thread_handle>( cpi->process_handle )->wait( t );
156	break;
157    }
158    case SC_CTHREAD_PROC_: {
159        warn_cthread_wait();
160	sc_cthread_handle cthread_h =
161            RCAST<sc_cthread_handle>( cpi->process_handle );
162	cthread_h->wait( t );
163	cthread_h->wait_cycles();
164	break;
165    }
166    default:
167	SC_REPORT_ERROR( SC_ID_WAIT_NOT_ALLOWED_, "\n        "
168			 "in SC_METHODs use next_trigger() instead" );
169        break;
170    }
171}
172
173void
174wait( const sc_time& t, const sc_event& e, sc_simcontext* simc )
175{
176    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
177    switch( cpi->kind ) {
178    case SC_THREAD_PROC_: {
179	RCAST<sc_thread_handle>( cpi->process_handle )->wait( t, e );
180	break;
181    }
182    case SC_CTHREAD_PROC_: {
183        warn_cthread_wait();
184	sc_cthread_handle cthread_h =
185            RCAST<sc_cthread_handle>( cpi->process_handle );
186	cthread_h->wait( t, e );
187	cthread_h->wait_cycles();
188	break;
189    }
190    default:
191	SC_REPORT_ERROR( SC_ID_WAIT_NOT_ALLOWED_, "\n        "
192			 "in SC_METHODs use next_trigger() instead" );
193        break;
194    }
195}
196
197void
198wait( const sc_time& t, const sc_event_or_list& el, sc_simcontext* simc )
199{
200    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
201    switch( cpi->kind ) {
202    case SC_THREAD_PROC_: {
203	RCAST<sc_thread_handle>( cpi->process_handle )->wait( t, el );
204	break;
205    }
206    case SC_CTHREAD_PROC_: {
207        warn_cthread_wait();
208	sc_cthread_handle cthread_h =
209            RCAST<sc_cthread_handle>( cpi->process_handle );
210	cthread_h->wait( t, el );
211	cthread_h->wait_cycles();
212	break;
213    }
214    default:
215	SC_REPORT_ERROR( SC_ID_WAIT_NOT_ALLOWED_, "\n        "
216			 "in SC_METHODs use next_trigger() instead" );
217        break;
218    }
219}
220
221void
222wait( const sc_time& t, const sc_event_and_list& el, sc_simcontext* simc )
223{
224    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
225    switch( cpi->kind ) {
226    case SC_THREAD_PROC_: {
227	RCAST<sc_thread_handle>( cpi->process_handle )->wait( t, el );
228	break;
229    }
230    case SC_CTHREAD_PROC_: {
231        warn_cthread_wait();
232	sc_cthread_handle cthread_h =
233            RCAST<sc_cthread_handle>( cpi->process_handle );
234	cthread_h->wait( t, el );
235	cthread_h->wait_cycles();
236	break;
237    }
238    default:
239	SC_REPORT_ERROR( SC_ID_WAIT_NOT_ALLOWED_, "\n        "
240			 "in SC_METHODs use next_trigger() instead" );
241        break;
242    }
243}
244
245
246// static sensitivity for SC_METHODs
247
248void
249next_trigger( sc_simcontext* simc )
250{
251    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
252    if( cpi->kind == SC_METHOD_PROC_ ) {
253	RCAST<sc_method_handle>( cpi->process_handle )->clear_trigger();
254    } else {
255	SC_REPORT_ERROR( SC_ID_NEXT_TRIGGER_NOT_ALLOWED_, "\n        "
256			 "in SC_THREADs and SC_CTHREADs use wait() instead" );
257    }
258}
259
260
261// dynamic sensitivity for SC_METHODs
262
263void
264next_trigger( const sc_event& e, sc_simcontext* simc )
265{
266    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
267    if( cpi->kind == SC_METHOD_PROC_ ) {
268	RCAST<sc_method_handle>( cpi->process_handle )->next_trigger( e );
269    } else {
270	SC_REPORT_ERROR( SC_ID_NEXT_TRIGGER_NOT_ALLOWED_, "\n        "
271			 "in SC_THREADs and SC_CTHREADs use wait() instead" );
272    }
273}
274
275void
276next_trigger( const sc_event_or_list& el, sc_simcontext* simc )
277{
278    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
279    if( cpi->kind == SC_METHOD_PROC_ ) {
280	RCAST<sc_method_handle>( cpi->process_handle )->next_trigger( el );
281    } else {
282	SC_REPORT_ERROR( SC_ID_NEXT_TRIGGER_NOT_ALLOWED_, "\n        "
283			 "in SC_THREADs and SC_CTHREADs use wait() instead" );
284    }
285}
286
287void
288next_trigger( const sc_event_and_list& el, sc_simcontext* simc )
289{
290    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
291    if( cpi->kind == SC_METHOD_PROC_ ) {
292	RCAST<sc_method_handle>( cpi->process_handle )->next_trigger( el );
293    } else {
294	SC_REPORT_ERROR( SC_ID_NEXT_TRIGGER_NOT_ALLOWED_, "\n        "
295			 "in SC_THREADs and SC_CTHREADs use wait() instead" );
296    }
297}
298
299void
300next_trigger( const sc_time& t, sc_simcontext* simc )
301{
302    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
303    if( cpi->kind == SC_METHOD_PROC_ ) {
304	RCAST<sc_method_handle>( cpi->process_handle )->next_trigger( t );
305    } else {
306	SC_REPORT_ERROR( SC_ID_NEXT_TRIGGER_NOT_ALLOWED_, "\n        "
307			 "in SC_THREADs and SC_CTHREADs use wait() instead" );
308    }
309}
310
311void
312next_trigger( const sc_time& t, const sc_event& e, sc_simcontext* simc )
313{
314    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
315    if( cpi->kind == SC_METHOD_PROC_ ) {
316	RCAST<sc_method_handle>( cpi->process_handle )->next_trigger( t, e );
317    } else {
318	SC_REPORT_ERROR( SC_ID_NEXT_TRIGGER_NOT_ALLOWED_, "\n        "
319			 "in SC_THREADs and SC_CTHREADs use wait() instead" );
320    }
321}
322
323void
324next_trigger( const sc_time& t, const sc_event_or_list& el, sc_simcontext* simc)
325{
326    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
327    if( cpi->kind == SC_METHOD_PROC_ ) {
328	RCAST<sc_method_handle>( cpi->process_handle )->next_trigger( t, el );
329    } else {
330	SC_REPORT_ERROR( SC_ID_NEXT_TRIGGER_NOT_ALLOWED_, "\n        "
331			 "in SC_THREADs and SC_CTHREADs use wait() instead" );
332    }
333}
334
335void
336next_trigger(const sc_time& t, const sc_event_and_list& el, sc_simcontext* simc)
337{
338    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
339    if( cpi->kind == SC_METHOD_PROC_ ) {
340	RCAST<sc_method_handle>( cpi->process_handle )->next_trigger( t, el );
341    } else {
342	SC_REPORT_ERROR( SC_ID_NEXT_TRIGGER_NOT_ALLOWED_, "\n        "
343			 "in SC_THREADs and SC_CTHREADs use wait() instead" );
344    }
345}
346
347
348// for SC_METHODs and SC_THREADs and SC_CTHREADs
349
350bool
351timed_out( sc_simcontext* simc )
352{
353    static bool warn_timed_out=true;
354    if ( warn_timed_out )
355    {
356        warn_timed_out = false;
357        SC_REPORT_INFO(SC_ID_IEEE_1666_DEPRECATION_,
358	    "timed_out() function is deprecated" );
359    }
360
361    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
362    return cpi->process_handle->timed_out();
363}
364
365
366
367// misc.
368
369void
370sc_set_location( const char* file, int lineno, sc_simcontext* simc )
371{
372    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
373    sc_process_b* handle = cpi->process_handle;
374    handle->file = file;
375    handle->lineno = lineno;
376}
377
378} // namespace sc_core
379
380/*
381$Log: sc_wait.cpp,v $
382Revision 1.6  2011/08/26 20:46:11  acg
383 Andy Goodrich: moved the modification log to the end of the file to
384 eliminate source line number skew when check-ins are done.
385
386Revision 1.5  2011/02/18 20:27:14  acg
387 Andy Goodrich: Updated Copyrights.
388
389Revision 1.4  2011/02/13 21:47:38  acg
390 Andy Goodrich: update copyright notice.
391
392Revision 1.3  2011/01/18 20:10:45  acg
393 Andy Goodrich: changes for IEEE1666_2011 semantics.
394
395Revision 1.2  2008/05/22 17:06:27  acg
396 Andy Goodrich: updated copyright notice to include 2008.
397
398Revision 1.1.1.1  2006/12/15 20:20:05  acg
399SystemC 2.3
400
401Revision 1.7  2006/02/02 20:20:39  acg
402 Andy Goodrich: warnings for SC_THREAD waits.
403
404Revision 1.6  2006/02/01 01:36:54  acg
405 Andy Goodrich: addition of deprecation comments for SC_CTHREAD waits other
406 than wait() and wait(N).
407
408Revision 1.5  2006/01/31 22:17:40  acg
409 Andy Goodrich: added deprecation warnings for SC_CTHREAD waits other than
410 wait() and wait(N).
411
412Revision 1.4  2006/01/25 00:31:20  acg
413 Andy Goodrich: Changed over to use a standard message id of
414 SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
415
416Revision 1.3  2006/01/24 20:49:05  acg
417Andy Goodrich: changes to remove the use of deprecated features within the
418simulator, and to issue warning messages when deprecated features are used.
419
420Revision 1.2  2006/01/03 23:18:45  acg
421Changed copyright to include 2006.
422
423Revision 1.1.1.1  2005/12/19 23:16:44  acg
424First check in of SystemC 2.1 into its own archive.
425
426Revision 1.10  2005/09/02 19:03:30  acg
427Changes for dynamic processes. Removal of lambda support.
428
429Revision 1.9  2005/07/30 03:45:05  acg
430Changes from 2.1, including changes for sc_process_handle.
431
432Revision 1.8  2005/04/04 00:16:07  acg
433Changes for directory name change to sys from systemc.
434Changes for sc_string going to std::string.
435Changes for sc_pvector going to std::vector.
436Changes for reference pools for bit and part selections.
437Changes for const sc_concatref support.
438
439Revision 1.5  2004/09/27 20:49:10  acg
440Andy Goodrich, Forte Design Systems, Inc.
441   - Added a $Log comment so that CVS checkin comments appear in the
442     checkout source.
443
444*/
445
446// Taf!
447