theUltimateSource
Junior Member level 1
hello, I have problems with my code. I set up a timer on my Xilinx Zynq board and tested it. However, once I call
the timer does not work anymore. I commented out the compromising lines in that function, but the function itself works as well (it turns on a led).
I don't know where the problem is, can you help? Also, I wonder how I can manually trigger the timer interrupt in the Xilinx SDK for fault insertion?
here is my code:
Code C - [expand] 1 int GPIOInitFunction(XGpioPs* GPIOInst);
the timer does not work anymore. I commented out the compromising lines in that function, but the function itself works as well (it turns on a led).
I don't know where the problem is, can you help? Also, I wonder how I can manually trigger the timer interrupt in the Xilinx SDK for fault insertion?
here is my code:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 /***************************** Include Files *********************************/ #include "xparameters.h" #include "xgpio.h" #include "xgpiops.h" #include "xtmrctr.h" #include "xscugic.h" #include "xil_exception.h" #include "xil_printf.h" /* ------------------------------------------------------------ */ /* constant definitions */ /* ------------------------------------------------------------ */ XScuGic INTCInst; XTmrCtr TMRInst; XGpioPs GPIOInst; /* * Device hardware build related constants. */ #define INTC_DEVICE_ID XPAR_PS7_SCUGIC_0_DEVICE_ID #define TMR_DEVICE_ID XPAR_TMRCTR_0_DEVICE_ID #define LEDS_DEVICE_ID XPAR_AXI_GPIO_1_DEVICE_ID #define INTC_GPIO_INTERRUPT_ID XPAR_FABRIC_AXI_GPIO_0_IP2INTC_IRPT_INTR #define INTC_TMR_INTERRUPT_ID XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR #define TMR_LOAD (-100000000) #define ledpin 7 /************************** Function Prototypes ******************************/ static void TMR_Intr_Handler(void *baseaddr_p); static int InterruptSystemSetup(XScuGic *XScuGicInstancePtr); static int IntcInitFunction(u16 DeviceId, XTmrCtr *TmrInstancePtr); int GPIOInitFunction(XGpioPs* GPIOInst); static void TMR_Intr_Handler(void* data) { xil_printf("interrupt\n\r"); if (XTmrCtr_IsExpired(&TMRInst,0)){ XTmrCtr_Stop(&TMRInst,0); XTmrCtr_Reset(&TMRInst,0); XTmrCtr_Start(&TMRInst,0); } } int GPIOInitFunction(XGpioPs* GPIOInst) { XGpioPs_Config *GPIOConfigPtr; //gpio config //GPIO Initilization GPIOConfigPtr = XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID); // XGpioPs_CfgInitialize(&GPIOInst, GPIOConfigPtr,GPIOConfigPtr->BaseAddr); // //set direction and enable output // XGpioPs_SetDirectionPin(&GPIOInst, ledpin, 1); // XGpioPs_SetOutputEnablePin(&GPIOInst, ledpin, 1); // XGpioPs_WritePin(&GPIOInst, ledpin, 1); return XST_SUCCESS; } u8 DemoInitialize(void) { /*************************************************** * initializations * **************************************************/ // Initialise PS LEDs if(XST_SUCCESS != GPIOInitFunction(&GPIOInst)) return XST_FAILURE; // // SETUP THE TIMER // if(XST_SUCCESS != XTmrCtr_Initialize(&TMRInst, TMR_DEVICE_ID)) return XST_FAILURE; XTmrCtr_SetHandler(&TMRInst, TMR_Intr_Handler, &TMRInst); XTmrCtr_SetResetValue(&TMRInst, 0, TMR_LOAD); XTmrCtr_SetOptions(&TMRInst, 0, XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION); // Initialize interrupt controller if(XST_SUCCESS != IntcInitFunction(INTC_DEVICE_ID, &TMRInst)) return XST_FAILURE; XTmrCtr_Start(&TMRInst, 0); return XST_SUCCESS; } int main(){ DemoInitialize(); while(1); return 0; } static int InterruptSystemSetup(XScuGic *XScuGicInstancePtr) { Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler, XScuGicInstancePtr); Xil_ExceptionEnable(); return XST_SUCCESS; } static int IntcInitFunction(u16 DeviceId, XTmrCtr *TmrInstancePtr) { XScuGic_Config *IntcConfig; int status; // Interrupt controller initialization IntcConfig = XScuGic_LookupConfig(DeviceId); if(XST_SUCCESS != XScuGic_CfgInitialize(&INTCInst, IntcConfig, IntcConfig->CpuBaseAddress)) return XST_FAILURE; // Call to interrupt setup if(XST_SUCCESS != InterruptSystemSetup(&INTCInst)) return XST_FAILURE; // Connect timer interrupt to handler status = XScuGic_Connect(&INTCInst, INTC_TMR_INTERRUPT_ID, (Xil_ExceptionHandler)TMR_Intr_Handler, (void *)TmrInstancePtr); if(status != XST_SUCCESS) return XST_FAILURE; // Enable timer interrupts in the controller XScuGic_Enable(&INTCInst, INTC_TMR_INTERRUPT_ID); return XST_SUCCESS; }