Guest User

Untitled

a guest
Sep 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 15.14 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(slv_reg3,slv_reg4)
  186.       begin
  187.                 data(conv_integer(slv_reg4)*32 to 31+ (conv_integer(slv_reg4)*32))  <= slv_reg3;
  188.     end process;
  189.  
  190.  
  191.  
  192.   -- input registers from filter
  193.   slv_reg8 <= x"00000001";
  194.   slv_reg9 <= (31 => '1', others => '0');
  195.  
  196.  
  197.   ------------------------------------------
  198.   -- Example code to read/write user logic slave model s/w accessible registers
  199.   --
  200.   -- Note:
  201.   -- The example code presented here is to show you one way of reading/writing
  202.   -- software accessible registers implemented in the user logic slave model.
  203.   -- Each bit of the Bus2IP_WrCE/Bus2IP_RdCE signals is configured to correspond
  204.   -- to one software accessible register by the top level template. For example,
  205.   -- if you have four 32 bit software accessible registers in the user logic,
  206.   -- you are basically operating on the following memory mapped registers:
  207.   --
  208.   --    Bus2IP_WrCE/Bus2IP_RdCE   Memory Mapped Register
  209.   --                     "1000"   C_BASEADDR + 0x0
  210.   --                     "0100"   C_BASEADDR + 0x4
  211.   --                     "0010"   C_BASEADDR + 0x8
  212.   --                     "0001"   C_BASEADDR + 0xC
  213.   --
  214.   ------------------------------------------
  215.   slv_reg_write_sel <= Bus2IP_WrCE(0 to 9);
  216.   slv_reg_read_sel  <= Bus2IP_RdCE(0 to 9);
  217.   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);
  218.   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);
  219.  
  220.   -- implement slave model software accessible register(s)
  221.   SLAVE_REG_WRITE_PROC : process( Bus2IP_Clk ) is
  222.   begin
  223.  
  224.     if Bus2IP_Clk'event and Bus2IP_Clk = '1' then
  225.       if Bus2IP_Reset = '1' then
  226.         slv_reg0 <= (others => '0');
  227.         slv_reg1 <= (others => '0');
  228.         slv_reg2 <= (others => '0');
  229.         slv_reg3 <= (others => '0');
  230.         slv_reg4 <= (others => '0');
  231.         -- slv_reg5 <= (others => '0');
  232.         -- slv_reg6 <= (others => '0');
  233.         -- slv_reg7 <= (others => '0');
  234.         -- slv_reg8 <= (others => '0');
  235.         -- slv_reg9 <= (others => '0');
  236.       else
  237.         case slv_reg_write_sel is
  238.           when "1000000000" =>
  239.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  240.               if ( Bus2IP_BE(byte_index) = '1' ) then
  241.                 slv_reg0(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  242.               end if;
  243.             end loop;
  244.           when "0100000000" =>
  245.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  246.               if ( Bus2IP_BE(byte_index) = '1' ) then
  247.                 slv_reg1(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  248.               end if;
  249.             end loop;
  250.           when "0010000000" =>
  251.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  252.               if ( Bus2IP_BE(byte_index) = '1' ) then
  253.                 slv_reg2(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  254.               end if;
  255.             end loop;
  256.           when "0001000000" =>
  257.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  258.               if ( Bus2IP_BE(byte_index) = '1' ) then
  259.                 slv_reg3(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  260.               end if;
  261.             end loop;
  262.           when "0000100000" =>
  263.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  264.               if ( Bus2IP_BE(byte_index) = '1' ) then
  265.                 slv_reg4(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  266.               end if;
  267.             end loop;
  268.           when "0000010000" =>
  269.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  270.               if ( Bus2IP_BE(byte_index) = '1' ) then
  271.                 -- slv_reg5(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  272.               end if;
  273.             end loop;
  274.           when "0000001000" =>
  275.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  276.               if ( Bus2IP_BE(byte_index) = '1' ) then
  277.                 -- slv_reg6(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  278.               end if;
  279.             end loop;
  280.           when "0000000100" =>
  281.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  282.               if ( Bus2IP_BE(byte_index) = '1' ) then
  283.                 -- slv_reg7(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  284.               end if;
  285.             end loop;
  286.           when "0000000010" =>
  287.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  288.               if ( Bus2IP_BE(byte_index) = '1' ) then
  289.                 -- slv_reg8(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  290.               end if;
  291.             end loop;
  292.           when "0000000001" =>
  293.             for byte_index in 0 to (C_SLV_DWIDTH/8)-1 loop
  294.               if ( Bus2IP_BE(byte_index) = '1' ) then
  295.                 -- slv_reg9(byte_index*8 to byte_index*8+7) <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  296.               end if;
  297.             end loop;
  298.           when others => null;
  299.         end case;
  300.       end if;
  301.     end if;
  302.  
  303.   end process SLAVE_REG_WRITE_PROC;
  304.  
  305.   -- implement slave model software accessible register(s) read mux
  306.   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
  307.   begin
  308.  
  309.     case slv_reg_read_sel is
  310.       when "1000000000" => slv_ip2bus_data <= slv_reg0;
  311.       when "0100000000" => slv_ip2bus_data <= slv_reg1;
  312.       when "0010000000" => slv_ip2bus_data <= slv_reg2;
  313.       when "0001000000" => slv_ip2bus_data <= slv_reg3;
  314.       when "0000100000" => slv_ip2bus_data <= slv_reg4;
  315.       when "0000010000" => slv_ip2bus_data <= slv_reg5;
  316.       when "0000001000" => slv_ip2bus_data <= slv_reg6;
  317.       when "0000000100" => slv_ip2bus_data <= slv_reg7;
  318.       when "0000000010" => slv_ip2bus_data <= slv_reg8;
  319.       when "0000000001" => slv_ip2bus_data <= slv_reg9;
  320.       when others => slv_ip2bus_data <= (others => '0');
  321.     end case;
  322.        
  323.    
  324.   end process SLAVE_REG_READ_PROC;
  325.  
  326.   ------------------------------------------
  327.   -- Example code to drive IP to Bus signals
  328.   ------------------------------------------
  329.   IP2Bus_Data  <= slv_ip2bus_data when slv_read_ack = '1' else
  330.                   (others => '0');
  331.  
  332.   IP2Bus_WrAck <= slv_write_ack;
  333.   IP2Bus_RdAck <= slv_read_ack;
  334.   IP2Bus_Error <= '0';
  335.  
  336. end IMP;
Add Comment
Please, Sign In to add comment