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