Main Content

このページは機械翻訳を使用して翻訳されました。最新版の英語を参照するには、ここをクリックします。

テンプレートを使用して SystemVerilog DPI および UVM コンポーネントを作成する

この例では、組み込みテンプレートを使用してMATLAB®関数から SystemVerilog ダイレクト プログラミング インターフェイス (DPI) およびユニバーサル検証手法 (UVM) コンポーネントを生成する方法を示します。この例では、生成された SystemVerilog とそれがテンプレートにどのように関連しているかも確認します。この例では、カスタム テンプレートの作成に使用できる基本的なテンプレート機能を説明します。

HDL Verifier™ は、ほとんどのユースケースをカバーする組み込みテンプレートを提供します。別のテンプレートが必要な場合は、この例に示す概念を使用してカスタム テンプレートを作成します。

はじめに

この例では、正弦波MATLAB関数をテスト対象デザイン (DUT) として使用し、組み込みのシーケンシャル DPI テンプレートを使用して SystemVerilog DPI コンポーネントを生成する手順に従います。SystemVerilog DPI コンポーネントを生成した後、組み込みの UVM スコアボード テンプレートを使用して UVM スコアボードを生成し、DUT の出力を確認します。この例から、次の方法を学びます。

  • 辞書を使用してテンプレート変数を定義します。

  • テンプレート変数に値を割り当てます。

  • svdpiConfiguration オブジェクトのテンプレート変数をオーバーライドします。

  • テンプレート内のグループとしてポートのコレクションを表します。

SystemVerilog DPI コンポーネントの生成

シーケンシャル モジュール テンプレートは、正弦波MATLAB関数から Systemverilog DPI コンポーネントを生成します。

Default ports in the sequential module template for a DPI component. They are control singals (clock and reset), inputs, and outputs.

テンプレートからコンポーネントを生成するには、まず svdpiConfiguration オブジェクトを作成します。

svcfg=svdpiConfiguration
svcfg = 
  svdpiConfiguration with properties:

             ComponentKind: 'sequential-module'
        CoderConfiguration: [1x1 coder.EmbeddedCodeConfig]
         ComponentTypeName: ''
         TestBenchTypeName: ''
        TemplateDictionary: []
                PortGroups: []
    ComponentTemplateFiles: {'/mathworks/devel/bat/Bdoc23b/build/matlab/toolbox/hdlverifier/dpigenerator/rtw/SequentialModuleML.svt'}
    TestBenchTemplateFiles: {'/mathworks/devel/bat/Bdoc23b/build/matlab/toolbox/hdlverifier/dpigenerator/rtw/SequentialTestBenchML.svt'}

デフォルトでは、コンポーネントの種類は「sequential-module」に設定されています

sequential-module」は、 SequentialModuleML.svtテンプレート ファイルを使用してコンポーネントを生成します。テンプレートはこの場所にあります。

templateLocation = fileparts(svcfg.ComponentTemplateFiles{1});

次に、 dpigen関数を使用してコンポーネントを生成します。

dpigen sineWaveGen -testbench sineWaveGen_tb -args {0,0} -config svcfg
### Generating DPI-C Wrapper /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/sineWaveGen_dpi.c
### Generating DPI-C Wrapper header file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/sineWaveGen_dpi.h
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/sineWaveGen_pkg.sv from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/sineWaveGen.sv from template text.
### Generating makefiles for: sineWaveGen_dpi
### Running simulation to capture input and expected outputs for a standalone test bench.
### This may take some time...
Code generation successful.

Figure contains 2 axes objects and another object of type subplottext. Axes object 1 with title y1 contains an object of type line. Axes object 2 with title y2 contains an object of type line.

### ...DONE with vector capture.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/sineWaveGen_tb.sv from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/run_tb_mq.do from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/run_tb_xcelium.sh from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/run_tb_vcs.sh from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/run_tb_vivado.sh from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/run_tb_vivado.bat from template text.
### Compiling the DPI Component
Code generation successful.

テンプレート変数の定義と割り当て

DPI コンポーネントを生成した後、生成された SystemVerilog ファイルを確認し、それらをテンプレートに関連付けます。これら 2 つのテンプレート ファイルを開きます。

edit(svcfg.ComponentTemplateFiles{1});
edit(fullfile(fileparts(svcfg.ComponentTemplateFiles{1}),'SystemVerilogTemplateLibrary.svt'));

生成した SystemVerilog DPI コンポーネント ファイルを開きます。

edit(fullfile('codegen','dll','sineWaveGen','sineWaveGen.sv'));

