rc_signal_accessors.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  */
00039 #ifndef RC_SIGNAL_ACCESSORS_H_
00040 #define RC_SIGNAL_ACCESSORS_H_
00041 
00042 #include "ReChannel/communication/accessors/rc_accessor.h"
00043 #include "ReChannel/core/rc_reset_channel_if.h"
00044 
00045 namespace ReChannel {
00046 
00050 template<class T>
00051 class rc_fallback_interface<sc_signal_in_if<T> >
00052 : virtual public sc_signal_in_if<T>
00053 {
00054 public:
00055     rc_fallback_interface()
00056         : p_value(rc_undefined_value<T>())
00057     { }
00058     virtual const T& read() const
00059         { return p_value; }
00060     virtual const T& get_data_ref() const
00061         { return p_value; }
00062     virtual bool event() const
00063         { return false; }
00064     virtual bool posedge() const
00065         { return false; }
00066     virtual bool negedge() const
00067         { return false; }
00068 #if !defined(RC_USE_NON_OSCI_KERNEL)
00069     virtual sc_reset* is_reset() const
00070     {
00071         RC_REPORT_ERROR(RC_ID_NOT_IMPLEMENTED_,
00072             "'sc_reset* ReChannel::rc_fallback_interface"
00073             "<sc_signal_inout_if<T> >::is_reset() const'"
00074             " not implemented");
00075     }
00076 #endif // !defined(RC_USE_NON_OSCI_KERNEL)
00077     virtual const sc_event& default_event() const
00078     {
00079         SC_REPORT_WARNING(RC_ID_UNDEFINED_EVENT_WARNING_, 0);
00080         return p_undef;
00081     }
00082     virtual const sc_event& value_changed_event() const
00083         { return default_event(); }
00084     virtual const sc_event& posedge_event() const
00085         { return default_event(); }
00086     virtual const sc_event& negedge_event() const
00087         { return default_event(); }
00088 private:
00089     T        p_value;
00090     sc_event p_undef;
00091 };
00092 
00096 template<class T>
00097 class rc_fallback_interface<sc_signal_inout_if<T> >
00098 : virtual public sc_signal_inout_if<T>
00099 {
00100 public:
00101     rc_fallback_interface()
00102         : p_value(rc_undefined_value<T>())
00103     { }
00104     virtual const T& read() const
00105         { return p_value; }
00106     virtual const T& get_data_ref() const
00107         { return p_value; }
00108     virtual bool event() const
00109         { return false; }
00110     virtual void write(const T& value)
00111         { }
00112     virtual bool posedge() const
00113         { return false; }
00114     virtual bool negedge() const
00115         { return false; }
00116 #if !defined(RC_USE_NON_OSCI_KERNEL)
00117     virtual sc_reset* is_reset() const
00118     {
00119         RC_REPORT_ERROR(RC_ID_NOT_IMPLEMENTED_,
00120             "'sc_reset* ReChannel::rc_fallback_interface"
00121             "<sc_signal_inout_if<T> >::is_reset() const'"
00122             " not implemented");
00123     }
00124 #endif // !defined(RC_USE_NON_OSCI_KERNEL)
00125     virtual const sc_event& default_event() const
00126     {
00127         SC_REPORT_WARNING(RC_ID_UNDEFINED_EVENT_WARNING_, 0);
00128         return p_undef;
00129     }
00130     virtual const sc_event& value_changed_event() const
00131         { return default_event(); }
00132     virtual const sc_event& posedge_event() const
00133         { return default_event(); }
00134     virtual const sc_event& negedge_event() const
00135         { return default_event(); }
00136 private:
00137     T        p_value;
00138     sc_event p_undef;
00139 };
00140 
00144 template<class T>
00145 class rc_signal_in_accessor_base
00146     : public rc_abstract_accessor<sc_signal_in_if<T> >
00147 {
00148 protected:
00149     typedef sc_signal_in_if<T> if_type;
00150 
00151     rc_signal_in_accessor_base() { }
00152 
00153 public:
00154     RC_EVENT(default_event);
00155     RC_EVENT_ALIAS(default_event, value_changed_event);
00156 
00157     virtual const T& read() const
00158     {
00159         return this->rc_nb_forward(&if_type::read);
00160     }
00161     virtual const T& get_data_ref() const
00162     {
00163         return this->rc_nb_forward(&if_type::get_data_ref);
00164     }
00165     virtual bool event() const
00166     {
00167         return this->rc_nb_forward(&if_type::event);
00168     }
00169 };
00170 
00174 template<class T>
00175 class rc_accessor<sc_signal_in_if<T> >
00176     : public rc_signal_in_accessor_base<T>
00177 {
00178 public:
00179     typedef sc_signal_in_if<T> if_type;
00180 
00181     rc_accessor() { }
00182 };
00183 
00187 template<class T>
00188 class rc_signal_in_accessor_edged_base
00189     : public rc_signal_in_accessor_base<T>
00190 {
00191 protected:
00192     typedef sc_signal_in_if<T> if_type;
00193 
00194     rc_signal_in_accessor_edged_base() { }
00195 
00196 public:
00197     RC_EVENT(posedge_event);
00198     RC_EVENT(negedge_event);
00199 
00200     virtual bool posedge() const
00201     {
00202         return this->rc_nb_forward(&if_type::posedge);
00203     }
00204     virtual bool negedge() const
00205     {
00206         return this->rc_nb_forward(&if_type::negedge);
00207     }
00208 };
00209 
00213 template<>
00214 class rc_accessor<sc_signal_in_if<bool> >
00215     : public rc_signal_in_accessor_edged_base<bool>,
00216       virtual public rc_reset_channel_if
00217 {
00218 private:
00219     typedef rc_accessor<sc_signal_in_if<bool> > this_type;
00220     typedef internals::reset_signal             reset_signal_type;
00221 
00222 public:
00223     typedef sc_signal_in_if<bool> if_type;
00224 
00225     rc_accessor()
00226         : p_reset_signal(NULL)
00227     { }
00228 
00229 #if !defined(RC_USE_NON_OSCI_KERNEL)
00230     virtual sc_reset* is_reset() const
00231     {
00232 #       if !defined(RC_DISABLE_CTHREAD_MOBILITY)
00233             // workaround to allow mobility of CTHREADs with the OSCI Kernel
00234             return _rc_get_reset_signal().is_reset();
00235 #       else // defined(RC_DISABLE_CTHREAD_MOBILITY)
00236             return this->rc_nb_forward(&if_type::is_reset);
00237 #       endif // !defined(RC_DISABLE_CTHREAD_MOBILITY)
00238     }
00239 #endif // !defined(RC_USE_NON_OSCI_KERNEL)
00240 
00241 protected:
00242     virtual void register_process_control(
00243         rc_process_control& pctrl, bool active_level) const;
00244 
00245     virtual void unregister_process_control(
00246         rc_process_control& pctrl) const;
00247 
00248     virtual bool get_current_level() const
00249     { return (p_reset_signal != NULL ? p_reset_signal->read() : false); }
00250 
00251     virtual const sc_signal<bool>* get_underlying_reset_signal() const
00252         { return &_rc_get_reset_signal(); }
00253 
00254 private:
00255 
00256     reset_signal_type& _rc_get_reset_signal() const;
00257 
00258     void _rc_reset_updater_proc();
00259 
00260 private:
00261     mutable reset_signal_type* p_reset_signal;
00262 };
00263 
00267 template<>
00268 class rc_accessor<sc_signal_in_if<sc_dt::sc_logic> >
00269     : public rc_signal_in_accessor_edged_base<sc_dt::sc_logic>
00270 {
00271 public:
00272     typedef sc_signal_in_if<sc_dt::sc_logic> if_type;
00273 
00274     rc_accessor() { }
00275 };
00276 
00280 template<class T>
00281 class rc_signal_accessor_base
00282     : public rc_abstract_accessor<sc_signal_inout_if<T> >
00283 {
00284 protected:
00285     typedef sc_signal_inout_if<T> if_type;
00286 
00287     rc_signal_accessor_base() { }
00288 
00289 public:
00290     RC_EVENT(default_event);
00291     RC_EVENT_ALIAS(default_event, value_changed_event);
00292 
00293     virtual const T& read() const
00294     {
00295         return this->rc_nb_forward(&if_type::read);
00296     }
00297     virtual const T& get_data_ref() const
00298     {
00299         return this->rc_nb_forward(&if_type::get_data_ref);
00300     }
00301     virtual bool event() const
00302     {
00303         return this->rc_nb_forward(&if_type::event);
00304     }
00305     virtual void write(const T& value)
00306     {
00307 #       if !defined(RC_SIGNAL_WRITE_CHECK_DISABLED)
00308             this->rc_nb_forward_driver(&if_type::write, value);
00309 #       else
00310             this->rc_nb_forward(&if_type::write, value);
00311 #       endif
00312     }
00313 };
00314 
00318 template<class T>
00319 class rc_accessor<sc_signal_inout_if<T> >
00320     : public rc_signal_accessor_base<T>
00321 {
00322 public:
00323     typedef sc_signal_inout_if<T> if_type;
00324 
00325     rc_accessor() { }
00326 };
00327 
00331 template<class T>
00332 class rc_signal_accessor_edged_base
00333     : public rc_signal_accessor_base<T>
00334 {
00335 protected:
00336     typedef sc_signal_inout_if<T> if_type;
00337 
00338     rc_signal_accessor_edged_base() { }
00339 
00340 public:
00341     RC_EVENT(posedge_event);
00342     RC_EVENT(negedge_event);
00343 
00344     virtual bool posedge() const
00345     {
00346         return this->rc_nb_forward(&if_type::posedge);
00347     }
00348     virtual bool negedge() const
00349     {
00350         return this->rc_nb_forward(&if_type::negedge);
00351     }
00352 };
00353 
00357 template<>
00358 class rc_accessor<sc_signal_inout_if<bool> >
00359     : public rc_signal_accessor_edged_base<bool>,
00360       virtual public rc_reset_channel_if
00361 {
00362 private:
00363     typedef rc_accessor<sc_signal_inout_if<bool> > this_type;
00364     typedef internals::reset_signal                reset_signal_type;
00365 
00366 public:
00367     typedef sc_signal_inout_if<bool> if_type;
00368 
00369     rc_accessor()
00370         : p_reset_signal(NULL)
00371     { }
00372 
00373 #if !defined(RC_USE_NON_OSCI_KERNEL)
00374     virtual sc_reset* is_reset() const
00375     {
00376 #       if !defined(RC_DISABLE_CTHREAD_MOBILITY)
00377             // workaround to allow mobility of CTHREADs with the OSCI Kernel
00378             return _rc_get_reset_signal().is_reset();
00379 #       else // defined(RC_DISABLE_CTHREAD_MOBILITY)
00380             return this->rc_nb_forward(&if_type::is_reset);
00381 #       endif // !defined(RC_DISABLE_CTHREAD_MOBILITY)
00382     }
00383 #endif // !defined(RC_USE_NON_OSCI_KERNEL)
00384 
00385 protected:
00386     virtual void register_process_control(
00387         rc_process_control& pctrl, bool active_level) const;
00388 
00389     virtual void unregister_process_control(
00390         rc_process_control& pctrl) const;
00391 
00392     virtual bool get_current_level() const
00393     { return (p_reset_signal != NULL ? p_reset_signal->read() : false); }
00394 
00395     virtual const sc_signal<bool>* get_underlying_reset_signal() const
00396         { return &_rc_get_reset_signal(); }
00397 
00398 private:
00399 
00400     reset_signal_type& _rc_get_reset_signal() const;
00401 
00402     void _rc_reset_updater_proc();
00403 
00404 private:
00405     mutable reset_signal_type* p_reset_signal;
00406 };
00407 
00411 template<>
00412 class rc_accessor<sc_signal_inout_if<sc_dt::sc_logic> >
00413     : public rc_signal_accessor_edged_base<sc_dt::sc_logic>
00414 {
00415 public:
00416     typedef sc_signal_inout_if<sc_dt::sc_logic> if_type;
00417 
00418     rc_accessor() { }
00419 };
00420 
00421 } // namespace ReChannel
00422 
00423 #endif // RC_SIGNAL_ACCESSORS_H_
00424 //
00425 // $Id: rc_signal_accessors.h,v 1.8 2007/11/23 13:25:45 felke Exp $
00426 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/communication/accessors/rc_signal_accessors.h,v $
00427 //

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