SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_signal_rv.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_signal_rv.h -- The resolved vector signal class.
21 
22  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
23 
24  CHANGE LOG IS AT THE END OF THE FILE
25  *****************************************************************************/
26 
27 #ifndef SC_SIGNAL_RV_H
28 #define SC_SIGNAL_RV_H
29 
32 
33 namespace sc_core {
34 
36 
37 
38 // ----------------------------------------------------------------------------
39 // CLASS sc_lv_resolve<W>
40 //
41 // Resolution function for sc_dt::sc_lv<W>.
42 // ----------------------------------------------------------------------------
43 
45 
46 
47 template <int W>
49 {
50 public:
51 
52  // resolves sc_dt::sc_lv<W> values and returns the resolved value
53  static void resolve(sc_dt::sc_lv<W>&, const std::vector<sc_dt::sc_lv<W>*>&);
54 };
55 
56 
57 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
58 
59 // resolves sc_dt::sc_lv<W> values and returns the resolved value
60 
61 template <int W>
62 inline
63 void
65  const std::vector<sc_dt::sc_lv<W>*>& values_ )
66 {
67  int sz = values_.size();
68 
69  assert( sz != 0 );
70 
71  if( sz == 1 ) {
72  result_ = *values_[0];
73  return;
74  }
75 
76  for( int j = result_.length() - 1; j >= 0; -- j ) {
77  sc_dt::sc_logic_value_t res = (*values_[0])[j].value();
78  for( int i = sz - 1; i > 0 && res != 3; -- i ) {
79  res = sc_logic_resolution_tbl[res][(*values_[i])[j].value()];
80  }
81  result_[j] = res;
82  }
83 }
84 
85 
86 // ----------------------------------------------------------------------------
87 // CLASS : sc_signal_rv<W>
88 //
89 // The resolved vector signal class.
90 // ----------------------------------------------------------------------------
91 
92 template <int W>
94 : public sc_signal<sc_dt::sc_lv<W>, SC_MANY_WRITERS>
95 {
96 public:
97 
98  // typedefs
99 
103 
104 public:
105 
106  // constructors
107 
109  : base_type( sc_gen_unique_name( "signal_rv" ) )
110  {}
111 
112  explicit sc_signal_rv( const char* name_ )
113  : base_type( name_ )
114  {}
115 
116 
117  // destructor
118  virtual ~sc_signal_rv();
119 
120 
121  // interface methods
122 
123  virtual void register_port( sc_port_base&, const char* )
124  {}
125 
126 
127  // write the new value
128  virtual void write( const data_type& );
129 
130 
131  // other methods
132 
134  { write( a ); return *this; }
135 
137  { write( a.read() ); return *this; }
138 
139  virtual const char* kind() const
140  { return "sc_signal_rv"; }
141 
142 protected:
143 
144  virtual void update();
145 
146 protected:
147 
148  std::vector<sc_process_b*> m_proc_vec; // processes writing this signal
149  std::vector<data_type*> m_val_vec; // new values written this signal
150 
151 private:
152 
153  // disabled
154  sc_signal_rv( const this_type& );
155 };
156 
157 
158 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
159 
160 
161 // destructor
162 
163 template <int W>
164 inline
166 {
167  for( int i = m_val_vec.size() - 1; i >= 0; -- i ) {
168  delete m_val_vec[i];
169  }
170 }
171 
172 
173 // write the new value
174 
175 template <int W>
176 inline
177 void
179 {
181 
182  bool value_changed = false;
183  bool found = false;
184 
185  for( int i = m_proc_vec.size() - 1; i >= 0; -- i ) {
186  if( cur_proc == m_proc_vec[i] ) {
187  if( value_ != *m_val_vec[i] ) {
188  *m_val_vec[i] = value_;
189  value_changed = true;
190  }
191  found = true;
192  break;
193  }
194  }
195 
196  if( ! found ) {
197  m_proc_vec.push_back( cur_proc );
198  m_val_vec.push_back( new data_type( value_ ) );
199  value_changed = true;
200  }
201 
202  if( value_changed ) {
203  this->request_update();
204  }
205 }
206 
207 
208 template <int W>
209 inline
210 void
212 {
213  sc_lv_resolve<W>::resolve( this->m_new_val, m_val_vec );
214  base_type::update();
215 }
216 
217 } // namespace sc_core
218 
219 //$Log: sc_signal_rv.h,v $
220 //Revision 1.4 2011/08/26 20:45:44 acg
221 // Andy Goodrich: moved the modification log to the end of the file to
222 // eliminate source line number skew when check-ins are done.
223 //
224 //Revision 1.3 2011/04/19 02:36:26 acg
225 // Philipp A. Hartmann: new aysnc_update and mutex support.
226 //
227 //Revision 1.2 2011/02/18 20:23:45 acg
228 // Andy Goodrich: Copyright update.
229 //
230 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
231 //SystemC 2.3
232 //
233 //Revision 1.3 2006/03/21 00:00:27 acg
234 // Andy Goodrich: changed name of sc_get_current_process_base() to be
235 // sc_get_current_process_b() since its returning an sc_process_b instance.
236 //
237 //Revision 1.2 2006/01/03 23:18:26 acg
238 //Changed copyright to include 2006.
239 //
240 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
241 //First check in of SystemC 2.1 into its own archive.
242 //
243 //Revision 1.10 2005/09/15 23:01:52 acg
244 //Added std:: prefix to appropriate methods and types to get around
245 //issues with the Edison Front End.
246 //
247 //Revision 1.9 2005/06/10 22:43:55 acg
248 //Added CVS change log annotation.
249 //
250 
251 #endif
252 
253 // Taf!
sc_signal_rv(const char *name_)
Definition: sc_signal_rv.h:112
std::vector< data_type * > m_val_vec
Definition: sc_signal_rv.h:149
virtual void register_port(sc_port_base &, const char *)
Definition: sc_signal_rv.h:123
const sc_dt::sc_logic_value_t sc_logic_resolution_tbl[4][4]
Definition: sc_signal_rv.h:35
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
sc_process_b * sc_get_current_process_b()
allow multiple writers (with different ports)
virtual void write(const data_type &)
Definition: sc_signal_rv.h:178
const char * sc_gen_unique_name(const char *, bool preserve_first)
sc_logic_value_t
Definition: sc_logic.h:85
virtual void update()
Definition: sc_signal_rv.h:211
sc_signal< sc_dt::sc_lv< W >, SC_MANY_WRITERS > base_type
Definition: sc_signal_rv.h:101
std::vector< sc_process_b * > m_proc_vec
Definition: sc_signal_rv.h:148
static void resolve(sc_dt::sc_lv< W > &, const std::vector< sc_dt::sc_lv< W > * > &)
Definition: sc_signal_rv.h:64
virtual const T & read() const
Definition: sc_signal.h:130
sc_dt::sc_lv< W > data_type
Definition: sc_signal_rv.h:102
int length() const
Definition: sc_lv_base.h:244
sc_signal_rv< W > this_type
Definition: sc_signal_rv.h:100
this_type & operator=(const data_type &a)
Definition: sc_signal_rv.h:133
virtual const char * kind() const
Definition: sc_signal_rv.h:139