rc_fifo_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_FIFO_ACCESSORS_H_
00040 #define RC_FIFO_ACCESSORS_H_
00041 
00042 #include "ReChannel/communication/accessors/rc_accessor.h"
00043 
00044 namespace ReChannel {
00045 
00049 template<class T>
00050 class rc_fallback_interface<sc_fifo_in_if<T> >
00051 : virtual public sc_fifo_in_if<T>
00052 {
00053 public:
00054     rc_fallback_interface()
00055     : p_value(rc_undefined_value<T>())
00056     { }
00057     virtual bool nb_read(T& value)
00058         { value = p_value; return false; }
00059     virtual const sc_event& data_written_event() const
00060     {
00061         SC_REPORT_WARNING(RC_ID_UNDEFINED_EVENT_WARNING_, 0);
00062         return p_undef;
00063     }
00064     virtual void read(T& value)
00065         { ::sc_core::wait(p_undef); }
00066     virtual T read()
00067     {
00068         SC_REPORT_WARNING(RC_ID_UNDEFINED_BLOCKING_ACCESS_WARNING_, 0);
00069         ::sc_core::wait(p_undef); return p_value;
00070     }
00071     virtual int num_available() const
00072         { return 0; }
00073 private:
00074     const T  p_value;
00075     sc_event p_undef;
00076 };
00077 
00081 template<class T>
00082 class rc_fallback_interface<sc_fifo_out_if<T> >
00083 : virtual public sc_fifo_out_if<T>
00084 {
00085 public:
00086     rc_fallback_interface() { }
00087     virtual bool nb_write(const T& value)
00088         { return false; }
00089     virtual const sc_event& data_read_event() const
00090     {
00091         SC_REPORT_WARNING(RC_ID_UNDEFINED_EVENT_WARNING_, 0);
00092         return p_undef;
00093     }
00094     virtual void write(const T& value)
00095     {
00096         SC_REPORT_WARNING(RC_ID_UNDEFINED_BLOCKING_ACCESS_WARNING_, 0);
00097         ::sc_core::wait(p_undef);
00098     }
00099     virtual int num_free() const
00100         { return 0; }
00101 private:
00102     sc_event p_undef;
00103 };
00104 
00108 template<class T>
00109 RC_ACCESSOR_TEMPLATE(sc_fifo_in_if<T>)
00110 {
00111     RC_ACCESSOR_TEMPLATE_CTOR(sc_fifo_in_if<T>) { }
00112 
00113     RC_EVENT(data_written_event);
00114 
00115     virtual bool nb_read(T& value)
00116     {
00117         return this->rc_nb_forward(&if_type::nb_read, rc_ref(value));
00118     }
00119     virtual void read(T& value)
00120     {
00121         // prevent deadlocks in empty FIFOs
00122         while (this->num_available() <= 0) {
00123             this->wait(this->data_written_event());
00124         }
00125         this->rc_forward(&if_type::read, rc_ref(value));
00126     }
00127     virtual T read()
00128     {
00129         // prevent deadlocks in empty FIFOs
00130         while (this->num_available() <= 0) {
00131             this->wait(this->data_written_event());
00132         }
00133         return this->rc_forward(&if_type::read);
00134     }
00135     virtual int num_available() const
00136     {
00137         return this->rc_nb_forward(&if_type::num_available);
00138     }
00139 };
00140 
00144 template<class T>
00145 RC_ACCESSOR_TEMPLATE(sc_fifo_out_if<T>)
00146 {
00147     RC_ACCESSOR_TEMPLATE_CTOR(sc_fifo_out_if<T>) { }
00148 
00149     RC_EVENT(data_read_event);
00150 
00151     virtual bool nb_write(const T& value)
00152     {
00153         return this->rc_nb_forward(&if_type::nb_write, rc_cref(value));
00154     }
00155     virtual void write(const T& value)
00156     {
00157         // prevent deadlocks in empty FIFOs
00158         while (this->num_free() <= 0) {
00159             this->wait(this->data_read_event());
00160         }
00161         this->rc_forward(&if_type::write, rc_cref(value));
00162     }
00163     virtual int num_free() const
00164     {
00165         return this->rc_nb_forward(&if_type::num_free);
00166     }
00167 };
00168 
00169 } // namespace ReChannel
00170 
00171 #endif // RC_FIFO_ACCESSORS_H_
00172 
00173 //
00174 // $Id: rc_fifo_accessors.h,v 1.8 2008/01/01 13:34:25 felke Exp $
00175 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/communication/accessors/rc_fifo_accessors.h,v $
00176 //

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