
第04章验证与VCS使用.pdf
20页第四章验证与 VCS 使用本章将讲述的内容:第一节 验证什么是验证为什么需要验证验证的重要性如何进行验证第二节 VCS 简单使用方法2.1 什么是 VCS 2.2VCS 可以做什么2.3 怎样进行验证2.4VCS 的工作方式2.5VCS 使用方法举个简单例子2.6VirSim 的图形方式和每个窗口的介绍附录 A.VCS的参数附录 B.virsim简明帮助附录 C.simv简明帮助第一节验证当代码编写完之后,怎么确定是正确的呢,代码能不能符合设计要求,能不能完成所需要的功能,这就是验证所要做的工作验证在设计中有很重要的地位,从设计流程中可以看到,几乎设计工作每前进一步,都要进行验证对验证的要求,大多数人认为只要编译通过之后,能实现功能就可以了,其实决不仅仅这么简单,验证的目的应该是尽量多的找到代码中的错误,不管是编写错误还是功能错误,找出的错误越多,验证工作就做的越好越好既然验证这么重要,如何进行验证呢?对于验证来说,不同等级的验证,它的方法是不一样的什么是验证的等级,从设计流程(下图)可以看到,验证可以大致分为单独子模块验证、功能模块验证、系统顶级验证单独子模块验证,需要做的工作是验证它的功能和逻辑是否符合设计要求。
功能模块验证,需要验证这个模块的功能可不可以满足要求,是否会有非法数据或不该有的输出,错误的状态等系统顶级验证,更关注于系统整体的行为方式,模块间的联系和通讯,总线信号,数据流路径是否满足设计要求,数据处理或时序正确与否等验证需要一个支持的平台,这就是 test_bench,在这个测试平台上,有激励信号产生器、被测模块、响应分析和监测器,(下图)激励与控制:输入端口设置,测试向量,测试模式设置,同步名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 20 页 -响应分析器和监测器:可以及时监控输出信号变化,可以判断输出信号是正确、合法、错误、非法等等testbench可以用 verilog 描述语言搭建,也可以用C 语言编写,如果用C 语言编写,还需要相关的编译器并和与verilog 的接口第二节 VCS 的简单使用方法2.1 什么是 VCS VCS的全称是 Verilog Compile Simulator,是 Synopsys公司的强有力的电路仿真工具,可以进行电路的时序模拟2.2 VCS的工作方式VCS运行首先把输入的verilog源文件编译,然后生成可执行的模拟文件,也可以生成VCD 或者 VCD 记录文件。
然后运行这个可执行的文件,可以进行调试与分析;或者查看生成的 VCD 或者 VCD 记录文件还生成了一些供分析和查看的文件,以便于调试2.3 怎样进行仿真和验证仿真测试一个模块的大致步骤如下:(1)首先需要编写好模块的verilog 代码2)搭建testbench,充分了解被测模块的特性,编写测试向量,输入端口的激励,编写响应分析和监测部分3)运行 VCS 进行模拟,查看输出或者波形4)若发现错误,分析错误类型和原因,修改代码或者修正测试方法,直到符合测试要求2.4 VCS 的运行方式VCS 的运行方式有两种,一种是交互模式(interactive mode),一种是批处理模式(batch mode),两种方式各有优劣,具体用在不同的情况下在测试小模块或者底层模块,情况不太复杂的时候,而又需要很详细信息的时候,可以采用交互模式,交互性能更好,显示更直观;当进行复杂测试而关注于整体性能,而不必去查看每个信号的时候,只需要查看所需要关心的信号即可,这种情况可以用批处理模式2.5 VCS 简单使用例子Module Monitor&Analyzer Stimulus&Control 名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 20 页 -下面用一个简单的例子来说明如何使用VCS 这是个四位全加器的verilog 代码,存储为add4.v,module addr4(clk,in1,in2,sum,carry);output 3:0 sum;output carry;input clk;input 3:0 in1,in2;reg 3:0 sum;reg carry;integer temp;initial begin sum=0;carry=0;end always(posedge clk)begin temp=in1+in2;sum=temp;if(temp 15)carry=1;else carry=0;end endmodule 然后再根据这个模块写一个测试模块,也称之为testbench,存为 top.v,module top;reg clk_reg;reg 3:0 in1_reg,in2_reg;wire 3:0 sum;wire carry;addr4 a4(clk_reg,in1_reg,in2_reg,sum,carry);parameter d=100;initial begin clk_reg=0;in1_reg=0;in2_reg=0;repeat(16*100)begin#d in1_reg=in1_reg+1;in2_reg=in2_reg+1;/$display($stime,in1_reg+%d in2_reg+%d=sum%d carry is%d,in1_reg,名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 20 页 -in2_reg,sum,carry);/$display($stime,%b+%b=%b and carry is%b,in1_reg,in2_reg,sum,carry);end/$strobe($stime,in1_reg%b in2_reg%b sum%b carry%b,in1_reg,in2_reg,sum,carry);#1$finish(2);end always begin#50 clk_reg=clk_reg;end always(sum)begin/$display($stime,in1_reg+%d in2_reg+%d=sum%d carry_reg is%d,in1_reg,in2_reg,sum,carry_reg);$display($stime,now at a clock posedge,the operation is:%d+%d=%d and carry is%d,in1_reg,in2_reg,sum,carry);/$stop;end endmodule 最简单的仿真,只要运行vcs filename 即可,filename 可以有很多个,比如上面的例子:vcs top.v add4.v 然后,如果没有发现编译错误,将会出现VCS 的说明和一些信息,接下来的就是它的执行情况,翻译top.v 和 add4.v,可以自动发现顶层模块,如果定义了timescale 将显示用的timescale 信息,如果没有,就显示No TimeScale specified。
然后将产生一个名为simv 的可执行文件,这个就是模拟仿真文件下面是运行结果:Parsing design file top.v Parsing design file add4.v Top Level Modules:top No TimeScale specified 1 of 2 unique modules to generate 1 of 1 modules done Invoking loader.simv generation successfully completed 下面我们来运行一下这个simv 可执行文件,simv 结果将显示:名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 20 页 -Chronologic VCS simulator copyright 1991-2001 Contains Synopsys proprietary information.Compiler version 6.0;Runtime version 6.0;Jan 8 15:37 2002 0 now at a clock posedge,the operation is:0+0=0 and carry is 0 150 now at a clock posedge,the operation is:1+1=2 and carry is 0 250 now at a clock posedge,the operation is:2+2=4 and carry is 0 350 now at a clock posedge,the operation is:3+3=6 and carry is 0 450 now at a clock posedge,the operation is:4+4=8 and carry is 0 550 now at a clock posedge,the operation is:5+5=10 and carry is 0 650 now at a clock posedge,the operation is:6+6=12 and carry is 0 750 now at a clock posedge,the operation is:7+7=14 and carry is 0 850 now at a clock posedge,the operation is:8+8=0 and carry is 1 950 now at a clock posedge,the operation is:9+9=2 and carry is 1 1050 now at a clock posedge,the operation is:10+10=4 and carry is 1 1150 now at a clock posedge,the operation is:11+11=6 and carry is 1 1250 now at a clock posedge,the operation is:12+12=8 and carry is 1 1350 now at a clock posedge,the operation is:13+13=10 and carry is 1 1450 now at a clock posedge,the operation is:14+14=12 and carry is 1 1550 now at a clock posedge,the operation is:15+15=14 and carry is 1 1650 now at a clock posedge,the operation is:0+0=0 and carry is 0 1750 now at a clock posedge,the operation is:1+1=2 and carry is 0 1850 now at a clock posedge,the operation is:2+2=4 and carry is 0 1950 now at a clock posedge,the operation is:3+3=6 and carry is 0 2050 now at a clock posedge,the operation is:4+4=8 and carry is 0 2150 now at a clock posedge,the operation is:5+5=10 and carry is 0 2250 now at a clock posedge,the operation is:6+6=12 and carry is 0 2350 now at a clock posedge,the operation is:7+7=14 and carry is 0 2450 now at a。












