Simple test file structure

Test file structure

Why a simple test code can be generic it? This test file structure from the start. First we will give you the test code listed a convenient explanation

/****************************************************          

* Engineer:    Dream Brother Wing

*   QQ               :   761664056

*****************************************************/

`Timescale 1ns 01 / 1ps // time units and precision definitions

02  module tb;

03

04 // system input

05   REG  CLK ;    // system clock input

06   REG  rst_n ;  // reset

07 // system output

08   Wire  [ . 3 : 0 ] pio_led ; // the LED drive output

09  

10  initial

11      begin

12          clk=0;

13          rst_n=0;

14          #1000.1 rst_n=1;

15      end 

16      

. 17       Always  # 10 CLK = ~ CLK ; // 50MHz clock

18      

19  led_learn led_learn(

20 is           . CLK ( CLK ),        // the system clock input

21 is           . RST_N ( RST_N ),    // reset

22 is           . Pio_led ( pio_led ) // the LED drive output

23        );

24  endmodule

代码05-08行,相当于是“导线定义”,被测试模块所有的输入都要定义为 “reg”类型,被测试模块所有的输出都要定义为“wire”类型。

代码10-15行,测试激励编写模块。通过该模块我们可以给准备输入到被测试模块的“导线”赋值。

代码17行,通过always 块,可以实现clk信号自取反操作的无限循环,产生无限个数的时钟,方便仿真

代码19-23行,我们术语叫做“模块实例化”,实际上,大家可以等效理解为是“导线连接”,即将对应的导线连接到我们的待测试电路对应端口。

由此可见,待测试内部逻辑的变化对我们测试模块的编写是没有任何影响的,对于测试文件来说,我们关心的只是待测试模块的端口,仅此而已。大家以后开发过程中用到的测试文件实际上就是以此测试文件为基础,进行简单的修改就可以使用,相信大家一定会有一种似曾相识的感觉。

Guess you like

Origin www.cnblogs.com/mengyi1989/p/11515971.html