source: branches/with_autoconf/src/sc_signal.h @ 8

Last change on this file since 8 was 8, checked in by nipo, 16 years ago

Checkin autotools magic

File size: 8.5 KB
Line 
1/*------------------------------------------------------------\
2|                                                             |
3| Tool    :                  systemcass                       |
4|                                                             |
5| File    :                   sc_signal.h                     |
6|                                                             |
7| Author  :                 Buchmann Richard                  |
8|                           Taktak Sami                       |
9|                                                             |
10| Date    :                   09_07_2004                      |
11|                                                             |
12\------------------------------------------------------------*/
13#ifndef __SC_SIGNAL_H__
14#define __SC_SIGNAL_H__
15
16// Define registers writing method
17#include <iostream>
18#include "sc_fwd.h"
19#include "sc_nbdefs.h"
20//#include "sc_event_finder.h"
21//#include "sc_event.h"
22#include "sc_time.h" // SC_ZERO_TIME
23#include "sc_object.h"
24#include "sc_interface.h"
25#include "internal_ext.h"
26
27#ifdef CONFIG_CHECK_FSM_RULES
28#include "fsm_rules.h"
29#endif
30
31namespace sc_core {
32
33//
34#if ((__GNUC__ < 3) || (__GNUC_MINOR__ < 4))
35#define INLINE __attribute__((always_inline))
36#else
37/* gcc3.4 doesn't support */ 
38#define INLINE
39#endif
40
41#define READ_SIGNAL(value_type_,pointer_) \
42        ((value_type_&) (*((value_type_*) (pointer_))))
43
44        ///////////////////// DEPRECATED
45// C ANSI-only since it is needed to link with extern "C"
46// this declaration is not in casc.h since the CONFIG_CHECK_FSM_RULES macro
47// is not defined.
48
49extern void bind (sc_port_base&,sc_port_base&);
50extern void bind (sc_port_base&,sc_signal_base&);
51extern void bind (sc_signal_base &x);
52extern void bind (sc_port_base   &x);
53typedef tab_t base_type;
54struct pending_write {
55        base_type   *pointer;
56        base_type    value;
57        //pending_write (base_type *const pointer_, const base_type value_)
58        //{     pointer = pointer_; value = value_; }
59        friend std::ostream& operator << (std::ostream &o, const pending_write &p)
60        { return o << "(pointer = " << p.pointer << "; value = " << p.value << ")\n"; }
61};
62
63// Check pending_writing to register
64extern void pending_writing2register_clear  ();
65extern void pending_writing2register_record_and_check (const tab_t *);
66
67// Pending write to register (simple stack)
68typedef pending_write *pending_write_vector_t;
69extern pending_write_vector_t pending_write_vector;
70extern "C" unsigned int pending_write_vector_nb;
71extern unsigned int pending_write_vector_capacity;
72
73
74template <typename T>
75inline void post_write (base_type *const pointer_,
76                        const T          value_) /*INLINE*/;
77template <typename T>
78inline void post_multiwrite (base_type *const pointer_,
79                             const T          value_)
80{
81        size_t size = (sizeof (T)-1) / sizeof (base_type);
82        size_t i = 0;
83        const base_type *pvalue = (const base_type*)(&value_);
84        do {
85#if 0
86    cout << "post_multiwrite 0x" << hex << pvalue[i] << " @" << (pointer_ + i) << "\n";
87#endif
88                post_write (pointer_ + i, pvalue[i]);
89        } while (i++ < size);
90}
91template <typename T>
92inline void post_write (base_type *const pointer_, 
93                        const T          value_)
94{
95        if (sizeof (T) > sizeof (base_type)) {
96#if 0
97    cout << "sizeof (T) = " << sizeof (T) << " (base_type = " << sizeof
98(base_type) << "\n";
99#endif
100                post_multiwrite (pointer_,value_);
101        } else {
102#if defined(CONFIG_DEBUG)
103        if (pending_write_vector_nb >= pending_write_vector_capacity) {
104        //if (pending_write_vector_nb >= pending_write_vector_capacity * sizeof(pending_write)) {
105                std::cerr << "Error : The array for posted writing on register is too small.\n";
106                std::cerr << "Up to 1 writing per register is allowed during a cycle.\n";
107                std::cerr << "Please check the hardware description.\n";
108                exit (-1);
109        }
110#endif // CONFIG_DEBUG
111  pending_write_vector[pending_write_vector_nb].pointer = pointer_;
112//      pending_write_vector[pending_write_vector_nb++].value = *(reinterpret_cast<const base_type*const>(&value_)); => bug !
113  pending_write_vector[pending_write_vector_nb++].value = value_; // => bug avec blues !
114
115        // -> fix to use user-defined struct in sc_signal/sc_in/sc_out/sc_inout
116        // pending_write_vector[pending_write_vector_nb++].value = *((base_type*)&value_); => bug !
117#if 0
118        std::cerr << "posted write : ptr = " << pointer_ << ", val = " << value_ << "\n";
119#endif
120#if 0 
121        // introduce bug on using trace functions
122        if (value_ == READ_SIGNAL(T,pointer_))
123                return;
124#endif
125        };
126}
127
128inline bool is_posted_write ()
129{
130                return pending_write_vector_nb > 0;
131}
132
133extern "C" void update (void);
134
135// ----------------------------------------------------------------------------
136//  CLASS : sc_signal_base
137//
138//  The sc_signal_base<T> primitive channel class.
139// ----------------------------------------------------------------------------
140
141class sc_signal_base : public sc_object, public sc_interface
142{
143        //////
144        // Internal
145  friend class sc_clock;
146  friend class sc_port_base;
147  void init ();
148        //////                           
149 
150
151public: 
152  // LRM (?)
153  //virtual const sc_event /*&*/ default_event () const;
154  static const char* const kind_string;
155  //virtual const char *kind () const;
156
157  //
158public:
159  sc_signal_base();
160  sc_signal_base(const char* name_);
161  sc_signal_base(const char* name_, void*);
162        ~sc_signal_base();
163};
164
165template <typename T>
166class sc_signal : public sc_signal_base
167{
168private:
169        T val;
170  typedef T  data_type;
171  typedef sc_signal < T >  this_type;
172        ///////////
173        // Internal
174        public: void init ();
175        ///////////
176//  virtual void update ();
177  void check_writer ();
178public:
179  // constructors, destructor
180  sc_signal () 
181        { init (); }
182  explicit sc_signal (const char *name_): sc_signal_base(name_)
183        { init (); }
184  /*virtual */~ sc_signal () 
185  {}
186  // methods
187  /*
188  virtual void register_port (sc_port_base &, const char *)
189  {}
190  virtual const sc_event & default_event () const
191  {}
192  virtual const sc_event & value_changed_event () const
193  {}
194  */
195  /*virtual*/ inline const data_type & read () const INLINE;
196/*
197  virtual const T & get_data_ref () const
198  {}
199  virtual bool event () const
200  {}
201  */
202  /*virtual*/ inline void write (const data_type &) /*INLINE*/;
203  inline operator const data_type & () const
204  { return this->read(); }
205  inline this_type& operator = (const data_type & a)
206  { sc_signal<T>::write (a); return *this; }
207  inline this_type& operator = (const sc_signal < T > &a)
208  { sc_signal<T>::write (a.read()); return *this; }
209  inline this_type& operator += (const data_type & a)
210  { sc_signal<T>::write (read() + a); return *this; }
211  inline this_type& operator += (const sc_signal < T > &a)
212  { sc_signal<T>::write (read()+a.read()); return *this; }
213  const data_type & get_new_value () const;
214//  void trace (sc_trace_file * tf) const;
215  /*
216        virtual void print (std::ostream &o) const
217  { o << *this; }
218  virtual void dump (std::ostream &o) const
219  { o << *this; }
220        */
221private:
222  // disabled
223  sc_signal (const sc_signal < T > &);
224
225};
226
227template <typename T>
228void
229sc_signal<T>::init()
230{
231  set_pointer ((tab_t*)&val);
232  set_kind    (kind_string);
233        sc_interface::init (sizeof (data_type)); 
234  val = 0; /* The simulator initializes the signal/register to 0.    */
235           /* However, hardware initialization still has to be done. */
236           /* This kind of initialization is for trace diffing.      */
237}
238// read the value
239template <typename T>
240/*virtual*/ 
241inline 
242const T & 
243sc_signal<T>::read() const
244{
245#ifdef DUMP_READ
246  std::cerr << "read " << READ_SIGNAL(const T, get_pointer())
247                << " on signal " << name () << "\n";
248#endif
249#ifdef CONFIG_CHECK_FSM_RULES
250        // we can read value from sc_signal type (used like a register) at any time
251#endif 
252    return READ_SIGNAL(const T, get_pointer());
253}
254
255// write the new value
256template <typename T>
257inline
258void
259sc_signal<T>::write( const data_type& value_ )
260{
261#ifdef CONFIG_CHECK_FSM_RULES
262        if ((casc_fsm_step != TRANSITION) 
263                        && ( casc_fsm_step != STIMULI)) {
264                std::cerr << "FSM rules error : trying to write on signal " 
265                          << name () 
266                          << " from " << get_step_name () << " function.\n";
267                exit (-1);
268        }               
269#endif
270#ifdef CONFIG_DEBUG
271  if (get_pointer() == NULL)
272  {
273    std::cerr << "Error : Unable to write into '" << name () << "'.";
274    exit (24032005);
275  }
276#endif
277#ifdef CONFIG_CHECK_MULTIWRITING2REGISTER
278  pending_writing2register_record_and_check (get_pointer ());
279#endif
280#ifdef DUMP_WRITE
281  if (sc_signal<T>::read() == value_)
282    return;
283  std::cerr << "write (posted) " << value_
284                << " on sc_signal (writing into register) '" << name () << "'\n";
285#endif
286  post_write (/*(tab_t*)&val*/ get_pointer(), value_);
287}
288
289#undef INLINE
290
291#undef READ_SIGNAL
292
293} // end of namespace sc_core
294
295#endif /* __SC_SIGNAL_H__ */
296
Note: See TracBrowser for help on using the repository browser.