]> rtime.felk.cvut.cz Git - fpga/zynq/canbench-sw.git/blob - system/ip/audio_single_pwm_1.0/hdl/audio_single_pwm_v1_0.vhd
microzed_apo: Correct JX1_LVDS_21_N pin assignment on FPGA_IO header.
[fpga/zynq/canbench-sw.git] / system / ip / audio_single_pwm_1.0 / hdl / audio_single_pwm_v1_0.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4
5 entity audio_single_pwm_v1_0 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
13                 -- Parameters of Axi Slave Bus Interface S00_AXI
14                 C_S00_AXI_DATA_WIDTH    : integer       := 32;
15                 C_S00_AXI_ADDR_WIDTH    : integer       := 6;
16
17                 -- Parameters of Axi Master Bus Interface M00_AXI
18                 C_M00_AXI_START_DATA_VALUE      : std_logic_vector      := x"AA000000";
19                 C_M00_AXI_TARGET_SLAVE_BASE_ADDR        : std_logic_vector      := x"40000000";
20                 C_M00_AXI_ADDR_WIDTH    : integer       := 32;
21                 C_M00_AXI_DATA_WIDTH    : integer       := 32;
22                 C_M00_AXI_TRANSACTIONS_NUM      : integer       := 4
23         );
24         port (
25                 -- Users to add ports here
26                 speaker_pwm_out : out std_logic;
27                 irq_rq_out :      out std_logic;
28                 -- User ports ends
29                 -- Do not modify the ports beyond this line
30
31
32                 -- Ports of Axi Slave Bus Interface S00_AXI
33                 s00_axi_aclk    : in std_logic;
34                 s00_axi_aresetn : in std_logic;
35                 s00_axi_awaddr  : in std_logic_vector(C_S00_AXI_ADDR_WIDTH-1 downto 0);
36                 s00_axi_awprot  : in std_logic_vector(2 downto 0);
37                 s00_axi_awvalid : in std_logic;
38                 s00_axi_awready : out std_logic;
39                 s00_axi_wdata   : in std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0);
40                 s00_axi_wstrb   : in std_logic_vector((C_S00_AXI_DATA_WIDTH/8)-1 downto 0);
41                 s00_axi_wvalid  : in std_logic;
42                 s00_axi_wready  : out std_logic;
43                 s00_axi_bresp   : out std_logic_vector(1 downto 0);
44                 s00_axi_bvalid  : out std_logic;
45                 s00_axi_bready  : in std_logic;
46                 s00_axi_araddr  : in std_logic_vector(C_S00_AXI_ADDR_WIDTH-1 downto 0);
47                 s00_axi_arprot  : in std_logic_vector(2 downto 0);
48                 s00_axi_arvalid : in std_logic;
49                 s00_axi_arready : out std_logic;
50                 s00_axi_rdata   : out std_logic_vector(C_S00_AXI_DATA_WIDTH-1 downto 0);
51                 s00_axi_rresp   : out std_logic_vector(1 downto 0);
52                 s00_axi_rvalid  : out std_logic;
53                 s00_axi_rready  : in std_logic;
54
55                 -- Ports of Axi Master Bus Interface M00_AXI
56                 m00_axi_aclk    : in std_logic;
57                 m00_axi_aresetn : in std_logic;
58                 m00_axi_awaddr  : out std_logic_vector(C_M00_AXI_ADDR_WIDTH-1 downto 0);
59                 m00_axi_awprot  : out std_logic_vector(2 downto 0);
60                 m00_axi_awvalid : out std_logic;
61                 m00_axi_awready : in std_logic;
62                 m00_axi_wdata   : out std_logic_vector(C_M00_AXI_DATA_WIDTH-1 downto 0);
63                 m00_axi_wstrb   : out std_logic_vector(C_M00_AXI_DATA_WIDTH/8-1 downto 0);
64                 m00_axi_wvalid  : out std_logic;
65                 m00_axi_wready  : in std_logic;
66                 m00_axi_bresp   : in std_logic_vector(1 downto 0);
67                 m00_axi_bvalid  : in std_logic;
68                 m00_axi_bready  : out std_logic;
69                 m00_axi_araddr  : out std_logic_vector(C_M00_AXI_ADDR_WIDTH-1 downto 0);
70                 m00_axi_arprot  : out std_logic_vector(2 downto 0);
71                 m00_axi_arvalid : out std_logic;
72                 m00_axi_arready : in std_logic;
73                 m00_axi_rdata   : in std_logic_vector(C_M00_AXI_DATA_WIDTH-1 downto 0);
74                 m00_axi_rresp   : in std_logic_vector(1 downto 0);
75                 m00_axi_rvalid  : in std_logic;
76                 m00_axi_rready  : out std_logic
77         );
78 end audio_single_pwm_v1_0;
79
80 architecture arch_imp of audio_single_pwm_v1_0 is
81
82         -- component declaration
83         component audio_single_pwm_v1_0_S00_AXI is
84                 generic (
85                 C_S_AXI_DATA_WIDTH      : integer       := 32;
86                 C_S_AXI_ADDR_WIDTH      : integer       := 6;
87                 audio_pwm_width         : integer       := 24
88                 );
89                 port (
90                 audio_pwm_period: out std_logic_vector(audio_pwm_width-1 downto 0);
91                 audio_pwm_duty: out std_logic_vector(audio_pwm_width-1 downto 0);
92
93                 S_AXI_ACLK      : in std_logic;
94                 S_AXI_ARESETN   : in std_logic;
95                 S_AXI_AWADDR    : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
96                 S_AXI_AWPROT    : in std_logic_vector(2 downto 0);
97                 S_AXI_AWVALID   : in std_logic;
98                 S_AXI_AWREADY   : out std_logic;
99                 S_AXI_WDATA     : in std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
100                 S_AXI_WSTRB     : in std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0);
101                 S_AXI_WVALID    : in std_logic;
102                 S_AXI_WREADY    : out std_logic;
103                 S_AXI_BRESP     : out std_logic_vector(1 downto 0);
104                 S_AXI_BVALID    : out std_logic;
105                 S_AXI_BREADY    : in std_logic;
106                 S_AXI_ARADDR    : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
107                 S_AXI_ARPROT    : in std_logic_vector(2 downto 0);
108                 S_AXI_ARVALID   : in std_logic;
109                 S_AXI_ARREADY   : out std_logic;
110                 S_AXI_RDATA     : out std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
111                 S_AXI_RRESP     : out std_logic_vector(1 downto 0);
112                 S_AXI_RVALID    : out std_logic;
113                 S_AXI_RREADY    : in std_logic
114                 );
115         end component audio_single_pwm_v1_0_S00_AXI;
116
117         component audio_single_pwm_v1_0_M00_AXI is
118                 generic (
119                 C_M_START_DATA_VALUE    : std_logic_vector      := x"AA000000";
120                 C_M_TARGET_SLAVE_BASE_ADDR      : std_logic_vector      := x"40000000";
121                 C_M_AXI_ADDR_WIDTH      : integer       := 32;
122                 C_M_AXI_DATA_WIDTH      : integer       := 32;
123                 C_M_TRANSACTIONS_NUM    : integer       := 4
124                 );
125                 port (
126                 INIT_AXI_TXN    : in std_logic;
127                 ERROR   : out std_logic;
128                 TXN_DONE        : out std_logic;
129                 M_AXI_ACLK      : in std_logic;
130                 M_AXI_ARESETN   : in std_logic;
131                 M_AXI_AWADDR    : out std_logic_vector(C_M_AXI_ADDR_WIDTH-1 downto 0);
132                 M_AXI_AWPROT    : out std_logic_vector(2 downto 0);
133                 M_AXI_AWVALID   : out std_logic;
134                 M_AXI_AWREADY   : in std_logic;
135                 M_AXI_WDATA     : out std_logic_vector(C_M_AXI_DATA_WIDTH-1 downto 0);
136                 M_AXI_WSTRB     : out std_logic_vector(C_M_AXI_DATA_WIDTH/8-1 downto 0);
137                 M_AXI_WVALID    : out std_logic;
138                 M_AXI_WREADY    : in std_logic;
139                 M_AXI_BRESP     : in std_logic_vector(1 downto 0);
140                 M_AXI_BVALID    : in std_logic;
141                 M_AXI_BREADY    : out std_logic;
142                 M_AXI_ARADDR    : out std_logic_vector(C_M_AXI_ADDR_WIDTH-1 downto 0);
143                 M_AXI_ARPROT    : out std_logic_vector(2 downto 0);
144                 M_AXI_ARVALID   : out std_logic;
145                 M_AXI_ARREADY   : in std_logic;
146                 M_AXI_RDATA     : in std_logic_vector(C_M_AXI_DATA_WIDTH-1 downto 0);
147                 M_AXI_RRESP     : in std_logic_vector(1 downto 0);
148                 M_AXI_RVALID    : in std_logic;
149                 M_AXI_RREADY    : out std_logic
150                 );
151         end component audio_single_pwm_v1_0_M00_AXI;
152
153         component cnt_div is
154                 generic (
155                 cnt_width_g : natural := 4
156                 );
157                 port
158                 (
159                 clk_i     : in std_logic;                               --clk to divide
160                 en_i      : in std_logic;                               --enable bit?
161                 reset_i   : in std_logic;                               --asynch. reset
162                 ratio_i   : in std_logic_vector(cnt_width_g-1 downto 0);--initial value
163                 q_out_o   : out std_logic                               --generates puls when counter underflows
164                 );
165         end component;
166
167         component pulse_gen is
168                 generic (
169                 duration_width_g : natural := 4
170                 );
171                 port (
172                 clk_i      : in std_logic;                              --clk to divide
173                 en_i       : in std_logic;                              --enable bit?
174                 reset_i    : in std_logic;                              --asynch. reset
175                 trigger_i  : in std_logic;                              --start to generate pulse
176                 duration_i : in std_logic_vector(duration_width_g-1 downto 0);--duration/interval of the pulse
177                 q_out_o    : out std_logic                              --generates pulse for given duration
178                 );
179         end component;
180
181         constant audio_pwm_width : integer := 24;
182
183         signal audio_pwm_period: std_logic_vector(audio_pwm_width-1 downto 0);
184         signal audio_pwm_duty: std_logic_vector(audio_pwm_width-1 downto 0);
185
186         signal fsm_clk : std_logic;
187         signal fsm_rst : std_logic;
188
189         signal pwm_cycle_start : std_logic;
190
191         signal m00_axi_init_axi_txn     : std_logic;
192         signal m00_axi_error    : std_logic;
193         signal m00_axi_txn_done : std_logic;
194
195 begin
196
197 -- Instantiation of Axi Bus Interface S00_AXI
198 audio_single_pwm_v1_0_S00_AXI_inst : audio_single_pwm_v1_0_S00_AXI
199         generic map (
200                 C_S_AXI_DATA_WIDTH      => C_S00_AXI_DATA_WIDTH,
201                 C_S_AXI_ADDR_WIDTH      => C_S00_AXI_ADDR_WIDTH,
202
203                 audio_pwm_width => audio_pwm_width
204         )
205         port map (
206                 audio_pwm_period => audio_pwm_period,
207                 audio_pwm_duty  => audio_pwm_duty,
208
209                 S_AXI_ACLK      => s00_axi_aclk,
210                 S_AXI_ARESETN   => s00_axi_aresetn,
211                 S_AXI_AWADDR    => s00_axi_awaddr,
212                 S_AXI_AWPROT    => s00_axi_awprot,
213                 S_AXI_AWVALID   => s00_axi_awvalid,
214                 S_AXI_AWREADY   => s00_axi_awready,
215                 S_AXI_WDATA     => s00_axi_wdata,
216                 S_AXI_WSTRB     => s00_axi_wstrb,
217                 S_AXI_WVALID    => s00_axi_wvalid,
218                 S_AXI_WREADY    => s00_axi_wready,
219                 S_AXI_BRESP     => s00_axi_bresp,
220                 S_AXI_BVALID    => s00_axi_bvalid,
221                 S_AXI_BREADY    => s00_axi_bready,
222                 S_AXI_ARADDR    => s00_axi_araddr,
223                 S_AXI_ARPROT    => s00_axi_arprot,
224                 S_AXI_ARVALID   => s00_axi_arvalid,
225                 S_AXI_ARREADY   => s00_axi_arready,
226                 S_AXI_RDATA     => s00_axi_rdata,
227                 S_AXI_RRESP     => s00_axi_rresp,
228                 S_AXI_RVALID    => s00_axi_rvalid,
229                 S_AXI_RREADY    => s00_axi_rready
230         );
231
232 -- Instantiation of Axi Bus Interface M00_AXI
233 audio_single_pwm_v1_0_M00_AXI_inst : audio_single_pwm_v1_0_M00_AXI
234         generic map (
235                 C_M_START_DATA_VALUE    => C_M00_AXI_START_DATA_VALUE,
236                 C_M_TARGET_SLAVE_BASE_ADDR      => C_M00_AXI_TARGET_SLAVE_BASE_ADDR,
237                 C_M_AXI_ADDR_WIDTH      => C_M00_AXI_ADDR_WIDTH,
238                 C_M_AXI_DATA_WIDTH      => C_M00_AXI_DATA_WIDTH,
239                 C_M_TRANSACTIONS_NUM    => C_M00_AXI_TRANSACTIONS_NUM
240         )
241         port map (
242                 INIT_AXI_TXN    => m00_axi_init_axi_txn,
243                 ERROR   => m00_axi_error,
244                 TXN_DONE        => m00_axi_txn_done,
245                 M_AXI_ACLK      => m00_axi_aclk,
246                 M_AXI_ARESETN   => m00_axi_aresetn,
247                 M_AXI_AWADDR    => m00_axi_awaddr,
248                 M_AXI_AWPROT    => m00_axi_awprot,
249                 M_AXI_AWVALID   => m00_axi_awvalid,
250                 M_AXI_AWREADY   => m00_axi_awready,
251                 M_AXI_WDATA     => m00_axi_wdata,
252                 M_AXI_WSTRB     => m00_axi_wstrb,
253                 M_AXI_WVALID    => m00_axi_wvalid,
254                 M_AXI_WREADY    => m00_axi_wready,
255                 M_AXI_BRESP     => m00_axi_bresp,
256                 M_AXI_BVALID    => m00_axi_bvalid,
257                 M_AXI_BREADY    => m00_axi_bready,
258                 M_AXI_ARADDR    => m00_axi_araddr,
259                 M_AXI_ARPROT    => m00_axi_arprot,
260                 M_AXI_ARVALID   => m00_axi_arvalid,
261                 M_AXI_ARREADY   => m00_axi_arready,
262                 M_AXI_RDATA     => m00_axi_rdata,
263                 M_AXI_RRESP     => m00_axi_rresp,
264                 M_AXI_RVALID    => m00_axi_rvalid,
265                 M_AXI_RREADY    => m00_axi_rready
266         );
267
268         -- Add user logic here
269
270 cnt_div_inst: cnt_div
271         generic map (
272                 cnt_width_g => audio_pwm_width
273         )
274         port map (
275                 clk_i => fsm_clk,
276                 en_i => '1',
277                 reset_i => fsm_rst,
278                 ratio_i => audio_pwm_period,
279                 q_out_o => pwm_cycle_start
280         );
281
282 audio_pwm_inst: pulse_gen
283         generic map (
284                 duration_width_g => audio_pwm_width
285         )
286         port map (
287                 clk_i => fsm_clk,
288                 en_i => '1',
289                 reset_i => fsm_rst,
290                 trigger_i => pwm_cycle_start,
291                 duration_i => audio_pwm_duty,
292                 q_out_o => speaker_pwm_out
293         );
294
295         irq_rq_out <= '0';
296         m00_axi_init_axi_txn <= '0';
297
298         fsm_clk <= s00_axi_aclk;
299         fsm_rst <= not s00_axi_aresetn;
300         -- User logic ends
301
302 end arch_imp;