| 1 | /*------------------------------------------------------------\ | 
|---|
| 2 | |                                                             | | 
|---|
| 3 | | Tool    :                  systemcass                       | | 
|---|
| 4 | |                                                             | | 
|---|
| 5 | | File    :                   sc_port_ext.h                   | | 
|---|
| 6 | |                                                             | | 
|---|
| 7 | | Author  :                 Buchmann Richard                  | | 
|---|
| 8 | |                           Taktak Sami                       | | 
|---|
| 9 | |                                                             | | 
|---|
| 10 | | Date    :                   09_07_2004                      | | 
|---|
| 11 | |                                                             | | 
|---|
| 12 | \------------------------------------------------------------*/ | 
|---|
| 13 | #ifndef __SC_PORT_EXT_H__ | 
|---|
| 14 | #define __SC_PORT_EXT_H__ | 
|---|
| 15 |  | 
|---|
| 16 | // Define registers writing method | 
|---|
| 17 | #include <iostream> | 
|---|
| 18 | #include <cstdlib> | 
|---|
| 19 |  | 
|---|
| 20 | #ifdef HAVE_CONFIG_H | 
|---|
| 21 | #include "config.h" | 
|---|
| 22 | #endif | 
|---|
| 23 |  | 
|---|
| 24 | #include "internal_ext.h" | 
|---|
| 25 | #include "port_dependency_ext.h" | 
|---|
| 26 | #include "sc_event.h" | 
|---|
| 27 | #include "sc_fwd.h" | 
|---|
| 28 | #include "sc_interface.h" | 
|---|
| 29 | #include "sc_nbdefs.h" | 
|---|
| 30 | #include "sc_object.h" | 
|---|
| 31 |  | 
|---|
| 32 |  | 
|---|
| 33 | //__GNUC__ | 
|---|
| 34 | //__GNUC_MINOR__ | 
|---|
| 35 | //__GNUC_PATCHLEVEL__ | 
|---|
| 36 | // | 
|---|
| 37 | #if ((__GNUC__ < 3) || (__GNUC_MINOR__ < 4)) | 
|---|
| 38 | #define INLINE __attribute__((always_inline)) | 
|---|
| 39 | #else | 
|---|
| 40 | /* gcc3.4 doesn't support */ | 
|---|
| 41 | #define INLINE | 
|---|
| 42 | #endif | 
|---|
| 43 |  | 
|---|
| 44 | #include <list> | 
|---|
| 45 |  | 
|---|
| 46 | // | 
|---|
| 47 | namespace sc_core { | 
|---|
| 48 | // | 
|---|
| 49 |  | 
|---|
| 50 | using namespace sc_dt; | 
|---|
| 51 |  | 
|---|
| 52 | const char *get_name        (const tab_t *pointer); | 
|---|
| 53 |  | 
|---|
| 54 | #define READ_SIGNAL(value_type_,pointer_) \ | 
|---|
| 55 | ((value_type_&) (*((value_type_*) (pointer_)))) | 
|---|
| 56 |  | 
|---|
| 57 | ///////////////////// DEPRECATED | 
|---|
| 58 | // C ANSI-only since it is needed to link with extern "C" | 
|---|
| 59 |  | 
|---|
| 60 | extern void bind (sc_port_base&,sc_port_base&); | 
|---|
| 61 | extern void bind (sc_port_base&,sc_signal_base&); | 
|---|
| 62 | extern void bind (sc_signal_base &x); | 
|---|
| 63 | extern void bind (sc_port_base   &x); | 
|---|
| 64 |  | 
|---|
| 65 | // KIND STRING | 
|---|
| 66 | extern const char * const sc_inout_string; | 
|---|
| 67 | extern const char * const sc_in_string; | 
|---|
| 68 | extern const char * const sc_out_string; | 
|---|
| 69 |  | 
|---|
| 70 | extern "C" void update (void); | 
|---|
| 71 |  | 
|---|
| 72 | class sc_port_base : public sc_object, public sc_interface | 
|---|
| 73 | { | 
|---|
| 74 | protected: | 
|---|
| 75 | typedef sc_port_base                        base_type; | 
|---|
| 76 | public: | 
|---|
| 77 | /////////// | 
|---|
| 78 | // Internal | 
|---|
| 79 | const sc_module &get_module () const; | 
|---|
| 80 | void             init (); | 
|---|
| 81 | void             check_multiwriting2port () const; | 
|---|
| 82 | /////////// | 
|---|
| 83 |  | 
|---|
| 84 | friend std::ostream& operator << (std::ostream &, const sc_port_base &); | 
|---|
| 85 |  | 
|---|
| 86 | // LRM | 
|---|
| 87 | //virtual const sc_event /*&*/ default_event () const; | 
|---|
| 88 | static const char* const kind_string; | 
|---|
| 89 | //  virtual const char *kind () const; | 
|---|
| 90 | // | 
|---|
| 91 | sc_port_base(); | 
|---|
| 92 | sc_port_base(const char* name_); | 
|---|
| 93 | explicit sc_port_base(const sc_port_base& parent_); | 
|---|
| 94 | /*virtual */~sc_port_base () {}; | 
|---|
| 95 | // bind to a handle | 
|---|
| 96 | void operator () (method_process_t &func) const; | 
|---|
| 97 | }; | 
|---|
| 98 |  | 
|---|
| 99 | template < typename T > class sc_port_b:public sc_port_base | 
|---|
| 100 | { | 
|---|
| 101 | }; | 
|---|
| 102 |  | 
|---|
| 103 | // ---------------------------------------------------------------------------- | 
|---|
| 104 | //  CLASS : sc_in<T> | 
|---|
| 105 | // | 
|---|
| 106 | // ---------------------------------------------------------------------------- | 
|---|
| 107 |  | 
|---|
| 108 | template <typename T> | 
|---|
| 109 | class sc_in : public sc_port_base | 
|---|
| 110 | { | 
|---|
| 111 | private: | 
|---|
| 112 | typedef T  data_type; | 
|---|
| 113 | typedef sc_port_base                  base_type; | 
|---|
| 114 | typedef sc_in<data_type>              this_type; | 
|---|
| 115 | typedef sc_signal<data_type>          signal_type; | 
|---|
| 116 |  | 
|---|
| 117 | /////////// | 
|---|
| 118 | // Internal | 
|---|
| 119 | void init (); | 
|---|
| 120 | /* | 
|---|
| 121 | public: virtual size_t data_size () const | 
|---|
| 122 | { return sizeof (data_type); } | 
|---|
| 123 | */ | 
|---|
| 124 | /////////// | 
|---|
| 125 | public: | 
|---|
| 126 | // constructors | 
|---|
| 127 | sc_in(): base_type() { init (); } | 
|---|
| 128 |  | 
|---|
| 129 | explicit sc_in(const char* name_): base_type(name_) { init (); } | 
|---|
| 130 |  | 
|---|
| 131 | explicit sc_in(const base_type& parent_ ): base_type( parent_ ) { init (); } | 
|---|
| 132 |  | 
|---|
| 133 | /* | 
|---|
| 134 | // LRM error ! | 
|---|
| 135 | //static const char *const kind_string; this is a template ! | 
|---|
| 136 | */ | 
|---|
| 137 | //  virtual const char *kind () const | 
|---|
| 138 | //  { return "sc_in"; }; | 
|---|
| 139 |  | 
|---|
| 140 | #if 0 | 
|---|
| 141 | // LRM | 
|---|
| 142 | sc_event_finder& neg () const { return *new sc_event_finder (*(sc_port_base*)this);}; | 
|---|
| 143 | sc_event_finder& pos () const { return *new sc_event_finder (*(sc_port_base*)this);}; | 
|---|
| 144 | #endif | 
|---|
| 145 |  | 
|---|
| 146 | sc_event         neg () const { return sc_event (*this, sc_event::NEG);}; | 
|---|
| 147 | sc_event         pos () const { return sc_event (*this, sc_event::POS);}; | 
|---|
| 148 | // read the current value | 
|---|
| 149 | inline const T& read() const INLINE; | 
|---|
| 150 | inline operator const T& () const INLINE; | 
|---|
| 151 |  | 
|---|
| 152 | // operateur == | 
|---|
| 153 | inline bool operator == (const T& v) INLINE; | 
|---|
| 154 |  | 
|---|
| 155 | // bind to in interface | 
|---|
| 156 | void operator () (sc_signal<data_type> &s) | 
|---|
| 157 | { sc_core::bind (*this,s); } | 
|---|
| 158 |  | 
|---|
| 159 | // binding for hierarchical description | 
|---|
| 160 | void operator () (this_type &parent_) | 
|---|
| 161 | { sc_core::bind (*this,parent_); } | 
|---|
| 162 |  | 
|---|
| 163 | void operator () (sc_out<data_type> &o) | 
|---|
| 164 | { sc_core::bind (*this,o); } | 
|---|
| 165 |  | 
|---|
| 166 | /*virtual */~sc_in() {}; | 
|---|
| 167 |  | 
|---|
| 168 | }; | 
|---|
| 169 |  | 
|---|
| 170 | template <typename T> | 
|---|
| 171 | void | 
|---|
| 172 | sc_in<T>::init() | 
|---|
| 173 | { | 
|---|
| 174 | set_kind (sc_in_string); | 
|---|
| 175 | sc_interface::init (sizeof (data_type)); | 
|---|
| 176 | } | 
|---|
| 177 |  | 
|---|
| 178 | // read | 
|---|
| 179 | template <typename T> inline | 
|---|
| 180 | const T& | 
|---|
| 181 | sc_in<T>::read() const | 
|---|
| 182 | { | 
|---|
| 183 | #ifdef DUMP_READ | 
|---|
| 184 | std::cerr << "read " << READ_SIGNAL(const T&, get_pointer()) | 
|---|
| 185 | << " on signal " << name () << "\n"; | 
|---|
| 186 | #endif | 
|---|
| 187 | return READ_SIGNAL(const T, get_pointer()); | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|
| 190 | template <typename T> inline | 
|---|
| 191 | sc_in<T>::operator const T& () const | 
|---|
| 192 | { return sc_in<T>::read (); } | 
|---|
| 193 |  | 
|---|
| 194 | template <typename T> inline | 
|---|
| 195 | bool sc_in<T>::operator == (const T& v) { | 
|---|
| 196 | return sc_in<T>::read() == v; | 
|---|
| 197 | } | 
|---|
| 198 |  | 
|---|
| 199 | // ---------------------------------------------------------------------------- | 
|---|
| 200 | //  CLASS : sc_inout<T> | 
|---|
| 201 | // | 
|---|
| 202 | // ---------------------------------------------------------------------------- | 
|---|
| 203 |  | 
|---|
| 204 | template <typename T> | 
|---|
| 205 | class sc_inout : public sc_port_base | 
|---|
| 206 | { | 
|---|
| 207 | /////////// | 
|---|
| 208 | // Internal | 
|---|
| 209 | protected: | 
|---|
| 210 | void init (); | 
|---|
| 211 | T val; | 
|---|
| 212 | private: | 
|---|
| 213 | typedef T                                   data_type; | 
|---|
| 214 |  | 
|---|
| 215 | typedef sc_inout<data_type>                 this_type; | 
|---|
| 216 | typedef sc_signal<data_type>                signal_type; | 
|---|
| 217 |  | 
|---|
| 218 | /* | 
|---|
| 219 | public: virtual size_t data_size () const | 
|---|
| 220 | { return sizeof (data_type); } | 
|---|
| 221 | */ | 
|---|
| 222 | /////////// | 
|---|
| 223 | public: | 
|---|
| 224 | // contructeurs | 
|---|
| 225 | sc_inout(): base_type() { init (); }; | 
|---|
| 226 |  | 
|---|
| 227 | explicit sc_inout(const char* name_): base_type(name_) { init (); }; | 
|---|
| 228 |  | 
|---|
| 229 | /* | 
|---|
| 230 | // LRM error ! | 
|---|
| 231 | //static const char *const kind_string; this is a template ! | 
|---|
| 232 | */ | 
|---|
| 233 | //virtual const char *kind () const | 
|---|
| 234 | //{ return "sc_inout"; }; | 
|---|
| 235 |  | 
|---|
| 236 | // read the current value | 
|---|
| 237 | inline const T& read() const INLINE; | 
|---|
| 238 | // write the new value | 
|---|
| 239 | inline void write( const T& ) INLINE; | 
|---|
| 240 | template <int W> inline void write( const sc_uint<W>& v) | 
|---|
| 241 | { sc_inout<T>::write (v.read()); } | 
|---|
| 242 |  | 
|---|
| 243 | inline operator const T& () const INLINE; | 
|---|
| 244 |  | 
|---|
| 245 | inline sc_inout<T>& operator = ( const T& a ) INLINE; | 
|---|
| 246 |  | 
|---|
| 247 | inline sc_inout<T>& operator = ( const sc_signal<T>& a ) INLINE; | 
|---|
| 248 |  | 
|---|
| 249 | //  inline sc_inout<T>& operator = ( const sc_port_base& a ) INLINE; | 
|---|
| 250 |  | 
|---|
| 251 | // operateur == | 
|---|
| 252 | inline bool operator == (const bool& v) INLINE; | 
|---|
| 253 |  | 
|---|
| 254 | // bind to in interface | 
|---|
| 255 | void operator () (sc_signal<data_type> &s) | 
|---|
| 256 | { bind (*this); bind (*this,s); } | 
|---|
| 257 |  | 
|---|
| 258 | void operator () (this_type &parent_) | 
|---|
| 259 | { bind (*this,parent_); } | 
|---|
| 260 |  | 
|---|
| 261 | /*virtual */~sc_inout() {}; | 
|---|
| 262 | }; | 
|---|
| 263 |  | 
|---|
| 264 | template <typename T> | 
|---|
| 265 | void | 
|---|
| 266 | sc_inout<T>::init () | 
|---|
| 267 | { | 
|---|
| 268 | set_pointer ((tab_t*)(void*)&val); | 
|---|
| 269 | sc_object::set_kind    (sc_inout_string); | 
|---|
| 270 | sc_interface::init (sizeof (data_type)); | 
|---|
| 271 | /*ref*/ val = (0); | 
|---|
| 272 | //sc_inout::write (0); | 
|---|
| 273 | /* Fix : | 
|---|
| 274 | * FSM checker generates an error at runtime | 
|---|
| 275 | */ | 
|---|
| 276 |  | 
|---|
| 277 | } | 
|---|
| 278 |  | 
|---|
| 279 | // read | 
|---|
| 280 | template <typename T> | 
|---|
| 281 | inline | 
|---|
| 282 | const T& | 
|---|
| 283 | sc_inout<T>::read() const | 
|---|
| 284 | { | 
|---|
| 285 | #ifdef DUMP_READ | 
|---|
| 286 | std::cerr << "read " << READ_SIGNAL(const T, get_pointer()) // val | 
|---|
| 287 | << " on signal " << name () << "\n"; | 
|---|
| 288 | #endif | 
|---|
| 289 | //  return val; | 
|---|
| 290 | return READ_SIGNAL(const T, get_pointer()); | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 | // write the new value | 
|---|
| 294 | template <typename T> | 
|---|
| 295 | inline | 
|---|
| 296 | void | 
|---|
| 297 | sc_inout<T>::write( const T& value_ ) | 
|---|
| 298 | { | 
|---|
| 299 | #ifdef DUMP_WRITE | 
|---|
| 300 | std::cerr << "write " << value_ | 
|---|
| 301 | << " on in/out port (writing into a signal) '" << name () << "'\n"; | 
|---|
| 302 | #endif | 
|---|
| 303 | //  T& ref = *(T*)(get_pointer()); | 
|---|
| 304 | #ifndef USE_PORT_DEPENDENCY | 
|---|
| 305 | unstable |= (value_) != val; //ref; | 
|---|
| 306 | #endif | 
|---|
| 307 | /*ref*/ val = (value_); | 
|---|
| 308 | } | 
|---|
| 309 |  | 
|---|
| 310 | template <typename T> | 
|---|
| 311 | inline | 
|---|
| 312 | sc_inout<T>::operator const T& () const | 
|---|
| 313 | { return sc_inout<T>::read(); } | 
|---|
| 314 |  | 
|---|
| 315 | template <typename T> | 
|---|
| 316 | inline sc_inout<T>& sc_inout<T>::operator = ( const T& a ) | 
|---|
| 317 | { sc_inout<T>::write( a ); return *this; } | 
|---|
| 318 |  | 
|---|
| 319 | template <typename T> | 
|---|
| 320 | inline | 
|---|
| 321 | sc_inout<T>& sc_inout<T>::operator = ( const sc_signal<T>& a ) | 
|---|
| 322 | { sc_inout<T>::write( a.read() ); return *this; } | 
|---|
| 323 | /* | 
|---|
| 324 | template <typename T> | 
|---|
| 325 | inline | 
|---|
| 326 | sc_inout<T>& sc_inout<T>::operator = ( const sc_port_base& a ) | 
|---|
| 327 | { write( a.read() ); return *this; } | 
|---|
| 328 | */ | 
|---|
| 329 | template <typename T> | 
|---|
| 330 | inline | 
|---|
| 331 | bool sc_inout<T>::operator == (const bool& v) | 
|---|
| 332 | { return sc_inout<T>::read() == v; } | 
|---|
| 333 |  | 
|---|
| 334 | // ---------------------------------------------------------------------------- | 
|---|
| 335 | //  CLASS : sc_out<T> | 
|---|
| 336 | // | 
|---|
| 337 | // ---------------------------------------------------------------------------- | 
|---|
| 338 | // Official SystemC implementation notes : | 
|---|
| 339 | // "sc_out can also read from its port, hence no difference with sc_inout. | 
|---|
| 340 | // For debugging reasons, a class is provided instead of a define." | 
|---|
| 341 |  | 
|---|
| 342 | template <typename T> | 
|---|
| 343 | class sc_out : public sc_inout<T> | 
|---|
| 344 | { | 
|---|
| 345 | /////////// | 
|---|
| 346 | // Internal | 
|---|
| 347 | void init (); | 
|---|
| 348 | /////////// | 
|---|
| 349 | public: | 
|---|
| 350 | // typedefs | 
|---|
| 351 | typedef T data_type; | 
|---|
| 352 | typedef sc_inout<T> base_type; | 
|---|
| 353 | typedef sc_out<data_type>      this_type; | 
|---|
| 354 | typedef sc_signal<data_type>   signal_type; | 
|---|
| 355 | public: | 
|---|
| 356 | // constructors & destructor | 
|---|
| 357 | sc_out(): base_type() { init (); }; | 
|---|
| 358 | explicit sc_out(const char* name_): base_type(name_) { init (); }; | 
|---|
| 359 | sc_out (this_type & parent_); | 
|---|
| 360 | sc_out (const char *name_, this_type & parent_); | 
|---|
| 361 |  | 
|---|
| 362 | /* | 
|---|
| 363 | // LRM error ! | 
|---|
| 364 | //static const char *const kind_string; this is a template ! | 
|---|
| 365 | */ | 
|---|
| 366 | //virtual const char *kind () const | 
|---|
| 367 | //{ return "sc_out"; }; | 
|---|
| 368 |  | 
|---|
| 369 |  | 
|---|
| 370 | inline this_type& operator = ( const data_type& a ) INLINE; | 
|---|
| 371 | inline bool operator == (const bool& v) INLINE; | 
|---|
| 372 |  | 
|---|
| 373 | // bind to in interface | 
|---|
| 374 | void operator () (sc_signal<data_type> &s) | 
|---|
| 375 | { bind (*this,s); } | 
|---|
| 376 |  | 
|---|
| 377 | void operator () (this_type &parent_) | 
|---|
| 378 | { bind (*this,parent_); } | 
|---|
| 379 |  | 
|---|
| 380 | ////////////////////// | 
|---|
| 381 | // Systemcass specific | 
|---|
| 382 | void operator () (sc_port_base &o) | 
|---|
| 383 | { set_port_dependency (&o, (sc_port_base&)(*this)); } | 
|---|
| 384 | /* | 
|---|
| 385 | void operator () () // n'a pas de sens... | 
|---|
| 386 | { set_port_dependency (NULL, (sc_port_base&)(*this)); } | 
|---|
| 387 | */ | 
|---|
| 388 | ////////////////////// | 
|---|
| 389 |  | 
|---|
| 390 |  | 
|---|
| 391 | /*virtual */~ sc_out () {}; | 
|---|
| 392 |  | 
|---|
| 393 | private: | 
|---|
| 394 | // disabled | 
|---|
| 395 | sc_out (const this_type &); | 
|---|
| 396 | }; | 
|---|
| 397 |  | 
|---|
| 398 | // | 
|---|
| 399 | template<typename T> | 
|---|
| 400 | void | 
|---|
| 401 | sc_out<T>::init () | 
|---|
| 402 | { | 
|---|
| 403 | sc_inout<T>::init (); | 
|---|
| 404 | //  tab_t *t = &(sc_inout<T>::val); | 
|---|
| 405 | //  sc_interface::set_pointer (t); | 
|---|
| 406 | sc_object::set_kind (sc_out_string); | 
|---|
| 407 | //  sc_interface::init (sizeof (data_type)); | 
|---|
| 408 | //  /*ref*/ sc_inout<T>::val = 0; | 
|---|
| 409 | //sc_inout<T>::write (0); | 
|---|
| 410 | /* Fix : | 
|---|
| 411 | * FSM checker generates an error at runtime | 
|---|
| 412 | */ | 
|---|
| 413 | } | 
|---|
| 414 |  | 
|---|
| 415 | template<typename T> inline | 
|---|
| 416 | sc_out<T>& | 
|---|
| 417 | sc_out<T>::operator = ( const data_type& a ) | 
|---|
| 418 | { sc_out<T>::write( a ); return *this; } | 
|---|
| 419 |  | 
|---|
| 420 | template<typename T> inline | 
|---|
| 421 | bool | 
|---|
| 422 | sc_out<T>::operator == (const bool& v) | 
|---|
| 423 | { return sc_out<T>::read() == v; } | 
|---|
| 424 |  | 
|---|
| 425 | // Dumps | 
|---|
| 426 | template<typename T> inline | 
|---|
| 427 | std::ostream& operator<<( std::ostream& os, const sc_in<T> &r) | 
|---|
| 428 | { return os << r.read (); } | 
|---|
| 429 |  | 
|---|
| 430 | // Add '&' | 
|---|
| 431 | template<class T> inline | 
|---|
| 432 | std::ostream& operator<<( std::ostream& os, const sc_inout<T> &r) | 
|---|
| 433 | { return os << r.read (); } | 
|---|
| 434 |  | 
|---|
| 435 | template<class T> inline | 
|---|
| 436 | std::ostream& operator<<( std::ostream& os, const sc_signal<T> &r) | 
|---|
| 437 | { return os << r.read (); } | 
|---|
| 438 |  | 
|---|
| 439 | // Declarations | 
|---|
| 440 | typedef sc_in<bool> sc_in_clk; | 
|---|
| 441 |  | 
|---|
| 442 | #undef INLINE | 
|---|
| 443 |  | 
|---|
| 444 | #undef READ_SIGNAL | 
|---|
| 445 |  | 
|---|
| 446 | } // end of sc_core namespace | 
|---|
| 447 |  | 
|---|
| 448 | using sc_core::sc_in_clk; | 
|---|
| 449 |  | 
|---|
| 450 | #endif /* __SC_PORT_EXT_H__ */ | 
|---|