/***********************************************************************************************
* Company: Microsemi Corporation
*
* File: main.c
* File history:
*      Revision: 1.0 Date: May 4, 2010
*
* Description:
*
* This code enables the GPIO 0, GPIO 1 and Fabric interrupts. And implements the Interrupt
* handler functionality for these interrupts.
*
* Author: Pavan Marisetti
*         pavan.marisetti@microsemi.com
*         Corporate Applications Engineering
*
************************************************************************************************/

// Including Directories
/***********************************************************************************************/

#include "../drivers/mss_uart/mss_uart.h"
#include "../drivers/mss_gpio/mss_gpio.h"
#include "../drivers/mss_watchdog/mss_watchdog.h"

/***********************************************************************************************
 Interrupt Handlers
************************************************************************************************/

/* GPIO 0 Interrupt Handler */
/* This Interrupt handler executes upon the occurrence of
   GPIO 0 interrupt, which is from the timer 2 in the FPGA
   Fabric. This function prints source of the interrupt to the
   hyperterminal */
void GPIO0_IRQHandler( void )
  {


	  printf(" Timer 2 Interrupt occurred - GPIO 0 \n\r");
	  MSS_GPIO_clear_irq( MSS_GPIO_0 );
      NVIC_ClearPendingIRQ( GPIO0_IRQn );
  }


/* GPIO 1 Interrupt Handler */
/* This Interrupt handler executes upon the occurrence of
   GPIO 1 interrupt, which is from the Switch.
   This function prints source of the interrupt to the
   hyperterminal */

void GPIO1_IRQHandler( void )
  {
	printf(" Switch Interrupt occurred - GPIO 1 \n\r");
	MSS_GPIO_clear_irq( MSS_GPIO_1 );
    NVIC_ClearPendingIRQ( GPIO1_IRQn );

  }
/* Fabric Interrupt Handler */
/* This Interrupt handler executes upon the occurrence of
   fabric interrupt, which is from the timer 1.
   This function prints the source of the interrupt to the
   hyperterminal */
void Fabric_IRQHandler( void )
{

    printf(" Timer 1 Interrupt occurred - FABINT \n\r");
	NVIC_ClearPendingIRQ( Fabric_IRQn );

  }

/***********************************************************************************************
 Function Main
************************************************************************************************/

void main()
{
	/* Watchdog Disabling function*/
	MSS_WD_disable();

    /* Enabling of GPIO 0, GPIO 1 and Fabric Interrupts*/
    NVIC_EnableIRQ(GPIO0_IRQn);
	MSS_GPIO_config( MSS_GPIO_0, MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_POSITIVE );
	MSS_GPIO_enable_irq( MSS_GPIO_0 );

	NVIC_EnableIRQ(GPIO1_IRQn);
	MSS_GPIO_config( MSS_GPIO_1, MSS_GPIO_INPUT_MODE | MSS_GPIO_IRQ_EDGE_NEGATIVE );
	MSS_GPIO_enable_irq( MSS_GPIO_1 );
	NVIC_EnableIRQ(Fabric_IRQn);

	for(;;)
	{

	}

}
/***********************************************************************************************
 End of function Main
************************************************************************************************/
