1 / 37

第九讲 基本的输入和输出

第九讲 基本的输入和输出. 提纲. 基本 input/output 文件 测试程序( Testbenches ) ASSERT 语句. 文件对象. VHDL 的对象包括 信号 变量 常量 文件 通过引入文件类型,使得我们可以定义和使用文件对象. 文件定义. 文件可以通过它所存储的内容来进行区分 type text 是字符串文件; type IntegerFileType 是整数型文件; VHDL 1987 中的文件定义 file infile: text is in “inputdata.txt” ;

korene
Download Presentation

第九讲 基本的输入和输出

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第九讲 基本的输入和输出

  2. 提纲 • 基本input/output文件 • 测试程序(Testbenches) • ASSERT语句

  3. 文件对象 • VHDL的对象包括 • 信号 • 变量 • 常量 • 文件 • 通过引入文件类型,使得我们可以定义和使用文件对象

  4. 文件定义 • 文件可以通过它所存储的内容来进行区分 • type text 是字符串文件; • type IntegerFileType 是整数型文件; • VHDL 1987中的文件定义 • file infile: text is in “inputdata.txt”; • file outfile: text is out “outputdata.txt”; • VHDL 1993中的文件定义 • file infile: text open read_mode is “inputdata.txt”; • file outfile: text open write_mode is “outputdata.txt”;

  5. 文件定义:二进制I/O文件(VHDL 1993)

  6. 文件定义:二进制I/O文件(VHDL 1993) • VHDL支持read(f,value), write(f, value)和 endfile(f)操作; • VHDL 93支持File_Open()和File_Close()操作; • 直接和间接的文件打开操作;

  7. 文件定义:二进制I/O文件(VHDL 1987)

  8. 文件定义:二进制I/O文件(VHDL 1987) • VHDL1987支持read(f,value), write(f, value)和 endfile(f)操作; • 通过文件声明来间接地进行文件打开操作;

  9. 文件定义:TEXTIO包

  10. 文件定义:TEXTIO包 • 文件是按行(lines)来组织的; • Read()和write()子程序对line数据结构进行操作; • Readline()和writeline()子程序和文件进行数据交换; • 基于Text的 I/O操作; • 在STD 库的TEXTIO包中封装了全部的操作子程序 • 从行( lines )中读取和写入预定义类型数据的子程序; • 针对std_input and std_output的预定义访问操作; • 子程序名的重载(Overloaded);

  11. 文件定义:TEXTIO包的使用

  12. 文件定义:TEXTIO包的使用

  13. 文件定义:TEXTIO包的使用

  14. 文件定义:扩展TEXTIO支持其他数据类型 • 对用户隐藏TEXTIO的ASCII格式; • 针对所希望的数据类型的读和写,如, std_logic_vector ,提供类型转换子程序; • 将子程序封装在包中; • 将包( package)安装在库( library)中,然后通过use子句使库中的内容可见;

  15. 代码示例:类型转换

  16. 代码示例:类型转换

  17. 代码示例:(Bhasker95) • 输出格式定义: write (buf, “This is the header”); writeline (outfile,buf); write (buf, “Clk =”); write (buf, clk); write (buf, “, N1 =”); write (buf, N1); • 输出结果: This is the header Clk = 0, N1 = 01001011

  18. 代码示例:(Bhasker95) • 读入的格式化输入行:

  19. 代码示例:(Bhasker95) • 读入该格式化输入行的程序:

  20. 代码示例:文件名的处理

  21. 代码示例:文件名的处理 • 在上面的代码中假定“input”映射到模拟器的控制台 • 通常“input”和 “output”分别映射到标准输入和标准输出

  22. 代码示例:测试模块

  23. 代码示例:测试模块

  24. 代码示例:测试程序(Testbenches) • 测试程序具有一定的通用性 • 基本策略是:施加测试激励,测量和记录响应矢量

  25. 代码示例:测试程序(Testbenches) •测试程序产生周期性的时钟信号并施加测矢量

  26. 代码示例:测试程序(Testbenches)

  27. 代码示例:结构化测试模块

  28. 测试激励的生成 • 定义功能测试所需的激励矢量和参考矢量 • 激励源 • 局部常数阵列 • I/O文件 • 时钟和复位信号的生成 • 通常与激励矢量相隔离 • 实现周期性的激励

  29. 测试激励的生成:示例(Smith96)

  30. 测试激励的生成:示例(Smith96)

  31. 测试结果的确认(Validation) • 将测试响应矢量与参考矢量相比较,并在外部文件中记录其中不匹配的部分(出错点); • 同时需要记录出错点所对应的仿真时间点; • 可能需要记录仿真状态。

  32. 断言(ASSERT) • 将测试响应矢量与参考矢量相比较,并在外部文件中记录其中不匹配的部分(出错点); • 同时需要记录出错点所对应的仿真时间点; • 可能需要记录仿真状态。

  33. 断言(ASSERT) assert Q = check(1) and Qbar = check(0) report “Test Vector Failed” severity error; 仿真器控制台输出示例 Selected Top-Level: srbench (behavioral) : ERROR : Test Vector Failed : Time: 20 ns, Iteration: 0, Instance: /T1. : ERROR : Test Vector Failed : Time: 100 ns, Iteration: 0, Instance: /T1.

  34. 断言(ASSERT) assert Q = check(1) and Qbar = check(0) report “Test Vector Failed” severity error; 仿真器控制台输出示例 Selected Top-Level: srbench (behavioral) : ERROR : Test Vector Failed : Time: 20 ns, Iteration: 0, Instance: /T1. : ERROR : Test Vector Failed : Time: 100 ns, Iteration: 0, Instance: /T1.

  35. 断言(ASSERT) • 设计者可以在预定义的级别上报告出错情况:NOTE,WARNING, ERROR and FAILURE (枚举类型) • 报告的参数是一个字符串,该字符串会写到仿真输出 • 断言所对应的操作是仿真器相关的 • 并行 vs. 串行断言语句 • 在不中断仿真的情况下TEXTIO比 ASSERT快

  36. 断言(ASSERT):示例(Bhaskar 95) • architecture check_times of DFF is • constant hold_time: time:=5 ns; • constant setup_time : time:= 2 ns; • begin • process • variable lastevent: time; • begin • if d’event then • assert NOW = 0 ns or (NOW - lastevent) >=hold_time • report “Hold time too short” • severity FAILURE; • lastevent := NOW; • end if; • -- check setup time • -- D flip flop behavioral model • end process; • end architecture check_times

  37. 总结 • 基本input/output • ASCII I/O和 TEXTIO package • binary I/O • VHDL 87 vs. VHDL 93 • 测试程序(Testbenches) • ASSERT语句

More Related