アウトプットブログ

勉強したことをまとめていきます。

VHDL/SystemVerilog混在シミュレーション

自分は普段の開発ではVHDLを使用している。テストベンチも同様なのだが、少し凝ったことをしようとすると面倒と感じることがあった。調べるとSystemVerilogのDPI-Cという機能で検証にC言語の関数を使用できるらしく、何が出来るのか試してみることにした。

そもそもSystemVerilogを使用したことがないので、まずは混在シミュレーションを試す。インクリメントデータを出力するVHDLモジュールをSystemVerilogで記述したテストベンチから呼び出す。

環境はWindows10 64bitでModelSim ASE 10.4bを使用。
※ModelSim ASEでのVHDL/SystemVerilog混在シミュレーションは10.3d以降のみ可能なようです。

・テストモジュール:hoge_vhd.vhd

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity hoge_vhd is
 port (
  srst_i : in std_logic;
  clk_i  : in std_logic;
  d_o    : out std_logic_vector (7 downto 0)
 );
end hoge_vhd;

architecture rtl of hoge_vhd is

signal inc : std_logic_vector (7 downto 0);

begin

-- インクリメントデータを生成・出力
process (clk_i) begin
 if (rising_edge(clk_i)) then
  if (srst_i = '1') then
   inc <= (others => '0');
  else
   inc <= inc + 1;
  end if;
 end if;
end process;

d_o <= inc;

end rtl;

・テストベンチ:hoge_sv.sv

timeunit 1ns;
timeprecision 10ps;

module hoge_sv();
 
 // クロック
 bit clk_i = 1'b0;
 always begin
  #5ns clk_i = ~clk_i;
 end
 
 // リセット
 bit srst_i;
 initial begin
  srst_i = 1'b1;
  #100ns;
  @(posedge clk_i) #1ps srst_i = 1'b0;
 end
 
 // VHDLモジュールをインスタンス化
 byte d_o; 
 
 hoge_vhd u_vhd (
  .srst_i(srst_i), //: in std_logic;
  .clk_i(clk_i),   //: in std_logic;
  
  .d_o(d_o)        //: out std_logic_vector (31 downto 0)
 );
 
endmodule

ModelSimプロジェクト作成、シミュレーション実行はVHDLのみの場合と同様の手順で問題なかった。シミュレーション結果が以下。VHDL、SystemVerilogの両階層でインクリメントデータを確認できた。
f:id:HappyField:20151121013342j:plain