Guest User

Untitled

a guest
Sep 9th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.28 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    20:31:22 07/07/2012
  6. -- Design Name:
  7. -- Module Name:    filtre - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.std_logic_unsigned.all;
  23. use IEEE.numeric_std.all;
  24.  
  25. use work.filter_pkg.all;
  26.  
  27.  
  28. entity filtre is
  29.  
  30.     port(reset_n : in std_logic;
  31.           clk   : in std_logic;
  32.           btn   : in std_logic;
  33.           p_val : in std_logic;
  34.           q_val : in std_logic;  
  35.           idata : in std_logic_vector(max_msg_bits-1 downto 0);
  36.           leds  : out std_logic_vector(7 downto 0)
  37.           );
  38.      
  39. end filtre;
  40.  
  41. architecture Behavioral of filtre is
  42.  
  43. signal ram : std_logic_vector(2**num_hash_bits-1 downto 0);
  44. signal match : std_logic;
  45.  
  46. -- ran_sig
  47. signal ran_sig : hash_array;
  48.  
  49. -- H3 signals
  50. signal h3_data_in : std_logic_vector(max_msg_bits-1 downto 0);
  51. signal h3_data_out : hash_o_array;
  52.  
  53. -- lfsr signals
  54.  
  55. signal lfsr_rdv : std_logic_vector (num_hash_bits-1 downto 0);
  56.  
  57. -- H3 component declaration
  58. component h3
  59. generic ( index : integer;
  60.             rnd_v : hash_array
  61.             );
  62. port (
  63.       data_in  : in std_logic_vector(max_msg_bits-1 downto 0);
  64.         data_out : out std_logic_vector(num_hash_bits-1 downto 0)
  65.         );
  66.    
  67. end component;
  68.  
  69. -- lfsr component declaration
  70.  
  71. component lfsr
  72.     generic (random_num_length : integer);
  73.     port (
  74.           clk : in std_logic;
  75.           random_num : out std_logic_vector (num_hash_bits-1 downto 0)   --output vector            
  76.         );
  77. end component;
  78.  
  79. begin
  80.  
  81. --process(btn)
  82. --begin
  83. --if (btn= '1') then
  84. --  leds <= ram(7 downto 0);
  85. --else
  86. --  leds <= ram (15 downto 8);
  87. --end if;
  88. --end process;
  89.  
  90. --leds <= "0000" & h3_data_out;
  91. leds <= "0000000" & match;
  92. h3_data_in <= x"00" & idata(7 downto 0);
  93.  
  94. -- H3 instantiation
  95. h_func: for i in 0 to num_hash_functions-1 generate
  96.  
  97.  h3_inst : h3
  98.     generic map(
  99.             index => i,
  100.             rnd_v => ran_sig
  101.             )
  102. port map(
  103.     data_in => h3_data_in,
  104.     data_out => h3_data_out(i));
  105.        
  106. end generate h_func;
  107.  
  108. -- lfsr instantiation
  109. lfsr_inst : lfsr
  110.     generic map (
  111.             random_num_length => num_hash_bits
  112.                     )
  113.     port map (
  114.             clk => clk,
  115.             random_num => lfsr_rdv
  116.             );
  117.  
  118.    
  119.      
  120. process (clk, reset_n)
  121. variable match_int :std_logic;
  122. begin
  123. if reset_n = '0' then
  124.     ram <= (others => '0');
  125.     match <= '0';
  126.  
  127. elsif rising_edge(clk) then
  128.    for k in 0 to num_hash_functions-1 loop
  129.         for  b in 0 to  max_msg_length-1 loop  -- loop on the 8 bits of input byte
  130.             for  i in 0 to  7 loop  -- loop on the 8 bits of input byte
  131.                 ran_sig(k)(b)(i) <=  lfsr_rdv ;
  132.             end loop ;
  133.         end loop;
  134.     end loop;  
  135.     if (p_val ='1') then
  136.         for i in 0 to num_hash_functions-1 loop
  137.             ram(to_integer(unsigned(h3_data_out(i)))) <= '1';
  138.         end loop;
  139.        
  140.     elsif (q_val ='1') then
  141.         match_int := '1';
  142.         for i in 0 to num_hash_functions-1 loop
  143.             match_int := match_int and ram(to_integer(unsigned(h3_data_out(i))));
  144.         end loop;
  145.         match <= match_int;
  146.     end if;
  147.    
  148. end if;    
  149. end process;  
  150.  
  151. end Behavioral;
Add Comment
Please, Sign In to add comment