1
votes

I am realizing a N-bit Barrel Shifter.

Here it is my component:

entity barrel_shifter is
    Generic ( N : integer := 4);
    Port ( data_in : in  STD_LOGIC_VECTOR (N-1 downto 0);
           shift : in  STD_LOGIC_VECTOR (integer(ceil(log2(real(N))))-1 downto 0); -- log2 of N => number of inputs for the shift
           data_out : out  STD_LOGIC_VECTOR (N-1 downto 0));
end barrel_shifter;

For my purpose I've created an N-bit multiplexer too, and this is its code:

entity mux is
    Generic ( N : integer := 4);
    Port ( data_in : in  STD_LOGIC_VECTOR (N-1 downto 0);
           sel : in  STD_LOGIC_VECTOR (integer(ceil(log2(real(N))))-1 downto 0); -- log2 of N => number of inputs for the shift
           data_out : out  STD_LOGIC);
end mux;

architecture Behavioral of mux is

begin
    data_out <= data_in(to_integer(unsigned(sel)));
end Behavioral;

Now to realize a Circular Barrel Shifter I need to connect these N multiplexer in different ways. You can find an example here, page 2, figure 1. As you can see IN0 is connected only one time to the D0 multiplexer input. The next time IN0 is connected to the D1 multiplexer input, and so on... (it's the same logic for the other inputs)

But how can I realize in VHDL something like that? If I hadn't STD_LOGIC_VECTOR as input it would be easy, but I need to make a generic Barrel Shifter (with generic map construct), so I can't manually connect each wire because I don't know the value of the generic N.

In my barrel_shifter entity I tried this:

architecture Structural of barrel_shifter is

    signal q : STD_LOGIC_VECTOR (N-1 downto 0);

begin

    connections: for i in 0 to N-1 generate
        mux: entity work.mux(Behavioral) generic map(N) port map(std_logic_vector(unsigned(data_in) srl 1), shift, q(i));
    end generate connections;

    data_out <= q;

end Structural;

But it simply doesn't work ("Actual, result of operator, associated with Formal Signal, Signal 'data_in', is not a Signal. (LRM 2.1.1)"). I've tried using variable and signals, like this:

data_tmp := data_in(i downto 0) & data_in(N-i downto 1);

But I still couldn't figure out the right way to do these connections.

1

1 Answers

2
votes

Which tool is reporting this?

Xilinx XST reports

barrel_shifter.vhd" Line 20: Actual for formal port data_in is neither a static 
name nor a globally static expression

which helps pin down the problem as the expression std_logic_vector(unsigned(data_in) srl 1) mapped to data_in on the mux. Declaring a temporary signal

architecture Structural of barrel_shifter is

    signal q    : STD_LOGIC_VECTOR (N-1 downto 0);
    signal temp : STD_LOGIC_VECTOR (N-1 downto 0);
begin

    temp <= std_logic_vector(unsigned(data_in) srl 1);

    connections: for i in 0 to N-1 generate
        mux: entity work.mux(Behavioral) generic map(N) 
                                         port map(temp, shift, q(i));
    end generate connections;
    ...
end

resolves the problem.