SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_signal_rv.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_signal_rv.h -- The resolved vector signal class.
23 */
33 #ifndef SC_SIGNAL_RV_H
34 #define SC_SIGNAL_RV_H
35 
38 
39 namespace sc_core {
40 
42 
43 // ----------------------------------------------------------------------------
44 // CLASS sc_lv_resolve<W>
45 //
46 // Resolution function for sc_dt::sc_lv<W>.
47 // ----------------------------------------------------------------------------
48 
50 
51 
52 template <int W>
54 {
55 public:
56 
57  // resolves sc_dt::sc_lv<W> values and returns the resolved value
58  static void resolve(sc_dt::sc_lv<W>&, const std::vector<sc_dt::sc_lv<W>*>&);
59 };
60 
61 
62 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
63 
64 // resolves sc_dt::sc_lv<W> values and returns the resolved value
65 
66 template <int W>
67 inline
68 void
70  const std::vector<sc_dt::sc_lv<W>*>& values_ )
71 {
72  int sz = values_.size();
73 
74  sc_assert( sz != 0 );
75 
76  if( sz == 1 ) {
77  result_ = *values_[0];
78  return;
79  }
80 
81  for( int j = result_.length() - 1; j >= 0; -- j ) {
82  sc_dt::sc_logic_value_t res = (*values_[0])[j].value();
83  for( int i = sz - 1; i > 0 && res != 3; -- i ) {
84  res = sc_logic_resolution_tbl[res][(*values_[i])[j].value()];
85  }
86  result_[j] = res;
87  }
88 }
89 
90 
97 template <int W>
99 : public sc_signal<sc_dt::sc_lv<W>, SC_MANY_WRITERS>
100 {
101 public:
102 
103  // typedefs
104 
108 
109 public:
110 
111  // constructors
112 
114  : base_type( sc_gen_unique_name( "signal_rv" ) )
115  {}
116 
117  explicit sc_signal_rv( const char* name_ )
118  : base_type( name_, value_type() )
119  {}
120 
121  sc_signal_rv( const char* name_, const value_type& initial_value_ )
122  : base_type( name_, initial_value_ )
123  {}
124 
125 
126  // destructor
127  virtual ~sc_signal_rv();
128 
129 
130  // interface methods
131 
132  virtual void register_port( sc_port_base&, const char* )
133  {}
134 
135 
136  // write the new value
137  virtual void write( const value_type& );
138 
139 
140  // other methods
141  virtual const char* kind() const
142  { return "sc_signal_rv"; }
143 
144 
145  // assignment
146  this_type& operator = ( const value_type& a )
147  { base_type::operator=(a); return *this; }
148 
149  this_type& operator = ( const sc_signal_in_if<value_type>& a )
150  { base_type::operator=(a); return *this; }
151 
152  this_type& operator = ( const this_type& a )
153  { base_type::operator=(a); return *this; }
154 
155 protected:
156 
157  virtual void update();
158 
159 protected:
160 
161  std::vector<sc_process_b*> m_proc_vec; // processes writing this signal
162  std::vector<value_type*> m_val_vec; // new values written this signal
163 
164 private:
165 
166  // disabled
167  sc_signal_rv( const this_type& );
168 };
169 
170 
171 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
172 
173 
174 // destructor
175 
176 template <int W>
177 inline
179 {
180  for( int i = m_val_vec.size() - 1; i >= 0; -- i ) {
181  delete m_val_vec[i];
182  }
183 }
184 
185 
186 // write the new value
187 
188 template <int W>
189 inline
190 void
192 {
194 
195  bool value_changed = false;
196  bool found = false;
197 
198  for( int i = m_proc_vec.size() - 1; i >= 0; -- i ) {
199  if( cur_proc == m_proc_vec[i] ) {
200  if( value_ != *m_val_vec[i] ) {
201  *m_val_vec[i] = value_;
202  value_changed = true;
203  }
204  found = true;
205  break;
206  }
207  }
208 
209  if( ! found ) {
210  m_proc_vec.push_back( cur_proc );
211  m_val_vec.push_back( new value_type( value_ ) );
212  value_changed = true;
213  }
214 
215  if( value_changed ) {
216  this->request_update();
217  }
218 }
219 
220 
221 template <int W>
222 inline
223 void
225 {
226  sc_lv_resolve<W>::resolve( this->m_new_val, m_val_vec );
227  base_type::update();
228 }
229 
230 } // namespace sc_core
231 
232 //$Log: sc_signal_rv.h,v $
233 //Revision 1.4 2011/08/26 20:45:44 acg
234 // Andy Goodrich: moved the modification log to the end of the file to
235 // eliminate source line number skew when check-ins are done.
236 //
237 //Revision 1.3 2011/04/19 02:36:26 acg
238 // Philipp A. Hartmann: new aysnc_update and mutex support.
239 //
240 //Revision 1.2 2011/02/18 20:23:45 acg
241 // Andy Goodrich: Copyright update.
242 //
243 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
244 //SystemC 2.3
245 //
246 //Revision 1.3 2006/03/21 00:00:27 acg
247 // Andy Goodrich: changed name of sc_get_current_process_base() to be
248 // sc_get_current_process_b() since its returning an sc_process_b instance.
249 //
250 //Revision 1.2 2006/01/03 23:18:26 acg
251 //Changed copyright to include 2006.
252 //
253 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
254 //First check in of SystemC 2.1 into its own archive.
255 //
256 //Revision 1.10 2005/09/15 23:01:52 acg
257 //Added std:: prefix to appropriate methods and types to get around
258 //issues with the Edison Front End.
259 //
260 //Revision 1.9 2005/06/10 22:43:55 acg
261 //Added CVS change log annotation.
262 //
263 
264 #endif
265 
266 // Taf!
int length() const
Definition: sc_lv_base.h:207
#define sc_assert(expr)
Definition: sc_report.h:270
sc_process_b * sc_get_current_process_b()
sc_signal_rv(const char *name_)
Definition: sc_signal_rv.h:117
virtual void register_port(sc_port_base &, const char *)
Definition: sc_signal_rv.h:132
sc_signal< sc_dt::sc_lv< W >, SC_MANY_WRITERS > base_type
Definition: sc_signal_rv.h:106
Arbitrary size logic vector class.
The sc_signal<T> primitive channel class.
virtual void update()
Definition: sc_signal_rv.h:224
Abstract base class for class sc_port_b.
Definition: sc_port.h:81
std::vector< sc_process_b * > m_proc_vec
Definition: sc_signal_rv.h:161
sc_logic_value_t
Enumeration of values for sc_logic.
Definition: sc_logic.h:90
The resolved vector signal class.
SC_API const sc_dt::sc_logic_value_t sc_logic_resolution_tbl[4][4]
Definition: sc_signal_rv.h:41
sc_dt::sc_lv< W > value_type
Definition: sc_signal_rv.h:107
sc_signal_rv< W > this_type
Definition: sc_signal_rv.h:105
sc_clock period is zero sc_clock low time is zero sc_fifo< T > cannot have more than one writer bind interface to port failed complete binding failed remove port failed insert primitive channel failed sc_signal< T > cannot have more than one driver resolved port not bound to resolved signal sc_semaphore requires an initial value
std::vector< value_type * > m_val_vec
Definition: sc_signal_rv.h:162
virtual const char * kind() const
Definition: sc_signal_rv.h:141
virtual void write(const value_type &)
Definition: sc_signal_rv.h:191
SC_API const char * sc_gen_unique_name(const char *, bool preserve_first)
static void resolve(sc_dt::sc_lv< W > &, const std::vector< sc_dt::sc_lv< W > *> &)
Definition: sc_signal_rv.h:69
sc_signal_rv(const char *name_, const value_type &initial_value_)
Definition: sc_signal_rv.h:121
#define SC_API
Definition: sc_cmnhdr.h:168
allow multiple writers (with different ports)