This is my first time posting, so I will try to be as more specific as I can.
In the part of the code that I am going to post, I am trying to implement in a generic way the code in the "Case"-expression that I have commented out. This code, is part of a bigger implementation and I have only kept the signals that are currently in use in this code.
So the thing is that I want my outputs "kin" and "din" to be generic and in accordance to what comes as input in the address bus "bus_a", the correct words (2-byte long) of the registers "kin_2" and "din_2" should be filled with the value of the "bus_di" input at that time.
For my example here, I am going to use the original lengths for "kin" and "din", which are 128-bit each. So for 128-bit length, N=16 (16*8-bit = 128bit) and K=8.
library IEEE;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_1164.ALL;
entity stck_if is
generic (N: integer:=16; K: integer:=8);
port ( -------------- Clock and Reset
clk: in std_logic;
rst: in std_logic;
bus_a: in std_logic_vector (15 downto 0); -- Address
bus_di: in std_logic_vector (15 downto 0); --Data In
kin: out std_logic_vector (8*N-1 downto 0);
din: out std_logic_vector (8*N-1 downto 0));
end stck_if;
architecture stck_if_arch of stck_if is
signal kin_2: std_logic_vector (8*N-1 downto 0);
signal din_2: std_logic_vector (8*N-1 downto 0);
signal encdec_2: std_logic;
signal trig_wr: std_logic;
begin
proc1: process(clk,rst)
variable int_add: integer:=0;
variable add: std_logic_vector (15 downto 0);
variable bit_add: std_logic_vector (15 downto 0);
begin
if rst='1' then
encdec_2<='0';
kin_2<=(others =>'0');
din_2<=(others =>'0');
elsif (clk'event and clk='1') then
if (trig_wr = '1') then
if (bus_a = "0000000000001100") then
encdec_2 <= bus_di(0);
end if;
for i in 0 to K-1 loop
bit_add:="0000000100000000";
int_add:= 2*i;
add:=std_logic_vector(to_unsigned(int_add, 16));
bit_add:= std_logic_vector(unsigned(bit_add) + unsigned(add));
if (bus_a = bit_add) then
kin_2((8*(N-int_add)-1) downto 8*(N-int_add)) <= bus_di;
end if;
end loop;
for i in 0 to K-1 loop
bit_add:="0000000101000000";
int_add:= 2*i;
add:=std_logic_vector(to_unsigned(int_add, 16));
bit_add:= std_logic_vector(unsigned(bit_add) + unsigned(add));
if (bus_a = bit_add) then
din_2((8*(N-int_add)-1) downto 8*(N-int_add)) <= bus_di;
end if;
end loop;
--case bus_a is
-- when "0000000000001100"=> encdec_2 <= bus_di(0); --bus_a = 000C hex
-- when "0000000100000000"=> kin_2(127 downto 112) <= bus_di; --bus_a = 0100 hex
-- when "0000000100000010"=> kin_2(111 downto 96) <= bus_di; --bus_a = 0102 hex
-- when "0000000100000100"=> kin_2(95 downto 80) <= bus_di; --bus_a = 0104 hex
-- when "0000000100000110"=> kin_2(79 downto 64) <= bus_di; --bus_a = 0106 hex
-- when "0000000100001000"=> kin_2(63 downto 48) <= bus_di; --bus_a = 0108 hex
-- when "0000000100001010"=> kin_2(47 downto 32) <= bus_di; --bus_a = 010A hex
-- when "0000000100001100"=> kin_2(31 downto 16) <= bus_di; --bus_a = 010C hex
-- when "0000000100001110"=> kin_2(15 downto 0) <= bus_di; --bus_a = 010E hex
-- when "0000000101000000"=> din_2(127 downto 112) <= bus_di; --bus_a = 0140 hex
-- when "0000000101000010"=> din_2(111 downto 96) <= bus_di; --bus_a = 0142 hex
-- when "0000000101000100"=> din_2(95 downto 80) <= bus_di; --bus_a = 0144 hex
-- when "0000000101000110"=> din_2(79 downto 64) <= bus_di; --bus_a = 0146 hex
-- when "0000000101001000"=> din_2(63 downto 48) <= bus_di; --bus_a = 0148 hex
-- when "0000000101001010"=> din_2(47 downto 32) <= bus_di; --bus_a = 014A hex
-- when "0000000101001100"=> din_2(31 downto 16) <= bus_di; --bus_a = 014C hex
-- when "0000000101001110"=> din_2(15 downto 0) <= bus_di; --bus_a = 014E hex
-- when others => null;
--end case;
end if;
end if;
end process;
kin <= kin_2;
din <= din_2;
end stck_if_arch;
I am using ModelSim PE Student Edition 10.4a. In order to simulate the operation of the implementation, I use the following code at the command line of ModelSim:
restart -f
//clock period 20ns
force -freeze sim:/stck_if/clk 1 0, 0 {10 ns} -r 20
//Activate reset
force -freeze sim:/stck_if/rst 1 0
run
//activate wr
force -freeze sim:/stck_if/trig_wr 1 0
force -freeze sim:/stck_if/rst 0 0
run
force -freeze sim:/stck_if/bus_a 16'h0100 0
force -freeze sim:/stck_if/bus_di 16'h1111 0
run
run
force -freeze sim:/stck_if/bus_a 16'h0102 0
run
run
force -freeze sim:/stck_if/bus_a 16'h0104 0
run
run
force -freeze sim:/stck_if/bus_a 16'h0106 0
run
run
force -freeze sim:/stck_if/bus_a 16'h0108 0
run
run
etc.
Although the code is compiling without giving any error, during simulation ModelSim gives the following error:
- Cannot continue because of fatal error. HDL call sequence: Stopped at C:/Modeltech_pe_edu_10.4a/examples/stack.vhd 53 ForLoop loop
From what I understand, the problem is in the use of "For Loop" and from what I assume, it must be that VHDL cannot translate the following expression:
kin_2((8*(N-int_add)-1) downto 8*(N-int_add)) <= bus_di;
into an actual circuit.
Am I right with my hypothesis? Any ideas of how to overcome this problem, or any suggestions on where I should look/read to find my answers, would be really helpfull!