如何在v / hdl编程的测试平台上以不同的时钟周期写入输入值?

时间:2014-04-18 09:29:14

标签: vhdl xilinx spartan

我正在为AES加密算法编写vhdl代码,我必须采用128位数据来加密所用的1位输入引脚。对于128位数据,我使用了128个时钟周期和case语句。我必须编写测试平台来检查代码的正常工作。如何在测试平台上以不同的时钟周期写入128位数据。

if(clk'event and clk = '1') then
    count <= count + 1;
    end if;
    end process;        
    process(count,a)
begin
 case count is
 when 0 =>
    it(127)<=a;
    when 1 =>
    it(126)<=a;
    when 2 =>
    it(125)<=a;
    when 3 =>
    it(124)<=a;
    when 4 =>
    it(123)<=a;
    when 5 =>
    it(122)<=a;
    when 6 =>
    it(121)<=a;
    when 7 =>
    it(120)<=a;    .... n go for 0th bit
  1. a in bit
  2. 它(128位信号)

2 个答案:

答案 0 :(得分:0)

您的代码存在的问题远多于案例陈述。

我希望这会对你有所帮助:

--very important this signal should be an integer
signal count : integer range 0 to 127;
signal it    : std_logic_vector (127 downto 0);

begin
process count (clk,reset)
begin
  if (reset = '1') then
    count <= 0;
    it <= (others=>(others=>'0'));
  elsif (rising_edge(clk)) then
    count <= count + 1;
    it(count) <= a; 
  end if;
end process;

在不同的过程中编写计数更好。 我无法在这里测试我的代码,希望每一个想法都是正确的。

答案 1 :(得分:0)

您希望实现移位寄存器以串行方式提供数据。通常,您应该仅将case语句用于控制逻辑而不是数据流。将数据矢量作为可寻址阵列处理也是可能的,但它会合成一个解码器,这将成为这种尺寸的时序问题,并不是将位移动到位所必需的。

signal data : std_logic_vector(127 downto 0);
...
sreg: process(clock, reset)
begin
  if reset = '1' then
    data <= (others => '0');
  elsif rising_edge(clock) then
    if shift_en = '1' then
      data <= data(126 downto 0) & a; -- Shift left
      -- data <= a & data(127 downto 1); -- Shift right
    end if;
  end if;
end process;

您必须决定如何控制填充移位寄存器时的操作。要么实现一个计数器来计算128个移位,要么使用另一个控制信号,在完成移位时开始下一个处理阶段。

在测试平台方面,您可以更灵活地驱动信号,因为不需要考虑合成结果。您通常有两种选择:编写与DUT类似的同步过程,或使用等待语句来管理信令的顺序,而无需实现可合成代码中所需的同步机制。

constant CPERIOD : delay_length := 10 ns;
...
stim: process is
  variable data : std_logic_vector(127 downto 0);
begin
  -- Initialize signal drivers
  a <= '0';
  shift_en <= '0';
  reset <= '1', '0' after CPERIOD * 2;
  wait until falling_edge(clock);
  wait for CPERIOD * 2;

  data := X"CAFEBABECAFED00D8BADFOODDEADBEEF";

  -- Shift data in from left to right
  shift_en <= '1';
  for i in data'range loop
    a <= data(i);
    wait for CPERIOD;
  end loop;
  shift_en <= '0';
  wait for CPERIOD;

  wait; -- Stop process from restarting
end process;

注意:在时钟的下降沿驱动激励是一种懒惰技术,当您在与接收器相同的边缘上行驶时,可以避免任何与delta周期排序有关的问题。当您想要表示信号的准确定时时,这并不总是合适的,但保证您不必以与预期不同的顺序与模拟引擎处理事件搏斗。绝对不能用可综合的代码(除非你正在尝试使用多米诺骨牌逻辑)。