SystemC 2.3 : reset/kill event

SystemC 2.3では、reset/kill 発生時のイベントを利用して
プロセスを動作させることも出来ます。

  • サンプルコード
 # include <stdio.h>
 # include <systemc.h>

SC_MODULE( hoge ){

  sc_event          ev;
  sc_process_handle t;
  int               q;

  SC_CTOR( hoge )
  {
    SC_THREAD( calling );
    SC_THREAD( target );
      t = sc_get_current_process_handle();
    SC_METHOD( reset_handler );
      dont_initialize();
      sensitive << t.reset_event() ;
    SC_METHOD( kill_handler );
      dont_initialize();
      sensitive << t.terminated_event() ;
  }

  void calling(){
    wait(10, SC_NS);
    ev.notify();

    wait(10, SC_NS);
    t.reset();

    wait(10, SC_NS);
    ev.notify();

    wait(10, SC_NS);
    t.kill();
    assert( t.terminated() );

    wait(10, SC_NS);
    ev.notify();
  }

  void target(){
    q = 0;
    while (1) {
      wait(ev);
      ++q;
      cout << sc_time_stamp();
      cout << " q = " << q << endl;
    }
  }

  void reset_handler(){
    cout << sc_time_stamp();
    cout << " : target was reset" << endl;
  }

  void kill_handler(){
    cout << sc_time_stamp();
    cout << " : target was killed" << endl;
  }
};

int sc_main(int argc, char *argv[]) {

  hoge mhoge("hoge");
  sc_start(500, sc_core::SC_NS);

  return 0;
}
  • 実行結果
$> ./main 

             SystemC 2.3.0-ASI --- Feb 16 2013 23:56:43
        Copyright (c) 1996-2012 by all Contributors,
        ALL RIGHTS RESERVED

10 ns q = 1
20 ns : target was reset
30 ns q = 1
40 ns : target was killed