erikwikt
Junior Member level 1
As the title says, can someone please explain to me why 2 is subtracted from dmaSectorCount on line 83?
Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.ALL;
entity Command_DMA_read is
port (
clk : in std_logic;
reset : in std_logic;
din : in std_logic_vector(31 downto 0);
dout : out std_logic_vector(31 downto 0);
sector : in std_logic_vector(15 downto 0);
data_avl : in std_logic;
enw : out std_logic;
enr : out std_logic
);
end Command_DMA_read;
architecture behaviour of Command_DMA_read is
constant iterationLimit : unsigned(6 downto 0) := "1111111";
type states is (S0, S1, S2, S4, S5);
signal state, next_state : states;
begin -- behaviour
STATE_TRANS: process (clk, reset)
begin -- process STATE_TRANS
if reset = '1' then
state <= S0;
elsif rising_edge(clk) then
state <= next_state;
end if;
end process STATE_TRANS;
NEXTSTATEGEN: process(state, data_avl)
variable dmaIterator : unsigned((iterationLimit'length) downto 0);
variable dmaSectorCount : unsigned((sector'length - 1) downto 0);
begin
case state is
when S0 =>
dout <= (others => '0');
enw <= '0';
enr <= '0';
dmaIterator := (others => '0');
next_state <= S5;
when S1 =>
if dmaSectorCount = X"0000" then
next_state <= S2;
elsif data_avl = '1' then
if dmaIterator = iterationLimit then
enw <= '1';
enr <= '1';
dmaIterator := dmaIterator;
next_state <= S4;
else
enw <= '1';
enr <= '1';
dmaIterator := dmaIterator + 1;
next_state <= S1;
end if;
else
enw <= '0';
enr <= '1';
dmaIterator := dmaIterator;
next_state <= S1;
end if;
when S2 =>
enw <= '0';
enr <= '0';
next_state <= S2;
when S4 =>
enw <= '0';
enr <= '0';
dmaIterator := (others => '0');
dmaSectorCount := dmaSectorCount - 1;
next_state <= S1;
when S5 =>
dmaSectorCount := unsigned(sector);
next_state <= S1;
when others =>
next_state <= S0;
end case;
end process NEXTSTATEGEN;
end behaviour;