Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_arith.all;
- use ieee.std_logic_misc.all;
- use ieee.std_logic_unsigned.all;
- -- Uncomment the following library declaration if using
- -- arithmetic functions with Signed or Unsigned values
- --use IEEE.NUMERIC_STD.ALL;
- -- Uncomment the following library declaration if instantiating
- -- any Xilinx leaf cells in this code.
- --library UNISIM;
- --use UNISIM.VComponents.all;
- entity hamming_decoder is
- Port (
- clk_i : in std_logic;
- rst_i : in std_logic;
- -- inputs
- dat_i : in std_logic_vector(15 downto 0);
- vld_i : in std_logic;
- rdy_o : out std_logic;
- -- outputs
- dat_o : out std_logic_vector(15 downto 0);
- vld_o : out std_logic;
- rdy_i : in std_logic
- );
- end hamming_decoder;
- architecture Behavioral of hamming_decoder is
- --HAMMING
- --CONSTANT
- constant MAX_COUNT : integer := 1;
- --RECEIVE SIG
- signal data_buf : std_logic_vector (31 downto 0);
- signal count_data : integer range 0 to MAX_COUNT;
- --TRANSMIT SIG
- signal buf_zero : std_logic_vector (15 downto 0);
- --TYPE
- type decoder_type is (RECEIVE_DATA, DECRYPTION, SENDING_DATA);
- signal decoder_state: decoder_type;
- begin
- RECEIVE_PROC : process (clk_i, rst_i)
- begin
- if rst_i = '1' then
- data_buf <= (others =>'0');
- decoder_state <= RECEIVE_DATA;
- rdy_o <= '0';
- dat_o <= (others =>'0');
- vld_o <= '0';
- buf_zero <= (others =>'0');
- elsif rising_edge(clk_i) then
- case decoder_state is
- when RECEIVE_DATA =>
- rdy_o <= '1';
- if vld_i = '1' then
- data_buf <= data_buf(15 downto 0) & dat_i;
- if count_data = MAX_COUNT then
- count_data <= 0;
- decoder_state <= DECRYPTION;
- rdy_o <= '0';
- else
- count_data <= count_data + 1;
- end if;
- end if;
- when DECRYPTION =>
- decoder_state <= SENDING_DATA;
- when SENDING_DATA =>
- vld_o <= '1';
- if rdy_i = '1' then
- data_buf <= data_buf(15 downto 0) & buf_zero;
- dat_o <= data_buf(31 downto 16);
- if count_data = MAX_COUNT then
- count_data <= 0;
- decoder_state <= RECEIVE_DATA;
- rdy_o <= '0';
- vld_o <= '0';
- else
- count_data <= count_data + 1;
- end if;
- end if;
- end case;
- end if;
- end process;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement