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