如何使用Debussy與ModelSim做Co-Simulation? (SOC) (Verilog) (VHDL) (Debussy) (ModelSim)
Abstract
本文介紹如何使用Debussy與ModelSim做Co-Simulation,並使用Verilog、VHDL以及Verilog搭配VHDL交叉一起simulation。 Introduction
使用環境:Debussy 5.4 v9 + ModelSim SE 6.3e
我之前一直使用Debussy + NC-Verilog做simulation,Debussy (Verdi)可以說是HDL的Source Insight,是trace與debug的神兵利器,NC-Verilog也是Verilog simulator中速度最快的,可是最近因工作需要,拿到的一包code卻是用Verilog寫RTL,用VHDL寫testbench,所以必須2種語言一起做simulation,我在NC-Verilog一直無法成功讓兩種語言一起simulation。ModelSim雖然支援Verilog + VHDL co-simulation,但用慣Debussy的我還是無法忘懷其方便的trace code方式,所以若能讓ModelSim也能dump出Debussy所需要的fsdb檔案,這樣就太完美了。 接下來會分4個方式討論
1.RTL與testbench皆使用Verilog 2.RTL與testbench皆使用VHDL
3.RTL使用VHDL,testbench使用Verilog 4.RTL使用Verilog,testbench使用VHDL 1.RTL與testbench皆使用Verilog Step 1:
設定ModeSim使用Verilog PLI (因為testbench使用Verilog) 將C:\\Novas\\Debussy\\share\\PLI\\modelsim_pli\\WINNT\\novas.dll複製到C:\\Modeltech_6.3e\\win32\\下
修改C:\\Modeltech_6.3e\\modelsim.ini,將Veriuser部分修改成如下所示:
; List of dynamically loaded objects for Verilog PLI applications ; Veriuser = veriuser.sl ; use by verilog Veriuser = novas.dll
; use by vhdl
; Veriuser = novas_fli.dll 复制代码
modelsim.ini是個read only檔,要修改前記得修改其屬性才能存檔。 Step 2:
RTL部分 (以4 bit counter為例) counter.v / Verilog
1 /*
2 (C) OOMusou 2011 http://oomusou.cnblogs.com 3
4 Filename : counter.v
5 Simulator : ModelSim 6.3e, Debussy 5.4 v9 6 Description : ModelSim with debussy 7 Release : 01/31/2010 1.0 8 */ 9
10 module counter ( 11 clk, 12 rst_n, 13 cnt 14 ); 15
16 input clk; 17 input rst_n; 18 output [3:0] cnt; 19
20 reg [3:0] cnt; 21
22 always@(posedge clk, negedge rst_n) begin 23 if (~rst_n) 24 cnt <= 4'h0; 25 else
26 cnt <= cnt + 1'b1; 27 end 28
29 endmodule 复制代码
Step 3: Testbench部分
counter_tb.v / Verilog
1 /*
2 (C) OOMusou 2011 http://oomusou.cnblogs.com 3
4 Filename : counter_tb.v
5 Compiler : ModelSim 6.3e, Debussy 5.4 v9 6 Description : ModelSim with debussy 7 Release : 01/31/2010 1.0 8 */ 9
10 module counter_tb; 11
12 reg clk; 13 reg rst_n; 14 wire [3:0] cnt; 15
16 // 50MHz
17 always #(10) clk = ~clk; 18
19 initial begin 20 #0;
21 clk = 1'b0; 22 rst_n = 1'b0; 23 24 #5;
25 rst_n = 1'b1; 26 #195; 27 $finish; 28 end 29
30 initial begin
31 $fsdbDumpfile(\); 32 $fsdbDumpvars(0, counter_tb); 33 end 34
35 counter u_counter ( 36 .clk(clk), 37 .rst_n(rst_n), 38 .cnt(cnt) 39 ); 40
41 endmodule 复制代码
19行
initial begin #0;
clk = 1'b0; rst_n = 1'b0; #5;
rst_n = 1'b1; #195; $finish; end 复制代码
一搬來說,若在NC-Verilog做simulation,我們會在testbench內指定結束simulation的時間,不過在ModelSim裡,simulation時間是由ModelSim script控制,在testbench內寫$finish並沒有用,所以會省略$finish時間入下。
initial begin #0;
clk = 1'b0; rst_n = 1'b0; #5;
rst_n = 1'b1; end 复制代码
Step 4:
ModelSim script部分 vsim.do
vlib work vlog counter.v vlog counter_tb.v vsim counter_tb run 200ns q 复制代码
其中
vlib work
建立work library。
vlog counter.v vlog counter_tb.v 复制代码
編譯RTL:counter.v 與 testbench:counter_tb.v,vlog為modelsim的Verilog compiler。
vsim counter_tb
以counter_tb為top module進行simulation。
run 200ns
命令ModelSim執行200 ns的simulation。
q
離開ModelSim Step 5:
執行ModelSim的批次檔 mod.bat
vsim -c -do sim.do
-c 表示ModelSim將以console mode執行,因為在Debussy + ModelSim時,只把ModelSim當成NC-Verilog使用,並沒有用到ModelSim的GUI模式。 -do 表示執行ModelSim script。 執行結果
D:\\0Clare\\VerilogLab\\ModelSim\\counter_verilog>vsim -c -do sim.do Reading C:/Modeltech_6.3e/tcl/vsim/pref.tcl # 6.3e
# do sim.do
# ** Warning: (vlib-34) Library already exists at \
# Model Technology ModelSim SE vlog 6.3e Compiler 2008.02 Feb 2 2008 # -- Compiling module counter #
# Top level modules: # counter
# Model Technology ModelSim SE vlog 6.3e Compiler 2008.02 Feb 2 2008 # -- Compiling module counter_tb #
# Top level modules: