dotafengvs的个人空间 https://blog.eetop.cn/913985 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

(转帖) 如何使用Debussy與ModelSim做Co-Simulation

已有 1749 次阅读| 2014-3-21 15:43

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("counter.fsdb");
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 "work".
# 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:
# counter_tb
# vsim counter_tb
# ** Note: (vsim-3813) Design is being optimized due to module recompilation...
# ** Note: (vsim-3865) Due to PLI being present, full design access is being specified.
# Loading C:\Modeltech_6.3e\win32/novas.dll
# // ModelSim SE 6.3e Feb 2 2008
# //
# // Copyright 1991-2008 Mentor Graphics Corporation
# // All Rights Reserved.
# //
# // THIS WORK CONTAINS TRADE SECRET AND
# // PROPRIETARY INFORMATION WHICH IS THE PROPERTY
# // OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS
# // AND IS SUBJECT TO LICENSE TERMS.
# //
# Loading work.counter_tb(fast)
# Loading work.counter(fast)
# Novas FSDB Dumper for ModelSim, Release 5.4v9 (Win95/NT) 05/04/2005
# Copyright (C) 1996 - 2004 by Novas Software, Inc.
# *Novas* Create FSDB file 'counter.fsdb'
# *Novas* Start dumping the scope(counter_tb), layer(0).
# *Novas* End of dumping.
# ** Note: $finish : counter_tb.v(27)
# Time: 200 ns Iteration: 0 Instance: /counter_tb
复制代码

Step 6:

執行Debussy批次檔部份

deb.bat

debussy -2001 counter_tb.v counter.v -ssf counter.fsdb -sswr counter.rc

-2001表示支援Verilog 2001語法

-ssf 載入Debussy dump file

-sswr 載入Debussy signal file

執行結果

deb01

2.RTL與testbench皆使用VHDL

Step 1:

設定ModelSim使用VHDL FLI (因為testbench使用VHDL)

將C:\Novas\Debussy\share\PLI\modelsim_fli54\WINNT\novas_fli.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檔,要修改前記得修改其屬性才能存檔。

複製C:\Novas\Debussy\share\PLI\modelsim_fli54\WINNT\novas.vhd到自己的project底下

(為什麼Verilog不需要這個檔,而VHDL需要這個檔,稍後會解釋)

Step 2:

RTL部分 (以4 bit counter為例)

counter.vhd / VHDL

复制代码
1 -- (C) OOMusou 2011 http://oomusou.cnblogs.com
2
3 -- Filename : counter.vhd
4 -- Simulator : ModelSim 6.3e, Debussy 5.4 v9
5 -- Description : ModelSim with debussy
6 -- Release : 02/05/2011 1.0
7
8 library IEEE;
9 use IEEE.std_logic_1164.all;
10 use IEEE.std_logic_unsigned.all;
11
12 entity counter is
13 port ( clk : in std_logic;
14 rst_n : in std_logic;
15 cnt : out std_logic_vector(3 downto 0));
16 end entity counter;
17
18 architecture arc of counter is
19 signal cnt_r : std_logic_vector(3 downto 0);
20 begin
21 process(clk, rst_n)
22 begin
23 if (rst_n = '0') then
24 cnt_r <= "0000";
25 elsif rising_edge(clk) then
26 cnt_r <= cnt_r + 1;
27 end if;
28 end process;
29
30 cnt <= cnt_r;
31 end arc;
复制代码

Step 3:

Testbench部分

counter.vhd / VHDL

复制代码
1 -- (C) OOMusou 2011 http://oomusou.cnblogs.com
2
3 -- Filename : counter_tb.vhd
4 -- Simulator : ModelSim 6.3e, Debussy 5.4 v9
5 -- Description : ModelSim with debussy
6 -- Release : 01/31/2010 1.0
7
8 library IEEE;
9 use IEEE.std_logic_1164.all;
10 use IEEE.std_logic_unsigned.all;
11 use work.pkg.all;
12
13 entity counter_tb is
14 end entity counter_tb;
15
16 architecture arc of counter_tb is
17 component counter
18 port (
19 clk : in std_logic;
20 rst_n : in std_logic;
21 cnt : out std_logic_vector(3 downto 0)
22 );
23 end component;
24
25 signal clk : std_logic := '0';
26 signal rst_n : std_logic := '0';
27 signal cnt : std_logic_vector(3 downto 0);
28
29 begin
30 process
31 begin -- 50MHz
32 clk_loop : loop
33 clk <= '0';
34 wait for 10 ns;
35 clk <= '1';
36 wait for 10 ns;
37 end loop clk_loop;
38 end process;
39
40 process
41 begin
42 wait for 5 ns;
43 rst_n <= '1';
44 end process;
45
46 process
47 begin
48 fsdbDumpfile("counter.fsdb");
49 fsdbDumpvars(0, "counter_tb");
50 wait;
51 end process;
52
53 u_counter : counter
54 port map (
55 clk => clk,
56 rst_n => rst_n,
57 cnt => cnt
58 );
59 end arc;
复制代码

11行

use work.pkg.all;

這是因為novas.vhd與VHDL FLI的原因,稍後會解釋。

47行

process
begin
fsdbDumpfile(
"counter.fsdb");
fsdbDumpvars(
0, "counter_tb");
wait;
end process;

一樣使用fsdbDumpfile()與fsdbDumpvars()兩個Debussy所提供的函數,不過在VHDL FLI並不需要如Verilog PLI一樣加上$。

wait也一定要加上,否則在ModelSim做simulation時會造成無窮回圈無法停止。

Step 4:

ModelSim script部分

vsim.do

复制代码
vlib work
vcom novas
.vhd
vcom counter
.vhd
vcom counter_tb
.vhd
vsim counter_tb
run 200ns
q
复制代码

因為是VHDL,所以全部改用vcom編譯。

其中novas.vhd是從Debussy目錄複製過來的,為什麼需要編譯這個檔案呢?

VHDL FLI (Foreign Language Interface)與Verilog PLI (Programming Language Interface)不同的地方在於,當你自己提供由C寫的function給simulator使用時,Verilog PLI會自己到所提供的dll去找是否有此function,但VHDL FLI需要自己去提供mapping的動作,告訴simulator哪一個function對應dll內那ㄧ個function,novas.vhd就是提供這個mapping的腳色。

若直接使用Debussy所提供的novas.vhd,在執行ModelSim會有以下錯誤訊息。

# ** Warning: (vsim-FLI-3159) Failed to find foreign function 'fliparseVariableInFile' in FLI object file "C:\Modeltech_6.3e\win32/./novas_fli.dll".

意思是novas.vhd定義的fliparseVariableInFile在novas_fli.dll找不到,致於為什麼會有此錯誤,我並不清楚。

將novas.vhd修改成如下所示:

novas.vhd / VHDL

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 2

    粉丝
  • 0

    好友
  • 0

    获赞
  • 1

    评论
  • 1651

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-3 08:03 , Processed in 0.022529 second(s), 13 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部