sc_signal_resolved.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-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_signal_resolved.cpp -- The resolved signal class.
00021 
00022   Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
00023 
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027 
00028   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00029   changes you are making here.
00030 
00031       Name, Affiliation, Date:
00032   Description of Modification:
00033     
00034  *****************************************************************************/
00035 
00036 
00037 // $Log: sc_signal_resolved.cpp,v $
00038 // Revision 1.1.1.1  2006/12/15 20:31:35  acg
00039 // SystemC 2.2
00040 //
00041 // Revision 1.4  2006/03/21 00:00:27  acg
00042 //   Andy Goodrich: changed name of sc_get_current_process_base() to be
00043 //   sc_get_current_process_b() since its returning an sc_process_b instance.
00044 //
00045 // Revision 1.3  2006/01/13 18:47:42  acg
00046 // Added $Log command so that CVS comments are reproduced in the source.
00047 //
00048 
00049 #include "sysc/communication/sc_signal_resolved.h"
00050 
00051 namespace sc_core {
00052 
00053 // Note that we assume that two drivers driving the resolved signal to a 1 or
00054 // 0 is O.K. This might not be true for all technologies, but is certainly
00055 // true for CMOS, the predominant technology in use today.
00056 
00057 const sc_dt::sc_logic_value_t
00058 sc_logic_resolution_tbl[4][4] =
00059 {   //    0      1      Z      X
00060     { sc_dt::Log_0, sc_dt::Log_X, sc_dt::Log_0, sc_dt::Log_X }, // 0
00061     { sc_dt::Log_X, sc_dt::Log_1, sc_dt::Log_1, sc_dt::Log_X }, // 1
00062     { sc_dt::Log_0, sc_dt::Log_1, sc_dt::Log_Z, sc_dt::Log_X }, // Z
00063     { sc_dt::Log_X, sc_dt::Log_X, sc_dt::Log_X, sc_dt::Log_X }  // X
00064 };
00065 
00066 
00067 // ----------------------------------------------------------------------------
00068 //  CLASS : sc_logic_resolve
00069 //
00070 //  Resolution function for sc_dt::sc_logic.
00071 // ----------------------------------------------------------------------------
00072 
00073 // resolves sc_dt::sc_logic values and returns the resolved value
00074 
00075 void
00076 sc_logic_resolve::resolve( sc_dt::sc_logic& result_,
00077                const std::vector<sc_dt::sc_logic*>& values_ )
00078 {
00079     int sz = values_.size();
00080 
00081     assert( sz != 0 );
00082 
00083     if( sz == 1 ) {
00084     result_ = *values_[0];
00085     return;
00086     }
00087 
00088     sc_dt::sc_logic_value_t res = values_[0]->value();
00089     for( int i = sz - 1; i > 0 && res != 3; -- i ) {
00090     res = sc_logic_resolution_tbl[res][values_[i]->value()];
00091     }
00092     result_ = res;
00093 }
00094 
00095 
00096 // ----------------------------------------------------------------------------
00097 //  CLASS : sc_signal_resolved
00098 //
00099 //  The resolved signal class.
00100 // ----------------------------------------------------------------------------
00101 
00102 // destructor
00103 
00104 sc_signal_resolved::~sc_signal_resolved()
00105 {
00106     for( int i = m_val_vec.size() - 1; i >= 0; -- i ) {
00107     delete m_val_vec[i];
00108     }
00109 }
00110 
00111 
00112 // write the new value
00113 
00114 void
00115 sc_signal_resolved::write( const data_type& value_ )
00116 {
00117     sc_process_b* cur_proc = sc_get_current_process_b();
00118 
00119     bool value_changed = false;
00120     bool found = false;
00121     
00122     for( int i = m_proc_vec.size() - 1; i >= 0; -- i ) {
00123     if( cur_proc == m_proc_vec[i] ) {
00124         if( value_ != *m_val_vec[i] ) {
00125         *m_val_vec[i] = value_;
00126         value_changed = true;
00127         }
00128         found = true;
00129         break;
00130     }
00131     }
00132     
00133     if( ! found ) {
00134     m_proc_vec.push_back( cur_proc );
00135     m_val_vec.push_back( new data_type( value_ ) );
00136     value_changed = true;
00137     }
00138     
00139     if( value_changed ) {
00140     request_update();
00141     }
00142 }
00143 
00144 
00145 void
00146 sc_signal_resolved::update()
00147 {
00148     sc_logic_resolve::resolve( m_new_val, m_val_vec );
00149     base_type::update();
00150 }
00151 
00152 
00153 } // namespace sc_core
00154 
00155 // Taf!

Generated on Wed Jan 21 15:32:06 2009 for SystemC by  doxygen 1.5.5