00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2005 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_rv.h -- The resolved vector 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 #ifndef SC_SIGNAL_RV_H 00037 #define SC_SIGNAL_RV_H 00038 00039 #include "sysc/communication/sc_signal.h" 00040 #include "sysc/datatypes/bit/sc_lv.h" 00041 00042 namespace sc_core { 00043 00044 class sc_process_b; 00045 00046 00047 // ---------------------------------------------------------------------------- 00048 // CLASS sc_lv_resolve<W> 00049 // 00050 // Resolution function for sc_dt::sc_lv<W>. 00051 // ---------------------------------------------------------------------------- 00052 00053 extern const sc_dt::sc_logic_value_t sc_logic_resolution_tbl[4][4]; 00054 00055 00056 template <int W> 00057 class sc_lv_resolve 00058 { 00059 public: 00060 00061 // resolves sc_dt::sc_lv<W> values and returns the resolved value 00062 static void resolve(sc_dt::sc_lv<W>&, const sc_pvector<sc_dt::sc_lv<W>*>&); 00063 }; 00064 00065 00066 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00067 00068 // resolves sc_dt::sc_lv<W> values and returns the resolved value 00069 00070 template <int W> 00071 inline 00072 void 00073 sc_lv_resolve<W>::resolve( sc_dt::sc_lv<W>& result_, 00074 const sc_pvector<sc_dt::sc_lv<W>*>& values_ ) 00075 { 00076 int sz = values_.size(); 00077 00078 assert( sz != 0 ); 00079 00080 if( sz == 1 ) { 00081 result_ = *values_[0]; 00082 return; 00083 } 00084 00085 for( int j = result_.length() - 1; j >= 0; -- j ) { 00086 sc_dt::sc_logic_value_t res = (*values_[0])[j].value(); 00087 for( int i = sz - 1; i > 0 && res != 3; -- i ) { 00088 res = sc_logic_resolution_tbl[res][(*values_[i])[j].value()]; 00089 } 00090 result_[j] = res; 00091 } 00092 } 00093 00094 00095 // ---------------------------------------------------------------------------- 00096 // CLASS : sc_signal_rv<W> 00097 // 00098 // The resolved vector signal class. 00099 // ---------------------------------------------------------------------------- 00100 00101 template <int W> 00102 class sc_signal_rv 00103 : public sc_signal<sc_dt::sc_lv<W> > 00104 { 00105 public: 00106 00107 // typedefs 00108 00109 typedef sc_signal_rv<W> this_type; 00110 typedef sc_signal<sc_dt::sc_lv<W> > base_type; 00111 typedef sc_dt::sc_lv<W> data_type; 00112 00113 public: 00114 00115 // constructors 00116 00117 sc_signal_rv() 00118 : base_type( sc_gen_unique_name( "signal_rv" ) ) 00119 {} 00120 00121 explicit sc_signal_rv( const char* name_ ) 00122 : base_type( name_ ) 00123 {} 00124 00125 00126 // destructor 00127 virtual ~sc_signal_rv(); 00128 00129 00130 // interface methods 00131 00132 virtual void register_port( sc_port_base&, const char* ) 00133 {} 00134 00135 00136 // write the new value 00137 virtual void write( const data_type& ); 00138 00139 00140 // other methods 00141 00142 this_type& operator = ( const data_type& a ) 00143 { write( a ); return *this; } 00144 00145 this_type& operator = ( const this_type& a ) 00146 { write( a.read() ); return *this; } 00147 00148 virtual const char* kind() const 00149 { return "sc_signal_rv"; } 00150 00151 protected: 00152 00153 virtual void update(); 00154 00155 protected: 00156 00157 sc_pvector<sc_process_b*> m_proc_vec; // processes writing to this signal 00158 sc_pvector<data_type*> m_val_vec; // new values written to this signal 00159 00160 private: 00161 00162 // disabled 00163 sc_signal_rv( const this_type& ); 00164 }; 00165 00166 00167 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00168 00169 00170 // destructor 00171 00172 template <int W> 00173 inline 00174 sc_signal_rv<W>::~sc_signal_rv() 00175 { 00176 for( int i = m_val_vec.size() - 1; i >= 0; -- i ) { 00177 delete m_val_vec[i]; 00178 } 00179 } 00180 00181 00182 // write the new value 00183 00184 template <int W> 00185 inline 00186 void 00187 sc_signal_rv<W>::write( const data_type& value_ ) 00188 { 00189 sc_process_b* cur_proc = sc_get_curr_process_handle(); 00190 00191 bool value_changed = false; 00192 bool found = false; 00193 00194 for( int i = m_proc_vec.size() - 1; i >= 0; -- i ) { 00195 if( cur_proc == m_proc_vec[i] ) { 00196 if( value_ != *m_val_vec[i] ) { 00197 *m_val_vec[i] = value_; 00198 value_changed = true; 00199 } 00200 found = true; 00201 break; 00202 } 00203 } 00204 00205 if( ! found ) { 00206 m_proc_vec.push_back( cur_proc ); 00207 m_val_vec.push_back( new data_type( value_ ) ); 00208 value_changed = true; 00209 } 00210 00211 if( value_changed ) { 00212 this->request_update(); 00213 } 00214 } 00215 00216 00217 template <int W> 00218 inline 00219 void 00220 sc_signal_rv<W>::update() 00221 { 00222 sc_lv_resolve<W>::resolve( this->m_new_val, m_val_vec ); 00223 base_type::update(); 00224 } 00225 00226 } // namespace sc_core 00227 00228 #endif 00229 00230 // Taf!
1.5.1