16.2.7.2 SystemCとの協調シミュレーション

DPIを使うことで、SystemCを呼び出すこともできます。 DLL化を行いmain()をインポートすればよいですね。この場合、二つのシミュレータ、VerilogHDLとSystemC、二つの独立した時刻を持って動きます。SystemCが時刻を消費しなければ、このモデルでも問題ありませんが、SystemCも時刻を消費するモデルの場合は、それぞれの時刻に気を配らなくてはいけないのが面倒になります。そのために、HDLと接続する場合は、大抵のシミュレーションベンダは、OSCIの提供するシミュレータではなく、それぞれのベンダのシミュレーションカーネルと統合したシングルシミュレーションカーネルを独自に持っています。
VeritakSVも、独自のシングルシミュレーションカーネルを持っています。

これを使えば、SystemCとSystemVerilogの時刻は、共通に進みますから、後は、インターフェースの部分をDPI上で、ファンクション・タスクコールすることで、接続を行います。書きようによっては、ピン間接続を模擬する書き方もできますが、トランザクションとしてまとめてコールした方がイベント数は少なく済み、シミュレーション負荷は低減できます。


< VeritakSVでのSystemC統合カーネル>

下のソースで、コメント部が、協調シミュレーションで追加した全てです。ライブラリは、パッケージに含まれるSystemC.lib veritak_sv.libを追加します。このライブラリは、OSCIとは異なるVeritakSV専用のライブラリです。これらを下のように加えることでHDLとSystemCは、シングルカーネルで動きます。



