2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
5 entity servo_led_ps2_v1_0_S00_AXI is
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
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
18 -- Users to add ports here
19 S_REG0 : out std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
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);
27 -- Do not modify the ports beyond this line
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
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
90 end servo_led_ps2_v1_0_S00_AXI;
92 architecture arch_imp of servo_led_ps2_v1_0_S00_AXI is
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;
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;
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
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.
156 if rising_edge(S_AXI_ACLK) then
157 if S_AXI_ARESETN = '0' then
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.
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.
179 if rising_edge(S_AXI_ACLK) then
180 if S_AXI_ARESETN = '0' then
181 axi_awaddr <= (others => '0');
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;
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.
198 if rising_edge(S_AXI_ACLK) then
199 if S_AXI_ARESETN = '0' then
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.
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 ;
225 variable loc_addr :std_logic_vector(OPT_MEM_ADDR_BITS downto 0);
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');
238 loc_addr := axi_awaddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
239 if (slv_reg_wren = '1') then
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
246 slv_reg0(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
254 slv_reg1(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
262 slv_reg2(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
270 slv_reg3(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
278 slv_reg4(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
286 slv_reg5(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
294 slv_reg6(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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
302 slv_reg7(byte_index*8+7 downto byte_index*8) <= S_AXI_WDATA(byte_index*8+7 downto byte_index*8);
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;
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.
328 if rising_edge(S_AXI_ACLK) then
329 if S_AXI_ARESETN = '0' then
331 axi_bresp <= "00"; --need to work more on the responses
333 if (axi_awready = '1' and S_AXI_AWVALID = '1' and axi_wready = '1' and S_AXI_WVALID = '1' and axi_bvalid = '0' ) then
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)
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.
352 if rising_edge(S_AXI_ACLK) then
353 if S_AXI_ARESETN = '0' then
355 axi_araddr <= (others => '1');
357 if (axi_arready = '0' and S_AXI_ARVALID = '1') then
358 -- indicates that the slave has acceped the valid read address
360 -- Read Address latching
361 axi_araddr <= S_AXI_ARADDR;
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).
379 if rising_edge(S_AXI_ACLK) then
380 if S_AXI_ARESETN = '0' then
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
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
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) ;
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);
404 -- Address decoding for reading registers
405 loc_addr := axi_araddr(ADDR_LSB + OPT_MEM_ADDR_BITS downto ADDR_LSB);
408 reg_data_out <= slv_reg0;
410 reg_data_out <= slv_reg1;
412 reg_data_out <= slv_reg2;
414 reg_data_out <= slv_reg3;
416 reg_data_out <= slv_reg4;
418 reg_data_out <= slv_reg5;
420 reg_data_out <= slv_reg6;
422 reg_data_out <= slv_reg7;
424 reg_data_out <= (others => '0');
428 -- Output register or memory read data
429 process( S_AXI_ACLK ) is
431 if (rising_edge (S_AXI_ACLK)) then
432 if ( S_AXI_ARESETN = '0' ) then
433 axi_rdata <= (others => '0');
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
440 axi_rdata <= reg_data_out; -- register read data
447 -- Add user logic here