sc_signal_rv.h

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_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 //$Log: sc_signal_rv.h,v $
00036 //Revision 1.1.1.1  2006/12/15 20:31:35  acg
00037 //SystemC 2.2
00038 //
00039 //Revision 1.3  2006/03/21 00:00:27  acg
00040 //  Andy Goodrich: changed name of sc_get_current_process_base() to be
00041 //  sc_get_current_process_b() since its returning an sc_process_b instance.
00042 //
00043 //Revision 1.2  2006/01/03 23:18:26  acg
00044 //Changed copyright to include 2006.
00045 //
00046 //Revision 1.1.1.1  2005/12/19 23:16:43  acg
00047 //First check in of SystemC 2.1 into its own archive.
00048 //
00049 //Revision 1.10  2005/09/15 23:01:52  acg
00050 //Added std:: prefix to appropriate methods and types to get around
00051 //issues with the Edison Front End.
00052 //
00053 //Revision 1.9  2005/06/10 22:43:55  acg
00054 //Added CVS change log annotation.
00055 //
00056 
00057 #ifndef SC_SIGNAL_RV_H
00058 #define SC_SIGNAL_RV_H
00059 
00060 #include "sysc/communication/sc_signal.h"
00061 #include "sysc/datatypes/bit/sc_lv.h"
00062 
00063 namespace sc_core {
00064 
00065 class sc_process_b;
00066 
00067 
00068 // ----------------------------------------------------------------------------
00069 //  CLASS sc_lv_resolve<W>
00070 //
00071 //  Resolution function for sc_dt::sc_lv<W>.
00072 // ----------------------------------------------------------------------------
00073 
00074 extern const sc_dt::sc_logic_value_t sc_logic_resolution_tbl[4][4];
00075 
00076 
00077 template <int W>
00078 class sc_lv_resolve
00079 {
00080 public:
00081 
00082     // resolves sc_dt::sc_lv<W> values and returns the resolved value
00083     static void resolve(sc_dt::sc_lv<W>&, const std::vector<sc_dt::sc_lv<W>*>&);
00084 };
00085 
00086 
00087 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00088 
00089 // resolves sc_dt::sc_lv<W> values and returns the resolved value
00090 
00091 template <int W>
00092 inline
00093 void
00094 sc_lv_resolve<W>::resolve( sc_dt::sc_lv<W>& result_,
00095                const std::vector<sc_dt::sc_lv<W>*>& values_ )
00096 {
00097     int sz = values_.size();
00098 
00099     assert( sz != 0 );
00100 
00101     if( sz == 1 ) {
00102     result_ = *values_[0];
00103     return;
00104     }
00105 
00106     for( int j = result_.length() - 1; j >= 0; -- j ) {
00107     sc_dt::sc_logic_value_t res = (*values_[0])[j].value();
00108     for( int i = sz - 1; i > 0 && res != 3; -- i ) {
00109         res = sc_logic_resolution_tbl[res][(*values_[i])[j].value()];
00110     }
00111     result_[j] = res;
00112     }
00113 }
00114 
00115 
00116 // ----------------------------------------------------------------------------
00117 //  CLASS : sc_signal_rv<W>
00118 //
00119 //  The resolved vector signal class.
00120 // ----------------------------------------------------------------------------
00121 
00122 template <int W>
00123 class sc_signal_rv
00124 : public sc_signal<sc_dt::sc_lv<W> >
00125 {
00126 public:
00127 
00128     // typedefs
00129 
00130     typedef sc_signal_rv<W>             this_type;
00131     typedef sc_signal<sc_dt::sc_lv<W> > base_type;
00132     typedef sc_dt::sc_lv<W>             data_type;
00133 
00134 public:
00135 
00136     // constructors
00137 
00138     sc_signal_rv()
00139         : base_type( sc_gen_unique_name( "signal_rv" ) )
00140     {}
00141 
00142     explicit sc_signal_rv( const char* name_ )
00143         : base_type( name_ )
00144     {}
00145 
00146 
00147     // destructor
00148     virtual ~sc_signal_rv();
00149 
00150 
00151     // interface methods
00152 
00153     virtual void register_port( sc_port_base&, const char* )
00154     {}
00155 
00156 
00157     // write the new value
00158     virtual void write( const data_type& );
00159 
00160 
00161     // other methods
00162 
00163     this_type& operator = ( const data_type& a )
00164         { write( a ); return *this; }
00165 
00166     this_type& operator = ( const this_type& a )
00167         { write( a.read() ); return *this; }
00168 
00169     virtual const char* kind() const
00170         { return "sc_signal_rv"; }
00171 
00172 protected:
00173 
00174     virtual void update();
00175 
00176 protected:
00177 
00178     std::vector<sc_process_b*> m_proc_vec; // processes writing this signal
00179     std::vector<data_type*>       m_val_vec;  // new values written this signal
00180 
00181 private:
00182 
00183     // disabled
00184     sc_signal_rv( const this_type& );
00185 };
00186 
00187 
00188 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00189 
00190 
00191 // destructor
00192 
00193 template <int W>
00194 inline
00195 sc_signal_rv<W>::~sc_signal_rv()
00196 {
00197     for( int i = m_val_vec.size() - 1; i >= 0; -- i ) {
00198     delete m_val_vec[i];
00199     }
00200 }
00201 
00202 
00203 // write the new value
00204 
00205 template <int W>
00206 inline
00207 void
00208 sc_signal_rv<W>::write( const data_type& value_ )
00209 {
00210     sc_process_b* cur_proc = sc_get_current_process_b();
00211 
00212     bool value_changed = false;
00213     bool found = false;
00214     
00215     for( int i = m_proc_vec.size() - 1; i >= 0; -- i ) {
00216     if( cur_proc == m_proc_vec[i] ) {
00217         if( value_ != *m_val_vec[i] ) {
00218         *m_val_vec[i] = value_;
00219         value_changed = true;
00220         }
00221         found = true;
00222         break;
00223     }
00224     }
00225     
00226     if( ! found ) {
00227     m_proc_vec.push_back( cur_proc );
00228     m_val_vec.push_back( new data_type( value_ ) );
00229     value_changed = true;
00230     }
00231     
00232     if( value_changed ) {
00233     this->request_update();
00234     }
00235 }
00236 
00237 
00238 template <int W>
00239 inline
00240 void
00241 sc_signal_rv<W>::update()
00242 {
00243     sc_lv_resolve<W>::resolve( this->m_new_val, m_val_vec );
00244     base_type::update();
00245 }
00246 
00247 } // namespace sc_core
00248 
00249 #endif
00250 
00251 // Taf!

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