/**
* This function is the Interrupt Service Routine for the GPIO device.  It
* will be called by the processor whenever an interrupt is asserted by the
* device.
*
* This function will detect the push button on the board has changed state
* and then turn on or off the LED.
*
* @param	InstancePtr is the GPIO instance pointer to operate on.
*		It is a void pointer to meet the interface of an interrupt
*		processing function.
*
* @return	None.
*
* @note		None.
*
*****************************************************************************/
void GpioIsr(void *InstancePtr)
{
	XGpio *GpioPtr = (XGpio *)InstancePtr;
	u32 Led;
	u32 LedState;
	u32 Buttons;
	u32 ButtonFound;
	u32 ButtonsChanged = 0;
	static u32 PreviousButtons;

	/*
	 * Disable the interrupt
	 */
	XGpio_InterruptDisable(GpioPtr, BUTTON_INTERRUPT);

	/* Keep track of the number of interrupts that occur */

	InterruptCount++;

	/*
	 * There should not be any other interrupts occuring other than the
	 * the button changes
	 */
	if ((XGpio_InterruptGetStatus(GpioPtr) & BUTTON_INTERRUPT) !=
		BUTTON_INTERRUPT) {
		return;
	}


	/*
	 * Read state of push buttons and determine which ones changed
	 * states from the previous interrupt. Save a copy of the buttons
	 * for the next interrupt
	 */
	Buttons = XGpio_DiscreteRead(GpioPtr, BUTTON_CHANNEL);
	ButtonsChanged = Buttons ^ PreviousButtons;
	PreviousButtons = Buttons;

	/*
	 * Handle all button state changes that occurred since the last
	 * interrupt
	 */
	while (ButtonsChanged != 0) {
		/*
		 * Determine which button changed state and then get
		 * the current state of the associated LED
		 */
		 Led = MapButton2Led(ButtonsChanged, &ButtonFound);
		 LedState = XGpio_DiscreteRead(GpioPtr, LED_CHANNEL) & Led;

		 /*
		  * Clear the button that is being processed so that it is
		  * done and others can be handled also
		  */
		 ButtonsChanged &= ~ButtonFound;

		 /* Toggle the state of the LED */
		 if (LedState) {
			 XGpio_DiscreteClear(GpioPtr, LED_CHANNEL, Led);
		 } else {
			 XGpio_DiscreteSet(GpioPtr, LED_CHANNEL, Led);
		 }
	 }

	 /* Clear the interrupt such that it is no longer pending in the GPIO */

	 (void)XGpio_InterruptClear(GpioPtr, BUTTON_INTERRUPT);

	 /*
	  * Enable the interrupt
	  */
	 XGpio_InterruptEnable(GpioPtr, BUTTON_INTERRUPT);

}
void BTN_Intr_Handler(void *InstancePtr)
{

	// Ignore additional button presses
		if ((XGpio_InterruptGetStatus(&BTNInst) & BTN_INT) !=
				BTN_INT) {
				return;

		// Disable GPIO interrupts
		XGpio_InterruptDisable(&BTNInst, BTN_INT);
				 }


		btn_value = XGpio_DiscreteRead(&BTNInst, 1);
		switch (btn_value){

					//Checking if BTNC was pressed. Action: Show Alex in the middle
					case 1:
						x=8;
						y=2;
						clear_OLED();
						show_alex(x,y);
					break;

					//Checking if BTND was pressed. Action: Check for boundary and move Alex down.
					case 2:
						if (y<3)
							{
								y=y+1;
								clear_OLED();
								show_alex(x,y);
							}
					break;

					//Checking if BTNL was pressed. Action: Check for boundary and move Alex left.
					case 4:
						if (x>0)
							{
								x=x-1;
								clear_OLED();
								show_alex(x,y);
							}
					break;

					//Checking if BTNR was pressed. Action: Check for boundary and move Alex right.
					case 8:
						if (x<15)
							{
								x=x+1;
								clear_OLED();
								show_alex(x,y);
							}
					break;

					//Checking if BTNU was pressed. Action: Check for boundary and move Alex up.
					case 16:
						if (y>0)
							{
								y=y-1;
								clear_OLED();
								show_alex(x,y);
							}
					break;

					default:
					break;
						}


		// Acknowledge GPIO interrupts
	    (void)XGpio_InterruptClear(&BTNInst, BTN_INT);
	    // Enable GPIO interrupts
	    XGpio_InterruptEnable(&BTNInst, BTN_INT);

}
Beispiel #3
0
/**
* This function is the Interrupt Service Routine for the GPIO device.
*
* This function will detect the push button on the board has changed state
* and then prepare data to be sent to the host upon receiving the Get
*
* @param	InstancePtr is the GPIO component to operate on. It is a void
*		pointer to meet the interface of an interrupt processing
* 		function.
*
* @return 	None.
*
* @note		None.
*
*****************************************************************************/
void GpioIsr(void *InstancePtr)
{
	XGpio *GpioPtr = (XGpio *)InstancePtr;
	u32 Buttons;
	u32 ButtonsChanged = 0;
	static u32 PreviousButtons;
	u8 Index = 0;
	static u8 State = 0;
	const u8 Position[] = {-4, -4, -4, 0, 4, 4, 4, 0, -4, -4};
	u8 TxBuf[4];


	/*
	 * Disable the interrupt
	 */
	XGpio_InterruptDisable(GpioPtr, BUTTON_INTERRUPT);


	/*
	 * There should not be any other interrupts occurring other than the
	 * the button changes.
	 */
	if ((XGpio_InterruptGetStatus(GpioPtr) & BUTTON_INTERRUPT) !=
		BUTTON_INTERRUPT) {
		return;
	}

	/*
	 * Read state of push buttons and determine which ones changed
	 * states from the previous interrupt. Save a copy of the buttons
	 * for the next interrupt.
	 */
	Buttons = (XGpio_DiscreteRead(GpioPtr, BUTTON_CHANNEL) & 0x1F) ;
	ButtonsChanged = Buttons ^ PreviousButtons;
	PreviousButtons = Buttons;

	/*
	 * Handle all button state changes that occurred since the last
	 * interrupt
	 */
	while (ButtonsChanged != 0) {

		/*
		 * Determine which button changed state and then get
		 * the current state of the associated LED
		 */
		if (ButtonsChanged & 0x1F){

				if (ButtonsChanged & EXIT_BUTTON){
					StopTest = TRUE;
					break;
				}
				TxBuf[1] = Position [State];
				TxBuf[2] = Position [State+2];
				++State;
				for (Index =0; Index < 5; Index++){
					XUsb_EpDataSend(&UsbInstance, 1,
						(unsigned char *)&TxBuf[0], 4);
				}

				if (State > 7)
					State = 0;
		}
		break;
	}

	/*
	 * Clear the interrupt such that it is no longer pending in the GPIO
	 */
	(void)XGpio_InterruptClear(GpioPtr, BUTTON_INTERRUPT);

	/*
	 * Enable the interrupt
	 */
	XGpio_InterruptEnable(GpioPtr, BUTTON_INTERRUPT);

}
Beispiel #4
0
void clear_interrupt_gpio( cyg_uint32 mask )
{
    XGpio_InterruptClear(&gpio_manager_device, mask);
}