テンプレート変数に値を割り当てる方法を理解するには、生成されたコンポーネント ファイルをテンプレート ファイルと比較します。sineWaveGen.svファイルは、SequentialModuleML.svtテンプレート ファイルの次のセクションから作成されます。これには、< SVTLCommonHeader> という名前のテンプレート変数が含まれています。

SVTL common header variable.

SequentialModuleML.svtテンプレート ファイルには、 SystemVerilogTemplateLibrary.svtの内容も含まれています。

Include SystemVerilogTemplateLibrary.svt

HDL Verifier™ は、 SVTLCommonHeaderファイルのローカル ディクショナリにSystemVerilogTemplateLibrary.svt テンプレート変数を定義します。ローカル辞書の構文は%<BEGIN_LOCAL_DICTIONARY> ... %<END_LOCAL_DICTIONARY>です。

辞書エントリの形式は、template_variable_name = template_variable_value です。この例では、 SVTLCommonHeaderの定義に複数の行が必要なので、 %<BEGIN_VARIABLE_DEFINITION> ... %<END_VARIABLE_DEFINITION>コード ブロックを使用します。複数行の定義にはこの形式を使用します。

Define template variable in the local dictionary.

ディクショナリでテンプレート変数を定義した後、テンプレート ファイルでその変数を%<variable_name>の形式で使用します。 。この例では、変数は%<SVTLCommonHeader>です。コード生成中に、テンプレート変数はその定義された内容に置き換えられます。この DPI コンポーネントでは、 sineWaveGen.sv SVTLCommonHeaderテンプレート変数の内容が含まれています。

SVTLCommonHeader is replaced by its defined content.

UVM スコアボードの生成

UVM スコアボードは UVM コンポーネントです。通常、スコアボードはモニターを介して DUT からの入力、およびゴールデン参照モデル (予測子) からの入力を受け入れます。UVM テストベンチの詳細については、 「UVM コンポーネント生成の概要」を参照してください。

例のこの部分では、正弦波発生器 (DUT) の出力とゴールデン リファレンスの出力を比較する UVM スコアボードを生成します。出力を監視するために、スコアボードは正規化された正弦波関数をゴールデンリファレンスとして使用し、DUT 正弦波の振幅をスコアボード構成オブジェクトのパラメーターとして使用します。

MATLABコマンド ラインで、コンポーネントの種類を'uvm-scoreboard'に設定します。

clear svcfg;
svcfg=svdpiConfiguration;
svcfg.ComponentKind = 'uvm-scoreboard'
svcfg = 
  svdpiConfiguration with properties:

             ComponentKind: 'uvm-scoreboard'
        CoderConfiguration: [1x1 coder.EmbeddedCodeConfig]
         ComponentTypeName: ''
         TestBenchTypeName: ''
        TemplateDictionary: []
                PortGroups: []
    ComponentTemplateFiles: {'/mathworks/devel/bat/Bdoc23b/build/matlab/toolbox/hdlverifier/dpigenerator/rtw/ScoreboardComponentML.svt'}
    TestBenchTemplateFiles: {'/mathworks/devel/bat/Bdoc23b/build/matlab/toolbox/hdlverifier/dpigenerator/rtw/ScoreboardTestBenchML.svt'}

スコアボードのテンプレート ファイルを開きます。

edit(svcfg.ComponentTemplateFiles{:});

辞書はテンプレート変数を定義します。テンプレート変数InputTransTypeNameのデフォルト値はscoreboard_input_trans です。 svdpiConfigurationオブジェクトを使用して、このテンプレート変数の値をオーバーライドできます。

override the value of a template variable

InputTransTypeNameの値をsineWaveTransにオーバーライドするには、次の コマンドを入力します。

svcfg.TemplateDictionary = {'InputTransTypeName','sineWaveTrans'};

このスコアボード テンプレートには、 PREDICTOR_INPUTSMONITOR_INPUTS、およびCONFIG_OBJECT_INPUTSの 3 つのポート グループがあります。コードを生成する前に、 svdpiConfigurationを使用して、どのポートがどのポート グループに属するかを指定します。この例では、 sineWaveCheck.mファイルには 5 つの入力があります: in1FromMonin2FromMoninFromPredamp1、およびamp2in1FromMonおよびin2FromMon 入力はMONITOR_INPUTSグループに属します。inFromPred 入力はPREDICTOR_INPUTSグループに属します。amp1およびamp2 入力は、CONFIG_OBJECT_INPUTSグループに属します。各入力をそれぞれのポート グループに割り当てます。

