XilinxProcessorIPLib/drivers/gpiops/examples/xgpiops_intr_example.c
int GpioIntrExample(XScuGic *Intc, XGpioPs *Gpio, u16 DeviceId, u16 GpioIntrId)
{
	XGpioPs_Config *ConfigPtr;
	int Status;
	int Type_of_board;

	/* Initialize the Gpio driver. */
	ConfigPtr = XGpioPs_LookupConfig(DeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	Type_of_board = XGetPlatform_Info();
	switch (Type_of_board) {
		case XPLAT_ZYNQ_ULTRA_MP:
			Input_Bank_Pin = 22;
			Input_Pin = 22;
			Output_Pin = 23;
			break;

		case XPLAT_ZYNQ:
			Input_Bank_Pin = 14;
			Input_Pin = 14;
			Output_Pin = 10;
			break;
#ifdef versal
		case XPLAT_VERSAL:
			/* Accessing PMC GPIO by setting field to 1 */
			Gpio->PmcGpio  =  1;
			Input_Bank_Pin =  4;
			Input_Pin      = 56;
			Output_Pin     = 52;
			break;
#endif
	}
	XGpioPs_CfgInitialize(Gpio, ConfigPtr, ConfigPtr->BaseAddr);

	/* Run a self-test on the GPIO device. */
	Status = XGpioPs_SelfTest(Gpio);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Set the direction for the specified pin to be input */
	XGpioPs_SetDirectionPin(Gpio, Input_Pin, 0x0);

	/* Set the direction for the specified pin to be output. */
	XGpioPs_SetDirectionPin(Gpio, Output_Pin, 1);
	XGpioPs_SetOutputEnablePin(Gpio, Output_Pin, 1);
	XGpioPs_WritePin(Gpio, Output_Pin, 0x0);

	/*
	 * Setup the interrupts such that interrupt processing can occur. If
	 * an error occurs then exit.
	 */
	Status = SetupInterruptSystem(Intc, Gpio, GPIO_INTERRUPT_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	xil_printf("\n\rPush Switch button to exit\n\r");
	AllButtonsPressed = FALSE;

	/*
	 * Loop forever while the button changes are handled by the interrupt
	 * level processing.
	 */
	while(AllButtonsPressed == FALSE);

	return XST_SUCCESS;
}
/****************************************************************************/
/**
* This function shows the usage of interrupt fucntionality of the GPIO device.
* It is responsible for initializing the GPIO device, setting up interrupts and
* providing a foreground loop such that interrupts can occur in the background.
*
* @param	Intc is a pointer to the XScuGic driver Instance.
* @param	Gpio is a pointer to the XGpioPs driver Instance.
* @param	DeviceId is the XPAR_<Gpio_Instance>_PS_DEVICE_ID value
*		from xparameters.h.
* @param	GpioIntrId is XPAR_<GIC>_<GPIO_Instance>_VEC_ID value
*		from xparameters.h
*
* @return
*		- XST_SUCCESS if the example has completed successfully.
*		- XST_FAILURE if the example has failed.
*
* @note		None
*
*****************************************************************************/
This function shows the usage of interrupt fucntionality of the GPIO device.
It is responsible for initializing the GPIO device, setting up interrupts and
providing a foreground loop such that interrupts can occur in the background.
This function shows the usage of interrupt fucntionality of the GPIO device . It is responsible for initializing the GPIO device setting up interrupts and providing a foreground loop such that interrupts can occur in the background .
int GpioIntrExample(XScuGic *Intc, XGpioPs *Gpio, u16 DeviceId, u16 GpioIntrId)
{
	XGpioPs_Config *ConfigPtr;
	int Status;
	int Type_of_board;
	ConfigPtr = XGpioPs_LookupConfig(DeviceId);
	if (ConfigPtr == NULL) {
		return XST_FAILURE;
	}
	Type_of_board = XGetPlatform_Info();
	switch (Type_of_board) {
		case XPLAT_ZYNQ_ULTRA_MP:
			Input_Bank_Pin = 22;
			Input_Pin = 22;
			Output_Pin = 23;
			break;
		case XPLAT_ZYNQ:
			Input_Bank_Pin = 14;
			Input_Pin = 14;
			Output_Pin = 10;
			break;
#ifdef versal
		case XPLAT_VERSAL:
			Gpio->PmcGpio  =  1;
			Input_Bank_Pin =  4;
			Input_Pin      = 56;
			Output_Pin     = 52;
			break;
#endif
	}
	XGpioPs_CfgInitialize(Gpio, ConfigPtr, ConfigPtr->BaseAddr);
	Status = XGpioPs_SelfTest(Gpio);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XGpioPs_SetDirectionPin(Gpio, Input_Pin, 0x0);
	XGpioPs_SetDirectionPin(Gpio, Output_Pin, 1);
	XGpioPs_SetOutputEnablePin(Gpio, Output_Pin, 1);
	XGpioPs_WritePin(Gpio, Output_Pin, 0x0);
	Status = SetupInterruptSystem(Intc, Gpio, GPIO_INTERRUPT_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	xil_printf("\n\rPush Switch button to exit\n\r");
	AllButtonsPressed = FALSE;
	while(AllButtonsPressed == FALSE);
	return XST_SUCCESS;
}
int GpioIntrExample ( XScuGic * Intc , XGpioPs * Gpio , u16 DeviceId , u16 GpioIntrId ) { XGpioPs_Config * ConfigPtr ; int Status ; int Type_of_board ; ConfigPtr = XGpioPs_LookupConfig ( DeviceId ) ; if ( ConfigPtr == NULL ) { return XST_FAILURE ; } Type_of_board = XGetPlatform_Info ( ) ; switch ( Type_of_board ) { case XPLAT_ZYNQ_ULTRA_MP : Input_Bank_Pin = 22 ; Input_Pin = 22 ; Output_Pin = 23 ; break ; case XPLAT_ZYNQ : Input_Bank_Pin = 14 ; Input_Pin = 14 ; Output_Pin = 10 ; break ; #ifdef versal case XPLAT_VERSAL : Gpio -> PmcGpio = 1 ; Input_Bank_Pin = 4 ; Input_Pin = 56 ; Output_Pin = 52 ; break ; #endif } XGpioPs_CfgInitialize ( Gpio , ConfigPtr , ConfigPtr -> BaseAddr ) ; Status = XGpioPs_SelfTest ( Gpio ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } XGpioPs_SetDirectionPin ( Gpio , Input_Pin , 0x0 ) ; XGpioPs_SetDirectionPin ( Gpio , Output_Pin , 1 ) ; XGpioPs_SetOutputEnablePin ( Gpio , Output_Pin , 1 ) ; XGpioPs_WritePin ( Gpio , Output_Pin , 0x0 ) ; Status = SetupInterruptSystem ( Intc , Gpio , GPIO_INTERRUPT_ID ) ; if ( Status != XST_SUCCESS ) { return XST_FAILURE ; } xil_printf ( " \n \r \n \r " ) ; AllButtonsPressed = FALSE ; while ( AllButtonsPressed == FALSE ) ; return XST_SUCCESS ; }
This function shows the usage of interrupt fucntionality of the GPIO device.
This function shows the usage of interrupt fucntionality of the GPIO device .
/* Initialize the Gpio driver. */ /* Accessing PMC GPIO by setting field to 1 */ /* Run a self-test on the GPIO device. */ /* Set the direction for the specified pin to be input */ /* Set the direction for the specified pin to be output. */ /*
	 * Setup the interrupts such that interrupt processing can occur. If
	 * an error occurs then exit.
	 */ /*
	 * Loop forever while the button changes are handled by the interrupt
	 * level processing.
	 */