0

我正在为 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. 一点点
  2. 它(128位信号)
4

2 回答 2

0

您的代码有更多的问题,而不仅仅是 case 语句。

我希望这能帮到您:

--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;

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

于 2014-04-18T13:42:31.007 回答
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 周期排序的任何问题。当您想要表示信号的准确时序但保证您不必以与预期不同的顺序处理事件时与模拟引擎搏斗时,这样做并不总是合适的。绝对不要在可综合的代码中这样做(除非你正在试验多米诺逻辑)。

于 2014-04-18T15:36:33.070 回答