/* * XSCUTimer vs sleep example */ /* #include "xscutimer.h" #include "xscugic.h" #include "xil_exception.h" #include "xparameters.h" #include "xgpio.h" #define TIMER_DEVICE_ID XPAR_XSCUTIMER_0_DEVICE_ID #define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID #define TIMER_IRPT_INTR XPAR_SCUTIMER_INTR #define TIMER_LOAD_VALUE 325000000 static XScuTimer Timer; static XScuGic Intc; static void TimerIntrHandler(void *CallBackRef); static void SetupInterruptSystem(XScuTimer *TMRInstancePtr, XScuTimer_Config *TMRConfigPtr, XScuGic *IntcInstancePtr, XScuGic_Config *IntcConfigPtr); static int tog=0; static XGpio leds; static int cntintr=0; int main(){ xil_printf("Hello\r\n"); XGpio_Initialize(&leds, XPAR_LEDS_DEVICE_ID); XGpio_SetDataDirection(&leds, 1, 0); XGpio_DiscreteWrite(&leds, 1, tog); XScuTimer_Config *TMRConfigPtr; XScuGic_Config *IntcConfigPtr; //init_platform(); TMRConfigPtr = XScuTimer_LookupConfig(TIMER_DEVICE_ID); IntcConfigPtr = XScuGic_LookupConfig(INTC_DEVICE_ID); SetupInterruptSystem(&Timer, TMRConfigPtr, &Intc, IntcConfigPtr); XScuTimer_Start(&Timer); while(1){ ; sleep(10); xil_printf("Interrupts:%d\r\n",cntintr) ; } return 0; } static void TimerIntrHandler(void *CallBackRef){ XScuTimer *TimerInstancePtr = (XScuTimer *) CallBackRef; XScuTimer_ClearInterruptStatus(TimerInstancePtr); //xil_printf("Event!\n\r"); cntintr++; // Toggle less significant Led tog = ~tog & 1; XGpio_DiscreteWrite(&leds, 1, tog); } static void SetupInterruptSystem(XScuTimer *TMRInstancePtr, XScuTimer_Config *TMRConfigPtr, XScuGic *IntcInstancePtr, XScuGic_Config *IntcConfigPtr){ //timer initialization XScuTimer_CfgInitialize(TMRInstancePtr, TMRConfigPtr, TMRConfigPtr->BaseAddr); //load the timer XScuTimer_LoadTimer(TMRInstancePtr, TIMER_LOAD_VALUE); XScuTimer_EnableAutoReload(TMRInstancePtr); XScuGic_CfgInitialize(IntcInstancePtr, IntcConfigPtr, IntcConfigPtr->CpuBaseAddress); Xil_ExceptionInit(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler, (void *)IntcInstancePtr); Xil_ExceptionEnable(); XScuGic_Connect(IntcInstancePtr, TIMER_IRPT_INTR, (Xil_ExceptionHandler)TimerIntrHandler, (void *)TMRInstancePtr); XScuGic_Enable(IntcInstancePtr, TIMER_IRPT_INTR); XScuTimer_EnableInterrupt(TMRInstancePtr); }