rc_sc_signal.h

Go to the documentation of this file.
00001 // vim:set et sts=4 ts=4 tw=75 sw=4 ai ci cin cino=g0,t0:
00002 /*
00003  * Copyright (C) 2007, Technical Computer Science Group,
00004  *                     University of Bonn
00005  *
00006  * This file is part of the ReChannel library.
00007  *
00008  * The ReChannel library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be
00014  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this library; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022  *
00023  * Authors: Andreas Raabe and Armin Felke. Implementation by Armin Felke.
00024  *          {raabe, felke}@cs.uni-bonn.de
00025  */
00037 #ifndef RC_SC_SIGNAL_H_
00038 #define RC_SC_SIGNAL_H_
00039 
00040 #include "ReChannel/core/rc_reconfigurable.h"
00041 #include "ReChannel/core/rc_resettable.h"
00042 #include "ReChannel/communication/exportals/rc_signal_exportals.h"
00043 #include "ReChannel/core/rc_reset_channel_if.h"
00044 
00045 namespace ReChannel {
00046 
00050 template<class T, class SIGNAL=sc_signal<T> >
00051 class rc_sc_signal_b
00052     : public sc_channel,
00053       virtual public sc_signal_inout_if<T>,
00054       virtual public rc_resettable
00055 {
00056 protected:
00057     typedef sc_signal_inout_if<T> if_type;
00058     typedef SIGNAL                signal_type;
00059 
00060 protected:
00061 
00062 /* constructor */
00063 
00064     explicit rc_sc_signal_b(const sc_module_name& name_);
00065 
00066 public:
00067 
00068 /* interface methods */
00069 
00070     virtual void register_port(sc_port_base& port_, const char* if_name_)
00071         { return m_signal.register_port(port_, if_name_); }
00072 
00073     virtual const T& read() const
00074         { return get_if().read(); }
00075 
00076     virtual const T& get_data_ref() const
00077         { return get_if().get_data_ref(); }
00078 
00079     virtual void write(const T& value)
00080     {
00081         if (!p_constr_done) { m_reset_value = value; }
00082         get_if().write(value);
00083     }
00084 
00085     virtual const sc_event& default_event() const
00086         { return get_exportal_if().default_event(); }
00087 
00088     virtual const sc_event& value_changed_event() const
00089         { return get_exportal_if().value_changed_event(); }
00090 
00091 /* other channel methods */
00092 
00093     virtual bool event() const
00094         { return m_signal.event(); }
00095 
00096     virtual void print(std::ostream& sout=std::cout) const
00097         { m_signal.print(sout); }
00098 
00099     virtual void dump(std::ostream& sout=std::cout) const
00100         { m_signal.dump(sout); }
00101 
00102     virtual const char* kind() const
00103         { return m_signal.kind(); }
00104 
00105 protected:
00106 
00107     virtual void end_of_elaboration()
00108     {
00109         //p_if = &((if_type&)p_exportal.static_export());
00110     }
00111 
00112     virtual void start_of_simulation()
00113     {
00114         p_constr_done = true;
00115     }
00116 
00117     RC_ON_RESET()
00118     {
00119         driver_write(m_reset_value);
00120     }
00121 
00122     RC_ON_INIT_RESETTABLE() { }
00123 
00124 protected:
00125 
00126     inline if_type& get_if();
00127 
00128     inline if_type& get_exportal_if() const
00129         { return *p_if; }
00130 
00131     inline const if_type& get_if() const;
00132 
00133     inline void driver_write(const T& value, int index=0);
00134 
00135     inline int get_driver_count() const
00136         { return p_interface_wrapper->get_nb_driver_count(); }
00137 
00138 protected:
00139     signal_type                    m_signal;
00140     T                              m_reset_value;
00141 
00142 private:
00143     rc_exportal<if_type>           p_exportal;
00144     rc_interface_wrapper<if_type>* p_interface_wrapper;
00145     const rc_reconfigurable*       p_reconf;
00146     if_type*                       p_if;
00147     bool                           p_constr_done;
00148 };
00149 
00153 template<class T>
00154 class rc_sc_signal
00155     : public rc_sc_signal_b<T>
00156 {
00157 private:
00158     typedef rc_sc_signal_b<T> base_type;
00159 
00160 public:
00161     explicit rc_sc_signal(
00162         const sc_module_name& name_=sc_gen_unique_name("signal"))
00163         : base_type(name_)
00164     { }
00165 
00166     operator const T&() const
00167         { return this->read(); }
00168 
00169     rc_sc_signal<T>& operator= (const T& value)
00170         { this->write(value); return *this; }
00171 
00172     rc_sc_signal<T>& operator= (const rc_sc_signal<T>& signal_)
00173         { this->write(signal_); return *this; }
00174 };
00175 
00179 template<>
00180 class rc_sc_signal<bool>
00181     : public rc_sc_signal_b<bool, internals::reset_signal>,
00182       virtual public rc_reset_channel_if
00183 {
00184 private:
00185     typedef rc_sc_signal_b<bool, internals::reset_signal>
00186         base_type;
00187 
00188 public:
00189     explicit rc_sc_signal(
00190         const sc_module_name& name_=sc_gen_unique_name("signal"))
00191         : base_type(name_)
00192     { }
00193 
00194 /* interface methods */
00195 
00196     virtual bool posedge() const
00197         { return get_if().posedge(); }
00198 
00199     virtual bool negedge() const
00200         { return get_if().negedge(); }
00201 
00202     virtual const sc_event& posedge_event() const
00203         { return get_exportal_if().posedge_event(); }
00204 
00205     virtual const sc_event& negedge_event() const
00206         { return get_exportal_if().negedge_event(); }
00207 
00208 #if !defined(RC_USE_NON_OSCI_KERNEL)
00209     virtual sc_reset* is_reset() const
00210         { return m_signal.is_reset(); }
00211 #endif // !defined(RC_USE_NON_OSCI_KERNEL)
00212 
00213 protected:
00214     virtual void register_process_control(
00215         rc_process_control& pctrl, bool reset_level) const
00216     {
00217         m_signal.register_process_control(pctrl, reset_level);
00218     }
00219 
00220     virtual void unregister_process_control(
00221         rc_process_control& pctrl) const
00222     {
00223         m_signal.unregister_process_control(pctrl);
00224     }
00225 
00226     virtual bool get_current_level() const
00227         { return m_signal.read(); }
00228 
00229     virtual const sc_signal<bool>* get_underlying_reset_signal() const
00230         { return &m_signal; }
00231 
00232 /* other channel methods */
00233 
00234 public:
00235     operator const bool&() const
00236         { return this->read(); }
00237 
00238     rc_sc_signal<bool>& operator= (const bool& value)
00239         { this->write(value); return *this; }
00240 
00241     rc_sc_signal<bool>& operator= (const rc_sc_signal<bool>& signal_)
00242         { this->write(signal_); return *this; }
00243 };
00244 
00248 template<>
00249 class rc_sc_signal<sc_logic>
00250     : public rc_sc_signal_b<sc_logic>
00251 {
00252 private:
00253     typedef rc_sc_signal_b<sc_logic> base_type;
00254 
00255 public:
00256     explicit rc_sc_signal(
00257         const sc_module_name& name_=sc_gen_unique_name("signal"))
00258         : base_type(name_)
00259     { }
00260 
00261 /* interface methods */
00262 
00263     virtual bool posedge() const
00264         { return get_if().posedge(); }
00265 
00266     virtual bool negedge() const
00267         { return get_if().negedge(); }
00268 
00269     virtual const sc_event& posedge_event() const
00270         { return get_exportal_if().posedge_event(); }
00271 
00272     virtual const sc_event& negedge_event() const
00273         { return get_exportal_if().negedge_event(); }
00274 
00275 /* other channel methods */
00276 
00277     operator const sc_logic&() const
00278         { return this->read(); }
00279 
00280     rc_sc_signal<sc_logic>& operator= (const sc_logic& value)
00281         { this->write(value); return *this; }
00282 
00283     rc_sc_signal<sc_logic>& operator= (const rc_sc_signal<sc_logic>& signal_)
00284         { this->write(signal_); return *this; }
00285 };
00286 
00287 /* inline code */
00288 
00289 template<class T, class SIGNAL>
00290 inline
00291 typename rc_sc_signal_b<T, SIGNAL>::if_type&
00292 rc_sc_signal_b<T, SIGNAL>::get_if()
00293 {
00294     if (p_reconf != NULL && p_constr_done) {
00295         return *p_if;
00296     } else {
00297         return m_signal;
00298     }
00299 }
00300 
00301 template<class T, class SIGNAL>
00302 inline
00303 const typename rc_sc_signal_b<T, SIGNAL>::if_type&
00304 rc_sc_signal_b<T, SIGNAL>::get_if() const
00305 {
00306     if (p_reconf != NULL && p_constr_done) {
00307         return *p_if;
00308     } else {
00309         return m_signal;
00310     }
00311 }
00312 
00313 template<class T, class SIGNAL>
00314 inline
00315 void rc_sc_signal_b<T, SIGNAL>::driver_write(const T& value, int index)
00316 {
00317     p_interface_wrapper->get_nb_driver_access(index)->call(
00318         &if_type::write, value);
00319 }
00320 
00321 /* template code */
00322 
00323 template<class T, class SIGNAL>
00324 rc_sc_signal_b<T, SIGNAL>::rc_sc_signal_b(const sc_module_name& name_)
00325     : sc_channel(name_),
00326       m_signal(name_), m_reset_value(m_signal.read()),
00327       p_exportal("_rc_exportal"), p_interface_wrapper(NULL), p_if(NULL),
00328       p_constr_done(false)
00329 {
00330     p_interface_wrapper = &p_exportal.bind_exclusively(m_signal);
00331     p_reconf = rc_register_resettable(*this, this->get_parent_object());
00332     p_if = &((if_type&)p_exportal.static_export());
00333 }
00334 
00335 } // namespace ReChannel
00336 
00337 #endif // RC_SC_SIGNAL_H_
00338 
00339 //
00340 // $Id: rc_sc_signal.h,v 1.10 2007/11/23 13:25:45 felke Exp $
00341 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/components/rc_sc_signal.h,v $
00342 //

Generated on Tue Jan 1 23:13:55 2008 for ReChannel by  doxygen 1.5.3