exjobb-public/src/fifo_buffer/fifo_deserializer.vhd

63 lines
1.5 KiB
VHDL

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.MATH_REAL.all;
use ieee.numeric_std.all;
entity fifo_deserializer is
generic (
output_width : natural := 8;
input_width : natural := 8
);
port (
rst, clk : in std_logic;
ready_in : in std_logic;
ready_out : out std_logic;
valid_in : in std_logic;
valid_out : out std_logic;
data_in : in std_logic_vector(input_width - 1 downto 0);
data_out : out std_logic_vector(output_width - 1 downto 0)
);
end entity fifo_deserializer;
architecture rtl of fifo_deserializer is
constant out_over_in : natural := output_width / input_width;
type state_t is record
count : integer;
data : std_logic_vector(output_width - 1 downto 0);
end record state_t;
signal st : state_t;
begin
comb_proc: process(rst,clk,valid_in,ready_in,data_in,st)
begin
if st.count = out_over_in then
valid_out <= '1';
else
valid_out <= '0';
end if;
if not (st.count = out_over_in) and ready_in = '1' then
ready_out <= '1';
else
ready_out <= '0';
end if;
data_out <= st.data;
end process comb_proc;
seq_proc: process(clk, rst)
begin
if rst = '1' then
st.count <= 0;
st.data <= (others => '0');
elsif (rising_edge(clk)) then
if st.count = out_over_in then
st.count <= 0;
elsif valid_in = '1' and ready_in = '1' then
st.count <= st.count + 1;
st.data((st.count + 1) * input_width - 1 downto st.count * input_width) <= data_in;
end if;
end if;
end process seq_proc;
end architecture rtl;