int setup_interrupt() { //This functions sets up the interrupt on the ARM int result; XScuGic_Config *pCfg = XScuGic_LookupConfig(XPAR_SCUGIC_0_DEVICE_ID); if (pCfg == NULL){ print("Interrupt Configuration Lookup Failed\n\r"); return XST_FAILURE; } result = XScuGic_CfgInitialize(&ScuGic,pCfg,pCfg->CpuBaseAddress); if(result != XST_SUCCESS){ return result; } // self test result = XScuGic_SelfTest(&ScuGic); if(result != XST_SUCCESS){ return result; } // Initialize the exception handler Xil_ExceptionInit(); // Register the exception handler Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,(Xil_ExceptionHandler)XScuGic_InterruptHandler,&ScuGic); //Enable the exception handler Xil_ExceptionEnable(); // Connect the Voice Rec ISR to the exception table result = XScuGic_Connect(&ScuGic,XPAR_FABRIC_VOICEREC_0_INTERRUPT_INTR,(Xil_InterruptHandler)hls_voicerec_isr,&HlsVoiceRec); if(result != XST_SUCCESS){ return result; } // Enable the Voice Rec ISR XScuGic_Enable(&ScuGic,XPAR_FABRIC_VOICEREC_0_INTERRUPT_INTR); return XST_SUCCESS; }
XStatus InitInterruptController(INTC* intc) { int Status; // Start the interrupt controller #ifdef XPAR_INTC_0_DEVICE_ID // Initialize the driver instance RETURN_ON_FAILURE(XIntc_Initialize(intc, INTC_DEVICE_ID)); RETURN_ON_FAILURE(XIntc_Start(intc, XIN_REAL_MODE)); #else XScuGic_Config *GicConfig; GicConfig = XScuGic_LookupConfig(INTC_DEVICE_ID); XScuGic_CfgInitialize(intc, GicConfig, GicConfig->CpuBaseAddress); Status = XScuGic_SelfTest(intc); if (Status != XST_SUCCESS) { return XST_FAILURE; } #endif Xil_ExceptionInit(); /* * register the interrupt controller handler with the exception table. * This is in fact the ISR dispatch routine, calling our ISRs */ Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler) INTC_HANDLER, intc); Xil_ExceptionEnable(); return XST_SUCCESS; }
int ScuGicExample(u16 DeviceId) { int Status; /* * Initialize the interrupt controller driver so that it is ready to * use. */ GicConfig = XScuGic_LookupConfig(DeviceId); if (NULL == GicConfig) { return XST_FAILURE; } Status = XScuGic_CfgInitialize(&InterruptController, GicConfig, GicConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built * correctly */ Status = XScuGic_SelfTest(&InterruptController); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Setup the Interrupt System */ Status = SetUpInterruptSystem(&InterruptController); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect a device driver handler that will be called when an * interrupt for the device occurs, the device driver handler performs * the specific interrupt processing for the device */ Status = XScuGic_Connect(&InterruptController, INTC_DEVICE_INT_ID, (Xil_ExceptionHandler)DeviceDriverHandler, (void *)&InterruptController); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the device and then cause (simulate) an * interrupt so the handlers will be called */ XScuGic_Enable(&InterruptController, INTC_DEVICE_INT_ID); return XST_SUCCESS; }
/** * * This function is an example of how to use the interrupt controller driver * (XScuGic) and the hardware device. This function is designed to * work without any hardware devices to cause interrupts. It may not return * if the interrupt controller is not properly connected to the processor in * either software or hardware. * * This function relies on the fact that the interrupt controller hardware * has come out of the reset state such that it will allow interrupts to be * simulated by the software. * * @param DeviceId is Device ID of the Interrupt Controller Device, * typically XPAR_<INTC_instance>_DEVICE_ID value from * xparameters.h * * @return XST_SUCCESS to indicate success, otherwise XST_FAILURE * * @note None. * ******************************************************************************/ int ScuGicExample(u16 DeviceId) { int Status; /* * Initialize the interrupt controller driver so that it is ready to * use. */ GicConfig = XScuGic_LookupConfig(DeviceId); if (NULL == GicConfig) { return XST_FAILURE; } Status = XScuGic_CfgInitialize(&InterruptController, GicConfig, GicConfig->CpuBaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built * correctly */ Status = XScuGic_SelfTest(&InterruptController); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Setup the Interrupt System */ Status = SetUpInterruptSystem(&InterruptController); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect a device driver handler that will be called when an * interrupt for the device occurs, the device driver handler performs * the specific interrupt processing for the device */ Status = XScuGic_Connect(&InterruptController, INTC_DEVICE_INT_ID, (Xil_ExceptionHandler)DeviceDriverHandler, (void *)&InterruptController); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupt for the device and then cause (simulate) an * interrupt so the handlers will be called */ XScuGic_Enable(&InterruptController, INTC_DEVICE_INT_ID); /* * Simulate the Interrupt */ Status = XScuGic_SoftwareIntr(&InterruptController, INTC_DEVICE_INT_ID, XSCUGIC_SPI_CPU0_MASK); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Wait for the interrupt to be processed, if the interrupt does not * occur this loop will wait forever */ while (1) { /* * If the interrupt occurred which is indicated by the global * variable which is set in the device driver handler, then * stop waiting */ if (InterruptProcessed) { break; } } return XST_SUCCESS; }