addPortGroup(svcfg,'MONITOR_INPUTS',{'in1FromMon','in2FromMon'});
addPortGroup(svcfg,'PREDICTOR_INPUTS',{'inFromPred'});
addPortGroup(svcfg,'CONFIG_OBJECT_INPUTS',{'amp1','amp2'});

UVM スコアボード コンポーネントを生成します。

dpigen sineWaveCheck -testbench sineWaveCheck_tb -args {zeros(1,100),zeros(1,100),zeros(1,100),0,0} -config svcfg
### Generating DPI-C Wrapper /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/sineWaveCheck_dpi.c
### Generating DPI-C Wrapper header file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/sineWaveCheck_dpi.h
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/sineWaveCheck_pkg.sv from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/sineWaveTrans.sv from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/scoreboard_output_trans.sv from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/scoreboard_cfgobj.sv from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/sineWaveCheck.sv from template text.
### Generating makefiles for: sineWaveCheck_dpi
### Running simulation to capture input and expected outputs for a standalone test bench.
### This may take some time...
Code generation successful.

Figure contains 6 axes objects and another object of type subplottext. Axes object 1 with title DUT sine wave 1 contains an object of type line. Axes object 2 with title expected sine wave 1 contains an object of type line. Axes object 3 with title mismatch1 contains an object of type line. Axes object 4 with title DUT sine wave 2 contains an object of type line. Axes object 5 with title expected sine wave 2 contains an object of type line. Axes object 6 with title mismatch2 contains an object of type line.

### ...DONE with vector capture.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/sineWaveCheck_tb.sv from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/sineWaveCheck_tb_pkg.sv from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/run_tb_mq.do from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/run_tb_xcelium.sh from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/run_tb_vcs.sh from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/run_tb_vivado.sh from template text.
### Generating source code file /tmp/Bdoc23b_2492649_1044276/tpd2444e94/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/run_tb_vivado.bat from template text.
### Compiling the DPI Component
Code generation successful.

生成されたスコアボード コンポーネント ファイルを開きます。

edit(fullfile('codegen','dll','sineWaveCheck','sineWaveCheck.sv'))

HDL Verifier は、生成されたInputTransTypeName内でsineWaveTrans として割り当てるため、すべての関連項目はを使用します。 sineWaveTrans

HDL Verifier は、%<BEGIN_FOREACH_PORT PortGroup> ... %<END_FOREACH_PORT>コード ブロックでポート グループを定義します。このコード ブロックは、PortGroup 内のすべてのポートで反復してコードを出力します。この例では、コード ブロックはモニター ポート グループ内のすべてのポートを反復し、そのポート名を使用して SystemVerilog コードを作成します。

ModelSim® がシステム パス上にあることを確認してから、このディレクティブを入力してテスト ベンチ ディレクトリに移動します。

cd(fullfile('codegen','dll','sineWaveCheck','dpi_tb'))

テストベンチを実行し、ModelSim で生成されたスコアボード コンポーネントを確認します。

!vsim < run_tb_mq.do

HDL シミュレーションでテストが成功したことに注意してください。

# UVM_INFO @ 0: reporter [RNTST] Running test sineWaveCheck_tb_test...

# UVM_INFO ./sineWaveCheck_tb.sv(98) @ 40: uvm_test_top [WRITING_INPUTS] writing scoreboard inputs

# UVM_INFO ./sineWaveCheck_tb.sv(104) @ 41: uvm_test_top [GETTING_RESULT] getting scoreboard result

# **************TEST COMPLETED (PASSED)**************

# ** Note: $finish : ./sineWaveCheck_tb.sv(223)

# Time: 42 ns Iteration: 0 Instance: /sineWaveCheck_tb

# End time: 16:48:55 on Jan 18,2023, Elapsed time: 0:00:02

# Errors: 0, Warnings: 0

概要

この例では、組み込みテンプレートを使用してMATLAB関数から SystemVerilog DPI および UVM コンポーネントを生成する方法を示します。この例から、次の方法を学びます。

  • 辞書を使用してテンプレート変数を定義する

  • svdpiConfiguration オブジェクトを使用してテンプレート変数のデフォルト値をオーバーライドする

  • テンプレート内のグループとしてポートのコレクションを表します

これらの方法を使用して、独自のテンプレートを作成したり、ニーズに合わせて組み込みのテンプレートをコピーして変更したりできます。テンプレート言語構文の詳細については、「 テンプレート エンジンの言語構文 」を参照してください。

参考

関連するトピック