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: ''
        MATLABFunctionName: ''
                PortGroups: []
    ComponentTemplateFiles: {'/mathworks/devel/bat/filer/batfs1904-0/Bdoc24a.2589924/build/matlab/toolbox/hdlverifier/dpigenerator/rtw/SequentialModuleML.svt'}
    TestBenchTemplateFiles: {'/mathworks/devel/bat/filer/batfs1904-0/Bdoc24a.2589924/build/matlab/toolbox/hdlverifier/dpigenerator/rtw/SequentialTestBenchML.svt'}
        TemplateDictionary: []

デフォルトでは、コンポーネントの種類は「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/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveGen/sineWaveGen_dpi.c
### Generating DPI-C Wrapper header file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveGen/sineWaveGen_dpi.h
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveGen/sineWaveGen_pkg.sv from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/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.

### ...DONE with vector capture.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/sineWaveGen_tb.sv from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/run_tb_mq.do from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/run_tb_xcelium.sh from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/run_tb_vcs.sh from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveGen/dpi_tb/run_tb_vivado.sh from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/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™ は、SystemVerilogTemplateLibrary.svt ファイルのローカル辞書内の SVTLCommonHeader テンプレート変数を定義します。ローカル辞書の構文は %<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: ''
        MATLABFunctionName: ''
                PortGroups: []
    ComponentTemplateFiles: {'/mathworks/devel/bat/filer/batfs1904-0/Bdoc24a.2589924/build/matlab/toolbox/hdlverifier/dpigenerator/rtw/ScoreboardComponentML.svt'}
    TestBenchTemplateFiles: {'/mathworks/devel/bat/filer/batfs1904-0/Bdoc24a.2589924/build/matlab/toolbox/hdlverifier/dpigenerator/rtw/ScoreboardTestBenchML.svt'}
        TemplateDictionary: []

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

edit(svcfg.ComponentTemplateFiles{:});

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

override the value of a template variable

InputTransTypeName の値を sineWaveTrans に上書きするには、 次の コマンドを入力します。

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

このスコアボード テンプレートには、PREDICTOR_INPUTSMONITOR_INPUTSCONFIG_OBJECT_INPUTS の 3 つのポート グループがあります。コードを生成する前に、svdpiConfiguration を使用して、どのポートがどのポート グループに属するかを指定します。この例では、sineWaveCheck.m ファイルには 5 つの入力 (in1FromMonin2FromMoninFromPredamp1amp2) があります。in1FromMon および 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/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/sineWaveCheck_dpi.c
### Generating DPI-C Wrapper header file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/sineWaveCheck_dpi.h
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/sineWaveCheck_pkg.sv from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/sineWaveTrans.sv from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/scoreboard_output_trans.sv from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/scoreboard_cfgobj.sv from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/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.

### ...DONE with vector capture.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/sineWaveCheck_tb.sv from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/sineWaveCheck_tb_pkg.sv from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/run_tb_mq.do from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/run_tb_xcelium.sh from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/run_tb_vcs.sh from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/hdlverifier-ex18925523/codegen/dll/sineWaveCheck/dpi_tb/run_tb_vivado.sh from template text.
### Generating source code file /tmp/Bdoc24a_2589924_894856/tpcc27045f/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 は、生成された sineWaveCheck.svsineWaveTrans として InputTransTypeName の値を割り当てるため、関連するすべての項目は 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 オブジェクトを使用してテンプレート変数のデフォルト値を上書きする

  • テンプレート内のポートの集合をグループとして表す

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

参考

関連するトピック