]> rtime.felk.cvut.cz Git - fpga/zynq/canbench-sw.git/blob - system/ip/spi_leds_and_enc_1.0/hdl/spi_leds_and_enc_v1_0_S00_AXI.vhd
microzed_apo: Correct JX1_LVDS_21_N pin assignment on FPGA_IO header.
[fpga/zynq/canbench-sw.git] / system / ip / spi_leds_and_enc_1.0 / hdl / spi_leds_and_enc_v1_0_S00_AXI.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4
5 entity spi_leds_and_enc_v1_0_S00_AXI is
6         generic (
7                 -- Users to add parameters here
8
9                 -- User parameters ends
10                 -- Do not modify the parameters beyond this line
11
12                 -- Width of S_AXI data bus
13                 C_S_AXI_DATA_WIDTH      : integer       := 32;
14                 -- Width of S_AXI address bus
15                 C_S_AXI_ADDR_WIDTH      : integer       := 6
16         );
17         port (
18                 -- Users to add ports here
19
20                 output_led_line : out std_logic_vector(31 downto 0);
21                 output_led_rgb1 : out std_logic_vector(23 downto 0);
22                 output_led_rgb2 : out std_logic_vector(23 downto 0);
23                 output_led_direct : out std_logic_vector(7 downto 0);
24                 output_kbd_direct : out std_logic_vector(3 downto 0);
25
26                 in_enc_direct : in std_logic_vector(8 downto 0);
27                 in_kbd_direct : in std_logic_vector(3 downto 0);
28                 in_enc_8bit : in std_logic_vector(23 downto 0);
29                 in_enc_buttons : in std_logic_vector(2 downto 0);
30
31                 -- User ports ends
32                 -- Do not modify the ports beyond this line
33
34                 -- Global Clock Signal
35                 S_AXI_ACLK      : in std_logic;
36                 -- Global Reset Signal. This Signal is Active LOW
37                 S_AXI_ARESETN   : in std_logic;
38                 -- Write address (issued by master, acceped by Slave)
39                 S_AXI_AWADDR    : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
40                 -- Write channel Protection type. This signal indicates the
41                 -- privilege and security level of the transaction, and whether
42                 -- the transaction is a data access or an instruction access.
43                 S_AXI_AWPROT    : in std_logic_vector(2 downto 0);
44                 -- Write address valid. This signal indicates that the master signaling
45                 -- valid write address and control information.
46                 S_AXI_AWVALID   : in std_logic;
47                 -- Write address ready. This signal indicates that the slave is ready
48                 -- to accept an address and associated control signals.
49                 S_AXI_AWREADY   : out std_logic;
50                 -- Write data (issued by master, acceped by Slave)
51                 S_AXI_WDATA     : in std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
52                 -- Write strobes. This signal indicates which byte lanes hold
53                 -- valid data. There is one write strobe bit for each eight
54                 -- bits of the write data bus.
55                 S_AXI_WSTRB     : in std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0);
56                 -- Write valid. This signal indicates that valid write
57                 -- data and strobes are available.
58                 S_AXI_WVALID    : in std_logic;
59                 -- Write ready. This signal indicates that the slave
60                 -- can accept the write data.
61                 S_AXI_WREADY    : out std_logic;
62                 -- Write response. This signal indicates the status
63                 -- of the write transaction.
64                 S_AXI_BRESP     : out std_logic_vector(1 downto 0);
65                 -- Write response valid. This signal indicates that the channel
66                 -- is signaling a valid write response.
67                 S_AXI_BVALID    : out std_logic;
68                 -- Response ready. This signal indicates that the master
69                 -- can accept a write response.
70                 S_AXI_BREADY    : in std_logic;
71                 -- Read address (issued by master, acceped by Slave)
72                 S_AXI_ARADDR    : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
73                 -- Protection type. This signal indicates the privilege
74                 -- and security level of the transaction, and whether the
75                 -- transaction is a data access or an instruction access.
76                 S_AXI_ARPROT    : in std_logic_vector(2 downto 0);
77                 -- Read address valid. This signal indicates that the channel
78                 -- is signaling valid read address and control information.
79                 S_AXI_ARVALID   : in std_logic;
80                 -- Read address ready. This signal indicates that the slave is
81                 -- ready to accept an address and associated control signals.
82                 S_AXI_ARREADY   : out std_logic;
83                 -- Read data (issued by slave)
84                 S_AXI_RDATA     : out std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
85                 -- Read response. This signal indicates the status of the
86                 -- read transfer.
87                 S_AXI_RRESP     : out std_logic_vector(1 downto 0);
88                 -- Read valid. This signal indicates that the channel is
89                 -- signaling the required read data.
90                 S_AXI_RVALID    : out std_logic;
91                 -- Read ready. This signal indicates that the master can
92                 -- accept the read data and response information.
93                 S_AXI_RREADY    : in std_logic
94         );
95 end spi_leds_and_enc_v1_0_S00_AXI;
96
97 architecture arch_imp of spi_leds_and_enc_v1_0_S00_AXI is
98
99         -- AXI4LITE signals
100         signal axi_awaddr       : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
101         signal axi_awready      : std_logic;
102         signal axi_wready       : std_logic;
103         signal axi_bresp        : std_logic_vector(1 downto 0);
104         signal axi_bvalid       : std_logic;
105         signal axi_araddr       : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
106         signal axi_arready      : std_logic;
107         signal axi_rdata        : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
108         signal axi_rresp        : std_logic_vector(1 downto 0);
109         signal axi_rvalid       : std_logic;
110
111         -- Example-specific design signals
112         -- local parameter for addressing 32 bit / 64 bit C_S_AXI_DATA_WIDTH
113         -- ADDR_LSB is used for addressing 32/64 bit registers/memories
114         -- ADDR_LSB = 2 for 32 bits (n downto 2)
115         -- ADDR_LSB = 3 for 64 bits (n downto 3)
116         constant ADDR_LSB  : integer := (C_S_AXI_DATA_WIDTH/32)+ 1;
117         constant OPT_MEM_ADDR_BITS : integer := 3;
118         ------------------------------------------------
119         ---- Signals for user logic register space example
120         --------------------------------------------------
121         ---- Number of Slave Registers 16
122         signal slv_reg0 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
123         signal slv_reg1 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
124         signal slv_reg2 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
125         signal slv_reg3 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
126         signal slv_reg4 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
127         signal slv_reg5 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
128         signal slv_reg6 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
129         signal slv_reg7 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
130         signal slv_reg8 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
131         signal slv_reg9 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
132         signal slv_reg10        :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
133         signal slv_reg11        :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
134         signal slv_reg12        :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
135         signal slv_reg13        :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
136         signal slv_reg14        :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
137         signal slv_reg15        :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
138         signal slv_reg_rden     : std_logic;
139         signal slv_reg_wren     : std_logic;
140         signal reg_data_out     :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
141         signal byte_index       : integer;
142
143 begin
144         -- I/O Connections assignments
145
146         S_AXI_AWREADY   <= axi_awready;
147         S_AXI_WREADY    <= axi_wready;
148         S_AXI_BRESP     <= axi_bresp;
149         S_AXI_BVALID    <= axi_bvalid;
150         S_AXI_ARREADY   <= axi_arready;
151         S_AXI_RDATA     <= axi_rdata;
152         S_AXI_RRESP     <= axi_rresp;
153         S_AXI_RVALID    <= axi_rvalid;
154         -- Implement axi_awready generation
155         -- axi_awready is asserted for one S_AXI_ACLK clock cycle when both
156         -- S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_awready is
157         -- de-asserted when reset is low.
158
159         process (S_AXI_ACLK)
160         begin
161           if rising_edge(S_AXI_ACLK) then
162             if S_AXI_ARESETN = '0' then
163               axi_awready <= '0';
164             else
165               if (axi_awready = '0' and S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') then
166                 -- slave is ready to accept write address when
167                 -- there is a valid write address and write data
168                 -- on the write address and data bus. This design
169                 -- expects no outstanding transactions.
170                 axi_awready <= '1';
171               else
172                 axi_awready <= '0';
173               end if;
174             end if;
175           end if;
176         end process;
177
178         -- Implement axi_awaddr latching
179         -- This process is used to latch the address when both
180         -- S_AXI_AWVALID and S_AXI_WVALID are valid.
181
182         process (S_AXI_ACLK)
183         begin
184           if rising_edge(S_AXI_ACLK) then
185             if S_AXI_ARESETN = '0' then
186               axi_awaddr <= (others => '0');
187             else
188               if (axi_awready = '0' and S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') then
189                 -- Write Address latching
190                 axi_awaddr <= S_AXI_AWADDR;
191               end if;
192             end if;
193           end if;
194         end process;
195
196         -- Implement axi_wready generation
197         -- axi_wready is asserted for one S_AXI_ACLK clock cycle when both
198         -- S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_wready is
199         -- de-asserted when reset is low.
200
201         process (S_AXI_ACLK)
202         begin
203           if rising_edge(S_AXI_ACLK) then
204             if S_AXI_ARESETN = '0' then
205               axi_wready <= '0';
206             else
207               if (axi_wready = '0' and S_AXI_WVALID = '1' and S_AXI_AWVALID = '1') then
208                   -- slave is ready to accept write data when
209                   -- there is a valid write address and write data
210                   -- on the write address and data bus. This design
211                   -- expects no outstanding transactions.
212                   axi_wready <= '1';
213               else
214                 axi_wready <= '0';
215               end if;
216             end if;
217           end if;
218         end process;
219
220         -- Implement memory mapped register select and write logic generation
221         -- The write data is accepted and written to memory mapped registers when
222         -- axi_awready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted. Write strobes are used to
223         -- select byte enables of slave registers while writing.
224         -- These registers are cleared when reset (active low) is applied.
225         -- Slave register write enable is asserted when valid address and data are available
226         -- and the slave is ready to accept the write address and write data.
227         slv_reg_wren <= axi_wready and S_AXI_WVALID and axi_awready and S_AXI_AWVALID ;
228
229         process (S_AXI_ACLK)
230         variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
231         begin
232           if rising_edge(S_AXI_ACLK) then
233             if S_AXI_ARESETN = '0' then
234               slv_reg0 <= (others => '0');
235               slv_reg1 <= (others => '0');
236               slv_reg2 <= (others => '0');
237               slv_reg3 <= (others => '0');
238               slv_reg4 <= (others => '0');
239               slv_reg5 <= (others => '0');
240               slv_reg6 <= (others => '0');
241               slv_reg7 <= (others => '0');
242               -- slv_reg8 <= (others => '0');
243               -- slv_reg9 <= (others => '0');
244               slv_reg10 <= (others => '0');
245               slv_reg11 <= (others => '0');
246               slv_reg12 <= (others => '0');
247               slv_reg13 <= (others => '0');
248               slv_reg14 <= (others => '0');
249               slv_reg15 <= (others => '0');
250             else
251               loc_addr := axi_awaddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
252               if (slv_reg_wren = '1') then
253                 case loc_addr is
254                   when b"0000" =>
255                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
256                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
257                         -- Respective byte enables are asserted as per write strobes
258                         -- slave registor 0
259                         slv_reg0(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
260                       end if;
261                     end loop;
262                   when b"0001" =>
263                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
264                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
265                         -- Respective byte enables are asserted as per write strobes
266                         -- slave registor 1
267                         slv_reg1(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
268                       end if;
269                     end loop;
270                   when b"0010" =>
271                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
272                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
273                         -- Respective byte enables are asserted as per write strobes
274                         -- slave registor 2
275                         slv_reg2(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
276                       end if;
277                     end loop;
278                   when b"0011" =>
279                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
280                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
281                         -- Respective byte enables are asserted as per write strobes
282                         -- slave registor 3
283                         slv_reg3(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
284                       end if;
285                     end loop;
286                   when b"0100" =>
287                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
288                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
289                         -- Respective byte enables are asserted as per write strobes
290                         -- slave registor 4
291                         slv_reg4(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
292                       end if;
293                     end loop;
294                   when b"0101" =>
295                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
296                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
297                         -- Respective byte enables are asserted as per write strobes
298                         -- slave registor 5
299                         slv_reg5(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
300                       end if;
301                     end loop;
302                   when b"0110" =>
303                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
304                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
305                         -- Respective byte enables are asserted as per write strobes
306                         -- slave registor 6
307                         slv_reg6(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
308                       end if;
309                     end loop;
310                   when b"0111" =>
311                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
312                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
313                         -- Respective byte enables are asserted as per write strobes
314                         -- slave registor 7
315                         slv_reg7(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
316                       end if;
317                     end loop;
318                   -- when b"1000" =>
319                   --   for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
320                   --     if ( S_AXI_WSTRB(byte_index) = '1' ) then
321                   --       -- Respective byte enables are asserted as per write strobes
322                   --       -- slave registor 8
323                   --       slv_reg8(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
324                   --     end if;
325                   --   end loop;
326                   -- when b"1001" =>
327                   --   for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
328                   --     if ( S_AXI_WSTRB(byte_index) = '1' ) then
329                   --       -- Respective byte enables are asserted as per write strobes
330                   --       -- slave registor 9
331                   --       slv_reg9(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
332                   --     end if;
333                   --   end loop;
334                   when b"1010" =>
335                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
336                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
337                         -- Respective byte enables are asserted as per write strobes
338                         -- slave registor 10
339                         slv_reg10(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
340                       end if;
341                     end loop;
342                   when b"1011" =>
343                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
344                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
345                         -- Respective byte enables are asserted as per write strobes
346                         -- slave registor 11
347                         slv_reg11(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
348                       end if;
349                     end loop;
350                   when b"1100" =>
351                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
352                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
353                         -- Respective byte enables are asserted as per write strobes
354                         -- slave registor 12
355                         slv_reg12(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
356                       end if;
357                     end loop;
358                   when b"1101" =>
359                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
360                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
361                         -- Respective byte enables are asserted as per write strobes
362                         -- slave registor 13
363                         slv_reg13(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
364                       end if;
365                     end loop;
366                   when b"1110" =>
367                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
368                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
369                         -- Respective byte enables are asserted as per write strobes
370                         -- slave registor 14
371                         slv_reg14(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
372                       end if;
373                     end loop;
374                   when b"1111" =>
375                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
376                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
377                         -- Respective byte enables are asserted as per write strobes
378                         -- slave registor 15
379                         slv_reg15(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
380                       end if;
381                     end loop;
382                   when others =>
383                     slv_reg0 <= slv_reg0;
384                     slv_reg1 <= slv_reg1;
385                     slv_reg2 <= slv_reg2;
386                     slv_reg3 <= slv_reg3;
387                     slv_reg4 <= slv_reg4;
388                     slv_reg5 <= slv_reg5;
389                     slv_reg6 <= slv_reg6;
390                     slv_reg7 <= slv_reg7;
391                     -- slv_reg8 <= slv_reg8;
392                     -- slv_reg9 <= slv_reg9;
393                     slv_reg10 <= slv_reg10;
394                     slv_reg11 <= slv_reg11;
395                     slv_reg12 <= slv_reg12;
396                     slv_reg13 <= slv_reg13;
397                     slv_reg14 <= slv_reg14;
398                     slv_reg15 <= slv_reg15;
399                 end case;
400               end if;
401             end if;
402           end if;
403         end process;
404
405         -- Implement write response logic generation
406         -- The write response and response valid signals are asserted by the slave
407         -- when axi_wready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted.
408         -- This marks the acceptance of address and indicates the status of
409         -- write transaction.
410
411         process (S_AXI_ACLK)
412         begin
413           if rising_edge(S_AXI_ACLK) then
414             if S_AXI_ARESETN = '0' then
415               axi_bvalid  <= '0';
416               axi_bresp   <= "00"; --need to work more on the responses
417             else
418               if (axi_awready = '1' and S_AXI_AWVALID = '1' and axi_wready = '1' and S_AXI_WVALID = '1' and axi_bvalid = '0'  ) then
419                 axi_bvalid <= '1';
420                 axi_bresp  <= "00";
421               elsif (S_AXI_BREADY = '1' and axi_bvalid = '1') then   --check if bready is asserted while bvalid is high)
422                 axi_bvalid <= '0';                                 -- (there is a possibility that bready is always asserted high)
423               end if;
424             end if;
425           end if;
426         end process;
427
428         -- Implement axi_arready generation
429         -- axi_arready is asserted for one S_AXI_ACLK clock cycle when
430         -- S_AXI_ARVALID is asserted. axi_awready is
431         -- de-asserted when reset (active low) is asserted.
432         -- The read address is also latched when S_AXI_ARVALID is
433         -- asserted. axi_araddr is reset to zero on reset assertion.
434
435         process (S_AXI_ACLK)
436         begin
437           if rising_edge(S_AXI_ACLK) then
438             if S_AXI_ARESETN = '0' then
439               axi_arready <= '0';
440               axi_araddr  <= (others => '1');
441             else
442               if (axi_arready = '0' and S_AXI_ARVALID = '1') then
443                 -- indicates that the slave has acceped the valid read address
444                 axi_arready <= '1';
445                 -- Read Address latching
446                 axi_araddr  <= S_AXI_ARADDR;
447               else
448                 axi_arready <= '0';
449               end if;
450             end if;
451           end if;
452         end process;
453
454         -- Implement axi_arvalid generation
455         -- axi_rvalid is asserted for one S_AXI_ACLK clock cycle when both
456         -- S_AXI_ARVALID and axi_arready are asserted. The slave registers
457         -- data are available on the axi_rdata bus at this instance. The
458         -- assertion of axi_rvalid marks the validity of read data on the
459         -- bus and axi_rresp indicates the status of read transaction.axi_rvalid
460         -- is deasserted on reset (active low). axi_rresp and axi_rdata are
461         -- cleared to zero on reset (active low).
462         process (S_AXI_ACLK)
463         begin
464           if rising_edge(S_AXI_ACLK) then
465             if S_AXI_ARESETN = '0' then
466               axi_rvalid <= '0';
467               axi_rresp  <= "00";
468             else
469               if (axi_arready = '1' and S_AXI_ARVALID = '1' and axi_rvalid = '0') then
470                 -- Valid read data is available at the read data bus
471                 axi_rvalid <= '1';
472                 axi_rresp  <= "00"; -- 'OKAY' response
473               elsif (axi_rvalid = '1' and S_AXI_RREADY = '1') then
474                 -- Read data is accepted by the master
475                 axi_rvalid <= '0';
476               end if;
477             end if;
478           end if;
479         end process;
480
481         -- Implement memory mapped register select and read logic generation
482         -- Slave register read enable is asserted when valid address is available
483         -- and the slave is ready to accept the read address.
484         slv_reg_rden <= axi_arready and S_AXI_ARVALID and (not axi_rvalid) ;
485
486         process (slv_reg0, slv_reg1, slv_reg2, slv_reg3, slv_reg4, slv_reg5, slv_reg6, slv_reg7, slv_reg8, slv_reg9, slv_reg10, slv_reg11, slv_reg12, slv_reg13, slv_reg14, slv_reg15, axi_araddr, S_AXI_ARESETN, slv_reg_rden)
487         variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
488         begin
489             -- Address decoding for reading registers
490             loc_addr := axi_araddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
491             case loc_addr is
492               when b"0000" =>
493                 reg_data_out <= slv_reg0;
494               when b"0001" =>
495                 reg_data_out <= slv_reg1;
496               when b"0010" =>
497                 reg_data_out <= slv_reg2;
498               when b"0011" =>
499                 reg_data_out <= slv_reg3;
500               when b"0100" =>
501                 reg_data_out <= slv_reg4;
502               when b"0101" =>
503                 reg_data_out <= slv_reg5;
504               when b"0110" =>
505                 reg_data_out <= slv_reg6;
506               when b"0111" =>
507                 reg_data_out <= slv_reg7;
508               when b"1000" =>
509                 reg_data_out <= slv_reg8;
510               when b"1001" =>
511                 reg_data_out <= slv_reg9;
512               when b"1010" =>
513                 reg_data_out <= slv_reg10;
514               when b"1011" =>
515                 reg_data_out <= slv_reg11;
516               when b"1100" =>
517                 reg_data_out <= slv_reg12;
518               when b"1101" =>
519                 reg_data_out <= slv_reg13;
520               when b"1110" =>
521                 reg_data_out <= slv_reg14;
522               when b"1111" =>
523                 reg_data_out <= slv_reg15;
524               when others =>
525                 reg_data_out  <= (others => '0');
526             end case;
527         end process;
528
529         -- Output register or memory read data
530         process( S_AXI_ACLK ) is
531         begin
532           if (rising_edge (S_AXI_ACLK)) then
533             if ( S_AXI_ARESETN = '0' ) then
534               axi_rdata  <= (others => '0');
535             else
536               if (slv_reg_rden = '1') then
537                 -- When there is a valid read address (S_AXI_ARVALID) with
538                 -- acceptance of read address by the slave (axi_arready),
539                 -- output the read dada
540                 -- Read address mux
541                   axi_rdata <= reg_data_out;     -- register read data
542               end if;
543             end if;
544           end if;
545         end process;
546
547
548         -- Add user logic here
549
550         output_led_line <= slv_reg1(31 downto 0);
551         output_led_rgb1 <= slv_reg4(23 downto 0);
552         output_led_rgb2 <= slv_reg5(23 downto 0);
553         output_led_direct <= slv_reg6(7 downto 0);
554         output_kbd_direct <= slv_reg6(11 downto 8);
555
556         slv_reg8(3 downto 0) <= in_kbd_direct;
557         slv_reg8(15 downto 4) <= (others => '0');
558         slv_reg8(24 downto 16) <= in_enc_direct;
559         slv_reg8(31 downto 25) <= (others => '0');
560
561         slv_reg9(23 downto 0) <= in_enc_8bit;
562         slv_reg9(26 downto 24) <= in_enc_buttons;
563         slv_reg9(31 downto 27) <= (others => '0');
564
565         -- User logic ends
566
567 end arch_imp;