]> rtime.felk.cvut.cz Git - fpga/zynq/canbench-sw.git/blob - system/ip/servo_led_ps2_1.0/hdl/servo_led_ps2_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 / servo_led_ps2_1.0 / hdl / servo_led_ps2_v1_0_S00_AXI.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4
5 entity servo_led_ps2_v1_0_S00_AXI is
6         generic (
7                 -- Users to add parameters here
8                 servo_pwm_width         : integer       := 24;
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       := 5
16         );
17         port (
18                 -- Users to add ports here
19                 S_REG0          : out std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
20
21                 servo_pwm_period: out std_logic_vector(servo_pwm_width-1 downto 0);
22                 servo1_pwm_duty: out std_logic_vector(servo_pwm_width-1 downto 0);
23                 servo2_pwm_duty: out std_logic_vector(servo_pwm_width-1 downto 0);
24                 servo3_pwm_duty: out std_logic_vector(servo_pwm_width-1 downto 0);
25                 servo4_pwm_duty: out std_logic_vector(servo_pwm_width-1 downto 0);
26                 -- User ports ends
27                 -- Do not modify the ports beyond this line
28
29                 -- Global Clock Signal
30                 S_AXI_ACLK      : in std_logic;
31                 -- Global Reset Signal. This Signal is Active LOW
32                 S_AXI_ARESETN   : in std_logic;
33                 -- Write address (issued by master, acceped by Slave)
34                 S_AXI_AWADDR    : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
35                 -- Write channel Protection type. This signal indicates the
36                 -- privilege and security level of the transaction, and whether
37                 -- the transaction is a data access or an instruction access.
38                 S_AXI_AWPROT    : in std_logic_vector(2 downto 0);
39                 -- Write address valid. This signal indicates that the master signaling
40                 -- valid write address and control information.
41                 S_AXI_AWVALID   : in std_logic;
42                 -- Write address ready. This signal indicates that the slave is ready
43                 -- to accept an address and associated control signals.
44                 S_AXI_AWREADY   : out std_logic;
45                 -- Write data (issued by master, acceped by Slave)
46                 S_AXI_WDATA     : in std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
47                 -- Write strobes. This signal indicates which byte lanes hold
48                 -- valid data. There is one write strobe bit for each eight
49                 -- bits of the write data bus.
50                 S_AXI_WSTRB     : in std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0);
51                 -- Write valid. This signal indicates that valid write
52                 -- data and strobes are available.
53                 S_AXI_WVALID    : in std_logic;
54                 -- Write ready. This signal indicates that the slave
55                 -- can accept the write data.
56                 S_AXI_WREADY    : out std_logic;
57                 -- Write response. This signal indicates the status
58                 -- of the write transaction.
59                 S_AXI_BRESP     : out std_logic_vector(1 downto 0);
60                 -- Write response valid. This signal indicates that the channel
61                 -- is signaling a valid write response.
62                 S_AXI_BVALID    : out std_logic;
63                 -- Response ready. This signal indicates that the master
64                 -- can accept a write response.
65                 S_AXI_BREADY    : in std_logic;
66                 -- Read address (issued by master, acceped by Slave)
67                 S_AXI_ARADDR    : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
68                 -- Protection type. This signal indicates the privilege
69                 -- and security level of the transaction, and whether the
70                 -- transaction is a data access or an instruction access.
71                 S_AXI_ARPROT    : in std_logic_vector(2 downto 0);
72                 -- Read address valid. This signal indicates that the channel
73                 -- is signaling valid read address and control information.
74                 S_AXI_ARVALID   : in std_logic;
75                 -- Read address ready. This signal indicates that the slave is
76                 -- ready to accept an address and associated control signals.
77                 S_AXI_ARREADY   : out std_logic;
78                 -- Read data (issued by slave)
79                 S_AXI_RDATA     : out std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
80                 -- Read response. This signal indicates the status of the
81                 -- read transfer.
82                 S_AXI_RRESP     : out std_logic_vector(1 downto 0);
83                 -- Read valid. This signal indicates that the channel is
84                 -- signaling the required read data.
85                 S_AXI_RVALID    : out std_logic;
86                 -- Read ready. This signal indicates that the master can
87                 -- accept the read data and response information.
88                 S_AXI_RREADY    : in std_logic
89         );
90 end servo_led_ps2_v1_0_S00_AXI;
91
92 architecture arch_imp of servo_led_ps2_v1_0_S00_AXI is
93
94         -- AXI4LITE signals
95         signal axi_awaddr       : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
96         signal axi_awready      : std_logic;
97         signal axi_wready       : std_logic;
98         signal axi_bresp        : std_logic_vector(1 downto 0);
99         signal axi_bvalid       : std_logic;
100         signal axi_araddr       : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
101         signal axi_arready      : std_logic;
102         signal axi_rdata        : std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
103         signal axi_rresp        : std_logic_vector(1 downto 0);
104         signal axi_rvalid       : std_logic;
105
106         -- Example-specific design signals
107         -- local parameter for addressing 32 bit / 64 bit C_S_AXI_DATA_WIDTH
108         -- ADDR_LSB is used for addressing 32/64 bit registers/memories
109         -- ADDR_LSB = 2 for 32 bits (n downto 2)
110         -- ADDR_LSB = 3 for 64 bits (n downto 3)
111         constant ADDR_LSB  : integer := (C_S_AXI_DATA_WIDTH/32)+ 1;
112         constant OPT_MEM_ADDR_BITS : integer := 2;
113         ------------------------------------------------
114         ---- Signals for user logic register space example
115         --------------------------------------------------
116         ---- Number of Slave Registers 8
117         signal slv_reg0 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
118         signal slv_reg1 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
119         signal slv_reg2 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
120         signal slv_reg3 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
121         signal slv_reg4 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
122         signal slv_reg5 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
123         signal slv_reg6 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
124         signal slv_reg7 :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
125         signal slv_reg_rden     : std_logic;
126         signal slv_reg_wren     : std_logic;
127         signal reg_data_out     :std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
128         signal byte_index       : integer;
129
130 begin
131
132         -- User signals
133         S_REG0          <= slv_reg0;
134         servo_pwm_period <= slv_reg3(servo_pwm_width-1 downto 0);
135         servo1_pwm_duty <= slv_reg4(servo_pwm_width-1 downto 0);
136         servo2_pwm_duty <= slv_reg5(servo_pwm_width-1 downto 0);
137         servo3_pwm_duty <= slv_reg6(servo_pwm_width-1 downto 0);
138         servo4_pwm_duty <= slv_reg7(servo_pwm_width-1 downto 0);
139         -- I/O Connections assignments
140
141         S_AXI_AWREADY   <= axi_awready;
142         S_AXI_WREADY    <= axi_wready;
143         S_AXI_BRESP     <= axi_bresp;
144         S_AXI_BVALID    <= axi_bvalid;
145         S_AXI_ARREADY   <= axi_arready;
146         S_AXI_RDATA     <= axi_rdata;
147         S_AXI_RRESP     <= axi_rresp;
148         S_AXI_RVALID    <= axi_rvalid;
149         -- Implement axi_awready generation
150         -- axi_awready is asserted for one S_AXI_ACLK clock cycle when both
151         -- S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_awready is
152         -- de-asserted when reset is low.
153
154         process (S_AXI_ACLK)
155         begin
156           if rising_edge(S_AXI_ACLK) then
157             if S_AXI_ARESETN = '0' then
158               axi_awready <= '0';
159             else
160               if (axi_awready = '0' and S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') then
161                 -- slave is ready to accept write address when
162                 -- there is a valid write address and write data
163                 -- on the write address and data bus. This design
164                 -- expects no outstanding transactions.
165                 axi_awready <= '1';
166               else
167                 axi_awready <= '0';
168               end if;
169             end if;
170           end if;
171         end process;
172
173         -- Implement axi_awaddr latching
174         -- This process is used to latch the address when both
175         -- S_AXI_AWVALID and S_AXI_WVALID are valid.
176
177         process (S_AXI_ACLK)
178         begin
179           if rising_edge(S_AXI_ACLK) then
180             if S_AXI_ARESETN = '0' then
181               axi_awaddr <= (others => '0');
182             else
183               if (axi_awready = '0' and S_AXI_AWVALID = '1' and S_AXI_WVALID = '1') then
184                 -- Write Address latching
185                 axi_awaddr <= S_AXI_AWADDR;
186               end if;
187             end if;
188           end if;
189         end process;
190
191         -- Implement axi_wready generation
192         -- axi_wready is asserted for one S_AXI_ACLK clock cycle when both
193         -- S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_wready is
194         -- de-asserted when reset is low.
195
196         process (S_AXI_ACLK)
197         begin
198           if rising_edge(S_AXI_ACLK) then
199             if S_AXI_ARESETN = '0' then
200               axi_wready <= '0';
201             else
202               if (axi_wready = '0' and S_AXI_WVALID = '1' and S_AXI_AWVALID = '1') then
203                   -- slave is ready to accept write data when
204                   -- there is a valid write address and write data
205                   -- on the write address and data bus. This design
206                   -- expects no outstanding transactions.
207                   axi_wready <= '1';
208               else
209                 axi_wready <= '0';
210               end if;
211             end if;
212           end if;
213         end process;
214
215         -- Implement memory mapped register select and write logic generation
216         -- The write data is accepted and written to memory mapped registers when
217         -- axi_awready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted. Write strobes are used to
218         -- select byte enables of slave registers while writing.
219         -- These registers are cleared when reset (active low) is applied.
220         -- Slave register write enable is asserted when valid address and data are available
221         -- and the slave is ready to accept the write address and write data.
222         slv_reg_wren <= axi_wready and S_AXI_WVALID and axi_awready and S_AXI_AWVALID ;
223
224         process (S_AXI_ACLK)
225         variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
226         begin
227           if rising_edge(S_AXI_ACLK) then
228             if S_AXI_ARESETN = '0' then
229               slv_reg0 <= (others => '0');
230               slv_reg1 <= (others => '0');
231               slv_reg2 <= (others => '0');
232               slv_reg3 <= (others => '0');
233               slv_reg4 <= (others => '0');
234               slv_reg5 <= (others => '0');
235               slv_reg6 <= (others => '0');
236               slv_reg7 <= (others => '0');
237             else
238               loc_addr := axi_awaddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
239               if (slv_reg_wren = '1') then
240                 case loc_addr is
241                   when b"000" =>
242                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
243                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
244                         -- Respective byte enables are asserted as per write strobes
245                         -- slave registor 0
246                         slv_reg0(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
247                       end if;
248                     end loop;
249                   when b"001" =>
250                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
251                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
252                         -- Respective byte enables are asserted as per write strobes
253                         -- slave registor 1
254                         slv_reg1(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
255                       end if;
256                     end loop;
257                   when b"010" =>
258                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
259                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
260                         -- Respective byte enables are asserted as per write strobes
261                         -- slave registor 2
262                         slv_reg2(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
263                       end if;
264                     end loop;
265                   when b"011" =>
266                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
267                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
268                         -- Respective byte enables are asserted as per write strobes
269                         -- slave registor 3
270                         slv_reg3(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
271                       end if;
272                     end loop;
273                   when b"100" =>
274                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
275                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
276                         -- Respective byte enables are asserted as per write strobes
277                         -- slave registor 4
278                         slv_reg4(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
279                       end if;
280                     end loop;
281                   when b"101" =>
282                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
283                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
284                         -- Respective byte enables are asserted as per write strobes
285                         -- slave registor 5
286                         slv_reg5(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
287                       end if;
288                     end loop;
289                   when b"110" =>
290                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
291                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
292                         -- Respective byte enables are asserted as per write strobes
293                         -- slave registor 6
294                         slv_reg6(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
295                       end if;
296                     end loop;
297                   when b"111" =>
298                     for byte_index in 0 to (C_S_AXI_DATA_WIDTH/8-1) loop
299                       if ( S_AXI_WSTRB(byte_index) = '1' ) then
300                         -- Respective byte enables are asserted as per write strobes
301                         -- slave registor 7
302                         slv_reg7(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
303                       end if;
304                     end loop;
305                   when others =>
306                     slv_reg0 <= slv_reg0;
307                     slv_reg1 <= slv_reg1;
308                     slv_reg2 <= slv_reg2;
309                     slv_reg3 <= slv_reg3;
310                     slv_reg4 <= slv_reg4;
311                     slv_reg5 <= slv_reg5;
312                     slv_reg6 <= slv_reg6;
313                     slv_reg7 <= slv_reg7;
314                 end case;
315               end if;
316             end if;
317           end if;
318         end process;
319
320         -- Implement write response logic generation
321         -- The write response and response valid signals are asserted by the slave
322         -- when axi_wready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted.
323         -- This marks the acceptance of address and indicates the status of
324         -- write transaction.
325
326         process (S_AXI_ACLK)
327         begin
328           if rising_edge(S_AXI_ACLK) then
329             if S_AXI_ARESETN = '0' then
330               axi_bvalid  <= '0';
331               axi_bresp   <= "00"; --need to work more on the responses
332             else
333               if (axi_awready = '1' and S_AXI_AWVALID = '1' and axi_wready = '1' and S_AXI_WVALID = '1' and axi_bvalid = '0'  ) then
334                 axi_bvalid <= '1';
335                 axi_bresp  <= "00";
336               elsif (S_AXI_BREADY = '1' and axi_bvalid = '1') then   --check if bready is asserted while bvalid is high)
337                 axi_bvalid <= '0';                                 -- (there is a possibility that bready is always asserted high)
338               end if;
339             end if;
340           end if;
341         end process;
342
343         -- Implement axi_arready generation
344         -- axi_arready is asserted for one S_AXI_ACLK clock cycle when
345         -- S_AXI_ARVALID is asserted. axi_awready is
346         -- de-asserted when reset (active low) is asserted.
347         -- The read address is also latched when S_AXI_ARVALID is
348         -- asserted. axi_araddr is reset to zero on reset assertion.
349
350         process (S_AXI_ACLK)
351         begin
352           if rising_edge(S_AXI_ACLK) then
353             if S_AXI_ARESETN = '0' then
354               axi_arready <= '0';
355               axi_araddr  <= (others => '1');
356             else
357               if (axi_arready = '0' and S_AXI_ARVALID = '1') then
358                 -- indicates that the slave has acceped the valid read address
359                 axi_arready <= '1';
360                 -- Read Address latching
361                 axi_araddr  <= S_AXI_ARADDR;
362               else
363                 axi_arready <= '0';
364               end if;
365             end if;
366           end if;
367         end process;
368
369         -- Implement axi_arvalid generation
370         -- axi_rvalid is asserted for one S_AXI_ACLK clock cycle when both
371         -- S_AXI_ARVALID and axi_arready are asserted. The slave registers
372         -- data are available on the axi_rdata bus at this instance. The
373         -- assertion of axi_rvalid marks the validity of read data on the
374         -- bus and axi_rresp indicates the status of read transaction.axi_rvalid
375         -- is deasserted on reset (active low). axi_rresp and axi_rdata are
376         -- cleared to zero on reset (active low).
377         process (S_AXI_ACLK)
378         begin
379           if rising_edge(S_AXI_ACLK) then
380             if S_AXI_ARESETN = '0' then
381               axi_rvalid <= '0';
382               axi_rresp  <= "00";
383             else
384               if (axi_arready = '1' and S_AXI_ARVALID = '1' and axi_rvalid = '0') then
385                 -- Valid read data is available at the read data bus
386                 axi_rvalid <= '1';
387                 axi_rresp  <= "00"; -- 'OKAY' response
388               elsif (axi_rvalid = '1' and S_AXI_RREADY = '1') then
389                 -- Read data is accepted by the master
390                 axi_rvalid <= '0';
391               end if;
392             end if;
393           end if;
394         end process;
395
396         -- Implement memory mapped register select and read logic generation
397         -- Slave register read enable is asserted when valid address is available
398         -- and the slave is ready to accept the read address.
399         slv_reg_rden <= axi_arready and S_AXI_ARVALID and (not axi_rvalid) ;
400
401         process (slv_reg0, slv_reg1, slv_reg2, slv_reg3, slv_reg4, slv_reg5, slv_reg6, slv_reg7, axi_araddr, S_AXI_ARESETN, slv_reg_rden)
402         variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
403         begin
404             -- Address decoding for reading registers
405             loc_addr := axi_araddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
406             case loc_addr is
407               when b"000" =>
408                 reg_data_out <= slv_reg0;
409               when b"001" =>
410                 reg_data_out <= slv_reg1;
411               when b"010" =>
412                 reg_data_out <= slv_reg2;
413               when b"011" =>
414                 reg_data_out <= slv_reg3;
415               when b"100" =>
416                 reg_data_out <= slv_reg4;
417               when b"101" =>
418                 reg_data_out <= slv_reg5;
419               when b"110" =>
420                 reg_data_out <= slv_reg6;
421               when b"111" =>
422                 reg_data_out <= slv_reg7;
423               when others =>
424                 reg_data_out  <= (others => '0');
425             end case;
426         end process;
427
428         -- Output register or memory read data
429         process( S_AXI_ACLK ) is
430         begin
431           if (rising_edge (S_AXI_ACLK)) then
432             if ( S_AXI_ARESETN = '0' ) then
433               axi_rdata  <= (others => '0');
434             else
435               if (slv_reg_rden = '1') then
436                 -- When there is a valid read address (S_AXI_ARVALID) with
437                 -- acceptance of read address by the slave (axi_arready),
438                 -- output the read dada
439                 -- Read address mux
440                   axi_rdata <= reg_data_out;     -- register read data
441               end if;
442             end if;
443           end if;
444         end process;
445
446
447         -- Add user logic here
448
449         -- User logic ends
450
451 end arch_imp;