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