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_cthread.cpp -- Wait() and related functions for SC_CTHREADs.
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
32#include "sysc/kernel/sc_kernel_ids.h"
33#include "sysc/kernel/sc_cthread_process.h"
34#include "sysc/kernel/sc_simcontext_int.h"
35#include "sysc/kernel/sc_wait_cthread.h"
36#include "sysc/communication/sc_port.h"
37#include "sysc/kernel/sc_wait.h"
38namespace sc_core
39{
40
41// for SC_CTHREADs
42
43void
44halt( sc_simcontext* simc )
45{
46    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
47    switch( cpi->kind ) {
48    case SC_CTHREAD_PROC_: {
49	RCAST<sc_cthread_handle>( cpi->process_handle )->wait_halt();
50	break;
51    }
52    default:
53	SC_REPORT_ERROR( SC_ID_HALT_NOT_ALLOWED_, 0 );
54	break;
55    }
56}
57
58
59void
60wait( int n, sc_simcontext* simc )
61{
62    sc_curr_proc_handle cpi = simc->get_curr_proc_info();
63    if( n <= 0 ) {
64	char msg[BUFSIZ];
65	std::sprintf( msg, "n = %d", n );
66	SC_REPORT_ERROR( SC_ID_WAIT_N_INVALID_, msg );
67    }
68    switch( cpi->kind ) {
69      case SC_THREAD_PROC_:
70      case SC_CTHREAD_PROC_:
71	RCAST<sc_cthread_handle>( cpi->process_handle )->wait_cycles( n );
72        break;
73      default:
74        SC_REPORT_ERROR( SC_ID_WAIT_NOT_ALLOWED_, "\n        "
75	                 "in SC_METHODs use next_trigger() instead" );
76        break;
77    }
78}
79
80
81void
82at_posedge( const sc_signal_in_if<bool>& s, sc_simcontext* simc )
83{
84    if( s.read() == true )
85        do { wait(simc); } while ( s.read() == true );
86    do { wait(simc); } while ( s.read() == false );
87}
88
89void
90at_posedge( const sc_signal_in_if<sc_dt::sc_logic>& s, sc_simcontext* simc )
91{
92    if( s.read() == '1' )
93        do { wait(simc); } while ( s.read() == '1' );
94    do { wait(simc); } while ( s.read() == '0' );
95}
96
97void
98at_negedge( const sc_signal_in_if<bool>& s, sc_simcontext* simc )
99{
100    if( s.read() == false )
101        do { wait(simc); } while ( s.read() == false );
102    do { wait(simc); } while ( s.read() == true );
103}
104
105void
106at_negedge( const sc_signal_in_if<sc_dt::sc_logic>& s, sc_simcontext* simc )
107{
108    if( s.read() == '0' )
109        do { wait(simc); } while ( s.read() == '0' );
110    do { wait(simc); } while ( s.read() == '1' );
111}
112
113
114} // namespace sc_core
115
116/*
117$Log: sc_wait_cthread.cpp,v $
118Revision 1.6  2011/08/26 20:46:11  acg
119 Andy Goodrich: moved the modification log to the end of the file to
120 eliminate source line number skew when check-ins are done.
121
122Revision 1.5  2011/02/18 20:27:14  acg
123 Andy Goodrich: Updated Copyrights.
124
125Revision 1.4  2011/02/13 21:47:38  acg
126 Andy Goodrich: update copyright notice.
127
128Revision 1.3  2009/10/14 19:07:42  acg
129 Andy Goodrich: added an error message for wait(n) being called from an
130 SC_METHOD.
131
132Revision 1.2  2008/05/22 17:06:27  acg
133 Andy Goodrich: updated copyright notice to include 2008.
134
135Revision 1.1.1.1  2006/12/15 20:20:05  acg
136SystemC 2.3
137
138Revision 1.3  2006/03/13 20:26:51  acg
139 Andy Goodrich: Addition of forward class declarations, e.g.,
140 sc_reset, to keep gcc 4.x happy.
141
142Revision 1.2  2006/01/03 23:18:45  acg
143Changed copyright to include 2006.
144
145Revision 1.1.1.1  2005/12/19 23:16:44  acg
146First check in of SystemC 2.1 into its own archive.
147
148Revision 1.10  2005/09/15 23:02:18  acg
149Added std:: prefix to appropriate methods and types to get around
150issues with the Edison Front End.
151
152Revision 1.9  2005/09/02 19:03:30  acg
153Changes for dynamic processes. Removal of lambda support.
154
155Revision 1.8  2005/04/04 00:16:08  acg
156Changes for directory name change to sys from systemc.
157Changes for sc_string going to std::string.
158Changes for sc_pvector going to std::vector.
159Changes for reference pools for bit and part selections.
160Changes for const sc_concatref support.
161
162Revision 1.5  2004/09/27 20:49:10  acg
163Andy Goodrich, Forte Design Systems, Inc.
164   - Added a $Log comment so that CVS checkin comments appear in the
165     checkout source.
166
167*/
168
169// Taf!
170