Zing参考设计.docx_第1页
Zing参考设计.docx_第2页
Zing参考设计.docx_第3页
Zing参考设计.docx_第4页
Zing参考设计.docx_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

按键点灯设计 (使用14.3版本软件)本参考设计基于zing开发板。主要是熟悉zynq器件开发及调试的基本步骤。主要包括,uart测试、采用pl端逻辑设计ps外设、axi总线chipscope调试、定时器中断设计、按键及点灯的设计。一、建立工程:1、 打开planahead开始设计。2、 点击create new project建立新的工程- next- 填好项目名称和文件路径 next - rtl project - next - next - next 直至界面:3、 如图,选择xilinx zc702开发板 next finish二、添加arm处理器 1、点击add sources -选择add or create embedded sources - next -create sub-design - 填入处理器名称 - finish 2、弹出对话框,是否使用base system builder,选择yes 3、默认采用axi总线架构,点ok 4、默认选择xilinx zc702开发板,点next 5、remove gpio_sw and leds_4bits,点finish 此时已添加和ps部分,并参照xilinx zc702开发板设计配置好外设、时钟、ddr内存等。三、添加pl部分的外设,并连接到ps上 1、添加一个外部按键。点击ip catalog- 展开general purpose io菜单 -双击axi general purpose io 2、点击yes - 把channel 1中的gpio data channel width改为1,点击ok,用pl部分逻辑实现一个板上按键。4、 弹出对话框,是否把添加的ip连接到处理器总线上。默认选择,点ok。 5、此时在zynq的菜单下可以看到,ps部分的gp0口被使能了。刚加入的gpio ip连接到了处理器上。点击address菜单可以看到给其分配了0x41200000地址。6、同样的方法加入定时器ip。双击axi timer/counter - yes - ok - ok 7、切换到ports菜单,展开processing_system7_0,点击l to h: no connection 8、把定时器的中断信号添加到右边,可以看到系统自动给其分配了中断号91,点击ok四、使能ps部分的外设gpio,并使用emio1、切换到zynq菜单,点击i/o peripherals 2、把gpio改为用emio,把位宽改为1。用emio实现一个板上按键。 3、切换到ports菜单,把gpio的管脚连接到外部。五、添加chipscope模块用来观察axi总线上的信号。 1、在ip catalog中找到chipscope axi monitor ip,双击添加,点yes,点ok。 2、双击添加chipscope intergrated controller,点yes,点ok。 3、切换到bus interfaces菜单。把mon_axi连接到gpio的s_axi总线上,用于观测pl部分gpio的总线信号。 4、切换到ports菜单,把chipscope_icon_0中的control0信号连接到chipscope_axi_monitor_0的chipscope_icon_control信号上。5、 点击drc,检查设计中是否存在错误。至此edk部分的完成。关闭edk工具,转回到planahead界面。六、添加顶层文件,管脚约束,导出硬件至sdk中。 1、在design sources中找到处理器,点右键选择create top hdl自动生成顶层文件。 2、点击add sources,添加约束文件,next- create file -输入约束名称- ok - finish 3、在constraints中找到刚添加的约束文件,双击打开。按照zing开发板的连接分配好管脚。pl部分的gpio按键指定到pu1,ps部分gpio按键指定到pu2。 4、点击generate bitstream生成pl部分的bit文件。5、待编译完成后,点击file -export - export bitstream file,输入文件名,点击save。导出pl部分的bit文件便于之后的设计。 6、点击file -export - export hardware for sdk,勾选launch sdk,点ok。七、在sdk中设计软件程序。 1、进入到sdk界面,点击file - new - application project,输入软件工程名,选择hello world,点finish。建立了一个简单的在串口上打印hello world的工程,并自动编译驱动库及程序。 2、展开led目录下src菜单,双击hellowrold.c打开文件。 3、用以下程序替换helloword.c中的内容。点击保存,程序自动编译。/* 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 #include platform.h#include xil_types.h#include xgpio.h#include xtmrctr.h#include xparameters.h#include xgpiops.h#include xil_io.h#include xil_exception.h#include xscugic.hstatic xgpiops psgpioinstanceptr;extern xgpiops_config xgpiops_configtablexpar_xgpiops_num_instances;static int ipinnumber = 10;xscugic interruptcontroller; /* instance of the interrupt controller */static xscugic_config *gicconfig;/* the configuration parameters of thecontroller */static int interruptflag;void print(char *str);extern char inbyte(void);void timer_interrupthandler(void *data, u8 tmrctrnumber)print(rn);print(rn);print(rn);print( inside timer isr n r );xtmrctr_stop(data,tmrctrnumber);/ ps gpio writtingprint(led ds23 turned on rn);xgpiops_writepin(&psgpioinstanceptr,ipinnumber,1);xtmrctr_reset(data,tmrctrnumber);print( timer isr exitn n r);print(rn);print(rn);print(rn);interruptflag = 1;int setupinterruptsystem(xscugic *xscugicinstanceptr)/* connect the interrupt controller interrupt handler to the hardware* interrupt handling logic in the arm processor.*/xil_exceptionregisterhandler(xil_exception_id_int,(xil_exceptionhandler) xscugic_interrupthandler,xscugicinstanceptr);/* enable interrupts in the arm*/xil_exceptionenable();return xst_success;int scugicinterrupt_init(u16 deviceid,xtmrctr *timerinstanceptr)int status;/* initialize the interrupt controller driver so that it is ready to* use.* */gicconfig = xscugic_lookupconfig(deviceid);if (null = gicconfig) return xst_failure;status = xscugic_cfginitialize(&interruptcontroller, gicconfig,gicconfig-cpubaseaddress);if (status != xst_success) return xst_failure;/* setup the interrupt system* */status = setupinterruptsystem(&interruptcontroller);if (status != xst_success) return xst_failure;/* connect a device driver handler that will be called when an* interrupt for the device occurs, the device driver handler performs* the specific interrupt processing for the device*/status = xscugic_connect(&interruptcontroller,xpar_fabric_axi_timer_0_interrupt_intr,(xil_exceptionhandler)xtmrctr_interrupthandler,(void *)timerinstanceptr);if (status != xst_success) return xst_failure;/* enable the interrupt for the device and then cause (simulate) an* interrupt so the handlers will be called*/xscugic_enable(&interruptcontroller, xpar_fabric_axi_timer_0_interrupt_intr);return xst_success;int main()static xgpio gpioinstance_ptr;xgpiops_config*gpioconfigptr;xtmrctr timerinstanceptr;int xstatus;u32 readstatus=0,oldreadstatus=0;/u32 effectiveadress = 0xe000a000;int ipinnumberemio = 54;u32 upindirectionemio = 0x0;/ input pin/ pin directionu32 upindirection = 0x1;int exit_flag,choice,internal_choice;init_platform();/* data = *(u32 *)(0x42800004);print(ok n);data = *(u32 *)(0x41200004);print(ok-1 n);*/print(# application starts #nr);print(rn);/step-1 :axi gpio initialization/xstatus = xgpio_initialize(&gpioinstance_ptr,xpar_axi_gpio_0_device_id);if(xst_success != xstatus)print(gpio init failednr);/step-2 :axi gpio set the direction/xgpio_setdatadirection(&gpioinstance_ptr, 1,1);/step-3 :axi timer initialization/xstatus = xtmrctr_initialize(&timerinstanceptr,xpar_axi_timer_0_device_id);if(xst_success != xstatus)print(timer init failed nr);/step-4 :set timer handler/xtmrctr_sethandler(&timerinstanceptr,timer_interrupthandler,&timerinstanceptr);/step-5 :setting timer reset value/xtmrctr_setresetvalue(&timerinstanceptr,0, /change with generic value0xf0000000);/step-6 :setting timer option (interrupt mode and auto reload )/xtmrctr_setoptions(&timerinstanceptr,xpar_axi_timer_0_device_id,(xtc_int_mode_option | xtc_auto_reload_option );/step-7 :ps gpio intialization/gpioconfigptr = xgpiops_lookupconfig(xpar_ps7_gpio_0_device_id);if(gpioconfigptr = null)return xst_failure;xstatus = xgpiops_cfginitialize(&psgpioinstanceptr,gpioconfigptr,gpioconfigptr-baseaddr);if(xst_success != xstatus)print( ps gpio init failed nr);/step-8 :ps gpio pin setting to output/xgpiops_setdirectionpin(&psgpioinstanceptr, ipinnumber,upindirection);xgpiops_setoutputenablepin(&psgpioinstanceptr, ipinnumber,1);/step-9 :emio pin setting to input port/xgpiops_setdirectionpin(&psgpioinstanceptr,ipinnumberemio,upindirectionemio);xgpiops_setoutputenablepin(&psgpioinstanceptr, ipinnumberemio,0);/step-10 : scugic interrupt controller intialization/registration of the timer isr/xstatus=scugicinterrupt_init(xpar_ps7_scugic_0_device_id,&timerinstanceptr);if(xst_success != xstatus)print( :( scugic init failed nr);/step-11 :user selection procedure to select and execute tests/exit_flag = 0;while(exit_flag != 1)print( select the operation from the below menu rn);print(# menu starts #rn);print(press 1 to use normal gpio as an input (sw5 switch)rn);print(press 2 to use emio as an input (sw7 switch)rn);print(press any other key to exitrn);print( # menu ends #rn);choice = inbyte();printf(selection : %c rn,choice);internal_choice = 1;switch(choice)/ use case for axi gpio/case 1:exit_flag = 0;print(press switch sw5 push button on board rn);print( rn);while(internal_choice != 0)readstatus = xgpio_discreteread(&gpioinstance_ptr, 1);if(1= readstatus & 0 = oldreadstatus )print($rn);print(sw5 push button pressed nr);print(led ds23 turned off rn);xgpiops_writepin(&psgpioinstanceptr,ipinnumber,0);/start timerxtmrctr_start(&timerinstanceptr,0);print(timer start nr);/wait for interrupt;print(wait for the timer interrupt to tigger rn);print($rn);print( rn);while(interruptflag != 1);interruptflag = 0;print( #rn );print(press 0 to go to main menu nr );print(press any other key to remain in axi gpio test nr );print( #rn );internal_choice = inbyte();printf(select = %c rn,internal_choice);if(internal_choice != 0)print(press switch sw5 push button on board rn);oldreadstatus = readstatus;print( rn);print( rn);break;case 2 :/usecase for ps gpio/exit_flag = 0;print(press switch sw7 push button on board rn);print( rn);while(internal_choice != 0)readstatus = xgpiops_readpin(&psgpioinstanceptr,ipinnumberemio);if(1= readstatus & 0 = oldreadstatus )print($rn);print(sw7 push button pressed nr);print(led ds23 turned off rn);xgpiops_writepin(&psgpioinstanceptr,ipinnumber,0);/start timerxtmrctr_start(&timerinstanceptr,0);print(timer start nr);/wait for interrupt;print(wait for the timer interrupt to tigger rn);print($rn);print( rn);while(interruptflag != 1);interruptflag = 0;print( #rn );print(press 0 to go to main menu nr );print(press any other key to remain in emio test nr );print( #rn );internal_choice = inbyte();printf(select = %c rn,internal_choice);if(internal_choice != 0)print(press switch sw7 push button on board rn);oldreadstatus = readstatus;print( rn);print( rn);break;default :exit_flag = 1;break;print(rn);print(*rn);print(bye rn);print(*rn);cleanup_platform();return 0;八、采用jtag模式调试程序。 1、按照下图,接好电源、jtag电缆、uart口。模式管脚js3、js4、js5、js6、js7的连接见图中所示,跳线均接2、3针。 2、点击xilinx tools - program fpga,指定之前生成的pl部分下载文件,点击program。 3、切换到terminal 1串口调试工具,点击settings,设置好串口,点击ok,串口自动连接。 4、在project explorer菜单下,选择软件工程,右键run as - run configurations,点击xilinx c/c+ elf,按照图中选择需要debug的工程,点击run。6、 在terminal 1中出现如下打印信息:# application starts # select the operation from the below menu # menu starts #press 1 to use normal gpio as an input (pu1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论