rc_sc_fifo.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_FIFO_H_
00038 #define RC_SC_FIFO_H_
00039 
00040 #include "ReChannel/core/rc_reconfigurable.h"
00041 #include "ReChannel/core/rc_resettable.h"
00042 #include "ReChannel/communication/exportals/rc_fifo_exportals.h"
00043 
00044 namespace ReChannel {
00045 
00049 template<class T>
00050 class rc_sc_fifo
00051     : public sc_channel,
00052       virtual public sc_fifo_in_if<T>,
00053       virtual public sc_fifo_out_if<T>,
00054       virtual public rc_resettable
00055 {
00056 public:
00057 
00058 /* constructors */
00059 
00060     explicit rc_sc_fifo(int n=16);
00061 
00062     rc_sc_fifo(const sc_module_name& name_, int n=16);
00063 
00064 /* interface methods */
00065 
00066     virtual void register_port(sc_port_base& port_, const char* if_name_)
00067         { return p_fifo.register_port(port_, if_name_); }
00068 
00069     virtual bool nb_read(T& value)
00070         { return get_in_if().nb_read(value); }
00071 
00072     virtual void read(T& value)
00073         { get_in_if().read(value); }
00074 
00075     virtual T read()
00076         { return get_in_if().read(); }
00077 
00078     virtual int num_available() const
00079         { return get_in_if().num_available(); }
00080 
00081     virtual const sc_event& data_written_event() const
00082         { return get_in_exportal_if().data_written_event(); }
00083 
00084     virtual bool nb_write(const T& value)
00085         { return get_out_if().nb_write(value); }
00086 
00087     virtual void write(const T& value)
00088         { get_out_if().write(value); }
00089 
00090     virtual int num_free() const
00091         { return get_out_if().num_free(); }
00092 
00093     virtual const sc_event& data_read_event() const
00094         { return get_out_exportal_if().data_read_event(); }
00095 
00096 /* other channel methods */
00097 
00098     operator T()
00099         { return this->read(); }
00100 
00101     rc_sc_fifo<T>& operator=(const T& value)
00102         { this->write(value); return *this; }
00103 
00104     virtual void print(std::ostream& sout=std::cout) const
00105         { p_fifo.print(sout); }
00106 
00107     virtual void dump(std::ostream& sout=std::cout) const
00108         { p_fifo.dump(sout); }
00109 
00110     virtual const char* kind() const
00111         { return p_fifo.kind(); }
00112 
00113 protected:
00114 
00115     virtual void start_of_simulation()
00116     {
00117         p_constr_done = true;
00118     }
00119 
00120     RC_ON_RESET()
00121     {
00122         // clear the FIFO
00123         T dummy;
00124         while(p_fifo.nb_read(dummy))
00125         { }
00126     }
00127 
00128     RC_ON_INIT_RESETTABLE() { }
00129 
00130 private:
00131 
00132     inline sc_fifo_in_if<T>& get_in_if();
00133 
00134     inline const sc_fifo_in_if<T>& get_in_if() const;
00135 
00136     inline sc_fifo_in_if<T>& get_in_exportal_if() const
00137         { return *p_in_if; }
00138 
00139     inline sc_fifo_out_if<T>& get_out_if();
00140 
00141     inline const sc_fifo_out_if<T>& get_out_if() const;
00142 
00143     inline sc_fifo_out_if<T>& get_out_exportal_if() const
00144         { return *p_out_if; }
00145 
00146 private:
00147     sc_fifo<T>                      p_fifo;
00148     rc_exportal<sc_fifo_in_if<T> >  p_exp_in;
00149     rc_exportal<sc_fifo_out_if<T> > p_exp_out;
00150     const rc_reconfigurable*        p_reconf;
00151     sc_fifo_in_if<T>*               p_in_if;
00152     sc_fifo_out_if<T>*              p_out_if;
00153     bool                            p_constr_done;
00154 };
00155 
00156 /* inline code */
00157 
00158 template<class T>
00159 inline
00160 sc_fifo_in_if<T>& rc_sc_fifo<T>::get_in_if()
00161 {
00162     if (p_reconf != NULL && p_constr_done) {
00163         return *p_in_if;
00164     } else {
00165         return p_fifo;
00166     }
00167 }
00168 
00169 template<class T>
00170 inline
00171 const sc_fifo_in_if<T>& rc_sc_fifo<T>::get_in_if() const
00172 {
00173     if (p_reconf != NULL && p_constr_done) {
00174         return *p_in_if;
00175     } else {
00176         return p_fifo;
00177     }
00178 }
00179 
00180 template<class T>
00181 inline
00182 sc_fifo_out_if<T>& rc_sc_fifo<T>::get_out_if()
00183 {
00184     if (p_reconf != NULL && p_constr_done) {
00185         return *p_out_if;
00186     } else {
00187         return p_fifo;
00188     }
00189 }
00190 
00191 template<class T>
00192 inline
00193 const sc_fifo_out_if<T>& rc_sc_fifo<T>::get_out_if() const
00194 {
00195     if (p_reconf != NULL && p_constr_done) {
00196         return *p_out_if;
00197     } else {
00198         return p_fifo;
00199     }
00200 }
00201 
00202 /* template code */
00203 
00204 template<class T>
00205 rc_sc_fifo<T>::rc_sc_fifo(int n)
00206     : sc_channel(sc_module_name(sc_gen_unique_name("fifo"))),
00207       p_fifo(n),
00208       p_exp_in("_rc_exportal_in"), p_exp_out("_rc_exportal_out"),
00209       p_in_if(NULL), p_out_if(NULL), p_constr_done(false)
00210 {
00211     p_exp_in.bind_exclusively(p_fifo);
00212     p_exp_out.bind_exclusively(p_fifo);
00213     p_reconf = rc_register_resettable(*this, this->get_parent_object());
00214     p_in_if = &p_exp_in.static_export();
00215     p_out_if = &p_exp_out.static_export();
00216 }
00217 
00218 template<class T>
00219 rc_sc_fifo<T>::rc_sc_fifo(const sc_module_name& name_, int n)
00220     : sc_channel(name_),
00221       p_fifo(name_, n),
00222       p_exp_in("_rc_exportal_in"), p_exp_out("_rc_exportal_out"),
00223       p_in_if(NULL), p_out_if(NULL), p_constr_done(false)
00224 {
00225     p_exp_in.bind_exclusively(p_fifo);
00226     p_exp_out.bind_exclusively(p_fifo);
00227     p_reconf = rc_register_resettable(*this, this->get_parent_object());
00228     p_in_if = &p_exp_in.static_export();
00229     p_out_if = &p_exp_out.static_export();
00230 }
00231 
00232 } // namespace ReChannel
00233 
00234 #endif //RC_SC_FIFO_H_
00235 
00236 //
00237 // $Id: rc_sc_fifo.h,v 1.7 2007/11/23 13:25:45 felke Exp $
00238 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/components/rc_sc_fifo.h,v $
00239 //

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