00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 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 (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.accellera.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_buffer.h -- The sc_buffer<T> primitive channel class. 00021 Like sc_signal<T>, but *every* write causes an event. 00022 00023 Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21 00024 00025 CHANGE LOG IS AT THE END OF THE FILE 00026 *****************************************************************************/ 00027 00028 #ifndef SC_BUFFER_H 00029 #define SC_BUFFER_H 00030 00031 00032 #include "sysc/communication/sc_signal.h" 00033 00034 namespace sc_core { 00035 00036 /**************************************************************************/ 00042 template< typename T, sc_writer_policy POL = SC_DEFAULT_WRITER_POLICY > 00043 class sc_buffer 00044 : public sc_signal<T,POL> 00045 { 00046 public: 00047 00048 // typedefs 00049 00050 typedef sc_buffer<T,POL> this_type; 00051 typedef sc_signal<T,POL> base_type; 00052 00053 public: 00054 00055 // constructors 00056 00057 sc_buffer() 00058 : base_type( sc_gen_unique_name( "buffer" ) ) 00059 {} 00060 00061 explicit sc_buffer( const char* name_ ) 00062 : base_type( name_ ) 00063 {} 00064 00065 sc_buffer( const char* name_, const T& initial_value_ ) 00066 : base_type( name_, initial_value_ ) 00067 {} 00068 00069 // interface methods 00070 00071 // write the new value 00072 virtual void write( const T& ); 00073 00074 00075 // other methods 00076 00077 this_type& operator = ( const T& a ) 00078 { write( a ); return *this; } 00079 00080 this_type& operator = ( const sc_signal_in_if<T>& a ) 00081 { write( a.read() ); return *this; } 00082 00083 this_type& operator = ( const this_type& a ) 00084 { write( a.read() ); return *this; } 00085 00086 virtual const char* kind() const 00087 { return "sc_buffer"; } 00088 00089 protected: 00090 00091 virtual void update(); 00092 00093 private: 00094 00095 // disabled 00096 sc_buffer( const this_type& ); 00097 }; 00098 00099 00100 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 00101 00102 // write the new value 00103 00104 template< typename T, sc_writer_policy POL > 00105 inline 00106 void 00107 sc_buffer<T,POL>::write( const T& value_ ) 00108 { 00109 // 02/23/2015 GL: acquire a lock to protect concurrent communication, 00110 // but sc_signal should have a single write port?! 00111 // 02/24/2015 GL: the reason to add "this->" before m_mutex: 00112 // http://www.parashift.com/c++-faq-lite/nondependent-name-lookup-members.html 00113 chnl_scoped_lock lock( this->m_mutex ); 00114 00115 if( !base_type::policy_type::check_write(this,true) ) 00116 return; 00117 00118 this->m_new_val = value_; 00119 this->request_update(); 00120 // 02/23/2015 GL: return releases the lock 00121 } 00122 00123 00124 template< typename T, sc_writer_policy POL > 00125 inline 00126 void 00127 sc_buffer<T,POL>::update() 00128 { 00129 base_type::policy_type::update(); 00130 base_type::do_update(); 00131 } 00132 00133 } // namespace sc_core 00134 00135 #endif 00136 00137 //$Log: sc_buffer.h,v $ 00138 //Revision 1.7 2011/08/26 20:45:39 acg 00139 // Andy Goodrich: moved the modification log to the end of the file to 00140 // eliminate source line number skew when check-ins are done. 00141 // 00142 //Revision 1.6 2011/04/08 18:22:45 acg 00143 // Philipp A. Hartmann: use the context of the primitive channel to get 00144 // the change stamp value. 00145 // 00146 //Revision 1.5 2011/04/05 20:48:09 acg 00147 // Andy Goodrich: changes to make sure that event(), posedge() and negedge() 00148 // only return true if the clock has not moved. 00149 // 00150 //Revision 1.4 2011/04/05 06:15:18 acg 00151 // Philipp A. Hartmann: sc_writer_policy: ignore no-ops in delta check. 00152 // 00153 //Revision 1.3 2011/02/18 20:23:45 acg 00154 // Andy Goodrich: Copyright update. 00155 // 00156 //Revision 1.2 2010/12/07 19:50:36 acg 00157 // Andy Goodrich: addition of writer policies, courtesy of Philipp Hartmann. 00158 // 00159 //Revision 1.1.1.1 2006/12/15 20:20:04 acg 00160 //SystemC 2.3 00161 // 00162 //Revision 1.8 2006/03/13 20:19:43 acg 00163 // Andy Goodrich: changed sc_event instances into pointers to sc_event instances 00164 // that are allocated as needed. This saves considerable storage for large 00165 // numbers of signals, etc. 00166 // 00167 //Revision 1.7 2006/01/26 21:00:49 acg 00168 // Andy Goodrich: conversion to use sc_event::notify(SC_ZERO_TIME) instead of 00169 // sc_event::notify_delayed() 00170 // 00171 //Revision 1.6 2006/01/24 20:46:31 acg 00172 //Andy Goodrich: changes to eliminate use of deprecated features. For instance, 00173 //using notify(SC_ZERO_TIME) in place of notify_delayed(). 00174 // 00175 //Revision 1.5 2006/01/19 19:18:25 acg 00176 //Andy Goodrich: eliminated check_writer in favor of inline code within the 00177 //write() method since we always execute the check_writer code even when 00178 //check writing is turned off. 00179 // 00180 //Revision 1.4 2006/01/19 00:30:57 acg 00181 //Andy Goodrich: Yet another implementation for disabling write checks on 00182 //signals. This version uses an environment variable, SC_SIGNAL_WRITE_CHECK, 00183 //that when set to DISABLE will turn off write checking. 00184 // 00185 //Revision 1.3 2006/01/13 18:47:20 acg 00186 //Reversed sense of multiwriter signal check. It now defaults to ON unless the 00187 //user defines SC_NO_WRITE_CHEK before inclusion of the file. 00188 // 00189 //Revision 1.2 2006/01/03 23:18:26 acg 00190 //Changed copyright to include 2006. 00191 // 00192 //Revision 1.1.1.1 2005/12/19 23:16:43 acg 00193 //First check in of SystemC 2.1 into its own archive. 00194 // 00195 //Revision 1.9 2005/06/10 22:43:55 acg 00196 //Added CVS change log annotation. 00197 // 00198 00199 // Taf!