Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 11.57 KB | None | 0 0
  1. ------------------------------------------------------------------------------
  2. -- user_logic.vhd - entity/architecture pair
  3. ------------------------------------------------------------------------------
  4. --
  5. -- ***************************************************************************
  6. -- ** Copyright (c) 1995-2010 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:              Sun Oct 31 21:24:20 2010 (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.  
  62. --USER libraries added here
  63.  
  64. ------------------------------------------------------------------------------
  65. -- Entity section
  66. ------------------------------------------------------------------------------
  67. -- Definition of Generics:
  68. --   C_SLV_AWIDTH                 -- Slave interface address bus width
  69. --   C_SLV_DWIDTH                 -- Slave interface data bus width
  70. --   C_NUM_MEM                    -- Number of memory spaces
  71. --
  72. -- Definition of Ports:
  73. --   Bus2IP_Clk                   -- Bus to IP clock
  74. --   Bus2IP_Reset                 -- Bus to IP reset
  75. --   Bus2IP_Addr                  -- Bus to IP address bus
  76. --   Bus2IP_CS                    -- Bus to IP chip select for user logic memory selection
  77. --   Bus2IP_RNW                   -- Bus to IP read/not write
  78. --   Bus2IP_Data                  -- Bus to IP data bus
  79. --   Bus2IP_BE                    -- Bus to IP byte enables
  80. --   Bus2IP_Burst                 -- Bus to IP burst-mode qualifier
  81. --   Bus2IP_BurstLength           -- Bus to IP burst length
  82. --   Bus2IP_RdReq                 -- Bus to IP read request
  83. --   Bus2IP_WrReq                 -- Bus to IP write request
  84. --   IP2Bus_AddrAck               -- IP to Bus address acknowledgement
  85. --   IP2Bus_Data                  -- IP to Bus data bus
  86. --   IP2Bus_RdAck                 -- IP to Bus read transfer acknowledgement
  87. --   IP2Bus_WrAck                 -- IP to Bus write transfer acknowledgement
  88. --   IP2Bus_Error                 -- IP to Bus error response
  89. ------------------------------------------------------------------------------
  90.  
  91. entity user_logic is
  92.   generic
  93.   (
  94.     -- ADD USER GENERICS BELOW THIS LINE ---------------
  95.     --USER generics added here
  96.     -- ADD USER GENERICS ABOVE THIS LINE ---------------
  97.  
  98.     -- DO NOT EDIT BELOW THIS LINE ---------------------
  99.     -- Bus protocol parameters, do not add to or delete
  100.     C_SLV_AWIDTH                   : integer              := 32;
  101.     C_SLV_DWIDTH                   : integer              := 32;
  102.     C_NUM_MEM                      : integer              := 2
  103.     -- DO NOT EDIT ABOVE THIS LINE ---------------------
  104.   );
  105.   port
  106.   (
  107.     -- ADD USER PORTS BELOW THIS LINE ------------------
  108.     --USER ports added here
  109.     -- ADD USER PORTS ABOVE THIS LINE ------------------
  110.  
  111.     -- DO NOT EDIT BELOW THIS LINE ---------------------
  112.     -- Bus protocol ports, do not add to or delete
  113.     Bus2IP_Clk                     : in  std_logic;
  114.     Bus2IP_Reset                   : in  std_logic;
  115.     Bus2IP_Addr                    : in  std_logic_vector(0 to C_SLV_AWIDTH-1);
  116.     Bus2IP_CS                      : in  std_logic_vector(0 to C_NUM_MEM-1);
  117.     Bus2IP_RNW                     : in  std_logic;
  118.     Bus2IP_Data                    : in  std_logic_vector(0 to C_SLV_DWIDTH-1);
  119.     Bus2IP_BE                      : in  std_logic_vector(0 to C_SLV_DWIDTH/8-1);
  120.     Bus2IP_Burst                   : in  std_logic;
  121.     Bus2IP_BurstLength             : in  std_logic_vector(0 to 8);
  122.     Bus2IP_RdReq                   : in  std_logic;
  123.     Bus2IP_WrReq                   : in  std_logic;
  124.     IP2Bus_AddrAck                 : out std_logic;
  125.     IP2Bus_Data                    : out std_logic_vector(0 to C_SLV_DWIDTH-1);
  126.     IP2Bus_RdAck                   : out std_logic;
  127.     IP2Bus_WrAck                   : out std_logic;
  128.     IP2Bus_Error                   : out std_logic
  129.     -- DO NOT EDIT ABOVE THIS LINE ---------------------
  130.   );
  131.  
  132.   attribute SIGIS : string;
  133.   attribute SIGIS of Bus2IP_Clk    : signal is "CLK";
  134.   attribute SIGIS of Bus2IP_Reset  : signal is "RST";
  135.  
  136. end entity user_logic;
  137.  
  138. ------------------------------------------------------------------------------
  139. -- Architecture section
  140. ------------------------------------------------------------------------------
  141.  
  142. architecture IMP of user_logic is
  143.  
  144.   --USER signal declarations added here, as needed for user logic
  145.  
  146.   ------------------------------------------
  147.   -- Signals for user logic memory space example
  148.   ------------------------------------------
  149.   type BYTE_RAM_TYPE is array (0 to 255) of std_logic_vector(0 to 7);
  150.   type DO_TYPE is array (0 to C_NUM_MEM-1) of std_logic_vector(0 to C_SLV_DWIDTH-1);
  151.   signal mem_data_out                   : DO_TYPE;
  152.   signal mem_address                    : std_logic_vector(0 to 7);
  153.   signal mem_select                     : std_logic_vector(0 to 1);
  154.   signal mem_read_enable                : std_logic;
  155.   signal mem_ip2bus_data                : std_logic_vector(0 to C_SLV_DWIDTH-1);
  156.   signal mem_read_ack_dly1              : std_logic;
  157.   signal mem_read_ack                   : std_logic;
  158.   signal mem_write_ack                  : std_logic;
  159.  
  160. begin
  161.  
  162.   --USER logic implementation added here
  163.  
  164.   ------------------------------------------
  165.   -- Example code to access user logic memory region
  166.   --
  167.   -- Note:
  168.   -- The example code presented here is to show you one way of using
  169.   -- the user logic memory space features. The Bus2IP_Addr, Bus2IP_CS,
  170.   -- and Bus2IP_RNW IPIC signals are dedicated to these user logic
  171.   -- memory spaces. Each user logic memory space has its own address
  172.   -- range and is allocated one bit on the Bus2IP_CS signal to indicated
  173.   -- selection of that memory space. Typically these user logic memory
  174.   -- spaces are used to implement memory controller type cores, but it
  175.   -- can also be used in cores that need to access additional address space
  176.   -- (non C_BASEADDR based), s.t. bridges. This code snippet infers
  177.   -- 2 256x64-bit (byte accessible) single-port Block RAM by XST.
  178.   ------------------------------------------
  179.   mem_select      <= Bus2IP_CS;
  180.   mem_read_enable <= ( Bus2IP_CS(0) or Bus2IP_CS(1) ) and Bus2IP_RdReq;
  181.   mem_read_ack    <= mem_read_ack_dly1;
  182.   mem_write_ack   <= ( Bus2IP_CS(0) or Bus2IP_CS(1) ) and Bus2IP_WrReq;
  183.   mem_address     <= Bus2IP_Addr(C_SLV_AWIDTH-11 to C_SLV_AWIDTH-4);
  184.  
  185.   -- this process generates the read acknowledge 1 clock after read enable
  186.   -- is presented to the BRAM block. The BRAM block has a 1 clock delay
  187.   -- from read enable to data out.
  188.   BRAM_RD_ACK_PROC : process( Bus2IP_Clk ) is
  189.   begin
  190.  
  191.     if ( Bus2IP_Clk'event and Bus2IP_Clk = '1' ) then
  192.       if ( Bus2IP_Reset = '1' ) then
  193.         mem_read_ack_dly1 <= '0';
  194.       else
  195.         mem_read_ack_dly1 <= mem_read_enable;
  196.       end if;
  197.     end if;
  198.  
  199.   end process BRAM_RD_ACK_PROC;
  200.  
  201.   -- implement Block RAM(s)
  202.   BRAM_GEN : for i in 0 to C_NUM_MEM-1 generate
  203.     constant NUM_BYTE_LANES : integer := (C_SLV_DWIDTH+7)/8;
  204.   begin
  205.  
  206.     BYTE_BRAM_GEN : for byte_index in 0 to NUM_BYTE_LANES-1 generate
  207.       signal ram           : BYTE_RAM_TYPE;
  208.       signal write_enable  : std_logic;
  209.       signal data_in       : std_logic_vector(0 to 7);
  210.       signal data_out      : std_logic_vector(0 to 7);
  211.       signal read_address  : std_logic_vector(0 to 7);
  212.     begin
  213.  
  214.       write_enable <= not(Bus2IP_RNW) and
  215.                       Bus2IP_CS(i) and
  216.                       Bus2IP_BE(byte_index);
  217.  
  218.       data_in <= Bus2IP_Data(byte_index*8 to byte_index*8+7);
  219.       mem_data_out(i)(byte_index*8 to byte_index*8+7) <= data_out;
  220.  
  221.       BYTE_RAM_PROC : process( Bus2IP_Clk ) is
  222.       begin
  223.  
  224.         if ( Bus2IP_Clk'event and Bus2IP_Clk = '1' ) then
  225.           if ( write_enable = '1' ) then
  226.             ram(CONV_INTEGER(mem_address)) <= data_in;
  227.           end if;
  228.           read_address <= mem_address;
  229.         end if;
  230.  
  231.       end process BYTE_RAM_PROC;
  232.  
  233.       data_out <= ram(CONV_INTEGER(read_address));
  234.  
  235.     end generate BYTE_BRAM_GEN;
  236.  
  237.   end generate BRAM_GEN;
  238.  
  239.   -- implement Block RAM read mux
  240.   MEM_IP2BUS_DATA_PROC : process( mem_data_out, mem_select ) is
  241.   begin
  242.  
  243.     case mem_select is
  244.       when "10" => mem_ip2bus_data <= mem_data_out(0);
  245.       when "01" => mem_ip2bus_data <= mem_data_out(1);
  246.       when others => mem_ip2bus_data <= (others => '0');
  247.     end case;
  248.  
  249.   end process MEM_IP2BUS_DATA_PROC;
  250.  
  251.   ------------------------------------------
  252.   -- Example code to drive IP to Bus signals
  253.   ------------------------------------------
  254.   IP2Bus_Data  <= mem_ip2bus_data when mem_read_ack = '1' else
  255.                   (others => '0');
  256.  
  257.   IP2Bus_AddrAck <= mem_write_ack or mem_read_enable;
  258.   IP2Bus_WrAck <= mem_write_ack;
  259.   IP2Bus_RdAck <= mem_read_ack;
  260.   IP2Bus_Error <= '0';
  261.  
  262. end IMP;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement