/*
* Copyright (c) 2009-2012 Xilinx, Inc. All rights reserved.
*
* Xilinx, Inc.
* XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
* COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
* ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
* STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
* IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
* FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
* XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
* THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
* ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
* FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/ /*
* helloworld.c: simple test application
*
* This application configures UART 16550 to baud rate 9600.
* PS7 UART (Zynq) is not initialized by this application, since
* bootrom/bsp configures it to baud rate 115200
*
* ------------------------------------------------
* | UART TYPE BAUD RATE |
* ------------------------------------------------
* uartns550 9600
* uartlite Configurable only in HW design
* ps7_uart 115200 (configured by bootrom/bsp)
*/ #include <stdio.h>
#include "platform.h"
#include "xgpiops.h" #include "xparameters.h"
#include "xstatus.h"
#include "xscugic.h"
#include "xil_exception.h" //void print(char *str); #define GPIO_DIR 0x0000 /*All work in input mode*/
#define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID //
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID //
#define GPIO_INTERRUPT_ID XPAR_XGPIOPS_0_INTR // All gpio in four banks to one output (IRQ ID#52) to interrupt controller /************************** Function Prototypes ******************************/ static void IntrHandler(void *CallBackRef, int Bank, u32 Status);
static int SetupInterruptSystem(XScuGic *Intc, XGpioPs *Gpio, u16 GpioIntrId);
int ScuGicInterruptSetup(XScuGic *IntcInstancePtr, u16 DeviceId); /************************** Variable Definitions *****************************/ /*
* The following are declared globally so they are zeroed and so they are
* easily accessible from a debugger.
*/
static XGpioPs Gpio; /* The Instance of the GPIO Driver */ XScuGic IntcInstance; /* The Instance of the Interrupt Controller Driver */ int main()
{
init_platform(); print("Hello World\n\r"); /*****************************************************************/
//Set GPIO Interrupt
/*****************************************************************/
XGpioPs_Config *ConfigPtr;
int Status = ;
XGpioPs Gpio;
/*
* Initialize the Gpio driver.
*/
//printf("Initialize the Gpio driver.\n\r");
ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
if (ConfigPtr == NULL) {
return XST_FAILURE;
} XGpioPs_CfgInitialize(&Gpio, ConfigPtr, ConfigPtr->BaseAddr); /*
* Setup direction register of bank2, so that all the pins are configured as inputs.
*/
//printf("Set gpio direction.\n\r");
XGpioPs_SetDirection(&Gpio, , GPIO_DIR); // bank2 set to all input #ifdef GPIOIOTEST
//printf("GPIO bank2 value is 0x%x \n\r",i);
// set gpio direction output,'1' for output
XGpioPs_SetDirection(&Gpio, , 0xff);
// set gpio output enable
XGpioPs_SetOutputEnable(&Gpio, , 0xff);
// write value
XGpioPs_Write(&Gpio, , 0xff);
#endif /***********************************************************************/
/* How to Set Interrupt */
/***********************************************************************/ IntCtl_Init(); // GPIO is Num.52 interrupt
Status = SetupInterruptSystem(&IntcInstance, &Gpio, GPIO_INTERRUPT_ID); if (Status != XST_SUCCESS) {
print("Set GPIO interrupt Failure \n\r");
}
else{
print("Set GPIO interrupt Successful \n\r");
} /***********************************************************************/ while()
{
sleep();
print("While(1) ing \n\r");
} return ;
} /*****************************************************************************/
/**
*
* This function is used by the TestAppGen generated application to setup
* the interrupt controller.
*
* @param IntcInstancePtr is the reference to the Interrupt Controller
* instance.
* @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 IntCtl_Init(void)
{
int Status; Status = ScuGicInterruptSetup(&IntcInstance, XPAR_PS7_SCUGIC_0_DEVICE_ID);
if (Status == ) {
print("ScuGic Interrupt Setup PASSED\r\n");
}
else {
print("ScuGic Interrupt Setup FAILED\r\n");
}
} /*****************************************************************************/
/**
*
* This function is used by the TestAppGen generated application to setup
* the interrupt controller.
*
* @param IntcInstancePtr is the reference to the Interrupt Controller
* instance.
* @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 ScuGicInterruptSetup(XScuGic *IntcInstancePtr, u16 DeviceId)
{ int Status;
static XScuGic_Config *GicConfig; /*
* 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(IntcInstancePtr, GicConfig, GicConfig->CpuBaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Initialize the exception table.
*/
Xil_ExceptionInit(); /*
* Connect the interrupt controller interrupt handler to the hardware
* interrupt handling logic in the processor.
*/
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
IntcInstancePtr); /*
* Enable exceptions.
*/
Xil_ExceptionEnable(); return XST_SUCCESS; }
/*****************************************************************************/
/**
*
* This function sets up the interrupt system for the example. It enables rasing
* edge interrupts for all the pins of bank 2 in the GPIO device.
*
* @param GicInstancePtr is a pointer to the XScuGic driver Instance.
* @param GpioInstancePtr contains a pointer to the instance of the GPIO
* component which is going to be connected to the interrupt
* controller.
* @param GpioIntrId is the interrupt Id and is typically
* XPAR_<GICPS>_<GPIOPS_instance>_VEC_ID value from
* xparameters.h.
*
* @return XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note None.
*
****************************************************************************/
static int SetupInterruptSystem(XScuGic *GicInstancePtr, XGpioPs *Gpio, u16 GpioIntrId)
{
int Status; XScuGic_Config *IntcConfig; /* Instance of the interrupt controller */ /*
* Connect the device driver handler that will be called when an
* interrupt for the device occurs, the handler defined above performs
* the specific interrupt processing for the device.
*
*
*/
printf("Connect the device driver handler to interrupt processing \n\r");
Status = XScuGic_Connect(GicInstancePtr, GpioIntrId,
(Xil_ExceptionHandler)XGpioPs_IntrHandler,
(void *)Gpio);
if (Status != XST_SUCCESS) {
return Status;
} /*
* @param GpioInstancePtr contains a pointer to the instance of the GPIO
* component which is going to be connected to the interrupt
* controller.
* @param set Interrupt Type 0 level ,1 edge
* @param Interrupt Polarity 1 rising or high level ,0 falling or low level
* @param Interrupt Any Edge Sensitive 0 single edge, 1 both edge
* Enable rising edge interrupts for all the pins in bank 2.
*/ XGpioPs_SetIntrType(Gpio, , 0xffffffff, 0xFFFFFFFF, 0x00); // rising edge only /*
* Set the handler for gpio interrupts.
*/
printf("Set the handler for gpio interrupts.\n\r");
XGpioPs_SetCallbackHandler(Gpio, (void *)Gpio, IntrHandler); /*
* Enable the GPIO interrupts of Bank 2.
*/
printf("Enable the GPIO interrupts of Bank 2.\n\r");
XGpioPs_IntrEnable(Gpio, , 0xffffffff); /*
* Enable the interrupt for the GPIO device.
*/
printf("Enable the interrupt for the GPIO device. \n\r");
XScuGic_Enable(GicInstancePtr, GpioIntrId); /*
* Enable interrupts in the Processor.
*/
printf("Enable interrupts in the Processor \n\r");
Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); return XST_SUCCESS;
} /****************************************************************************/
/**
* This function is the user layer callback function for the bank 0 interrupts of
* the GPIO device. It checks if all the switches have been pressed to stop the
* interrupt processing and exit from the example.
*
* @param CallBackRef is a pointer to the upper layer callback reference.
* @param Status is the Interrupt status of the GPIO bank.
*
* @return None.
*
* @note None.
*
******************************************************************************/
static void IntrHandler(void *CallBackRef, int Bank, u32 Status)
{
// Is it necessary to close interrupt ?
printf("Enter interrupt \n\r"); /*
* Do nothing if the intr is generated for a different bank.
*/
if (Bank == ) { switch (Status)
{
// Get interrupt source
case :
printf("The trigger is EMIO GPIO 0 of bank %d \n\r", Bank);
break; }
} else {
return;
}
}