2017-03-24 1 views
0

私のプロジェクトには、SystemCシミュレーションを実行する関数がいくつかあります(それぞれに独自の宣言preludeとsc_start()があります)。 次のように彼らが構築されています複数のSystemCシミュレーションを持つプロジェクトで例外が発生する

// first Simulation: 
sc_signal<double> s1_sim1; 
.. 
ControlFoo<double> *cf = new ControlFoo<double>(); 
cf->Foo_port(s1_sim1); 
.. 
sc_start(); // works fine 
delete(cf); 
.. 
// second Simulation: 
sc_signal<double> s1_sim2; // this leads to an exception 

必要に応じて、最初のシミュレーションが(sc_stopまで実行されます)。 しかし、最初のシミュレーションが完了した後に新しいsc_signalsを宣言しようとすると、例外が発生します。

問題を解決するにはどうすればよいですか?

敬具

答えて

2

ユーザーガイド:「あなたは、あなたがインスタンス化した後にのみ、シミュレーションを開始し、適切にすべてのモジュールと信号を接続することができます」

どのように動的にハードウェアを作成しますか?

オプションは別々のプロジェクトにモデルを分割するか、一つのプロジェクト内のすべてのモデルを宣言し、オンとオフそれらを切り替える方法を持っている、などあなたのフォローへの回答では、信号

を「有効」とされていますあなたはこのようなことを試すことができます。 「イネーブル」出力を持つコントローラモジュールを作成し、これを使用してオンとオフを切り替える一部のモデルまたはサブシステムを表すためにここで使用している3つの制御モジュールを制御します。

#include <systemc.h> 
#include <iostream> 

using namespace sc_core; 
using namespace std; 

/* 
Controller module with output enable signals to enable and 
disable other modules representing the models we wish to switch on/off 
*/ 
SC_MODULE(Controller){ 

    SC_CTOR(Controller) 
     : clk_i("clk_i"), 
     en_a("en_a"), 
     en_b("en_b"), 
     en_c("en_c"), 
     counter(0) 
    { 
     SC_METHOD(proc); 
     sensitive << clk_i.pos(); //run process on positive clock edge 
    } 

    void proc(){ 
     if(counter < 10){ //enable model A and disable others 
      en_a.write(true); 
      en_b.write(false); 
      en_c.write(false); 
     } 
     else if(counter < 20){ //enable B and disable others 
      en_a.write(false); 
      en_b.write(true); 
      en_c.write(false); 
     } 
     else{ //enable C and disable others 
      en_a.write(false); 
      en_b.write(false); 
      en_c.write(true); 
     } 
     counter = (counter + 1) % 30; 
    } 

    sc_in<bool> clk_i; // clock input 
    sc_out<bool> en_a; // enable model A when high 
    sc_out<bool> en_b; // enable model B when high 
    sc_out<bool> en_c; // enable model C when high 
    int counter; //simple counter to simulate some condition 
}; 

/* 
Module with an enable signal to represent the sub-systems we 
wish to switch on and off 
*/ 
SC_MODULE(Controlled){ 
    SC_CTOR(Controlled) : en_i("en_i"), clk_i("clk_i"){ 
     SC_METHOD(proc); 
     sensitive << clk_i.pos(); //run process on positive clock edge 
    } 

    void proc(){ 
     //if we are enabled then run "real process" otherwise do nothing 
     if(en_i.read() == true) enabledProc(); 

    } 

    // the "real process" that we wish to switch on and off 
    void enabledProc(){ 
     cout << "model " << name() << " is enabled\n"; 
    } 

    sc_in<bool> en_i; 
    sc_in<bool> clk_i; 
}; 


int sc_main(int, char**){ 

    // created controller and 3 controlled modules 
    Controller controller("controller"); 
    Controlled modelA("A"), modelB("B"), modelC("C"); 

    // create a clock and connect it to all 4 modules 
    sc_clock clk("clk", 1.0, SC_SEC); 
    controller.clk_i(clk); 
    modelA.clk_i(clk); 
    modelB.clk_i(clk); 
    modelC.clk_i(clk); 

    // create an enable signal for each module and connect to controller 
    sc_signal<bool> en_a("en_a"); 
    sc_signal<bool> en_b("en_b"); 
    sc_signal<bool> en_c("en_c"); 
    controller.en_a(en_a); 
    controller.en_b(en_b); 
    controller.en_c(en_c); 
    // connect enable lines to controlled modules 
    modelA.en_i(en_a); 
    modelB.en_i(en_b); 
    modelC.en_i(en_c); 

    sc_start(30, SC_SEC); // run for 30 seconds 

    return 0; 
} 

とコントローラが順番に各モジュールを有効にし、無効として、あなたは出力

model A is enabled 
model A is enabled 
model A is enabled 
model A is enabled 
model A is enabled 
model A is enabled 
model A is enabled 
model A is enabled 
model A is enabled 
model A is enabled 
model B is enabled 
model B is enabled 
model B is enabled 
model B is enabled 
model B is enabled 
model B is enabled 
model B is enabled 
model B is enabled 
model B is enabled 
model B is enabled 
model C is enabled 
model C is enabled 
model C is enabled 
model C is enabled 
model C is enabled 
model C is enabled 
model C is enabled 
model C is enabled 
model C is enabled 
model C is enabled 

を取得する必要があります。このシンプルな例は、私の簡単な印刷のために実際のシステムを最終的に代用できるようになるまで始めるべきである。

+0

あなたはその方法を誰に見せかけることができますか? –

関連する問題