Guest User

Untitled

a guest
Sep 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 15.26 KB | None | 0 0
  1. ------------------------------------------------------------------------------
  2. -- user_logic.vhd - entity/architecture pair
  3. ------------------------------------------------------------------------------
  4. --
  5. -- ***************************************************************************
  6. -- ** Copyright (c) 1995-2011 Xilinx, Inc.  All rights reserved.            **
  7. -- **                                                                       **
  8. -- ** Xilinx, Inc.                                                          **
  9. -- ** XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"         **
  10. -- ** AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND       **
  11. -- ** SOLUTIONS FOR XILINX DEVICES.  BY PROVIDING THIS DESIGN, CODE,        **
  12. -- ** OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,        **
  13. -- ** APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION           **
  14. -- ** THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,     **
  15. -- ** AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE      **
  16. -- ** FOR YOUR IMPLEMENTATION.  XILINX EXPRESSLY DISCLAIMS ANY              **
  17. -- ** WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE               **
  18. -- ** IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR        **
  19. -- ** REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF       **
  20. -- ** INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS       **
  21. -- ** FOR A PARTICULAR PURPOSE.                                             **
  22. -- **                                                                       **
  23. -- ***************************************************************************
  24. --
  25. ------------------------------------------------------------------------------
  26. -- Filename:          user_logic.vhd
  27. -- Version:           1.00.a
  28. -- Description:       User logic.
  29. -- Date:              Sat Jul 14 13:39:25 2012 (by Create and Import Peripheral Wizard)
  30. -- VHDL Standard:     VHDL'93
  31. ------------------------------------------------------------------------------
  32. -- Naming Conventions:
  33. --   active low signals:                    "*_n"
  34. --   clock signals:                         "clk", "clk_div#", "clk_#x"
  35. --   reset signals:                         "rst", "rst_n"
  36. --   generics:                              "C_*"
  37. --   user defined types:                    "*_TYPE"
  38. --   state machine next state:              "*_ns"
  39. --   state machine current state:           "*_cs"
  40. --   combinatorial signals:                 "*_com"
  41. --   pipelined or register delay signals:   "*_d#"
  42. --   counter signals:                       "*cnt*"
  43. --   clock enable signals:                  "*_ce"
  44. --   internal version of output port:       "*_i"
  45. --   device pins:                           "*_pin"
  46. --   ports:                                 "- Names begin with Uppercase"
  47. --   processes:                             "*_PROCESS"
  48. --   component instantiations:              "<ENTITY_>I_<#|FUNC>"
  49. ------------------------------------------------------------------------------
  50.  
  51. -- DO NOT EDIT BELOW THIS LINE --------------------
  52. library ieee;
  53. use ieee.std_logic_1164.all;
  54. use ieee.std_logic_arith.all;
  55. use ieee.std_logic_unsigned.all;
  56.  
  57. library proc_common_v3_00_a;
  58. use proc_common_v3_00_a.proc_common_pkg.all;
  59.  
  60. -- DO NOT EDIT ABOVE THIS LINE --------------------
  61. library filter_if_v1_00_a;
  62. use filter_if_v1_00_a.filtre;
  63. use filter_if_v1_00_a.filter_pkg.all;
  64.  
  65.  
  66. --USER libraries added here
  67.  
  68. ------------------------------------------------------------------------------
  69. -- Entity section
  70. ------------------------------------------------------------------------------
  71. -- Definition of Generics:
  72. --   C_SLV_DWIDTH                 -- Slave interface data bus width
  73. --   C_NUM_REG                    -- Number of software accessible registers
  74. --
  75. -- Definition of Ports:
  76. --   Bus2IP_Clk                   -- Bus to IP clock
  77. --   Bus2IP_Reset                 -- Bus to IP reset
  78. --   Bus2IP_Data                  -- Bus to IP data bus
  79. --   Bus2IP_BE                    -- Bus to IP byte enables
  80. --   Bus2IP_RdCE                  -- Bus to IP read chip enable
  81. --   Bus2IP_WrCE                  -- Bus to IP write chip enable
  82. --   IP2Bus_Data                  -- IP to Bus data bus
  83. --   IP2Bus_RdAck                 -- IP to Bus read transfer acknowledgement
  84. --   IP2Bus_WrAck                 -- IP to Bus write transfer acknowledgement
  85. --   IP2Bus_Error                 -- IP to Bus error response
  86. ------------------------------------------------------------------------------
  87.  
  88. entity user_logic is
  89.   generic
  90.   (
  91.     -- ADD USER GENERICS BELOW THIS LINE ---------------
  92.     --USER generics added here
  93.     -- ADD USER GENERICS ABOVE THIS LINE ---------------
  94.  
  95.     -- DO NOT EDIT BELOW THIS LINE ---------------------
  96.     -- Bus protocol parameters, do not add to or delete
  97.     C_SLV_DWIDTH                   : integer              := 32;
  98.     C_NUM_REG                      : integer              := 10
  99.     -- DO NOT EDIT ABOVE THIS LINE ---------------------
  100.   );
  101.   port
  102.   (
  103.     -- ADD USER PORTS BELOW THIS LINE ------------------
  104.  
  105.   -- ADD USER PORTS ABOVE THIS LINE ------------------
  106.  
  107.     -- DO NOT EDIT BELOW THIS LINE ---------------------
  108.     -- Bus protocol ports, do not add to or delete
  109.     Bus2IP_Clk                     : in  std_logic;
  110.     Bus2IP_Reset                   : in  std_logic;
  111.     Bus2IP_Data                    : in  std_logic_vector(0 to C_SLV_DWIDTH-1);
  112.     Bus2IP_BE                      : in  std_logic_vector(0 to C_SLV_DWIDTH/8-1);
  113.     Bus2IP_RdCE                    : in  std_logic_vector(0 to C_NUM_REG-1);
  114.     Bus2IP_WrCE                    : in  std_logic_vector(0 to C_NUM_REG-1);
  115.     IP2Bus_Data                    : out std_logic_vector(0 to C_SLV_DWIDTH-1);
  116.     IP2Bus_RdAck                   : out std_logic;
  117.     IP2Bus_WrAck                   : out std_logic;
  118.     IP2Bus_Error                   : out std_logic
  119.     -- DO NOT EDIT ABOVE THIS LINE ---------------------
  120.   );
  121.  
  122.   attribute MAX_FANOUT : string;
  123.   attribute SIGIS : string;
  124.  
  125.   attribute SIGIS of Bus2IP_Clk    : signal is "CLK";
  126.   attribute SIGIS of Bus2IP_Reset  : signal is "RST";
  127.  
  128. end entity user_logic;
  129.  
  130. ------------------------------------------------------------------------------
  131. -- Architecture section
  132. ------------------------------------------------------------------------------
  133.  
  134. architecture IMP of user_logic is
  135.  
  136.   --USER signal declarations added here, as needed for user logic
  137.  
  138. component filtre
  139. port(reset_n : in std_logic;
  140.     clk   : in std_logic;
  141.     p_val : in std_logic;
  142.     q_val : in std_logic;  
  143.     idata : in std_logic_vector(max_msg_bits-1 downto 0);
  144.     ram_out: out std_logic_vector(2**num_hash_bits-1 downto 0);
  145.     match  : out std_logic;
  146.     t_ready  : out std_logic
  147.       );    
  148. end component;
  149.  
  150.   ------------------------------------------
  151.   -- Signals for user logic slave model s/w accessible register example
  152.   ------------------------------------------
  153.   signal slv_reg0                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  154.   signal slv_reg1                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  155.   signal slv_reg2                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  156.   signal slv_reg3                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  157.   signal slv_reg4                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  158.   signal slv_reg5                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  159.   signal slv_reg6                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  160.   signal slv_reg7                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  161.   signal slv_reg8                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  162.   signal slv_reg9                       : std_logic_vector(0 to C_SLV_DWIDTH-1);
  163.   signal slv_reg_write_sel              : std_logic_vector(0 to 9);
  164.   signal slv_reg_read_sel               : std_logic_vector(0 to 9);
  165.   signal slv_ip2bus_data                : std_logic_vector(0 to C_SLV_DWIDTH-1);
  166.   signal slv_read_ack                   : std_logic;
  167.   signal slv_write_ack                  : std_logic;
  168.   signal data                           : std_logic_vector(0 to max_msg_bits-1);
  169. begin
  170.  
  171.  -- USER logic implementation added here
  172.  
  173.      
  174.       filtre_INST: entity filter_if_v1_00_a.filtre
  175.    port map (
  176.       reset_n => not(Bus2IP_Reset),
  177.       clk     => Bus2IP_Clk,
  178.       p_val   => slv_reg1(31),
  179.       q_val   => slv_reg2(31),
  180.       idata   => data,
  181.       ram_out => slv_reg7,
  182.       match   => slv_reg5(31),
  183.       t_ready => slv_reg6(31));
  184.      
  185.     process(Bus2IP_Clk)
  186.      
  187.       begin
  188.         if Bus2IP_Clk'event and Bus2IP_Clk = '1' then
  189.             if conv_integer(slv_reg4) < (max_msg_bits/32) then
  190.                 data(conv_integer(slv_reg4)*32 to 31+ (conv_integer(slv_reg4)*32))  <= slv_reg3;
  191.             end if;
  192.         end if;    
  193.     end process;
  194.  
  195.  
  196.  
  197.   -- input registers from filter
  198.   slv_reg8 <= x"00000001";
  199.   slv_reg9 <= (31 => '1', others => '0');
  200.  
  201.  
  202.   ------------------------------------------
  203.   -- Example code to read/write user logic slave model s/w accessible registers
  204.   --
  205.   -- Note:
  206.   -- The example code presented here is to show you one way of reading/writing
  207.   -- software accessible registers implemented in the user logic slave model.
  208.   -- Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond
  209.   -- to one software accessible register by the top level template. For example,
  210.   -- if you have four 32 bit software accessible registers in the user logic,
  211.   -- you are basically operating on the following memory mapped registers:
  212.   --
  213.   --    Bus2IP_WrCE/Bus2IP_RdCE   Memory Mapped Register
  214.   --                     "1000"   C_BASEADDR + 0x0
  215.   --                     "0100"   C_BASEADDR + 0x4
  216.   --                     "0010"   C_BASEADDR + 0x8
  217.   --                     "0001"   C_BASEADDR + 0xC
  218.   --
  219.   ------------------------------------------
  220.   slv_reg_write_sel <= Bus2IP_WrCE(0 to 9);
  221.   slv_reg_read_sel  <= Bus2IP_RdCE(0 to 9);
  222.   slv_write_ack     <= Bus2IP_WrCE(0) or Bus2IP_WrCE(1) or Bus2IP_WrCE(2) or Bus2IP_WrCE(3) or Bus2IP_WrCE(4) or Bus2IP_WrCE(5) or Bus2IP_WrCE(6) or Bus2IP_WrCE(7) or Bus2IP_WrCE(8) or Bus2IP_WrCE(9);
  223.   slv_read_ack      <= Bus2IP_RdCE(0) or Bus2IP_RdCE(1) or Bus2IP_RdCE(2) or Bus2IP_RdCE(3) or Bus2IP_RdCE(4) or Bus2IP_RdCE(5) or Bus2IP_RdCE(6) or Bus2IP_RdCE(7) or Bus2IP_RdCE(8) or Bus2IP_RdCE(9);
  224.  
  225.   -- implement slave model software accessible register(s)
  226.   SLAVE_REG_WRITE_PROC : process( Bus2IP_Clk ) is
  227.   begin
  228.  
  229.     if Bus2IP_Clk'event and Bus2IP_Clk = '1' then
  230.       if Bus2IP_Reset = '1' then
  231.         slv_reg0 <= (others => '0');
  232.         slv_reg1 <= (others => '0');
  233.         slv_reg2 <= (others => '0');
  234.         slv_reg3 <= (others => '0');
  235.         slv_reg4 <= (others => '0');
  236.         -- slv_reg5 <= (others => '0');
  237.         -- slv_reg6 <= (others => '0');
  238.         -- slv_reg7 <= (others => '0');
  239.         -- slv_reg8 <= (others => '0');
  240.         -- slv_reg9 <= (others => '0');
  241.       else
  242.         case slv_reg_write_sel is
  243.           when "1000000000" =>
  244.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  245.               if ( Bus2IP_BE(byte_index) = '1' ) then
  246.                 slv_reg0(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  247.               end if;
  248.             end loop;
  249.           when "0100000000" =>
  250.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  251.               if ( Bus2IP_BE(byte_index) = '1' ) then
  252.                 slv_reg1(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  253.               end if;
  254.             end loop;
  255.           when "0010000000" =>
  256.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  257.               if ( Bus2IP_BE(byte_index) = '1' ) then
  258.                 slv_reg2(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  259.               end if;
  260.             end loop;
  261.           when "0001000000" =>
  262.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  263.               if ( Bus2IP_BE(byte_index) = '1' ) then
  264.                 slv_reg3(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  265.               end if;
  266.             end loop;
  267.           when "0000100000" =>
  268.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  269.               if ( Bus2IP_BE(byte_index) = '1' ) then
  270.                 slv_reg4(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  271.               end if;
  272.             end loop;
  273.           when "0000010000" =>
  274.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  275.               if ( Bus2IP_BE(byte_index) = '1' ) then
  276.                 -- slv_reg5(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  277.               end if;
  278.             end loop;
  279.           when "0000001000" =>
  280.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  281.               if ( Bus2IP_BE(byte_index) = '1' ) then
  282.                 -- slv_reg6(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  283.               end if;
  284.             end loop;
  285.           when "0000000100" =>
  286.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  287.               if ( Bus2IP_BE(byte_index) = '1' ) then
  288.                 -- slv_reg7(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  289.               end if;
  290.             end loop;
  291.           when "0000000010" =>
  292.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  293.               if ( Bus2IP_BE(byte_index) = '1' ) then
  294.                 -- slv_reg8(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  295.               end if;
  296.             end loop;
  297.           when "0000000001" =>
  298.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  299.               if ( Bus2IP_BE(byte_index) = '1' ) then
  300.                 -- slv_reg9(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  301.               end if;
  302.             end loop;
  303.           when others => null;
  304.         end case;
  305.       end if;
  306.     end if;
  307.  
  308.   end process SLAVE_REG_WRITE_PROC;
  309.  
  310.   -- implement slave model software accessible register(s) read mux
  311.   SLAVE_REG_READ_PROC : process( slv_reg_read_sel, slv_reg0, slv_reg1, slv_reg2, slv_reg3, slv_reg4, slv_reg5, slv_reg6, slv_reg7, slv_reg8, slv_reg9 ) is
  312.   begin
  313.  
  314.     case slv_reg_read_sel is
  315.       when "1000000000" => slv_ip2bus_data <= slv_reg0;
  316.       when "0100000000" => slv_ip2bus_data <= slv_reg1;
  317.       when "0010000000" => slv_ip2bus_data <= slv_reg2;
  318.       when "0001000000" => slv_ip2bus_data <= slv_reg3;
  319.       when "0000100000" => slv_ip2bus_data <= slv_reg4;
  320.       when "0000010000" => slv_ip2bus_data <= slv_reg5;
  321.       when "0000001000" => slv_ip2bus_data <= slv_reg6;
  322.       when "0000000100" => slv_ip2bus_data <= slv_reg7;
  323.       when "0000000010" => slv_ip2bus_data <= slv_reg8;
  324.       when "0000000001" => slv_ip2bus_data <= slv_reg9;
  325.       when others => slv_ip2bus_data <= (others => '0');
  326.     end case;
  327.        
  328.    
  329.   end process SLAVE_REG_READ_PROC;
  330.  
  331.   ------------------------------------------
  332.   -- Example code to drive IP to Bus signals
  333.   ------------------------------------------
  334.   IP2Bus_Data  <= slv_ip2bus_data when slv_read_ack = '1' else
  335.                   (others => '0');
  336.  
  337.   IP2Bus_WrAck <= slv_write_ack;
  338.   IP2Bus_RdAck <= slv_read_ack;
  339.   IP2Bus_Error <= '0';
  340.  
  341. end IMP;
Add Comment
Please, Sign In to add comment