Guest
I have lack of consistency with my FSM code.
If the input condition in state "idle" is "if data="1101" then", the
state imediately changes to "write_fifo" and sets wr_fifo_en to '1'.
However, if in state "idle" and the input condition is "if
frame_mrk='1' then", the state changes one clock later to "write_fifo"
and sets wr_fifo_en to '1'.
Why is there is a delay with frame_mrk ? When does the input that you
are testing affect the variable assignment of state ?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.all;
entity RX_FIFO_WR_CONTROL is
Port ( data_clk : in STD_LOGIC;
data:in STD_LOGIC_VECTOR (3 downto 0);
frame_mrk : in STD_LOGIC;
rxdv: in STD_LOGIC;
fifo_full : in STD_LOGIC;
frame_good: in STD_LOGIC;
frame_bad: in STD_LOGIC;
fifo_wr_data: out STD_LOGIC_VECTOR (4 downto 0);
wr_fifo_en : out STD_LOGIC;
rst: in STD_LOGIC;
prog_full_thresh: out std_logic_VECTOR(10 downto 0));
end RX_FIFO_WR_CONTROL;
architecture RTL of RX_FIFO_WR_CONTROL is
signal ovr_flow: std_logic;
begin
prog_full_thresh<="11111111110";
-- FSM
process (data_clk,rst)
type fifo_cntrl_state is
(idle,write_fifo,over_flow,wait_end,read_frame_condition,write_frame_status);
variable state:fifo_cntrl_state;
begin
if rst='1' then
state:=idle;
ovr_flow<='0';
wr_fifo_en<='0';
fifo_wr_data<="00000";
elsif rising_edge(data_clk) then
case state is
when idle =>
if frame_mrk='1' then
--if data="1101" then
state:=write_fifo;
else
state:=idle;
end if;
when write_fifo =>
if frame_mrk='0' then
state:= wait_end;
elsif fifo_full='1' then
state:= over_flow;
else
state:=write_fifo;
end if;
when over_flow=>
state:=wait_end;
when wait_end =>
if rxdv='0' then
state:=read_frame_condition;
else
state:=wait_end;
end if;
when read_frame_condition =>
state:=write_frame_status;
when write_frame_status =>
state:=idle;
when others =>
state:= idle;
end case;
case state is
when idle=>
ovr_flow<='0';
wr_fifo_en<='0';
fifo_wr_data(3 downto 0)<="0000";
fifo_wr_data(4)<='0';
when write_fifo=>
ovr_flow<='0';
wr_fifo_en<='1';
fifo_wr_data(3 downto 0)<=data;
fifo_wr_data(4)<='1';
when over_flow=>
fifo_wr_data(3 downto 0)<=data;
fifo_wr_data(4)<='0';
ovr_flow<='1';
wr_fifo_en<='0';
when wait_end=>
fifo_wr_data(3 downto 0)<="0000";
fifo_wr_data(4)<='0';
wr_fifo_en<='0';
when read_frame_condition=>
wr_fifo_en<='0';
when write_frame_status=>
fifo_wr_data(4)<='0';
fifo_wr_data(3)<=ovr_flow;
fifo_wr_data(2)<=frame_good;
fifo_wr_data(1)<=frame_bad;
fifo_wr_data(0)<='0';
wr_fifo_en<='1';
ovr_flow<='0';
when others=>
ovr_flow<='0';
wr_fifo_en<='0';
fifo_wr_data(3 downto 0)<=data;
fifo_wr_data(4)<='0';
end case;
end if;
end process;
end RTL;
Cheers
Maurizio Gencarelli
Defence &Technology Organisation Salisbury
Australia
If the input condition in state "idle" is "if data="1101" then", the
state imediately changes to "write_fifo" and sets wr_fifo_en to '1'.
However, if in state "idle" and the input condition is "if
frame_mrk='1' then", the state changes one clock later to "write_fifo"
and sets wr_fifo_en to '1'.
Why is there is a delay with frame_mrk ? When does the input that you
are testing affect the variable assignment of state ?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.all;
entity RX_FIFO_WR_CONTROL is
Port ( data_clk : in STD_LOGIC;
data:in STD_LOGIC_VECTOR (3 downto 0);
frame_mrk : in STD_LOGIC;
rxdv: in STD_LOGIC;
fifo_full : in STD_LOGIC;
frame_good: in STD_LOGIC;
frame_bad: in STD_LOGIC;
fifo_wr_data: out STD_LOGIC_VECTOR (4 downto 0);
wr_fifo_en : out STD_LOGIC;
rst: in STD_LOGIC;
prog_full_thresh: out std_logic_VECTOR(10 downto 0));
end RX_FIFO_WR_CONTROL;
architecture RTL of RX_FIFO_WR_CONTROL is
signal ovr_flow: std_logic;
begin
prog_full_thresh<="11111111110";
-- FSM
process (data_clk,rst)
type fifo_cntrl_state is
(idle,write_fifo,over_flow,wait_end,read_frame_condition,write_frame_status);
variable state:fifo_cntrl_state;
begin
if rst='1' then
state:=idle;
ovr_flow<='0';
wr_fifo_en<='0';
fifo_wr_data<="00000";
elsif rising_edge(data_clk) then
case state is
when idle =>
if frame_mrk='1' then
--if data="1101" then
state:=write_fifo;
else
state:=idle;
end if;
when write_fifo =>
if frame_mrk='0' then
state:= wait_end;
elsif fifo_full='1' then
state:= over_flow;
else
state:=write_fifo;
end if;
when over_flow=>
state:=wait_end;
when wait_end =>
if rxdv='0' then
state:=read_frame_condition;
else
state:=wait_end;
end if;
when read_frame_condition =>
state:=write_frame_status;
when write_frame_status =>
state:=idle;
when others =>
state:= idle;
end case;
case state is
when idle=>
ovr_flow<='0';
wr_fifo_en<='0';
fifo_wr_data(3 downto 0)<="0000";
fifo_wr_data(4)<='0';
when write_fifo=>
ovr_flow<='0';
wr_fifo_en<='1';
fifo_wr_data(3 downto 0)<=data;
fifo_wr_data(4)<='1';
when over_flow=>
fifo_wr_data(3 downto 0)<=data;
fifo_wr_data(4)<='0';
ovr_flow<='1';
wr_fifo_en<='0';
when wait_end=>
fifo_wr_data(3 downto 0)<="0000";
fifo_wr_data(4)<='0';
wr_fifo_en<='0';
when read_frame_condition=>
wr_fifo_en<='0';
when write_frame_status=>
fifo_wr_data(4)<='0';
fifo_wr_data(3)<=ovr_flow;
fifo_wr_data(2)<=frame_good;
fifo_wr_data(1)<=frame_bad;
fifo_wr_data(0)<='0';
wr_fifo_en<='1';
ovr_flow<='0';
when others=>
ovr_flow<='0';
wr_fifo_en<='0';
fifo_wr_data(3 downto 0)<=data;
fifo_wr_data(4)<='0';
end case;
end if;
end process;
end RTL;
Cheers
Maurizio Gencarelli
Defence &Technology Organisation Salisbury
Australia