/** * File: gpiops_intr.c * Author: Theo Tsang * Date: 2023-03-24 15:00 * Description: omit * * Ver Who Date Changes * ----- ---- ---------- ------------- * 1.00 Theo 03/15/2024 First release */ #include "gpiops_intr.h" XScuGic InstancePtr; static void GpioPs_IntrHander_example(void *CallBackRef, u32 Bank, u32 Status) { xil_printf("Data read from GPIO Interrupt Bank=0x%x, IO_bit=0x%x\r\n", Bank, Status); } /** * Set the handler and Enable the interrupt. * * @param InstancePtr is a pointer to the XScuGic instance. * @param GpioInstancePtr is omit. * @param Int_Id contains the ID of the interrupt source and should be * in the range of 0 to XSCUGIC_MAX_NUM_INTR_INPUTS - 1 * * @return None. * * @note None. * */ void GpioPs_Setup_Intr_System(XScuGic * InstancePtr, XGpioPs *GpioInstancePtr, u16 Int_Id) { /* Set up the time Interrupt */ XScuGic_Connect(InstancePtr, Int_Id, (Xil_ExceptionHandler)XGpioPs_IntrHandler, (void *)GpioInstancePtr); /* Set the handler for gpio interrupts */ XGpioPs_SetCallbackHandler(GpioInstancePtr, (void *)GpioInstancePtr, GpioPs_IntrHander_example); /* Enable the interrupt for GPIO at GIC */ XScuGic_Enable(InstancePtr, Int_Id); } /** * Set the global interrupt callback function and enable global * interrupt. * * @param InstancePtr is omit. * * @return None. * * @note None. * */ void Setup_Intr_Exception(XScuGic * InstancePtr) { /* Enable interrupts from the hardware */ Xil_ExceptionInit(); Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler, (void *)InstancePtr); Xil_ExceptionEnable(); } /** * Initialize the interrupt controller driver. * * @param InstancePtr is omit. * * @return * - XST_SUCCESS if initialization was successful * * @note None. * */ s32 Init_Intr_System(XScuGic * InstancePtr) { int status; XScuGic_Config * ConfigPtr; /** * Initialize the interrupt controller driver so that it is ready to * use. */ ConfigPtr = XScuGic_LookupConfig(INTR_DEVICE_ID); if (NULL == ConfigPtr) { return XST_FAILURE; } status = XScuGic_CfgInitialize(InstancePtr, ConfigPtr, ConfigPtr->CpuBaseAddress); if (status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; } void GpioPs_Intr_Init(XGpioPs *GpioInstancePtr) { Init_Intr_System(&InstancePtr); GpioPs_Setup_Intr_System(&InstancePtr, GpioInstancePtr, GPIO_INTERRUPT_ID); Setup_Intr_Exception(&InstancePtr); }