電子發燒友網核心提示:ZedBoard開發板上的Zynq是一個ARM PS(processing system, 雙核A9 + 存儲管理 + 外設)+ PL(programable Logic) 結構,如果不使用PL,zynq的開發和普通的ARM 開發一樣。不同的是ARM PS是可配置,因而硬件信息是不固定的。這也是zynq靈活性的一個表現。電子發燒友網編輯現為讀者整合《玩轉賽靈思Zedboard開發板》系列文章, 其中包括在ZedBoard開發板上的一些應用實例。其內容包括:
玩轉賽靈思Zedboard開發板(1):ZedBoard詳解
玩轉賽靈思Zedboard開發板(2):ZedBoard最簡單的測試工程
玩轉賽靈思Zedboard開發板(3):基于Zynq PL的流水燈
玩轉賽靈思Zedboard開發板(4):如何使用自帶外設IP讓ARM PS訪問FPGA?
本文為玩轉賽靈思Zedboard開發板(5):基于AXI Lite 總線的從設備IP設計,內容精彩,敬請對電子發燒友網保持密切關注。本小節通過使用XPS中的定制IP向導(ipwiz),為已經存在的ARM PS 系統添加用戶自定IP(Custom IP ),了解AXI Lite IP基本結構,并掌握AXI Lite IP的定制方法,為后續編寫復雜AXI IP打下基礎。同時本小節IP定制方法同樣適用于MicroBlaze處理系統。本小節定制的是簡單LED的IP,只有一個數據寄存器,向其寫值就可以控 制8個LED相應亮滅。更多賽靈思(Xilinx)Zedboard基礎知識、相關手冊以及應用實例將陸續推出,以饗讀者,敬請期待。【本文的完整工程文件下載:見本文最后。】
硬件平臺:Digilent ZedBoard;開發環境:Windows XP 32 bit;軟件: XPS 14.2 +SDK 14.2。
一、創建ARM PS系統
同前面幾節一樣,首先使用XPS創建ARM PS系統。需要注意的是,在選擇外設時,同樣不要添加任何外設
二、定制AXI IP
ARM PS系統創建結束后,就可以開始定制用戶自定義IP。XPS提供了Create or Import Peripheral Wizward 向導,使得用戶自定義IP的創建變得非常簡單。當然在熟悉了AXI IP核結構和代碼編寫規則后,可以直接編寫自己的IP核而不使用向導。這里采用向導方式。
1、產生AXI IP外設模版
Hardware->Create or Import Peripheral Wizward ,啟動向導
歡迎界面
選擇從模板創建新外設
默認是將外設直接包含到當前XPS工程中
填入外設名。注意必須都是小寫。這里我們建立的是my_axi_ip。下面是版本控制,可以根據需要修改。同時面板的最下方還提示了將創建名為my_axi_ip_v1_00_a的庫(其實就是一個目錄),所有實現這個IP的HDL文件都在這個庫中。
接下來要選擇外設總線的類型。AXI4_Lite為最基本的AXI 總線,用于簡單處理,所有空間訪問都是通過地址/寄存器方式訪問,不支持突發;AXI4是標準AXI4總線標準,支持突然,支持高速;AXI4_Stream專門為數據流而設計。
在IPIF (IP 接口) 配置,這里配置接口的一些屬性,如是否是AXI 主/從設備等。我們所定制的IP是一個從設備,因而不需要使用主設備接口。
選擇需要的寄存器數量。因為我們只需要一個數據寄存器,這里選1。
接下來就是IPIC(IP 互聯),也就是IP的接口信號。以BUS2開頭的信號,意味對IP來說,這些信號是輸入信號;同樣IP2BUS意味著輸出信號。
這里一些信號做一些說明。
BUS2IP_WrCE(Write Chip Enable,寫使能)
Active high chip enable bus to the user logic. These chip enables are asserted only during active write transaction requests with the target address space and in conjunction with the corresponding sub-address within the space. Typically used for user logic writable registers selection.
BUS2IP_Data(Write Data,寫數據)
Write data bus to the user logic. Write data is accepted by the user logic during a write operation by assertion of the write acknowledgement signal and the rising edge of the Bus2IP_Clk.
BUS2IP_BE(Byte Enable,字節使能)
Byte Enable qualifiers for the requested read or write operation to the user logic. A bit in the Bus2IP_BE set to '1' indicates that the associated byte lane contains valid data. For example, if Bus2IP_BE = 0011, this indicates that byte lanes 2 and 3 contain valid data.
IPBUS2_RdAck(Read Acknowledgement,讀反饋)
Active high read data qualifier providing the read acknowledgement from the user logic. Read data on the IP2Bus_Data bus is deemed valid at the rising edge of the Bus2IP_Clk and IP2Bus_RdAck asserted high by the user logic.
接下來需要使用需要使用BFM (Bus Functional Models, 總線功能模型)對外設進行仿真。本例IP很簡單,不要使用。
最后,需要選擇HDL類型、ISE工程支持和軟件驅動模板。因為我比較習慣使用verilog,因而使用verilog模板。需要說明的是,IP接口仍然是VHDL編寫,只是用戶邏輯改用verilog。如果不需要使用軟件驅動模板的話,可以不選上。這里選上了,但是后續編程的時候我并沒有用。
最后給出了外設的信息summary。支持,my_axi_ip"外殼"基本完成。后續我們只需要對user_logic進行編寫,并修改元件引腳即可。
2、編寫IP
修改.mpd文件,在目錄
Lab4pcoresmy_axi_ip_v1_00_adata
其中,第39行
PORT LED = "", DIR = O, VEC = [7:0]
是我們添加上的,表明我們為其添加了一個名為LED的端口,方向是輸出,長度是8位。其他行代碼為默認,不需要修改。
修改用戶邏輯,在
Lab4pcoresmy_axi_ip_v1_00_ahdlveriloguser_logic.v
代碼中57、86行
LED,
output [7:0] LED;
表明在用戶邏輯中,定義了名為LED的端口,方向是輸出,長度為8。
代碼中119行
assign LED = slv_reg0[7:0];
表明將slv_reg0的低8位傳遞給輸出端口LED。其實就是實現了數據寄存器的值作用到輸出端口的功能。
需要將用戶邏輯和IPIF連接上,需要完成user_logic的例化
Lab4pcoresmy_axi_ip_v1_00_ahdlvhdlmy_axi_ip.vhd
1 ------------------------------------------------------------------------------
2 -- my_axi_ip.vhd - entity/architecture pair
3 ------------------------------------------------------------------------------
4 -- IMPORTANT:
5 -- DO NOT MODIFY THIS FILE EXCEPT IN THE DESIGNATED SECTIONS.
6 --
7 -- SEARCH FOR --USER TO DETERMINE WHERE CHANGES ARE ALLOWED.
8 --
9 -- TYPICALLY, THE ONLY ACCEPTABLE CHANGES INVOLVE ADDING NEW
10 -- PORTS AND GENERICS THAT GET PASSED THROUGH TO THE INSTANTIATION
11 -- OF THE USER_LOGIC ENTITY.
12 ------------------------------------------------------------------------------
13 --
14 -- ***************************************************************************
15 -- ** Copyright (c) 1995-2012 Xilinx, Inc. All rights reserved. **
16 -- ** **
17 -- ** Xilinx, Inc. **
18 -- ** XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" **
19 -- ** AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND **
20 -- ** SOLUTIONS FOR XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE, **
21 -- ** OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, **
22 -- ** APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION **
23 -- ** THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT, **
24 -- ** AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE **
25 -- ** FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY **
26 -- ** WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE **
27 -- ** IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR **
28 -- ** REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF **
29 -- ** INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS **
30 -- ** FOR A PARTICULAR PURPOSE. **
31 -- ** **
32 -- ***************************************************************************
33 --
34 ------------------------------------------------------------------------------
35 -- Filename: my_axi_ip.vhd
36 -- Version: 1.00.a
37 -- Description: Top level design, instantiates library components and user logic.
38 -- Date: Tue Oct 09 18:28:06 2012 (by Create and Import Peripheral Wizard)
39 -- VHDL Standard: VHDL'93
40 ------------------------------------------------------------------------------
41 -- Naming Conventions:
42 -- active low signals: "*_n"
43 -- clock signals: "clk", "clk_div#", "clk_#x"
44 -- reset signals: "rst", "rst_n"
45 -- generics: "C_*"
46 -- user defined types: "*_TYPE"
47 -- state machine next state: "*_ns"
48 -- state machine current state: "*_cs"
49 -- combinatorial signals: "*_com"
50 -- pipelined or register delay signals: "*_d#"
51 -- counter signals: "*cnt*"
52 -- clock enable signals: "*_ce"
53 -- internal version of output port: "*_i"
54 -- device pins: "*_pin"
55 -- ports: "- Names begin with Uppercase"
56 -- processes: "*_PROCESS"
57 -- component instantiations: "I_<#|FUNC>"
58 ------------------------------------------------------------------------------
59
60 library ieee;
61 use ieee.std_logic_1164.all;
62 use ieee.std_logic_arith.all;
63 use ieee.std_logic_unsigned.all;
64
65 library proc_common_v3_00_a;
66 use proc_common_v3_00_a.proc_common_pkg.all;
67 use proc_common_v3_00_a.ipif_pkg.all;
68
69 library axi_lite_ipif_v1_01_a;
70 use axi_lite_ipif_v1_01_a.axi_lite_ipif;
71
72 ------------------------------------------------------------------------------
73 -- Entity section
74 ------------------------------------------------------------------------------
75 -- Definition of Generics:
76 -- C_S_AXI_DATA_WIDTH -- AXI4LITE slave: Data width
77 -- C_S_AXI_ADDR_WIDTH -- AXI4LITE slave: Address Width
78 -- C_S_AXI_MIN_SIZE -- AXI4LITE slave: Min Size
79 -- C_USE_WSTRB -- AXI4LITE slave: Write Strobe
80 -- C_DPHASE_TIMEOUT -- AXI4LITE slave: Data Phase Timeout
81 -- C_BASEADDR -- AXI4LITE slave: base address
82 -- C_HIGHADDR -- AXI4LITE slave: high address
83 -- C_FAMILY -- FPGA Family
84 -- C_NUM_REG -- Number of software accessible registers
85 -- C_NUM_MEM -- Number of address-ranges
86 -- C_SLV_AWIDTH -- Slave interface address bus width
87 -- C_SLV_DWIDTH -- Slave interface data bus width
88 --
89 -- Definition of Ports:
90 -- S_AXI_ACLK -- AXI4LITE slave: Clock
91 -- S_AXI_ARESETN -- AXI4LITE slave: Reset
92 -- S_AXI_AWADDR -- AXI4LITE slave: Write address
93 -- S_AXI_AWVALID -- AXI4LITE slave: Write address valid
94 -- S_AXI_WDATA -- AXI4LITE slave: Write data
95 -- S_AXI_WSTRB -- AXI4LITE slave: Write strobe
96 -- S_AXI_WVALID -- AXI4LITE slave: Write data valid
97 -- S_AXI_BREADY -- AXI4LITE slave: Response ready
98 -- S_AXI_ARADDR -- AXI4LITE slave: Read address
99 -- S_AXI_ARVALID -- AXI4LITE slave: Read address valid
100 -- S_AXI_RREADY -- AXI4LITE slave: Read data ready
101 -- S_AXI_ARREADY -- AXI4LITE slave: read addres ready
102 -- S_AXI_RDATA -- AXI4LITE slave: Read data
103 -- S_AXI_RRESP -- AXI4LITE slave: Read data response
104 -- S_AXI_RVALID -- AXI4LITE slave: Read data valid
105 -- S_AXI_WREADY -- AXI4LITE slave: Write data ready
106 -- S_AXI_BRESP -- AXI4LITE slave: Response
107 -- S_AXI_BVALID -- AXI4LITE slave: Resonse valid
108 -- S_AXI_AWREADY -- AXI4LITE slave: Wrte address ready
109 ------------------------------------------------------------------------------
110
111 entity my_axi_ip is
112 generic
113 (
114 -- ADD USER GENERICS BELOW THIS LINE ---------------
115 --USER generics added here
116 -- ADD USER GENERICS ABOVE THIS LINE ---------------
117
118 -- DO NOT EDIT BELOW THIS LINE ---------------------
119 -- Bus protocol parameters, do not add to or delete
120 C_S_AXI_DATA_WIDTH : integer := 32;
121 C_S_AXI_ADDR_WIDTH : integer := 32;
122 C_S_AXI_MIN_SIZE : std_logic_vector := X"000001FF";
123 C_USE_WSTRB : integer := 0;
124 C_DPHASE_TIMEOUT : integer := 8;
125 C_BASEADDR : std_logic_vector := X"FFFFFFFF";
126 C_HIGHADDR : std_logic_vector := X"00000000";
127 C_FAMILY : string := "virtex6";
128 C_NUM_REG : integer := 1;
129 C_NUM_MEM : integer := 1;
130 C_SLV_AWIDTH : integer := 32;
131 C_SLV_DWIDTH : integer := 32
132 -- DO NOT EDIT ABOVE THIS LINE ---------------------
133 );
134 port
135 (
136 -- ADD USER PORTS BELOW THIS LINE ------------------
137 LED : out std_logic_vector(7 downto 0);
138 -- ADD USER PORTS ABOVE THIS LINE ------------------
139
140 -- DO NOT EDIT BELOW THIS LINE ---------------------
141 -- Bus protocol ports, do not add to or delete
142 S_AXI_ACLK : in std_logic;
143 S_AXI_ARESETN : in std_logic;
144 S_AXI_AWADDR : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
145 S_AXI_AWVALID : in std_logic;
146 S_AXI_WDATA : in std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
147 S_AXI_WSTRB : in std_logic_vector((C_S_AXI_DATA_WIDTH/8)-1 downto 0);
148 S_AXI_WVALID : in std_logic;
149 S_AXI_BREADY : in std_logic;
150 S_AXI_ARADDR : in std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
151 S_AXI_ARVALID : in std_logic;
152 S_AXI_RREADY : in std_logic;
153 S_AXI_ARREADY : out std_logic;
154 S_AXI_RDATA : out std_logic_vector(C_S_AXI_DATA_WIDTH-1 downto 0);
155 S_AXI_RRESP : out std_logic_vector(1 downto 0);
156 S_AXI_RVALID : out std_logic;
157 S_AXI_WREADY : out std_logic;
158 S_AXI_BRESP : out std_logic_vector(1 downto 0);
159 S_AXI_BVALID : out std_logic;
160 S_AXI_AWREADY : out std_logic
161 -- DO NOT EDIT ABOVE THIS LINE ---------------------
162 );
163
164 attribute MAX_FANOUT : string;
165 attribute SIGIS : string;
166 attribute MAX_FANOUT of S_AXI_ACLK : signal is "10000";
167 attribute MAX_FANOUT of S_AXI_ARESETN : signal is "10000";
168 attribute SIGIS of S_AXI_ACLK : signal is "Clk";
169 attribute SIGIS of S_AXI_ARESETN : signal is "Rst";
170 end entity my_axi_ip;
171
172 ------------------------------------------------------------------------------
173 -- Architecture section
174 ------------------------------------------------------------------------------
175
176 architecture IMP of my_axi_ip is
177
178 constant USER_SLV_DWIDTH : integer := C_S_AXI_DATA_WIDTH;
179
180 constant IPIF_SLV_DWIDTH : integer := C_S_AXI_DATA_WIDTH;
181
182 constant ZERO_ADDR_PAD : std_logic_vector(0 to 31) := (others => '0');
183 constant USER_SLV_BASEADDR : std_logic_vector := C_BASEADDR;
184 constant USER_SLV_HIGHADDR : std_logic_vector := C_HIGHADDR;
185
186 constant IPIF_ARD_ADDR_RANGE_ARRAY : SLV64_ARRAY_TYPE :=
187 (
188 ZERO_ADDR_PAD & USER_SLV_BASEADDR, -- user logic slave space base address
189 ZERO_ADDR_PAD & USER_SLV_HIGHADDR -- user logic slave space high address
190 );
191
192 constant USER_SLV_NUM_REG : integer := 1;
193 constant USER_NUM_REG : integer := USER_SLV_NUM_REG;
194 constant TOTAL_IPIF_CE : integer := USER_NUM_REG;
195
196 constant IPIF_ARD_NUM_CE_ARRAY : INTEGER_ARRAY_TYPE :=
197 (
198 0 => (USER_SLV_NUM_REG) -- number of ce for user logic slave space
199 );
200
201 ------------------------------------------
202 -- Index for CS/CE
203 ------------------------------------------
204 constant USER_SLV_CS_INDEX : integer := 0;
205 constant USER_SLV_CE_INDEX : integer := calc_start_ce_index(IPIF_ARD_NUM_CE_ARRAY, USER_SLV_CS_INDEX);
206
207 constant USER_CE_INDEX : integer := USER_SLV_CE_INDEX;
208
209 ------------------------------------------
210 -- IP Interconnect (IPIC) signal declarations
211 ------------------------------------------
212 signal ipif_Bus2IP_Clk : std_logic;
213 signal ipif_Bus2IP_Resetn : std_logic;
214 signal ipif_Bus2IP_Addr : std_logic_vector(C_S_AXI_ADDR_WIDTH-1 downto 0);
215 signal ipif_Bus2IP_RNW : std_logic;
216 signal ipif_Bus2IP_BE : std_logic_vector(IPIF_SLV_DWIDTH/8-1 downto 0);
217 signal ipif_Bus2IP_CS : std_logic_vector((IPIF_ARD_ADDR_RANGE_ARRAY'LENGTH)/2-1 downto 0);
218 signal ipif_Bus2IP_RdCE : std_logic_vector(calc_num_ce(IPIF_ARD_NUM_CE_ARRAY)-1 downto 0);
219 signal ipif_Bus2IP_WrCE : std_logic_vector(calc_num_ce(IPIF_ARD_NUM_CE_ARRAY)-1 downto 0);
220 signal ipif_Bus2IP_Data : std_logic_vector(IPIF_SLV_DWIDTH-1 downto 0);
221 signal ipif_IP2Bus_WrAck : std_logic;
222 signal ipif_IP2Bus_RdAck : std_logic;
223 signal ipif_IP2Bus_Error : std_logic;
224 signal ipif_IP2Bus_Data : std_logic_vector(IPIF_SLV_DWIDTH-1 downto 0);
225 signal user_Bus2IP_RdCE : std_logic_vector(USER_NUM_REG-1 downto 0);
226 signal user_Bus2IP_WrCE : std_logic_vector(USER_NUM_REG-1 downto 0);
227 signal user_IP2Bus_Data : std_logic_vector(USER_SLV_DWIDTH-1 downto 0);
228 signal user_IP2Bus_RdAck : std_logic;
229 signal user_IP2Bus_WrAck : std_logic;
230 signal user_IP2Bus_Error : std_logic;
231
232 ------------------------------------------
233 -- Component declaration for verilog user logic
234 ------------------------------------------
235 component user_logic is
236 generic
237 (
238 -- ADD USER GENERICS BELOW THIS LINE ---------------
239 --USER generics added here
240 -- ADD USER GENERICS ABOVE THIS LINE ---------------
241
242 -- DO NOT EDIT BELOW THIS LINE ---------------------
243 -- Bus protocol parameters, do not add to or delete
244 C_NUM_REG : integer := 1;
245 C_SLV_DWIDTH : integer := 32
246 -- DO NOT EDIT ABOVE THIS LINE ---------------------
247 );
248 port
249 (
250 -- ADD USER PORTS BELOW THIS LINE ------------------
251 LED : out std_logic_vector(7 downto 0);
252 -- ADD USER PORTS ABOVE THIS LINE ------------------
253
254 -- DO NOT EDIT BELOW THIS LINE ---------------------
255 -- Bus protocol ports, do not add to or delete
256 Bus2IP_Clk : in std_logic;
257 Bus2IP_Resetn : in std_logic;
258 Bus2IP_Data : in std_logic_vector(C_SLV_DWIDTH-1 downto 0);
259 Bus2IP_BE : in std_logic_vector(C_SLV_DWIDTH/8-1 downto 0);
260 Bus2IP_RdCE : in std_logic_vector(C_NUM_REG-1 downto 0);
261 Bus2IP_WrCE : in std_logic_vector(C_NUM_REG-1 downto 0);
262 IP2Bus_Data : out std_logic_vector(C_SLV_DWIDTH-1 downto 0);
263 IP2Bus_RdAck : out std_logic;
264 IP2Bus_WrAck : out std_logic;
265 IP2Bus_Error : out std_logic
266 -- DO NOT EDIT ABOVE THIS LINE ---------------------
267 );
268 end component user_logic;
269
270 begin
271
272 ------------------------------------------
273 -- instantiate axi_lite_ipif
274 ------------------------------------------
275 AXI_LITE_IPIF_I : entity axi_lite_ipif_v1_01_a.axi_lite_ipif
276 generic map
277 (
278 C_S_AXI_DATA_WIDTH => IPIF_SLV_DWIDTH,
279 C_S_AXI_ADDR_WIDTH => C_S_AXI_ADDR_WIDTH,
280 C_S_AXI_MIN_SIZE => C_S_AXI_MIN_SIZE,
281 C_USE_WSTRB => C_USE_WSTRB,
282 C_DPHASE_TIMEOUT => C_DPHASE_TIMEOUT,
283 C_ARD_ADDR_RANGE_ARRAY => IPIF_ARD_ADDR_RANGE_ARRAY,
284 C_ARD_NUM_CE_ARRAY => IPIF_ARD_NUM_CE_ARRAY,
285 C_FAMILY => C_FAMILY
286 )
287 port map
288 (
289 S_AXI_ACLK => S_AXI_ACLK,
290 S_AXI_ARESETN => S_AXI_ARESETN,
291 S_AXI_AWADDR => S_AXI_AWADDR,
292 S_AXI_AWVALID => S_AXI_AWVALID,
293 S_AXI_WDATA => S_AXI_WDATA,
294 S_AXI_WSTRB => S_AXI_WSTRB,
295 S_AXI_WVALID => S_AXI_WVALID,
296 S_AXI_BREADY => S_AXI_BREADY,
297 S_AXI_ARADDR => S_AXI_ARADDR,
298 S_AXI_ARVALID => S_AXI_ARVALID,
299 S_AXI_RREADY => S_AXI_RREADY,
300 S_AXI_ARREADY => S_AXI_ARREADY,
301 S_AXI_RDATA => S_AXI_RDATA,
302 S_AXI_RRESP => S_AXI_RRESP,
303 S_AXI_RVALID => S_AXI_RVALID,
304 S_AXI_WREADY => S_AXI_WREADY,
305 S_AXI_BRESP => S_AXI_BRESP,
306 S_AXI_BVALID => S_AXI_BVALID,
307 S_AXI_AWREADY => S_AXI_AWREADY,
308 Bus2IP_Clk => ipif_Bus2IP_Clk,
309 Bus2IP_Resetn => ipif_Bus2IP_Resetn,
310 Bus2IP_Addr => ipif_Bus2IP_Addr,
311 Bus2IP_RNW => ipif_Bus2IP_RNW,
312 Bus2IP_BE => ipif_Bus2IP_BE,
313 Bus2IP_CS => ipif_Bus2IP_CS,
314 Bus2IP_RdCE => ipif_Bus2IP_RdCE,
315 Bus2IP_WrCE => ipif_Bus2IP_WrCE,
316 Bus2IP_Data => ipif_Bus2IP_Data,
317 IP2Bus_WrAck => ipif_IP2Bus_WrAck,
318 IP2Bus_RdAck => ipif_IP2Bus_RdAck,
319 IP2Bus_Error => ipif_IP2Bus_Error,
320 IP2Bus_Data => ipif_IP2Bus_Data
321 );
322
323 ------------------------------------------
324 -- instantiate User Logic
325 ------------------------------------------
326 USER_LOGIC_I : component user_logic
327 generic map
328 (
329 -- MAP USER GENERICS BELOW THIS LINE ---------------
330 --USER generics mapped here
331 -- MAP USER GENERICS ABOVE THIS LINE ---------------
332
333 C_NUM_REG => USER_NUM_REG,
334 C_SLV_DWIDTH => USER_SLV_DWIDTH
335 )
336 port map
337 (
338 -- MAP USER PORTS BELOW THIS LINE ------------------
339 LED => LED,
340 -- MAP USER PORTS ABOVE THIS LINE ------------------
341
342 Bus2IP_Clk => ipif_Bus2IP_Clk,
343 Bus2IP_Resetn => ipif_Bus2IP_Resetn,
344 Bus2IP_Data => ipif_Bus2IP_Data,
345 Bus2IP_BE => ipif_Bus2IP_BE,
346 Bus2IP_RdCE => user_Bus2IP_RdCE,
347 Bus2IP_WrCE => user_Bus2IP_WrCE,
348 IP2Bus_Data => user_IP2Bus_Data,
349 IP2Bus_RdAck => user_IP2Bus_RdAck,
350 IP2Bus_WrAck => user_IP2Bus_WrAck,
351 IP2Bus_Error => user_IP2Bus_Error
352 );
353
354 ------------------------------------------
355 -- connect internal signals
356 ------------------------------------------
357 ipif_IP2Bus_Data <= user_IP2Bus_Data;
358 ipif_IP2Bus_WrAck <= user_IP2Bus_WrAck;
359 ipif_IP2Bus_RdAck <= user_IP2Bus_RdAck;
360 ipif_IP2Bus_Error <= user_IP2Bus_Error;
361
362 user_Bus2IP_RdCE <= ipif_Bus2IP_RdCE(USER_NUM_REG-1 downto 0);
363 user_Bus2IP_WrCE <= ipif_Bus2IP_WrCE(USER_NUM_REG-1 downto 0);
364
365 end IMP;
137行
LED : out std_logic_vector(7 downto 0);
定義IP的端口為LED,這里需要和之前修改MPD文件一致。
232-268行為元件聲明
1 ------------------------------------------
2 -- Component declaration for verilog user logic
3 ------------------------------------------
4 component user_logic is
5 generic
6 (
7 -- ADD USER GENERICS BELOW THIS LINE ---------------
8 --USER generics added here
9 -- ADD USER GENERICS ABOVE THIS LINE ---------------
10
11 -- DO NOT EDIT BELOW THIS LINE ---------------------
12 -- Bus protocol parameters, do not add to or delete
13 C_NUM_REG : integer := 1;
14 C_SLV_DWIDTH : integer := 32
15 -- DO NOT EDIT ABOVE THIS LINE ---------------------
16 );
17 port
18 (
19 -- ADD USER PORTS BELOW THIS LINE ------------------
20 LED : out std_logic_vector(7 downto 0);
21 -- ADD USER PORTS ABOVE THIS LINE ------------------
22
23 -- DO NOT EDIT BELOW THIS LINE ---------------------
24 -- Bus protocol ports, do not add to or delete
25 Bus2IP_Clk : in std_logic;
26 Bus2IP_Resetn : in std_logic;
27 Bus2IP_Data : in std_logic_vector(C_SLV_DWIDTH-1 downto 0);
28 Bus2IP_BE : in std_logic_vector(C_SLV_DWIDTH/8-1 downto 0);
29 Bus2IP_RdCE : in std_logic_vector(C_NUM_REG-1 downto 0);
30 Bus2IP_WrCE : in std_logic_vector(C_NUM_REG-1 downto 0);
31 IP2Bus_Data : out std_logic_vector(C_SLV_DWIDTH-1 downto 0);
32 IP2Bus_RdAck : out std_logic;
33 IP2Bus_WrAck : out std_logic;
34 IP2Bus_Error : out std_logic
35 -- DO NOT EDIT ABOVE THIS LINE ---------------------
36 );
37 end component user_logic;
323-352行為user_logic元件例化。VHDL是不區分大小寫的。
1 ------------------------------------------
2 -- instantiate User Logic
3 ------------------------------------------
4 USER_LOGIC_I : component user_logic
5 generic map
6 (
7 -- MAP USER GENERICS BELOW THIS LINE ---------------
8 --USER generics mapped here
9 -- MAP USER GENERICS ABOVE THIS LINE ---------------
10
11 C_NUM_REG => USER_NUM_REG,
12 C_SLV_DWIDTH => USER_SLV_DWIDTH
13 )
14 port map
15 (
16 -- MAP USER PORTS BELOW THIS LINE ------------------
17 LED => LED,
18 -- MAP USER PORTS ABOVE THIS LINE ------------------
19
20 Bus2IP_Clk => ipif_Bus2IP_Clk,
21 Bus2IP_Resetn => ipif_Bus2IP_Resetn,
22 Bus2IP_Data => ipif_Bus2IP_Data,
23 Bus2IP_BE => ipif_Bus2IP_BE,
24 Bus2IP_RdCE => user_Bus2IP_RdCE,
25 Bus2IP_WrCE => user_Bus2IP_WrCE,
26 IP2Bus_Data => user_IP2Bus_Data,
27 IP2Bus_RdAck => user_IP2Bus_RdAck,
28 IP2Bus_WrAck => user_IP2Bus_WrAck,
29 IP2Bus_Error => user_IP2Bus_Error
30 );
這幾個文件修改后保存。
Project->Rescan User Repositories(更新用戶倉庫?),讓XPS識別到對IP所做的修改
三、將自定義IP核添加到PS系統
同第三篇一樣,需要將IP添加到PS系統中。
在Ports標簽中,需要將我們定義的LED端口設置為外部端口,外部引腳名按照Zedboard的習慣,定義為LD
在Address標簽中,設定IP的地址。XPS支持自定義定制范圍、空間大小等。可以使用默認設置,也可以手動設置。這里我設置基地址為 0x40000000,其實也就是我們設定的數據寄存器的地址為0x40000000。如果有更多的寄存器,會以4字節offset 地址的方式訪問即可。
最后一樣修改ucf文件,完成約束。
1 NET LD[0] LOC = T22 | IOSTANDARD=LVCMOS33; # "LD0"
2 NET LD[1] LOC = T21 | IOSTANDARD=LVCMOS33; # "LD1"
3 NET LD[2] LOC = U22 | IOSTANDARD=LVCMOS33; # "LD2"
4 NET LD[3] LOC = U21 | IOSTANDARD=LVCMOS33; # "LD3"
5 NET LD[4] LOC = V22 | IOSTANDARD=LVCMOS33; # "LD4"
6 NET LD[5] LOC = W22 | IOSTANDARD=LVCMOS33; # "LD5"
7 NET LD[6] LOC = U19 | IOSTANDARD=LVCMOS33; # "LD6"
8 NET LD[7] LOC = U14 | IOSTANDARD=LVCMOS33; # "LD7"
最后對這個系統編譯,生成bitstream文件,并將硬件配置導入到SDK,并啟動SDK。
四、使用SDK編寫IP核驅動程序和應用程序
打開SDK,可以從系統信息system.xml中看到我們的系統信息。可以看到我們實例化連接到系統的ip是my_axi_ip_0,基地址是0x4000000。
建立軟件工程后,修改main代碼,如下
//@超群天晴 http://www.cnblogs.com/surpassal/ 1 #include
2 #include "xparameters.h"
3 #include "xil_types.h"
4 #include "xstatus.h"
5 #include "xil_io.h"http://包含xil_io頭文件,完成對絕對地址的訪問
6 #include "platform.h"
7
8 #define LED_DATA_REG 0x40000000
9
10 void print(char *ptr);
11 void delay(unsigned int delaytime);
12 void LED_Play(unsigned char led);
13
14
15 int main(void)
16 {
17
18 init_platform();
19
20 print("ZedBoard LAB4: MY_AXI_LEDs ");
21 print("超群天晴 2012年10月8日22:12:31 ");
22
23 LED_Play(0x03);
24 while(1);
25
26 cleanup_platform();
27
28 return 0;
29 }
30
31
32 void delay(unsigned int delaytime)
33 {
34 int i;
35 for(i=0;i
36 ;
37 }
38
39 void LED_Play(unsigned char led)
40 {
41 for(;;)
42 {
43 led=(led<<1)|(led>>7);
44 Xil_Out32(LED_DATA_REG,led);
45 delay(50000000);
46 }
47 }
定義了兩個函數
void delay(unsigned int delaytime);
void LED_Play(unsigned char led);
其中delay()為延時函數,參數為延時時間,100000000大約延時1s;
LED_Play()為LED流水燈函數,參數是流水初始值。在程序里面設定的是0x2,也就LD0、LD1最開始亮,然后流水。
其中第8行
#define LED_DATA_REG 0x40000000
使用宏定義,定義LED_DATA_REG,實際上就是自定義IP的基地址。
第44行
Xil_Out32(LED_DATA_REG,led);
使用了xil_io.h提供的絕對地址訪問函數Xil_Out32(u32 OutAddress, u32 Value),定義如下
1 /*****************************************************************************/
2 /**
3 *
4 * Performs an output operation for a 32-bit memory location by writing the
5 * specified Value to the the specified address.
6 *
7 * @param OutAddress contains the address to perform the output operation
8 * at.
9 * @param Value contains the Value to be output at the specified address.
10 *
11 * @return None.
12 *
13 * @note None.
14 *
15 ******************************************************************************/
16 void Xil_Out32(u32 OutAddress, u32 Value)
17 {
18 /* write the contents of the I/O location and then synchronize the I/O
19 * such that the I/O operation completes before proceeding on
20 */
21 *(volatile u32 *) OutAddress = Value;
22 SYNCHRONIZE_IO;
23 }
可以看出,其實現的功能就是向32位絕對地址OutAddress中寫入32位無符號值Value。參考這樣的寫法,可以將地址訪問修改
1 #define LED_DATA_ADDR 0x40000000
2 #define LED_DATA_REG(x) *(volatile unsigned int *) LED_DATA_ADDR = x
然后修改寄存器的值,只需要修改LED_DATA_REG(x)參數x的值即可。
五、運行結果
編譯下載之后,可以從超級終端看到調試信息
同時Zedboard上的 LD 流水
================================
備注:
有關AXI協議,請參考
AXI Bus Functional Model v1.1 Product Brief
================================
完整工程代碼:定制簡單LED的IP核的設計源代碼(Lab4.rar)
評論
查看更多