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
21 -- Do not modify the ports beyond this line
23 -- Global Clock Signal
24 S_AXI_ACLK : in std_logic;
25 -- Global Reset Signal. This Signal is Active LOW
26 S_AXI_ARESETN : in std_logic;
27 -- Write address (issued by master, acceped by Slave)
28 S_AXI_AWADDR : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
29 -- Write channel Protection type. This signal indicates the
30 -- privilege and security level of the transaction, and whether
31 -- the transaction is a data access or an instruction access.
32 S_AXI_AWPROT : in std_logic_vector(2 downto 0);
33 -- Write address valid. This signal indicates that the master signaling
34 -- valid write address and control information.
35 S_AXI_AWVALID : in std_logic;
36 -- Write address ready. This signal indicates that the slave is ready
37 -- to accept an address and associated control signals.
38 S_AXI_AWREADY : out std_logic;
39 -- Write data (issued by master, acceped by Slave)
40 S_AXI_WDATA : in std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
41 -- Write strobes. This signal indicates which byte lanes hold
42 -- valid data. There is one write strobe bit for each eight
43 -- bits of the write data bus.
44 S_AXI_WSTRB : in std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0);
45 -- Write valid. This signal indicates that valid write
46 -- data and strobes are available.
47 S_AXI_WVALID : in std_logic;
48 -- Write ready. This signal indicates that the slave
49 -- can accept the write data.
50 S_AXI_WREADY : out std_logic;
51 -- Write response. This signal indicates the status
52 -- of the write transaction.
53 S_AXI_BRESP : out std_logic_vector(1 downto 0);
54 -- Write response valid. This signal indicates that the channel
55 -- is signaling a valid write response.
56 S_AXI_BVALID : out std_logic;
57 -- Response ready. This signal indicates that the master
58 -- can accept a write response.
59 S_AXI_BREADY : in std_logic;
60 -- Read address (issued by master, acceped by Slave)
61 S_AXI_ARADDR : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
62 -- Protection type. This signal indicates the privilege
63 -- and security level of the transaction, and whether the
64 -- transaction is a data access or an instruction access.
65 S_AXI_ARPROT : in std_logic_vector(2 downto 0);
66 -- Read address valid. This signal indicates that the channel
67 -- is signaling valid read address and control information.
68 S_AXI_ARVALID : in std_logic;
69 -- Read address ready. This signal indicates that the slave is
70 -- ready to accept an address and associated control signals.
71 S_AXI_ARREADY : out std_logic;
72 -- Read data (issued by slave)
73 S_AXI_RDATA : out std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
74 -- Read response. This signal indicates the status of the
76 S_AXI_RRESP : out std_logic_vector(1 downto 0);
77 -- Read valid. This signal indicates that the channel is
78 -- signaling the required read data.
79 S_AXI_RVALID : out std_logic;
80 -- Read ready. This signal indicates that the master can
81 -- accept the read data and response information.
82 S_AXI_RREADY : in std_logic
84 end spi_leds_and_enc_v1_0_S00_AXI;
86 architecture arch_imp of spi_leds_and_enc_v1_0_S00_AXI is
89 signal axi_awaddr : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
90 signal axi_awready : std_logic;
91 signal axi_wready : std_logic;
92 signal axi_bresp : std_logic_vector(1 downto 0);
93 signal axi_bvalid : std_logic;
94 signal axi_araddr : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
95 signal axi_arready : std_logic;
96 signal axi_rdata : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
97 signal axi_rresp : std_logic_vector(1 downto 0);
98 signal axi_rvalid : std_logic;
100 -- Example-specific design signals
101 -- local parameter for addressing 32 bit / 64 bit C_S_AXI_DATA_WIDTH
102 -- ADDR_LSB is used for addressing 32/64 bit registers/memories
103 -- ADDR_LSB = 2 for 32 bits (n downto 2)
104 -- ADDR_LSB = 3 for 64 bits (n downto 3)
105 constant ADDR_LSB : integer := (C_S_AXI_DATA_WIDTH/32)+ 1;
106 constant OPT_MEM_ADDR_BITS : integer := 3;
107 ------------------------------------------------
108 ---- Signals for user logic register space example
109 --------------------------------------------------
110 ---- Number of Slave Registers 16
111 signal slv_reg0 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
112 signal slv_reg1 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
113 signal slv_reg2 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
114 signal slv_reg3 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
115 signal slv_reg4 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
116 signal slv_reg5 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
117 signal slv_reg6 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
118 signal slv_reg7 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
119 signal slv_reg8 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
120 signal slv_reg9 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
121 signal slv_reg10 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
122 signal slv_reg11 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
123 signal slv_reg12 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
124 signal slv_reg13 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
125 signal slv_reg14 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
126 signal slv_reg15 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
127 signal slv_reg_rden : std_logic;
128 signal slv_reg_wren : std_logic;
129 signal reg_data_out :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
130 signal byte_index : integer;
133 -- I/O Connections assignments
135 S_AXI_AWREADY <= axi_awready;
136 S_AXI_WREADY <= axi_wready;
137 S_AXI_BRESP <= axi_bresp;
138 S_AXI_BVALID <= axi_bvalid;
139 S_AXI_ARREADY <= axi_arready;
140 S_AXI_RDATA <= axi_rdata;
141 S_AXI_RRESP <= axi_rresp;
142 S_AXI_RVALID <= axi_rvalid;
143 -- Implement axi_awready generation
144 -- axi_awready is asserted for one S_AXI_ACLK clock cycle when both
145 -- S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_awready is
146 -- de-asserted when reset is low.
150 if rising_edge(S_AXI_ACLK) then
151 if S_AXI_ARESETN = '0' then
154 if (axi_awready = '0' and S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') then
155 -- slave is ready to accept write address when
156 -- there is a valid write address and write data
157 -- on the write address and data bus. This design
158 -- expects no outstanding transactions.
167 -- Implement axi_awaddr latching
168 -- This process is used to latch the address when both
169 -- S_AXI_AWVALID and S_AXI_WVALID are valid.
173 if rising_edge(S_AXI_ACLK) then
174 if S_AXI_ARESETN = '0' then
175 axi_awaddr <= (others => '0');
177 if (axi_awready = '0' and S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') then
178 -- Write Address latching
179 axi_awaddr <= S_AXI_AWADDR;
185 -- Implement axi_wready generation
186 -- axi_wready is asserted for one S_AXI_ACLK clock cycle when both
187 -- S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_wready is
188 -- de-asserted when reset is low.
192 if rising_edge(S_AXI_ACLK) then
193 if S_AXI_ARESETN = '0' then
196 if (axi_wready = '0' and S_AXI_WVALID = '1' and S_AXI_AWVALID = '1') then
197 -- slave is ready to accept write data when
198 -- there is a valid write address and write data
199 -- on the write address and data bus. This design
200 -- expects no outstanding transactions.
209 -- Implement memory mapped register select and write logic generation
210 -- The write data is accepted and written to memory mapped registers when
211 -- axi_awready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted. Write strobes are used to
212 -- select byte enables of slave registers while writing.
213 -- These registers are cleared when reset (active low) is applied.
214 -- Slave register write enable is asserted when valid address and data are available
215 -- and the slave is ready to accept the write address and write data.
216 slv_reg_wren <= axi_wready and S_AXI_WVALID and axi_awready and S_AXI_AWVALID ;
219 variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
221 if rising_edge(S_AXI_ACLK) then
222 if S_AXI_ARESETN = '0' then
223 slv_reg0 <= (others => '0');
224 slv_reg1 <= (others => '0');
225 slv_reg2 <= (others => '0');
226 slv_reg3 <= (others => '0');
227 slv_reg4 <= (others => '0');
228 slv_reg5 <= (others => '0');
229 slv_reg6 <= (others => '0');
230 slv_reg7 <= (others => '0');
231 slv_reg8 <= (others => '0');
232 slv_reg9 <= (others => '0');
233 slv_reg10 <= (others => '0');
234 slv_reg11 <= (others => '0');
235 slv_reg12 <= (others => '0');
236 slv_reg13 <= (others => '0');
237 slv_reg14 <= (others => '0');
238 slv_reg15 <= (others => '0');
240 loc_addr := axi_awaddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
241 if (slv_reg_wren = '1') then
244 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
245 if ( S_AXI_WSTRB(byte_index) = '1' ) then
246 -- Respective byte enables are asserted as per write strobes
248 slv_reg0(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
252 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
253 if ( S_AXI_WSTRB(byte_index) = '1' ) then
254 -- Respective byte enables are asserted as per write strobes
256 slv_reg1(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
260 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
261 if ( S_AXI_WSTRB(byte_index) = '1' ) then
262 -- Respective byte enables are asserted as per write strobes
264 slv_reg2(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
268 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
269 if ( S_AXI_WSTRB(byte_index) = '1' ) then
270 -- Respective byte enables are asserted as per write strobes
272 slv_reg3(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
276 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
277 if ( S_AXI_WSTRB(byte_index) = '1' ) then
278 -- Respective byte enables are asserted as per write strobes
280 slv_reg4(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
284 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
285 if ( S_AXI_WSTRB(byte_index) = '1' ) then
286 -- Respective byte enables are asserted as per write strobes
288 slv_reg5(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
292 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
293 if ( S_AXI_WSTRB(byte_index) = '1' ) then
294 -- Respective byte enables are asserted as per write strobes
296 slv_reg6(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
300 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
301 if ( S_AXI_WSTRB(byte_index) = '1' ) then
302 -- Respective byte enables are asserted as per write strobes
304 slv_reg7(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
308 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
309 if ( S_AXI_WSTRB(byte_index) = '1' ) then
310 -- Respective byte enables are asserted as per write strobes
312 slv_reg8(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
316 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
317 if ( S_AXI_WSTRB(byte_index) = '1' ) then
318 -- Respective byte enables are asserted as per write strobes
320 slv_reg9(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
324 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
325 if ( S_AXI_WSTRB(byte_index) = '1' ) then
326 -- Respective byte enables are asserted as per write strobes
328 slv_reg10(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
332 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
333 if ( S_AXI_WSTRB(byte_index) = '1' ) then
334 -- Respective byte enables are asserted as per write strobes
336 slv_reg11(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
340 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
341 if ( S_AXI_WSTRB(byte_index) = '1' ) then
342 -- Respective byte enables are asserted as per write strobes
344 slv_reg12(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
348 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
349 if ( S_AXI_WSTRB(byte_index) = '1' ) then
350 -- Respective byte enables are asserted as per write strobes
352 slv_reg13(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
356 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
357 if ( S_AXI_WSTRB(byte_index) = '1' ) then
358 -- Respective byte enables are asserted as per write strobes
360 slv_reg14(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
364 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
365 if ( S_AXI_WSTRB(byte_index) = '1' ) then
366 -- Respective byte enables are asserted as per write strobes
368 slv_reg15(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
372 slv_reg0 <= slv_reg0;
373 slv_reg1 <= slv_reg1;
374 slv_reg2 <= slv_reg2;
375 slv_reg3 <= slv_reg3;
376 slv_reg4 <= slv_reg4;
377 slv_reg5 <= slv_reg5;
378 slv_reg6 <= slv_reg6;
379 slv_reg7 <= slv_reg7;
380 slv_reg8 <= slv_reg8;
381 slv_reg9 <= slv_reg9;
382 slv_reg10 <= slv_reg10;
383 slv_reg11 <= slv_reg11;
384 slv_reg12 <= slv_reg12;
385 slv_reg13 <= slv_reg13;
386 slv_reg14 <= slv_reg14;
387 slv_reg15 <= slv_reg15;
394 -- Implement write response logic generation
395 -- The write response and response valid signals are asserted by the slave
396 -- when axi_wready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted.
397 -- This marks the acceptance of address and indicates the status of
398 -- write transaction.
402 if rising_edge(S_AXI_ACLK) then
403 if S_AXI_ARESETN = '0' then
405 axi_bresp <= "00"; --need to work more on the responses
407 if (axi_awready = '1' and S_AXI_AWVALID = '1' and axi_wready = '1' and S_AXI_WVALID = '1' and axi_bvalid = '0' ) then
410 elsif (S_AXI_BREADY = '1' and axi_bvalid = '1') then --check if bready is asserted while bvalid is high)
411 axi_bvalid <= '0'; -- (there is a possibility that bready is always asserted high)
417 -- Implement axi_arready generation
418 -- axi_arready is asserted for one S_AXI_ACLK clock cycle when
419 -- S_AXI_ARVALID is asserted. axi_awready is
420 -- de-asserted when reset (active low) is asserted.
421 -- The read address is also latched when S_AXI_ARVALID is
422 -- asserted. axi_araddr is reset to zero on reset assertion.
426 if rising_edge(S_AXI_ACLK) then
427 if S_AXI_ARESETN = '0' then
429 axi_araddr <= (others => '1');
431 if (axi_arready = '0' and S_AXI_ARVALID = '1') then
432 -- indicates that the slave has acceped the valid read address
434 -- Read Address latching
435 axi_araddr <= S_AXI_ARADDR;
443 -- Implement axi_arvalid generation
444 -- axi_rvalid is asserted for one S_AXI_ACLK clock cycle when both
445 -- S_AXI_ARVALID and axi_arready are asserted. The slave registers
446 -- data are available on the axi_rdata bus at this instance. The
447 -- assertion of axi_rvalid marks the validity of read data on the
448 -- bus and axi_rresp indicates the status of read transaction.axi_rvalid
449 -- is deasserted on reset (active low). axi_rresp and axi_rdata are
450 -- cleared to zero on reset (active low).
453 if rising_edge(S_AXI_ACLK) then
454 if S_AXI_ARESETN = '0' then
458 if (axi_arready = '1' and S_AXI_ARVALID = '1' and axi_rvalid = '0') then
459 -- Valid read data is available at the read data bus
461 axi_rresp <= "00"; -- 'OKAY' response
462 elsif (axi_rvalid = '1' and S_AXI_RREADY = '1') then
463 -- Read data is accepted by the master
470 -- Implement memory mapped register select and read logic generation
471 -- Slave register read enable is asserted when valid address is available
472 -- and the slave is ready to accept the read address.
473 slv_reg_rden <= axi_arready and S_AXI_ARVALID and (not axi_rvalid) ;
475 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)
476 variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
478 -- Address decoding for reading registers
479 loc_addr := axi_araddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
482 reg_data_out <= slv_reg0;
484 reg_data_out <= slv_reg1;
486 reg_data_out <= slv_reg2;
488 reg_data_out <= slv_reg3;
490 reg_data_out <= slv_reg4;
492 reg_data_out <= slv_reg5;
494 reg_data_out <= slv_reg6;
496 reg_data_out <= slv_reg7;
498 reg_data_out <= slv_reg8;
500 reg_data_out <= slv_reg9;
502 reg_data_out <= slv_reg10;
504 reg_data_out <= slv_reg11;
506 reg_data_out <= slv_reg12;
508 reg_data_out <= slv_reg13;
510 reg_data_out <= slv_reg14;
512 reg_data_out <= slv_reg15;
514 reg_data_out <= (others => '0');
518 -- Output register or memory read data
519 process( S_AXI_ACLK ) is
521 if (rising_edge (S_AXI_ACLK)) then
522 if ( S_AXI_ARESETN = '0' ) then
523 axi_rdata <= (others => '0');
525 if (slv_reg_rden = '1') then
526 -- When there is a valid read address (S_AXI_ARVALID) with
527 -- acceptance of read address by the slave (axi_arready),
528 -- output the read dada
530 axi_rdata <= reg_data_out; -- register read data
537 -- Add user logic here