#include<stdio.h>#include"xadcps.h"#include"xil_types.h"#include"Xscugic.h"//该文件包含配置驱动程序以及GIC的使用范围#include"Xil_exception.h"//该文件包含Cortex-A9的异常函数#include"xscutimer.h"#defineTIMER_DEVICE_IDXPAR_XSCUTIMER_0_DEVICE_ID//定义timer设备号#defineINTC_DEVICE_IDXPAR_SCUGIC_SINGLE_DEVICE_ID//定义中断控制器设备号(GIC中断控制器)#defineTIMER_IRPT_INTRXPAR_SCUTIMER_INTR//私有时钟中断#defineTIMER_LOAD_VALUE(767/2*1000*1000-1)//欲装载值staticvoidTimerIntrHandler(void*CallBackRef);voidSetupInterruptSystem(XScuGic *GicInstancePtr,XScuTimer *TimerInstancePtr, u16 TimerIntrId){
XScuGic_Config *IntcConfig;//GIC config//初始化SOC异常Xil_ExceptionInit();//initialise the GIC
IntcConfig =XScuGic_LookupConfig(INTC_DEVICE_ID);XScuGic_CfgInitialize(GicInstancePtr, IntcConfig, IntcConfig->CpuBaseAddress);//connect to the hardwareXil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,(Xil_ExceptionHandler) XScuGic_InterruptHandler,GicInstancePtr);//连接到中断处理硬件XScuGic_Connect(GicInstancePtr, TimerIntrId,(Xil_ExceptionHandler) TimerIntrHandler,(void*) TimerInstancePtr);//enable the interrupt for the Timer at GICXScuGic_Enable(GicInstancePtr, TimerIntrId);//enable interrupt on the timerXScuTimer_EnableInterrupt(TimerInstancePtr);// Enable interrupts in the Processor.Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ);}staticvoidTimerIntrHandler(void*CallBackRef){staticint sec =0;//计数
XScuTimer *TimerInstancePtr =(XScuTimer *) CallBackRef;XScuTimer_ClearInterruptStatus(TimerInstancePtr);//清除挂起的中断
sec++;xil_printf(" %d Second\n\r", sec);//每秒打印输出一次}