0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VivadoでシミュレーションするTclスクリプト(2025年版)

0
Posted at

はじめに

Xilinx 社のFPGA開発環境の Vivado、いちいち GUI でマウスボタンをポチポチするのは面倒です。
Vivado は Tcl スクリプトでバッチ処理が出来るので、決まり切った仕事なら Tcl スクリプトを書いて処理させたほうが楽です。
この記事では、Vivado でシミュレーションするTclスクリプトを解説します。

環境

  • Xilinx Vivado 2015.4
  • Xilinx Vivado 2016.4
  • Xilinx Vivado 2017.1
  • Xilinx Vivado 2017.2
  • Xilinx Vivado 2023.1
  • Xilinx Vivado 2025.1

Tclスクリプトの説明

1 プロジェクトを開く

このスクリプトではすでにプロジェクトが作られていることを前提にしています。
変数 project_name にプロジェクト名を、変数 project_directory にプロジェクトのあるディレクトリを設定しておきます。
この例では、project_name に "project" を、project_directory にTclスクリプトのあるディレクトリを指定しています。

simulation.tcl
set project_directory   [file dirname [info script]]
set project_name        "project"

open_project [file join $project_directory $project_name]

2 実行時間を設定する

シミュレーションする実行時間(runtime)を設定します。設定しない場合は、Vivado のデフォルト値である 1000ns が設定されます。

simulation.tcl
set_property -name {xsim.simulate.runtime} -value {1000ns} -objects [get_filesets sim_1]

シミュレーションが明示的に終了されるまで無限に実行する場合は次のように all を指定します。

simulation.tcl
set_property -name {xsim.simulate.runtime} -value {all} -objects [get_filesets sim_1]

3 デザインのトップレベルを指定する

もし必要ならば、シミュレーションを行うデザインののトップレベルを指定します。具体的には ファイルセット source_1 に "top" プロパティを設定することで行います。以下の例では ArgSort_AXI というモジュールを sources_1 のトップレベルとして指定しています。

simulation.tcl
update_compile_order -fileset sources_1
set obj [get_filesets sources_1]
set_property "top" "ArgSort_AXI"  $obj

4 テストベンチのトップレベルを指定する

シミュレーションを行うテストベンチのトップレベルを指定します。具体的にはファイルセット sim_1 に "top" プロパティを設定することで行います。

以下の例では変数 test_bench に指定したテストベンチのモジュール(ArgSort_AXI_Test_Bench_X04_W1_F1)を sim_1 のトップレベルとして指定しています。

simulation.tcl
set test_bench "ArgSort_AXI_Test_Bench_X04_W1_F1"
update_compile_order -fileset sim_1
set_property "top" $test_bench [get_filesets sim_1]

5 generic 変数に値を指定する

Vivado ではシミュレーション対象のテストベンチが generic 変数によって値を設定できるようになっている場合、シミュレーション時に値を上書きすることができます。具体的には、ファイルセット sim_1 に "generic" プロパティを設定することで行います。

以下の例では test_bench の generic 変数 SCENARIO_FILE には変数 scenario_full_path の値を、generic 変数 FINISH_ABORT には true を上書きしています。

simulation.tcl
set scenario_file  [file join $project_directory ".." ".." ".." "src" "test" "scenarios" $project_name "test_1.snr" ]
set current_vivado_version [version -short]
if       { [string first "2025.1" $current_vivado_version ] == 0 } {
    set scenario_full_path [file join ".." ".." ".."      $scenario_file ]
} elseif { [string first "2019.2" $current_vivado_version ] == 0 } {
    set scenario_full_path [file join ".." ".." ".."      $scenario_file ]
} elseif { [string first "2018.3" $current_vivado_version ] == 0 } {
    set scenario_full_path [file join ".." ".." ".."      $scenario_file ]
} elseif { [string first "2017"   $current_vivado_version ] == 0 } {
    set scenario_full_path [file join ".." ".." ".." ".." $scenario_file ]
} else {
   puts ""
   puts "ERROR: This model can not run in Vivado <$current_vivado_version>"
   return 1
}
set_property "generic" "SCENARIO_FILE=$scenario_full_path FINISH_ABORT=true" [get_filesets sim_1]

6 シミュレーションを実行する

simulation.tcl
launch_simulation

7 プロジェクトを閉じる

simulation.tcl
close_project

Tclスクリプトの実行

Vivado のバッチモードで実行する

Tclスクリプトを Vivado のバッチモードで実行する場合は次のようにします。

shell% vivado -mode batch -source simulation.tcl

Vivado の GUIモードから実行する

Tclスクリプトを Vivado のGUIモードから動かす場合は次のようにします。

Vivado > Tools > Run Tcl Script... > simulation.tcl

Tclスクリプトサンプル

simulation.tcl
#
# simulation.tcl  Tcl script for simulation
#
set project_directory       [file dirname [info script]]
set project_name            "argsort_axi"
set test_bench              "ArgSort_AXI_Test_Bench_X04_W1_F1"
set scenario_file           [file join $project_directory ".." ".." ".." "src" "test" "scenarios" $project_name "test_1.snr" ]
#
# Open Project
#
open_project [file join $project_directory $project_name]
#
# Set 'sources_1' fileset properties
#
update_compile_order -fileset sources_1
set obj [get_filesets sources_1]
set_property "top" "ArgSort_AXI"  $obj
#
# Set 'sim_1' fileset properties
#
set current_vivado_version [version -short]
if       { [string first "2025.1" $current_vivado_version ] == 0 } {
    set scenario_full_path [file join ".." ".." ".."      $scenario_file ]
} elseif { [string first "2019.2" $current_vivado_version ] == 0 } {
    set scenario_full_path [file join ".." ".." ".."      $scenario_file ]
} elseif { [string first "2018.3" $current_vivado_version ] == 0 } {
    set scenario_full_path [file join ".." ".." ".."      $scenario_file ]
} elseif { [string first "2017"   $current_vivado_version ] == 0 } {
    set scenario_full_path [file join ".." ".." ".." ".." $scenario_file ]
} else {
   puts ""
   puts "ERROR: This model can not run in Vivado <$current_vivado_version>"
   return 1
}
update_compile_order -fileset sim_1
set obj [get_filesets sim_1]
set_property "top"     $test_bench $obj
set_property "generic" "SCENARIO_FILE=$scenario_full_path FINISH_ABORT=true" $obj
set_property -name {xsim.simulate.runtime} -value {all} -objects $obj
#
# Run Simulation
#
launch_simulation
#
# Close Project
#
close_project

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?