I want to implement a generic bitslip module. Below is an example of what I want to do for 4 and 8. I cannot figure out how to write code so I can pass some generic N and the code will be generated automatically using for loops or something.
---- 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 ????
You can use the rotate_right()
function from numeric_std
. You can make this work for any size without a generic by just using unconstrained signals on a port. If you want, a generic can be added to force bits_in to match the size of 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));