SV側のソースです。

  1. `timescale 1ns/1ps
  2. module export_test1;
  3.  
  4.        
  5.         import "DPI-C"  context task fir_main();//DLL化したSystemCのエントリルーチン
  6.         export "DPI-C"  task    delay_task_by_parameter;//mainがHDLシミュレーション中生き続けるようにする
  7.  
  8.  
  9. //指定時間待つ
  10.         task delay_task_by_parameter( inputlongint d);
  11.                 #(d);
  12.         endtask;
  13.  
  14.         initialbegin
  15.  
  16.                 fork
  17.                         fir_main;//DLL化したSystemCを呼ぶ
  18.                         repeat (30)   #10 $display( "........................................................SV時刻は、%d",$time);
  19.                 join
  20.  
  21.         end
  22.  
  23.  
  24. endmodule


結果です。SystemC側とSV側では、共通の時刻で動作しています。

C:\Users\tak.sugawara\Documents\Visual Studio 2005\Projects\dpi_sample\fir.v(2)::export_test1
Verilogのシミュレーションの準備が完了しました。スタートは,Goボタンを押してください。
***** Veritak SV Engine Version 0.27 Build no.27.2009 *****

Veritak-SystemC Simulation Kernel Initialized. Nov.27.2009. 

             SystemC 2.2.0 --- Nov 27 2009 01:32:46
        Copyright (c) 1996-2006 by all Contributors
                    ALL RIGHTS RESERVED
Stimuli : 0 at time 9000
........................................................SV時刻は、                  10
Display : 0  at time 10000
Stimuli : 1 at time 19000
........................................................SV時刻は、                  20
Display : -6  at time 20000
Stimuli : 2 at time 29000
........................................................SV時刻は、                  30
Display : -16  at time 30000
Stimuli : 3 at time 39000
........................................................SV時刻は、                  40
Display : -13  at time 40000
Stimuli : 4 at time 49000
........................................................SV時刻は、                  50
Display : 6  at time 50000
Stimuli : 5 at time 59000
........................................................SV時刻は、                  60
Display : 7  at time 60000
Stimuli : 6 at time 69000
........................................................SV時刻は、                  70
Display : -33  at time 70000
Stimuli : 7 at time 79000
........................................................SV時刻は、                  80
Display : -50  at time 80000
Stimuli : 8 at time 89000
........................................................SV時刻は、                  90
Display : 87  at time 90000
Stimuli : 9 at time 99000
........................................................SV時刻は、                 100
Display : 446  at time 100000
Stimuli : 10 at time 109000
........................................................SV時刻は、                 110
Display : 959  at time 110000
Stimuli : 11 at time 119000
........................................................SV時刻は、                 120
Display : 1495  at time 120000
Stimuli : 12 at time 129000
........................................................SV時刻は、                 130
Display : 1990  at time 130000
Stimuli : 13 at time 139000
........................................................SV時刻は、                 140
Display : 2467  at time 140000
Stimuli : 14 at time 149000
........................................................SV時刻は、                 150
Display : 2960  at time 150000
Stimuli : 15 at time 159000
........................................................SV時刻は、                 160
Display : 3466  at time 160000
Stimuli : 16 at time 169000
........................................................SV時刻は、                 170
Display : 3968  at time 170000
Stimuli : 17 at time 179000
........................................................SV時刻は、                 180
Display : 4470  at time 180000
Stimuli : 18 at time 189000
........................................................SV時刻は、                 190
Display : 4972  at time 190000
Stimuli : 19 at time 199000
........................................................SV時刻は、                 200
Display : 5474  at time 200000
Stimuli : 20 at time 209000
........................................................SV時刻は、                 210
Display : 5976  at time 210000
Stimuli : 21 at time 219000
........................................................SV時刻は、                 220
Display : 6478  at time 220000
Stimuli : 22 at time 229000
........................................................SV時刻は、                 230
Display : 6980  at time 230000
Stimuli : 23 at time 239000
........................................................SV時刻は、                 240
Display : 7482  at time 240000
Simulation of 24 items finished at time 240000
........................................................SV時刻は、                 250
........................................................SV時刻は、                 260
........................................................SV時刻は、                 270
........................................................SV時刻は、                 280
........................................................SV時刻は、                 290
........................................................SV時刻は、                 300

**** Test Done. Total 109.00[msec] ****

<SystemVerilog-SystemC間の通信>

SVソースです。function ならば、CThread,Thread,Methodによらず、どこからでも呼び出せます。しかしながら、functionでは、ブロッキングプロセスを書けないので、fork -join_noneを使っているのがポイントです。

  1. `timescale 1ns/1ps
  2. module export_test1;
  3.         parameter  int POWER_UP=4;
  4.        
  5.         import "DPI-C"  context task fir_main();//DLL化したSystemCのエントリルーチン
  6.         import "DPI-C"  context  function void notify_power_up( input chandle);
  7.         export "DPI-C"  task    delay_task_by_parameter;//mainがHDLシミュレーション中生き続けるようにする
  8.         export "DPI-C"  function show_time;
  9.         export "DPI-C"  task delay_task;
  10.         export "DPI-C"  function wait_power_up_nb;
  11.        
  12. `define TAB1 "\t\t\t\t\t\t\t\t"
  13.         logic clk=0;
  14.         chandle fir;
  15.         always #10 clk=~clk;
  16.  
  17.         task delay_task;
  18.                         $display(" delay taskSV time=%d",$time);
  19.  
  20.         endtask
  21.  
  22.         task wait_power_up;
  23.                 $write(`TAB1); 
  24.                 $display("Power Up Command 受領 %d",$time);
  25.                 repeat(POWER_UP)  begin
  26.                         @(posedge clk);
  27.                 end
  28.                 $write(`TAB1);
  29.                 $display("Power Up 終了 %d",$time);
  30.                 notify_power_up(fir);//import functionを呼ぶ
  31.         endtask
  32.  
  33.         function void wait_power_up_nb( input chandle ch1);//function内では、ブロッキングできないが、(タスク起動やイベントやディレイは書けない)
  34.                 fir=ch1;//FIRのCハンドルを保存
  35.                 fork
  36.                         wait_power_up;//fork -jone_none内では、タスク起動ができる。
  37.                 join_none
  38.         endfunction
  39.  
  40.         function void show_time();
  41.                 $display(" SV time=%d",$time);
  42.         endfunction
  43.  
  44. //指定時間待つ
  45.         task delay_task_by_parameter( input longint d);
  46.                 #(d);
  47.         endtask;
  48.  
  49.         initialbegin
  50.  
  51.                 fork
  52.                         fir_main;//DLL化したSystemCを呼ぶ
  53.                         repeat (30)   #10 $display( "........................................................SV時刻は、%d",$time);
  54.                 join_any //fir_mainは、無限ループ
  55.                 $display("join_anyを脱出しました。");
  56.                 $finish;
  57.                
  58.         end
  59.  
  60.  
  61. endmodule

上のソースにさらに下を追加しました。

  1. #include <systemc.h>
  2. #include "fir.h"
  3. #include "dpi_veritak_header.h"
  4.  
  5. #define TAB1 "\t\t\t\t\t\t\t\t"
  6.  
  7. DPI_LINK_DECL DPI_DLLESPEC void notify_power_up( constvoid* ptr)
  8. {
  9.         fir* FIR=reinterpret_cast<fir*>( const_cast<void*>(ptr));
  10.         assert(FIR);
  11.         FIR->fir_event.notify();
  12.         cout<< TAB1<< "Notify Power Up: notify しました。"<<endl;
  13. }
  14.  
  15. void fir::power_up_seq (){
  16.  
  17.                 cout<< TAB1<<"reset="<< reset<<endl;
  18.                 wait_power_up_nb(this);
  19.                 wait(fir_event);
  20.                 cout<< TAB1<< " Power up Seq 終了を認識しました。"<<endl;
  21.  
  22. }

結果です。

C:\Users\tak.sugawara\Documents\Visual Studio 2005\Projects\dpi_sample\fir.v(2)::export_test1
Verilogのシミュレーションの準備が完了しました。スタートは,Goボタンを押してください。
***** Veritak SV Engine Version 0.27 Build no.27.2009 *****

Veritak-SystemC Simulation Kernel Initialized. Nov.27.2009. 

             SystemC 2.2.0 --- Nov 29 2009 06:40:39
        Copyright (c) 1996-2006 by all Contributors
                    ALL RIGHTS RESERVED
                                                                reset=0
                                                                Power Up Command 受領                    0
Stimuli : 0 at time 9000
........................................................SV時刻は、                  10
Display : 0  at time 10000
Stimuli : 1 at time 19000
........................................................SV時刻は、                  20
Display : -6  at time 20000
Stimuli : 2 at time 29000
........................................................SV時刻は、                  30
Display : -16  at time 30000
Stimuli : 3 at time 39000
........................................................SV時刻は、                  40
Display : -13  at time 40000
Stimuli : 4 at time 49000
........................................................SV時刻は、                  50
Display : 6  at time 50000
Stimuli : 5 at time 59000
........................................................SV時刻は、                  60
Display : 7  at time 60000
Stimuli : 6 at time 69000
                                                                Power Up 終了                   70
                                                                Notify Power Up: notify しました。
........................................................SV時刻は、                  70
                                                                 Power up Seq 終了を認識しました。
Display : -33  at time 70000
Stimuli : 7 at time 79000
........................................................SV時刻は、                  80
Display : -50  at time 80000
Stimuli : 8 at time 89000
........................................................SV時刻は、                  90
Display : 87  at time 90000
Stimuli : 9 at time 99000
........................................................SV時刻は、                 100
Display : 446  at time 100000
Stimuli : 10 at time 109000
........................................................SV時刻は、                 110
Display : 959  at time 110000
Stimuli : 11 at time 119000
........................................................SV時刻は、                 120
Display : 1495  at time 120000
Stimuli : 12 at time 129000
........................................................SV時刻は、                 130
Display : 1990  at time 130000
Stimuli : 13 at time 139000
........................................................SV時刻は、                 140
Display : 2467  at time 140000
Stimuli : 14 at time 149000
........................................................SV時刻は、                 150
Display : 2960  at time 150000
Stimuli : 15 at time 159000
........................................................SV時刻は、                 160
Display : 3466  at time 160000
Stimuli : 16 at time 169000
........................................................SV時刻は、                 170
Display : 3968  at time 170000
Stimuli : 17 at time 179000
........................................................SV時刻は、                 180
Display : 4470  at time 180000
Stimuli : 18 at time 189000
........................................................SV時刻は、                 190
Display : 4972  at time 190000
Stimuli : 19 at time 199000
........................................................SV時刻は、                 200
Display : 5474  at time 200000
Stimuli : 20 at time 209000
........................................................SV時刻は、                 210
Display : 5976  at time 210000
Stimuli : 21 at time 219000
........................................................SV時刻は、                 220
Display : 6478  at time 220000
Stimuli : 22 at time 229000
........................................................SV時刻は、                 230
Display : 6980  at time 230000
Stimuli : 23 at time 239000
........................................................SV時刻は、                 240
Display : 7482  at time 240000
Simulation of 24 items finished at time 240000
........................................................SV時刻は、                 250
........................................................SV時刻は、                 260
........................................................SV時刻は、                 270
........................................................SV時刻は、                 280
........................................................SV時刻は、                 290
........................................................SV時刻は、                 300
join_anyを脱出しました。

**** Test Done. Total 30.00[msec] ****