深入浅出FPGA-16-xilinx_zynq7000_EPP上一个简单实验(PS)
引言
现在的FPGA都很强大了,不仅有丰富的LE(LC),高端的还集成了CPUcore。这样,从硬件上就能做SOC,从软件上可以做嵌入式。
本节就做一个简单的实验,主要熟悉这个板子的PS资源。
15.1 实验目的
1》 熟悉zynq7000 EPP资源和design suite
2》 SDK编码,实现一个简单逻辑。
15.2 实验环境
Board :ZYNQ7000 EPP
Device:XC7Z020CLG484ACX1221
Design suite:14.1 (PlanAhead+XPS+SDK)
15.3 实验准备
a) 会planAhead创建工程
b) 简单了解和使用XPS和SDK
15.4 实验内容
a) 在XPS添加GPIO,此GPIO连到外部一个LED上。
b) 在SDK编写C代码控制GPIO来控制此LED的闪烁。
15.5 实验步骤
a) 打开planAhead,创建embedded新工程,添加PS7。
b) 打开XPS,添加GPIO。注意port名称,ucf文件里要用。
c) 添加UCF文件,内容:simple_led.ucf。
d) Create TOP HDL,然后生成bitstream。
e) 导出hardware,launch SDK。
f) 在SDK里创建helloword工程。
g) SDK编码,内容:helloworld.c。
h) Program FPGA
i) Run AS,configure
j) Run
15.6 实验结果
看板子,DS18这个led会闪烁。下图是串口打印信息:可以看到,可以通过软件来控制GPIO,就像在单片机上开发一样。
附:
SDK 代码:
/* * Copyright (c) 2009 Xilinx, Inc. All rights reserved. * * Xilinx, Inc. * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A * COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS * ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION. * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. * *//* * helloworld.c: simple test application */#include <stdio.h>#include "platform.h"#include "../../hello_world_bsp_0/ps7_cortexa9_0/include/xgpio.h"#include "../../hello_world_bsp_0/ps7_cortexa9_0/include/xparameters.h"#define MY_GPIO_DEVICE_ID XPAR_AXI_GPIO_0_DEVICE_IDvoid my_process(void);void led_flash(XGpio* led_p,unsigned int time,int count);void my_delay(int times);int main(){ init_platform(); my_process(); printf("my_process end!\r\n"); cleanup_platform(); return 0;}//==========================void my_process(void){XGpio led;int ret = 0;int read_led = 0;printf("my_process start...\n");ret = XGpio_Initialize(&led,MY_GPIO_DEVICE_ID);//led initif(0 != ret){printf("led init error:%d\n",ret);}else{printf("led init ok!%d \n\n",ret);}XGpio_SetDataDirection(&led,1,0x00000000);printf("setdir: input!\n\n");led_flash(&led,0xffffff,100);#if 0read_led = XGpio_DiscreteRead(&led,1);//init readprintf("before led read:%d\n\n",read_led);XGpio_DiscreteWrite(&led,1,0);//write 0printf("write 0!\n\n\n");read_led = XGpio_DiscreteRead(&led,1);//read againprintf("led read:%d\n\n",read_led);XGpio_DiscreteWrite(&led,1,1);//write 1printf("write 1!\n\n\n");read_led = XGpio_DiscreteRead(&led,1);//read againprintf("led read:%d\n\n",read_led);#endifreturn;}void my_delay(int times){while(times--){;//do nothing.}}void led_flash(XGpio* led_p,unsigned int time,int count){int loop = 0;for(loop=0;loop<count;loop++){XGpio_DiscreteWrite(led_p,1,1);//write 0my_delay(time);XGpio_DiscreteWrite(led_p,1,0);//write 0my_delay(time);}}