/*
 * main.c
 *
 *  Created on: 2022825
 *      Author: Administrator
 */


#include <stdio.h>
#include <xparameters.h>
#include <xgpiops.h>
#include <xscugic.h>
#include <xil_exception.h>


#define Input_Pin 47	//PS_KEY
#define Output_Pin  7 //PS_LED

static XGpioPs Gpio; /* The Instance of the GPIO Driver */
static XScuGic GicInstancePtr;
int main(void)
{

	XGpioPs_Config *ConfigPtr;
	ConfigPtr = XGpioPs_LookupConfig(XPAR_AXI_GPIO_0_DEVICE_ID);
	XGpioPs_CfgInitialize(&Gpio, ConfigPtr, ConfigPtr->BaseAddr);

	/* 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);

	XScuGic_Config *IntcConfig; /* Instance of the interrupt controller */
	IntcConfig = XScuGic_LookupConfig(XPAR_SCUGIC_SINGLE_DEVICE_ID);
	XScuGic_CfgInitialize(&GicInstancePtr, IntcConfig, IntcConfig->CpuBaseAddress);

	//עCPU쳣/жϷ
	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
					(Xil_ExceptionHandler)XScuGic_InterruptHandler,
					&GicInstancePtr);

	//ע/󶨾жϷ
	XScuGic_Connect(&GicInstancePtr, XPS_GPIO_INT_ID,
					(Xil_ExceptionHandler)XGpioPs_IntrHandler,
					&Gpio);


	/* Enable falling edge interrupts for all the pins in bank 1. */
	XGpioPs_SetIntrType(&Gpio, XGPIOPS_BANK1, 0xffffffff, 0x00000000, 0x00);

	/* Set the handler for gpio interrupts. */
	XGpioPs_SetCallbackHandler(&Gpio, &Gpio, IntrHandler);


	/* Enable the GPIO interrupts of Bank 1. */
	XGpioPs_IntrEnable(&Gpio, XGPIOPS_BANK1, (1 << Input_Pin));


}
