集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2029|回复: 0

编写高效的测试设计(testbenches)---8

[复制链接]
CCIE 发表于 2010-6-26 01:36:55 | 显示全部楼层 |阅读模式
本帖最后由 fpgaw 于 2011-8-17 13:41 编辑

VHDL例程
  以下是相当设计的VHDL测试文件,分别细分到独立的过程。
   
  Stimulus : process
  procedure addr_wr (address: in std_logic_vector(31 downto 0)) is
  begin
  data_addr_n <= ‘0’;
  we_rn <= ‘1’;
  ad <= address;
  end addr_wr;
  procedure data_wr (data_in: in std_logic_vector(31 downto 0 )) is
  begin
  data_addr_n <= ‘1’;
  we_rn <= ‘1’;
  ad <= data_in;
  end data_wr;
  procedure addr_rd (address: in std_logic_vector(31 downto 0)) is
  begin
  data_addr_n <= ‘0’;
  we_rn <= ‘0’;
  ad <= address;
  end addr_rd;
  procedure data_rd (data_in: in std_logic_vector(31 downto 0)) is
  begin
  data_addr_n <= ‘1’;
  we_rn <= ‘0’;
  ad <= data_in;
  end data_rd;
  procedure nop is
  begin
  data_addr_n <= ‘1’;
  we_rn = ‘0’;
  ad = ‘Z’;
  end nop;
  begin
  nop ; -- Nop
  wait for 200 ns;
  addr_wr (16#20340400#); -- Precharge, load Controller MR
  wait for 8 ns;
  data_wr (16#0704a076#); -- value for Controller MR
  wait for 8 ns;
  nop ; -- Nop
  wait for 40 ns;
  addr_wr (16#38000000#); -- Auto Refresh
  wait for 8 ns;
  data_wr (16#00000000#);
  wait for 8 ns;
  nop ; -- Nop
  ..
  ..
   
   
  细分激励到独立的任务使得激励很容易实现,也使得代码的可读性更好。
   
  在仿真时控制双向信号
  多数设计使用双向信号,在测试设计中必须区别对待双向信号和单向信号。
   
  VHDL示例
   
  The following is a VHDL bi-directional signal example:
  以下是一个vhdl描述的双向信号示例
   
  Library IEEE;
  use IEEE.STD_LOGIC_1164.all;
  use IEEE.STD_LOGIC_UNSIGNED.all;
  entity bidir_infer is
  port (DATA : inout STD_LOGIC_VECTOR(1 downto 0);
  READ_WRITE : in STD_LOGIC);
  end bidir_infer;
  architecture XILINX of bidir_infer is
  signal LATCH_OUT : STD_LOGIC_VECTOR(1 downto 0);
  begin
  process(READ_WRITE, DATA)
  begin
  if (READ_WRITE = ’1’) then
  LATCH_OUT <= DATA;
  end if;
  end process;
  process(READ_WRITE, LATCH_OUT)
  begin
  if (READ_WRITE = ’0’) then
  DATA(0) <= LATCH_OUT(0) and LATCH_OUT(1);
  DATA(1) <= LATCH_OUT(0) or LATCH_OUT(1);
  else
  DATA(0) <= ’Z’;
  DATA(1) <= ’Z’;
  end if;
  end process;
  end XILINX;
   
  为访问上例中的双向的DATA信号,一个测试可以设置如下:
   
  library ieee;
  use ieee.std_logic_1164.all;
  Entity testbench is
  End testbench;
  Architecture test_bidir of testbench is
  Component bidir_infer
  port (DATA : inout STD_LOGIC_VECTOR(1 downto 0);
  READ_WRITE : in STD_LOGIC);
  end component;
  signal read_writet: std_logic;
  signal datat, data_top : std_logic_vector(1 downto 0);
  begin
  datat <= data_top when (Read_writet = ’1’) else (others => ’Z’);
  data_top <= datat when (Read_writet = ’0’) else (others => ’Z’);
  uut : bidir_infer port map (datat, read_writet);
  process begin
  read_writet <= ’1’;
  data_top <= "10";
  wait for 50 ns;
  read_writet <= ’0’;
  wait;
  end process;
  end test_bidir;
   
  双向总线由测试台控制,双向总线的值可以通过数据顶层信号来访问。
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2024-12-24 00:00 , Processed in 0.057918 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表