2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
5 entity spi_leds_and_enc_v1_0_S00_AXI is
7 -- Users to add parameters here
9 -- User parameters ends
10 -- Do not modify the parameters beyond this line
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
18 -- Users to add ports here
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);
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);
32 -- Do not modify the ports beyond this line
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
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
95 end spi_leds_and_enc_v1_0_S00_AXI;
97 architecture arch_imp of spi_leds_and_enc_v1_0_S00_AXI is
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;
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;
144 -- I/O Connections assignments
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.
161 if rising_edge(S_AXI_ACLK) then
162 if S_AXI_ARESETN = '0' then
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.
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.
184 if rising_edge(S_AXI_ACLK) then
185 if S_AXI_ARESETN = '0' then
186 axi_awaddr <= (others => '0');
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;
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.
203 if rising_edge(S_AXI_ACLK) then
204 if S_AXI_ARESETN = '0' then
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.
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 ;
230 variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
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');
251 loc_addr := axi_awaddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
252 if (slv_reg_wren = '1') then
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
259 slv_reg0(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
267 slv_reg1(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
275 slv_reg2(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
283 slv_reg3(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
291 slv_reg4(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
299 slv_reg5(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
307 slv_reg6(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
315 slv_reg7(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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);
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);
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
339 slv_reg10(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
347 slv_reg11(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
355 slv_reg12(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
363 slv_reg13(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
371 slv_reg14(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
379 slv_reg15(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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;
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.
413 if rising_edge(S_AXI_ACLK) then
414 if S_AXI_ARESETN = '0' then
416 axi_bresp <= "00"; --need to work more on the responses
418 if (axi_awready = '1' and S_AXI_AWVALID = '1' and axi_wready = '1' and S_AXI_WVALID = '1' and axi_bvalid = '0' ) then
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)
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.
437 if rising_edge(S_AXI_ACLK) then
438 if S_AXI_ARESETN = '0' then
440 axi_araddr <= (others => '1');
442 if (axi_arready = '0' and S_AXI_ARVALID = '1') then
443 -- indicates that the slave has acceped the valid read address
445 -- Read Address latching
446 axi_araddr <= S_AXI_ARADDR;
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).
464 if rising_edge(S_AXI_ACLK) then
465 if S_AXI_ARESETN = '0' then
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
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
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) ;
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);
489 -- Address decoding for reading registers
490 loc_addr := axi_araddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
493 reg_data_out <= slv_reg0;
495 reg_data_out <= slv_reg1;
497 reg_data_out <= slv_reg2;
499 reg_data_out <= slv_reg3;
501 reg_data_out <= slv_reg4;
503 reg_data_out <= slv_reg5;
505 reg_data_out <= slv_reg6;
507 reg_data_out <= slv_reg7;
509 reg_data_out <= slv_reg8;
511 reg_data_out <= slv_reg9;
513 reg_data_out <= slv_reg10;
515 reg_data_out <= slv_reg11;
517 reg_data_out <= slv_reg12;
519 reg_data_out <= slv_reg13;
521 reg_data_out <= slv_reg14;
523 reg_data_out <= slv_reg15;
525 reg_data_out <= (others => '0');
529 -- Output register or memory read data
530 process( S_AXI_ACLK ) is
532 if (rising_edge (S_AXI_ACLK)) then
533 if ( S_AXI_ARESETN = '0' ) then
534 axi_rdata <= (others => '0');
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
541 axi_rdata <= reg_data_out; -- register read data
548 -- Add user logic here
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);
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');
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');