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 #ifndef _SYSC_PRINT_VERBOSE_MESSAGE_ENV_VAR
00044 #define _SYSC_PRINT_VERBOSE_MESSAGE_ENV_VAR "SYSC_PRINT_VERBOSE_MESSAGE"
00045 #endif
00046 namespace sc_core {
00047 
00048 class sc_name_gen;
00049 template<class T> class sc_in;
00050 template<class T> class sc_inout;
00051 template<class T> class sc_out;
00052 
00053 
00061 struct sc_bind_proxy
00062 {
00063     sc_interface* iface;
00064     sc_port_base* port;
00065     
00066     sc_bind_proxy();
00067     sc_bind_proxy( sc_interface& );
00068     sc_bind_proxy( sc_port_base& );
00069 };
00070 
00071 
00072 extern const sc_bind_proxy SC_BIND_PROXY_NIL;
00073 
00074 
00075 
00081 class sc_module
00082 : public sc_object, public sc_process_host
00083 {
00084     friend class sc_module_name;
00085     friend class sc_module_registry;
00086     friend class sc_object;
00087     friend class sc_port_registry;
00088     friend class sc_process_b;
00089     friend class sc_simcontext;
00090 
00091 public:
00092 
00093     sc_simcontext* sc_get_curr_simcontext()
00094         { return simcontext(); }
00095 
00096     
00097     const char* gen_unique_name( const char* basename_, bool preserve_first );
00098 
00099     virtual const char* kind() const
00100         { return "sc_module"; }
00101         void test_message();
00102 protected:
00103   
00104     
00105     virtual void before_end_of_elaboration();
00106 
00107     void construction_done();
00108 
00109     
00110     virtual void end_of_elaboration();
00111 
00112     void elaboration_done( bool& );
00113 
00114     
00115     virtual void start_of_simulation();
00116 
00117     void start_simulation();
00118 
00119     
00120     virtual void end_of_simulation();
00121 
00122     void simulation_done();
00123 
00124     void sc_module_init();
00125 
00126     
00127     sc_module();
00128     sc_module( const sc_module_name& nm ); 
00129 
00130      sc_module( const char* nm ); 
00131      sc_module( const std::string& nm );
00132 
00133 public:
00134 
00135     
00136     virtual ~sc_module();
00137 
00138     
00139 
00140     sc_module& operator << ( sc_interface& );
00141     sc_module& operator << ( sc_port_base& );
00142 
00143     sc_module& operator , ( sc_interface& interface_ )
00144         { return operator << ( interface_ ); }
00145 
00146     sc_module& operator , ( sc_port_base& port_ )
00147         { return operator << ( port_ ); }
00148 
00149     
00150 
00151     const ::std::vector<sc_object*>& get_child_objects() const;
00152 
00153 protected:
00154 
00155     
00156     void end_module();
00157 
00158 
00159     
00160     void dont_initialize();
00161 
00162     
00163 
00164     void positional_bind( sc_interface& );
00165     void positional_bind( sc_port_base& );
00166 
00167     
00168     void async_reset_signal_is( const sc_in<bool>& port, bool level );
00169     void async_reset_signal_is( const sc_inout<bool>& port, bool level );
00170     void async_reset_signal_is( const sc_out<bool>& port, bool level );
00171     void async_reset_signal_is( const sc_signal_in_if<bool>& iface, bool level);
00172     void reset_signal_is( const sc_in<bool>& port, bool level );
00173     void reset_signal_is( const sc_inout<bool>& port, bool level );
00174     void reset_signal_is( const sc_out<bool>& port, bool level );
00175     void reset_signal_is( const sc_signal_in_if<bool>& iface, bool level );
00176  
00177     
00178 
00179         void seg_bound()
00180         {
00181 		::sc_core::aux_seg_bound(simcontext());
00182         }
00187     
00188     void wait( int seg_id )
00189         { ::sc_core::wait( seg_id, simcontext() ); }
00190 
00191     
00192 
00197     
00198     void wait( const sc_event& e, int seg_id )
00199         { 
00200 		::sc_core::wait( e, seg_id, simcontext() ); }
00201 
00206     
00207     void wait( const sc_event_or_list& el, int seg_id )
00208         { ::sc_core::wait( el, seg_id, simcontext() ); }
00209 
00214     
00215     void wait( const sc_event_and_list& el, int seg_id )
00216         { ::sc_core::wait( el, seg_id, simcontext() ); }
00217 
00222     
00223     void wait( const sc_time& t, int seg_id )
00224         { ::sc_core::wait( t, seg_id, simcontext() ); }
00225 
00230     
00231     void wait( double v, sc_time_unit tu, int seg_id )
00232         { ::sc_core::wait( sc_time( v, tu, simcontext() ), seg_id, 
00233                            simcontext() ); }
00234 
00239     
00240     void wait( const sc_time& t, const sc_event& e, int seg_id )
00241         { ::sc_core::wait( t, e, seg_id, simcontext() ); }
00242 
00247     
00248     void wait( double v, sc_time_unit tu, const sc_event& e, int seg_id )
00249         { ::sc_core::wait( 
00250                 sc_time( v, tu, simcontext() ), e, seg_id, simcontext() ); }
00251 
00256     
00257     void wait( const sc_time& t, const sc_event_or_list& el, int seg_id )
00258         { ::sc_core::wait( t, el, seg_id, simcontext() ); }
00259 
00264     
00265     void wait( double v, sc_time_unit tu, const sc_event_or_list& el, 
00266                int seg_id )
00267         { ::sc_core::wait( sc_time( v, tu, simcontext() ), el, seg_id, 
00268                            simcontext() ); }
00269 
00274     
00275     void wait( const sc_time& t, const sc_event_and_list& el, int seg_id )
00276         { ::sc_core::wait( t, el, seg_id, simcontext() ); }
00277 
00282     
00283     void wait( double v, sc_time_unit tu, const sc_event_and_list& el,
00284                int seg_id )
00285         { ::sc_core::wait( sc_time( v, tu, simcontext() ), el, seg_id, 
00286                            simcontext() ); }
00287 
00288 
00289     
00290 
00295     
00296     void next_trigger( int seg_id )
00297         { ::sc_core::next_trigger( seg_id, simcontext() ); }
00298 
00299 
00300     
00301 
00306     
00307     void next_trigger( const sc_event& e, int seg_id )
00308         { ::sc_core::next_trigger( e, seg_id, simcontext() ); }
00309 
00314     
00315     void next_trigger( const sc_event_or_list& el, int seg_id )
00316         { ::sc_core::next_trigger( el, seg_id, simcontext() ); }
00317 
00322     
00323     void next_trigger( const sc_event_and_list& el, int seg_id )
00324         { ::sc_core::next_trigger( el, seg_id, simcontext() ); }
00325 
00330     
00331     void next_trigger( const sc_time& t, int seg_id )
00332         { ::sc_core::next_trigger( t, seg_id, simcontext() ); }
00333 
00338     
00339     void next_trigger( double v, sc_time_unit tu, int seg_id )
00340         { ::sc_core::next_trigger( 
00341             sc_time( v, tu, simcontext() ), seg_id, simcontext() ); }
00342 
00347     
00348     void next_trigger( const sc_time& t, const sc_event& e, int seg_id )
00349         { ::sc_core::next_trigger( t, e, seg_id, simcontext() ); }
00350 
00355     
00356     void next_trigger( double v, sc_time_unit tu, const sc_event& e,
00357                        int seg_id )
00358         { ::sc_core::next_trigger( 
00359                 sc_time( v, tu, simcontext() ), e, seg_id, simcontext() ); }
00360 
00365     
00366     void next_trigger( const sc_time& t, const sc_event_or_list& el,
00367                        int seg_id )
00368         { ::sc_core::next_trigger( t, el, seg_id, simcontext() ); }
00369 
00374     
00375     void next_trigger( double v, sc_time_unit tu, const sc_event_or_list& el,
00376                        int seg_id )
00377         { ::sc_core::next_trigger( 
00378             sc_time( v, tu, simcontext() ), el, seg_id, simcontext() ); }
00379 
00384     
00385     void next_trigger( const sc_time& t, const sc_event_and_list& el,
00386                        int seg_id )
00387         { ::sc_core::next_trigger( t, el, seg_id, simcontext() ); }
00388 
00393     
00394     void next_trigger( double v, sc_time_unit tu, const sc_event_and_list& el,
00395                        int seg_id )
00396         { ::sc_core::next_trigger( 
00397             sc_time( v, tu, simcontext() ), el, seg_id, simcontext() ); }
00398 
00399 
00400     
00401 
00402     bool timed_out()
00403         { return ::sc_core::timed_out(); }
00404 
00405 
00406     
00407 
00412     
00413     void halt( int seg_id )
00414         { ::sc_core::halt( seg_id, simcontext() ); }
00415 
00420     
00421     void wait( int n, int seg_id )
00422         { ::sc_core::wait( n, seg_id, simcontext() ); }
00423 
00428     
00429     void at_posedge( const sc_signal_in_if<bool>& s, int seg_id )
00430         { ::sc_core::at_posedge( s, seg_id, simcontext() ); }
00431 
00436     
00437     void at_posedge( const sc_signal_in_if<sc_dt::sc_logic>& s, int seg_id )
00438         { ::sc_core::at_posedge( s, seg_id, simcontext() ); }
00439 
00444     
00445     void at_negedge( const sc_signal_in_if<bool>& s, int seg_id )
00446         { ::sc_core::at_negedge( s, seg_id, simcontext() ); }
00447 
00452     
00453     void at_negedge( const sc_signal_in_if<sc_dt::sc_logic>& s, int seg_id )
00454         { ::sc_core::at_negedge( s, seg_id, simcontext() ); }
00455 
00456     
00457     void watching( bool  )
00458         { SC_REPORT_ERROR(SC_ID_WATCHING_NOT_ALLOWED_,""); }
00459 
00460     
00461     sc_sensitive     sensitive;
00462     sc_sensitive_pos sensitive_pos;
00463     sc_sensitive_neg sensitive_neg;
00464 
00469     
00470     void set_stack_size( std::size_t );
00471 
00472     int append_port( sc_port_base* );
00473 
00477     
00478     int m_instance_id;
00479 
00480 private:
00481     sc_module( const sc_module& );
00482     const sc_module& operator = ( const sc_module& );
00483 
00484 private:
00485 
00486     bool                        m_end_module_called;
00487     std::vector<sc_port_base*>* m_port_vec;
00488     int                         m_port_index;
00489     sc_name_gen*                m_name_gen;
00490     sc_module_name*             m_module_name_p;
00491 
00492 public:
00493 
00494     void defunct() { }
00495 
00496     
00497 
00498     void operator () ( const sc_bind_proxy& p001,
00499                        const sc_bind_proxy& p002 = SC_BIND_PROXY_NIL,
00500                        const sc_bind_proxy& p003 = SC_BIND_PROXY_NIL,
00501                        const sc_bind_proxy& p004 = SC_BIND_PROXY_NIL,
00502                        const sc_bind_proxy& p005 = SC_BIND_PROXY_NIL,
00503                        const sc_bind_proxy& p006 = SC_BIND_PROXY_NIL,
00504                        const sc_bind_proxy& p007 = SC_BIND_PROXY_NIL,
00505                        const sc_bind_proxy& p008 = SC_BIND_PROXY_NIL,
00506                        const sc_bind_proxy& p009 = SC_BIND_PROXY_NIL,
00507                        const sc_bind_proxy& p010 = SC_BIND_PROXY_NIL,
00508                        const sc_bind_proxy& p011 = SC_BIND_PROXY_NIL,
00509                        const sc_bind_proxy& p012 = SC_BIND_PROXY_NIL,
00510                        const sc_bind_proxy& p013 = SC_BIND_PROXY_NIL,
00511                        const sc_bind_proxy& p014 = SC_BIND_PROXY_NIL,
00512                        const sc_bind_proxy& p015 = SC_BIND_PROXY_NIL,
00513                        const sc_bind_proxy& p016 = SC_BIND_PROXY_NIL,
00514                        const sc_bind_proxy& p017 = SC_BIND_PROXY_NIL,
00515                        const sc_bind_proxy& p018 = SC_BIND_PROXY_NIL,
00516                        const sc_bind_proxy& p019 = SC_BIND_PROXY_NIL,
00517                        const sc_bind_proxy& p020 = SC_BIND_PROXY_NIL,
00518                        const sc_bind_proxy& p021 = SC_BIND_PROXY_NIL,
00519                        const sc_bind_proxy& p022 = SC_BIND_PROXY_NIL,
00520                        const sc_bind_proxy& p023 = SC_BIND_PROXY_NIL,
00521                        const sc_bind_proxy& p024 = SC_BIND_PROXY_NIL,
00522                        const sc_bind_proxy& p025 = SC_BIND_PROXY_NIL,
00523                        const sc_bind_proxy& p026 = SC_BIND_PROXY_NIL,
00524                        const sc_bind_proxy& p027 = SC_BIND_PROXY_NIL,
00525                        const sc_bind_proxy& p028 = SC_BIND_PROXY_NIL,
00526                        const sc_bind_proxy& p029 = SC_BIND_PROXY_NIL,
00527                        const sc_bind_proxy& p030 = SC_BIND_PROXY_NIL,
00528                        const sc_bind_proxy& p031 = SC_BIND_PROXY_NIL,
00529                        const sc_bind_proxy& p032 = SC_BIND_PROXY_NIL,
00530                        const sc_bind_proxy& p033 = SC_BIND_PROXY_NIL,
00531                        const sc_bind_proxy& p034 = SC_BIND_PROXY_NIL,
00532                        const sc_bind_proxy& p035 = SC_BIND_PROXY_NIL,
00533                        const sc_bind_proxy& p036 = SC_BIND_PROXY_NIL,
00534                        const sc_bind_proxy& p037 = SC_BIND_PROXY_NIL,
00535                        const sc_bind_proxy& p038 = SC_BIND_PROXY_NIL,
00536                        const sc_bind_proxy& p039 = SC_BIND_PROXY_NIL,
00537                        const sc_bind_proxy& p040 = SC_BIND_PROXY_NIL,
00538                        const sc_bind_proxy& p041 = SC_BIND_PROXY_NIL,
00539                        const sc_bind_proxy& p042 = SC_BIND_PROXY_NIL,
00540                        const sc_bind_proxy& p043 = SC_BIND_PROXY_NIL,
00541                        const sc_bind_proxy& p044 = SC_BIND_PROXY_NIL,
00542                        const sc_bind_proxy& p045 = SC_BIND_PROXY_NIL,
00543                        const sc_bind_proxy& p046 = SC_BIND_PROXY_NIL,
00544                        const sc_bind_proxy& p047 = SC_BIND_PROXY_NIL,
00545                        const sc_bind_proxy& p048 = SC_BIND_PROXY_NIL,
00546                        const sc_bind_proxy& p049 = SC_BIND_PROXY_NIL,
00547                        const sc_bind_proxy& p050 = SC_BIND_PROXY_NIL,
00548                        const sc_bind_proxy& p051 = SC_BIND_PROXY_NIL,
00549                        const sc_bind_proxy& p052 = SC_BIND_PROXY_NIL,
00550                        const sc_bind_proxy& p053 = SC_BIND_PROXY_NIL,
00551                        const sc_bind_proxy& p054 = SC_BIND_PROXY_NIL,
00552                        const sc_bind_proxy& p055 = SC_BIND_PROXY_NIL,
00553                        const sc_bind_proxy& p056 = SC_BIND_PROXY_NIL,
00554                        const sc_bind_proxy& p057 = SC_BIND_PROXY_NIL,
00555                        const sc_bind_proxy& p058 = SC_BIND_PROXY_NIL,
00556                        const sc_bind_proxy& p059 = SC_BIND_PROXY_NIL,
00557                        const sc_bind_proxy& p060 = SC_BIND_PROXY_NIL,
00558                        const sc_bind_proxy& p061 = SC_BIND_PROXY_NIL,
00559                        const sc_bind_proxy& p062 = SC_BIND_PROXY_NIL,
00560                        const sc_bind_proxy& p063 = SC_BIND_PROXY_NIL,
00561                        const sc_bind_proxy& p064 = SC_BIND_PROXY_NIL );
00562 
00563 };
00564 
00565 extern sc_module* sc_module_dynalloc(sc_module*);
00566 #define SC_NEW(x)  ::sc_core::sc_module_dynalloc(new x);
00567 
00568 
00569 
00570 
00571 
00572 
00573 #define SC_MODULE(user_module_name)                                           \
00574     struct user_module_name : ::sc_core::sc_module
00575 
00576 
00577 #define SC_CHANNEL(user_module_name)                                           \
00578     struct user_module_name : ::sc_core::sc_channel
00579 
00580 #define SC_CTOR(user_module_name)                                             \
00581     typedef user_module_name SC_CURRENT_USER_MODULE;                          \
00582     user_module_name( ::sc_core::sc_module_name )
00583 
00584 
00585 #define SC_HAS_PROCESS(user_module_name)                                      \
00586     typedef user_module_name SC_CURRENT_USER_MODULE
00587 
00588 
00589 
00590 
00591 
00592 
00593 
00594 
00595 
00596 
00601 
00602 
00603 #define declare_method_process(handle, name, host_tag, func, seg_id, inst_id)  \
00604     {                                                                          \
00605         ::sc_core::sc_process_handle handle =                                  \
00606             sc_core::sc_get_curr_simcontext()->create_method_process(          \
00607                 name,  false, SC_MAKE_FUNC_PTR( host_tag, func ),              \
00608                 this, 0, seg_id, inst_id );                                    \
00609         this->sensitive << handle;                                             \
00610         this->sensitive_pos << handle;                                         \
00611         this->sensitive_neg << handle;                                         \
00612     }
00613 
00618 
00619 
00620 #define declare_thread_process(handle, name, host_tag, func, seg_id, inst_id)  \
00621     {                                                                          \
00622         ::sc_core::sc_process_handle handle =                                  \
00623              sc_core::sc_get_curr_simcontext()->create_thread_process(         \
00624                  name,  false,                                                 \
00625                  SC_MAKE_FUNC_PTR( host_tag, func ),                           \
00626                  this, 0, seg_id, inst_id );                                   \
00627         this->sensitive << handle;                                             \
00628         this->sensitive_pos << handle;                                         \
00629         this->sensitive_neg << handle;                                         \
00630     }
00631 
00636 
00637 
00638 #define declare_cthread_process(handle, name, host_tag, func, edge,            \
00639                                 seg_id, inst_id)                               \
00640     {                                                                          \
00641         ::sc_core::sc_process_handle handle =                                  \
00642              sc_core::sc_get_curr_simcontext()->create_cthread_process(        \
00643                  name,  false,                                                 \
00644                  SC_MAKE_FUNC_PTR( host_tag, func ),                           \
00645                  this, 0, seg_id, inst_id );                                   \
00646         this->sensitive.operator() ( handle, edge );                           \
00647     }
00648 
00653 
00654 
00655 #define SC_CTHREAD(func, edge, seg_id, inst_id)                               \
00656     declare_cthread_process( func ## _handle,                                 \
00657                              #func,                                           \
00658                              SC_CURRENT_USER_MODULE,                          \
00659                              func,                                            \
00660                              edge,                                            \
00661                              seg_id,                                          \
00662                              inst_id )
00663 
00668 
00669 
00670 #define SC_METHOD(func, seg_id, inst_id)                                      \
00671     declare_method_process( func ## _handle,                                  \
00672                             #func,                                            \
00673                             SC_CURRENT_USER_MODULE,                           \
00674                             func,                                             \
00675                             seg_id,                                           \
00676                             inst_id )
00677 
00682 
00683 
00684 #define SC_THREAD(func, seg_id, inst_id)                                      \
00685     declare_thread_process( func ## _handle,                                  \
00686                             #func,                                            \
00687                             SC_CURRENT_USER_MODULE,                           \
00688                             func,                                             \
00689                             seg_id,                                           \
00690                             inst_id )
00691 
00692 
00693 
00694 
00695 
00696 
00697 
00698 
00699 
00700 typedef sc_module sc_behavior;
00701 
00702 
00703 
00708 
00709 class sc_channel
00710 : public sc_module
00711 {
00712     friend class sc_module_name;
00713     friend class sc_module_registry;
00714     friend class sc_object;
00715     friend class sc_port_registry;
00716     friend class sc_process_b;
00717     friend class sc_simcontext;
00718 
00719 public:
00720 
00721     virtual const char* kind() const
00722         { return "sc_channel"; }
00723 
00724 protected:
00725 
00726     
00727     sc_channel();
00728     sc_channel( const sc_module_name& nm ); 
00729 
00730      sc_channel( const char* nm ); 
00731      sc_channel( const std::string& nm );
00732 
00733 public:
00734 
00735     
00736     virtual ~sc_channel();
00737 
00738 private:
00739     sc_channel( const sc_channel& );
00740     const sc_channel& operator = ( const sc_channel& );
00741 
00742 protected:
00743 
00747     
00748     mutable CHNL_MTX_TYPE_ m_mutex;
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 
00852 
00853 
00854 
00855 
00856 
00857 
00858 
00859 #endif