370 likes | 471 Views
第九讲 基本的输入和输出. 提纲. 基本 input/output 文件 测试程序( Testbenches ) ASSERT 语句. 文件对象. VHDL 的对象包括 信号 变量 常量 文件 通过引入文件类型,使得我们可以定义和使用文件对象. 文件定义. 文件可以通过它所存储的内容来进行区分 type text 是字符串文件; type IntegerFileType 是整数型文件; VHDL 1987 中的文件定义 file infile: text is in “inputdata.txt” ;
E N D
提纲 • 基本input/output文件 • 测试程序(Testbenches) • ASSERT语句
文件对象 • VHDL的对象包括 • 信号 • 变量 • 常量 • 文件 • 通过引入文件类型,使得我们可以定义和使用文件对象
文件定义 • 文件可以通过它所存储的内容来进行区分 • 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”;
文件定义:二进制I/O文件(VHDL 1993) • VHDL支持read(f,value), write(f, value)和 endfile(f)操作; • VHDL 93支持File_Open()和File_Close()操作; • 直接和间接的文件打开操作;
文件定义:二进制I/O文件(VHDL 1987) • VHDL1987支持read(f,value), write(f, value)和 endfile(f)操作; • 通过文件声明来间接地进行文件打开操作;
文件定义:TEXTIO包 • 文件是按行(lines)来组织的; • Read()和write()子程序对line数据结构进行操作; • Readline()和writeline()子程序和文件进行数据交换; • 基于Text的 I/O操作; • 在STD 库的TEXTIO包中封装了全部的操作子程序 • 从行( lines )中读取和写入预定义类型数据的子程序; • 针对std_input and std_output的预定义访问操作; • 子程序名的重载(Overloaded);
文件定义:扩展TEXTIO支持其他数据类型 • 对用户隐藏TEXTIO的ASCII格式; • 针对所希望的数据类型的读和写,如, std_logic_vector ,提供类型转换子程序; • 将子程序封装在包中; • 将包( package)安装在库( library)中,然后通过use子句使库中的内容可见;
代码示例:(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
代码示例:(Bhasker95) • 读入的格式化输入行:
代码示例:(Bhasker95) • 读入该格式化输入行的程序:
代码示例:文件名的处理 • 在上面的代码中假定“input”映射到模拟器的控制台 • 通常“input”和 “output”分别映射到标准输入和标准输出
代码示例:测试程序(Testbenches) • 测试程序具有一定的通用性 • 基本策略是:施加测试激励,测量和记录响应矢量
代码示例:测试程序(Testbenches) •测试程序产生周期性的时钟信号并施加测矢量
测试激励的生成 • 定义功能测试所需的激励矢量和参考矢量 • 激励源 • 局部常数阵列 • I/O文件 • 时钟和复位信号的生成 • 通常与激励矢量相隔离 • 实现周期性的激励
测试结果的确认(Validation) • 将测试响应矢量与参考矢量相比较,并在外部文件中记录其中不匹配的部分(出错点); • 同时需要记录出错点所对应的仿真时间点; • 可能需要记录仿真状态。
断言(ASSERT) • 将测试响应矢量与参考矢量相比较,并在外部文件中记录其中不匹配的部分(出错点); • 同时需要记录出错点所对应的仿真时间点; • 可能需要记录仿真状态。
断言(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.
断言(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.
断言(ASSERT) • 设计者可以在预定义的级别上报告出错情况:NOTE,WARNING, ERROR and FAILURE (枚举类型) • 报告的参数是一个字符串,该字符串会写到仿真输出 • 断言所对应的操作是仿真器相关的 • 并行 vs. 串行断言语句 • 在不中断仿真的情况下TEXTIO比 ASSERT快
断言(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
总结 • 基本input/output • ASCII I/O和 TEXTIO package • binary I/O • VHDL 87 vs. VHDL 93 • 测试程序(Testbenches) • ASSERT语句