00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2006 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License Version 2.4 (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.systemc.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_wait_cthread.cpp -- Wait() and related functions for SC_CTHREADs. 00021 00022 Original Author: Stan Y. Liao, Synopsys, Inc. 00023 Martin Janssen, Synopsys, Inc. 00024 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 00029 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00030 changes you are making here. 00031 00032 Name, Affiliation, Date: 00033 Description of Modification: 00034 00035 *****************************************************************************/ 00036 00037 /* 00038 $Log: sc_wait_cthread.cpp,v $ 00039 Revision 1.1.1.1 2006/12/15 20:31:37 acg 00040 SystemC 2.2 00041 00042 Revision 1.3 2006/03/13 20:26:51 acg 00043 Andy Goodrich: Addition of forward class declarations, e.g., 00044 sc_reset, to keep gcc 4.x happy. 00045 00046 Revision 1.2 2006/01/03 23:18:45 acg 00047 Changed copyright to include 2006. 00048 00049 Revision 1.1.1.1 2005/12/19 23:16:44 acg 00050 First check in of SystemC 2.1 into its own archive. 00051 00052 Revision 1.10 2005/09/15 23:02:18 acg 00053 Added std:: prefix to appropriate methods and types to get around 00054 issues with the Edison Front End. 00055 00056 Revision 1.9 2005/09/02 19:03:30 acg 00057 Changes for dynamic processes. Removal of lambda support. 00058 00059 Revision 1.8 2005/04/04 00:16:08 acg 00060 Changes for directory name change to sys from systemc. 00061 Changes for sc_string going to std::string. 00062 Changes for sc_pvector going to std::vector. 00063 Changes for reference pools for bit and part selections. 00064 Changes for const sc_concatref support. 00065 00066 Revision 1.5 2004/09/27 20:49:10 acg 00067 Andy Goodrich, Forte Design Systems, Inc. 00068 - Added a $Log comment so that CVS checkin comments appear in the 00069 checkout source. 00070 00071 */ 00072 00073 00074 #include "sysc/kernel/sc_kernel_ids.h" 00075 #include "sysc/kernel/sc_cthread_process.h" 00076 #include "sysc/kernel/sc_simcontext_int.h" 00077 #include "sysc/kernel/sc_wait_cthread.h" 00078 #include "sysc/communication/sc_port.h" 00079 #include "sysc/kernel/sc_wait.h" 00080 namespace sc_core 00081 { 00082 00083 // for SC_CTHREADs 00084 00085 void 00086 halt( sc_simcontext* simc ) 00087 { 00088 sc_curr_proc_handle cpi = simc->get_curr_proc_info(); 00089 switch( cpi->kind ) { 00090 case SC_CTHREAD_PROC_: { 00091 RCAST<sc_cthread_handle>( cpi->process_handle )->wait_halt(); 00092 break; 00093 } 00094 default: 00095 SC_REPORT_ERROR( SC_ID_HALT_NOT_ALLOWED_, 0 ); 00096 break; 00097 } 00098 } 00099 00100 00101 void 00102 wait( int n, sc_simcontext* simc ) 00103 { 00104 sc_curr_proc_handle cpi = simc->get_curr_proc_info(); 00105 if( n <= 0 ) { 00106 char msg[BUFSIZ]; 00107 std::sprintf( msg, "n = %d", n ); 00108 SC_REPORT_ERROR( SC_ID_WAIT_N_INVALID_, msg ); 00109 } 00110 switch( cpi->kind ) { 00111 case SC_THREAD_PROC_: 00112 case SC_CTHREAD_PROC_: 00113 RCAST<sc_cthread_handle>( cpi->process_handle )->wait_cycles( n ); 00114 break; 00115 default: 00116 break; 00117 } 00118 } 00119 00120 00121 void 00122 at_posedge( const sc_signal_in_if<bool>& s, sc_simcontext* simc ) 00123 { 00124 if( s.read() == true ) 00125 do { wait(simc); } while ( s.read() == true ); 00126 do { wait(simc); } while ( s.read() == false ); 00127 } 00128 00129 void 00130 at_posedge( const sc_signal_in_if<sc_dt::sc_logic>& s, sc_simcontext* simc ) 00131 { 00132 if( s.read() == '1' ) 00133 do { wait(simc); } while ( s.read() == '1' ); 00134 do { wait(simc); } while ( s.read() == '0' ); 00135 } 00136 00137 void 00138 at_negedge( const sc_signal_in_if<bool>& s, sc_simcontext* simc ) 00139 { 00140 if( s.read() == false ) 00141 do { wait(simc); } while ( s.read() == false ); 00142 do { wait(simc); } while ( s.read() == true ); 00143 } 00144 00145 void 00146 at_negedge( const sc_signal_in_if<sc_dt::sc_logic>& s, sc_simcontext* simc ) 00147 { 00148 if( s.read() == '0' ) 00149 do { wait(simc); } while ( s.read() == '0' ); 00150 do { wait(simc); } while ( s.read() == '1' ); 00151 } 00152 00153 00154 } // namespace sc_core 00155 00156 // Taf!