2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
5 entity audio_single_pwm_v1_0_S00_AXI is
7 -- Users to add parameters here
8 audio_pwm_width : integer := 24;
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
19 audio_pwm_period: out std_logic_vector(audio_pwm_width-1 downto 0);
20 audio_pwm_duty: out std_logic_vector(audio_pwm_width-1 downto 0);
22 -- Do not modify the ports beyond this line
24 -- Global Clock Signal
25 S_AXI_ACLK : in std_logic;
26 -- Global Reset Signal. This Signal is Active LOW
27 S_AXI_ARESETN : in std_logic;
28 -- Write address (issued by master, acceped by Slave)
29 S_AXI_AWADDR : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
30 -- Write channel Protection type. This signal indicates the
31 -- privilege and security level of the transaction, and whether
32 -- the transaction is a data access or an instruction access.
33 S_AXI_AWPROT : in std_logic_vector(2 downto 0);
34 -- Write address valid. This signal indicates that the master signaling
35 -- valid write address and control information.
36 S_AXI_AWVALID : in std_logic;
37 -- Write address ready. This signal indicates that the slave is ready
38 -- to accept an address and associated control signals.
39 S_AXI_AWREADY : out std_logic;
40 -- Write data (issued by master, acceped by Slave)
41 S_AXI_WDATA : in std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
42 -- Write strobes. This signal indicates which byte lanes hold
43 -- valid data. There is one write strobe bit for each eight
44 -- bits of the write data bus.
45 S_AXI_WSTRB : in std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0);
46 -- Write valid. This signal indicates that valid write
47 -- data and strobes are available.
48 S_AXI_WVALID : in std_logic;
49 -- Write ready. This signal indicates that the slave
50 -- can accept the write data.
51 S_AXI_WREADY : out std_logic;
52 -- Write response. This signal indicates the status
53 -- of the write transaction.
54 S_AXI_BRESP : out std_logic_vector(1 downto 0);
55 -- Write response valid. This signal indicates that the channel
56 -- is signaling a valid write response.
57 S_AXI_BVALID : out std_logic;
58 -- Response ready. This signal indicates that the master
59 -- can accept a write response.
60 S_AXI_BREADY : in std_logic;
61 -- Read address (issued by master, acceped by Slave)
62 S_AXI_ARADDR : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
63 -- Protection type. This signal indicates the privilege
64 -- and security level of the transaction, and whether the
65 -- transaction is a data access or an instruction access.
66 S_AXI_ARPROT : in std_logic_vector(2 downto 0);
67 -- Read address valid. This signal indicates that the channel
68 -- is signaling valid read address and control information.
69 S_AXI_ARVALID : in std_logic;
70 -- Read address ready. This signal indicates that the slave is
71 -- ready to accept an address and associated control signals.
72 S_AXI_ARREADY : out std_logic;
73 -- Read data (issued by slave)
74 S_AXI_RDATA : out std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
75 -- Read response. This signal indicates the status of the
77 S_AXI_RRESP : out std_logic_vector(1 downto 0);
78 -- Read valid. This signal indicates that the channel is
79 -- signaling the required read data.
80 S_AXI_RVALID : out std_logic;
81 -- Read ready. This signal indicates that the master can
82 -- accept the read data and response information.
83 S_AXI_RREADY : in std_logic
85 end audio_single_pwm_v1_0_S00_AXI;
87 architecture arch_imp of audio_single_pwm_v1_0_S00_AXI is
90 signal axi_awaddr : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
91 signal axi_awready : std_logic;
92 signal axi_wready : std_logic;
93 signal axi_bresp : std_logic_vector(1 downto 0);
94 signal axi_bvalid : std_logic;
95 signal axi_araddr : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
96 signal axi_arready : std_logic;
97 signal axi_rdata : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
98 signal axi_rresp : std_logic_vector(1 downto 0);
99 signal axi_rvalid : std_logic;
101 -- Example-specific design signals
102 -- local parameter for addressing 32 bit / 64 bit C_S_AXI_DATA_WIDTH
103 -- ADDR_LSB is used for addressing 32/64 bit registers/memories
104 -- ADDR_LSB = 2 for 32 bits (n downto 2)
105 -- ADDR_LSB = 3 for 64 bits (n downto 3)
106 constant ADDR_LSB : integer := (C_S_AXI_DATA_WIDTH/32)+ 1;
107 constant OPT_MEM_ADDR_BITS : integer := 3;
108 ------------------------------------------------
109 ---- Signals for user logic register space example
110 --------------------------------------------------
111 ---- Number of Slave Registers 16
112 signal slv_reg0 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
113 signal slv_reg1 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
114 signal slv_reg2 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
115 signal slv_reg3 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
116 signal slv_reg4 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
117 signal slv_reg5 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
118 signal slv_reg6 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
119 signal slv_reg7 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
120 signal slv_reg8 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
121 signal slv_reg9 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
122 signal slv_reg10 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
123 signal slv_reg11 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
124 signal slv_reg12 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
125 signal slv_reg13 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
126 signal slv_reg14 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
127 signal slv_reg15 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
128 signal slv_reg_rden : std_logic;
129 signal slv_reg_wren : std_logic;
130 signal reg_data_out :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
131 signal byte_index : integer;
134 -- I/O Connections assignments
136 S_AXI_AWREADY <= axi_awready;
137 S_AXI_WREADY <= axi_wready;
138 S_AXI_BRESP <= axi_bresp;
139 S_AXI_BVALID <= axi_bvalid;
140 S_AXI_ARREADY <= axi_arready;
141 S_AXI_RDATA <= axi_rdata;
142 S_AXI_RRESP <= axi_rresp;
143 S_AXI_RVALID <= axi_rvalid;
144 -- Implement axi_awready generation
145 -- axi_awready is asserted for one S_AXI_ACLK clock cycle when both
146 -- S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_awready is
147 -- de-asserted when reset is low.
151 if rising_edge(S_AXI_ACLK) then
152 if S_AXI_ARESETN = '0' then
155 if (axi_awready = '0' and S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') then
156 -- slave is ready to accept write address when
157 -- there is a valid write address and write data
158 -- on the write address and data bus. This design
159 -- expects no outstanding transactions.
168 -- Implement axi_awaddr latching
169 -- This process is used to latch the address when both
170 -- S_AXI_AWVALID and S_AXI_WVALID are valid.
174 if rising_edge(S_AXI_ACLK) then
175 if S_AXI_ARESETN = '0' then
176 axi_awaddr <= (others => '0');
178 if (axi_awready = '0' and S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') then
179 -- Write Address latching
180 axi_awaddr <= S_AXI_AWADDR;
186 -- Implement axi_wready generation
187 -- axi_wready is asserted for one S_AXI_ACLK clock cycle when both
188 -- S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_wready is
189 -- de-asserted when reset is low.
193 if rising_edge(S_AXI_ACLK) then
194 if S_AXI_ARESETN = '0' then
197 if (axi_wready = '0' and S_AXI_WVALID = '1' and S_AXI_AWVALID = '1') then
198 -- slave is ready to accept write data when
199 -- there is a valid write address and write data
200 -- on the write address and data bus. This design
201 -- expects no outstanding transactions.
210 -- Implement memory mapped register select and write logic generation
211 -- The write data is accepted and written to memory mapped registers when
212 -- axi_awready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted. Write strobes are used to
213 -- select byte enables of slave registers while writing.
214 -- These registers are cleared when reset (active low) is applied.
215 -- Slave register write enable is asserted when valid address and data are available
216 -- and the slave is ready to accept the write address and write data.
217 slv_reg_wren <= axi_wready and S_AXI_WVALID and axi_awready and S_AXI_AWVALID ;
220 variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
222 if rising_edge(S_AXI_ACLK) then
223 if S_AXI_ARESETN = '0' then
224 slv_reg0 <= (others => '0');
225 slv_reg1 <= (others => '0');
226 slv_reg2 <= (others => '0');
227 slv_reg3 <= (others => '0');
228 slv_reg4 <= (others => '0');
229 slv_reg5 <= (others => '0');
230 slv_reg6 <= (others => '0');
231 slv_reg7 <= (others => '0');
232 slv_reg8 <= (others => '0');
233 slv_reg9 <= (others => '0');
234 slv_reg10 <= (others => '0');
235 slv_reg11 <= (others => '0');
236 slv_reg12 <= (others => '0');
237 slv_reg13 <= (others => '0');
238 slv_reg14 <= (others => '0');
239 slv_reg15 <= (others => '0');
241 loc_addr := axi_awaddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
242 if (slv_reg_wren = '1') then
245 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
246 if ( S_AXI_WSTRB(byte_index) = '1' ) then
247 -- Respective byte enables are asserted as per write strobes
249 slv_reg0(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
253 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
254 if ( S_AXI_WSTRB(byte_index) = '1' ) then
255 -- Respective byte enables are asserted as per write strobes
257 slv_reg1(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
261 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
262 if ( S_AXI_WSTRB(byte_index) = '1' ) then
263 -- Respective byte enables are asserted as per write strobes
265 slv_reg2(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
269 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
270 if ( S_AXI_WSTRB(byte_index) = '1' ) then
271 -- Respective byte enables are asserted as per write strobes
273 slv_reg3(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
277 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
278 if ( S_AXI_WSTRB(byte_index) = '1' ) then
279 -- Respective byte enables are asserted as per write strobes
281 slv_reg4(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
285 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
286 if ( S_AXI_WSTRB(byte_index) = '1' ) then
287 -- Respective byte enables are asserted as per write strobes
289 slv_reg5(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
293 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
294 if ( S_AXI_WSTRB(byte_index) = '1' ) then
295 -- Respective byte enables are asserted as per write strobes
297 slv_reg6(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
301 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
302 if ( S_AXI_WSTRB(byte_index) = '1' ) then
303 -- Respective byte enables are asserted as per write strobes
305 slv_reg7(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
309 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
310 if ( S_AXI_WSTRB(byte_index) = '1' ) then
311 -- Respective byte enables are asserted as per write strobes
313 slv_reg8(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
317 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
318 if ( S_AXI_WSTRB(byte_index) = '1' ) then
319 -- Respective byte enables are asserted as per write strobes
321 slv_reg9(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
325 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
326 if ( S_AXI_WSTRB(byte_index) = '1' ) then
327 -- Respective byte enables are asserted as per write strobes
329 slv_reg10(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
333 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
334 if ( S_AXI_WSTRB(byte_index) = '1' ) then
335 -- Respective byte enables are asserted as per write strobes
337 slv_reg11(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
341 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
342 if ( S_AXI_WSTRB(byte_index) = '1' ) then
343 -- Respective byte enables are asserted as per write strobes
345 slv_reg12(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
349 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
350 if ( S_AXI_WSTRB(byte_index) = '1' ) then
351 -- Respective byte enables are asserted as per write strobes
353 slv_reg13(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
357 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
358 if ( S_AXI_WSTRB(byte_index) = '1' ) then
359 -- Respective byte enables are asserted as per write strobes
361 slv_reg14(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
365 for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
366 if ( S_AXI_WSTRB(byte_index) = '1' ) then
367 -- Respective byte enables are asserted as per write strobes
369 slv_reg15(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
373 slv_reg0 <= slv_reg0;
374 slv_reg1 <= slv_reg1;
375 slv_reg2 <= slv_reg2;
376 slv_reg3 <= slv_reg3;
377 slv_reg4 <= slv_reg4;
378 slv_reg5 <= slv_reg5;
379 slv_reg6 <= slv_reg6;
380 slv_reg7 <= slv_reg7;
381 slv_reg8 <= slv_reg8;
382 slv_reg9 <= slv_reg9;
383 slv_reg10 <= slv_reg10;
384 slv_reg11 <= slv_reg11;
385 slv_reg12 <= slv_reg12;
386 slv_reg13 <= slv_reg13;
387 slv_reg14 <= slv_reg14;
388 slv_reg15 <= slv_reg15;
395 -- Implement write response logic generation
396 -- The write response and response valid signals are asserted by the slave
397 -- when axi_wready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted.
398 -- This marks the acceptance of address and indicates the status of
399 -- write transaction.
403 if rising_edge(S_AXI_ACLK) then
404 if S_AXI_ARESETN = '0' then
406 axi_bresp <= "00"; --need to work more on the responses
408 if (axi_awready = '1' and S_AXI_AWVALID = '1' and axi_wready = '1' and S_AXI_WVALID = '1' and axi_bvalid = '0' ) then
411 elsif (S_AXI_BREADY = '1' and axi_bvalid = '1') then --check if bready is asserted while bvalid is high)
412 axi_bvalid <= '0'; -- (there is a possibility that bready is always asserted high)
418 -- Implement axi_arready generation
419 -- axi_arready is asserted for one S_AXI_ACLK clock cycle when
420 -- S_AXI_ARVALID is asserted. axi_awready is
421 -- de-asserted when reset (active low) is asserted.
422 -- The read address is also latched when S_AXI_ARVALID is
423 -- asserted. axi_araddr is reset to zero on reset assertion.
427 if rising_edge(S_AXI_ACLK) then
428 if S_AXI_ARESETN = '0' then
430 axi_araddr <= (others => '1');
432 if (axi_arready = '0' and S_AXI_ARVALID = '1') then
433 -- indicates that the slave has acceped the valid read address
435 -- Read Address latching
436 axi_araddr <= S_AXI_ARADDR;
444 -- Implement axi_arvalid generation
445 -- axi_rvalid is asserted for one S_AXI_ACLK clock cycle when both
446 -- S_AXI_ARVALID and axi_arready are asserted. The slave registers
447 -- data are available on the axi_rdata bus at this instance. The
448 -- assertion of axi_rvalid marks the validity of read data on the
449 -- bus and axi_rresp indicates the status of read transaction.axi_rvalid
450 -- is deasserted on reset (active low). axi_rresp and axi_rdata are
451 -- cleared to zero on reset (active low).
454 if rising_edge(S_AXI_ACLK) then
455 if S_AXI_ARESETN = '0' then
459 if (axi_arready = '1' and S_AXI_ARVALID = '1' and axi_rvalid = '0') then
460 -- Valid read data is available at the read data bus
462 axi_rresp <= "00"; -- 'OKAY' response
463 elsif (axi_rvalid = '1' and S_AXI_RREADY = '1') then
464 -- Read data is accepted by the master
471 -- Implement memory mapped register select and read logic generation
472 -- Slave register read enable is asserted when valid address is available
473 -- and the slave is ready to accept the read address.
474 slv_reg_rden <= axi_arready and S_AXI_ARVALID and (not axi_rvalid) ;
476 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)
477 variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
479 -- Address decoding for reading registers
480 loc_addr := axi_araddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
483 reg_data_out <= slv_reg0;
485 reg_data_out <= slv_reg1;
487 reg_data_out <= slv_reg2;
489 reg_data_out <= slv_reg3;
491 reg_data_out <= slv_reg4;
493 reg_data_out <= slv_reg5;
495 reg_data_out <= slv_reg6;
497 reg_data_out <= slv_reg7;
499 reg_data_out <= slv_reg8;
501 reg_data_out <= slv_reg9;
503 reg_data_out <= slv_reg10;
505 reg_data_out <= slv_reg11;
507 reg_data_out <= slv_reg12;
509 reg_data_out <= slv_reg13;
511 reg_data_out <= slv_reg14;
513 reg_data_out <= slv_reg15;
515 reg_data_out <= (others => '0');
519 -- Output register or memory read data
520 process( S_AXI_ACLK ) is
522 if (rising_edge (S_AXI_ACLK)) then
523 if ( S_AXI_ARESETN = '0' ) then
524 axi_rdata <= (others => '0');
526 if (slv_reg_rden = '1') then
527 -- When there is a valid read address (S_AXI_ARVALID) with
528 -- acceptance of read address by the slave (axi_arready),
529 -- output the read dada
531 axi_rdata <= reg_data_out; -- register read data
538 -- Add user logic here
539 audio_pwm_period <= slv_reg2(audio_pwm_width-1 downto 0);
540 audio_pwm_duty <= slv_reg3(audio_pwm_width-1 downto 0);