Zing参考设计.docx
《Zing参考设计.docx》由会员分享,可在线阅读,更多相关《Zing参考设计.docx(30页珍藏版)》请在冰豆网上搜索。
![Zing参考设计.docx](https://file1.bdocx.com/fileroot1/2023-1/28/b915aaa7-3a1c-4674-9d18-5301db7f611d/b915aaa7-3a1c-4674-9d18-5301db7f611d1.gif)
Zing参考设计
按键点灯设计(使用14.3版本软件)
本参考设计基于Zing开发板。
主要是熟悉ZYNQ器件开发及调试的基本步骤。
主要包括,UART测试、采用PL端逻辑设计PS外设、AXI总线Chipscope调试、定时器中断设计、按键及点灯的设计。
一、建立工程:
1、打开PlanAhead开始设计。
2、点击CreateNewProject建立新的工程->Next->填好项目名称和文件路径Next->RTLProject->Next->Next->Next直至界面:
3、如图,选择XilinxZC702开发板Next–>Finish
二、添加ARM处理器
1、点击Addsources->选择AddorCreateEmbeddedSources->Next->CreateSub-Design->填入处理器名称->finish
2、弹出对话框,是否使用BaseSystemBuilder,选择Yes
3、默认采用AXI总线架构,点OK
4、默认选择XilinxZC702开发板,点Next
5、RemoveGPIO_SWandLEDs_4Bits,点Finish
此时已添加和PS部分,并参照XilinxZC702开发板设计配置好外设、时钟、DDR内存等。
三、添加PL部分的外设,并连接到PS上
1、添加一个外部按键。
点击IPCatalog->展开GeneralPurposeIO菜单->双击AXIGeneralPurposeIO
2、点击Yes->把Channel1中的GPIODataChannelWidth改为1,点击OK,用PL部分逻辑实现一个板上按键。
4、弹出对话框,是否把添加的IP连接到处理器总线上。
默认选择,点OK。
5、此时在ZYNQ的菜单下可以看到,PS部分的GP0口被使能了。
刚加入的GPIOIP连接到了处理器上。
点击Address菜单可以看到给其分配了0x41200000地址。
6、同样的方法加入定时器IP。
双击AXITimer/Counter->Yes->OK->OK
7、切换到Ports菜单,展开processing_system7_0,点击LtoH:
NoConnection
8、把定时器的中断信号添加到右边,可以看到系统自动给其分配了中断号91,点击OK
四、使能PS部分的外设GPIO,并使用EMIO
1、切换到ZYNQ菜单,点击I/OPeripherals
2、把GPIO改为用EMIO,把位宽改为1。
用EMIO实现一个板上按键。
3、切换到Ports菜单,把GPIO的管脚连接到外部。
五、添加Chipscope模块用来观察AXI总线上的信号。
1、在IPCatalog中找到ChipscopeAXIMonitorIP,双击添加,点Yes,点OK。
2、双击添加ChipscopeIntergratedController,点Yes,点OK。
3、切换到BusInterfaces菜单。
把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、在DesignSources中找到处理器,点右键选择CreateTopHDL自动生成顶层文件。
2、点击AddSources,添加约束文件,Next->CreateFile->输入约束名称->OK->Finish
3、在Constraints中找到刚添加的约束文件,双击打开。
按照Zing开发板的连接分配好管脚。
PL部分的GPIO按键指定到PU1,PS部分GPIO按键指定到PU2。
4、点击GenerateBitstream生成PL部分的Bit文件。
5、待编译完成后,点击File->Export->ExportBitstreamFile,输入文件名,点击Save。
导出PL部分的bit文件便于之后的设计。
6、点击File->Export->ExportHardwareForSDK,勾选LaunchSDK,点OK。
七、在SDK中设计软件程序。
1、进入到SDK界面,点击File->New->ApplicationProject,输入软件工程名,选择HelloWorld,点Finish。
建立了一个简单的在串口上打印HelloWorld的工程,并自动编译驱动库及程序。
2、展开Led目录下src菜单,双击Hellowrold.c打开文件。
3、用以下程序替换Helloword.c中的内容。
点击保存,程序自动编译。
/*
*Copyright(c)2009Xilinx,Inc.Allrightsreserved.
*
*Xilinx,Inc.
*XILINXISPROVIDINGTHISDESIGN,CODE,ORINFORMATION"ASIS"ASA
*COURTESYTOYOU.BYPROVIDINGTHISDESIGN,CODE,ORINFORMATIONAS
*ONEPOSSIBLEIMPLEMENTATIONOFTHISFEATURE,APPLICATIONOR
*STANDARD,XILINXISMAKINGNOREPRESENTATIONTHATTHISIMPLEMENTATION
*ISFREEFROMANYCLAIMSOFINFRINGEMENT,ANDYOUARERESPONSIBLE
*FOROBTAININGANYRIGHTSYOUMAYREQUIREFORYOURIMPLEMENTATION.
*XILINXEXPRESSLYDISCLAIMSANYWARRANTYWHATSOEVERWITHRESPECTTO
*THEADEQUACYOFTHEIMPLEMENTATION,INCLUDINGBUTNOTLIMITEDTO
*ANYWARRANTIESORREPRESENTATIONSTHATTHISIMPLEMENTATIONISFREE
*FROMCLAIMSOFINFRINGEMENT,IMPLIEDWARRANTIESOFMERCHANTABILITY
*ANDFITNESSFORAPARTICULARPURPOSE.
*
*/
/*
*helloworld.c:
simpletestapplication
*/
#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.h"
staticXGpioPspsGpioInstancePtr;
externXGpioPs_ConfigXGpioPs_ConfigTable[XPAR_XGPIOPS_NUM_INSTANCES];
staticintiPinNumber=10;
XScuGicInterruptController;/*InstanceoftheInterruptController*/
staticXScuGic_Config*GicConfig;/*Theconfigurationparametersofthe
controller*/
staticintInterruptFlag;
voidprint(char*str);
externcharinbyte(void);
voidTimer_InterruptHandler(void*data,u8TmrCtrNumber)
{
print("\r\n");
print("\r\n");
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n");
print("InsideTimerISR\n\r");
XTmrCtr_Stop(data,TmrCtrNumber);
//PSGPIOWritting
print("LED'DS23'TurnedON\r\n");
XGpioPs_WritePin(&psGpioInstancePtr,iPinNumber,1);
XTmrCtr_Reset(data,TmrCtrNumber);
print("TimerISRExit\n\n\r");
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n");
print("\r\n");
print("\r\n");
InterruptFlag=1;
}
intSetUpInterruptSystem(XScuGic*XScuGicInstancePtr)
{
/*
*Connecttheinterruptcontrollerinterrupthandlertothehardware
*interrupthandlinglogicintheARMprocessor.
*/
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
XScuGicInstancePtr);
/*
*EnableinterruptsintheARM
*/
Xil_ExceptionEnable();
returnXST_SUCCESS;
}
intScuGicInterrupt_Init(u16DeviceId,XTmrCtr*TimerInstancePtr)
{
intStatus;
/*
*Initializetheinterruptcontrollerdriversothatitisreadyto
*use.
**/
GicConfig=XScuGic_LookupConfig(DeviceId);
if(NULL==GicConfig){
returnXST_FAILURE;
}
Status=XScuGic_CfgInitialize(&InterruptController,GicConfig,
GicConfig->CpuBaseAddress);
if(Status!
=XST_SUCCESS){
returnXST_FAILURE;
}
/*
*SetuptheInterruptSystem
**/
Status=SetUpInterruptSystem(&InterruptController);
if(Status!
=XST_SUCCESS){
returnXST_FAILURE;
}
/*
*Connectadevicedriverhandlerthatwillbecalledwhenan
*interruptforthedeviceoccurs,thedevicedriverhandlerperforms
*thespecificinterruptprocessingforthedevice
*/
Status=XScuGic_Connect(&InterruptController,
XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR,
(Xil_ExceptionHandler)XTmrCtr_InterruptHandler,
(void*)TimerInstancePtr);
if(Status!
=XST_SUCCESS){
returnXST_FAILURE;
}
/*
*Enabletheinterruptforthedeviceandthencause(simulate)an
*interruptsothehandlerswillbecalled
*/
XScuGic_Enable(&InterruptController,XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR);
returnXST_SUCCESS;
}
intmain()
{
staticXGpioGPIOInstance_Ptr;
XGpioPs_Config*GpioConfigPtr;
XTmrCtrTimerInstancePtr;
intxStatus;
u32Readstatus=0,OldReadStatus=0;
//u32EffectiveAdress=0xE000A000;
intiPinNumberEMIO=54;
u32uPinDirectionEMIO=0x0;
//InputPin
//Pindirection
u32uPinDirection=0x1;
intexit_flag,choice,internal_choice;
init_platform();
/*data=*(u32*)(0x42800004);
print("OK\n");
data=*(u32*)(0x41200004);
print("OK-1\n");
*/
print("#####ApplicationStarts#####\n\r");
print("\r\n");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-1:
AXIGPIOInitialization
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xStatus=XGpio_Initialize(&GPIOInstance_Ptr,XPAR_AXI_GPIO_0_DEVICE_ID);
if(XST_SUCCESS!
=xStatus)
print("GPIOINITFAILED\n\r");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-2:
AXIGPIOSettheDirection
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XGpio_SetDataDirection(&GPIOInstance_Ptr,1,1);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-3:
AXITimerInitialization
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xStatus=XTmrCtr_Initialize(&TimerInstancePtr,XPAR_AXI_TIMER_0_DEVICE_ID);
if(XST_SUCCESS!
=xStatus)
print("TIMERINITFAILED\n\r");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-4:
SetTimerHandler
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XTmrCtr_SetHandler(&TimerInstancePtr,
Timer_InterruptHandler,
&TimerInstancePtr);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-5:
SettingtimerResetValue
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XTmrCtr_SetResetValue(&TimerInstancePtr,
0,//Changewithgenericvalue
0xf0000000);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-6:
SettingtimerOption(InterruptModeAndAutoReload)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XTmrCtr_SetOptions(&TimerInstancePtr,
XPAR_AXI_TIMER_0_DEVICE_ID,
(XTC_INT_MODE_OPTION|XTC_AUTO_RELOAD_OPTION));
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-7:
PSGPIOIntialization
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GpioConfigPtr=XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
if(GpioConfigPtr==NULL)
returnXST_FAILURE;
xStatus=XGpioPs_CfgInitialize(&psGpioInstancePtr,
GpioConfigPtr,
GpioConfigPtr->BaseAddr);
if(XST_SUCCESS!
=xStatus)
print("PSGPIOINITFAILED\n\r");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-8:
PSGPIOpinsettingtoOutput
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XGpioPs_SetDirectionPin(&psGpioInstancePtr,iPinNumber,uPinDirection);
XGpioPs_SetOutputEnablePin(&psGpioInstancePtr,iPinNumber,1);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-9:
EMIOPINSettingtoInputport
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
XGpioPs_SetDirectionPin(&psGpioInstancePtr,
iPinNumberEMIO,uPinDirectionEMIO);
XGpioPs_SetOutputEnablePin(&psGpioInstancePtr,iPinNumberEMIO,0);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-10:
SCUGICinterruptcontrollerIntialization
//RegistrationoftheTimerISR
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xStatus=
ScuGicInterrupt_Init(XPAR_PS7_SCUGIC_0_DEVICE_ID,&TimerInstancePtr);
if(XST_SUCCESS!
=xStatus)
print(":
(SCUGICINITFAILED\n\r");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Step-11:
Userselectionproceduretoselectandexecutetests
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
exit_flag=0;
while(exit_flag!
=1)
{
print("SELECTtheOperationfromtheBelowMenu\r\n");
print("#################