bambooflow Note

動的プロセス

最終更新:

bambooflow

- view
メンバー限定 登録/ログイン

SystemC 動的プロセスについて

メソッドを動的にSC_METHODやSC_THREAD指定することが可能。
普通のモデリング時には必要ないが、応用的なことに使用することがある。
たとえば、デバッグ機能を追加したい、とか、検証機能を強化したい、とか。
以下にその方法をメモる。 


動的プロセスを扱うための準備

以下のようにsytemc.hをインクルードする前にSC_INCLUDE_DYNAMIC_PROCESSESを定義する必要がある。

#define SC_INCLUDE_DYNAMIC_PROCESSES
#include <systemc.h>
 

もしくは、コンパイルオプションの "-D"を使用する方法もある。
g++ -I/usr/local/systemc-2.2 -DSC_INCLUDE_DYNAMIC_PROCESSES -c model.cpp


使用する関数

プロセスを指定するときに使用する。
プロセスとする関数を指定するときに使用する。
sc_bindはboost::bindのdefine定義。
プロセスのオプション設定をする。たとえば、センシティブ指定とか。

  • 戻り値なしで登録する場合
sc_process_handle hname = sc_spawn(
  /*void*/sc_bind( &funcName, ARGS... ),
  char* processName,
  sc_spawn_options spawnOptopns
);
 
sc_process_handle hname = sc_spawn(
  /*void*/sc_bind( &funcName, object, ARGS... ),
  char* processName,
  sc_spawn_options spawnOptopns
);
 

  • 戻り値ありで登録する場合
sc_process_handle hname = sc_spawn(
  &returnVar,
  sc_bind( &funcName, ARGS... ),
  char* processName,
  sc_spawn_options spawnOptopns
);
 
sc_process_handle hname = sc_spawn(
  &returnVar,
  sc_bind( &funcName, object, ARGS... ),
  char* processName,
  sc_spawn_options spawnOptopns
);
 

動的methodを指定する記述例


#define SC_INCLUDE_DYNAMIC_PROCESSES
#include <systemc.h>

SC_MODULE( DUT )
{
    sc_in<sc_uint<8> >  din1;
    sc_in<sc_uint<8> >  din2;
    sc_out<sc_uint<9> > dout;
 
    SC_CTOR( DUT ) {
 
        SC_THREAD( init_thread );
    }
 
    void init_thread() {
 
        sc_spawn_options mth;
        mth.spawn_method();
        mth.dont_initialize();
        mth.set_sensitivity( din1 );
        mth.set_sensitivity( din2 );
        sc_spawn( sc_bind(&DUT::spawn_method0,this), "method0", &mth );
    }
 
    void spawn_method0() { 
        dout.write( din1.read() + din2.read() );
    }
};
 

注意として、sc_spawnの指定は、プロセス内に記述する。
コンストラクタに記述すると実行時エラーとなる。

動的threadを指定する記述例


#define SC_INCLUDE_DYNAMIC_PROCESSES
#include <systemc.h>

SC_MODULE( DUT )
{
    sc_in<bool>   clk;
 
 
    SC_CTOR( DUT ) {
        SC_THREAD( run );
    }
 
    void run() {
        sc_spawn_options opt;
        opt.set_sensitivity( &clk.pos() );
        sc_spawn( sc_bind(&DUT::spawn_thread,this, false ), "thread0", &opt );
    }
 
    void spawn_thread( bool flag ) {
        while (true) {
            ・・・
            wait();
        }
    }
 
};
 

動的プロセスでは引数を渡したり戻り値を受け取ったりするができる。
例では、bool型の引数を渡している。
記事メニュー
目安箱バナー