MATLAB 関数の SystemVerilog コードの生成
この例では、MATLAB® 関数の SystemVerilog HDL コードを生成する方法を示します。SystemVerilog コードには、配列端子、パッケージ宣言、構造端子の使用など、Verilog® コードよりもさらに高度な機能があります。
アルゴリズムとテスト ベンチの確認
この例では、uint8 型の 2 行 2 列の 2 つの行列を加算する小さなアルゴリズムを使用します。
design_name = 'systemverilog_example'; testbench_name = 'systemverilog_example_tb';
MATLAB アルゴリズムとテスト ベンチを開きます。
open(design_name);
function out = systemverilog_example(in1, in2) out = in1 + in2; end
open(testbench_name);
function systemverilog_example_tb() in1 = uint8([[1 2]; [3 4]]); in2 = uint8([[5 6]; [7 8]]); i = 1; while i < 3 out = systemverilog_example(in1, in2); in1 = out; end end
HDL Coder プロジェクトの新規作成
新しいプロジェクトを作成するには、次のコマンドを入力します。
coder -hdlcoder -new systemverilog_example_prj
[MATLAB 関数] で、[MATLAB 関数の追加] をクリックし、systemverilog_example.m ファイルを選択します。[MATLAB テスト ベンチ] で、[ファイルの追加] をクリックし、systemverilog_example_tb.m を選択します。
MATLAB HDL Coder プロジェクトの作成と入力に関する詳細なチュートリアルについては、MATLAB から HDL へのワークフロー入門を参照してください。
固定小数点変換と HDL コード生成の実行
[ワークフロー アドバイザー] をクリックして MATLAB でワークフロー アドバイザーを起動します。
[HDL コード生成] をクリックし、
LanguageプロパティをSystemVerilogに設定します。[HDL コード生成] タスクを右クリックして [選択したタスクまで実行] をクリックし、最初から HDL コード生成までのすべてのステップを実行します。
ログ ウィンドウにあるリンクをクリックして、生成された HDL コードを確認します。
MATLAB コマンド ラインを使用した SystemVerilog コードの生成
MATLAB 設計の SystemVerilog コードは、MATLAB コマンド ウィンドウでコマンドを入力して生成することもできます。
最初に、coder.config オブジェクト hdlcfg を作成します。
hdlcfg = coder.config('hdl'); hdlcfg.TestBenchName = 'systemverilog_example_tb';
TargetLanguage プロパティを SystemVerilog に設定します。
hdlcfg.TargetLanguage = 'SystemVerilog';
3. コード生成を実行します。
codegen -config hdlcfg systemverilog_example
### Begin MATLAB to HDL Code Generation...
### Working on DUT: systemverilog_example.
### Using TestBench: systemverilog_example_tb.
### Begin SystemVerilog Code Generation
### Working on systemverilog_example as <a href="matlab:edit('/tmp/Bdoc25b_2988451_710120/tp11ca1a46/hdlcoder-ex49202891/codegen/systemverilog_example/hdlsrc/systemverilog_example.sv')">systemverilog_example.sv</a>.
### Generating package file <a href="matlab:edit('/tmp/Bdoc25b_2988451_710120/tp11ca1a46/hdlcoder-ex49202891/codegen/systemverilog_example/hdlsrc/systemverilog_example_pkg.sv')">systemverilog_example_pkg.sv</a>.
### Generating Resource Utilization Report <a href="matlab:hdlcoder.report.openDdg('/tmp/Bdoc25b_2988451_710120/tp11ca1a46/hdlcoder-ex49202891/codegen/systemverilog_example/hdlsrc/resource_report.html')">resource_report.html</a>.
### Generating Optimization report
### To rerun codegen evaluate the following commands...
---------------------
cgi = load('/tmp/Bdoc25b_2988451_710120/tp11ca1a46/hdlcoder-ex49202891/codegen/systemverilog_example/hdlsrc/codegen_info.mat');
inVals = cgi.CodeGenInfo.inVals;
cfg = cgi.CodeGenInfo.codegenSettings;
codegen -config cfg -args inVals -report
---------------------
### Generating HDL Conformance Report <a href="matlab:web('/tmp/Bdoc25b_2988451_710120/tp11ca1a46/hdlcoder-ex49202891/codegen/systemverilog_example/hdlsrc/systemverilog_example_hdl_conformance_report.html')">systemverilog_example_hdl_conformance_report.html</a>.
### HDL Conformance check complete with 0 errors, 0 warnings, and 0 messages.
### Code generation successful: To view the report, open('codegen/systemverilog_example/hdlsrc/html/report.mldatx')