Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

sc_wait_cthread.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2004 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.3 (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 #include "systemc/kernel/sc_kernel_ids.h"
00039 #include "systemc/kernel/sc_process_int.h"
00040 #include "systemc/kernel/sc_simcontext_int.h"
00041 #include "systemc/kernel/sc_wait_cthread.h"
00042 #include "systemc/communication/sc_port.h"
00043 
00044 
00045 // for SC_CTHREADs
00046 
00047 void
00048 halt( sc_simcontext* simc )
00049 {
00050     sc_curr_proc_handle cpi = simc->get_curr_proc_info();
00051     switch( cpi->kind ) {
00052     case SC_CTHREAD_PROC_: {
00053   RCAST<sc_cthread_handle>( cpi->process_handle )->wait_halt();
00054   break;
00055     }
00056     default:
00057   SC_REPORT_ERROR( SC_ID_HALT_NOT_ALLOWED_, 0 );
00058   break;
00059     }
00060 }
00061 
00062 
00063 void
00064 wait( int n, sc_simcontext* simc )
00065 {
00066     sc_curr_proc_handle cpi = simc->get_curr_proc_info();
00067     switch( cpi->kind ) {
00068     case SC_CTHREAD_PROC_: {
00069         if( n <= 0 ) {
00070             char msg[BUFSIZ];
00071             sprintf( msg, "n = %d", n );
00072             SC_REPORT_ERROR( SC_ID_WAIT_N_INVALID_, msg );
00073         }
00074   RCAST<sc_cthread_handle>( cpi->process_handle )->wait_clock( n );
00075         break;
00076     }
00077     default:
00078   SC_REPORT_ERROR( SC_ID_WAIT_N_NOT_ALLOWED_, 0 );
00079         break;
00080     }
00081 }
00082 
00083 
00084 void
00085 wait_until( const sc_lambda_ptr& lambda, sc_simcontext* simc )
00086 {
00087     sc_curr_proc_handle cpi = simc->get_curr_proc_info();
00088     switch( cpi->kind ) {
00089     case SC_CTHREAD_PROC_: {
00090   RCAST<sc_cthread_handle>( cpi->process_handle )->wait_lambda( lambda );
00091         break;
00092     }
00093     default:
00094   SC_REPORT_ERROR( SC_ID_WAIT_UNTIL_NOT_ALLOWED_, 0 );
00095         break;
00096     }
00097 }
00098 
00099 
00100 void
00101 at_posedge( const sc_signal_in_if<bool>& s, sc_simcontext* simc )
00102 {
00103     if( s.read() ) {
00104         wait_until( s.delayed() == false, simc );
00105         wait_until( s.delayed(), simc );
00106     } else {
00107         wait_until( s.delayed(), simc );
00108     }
00109 }
00110 
00111 void
00112 at_posedge( const sc_signal_in_if<sc_logic>& s, sc_simcontext* simc )
00113 {
00114     if( s.read() == '1' ) {
00115         wait_until( s.delayed() == '0', simc );
00116         wait_until( s.delayed() == '1', simc );
00117     } else {
00118         wait_until( s.delayed() == '1', simc );
00119     }
00120 }
00121 
00122 void
00123 at_negedge( const sc_signal_in_if<bool>& s, sc_simcontext* simc )
00124 {
00125     if( ! s.read() ) {
00126         wait_until( s.delayed(), simc );
00127         wait_until( s.delayed() == false, simc );
00128     } else {
00129         wait_until( s.delayed() == false, simc );
00130     }
00131 }
00132 
00133 void
00134 at_negedge( const sc_signal_in_if<sc_logic>& s, sc_simcontext* simc )
00135 {
00136     if( s.read() == '0' ) {
00137         wait_until( s.delayed() == '1', simc );
00138         wait_until( s.delayed() == '0', simc );
00139     } else {
00140         wait_until( s.delayed() == '0', simc );
00141     }
00142 }
00143 
00144 
00145 void
00146 watching_before_simulation( const sc_lambda_ptr& lambda, sc_simcontext* simc )
00147 {
00148     simc->get_port_registry()->add_lambda_for_resolution( lambda );
00149     sc_process_b* last_proc = sc_get_last_created_process_handle();
00150     
00151     if (!last_proc) return;
00152     if ( last_proc->is_cthread() ) {
00153   RCAST<sc_cthread_handle>( last_proc )->add_lambda( lambda );
00154     } else {
00155   SC_REPORT_ERROR( SC_ID_WATCHING_NOT_ALLOWED_, 0 );
00156     }
00157 }
00158 
00159 void
00160 watching_during_simulation( const sc_lambda_ptr& lambda, sc_simcontext* simc )
00161 {
00162     sc_curr_proc_handle cpi = simc->get_curr_proc_info();
00163     switch( cpi->kind ) {
00164     case SC_CTHREAD_PROC_: {
00165   RCAST<sc_cthread_handle>( cpi->process_handle )->add_lambda( lambda );
00166         break;
00167     }
00168     default:
00169   SC_REPORT_ERROR( SC_ID_WATCHING_NOT_ALLOWED_, 0 );
00170         break;
00171     }
00172 }
00173  
00174 
00175 void
00176 __reset_watching( sc_cthread_handle cthread_h )
00177 {
00178     cthread_h->__reset_watching();
00179 }
00180 
00181 void
00182 __open_watching( sc_cthread_handle cthread_h )
00183 {
00184     cthread_h->__open_watching();
00185 }
00186 
00187 void
00188 __close_watching( sc_cthread_handle cthread_h )
00189 {
00190     cthread_h->__close_watching();
00191     assert( cthread_h->__watch_level() >= 0 );
00192 }
00193 
00194 int
00195 __watch_level( sc_cthread_handle cthread_h )
00196 {
00197     return cthread_h->__watch_level();
00198 }
00199 
00200 void
00201 __watching_first( sc_cthread_handle cthread_h )
00202 {
00203     if( cthread_h->eval_watchlist_curr_level() ) {
00204         throw cthread_h->m_exception_level;
00205     }
00206 }
00207 
00208 void
00209 __sanitycheck_watchlists( sc_cthread_handle cthread_h )
00210 {
00211     assert( cthread_h->m_watchlists[cthread_h->__watch_level()]->empty() );
00212 }
00213 
00214 
00215 // Taf!

Generated on Fri Jan 14 08:29:09 2005 for SystemC2.1beta11(excludingMSLib)(IncludingSCV)\nProvidedby:www.openverificationfoundation.org by doxygen1.2.18