00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 #ifndef SC_MODULE_H
00030 #define SC_MODULE_H
00031 
00032 #include "sysc/kernel/sc_kernel_ids.h"
00033 #include "sysc/kernel/sc_process.h"
00034 #include "sysc/kernel/sc_module_name.h"
00035 #include "sysc/kernel/sc_sensitive.h"
00036 #include "sysc/kernel/sc_time.h"
00037 #include "sysc/kernel/sc_wait.h"
00038 #include "sysc/kernel/sc_wait_cthread.h"
00039 #include "sysc/kernel/sc_process.h"
00040 #include "sysc/kernel/sc_process_handle.h"
00041 #include "sysc/utils/sc_list.h"
00042 
00043 namespace sc_core {
00044 
00045 class sc_name_gen;
00046 template<class T> class sc_in;
00047 template<class T> class sc_inout;
00048 template<class T> class sc_out;
00049 
00050 
00058 struct sc_bind_proxy
00059 {
00060     sc_interface* iface;
00061     sc_port_base* port;
00062     
00063     sc_bind_proxy();
00064     sc_bind_proxy( sc_interface& );
00065     sc_bind_proxy( sc_port_base& );
00066 };
00067 
00068 
00069 extern const sc_bind_proxy SC_BIND_PROXY_NIL;
00070 
00071 
00072 
00078 class sc_module
00079 : public sc_object, public sc_process_host
00080 {
00081     friend class sc_module_name;
00082     friend class sc_module_registry;
00083     friend class sc_object;
00084     friend class sc_port_registry;
00085     friend class sc_process_b;
00086     friend class sc_simcontext;
00087 
00088 public:
00089 
00090     sc_simcontext* sc_get_curr_simcontext()
00091         { return simcontext(); }
00092 
00093     
00094     const char* gen_unique_name( const char* basename_, bool preserve_first );
00095 
00096     virtual const char* kind() const
00097         { return "sc_module"; }
00098 
00099 protected:
00100   
00101     
00102     virtual void before_end_of_elaboration();
00103 
00104     void construction_done();
00105 
00106     
00107     virtual void end_of_elaboration();
00108 
00109     void elaboration_done( bool& );
00110 
00111     
00112     virtual void start_of_simulation();
00113 
00114     void start_simulation();
00115 
00116     
00117     virtual void end_of_simulation();
00118 
00119     void simulation_done();
00120 
00121     void sc_module_init();
00122 
00123     
00124     sc_module();
00125     sc_module( const sc_module_name& nm ); 
00126 
00127      sc_module( const char* nm ); 
00128      sc_module( const std::string& nm );
00129 
00130 public:
00131 
00132     
00133     virtual ~sc_module();
00134 
00135     
00136 
00137     sc_module& operator << ( sc_interface& );
00138     sc_module& operator << ( sc_port_base& );
00139 
00140     sc_module& operator , ( sc_interface& interface_ )
00141         { return operator << ( interface_ ); }
00142 
00143     sc_module& operator , ( sc_port_base& port_ )
00144         { return operator << ( port_ ); }
00145 
00146     
00147 
00148     const ::std::vector<sc_object*>& get_child_objects() const;
00149 
00150 protected:
00151 
00152     
00153     void end_module();
00154 
00155 
00156     
00157     void dont_initialize();
00158 
00159     
00160 
00161     void positional_bind( sc_interface& );
00162     void positional_bind( sc_port_base& );
00163 
00164     
00165     void async_reset_signal_is( const sc_in<bool>& port, bool level );
00166     void async_reset_signal_is( const sc_inout<bool>& port, bool level );
00167     void async_reset_signal_is( const sc_out<bool>& port, bool level );
00168     void async_reset_signal_is( const sc_signal_in_if<bool>& iface, bool level);
00169     void reset_signal_is( const sc_in<bool>& port, bool level );
00170     void reset_signal_is( const sc_inout<bool>& port, bool level );
00171     void reset_signal_is( const sc_out<bool>& port, bool level );
00172     void reset_signal_is( const sc_signal_in_if<bool>& iface, bool level );
00173  
00174     
00175 
00180     
00181     void wait( int seg_id )
00182         { ::sc_core::wait( seg_id, simcontext() ); }
00183 
00184     
00185 
00190     
00191     void wait( const sc_event& e, int seg_id )
00192         { ::sc_core::wait( e, seg_id, simcontext() ); }
00193 
00198     
00199     void wait( const sc_event_or_list& el, int seg_id )
00200         { ::sc_core::wait( el, seg_id, simcontext() ); }
00201 
00206     
00207     void wait( const sc_event_and_list& el, int seg_id )
00208         { ::sc_core::wait( el, seg_id, simcontext() ); }
00209 
00214     
00215     void wait( const sc_time& t, int seg_id )
00216         { ::sc_core::wait( t, seg_id, simcontext() ); }
00217 
00222     
00223     void wait( double v, sc_time_unit tu, int seg_id )
00224         { ::sc_core::wait( sc_time( v, tu, simcontext() ), seg_id, 
00225                            simcontext() ); }
00226 
00231     
00232     void wait( const sc_time& t, const sc_event& e, int seg_id )
00233         { ::sc_core::wait( t, e, seg_id, simcontext() ); }
00234 
00239     
00240     void wait( double v, sc_time_unit tu, const sc_event& e, int seg_id )
00241         { ::sc_core::wait( 
00242                 sc_time( v, tu, simcontext() ), e, seg_id, simcontext() ); }
00243 
00248     
00249     void wait( const sc_time& t, const sc_event_or_list& el, int seg_id )
00250         { ::sc_core::wait( t, el, seg_id, simcontext() ); }
00251 
00256     
00257     void wait( double v, sc_time_unit tu, const sc_event_or_list& el, 
00258                int seg_id )
00259         { ::sc_core::wait( sc_time( v, tu, simcontext() ), el, seg_id, 
00260                            simcontext() ); }
00261 
00266     
00267     void wait( const sc_time& t, const sc_event_and_list& el, int seg_id )
00268         { ::sc_core::wait( t, el, seg_id, simcontext() ); }
00269 
00274     
00275     void wait( double v, sc_time_unit tu, const sc_event_and_list& el,
00276                int seg_id )
00277         { ::sc_core::wait( sc_time( v, tu, simcontext() ), el, seg_id, 
00278                            simcontext() ); }
00279 
00280 
00281     
00282 
00287     
00288     void next_trigger( int seg_id )
00289         { ::sc_core::next_trigger( seg_id, simcontext() ); }
00290 
00291 
00292     
00293 
00298     
00299     void next_trigger( const sc_event& e, int seg_id )
00300         { ::sc_core::next_trigger( e, seg_id, simcontext() ); }
00301 
00306     
00307     void next_trigger( const sc_event_or_list& el, int seg_id )
00308         { ::sc_core::next_trigger( el, seg_id, simcontext() ); }
00309 
00314     
00315     void next_trigger( const sc_event_and_list& el, int seg_id )
00316         { ::sc_core::next_trigger( el, seg_id, simcontext() ); }
00317 
00322     
00323     void next_trigger( const sc_time& t, int seg_id )
00324         { ::sc_core::next_trigger( t, seg_id, simcontext() ); }
00325 
00330     
00331     void next_trigger( double v, sc_time_unit tu, int seg_id )
00332         { ::sc_core::next_trigger( 
00333             sc_time( v, tu, simcontext() ), seg_id, simcontext() ); }
00334 
00339     
00340     void next_trigger( const sc_time& t, const sc_event& e, int seg_id )
00341         { ::sc_core::next_trigger( t, e, seg_id, simcontext() ); }
00342 
00347     
00348     void next_trigger( double v, sc_time_unit tu, const sc_event& e,
00349                        int seg_id )
00350         { ::sc_core::next_trigger( 
00351                 sc_time( v, tu, simcontext() ), e, seg_id, simcontext() ); }
00352 
00357     
00358     void next_trigger( const sc_time& t, const sc_event_or_list& el,
00359                        int seg_id )
00360         { ::sc_core::next_trigger( t, el, seg_id, simcontext() ); }
00361 
00366     
00367     void next_trigger( double v, sc_time_unit tu, const sc_event_or_list& el,
00368                        int seg_id )
00369         { ::sc_core::next_trigger( 
00370             sc_time( v, tu, simcontext() ), el, seg_id, simcontext() ); }
00371 
00376     
00377     void next_trigger( const sc_time& t, const sc_event_and_list& el,
00378                        int seg_id )
00379         { ::sc_core::next_trigger( t, el, seg_id, simcontext() ); }
00380 
00385     
00386     void next_trigger( double v, sc_time_unit tu, const sc_event_and_list& el,
00387                        int seg_id )
00388         { ::sc_core::next_trigger( 
00389             sc_time( v, tu, simcontext() ), el, seg_id, simcontext() ); }
00390 
00391 
00392     
00393 
00394     bool timed_out()
00395         { return ::sc_core::timed_out(); }
00396 
00397 
00398     
00399 
00404     
00405     void halt( int seg_id )
00406         { ::sc_core::halt( seg_id, simcontext() ); }
00407 
00412     
00413     void wait( int n, int seg_id )
00414         { ::sc_core::wait( n, seg_id, simcontext() ); }
00415 
00420     
00421     void at_posedge( const sc_signal_in_if<bool>& s, int seg_id )
00422         { ::sc_core::at_posedge( s, seg_id, simcontext() ); }
00423 
00428     
00429     void at_posedge( const sc_signal_in_if<sc_dt::sc_logic>& s, int seg_id )
00430         { ::sc_core::at_posedge( s, seg_id, simcontext() ); }
00431 
00436     
00437     void at_negedge( const sc_signal_in_if<bool>& s, int seg_id )
00438         { ::sc_core::at_negedge( s, seg_id, simcontext() ); }
00439 
00444     
00445     void at_negedge( const sc_signal_in_if<sc_dt::sc_logic>& s, int seg_id )
00446         { ::sc_core::at_negedge( s, seg_id, simcontext() ); }
00447 
00448     
00449     void watching( bool  )
00450         { SC_REPORT_ERROR(SC_ID_WATCHING_NOT_ALLOWED_,""); }
00451 
00452     
00453     sc_sensitive     sensitive;
00454     sc_sensitive_pos sensitive_pos;
00455     sc_sensitive_neg sensitive_neg;
00456 
00461     
00462     void set_stack_size( std::size_t );
00463 
00464     int append_port( sc_port_base* );
00465 
00469     
00470     int m_instance_id;
00471 
00472 private:
00473     sc_module( const sc_module& );
00474     const sc_module& operator = ( const sc_module& );
00475 
00476 private:
00477 
00478     bool                        m_end_module_called;
00479     std::vector<sc_port_base*>* m_port_vec;
00480     int                         m_port_index;
00481     sc_name_gen*                m_name_gen;
00482     sc_module_name*             m_module_name_p;
00483 
00484 public:
00485 
00486     void defunct() { }
00487 
00488     
00489 
00490     void operator () ( const sc_bind_proxy& p001,
00491                        const sc_bind_proxy& p002 = SC_BIND_PROXY_NIL,
00492                        const sc_bind_proxy& p003 = SC_BIND_PROXY_NIL,
00493                        const sc_bind_proxy& p004 = SC_BIND_PROXY_NIL,
00494                        const sc_bind_proxy& p005 = SC_BIND_PROXY_NIL,
00495                        const sc_bind_proxy& p006 = SC_BIND_PROXY_NIL,
00496                        const sc_bind_proxy& p007 = SC_BIND_PROXY_NIL,
00497                        const sc_bind_proxy& p008 = SC_BIND_PROXY_NIL,
00498                        const sc_bind_proxy& p009 = SC_BIND_PROXY_NIL,
00499                        const sc_bind_proxy& p010 = SC_BIND_PROXY_NIL,
00500                        const sc_bind_proxy& p011 = SC_BIND_PROXY_NIL,
00501                        const sc_bind_proxy& p012 = SC_BIND_PROXY_NIL,
00502                        const sc_bind_proxy& p013 = SC_BIND_PROXY_NIL,
00503                        const sc_bind_proxy& p014 = SC_BIND_PROXY_NIL,
00504                        const sc_bind_proxy& p015 = SC_BIND_PROXY_NIL,
00505                        const sc_bind_proxy& p016 = SC_BIND_PROXY_NIL,
00506                        const sc_bind_proxy& p017 = SC_BIND_PROXY_NIL,
00507                        const sc_bind_proxy& p018 = SC_BIND_PROXY_NIL,
00508                        const sc_bind_proxy& p019 = SC_BIND_PROXY_NIL,
00509                        const sc_bind_proxy& p020 = SC_BIND_PROXY_NIL,
00510                        const sc_bind_proxy& p021 = SC_BIND_PROXY_NIL,
00511                        const sc_bind_proxy& p022 = SC_BIND_PROXY_NIL,
00512                        const sc_bind_proxy& p023 = SC_BIND_PROXY_NIL,
00513                        const sc_bind_proxy& p024 = SC_BIND_PROXY_NIL,
00514                        const sc_bind_proxy& p025 = SC_BIND_PROXY_NIL,
00515                        const sc_bind_proxy& p026 = SC_BIND_PROXY_NIL,
00516                        const sc_bind_proxy& p027 = SC_BIND_PROXY_NIL,
00517                        const sc_bind_proxy& p028 = SC_BIND_PROXY_NIL,
00518                        const sc_bind_proxy& p029 = SC_BIND_PROXY_NIL,
00519                        const sc_bind_proxy& p030 = SC_BIND_PROXY_NIL,
00520                        const sc_bind_proxy& p031 = SC_BIND_PROXY_NIL,
00521                        const sc_bind_proxy& p032 = SC_BIND_PROXY_NIL,
00522                        const sc_bind_proxy& p033 = SC_BIND_PROXY_NIL,
00523                        const sc_bind_proxy& p034 = SC_BIND_PROXY_NIL,
00524                        const sc_bind_proxy& p035 = SC_BIND_PROXY_NIL,
00525                        const sc_bind_proxy& p036 = SC_BIND_PROXY_NIL,
00526                        const sc_bind_proxy& p037 = SC_BIND_PROXY_NIL,
00527                        const sc_bind_proxy& p038 = SC_BIND_PROXY_NIL,
00528                        const sc_bind_proxy& p039 = SC_BIND_PROXY_NIL,
00529                        const sc_bind_proxy& p040 = SC_BIND_PROXY_NIL,
00530                        const sc_bind_proxy& p041 = SC_BIND_PROXY_NIL,
00531                        const sc_bind_proxy& p042 = SC_BIND_PROXY_NIL,
00532                        const sc_bind_proxy& p043 = SC_BIND_PROXY_NIL,
00533                        const sc_bind_proxy& p044 = SC_BIND_PROXY_NIL,
00534                        const sc_bind_proxy& p045 = SC_BIND_PROXY_NIL,
00535                        const sc_bind_proxy& p046 = SC_BIND_PROXY_NIL,
00536                        const sc_bind_proxy& p047 = SC_BIND_PROXY_NIL,
00537                        const sc_bind_proxy& p048 = SC_BIND_PROXY_NIL,
00538                        const sc_bind_proxy& p049 = SC_BIND_PROXY_NIL,
00539                        const sc_bind_proxy& p050 = SC_BIND_PROXY_NIL,
00540                        const sc_bind_proxy& p051 = SC_BIND_PROXY_NIL,
00541                        const sc_bind_proxy& p052 = SC_BIND_PROXY_NIL,
00542                        const sc_bind_proxy& p053 = SC_BIND_PROXY_NIL,
00543                        const sc_bind_proxy& p054 = SC_BIND_PROXY_NIL,
00544                        const sc_bind_proxy& p055 = SC_BIND_PROXY_NIL,
00545                        const sc_bind_proxy& p056 = SC_BIND_PROXY_NIL,
00546                        const sc_bind_proxy& p057 = SC_BIND_PROXY_NIL,
00547                        const sc_bind_proxy& p058 = SC_BIND_PROXY_NIL,
00548                        const sc_bind_proxy& p059 = SC_BIND_PROXY_NIL,
00549                        const sc_bind_proxy& p060 = SC_BIND_PROXY_NIL,
00550                        const sc_bind_proxy& p061 = SC_BIND_PROXY_NIL,
00551                        const sc_bind_proxy& p062 = SC_BIND_PROXY_NIL,
00552                        const sc_bind_proxy& p063 = SC_BIND_PROXY_NIL,
00553                        const sc_bind_proxy& p064 = SC_BIND_PROXY_NIL );
00554 
00555 };
00556 
00557 extern sc_module* sc_module_dynalloc(sc_module*);
00558 #define SC_NEW(x)  ::sc_core::sc_module_dynalloc(new x);
00559 
00560 
00561 
00562 
00563 
00564 
00565 #define SC_MODULE(user_module_name)                                           \
00566     struct user_module_name : ::sc_core::sc_module
00567 
00568 
00569 #define SC_CHANNEL(user_module_name)                                           \
00570     struct user_module_name : ::sc_core::sc_channel
00571 
00572 #define SC_CTOR(user_module_name)                                             \
00573     typedef user_module_name SC_CURRENT_USER_MODULE;                          \
00574     user_module_name( ::sc_core::sc_module_name )
00575 
00576 
00577 #define SC_HAS_PROCESS(user_module_name)                                      \
00578     typedef user_module_name SC_CURRENT_USER_MODULE
00579 
00580 
00581 
00582 
00583 
00584 
00585 
00586 
00587 
00588 
00593 
00594 
00595 #define declare_method_process(handle, name, host_tag, func, seg_id, inst_id)  \
00596     {                                                                          \
00597         ::sc_core::sc_process_handle handle =                                  \
00598             sc_core::sc_get_curr_simcontext()->create_method_process(          \
00599                 name,  false, SC_MAKE_FUNC_PTR( host_tag, func ),              \
00600                 this, 0, seg_id, inst_id );                                    \
00601         this->sensitive << handle;                                             \
00602         this->sensitive_pos << handle;                                         \
00603         this->sensitive_neg << handle;                                         \
00604     }
00605 
00610 
00611 
00612 #define declare_thread_process(handle, name, host_tag, func, seg_id, inst_id)  \
00613     {                                                                          \
00614         ::sc_core::sc_process_handle handle =                                  \
00615              sc_core::sc_get_curr_simcontext()->create_thread_process(         \
00616                  name,  false,                                                 \
00617                  SC_MAKE_FUNC_PTR( host_tag, func ),                           \
00618                  this, 0, seg_id, inst_id );                                   \
00619         this->sensitive << handle;                                             \
00620         this->sensitive_pos << handle;                                         \
00621         this->sensitive_neg << handle;                                         \
00622     }
00623 
00628 
00629 
00630 #define declare_cthread_process(handle, name, host_tag, func, edge,            \
00631                                 seg_id, inst_id)                               \
00632     {                                                                          \
00633         ::sc_core::sc_process_handle handle =                                  \
00634              sc_core::sc_get_curr_simcontext()->create_cthread_process(        \
00635                  name,  false,                                                 \
00636                  SC_MAKE_FUNC_PTR( host_tag, func ),                           \
00637                  this, 0, seg_id, inst_id );                                   \
00638         this->sensitive.operator() ( handle, edge );                           \
00639     }
00640 
00645 
00646 
00647 #define SC_CTHREAD(func, edge, seg_id, inst_id)                               \
00648     declare_cthread_process( func ## _handle,                                 \
00649                              #func,                                           \
00650                              SC_CURRENT_USER_MODULE,                          \
00651                              func,                                            \
00652                              edge,                                            \
00653                              seg_id,                                          \
00654                              inst_id )
00655 
00660 
00661 
00662 #define SC_METHOD(func, seg_id, inst_id)                                      \
00663     declare_method_process( func ## _handle,                                  \
00664                             #func,                                            \
00665                             SC_CURRENT_USER_MODULE,                           \
00666                             func,                                             \
00667                             seg_id,                                           \
00668                             inst_id )
00669 
00674 
00675 
00676 #define SC_THREAD(func, seg_id, inst_id)                                      \
00677     declare_thread_process( func ## _handle,                                  \
00678                             #func,                                            \
00679                             SC_CURRENT_USER_MODULE,                           \
00680                             func,                                             \
00681                             seg_id,                                           \
00682                             inst_id )
00683 
00684 
00685 
00686 
00687 
00688 
00689 
00690 
00691 
00692 typedef sc_module sc_behavior;
00693 
00694 
00695 
00700 
00701 class sc_channel
00702 : public sc_module
00703 {
00704     friend class sc_module_name;
00705     friend class sc_module_registry;
00706     friend class sc_object;
00707     friend class sc_port_registry;
00708     friend class sc_process_b;
00709     friend class sc_simcontext;
00710 
00711 public:
00712 
00713     virtual const char* kind() const
00714         { return "sc_channel"; }
00715 
00716 protected:
00717 
00718     
00719     sc_channel();
00720     sc_channel( const sc_module_name& nm ); 
00721 
00722      sc_channel( const char* nm ); 
00723      sc_channel( const std::string& nm );
00724 
00725 public:
00726 
00727     
00728     virtual ~sc_channel();
00729 
00730 private:
00731     sc_channel( const sc_channel& );
00732     const sc_channel& operator = ( const sc_channel& );
00733 
00734 protected:
00735 
00739     
00740     mutable CHNL_MTX_TYPE_ m_mutex;
00741 };
00742 
00743 } 
00744 
00745 
00746 
00747 
00748 
00749 
00750 
00751 
00752 
00753 
00754 
00755 
00756 
00757 
00758 
00759 
00760 
00761 
00762 
00763 
00764 
00765 
00766 
00767 
00768 
00769 
00770 
00771 
00772 
00773 
00774 
00775 
00776 
00777 
00778 
00779 
00780 
00781 
00782 
00783 
00784 
00785 
00786 
00787 
00788 
00789 
00790 
00791 
00792 
00793 
00794 
00795 
00796 
00797 
00798 
00799 
00800 
00801 
00802 
00803 
00804 
00805 
00806 
00807 
00808 
00809 
00810 
00811 
00812 
00813 
00814 
00815 
00816 
00817 
00818 
00819 
00820 
00821 
00822 
00823 
00824 
00825 
00826 
00827 
00828 
00829 
00830 
00831 
00832 
00833 
00834 
00835 
00836 
00837 
00838 
00839 
00840 
00841 
00842 
00843 
00844 
00845 
00846 
00847 
00848 
00849 
00850 
00851 #endif