/***************************** Include Files *********************************/
#include "xparameters.h"
#include "xscutimer.h"
#include "xscugic.h"
#include "xil_exception.h"
#include "xil_printf.h"
/************************** Constant Definitions *****************************/
#define TIMER_DEVICE_ID XPAR_XSCUTIMER_0_DEVICE_ID
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
#define TIMER_INTR_ID XPS_SCU_TMR_INT_ID
#define TIMER_LOAD_VALUE (XPAR_PS7_CORTEXA9_0_CPU_CLK_FREQ_HZ/2 - 1) //loda time 1s
/************************** Function Prototypes ******************************/
static void TimerIntrHandler(void *CallBackRef);
/************************** Variable Definitions *****************************/
XScuTimer TimerInstance; /* Cortex A9 Scu Private Timer Instance */
XScuGic IntcInstance; /* Interrupt Controller Instance */
volatile int TimerCnt;
volatile int TimerIntr_Flag;
int main(){
XScuTimer_Config *TimeConfigPtr;
XScuGic_Config *IntcConfig;
xil_printf("SCU Timer Interrupt Example Test \r\n");
/************************** Timer Initialize *****************************/
TimeConfigPtr = XScuTimer_LookupConfig(TIMER_DEVICE_ID);
XScuTimer_CfgInitialize(&TimerInstance, TimeConfigPtr,TimeConfigPtr->BaseAddr);
/************************** Intc Initialize *****************************/
IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
XScuGic_CfgInitialize(&IntcInstance, IntcConfig,IntcConfig->CpuBaseAddress);
/************************** Intr System Setup *****************************/
//Exception setup
Xil_ExceptionInit();//None
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT,(Xil_ExceptionHandler)XScuGic_InterruptHandler,&IntcInstance);
Xil_ExceptionEnable();
//XScugic setup
XScuGic_Connect(&IntcInstance, TIMER_INTR_ID,(Xil_ExceptionHandler)TimerIntrHandler,&TimerInstance);
XScuGic_Enable(&IntcInstance, TIMER_INTR_ID);
//timer setup
XScuTimer_EnableInterrupt(&TimerInstance);
/************************** Timer Setup *****************************/
XScuTimer_EnableAutoReload(&TimerInstance);
XScuTimer_LoadTimer(&TimerInstance, TIMER_LOAD_VALUE);
XScuTimer_Start(&TimerInstance);
xil_printf("SCU Timer Start \r\n");
while(1){
if(TimerIntr_Flag){
xil_printf(" %d Second\n\r",TimerCnt);
TimerCnt++;
TimerIntr_Flag = 0;
}
}
}
/************************** TimerIntrHandler *****************************/
static void TimerIntrHandler(void *CallBackRef)
{
XScuTimer *TimerInstancePtr = (XScuTimer *) CallBackRef;
if (XScuTimer_IsExpired(TimerInstancePtr)) {
XScuTimer_ClearInterruptStatus(TimerInstancePtr);
TimerIntr_Flag = 1;
/*
if (TimerCnt == 30) {
XScuTimer_DisableAutoReload(TimerInstancePtr);
printf("Test Finish");
}
*/
}
}
Zynq定时器中断试验整理
最新推荐文章于 2024-06-27 10:14:46 发布