There's an issue of inferred latches on Output. This is caused by the
conditions present in the concurrent signal assignment, and are reported in synthesis. We want to avoid latches.
So with an Minimal, Complete and Verifiable Example we can modify the example to provide a combinatorial OR for all the flag1
drivers in all the processes produced by the nested for generate statements (14.5.5 Other concurrent statements Elaboration of all concurrent signal assignment statements and concurrent assertion statements consists of the construction of the equivalent process statement followed by the elaboration of the equivalent process statement.).
We also want to provide a selector to specify which outer and inner for generate loop statement specified output(j)
contributes to output
:
library ieee;
use ieee.std_logic_1164.all;
entity ex_case is
port ( output: out std_ulogic_vector(3 downto 0) );
end entity ex_case;
architecture foo of ex_case is
signal flag1: std_ulogic := '0';
constant n: natural := 4;
function reduce_or (input: std_logic_vector) return std_logic is
variable retval: std_logic;
begin -- MAY BE replace by "or" -2008, or by different reduction function
retval := '0';
for i in input'range loop
retval := retval or input(i);
end loop;
return retval;
end function;
function firstflag (iflag: std_logic_vector) return integer is
begin
for i in iflag'range loop
if To_bit(iflag(i)) = '1' then
return i;
end if;
end loop;
return iflag'LEFT; -- This will park on iflag' when no flag is set
end function;
signal iflag: std_logic_vector(0 to n - 1);
subtype iflag_subtype is std_logic_vector(iflag'range);
begin
loop1:
for j in 0 to n - 1 generate
type output_array is array (0 to n - 1) of std_logic;
signal ioutput: output_array;
signal jselect: natural range 0 to n - 1;
begin
-- flag1 <= '0'; -- REMOVED -- reset the flag, same as output_ready
loop2:
for i in 0 to n - 1 generate
signal iflag: std_logic_vector (0 to n - 1);
begin
ioutput(j) <= '1' when i >= j and iflag(j) = '0' else
'0';
iflag(i) <= '1' when i >= j else
'0'; -- output when valid data is available
iflag(j) <= reduce_or(iflag);
end generate loop2;
output(j) <= ioutput(firstflag(iflag)); -- A Multiplexer
end generate loop1;
flag1 <= '1' when iflag /= iflag_subtype'(others => '0') else
'0';
end architecture foo;
This analyzes, elaborates and simulates (while doing nothing impressive but demonstrating there's only one source for any particular output).
Note you can switch output back to type std_logic_vector, along with adding your address of output ports of your n x n switch as a condition for assigning flag and output to a '1'.
You might imagine depending on the packages you have available or the revision of the VHDL standard your tool chain supports it might be possible to eliminate function reduce_or instead using a pre-existing function or the unary "or" operator (-2008).
Without also having the address of the output port as a condition this example can't be thoroughly tested.
Output(j)
and n x n concurrent signal assignments toflag
. See IEEE Std 1076-2008 11.8 Generate statements, 14.5.3 Generate statements, 14.5.2 Block statements, 14.5.5 Other concurrent statements Elaboration of all concurrent signal assignment statements and concurrent assertion statements consists of the construction of the equivalent process statement followed by the elaboration of the equivalent process statement. You have multiple processes driving Output(j) and flag. Provide an MCVE.