通用的bitlip模块

时间:2014-04-29 23:57:29

标签: vhdl digital-logic

我想实现一个通用的bitlip模块。下面是我想要为4和8做的一个例子。我无法弄清楚如何编写代码以便我可以传递一些通用的N,代码将使用for循环或其他东西自动生成。

---- 4-bitslip
bits_slipped <= 
           bits_in(3 downto 0)                       when tap_sel = "00" else
           bits_in(2 downto 0) & bits_in(3)          when tap_sel = "01" else
           bits_in(1 downto 0) & bits_in(3 downto 2) when tap_sel = "10" else
           bits_in(0)          & bits_in(3 downto 1) when tap_sel = "11";

-- 8-bitslip
bits_slipped <= 
           bits_in(7 downto 0)                       when tap_sel = "000" else
           bits_in(6 downto 0) & bits_in(7)          when tap_sel = "001" else
           bits_in(5 downto 0) & bits_in(7 downto 6) when tap_sel = "010" else
           bits_in(4 downto 0) & bits_in(7 downto 5) when tap_sel = "011" else            
           bits_in(3 downto 0) & bits_in(7 downto 4) when tap_sel = "100" else
           bits_in(2 downto 0) & bits_in(7 downto 3) when tap_sel = "101" else
           bits_in(1 downto 0) & bits_in(7 downto 2) when tap_sel = "110" else               
           bits_in(0)          & bits_in(7 downto 1) when tap_sel = "111"; 

-- N-bitslip ????

1 个答案:

答案 0 :(得分:2)

您可以使用rotate_right()中的numeric_std功能。通过在端口上使用无约束信号,您可以在没有通用的情况下使这个工作适用于任何大小。如果需要,可以添加泛型以强制bits_in匹配bits_slipped的大小。

library ieee;
ise ieee.std_logic_1164.all;
use ieee.numeric_std.all;
...

port (
  bits_in : in unsigned;
  tap_sel : in unsigned;
  bits_slipped : out unsigned -- Must be same length as bits_in
);
...

bits_slipped <= rotate_right(bits_in, to_integer(tap_sel));