예제 #1
0
void encoder_init_all ()
	{
	uint8_t isr_counter = 0;
	
	Disable_global_interrupt();
	/* Initialization loop, this loop inits all required IO and interrupts
	 * for EIC module and pins used to read encoders.  */	
	while(isr_counter < ENCODER_COUNT)
		{
		/* Init io for interrupt line and state poll line. */
		gpio_enable_gpio_pin(encoder_handle[isr_counter].a_pin);
		gpio_enable_gpio_pin(encoder_handle[isr_counter].b_pin);
		
		/* Set pullup for both gpio channels. */
		gpio_enable_pin_pull_up(encoder_handle[isr_counter].a_pin);
		gpio_enable_pin_pull_up(encoder_handle[isr_counter].b_pin);
			
		/* Init interrupt from encoder A line */
		gpio_enable_pin_interrupt(encoder_handle[isr_counter].a_pin, GPIO_FALLING_EDGE);
		gpio_disable_pin_interrupt(encoder_handle[isr_counter].b_pin);
		
		INTC_register_interrupt(&encoders_and_buttons_isr, 
			AVR32_GPIO_IRQ_0 + (encoder_handle[isr_counter].a_pin/8),
			AVR32_INTC_INT0);			
		isr_counter++;
		}
	Enable_global_interrupt();
	}
/*! \brief Initializes SD/MMC resources: GPIO, MCI and SD/MMC.
 */
static void sd_mmc_mci_resources_init(void)
{
	static const gpio_map_t SD_MMC_MCI_GPIO_MAP = {
		{SD_SLOT_8BITS_CLK_PIN, SD_SLOT_8BITS_CLK_FUNCTION},	// SD CLK.
		{SD_SLOT_8BITS_CMD_PIN, SD_SLOT_8BITS_CMD_FUNCTION},	// SD CMD.
		{SD_SLOT_8BITS_DATA0_PIN, SD_SLOT_8BITS_DATA0_FUNCTION},	// SD DAT[0].
		{SD_SLOT_8BITS_DATA1_PIN, SD_SLOT_8BITS_DATA1_FUNCTION},	// DATA Pin.
		{SD_SLOT_8BITS_DATA2_PIN, SD_SLOT_8BITS_DATA2_FUNCTION},	// DATA Pin.
		{SD_SLOT_8BITS_DATA3_PIN, SD_SLOT_8BITS_DATA3_FUNCTION},	// DATA Pin.
		{SD_SLOT_8BITS_DATA4_PIN, SD_SLOT_8BITS_DATA4_FUNCTION},	// DATA Pin.
		{SD_SLOT_8BITS_DATA5_PIN, SD_SLOT_8BITS_DATA5_FUNCTION},	// DATA Pin.
		{SD_SLOT_8BITS_DATA6_PIN, SD_SLOT_8BITS_DATA6_FUNCTION},	// DATA Pin.
		{SD_SLOT_8BITS_DATA7_PIN, SD_SLOT_8BITS_DATA7_FUNCTION}	// DATA Pin.
	};

	// MCI options.
	static const mci_options_t MCI_OPTIONS = {
		.card_speed = 400000,
		.card_slot = SD_SLOT_8BITS,	// Default card initialization.
	};

	// Assign I/Os to MCI.
	gpio_enable_module(SD_MMC_MCI_GPIO_MAP,
			sizeof(SD_MMC_MCI_GPIO_MAP) /
			sizeof(SD_MMC_MCI_GPIO_MAP[0]));

	// Enable pull-up for Card Detect.
	gpio_enable_pin_pull_up(SD_SLOT_8BITS_CARD_DETECT);

	// Enable pull-up for Write Protect.
	gpio_enable_pin_pull_up(SD_SLOT_8BITS_WRITE_PROTECT);

	sd_mmc_mci_init(&MCI_OPTIONS, sysclk_get_pbb_hz(), sysclk_get_cpu_hz());
}
예제 #3
0
파일: rtouch.c 프로젝트: InSoonPark/asf
/** \brief Enable pull-ups for Y lines.
 *
 * Used to be able to trigger an interrupt upon a touch.
 */
static void inline rtouch_pullup_y_surface(void)
{
	gpio_enable_gpio_pin(rtouch_gpio_ymap[1].pin);
	gpio_enable_gpio_pin(rtouch_gpio_ymap[0].pin);

	gpio_enable_pin_pull_up(rtouch_gpio_ymap[0].pin);
	gpio_enable_pin_pull_up(rtouch_gpio_ymap[1].pin);
}
예제 #4
0
extern void init_gpio(void) {
	gpio_enable_gpio_pin(A00);
	gpio_enable_gpio_pin(A01);
	gpio_enable_gpio_pin(A02);
	gpio_enable_gpio_pin(A03);
	gpio_enable_gpio_pin(A04);
	gpio_enable_gpio_pin(A05);
	gpio_enable_gpio_pin(A06);
	gpio_enable_gpio_pin(A07);

	gpio_enable_gpio_pin(B08);
	gpio_enable_gpio_pin(B09);
	gpio_enable_gpio_pin(B10);
	gpio_enable_gpio_pin(B11);

  // loopback for version detection (on new version B00 and B01 are bridged)
	gpio_enable_gpio_pin(B00);
	gpio_enable_gpio_pin(B01);
  gpio_enable_pin_pull_up(B01);
  gpio_configure_pin(B00, GPIO_DIR_OUTPUT);
  gpio_set_pin_low(B00);

  // turn on pull-ups for SDA/SCL
  // gpio_enable_pin_pull_up(A09);
  // gpio_enable_pin_pull_up(A10);

	gpio_enable_gpio_pin(NMI);

	gpio_configure_pin(B08, GPIO_DIR_OUTPUT);
	gpio_configure_pin(B09, GPIO_DIR_OUTPUT);
	gpio_configure_pin(B10, GPIO_DIR_OUTPUT);
	gpio_configure_pin(B11, GPIO_DIR_OUTPUT);
}
예제 #5
0
extern void init_gpio(void) {
    gpio_enable_gpio_pin(B00);
    gpio_enable_gpio_pin(B01);
    gpio_enable_gpio_pin(B02);
    gpio_enable_gpio_pin(B03);
    gpio_enable_gpio_pin(B04);
    gpio_enable_gpio_pin(B05);
    gpio_enable_gpio_pin(B06);
    gpio_enable_gpio_pin(B07);
    gpio_enable_gpio_pin(B08);
    gpio_enable_gpio_pin(B09);
    gpio_enable_gpio_pin(B10);
    gpio_enable_gpio_pin(NMI);

    gpio_enable_pin_pull_up(B06);
    gpio_enable_pin_pull_up(B07);

    gpio_enable_pin_glitch_filter(B06);
    gpio_enable_pin_glitch_filter(B07);
    gpio_enable_pin_glitch_filter(NMI);
}
예제 #6
0
파일: board_init.c 프로젝트: 00alis/Arduino
static void init_spi(void)
{
#if defined(WL_SPI)
        int i;
#endif
        

#if defined(AT45DBX_SPI)
        static const gpio_map_t AT45DBX_SPI_GPIO_MAP = {
                { AT45DBX_SPI_SCK_PIN, AT45DBX_SPI_SCK_FUNCTION },
                { AT45DBX_SPI_MISO_PIN, AT45DBX_SPI_MISO_FUNCTION },
                { AT45DBX_SPI_MOSI_PIN, AT45DBX_SPI_MOSI_FUNCTION },
                { AT45DBX_SPI_NPCS2_PIN, AT45DBX_SPI_NPCS2_FUNCTION },
        };
#endif

        
#if defined(WL_SPI) 
	const gpio_map_t WL_SPI_GPIO_MAP = {
#if defined(WL_SPI_NPCS0)
            WL_SPI_NPCS0,
#endif
            WL_SPI_NPCS, WL_SPI_MISO, WL_SPI_MOSI, WL_SPI_SCK
        };
#endif

#if defined(WL_SPI) || defined(AT45DBX_SPI)
        spi_options_t spiOptions = {
                .modfdis = 1 /* only param used by spi_initMaster() */
        };
#endif

#if defined(AT45DBX_SPI)
        gpio_enable_module(AT45DBX_SPI_GPIO_MAP,
                           sizeof(AT45DBX_SPI_GPIO_MAP) /
                           sizeof(AT45DBX_SPI_GPIO_MAP[0]));
        spi_initMaster(AT45DBX_SPI, &spiOptions);
        spi_selectionMode(AT45DBX_SPI, 0, 0, 0);
#endif

#if defined(WL_SPI)
        /* same pins might be initialized twice here */
        gpio_enable_module(WL_SPI_GPIO_MAP,
                           sizeof(WL_SPI_GPIO_MAP) /
                           sizeof(WL_SPI_GPIO_MAP[0]));
        for (i = 0; i < sizeof(WL_SPI_GPIO_MAP)/sizeof(WL_SPI_GPIO_MAP[0]); i++)
                gpio_enable_pin_pull_up(WL_SPI_GPIO_MAP[i].pin);

        /* same SPI controller might be initialized again */
        spi_initMaster(&WL_SPI, &spiOptions);
        spi_selectionMode(&WL_SPI, 0, 0, 0);
#endif

#if defined(AT45DBX_SPI)
        spi_enable(AT45DBX_SPI);

        /* put up flash reset pin */
        gpio_set_gpio_pin(AT45DBX_CHIP_RESET);
#endif

#if defined(WL_SPI)
        spi_enable(&WL_SPI);
#endif
}


static void init_rs232(void)
{
#ifndef NO_SERIAL
#if defined(BOARD_RS232_0)
        const gpio_map_t BOARD_RS232_0_GPIO_MAP = {
                BOARD_RS232_0_TX,
                BOARD_RS232_0_RX,
#if defined(BOARD_RS232_0_RTS) && defined (BOARD_RS232_0_CTS)
                BOARD_RS232_0_RTS,
                BOARD_RS232_0_CTS
#endif
                
        };
#endif

#if defined(BOARD_RS232_1)
        const gpio_map_t BOARD_RS232_1_GPIO_MAP = {
                BOARD_RS232_1_TX,
                BOARD_RS232_1_RX
#if defined(BOARD_RS232_1_RTS) && defined (BOARD_RS232_1_CTS)
                BOARD_RS232_1_RTS,
                BOARD_RS232_1_CTS
#endif
        };
#endif

#if defined(BOARD_RS232_0)
	gpio_enable_module(BOARD_RS232_0_GPIO_MAP,
                           sizeof(BOARD_RS232_0_GPIO_MAP) / 
                           sizeof(BOARD_RS232_0_GPIO_MAP[0]));
#endif

#if defined(BOARD_RS232_1)
	gpio_enable_module(BOARD_RS232_1_GPIO_MAP,
                           sizeof(BOARD_RS232_1_GPIO_MAP) / 
                           sizeof(BOARD_RS232_1_GPIO_MAP[0]));
#endif
#endif /* NO_SERIAL */
}

static void init_printk(void)
{
#ifndef NO_SERIAL
#if defined(CONFIG_CONSOLE_PORT)
	const usart_options_t usart_options = {
		.baudrate = 57600,
		.charlength = 8,
		.paritytype = USART_NO_PARITY,
		.stopbits = USART_1_STOPBIT,
		.channelmode = USART_NORMAL_CHMODE
	};
	usart_init_rs232(&CONFIG_CONSOLE_PORT, &usart_options, FPBA_HZ);
#endif
#endif /* NO_SERIAL */
}

void board_init(void)
{
        
    init_exceptions();
    init_hmatrix();
    init_sys_clocks();
    init_interrupts();

    init_rs232();
    init_printk();
        
#ifdef WITH_SDRAM
    sdramc_init(FHSB_HZ);
#endif
    init_spi();
}
예제 #7
0
파일: macb.c 프로젝트: motion55/LWIPTEST2
static void prvSetupMACBInterrupt(volatile avr32_macb_t *macb)
{
#ifdef FREERTOS_USED
  // Create the semaphore used to trigger the MACB task.
  if (xSemaphore == NULL)
  {
    vSemaphoreCreateBinary( xSemaphore );
  }
#else
  // Init the variable counting the number of received frames not yet read.
  DataToRead = 0;
#endif


#ifdef FREERTOS_USED
  if( xSemaphore != NULL)
  {
    // We start by 'taking' the semaphore so the ISR can 'give' it when the
    // first interrupt occurs.
    xSemaphoreTake( xSemaphore, 0 );
#endif
    // Setup the interrupt for MACB.
    // Register the interrupt handler to the interrupt controller at interrupt level 2
    INTC_register_interrupt((__int_handler)&vMACB_ISR, AVR32_MACB_IRQ, AVR32_INTC_INT2);

#if ETHERNET_CONF_USE_PHY_IT == 1
	#if EXTPHY_MACB_USE_EXTINT
	static const gpio_map_t EIC_GPIO_MAP =
	{
		{EXTPHY_MACB_INTERRUPT_PIN, EXTPHY_MACB_INTERRUPT_FUNCTION},
	};
	gpio_enable_module(EIC_GPIO_MAP, sizeof(EIC_GPIO_MAP) / sizeof(EIC_GPIO_MAP[0]));
	// Enable GPIO pull ups for the interrupt pin.
	gpio_enable_pin_pull_up(EXTPHY_MACB_INTERRUPT_PIN);
    // Setup the interrupt for PHY.
    // Register the interrupt handler to the interrupt controller at interrupt level 2
    INTC_register_interrupt((__int_handler)&vPHY_ISR, EXTPHY_MACB_INTERRUPT_IRQ, AVR32_INTC_INT2);
	
	// Enable edge-triggered interrupt.
	eic_options.eic_mode  = EIC_MODE_EDGE_TRIGGERED;
	// Interrupt will trigger on falling edge (this is a must-do for the keypad scan
	// feature if the chosen mode is edge-triggered).
	eic_options.eic_edge  = EIC_EDGE_FALLING_EDGE;
	// Initialize in synchronous mode : interrupt is synchronized to the clock
	eic_options.eic_async = EIC_SYNCH_MODE;
	// Set the interrupt line number.
	eic_options.eic_line  = EXTPHY_MACB_INTERRUPT;
	// Init the EIC controller with the options
	eic_init(&AVR32_EIC, &eic_options, 1);
	// Enable the EIC line.
	eic_enable_line(&AVR32_EIC, EXTPHY_MACB_INTERRUPT);
	// Enable the interrupt for the EIC line.
	eic_enable_interrupt_line(&AVR32_EIC, EXTPHY_MACB_INTERRUPT);
	#else
    /* GPIO enable interrupt upon rising edge */
    gpio_enable_pin_interrupt(EXTPHY_MACB_INTERRUPT_PIN, GPIO_FALLING_EDGE);
    // Setup the interrupt for PHY.
    // Register the interrupt handler to the interrupt controller at interrupt level 2
    INTC_register_interrupt((__int_handler)&vPHY_ISR, (AVR32_GPIO_IRQ_0 + (EXTPHY_MACB_INTERRUPT_PIN/8)), AVR32_INTC_INT2);
	#endif
    /* enable interrupts on INT pin */
    vWriteMDIO( macb, PHY_MICR , ( MICR_INTEN | MICR_INTOE ));
    /* enable "link change" interrupt for Phy */
    vWriteMDIO( macb, PHY_MISR , MISR_LINK_INT_EN );
#endif

    // We want to interrupt on Rx and Tx events
    macb->ier = AVR32_MACB_IER_RCOMP_MASK | AVR32_MACB_IER_TCOMP_MASK;
#ifdef FREERTOS_USED
  }
#endif
}
예제 #8
0
파일: lin.c 프로젝트: InSoonPark/asf
/*! \brief  This function initializes the LIN controller and, if needed, the LIN
 *          interrupts.
 *
 * \param master \c true for master, \c false for slave
 * \param l_node Node Value
 * \param b_rate Baudrate Value
 * \param pba_hz PBA Value
 * \return Status PASS / FAIL
 *
 */
U8 lin_init (bool master,
             U8 l_node,
             U16 b_rate,
             long pba_hz) {
if (l_node == 0)
{
    // Enable GPIO Alternate Functions
    gpio_enable_module(USART_LIN_NODE0_GPIO_MAP,
                     sizeof(USART_LIN_NODE0_GPIO_MAP) / sizeof(USART_LIN_NODE0_GPIO_MAP[0]));

    gpio_enable_pin_pull_up(USART_LIN_NODE0_RX_PIN);

    // USART options.
    if (master)
      usart_init_lin_master(usart_lin_node0,b_rate,pba_hz);
    else
      usart_init_lin_slave(usart_lin_node0,b_rate,pba_hz);

    Disable_global_interrupt();

    if (master==false)
    {
		        //! Enable Interrupt for Error flags and end ID Reception
			#if ( defined (AVR32_USART_400_H_INCLUDED) ||  \
                              defined (AVR32_USART_410_H_INCLUDED) ||  \
                              defined (AVR32_USART_420_H_INCLUDED) )
				usart_lin_node0->ier = AVR32_USART_IER_LINIR_MASK  |
							 AVR32_USART_IER_LINBE_MASK  |
							 AVR32_USART_IER_LINISFE_MASK |
							 AVR32_USART_IER_LINIPE_MASK |
							 AVR32_USART_IER_LINCE_MASK  |
							 AVR32_USART_IER_LINSNRE_MASK;
				//! Register Interrupt for LIN
				INTC_register_interrupt(&lin_int_handler_node0,
										USART_LIN_NODE0_USART_IRQ,
										USART_LIN_NODE0_USART_IRQ_LEVEL);
			#else

				usart_lin_node0->ier = AVR32_USART_IER_LINID_MASK  |
							 AVR32_USART_IER_LINBE_MASK  |
							 AVR32_USART_IER_LINISFE_MASK |
							 AVR32_USART_IER_LINIPE_MASK |
							 AVR32_USART_IER_LINCE_MASK  |
							 AVR32_USART_IER_LINSNRE_MASK;
				//! Register Interrupt for LIN
				INTC_register_interrupt(&lin_int_handler_node0,
										USART_LIN_NODE0_USART_IRQ,
										USART_LIN_NODE0_USART_IRQ_LEVEL);
			#endif
    }

    //! Register Interrupt for PDCA Transfer TX
    INTC_register_interrupt(&lin_pdca_int_tx_handler_node0,
                            USART_LIN_NODE0_PDCA_TX_IRQ,
                            USART_LIN_NODE0_PDCA_TX_IRQ_LEVEL);

    //! Register Interrupt for PDCA Transfer RX
    INTC_register_interrupt(&lin_pdca_int_rx_handler_node0,
                            USART_LIN_NODE0_PDCA_RX_IRQ,
                            USART_LIN_NODE0_PDCA_RX_IRQ_LEVEL);

}
#ifdef USART_LIN_NODE1_INSTANCE
else
{
    // Enable GPIO Alternate Functions
    gpio_enable_module(USART_LIN_NODE1_GPIO_MAP,
                     sizeof(USART_LIN_NODE1_GPIO_MAP) / sizeof(USART_LIN_NODE1_GPIO_MAP[0]));


    gpio_enable_pin_pull_up(USART_LIN_NODE1_RX_PIN);

    // USART options.
    if (master)
      usart_init_lin_master(usart_lin_node1,b_rate,pba_hz);
    else
      usart_init_lin_slave(usart_lin_node1,b_rate,pba_hz);

    Disable_global_interrupt();

    if (master==false)
    {
		        //! Enable Interrupt for Error flags and end ID Reception
			#if ( defined (AVR32_USART_400_H_INCLUDED) ||  \
                              defined (AVR32_USART_410_H_INCLUDED) ||  \
                              defined (AVR32_USART_420_H_INCLUDED) )
				usart_lin_node1->ier = AVR32_USART_IER_LINIR_MASK  |
							 AVR32_USART_IER_LINBE_MASK  |
							 AVR32_USART_IER_LINISFE_MASK |
							 AVR32_USART_IER_LINIPE_MASK |
							 AVR32_USART_IER_LINCE_MASK  |
							 AVR32_USART_IER_LINSNRE_MASK;
				//! Register Interrupt for LIN
				INTC_register_interrupt(&lin_int_handler_node1,
										USART_LIN_NODE1_USART_IRQ,
										USART_LIN_NODE1_USART_IRQ_LEVEL);
			#else
				usart_lin_node1->ier = AVR32_USART_IER_LINID_MASK  |
							 AVR32_USART_IER_LINBE_MASK  |
							 AVR32_USART_IER_LINISFE_MASK |
							 AVR32_USART_IER_LINIPE_MASK |
							 AVR32_USART_IER_LINCE_MASK  |
							 AVR32_USART_IER_LINSNRE_MASK;
				//! Register Interrupt for LIN
				INTC_register_interrupt(&lin_int_handler_node1,
										USART_LIN_NODE1_USART_IRQ,
										USART_LIN_NODE1_USART_IRQ_LEVEL);
			#endif
    }

    //! Register Interrupt for PDCA Transfer TX
    INTC_register_interrupt(&lin_pdca_int_tx_handler_node1,
                            USART_LIN_NODE1_PDCA_TX_IRQ,
                            USART_LIN_NODE1_PDCA_TX_IRQ_LEVEL);

    //! Register Interrupt for PDCA Transfer RX
    INTC_register_interrupt(&lin_pdca_int_rx_handler_node1,
                            USART_LIN_NODE1_PDCA_RX_IRQ,
                            USART_LIN_NODE1_PDCA_RX_IRQ_LEVEL);
}
#endif
    return PASS;
}
int main(void)
{
	enum sleepmgr_mode      current_sleep_mode = SLEEPMGR_ACTIVE;
	uint32_t                ast_counter = 0;

	/*
	 * Initialize the synchronous clock system to the default configuration
	 * set in conf_clock.h.
	 * \note All non-essential peripheral clocks are initially disabled.
	 */
	sysclk_init();

	/*
	 * Initialize the resources used by this example to the default
	 * configuration set in conf_board.h
	 */
	board_init();

	/*
	 * Turn the activity status LED on to inform the user that the device
	 * is active.
	 */
	gpio_set_pin_low(LED_ACTIVITY_STATUS_PIN);

	/*
	 * Configure pin change interrupt for asynchronous wake-up (required to
	 * wake up from the STATIC sleep mode) and enable the EIC clock.
	 *
	 * First, enable the clock for the EIC module.
	 */
	sysclk_enable_pba_module(SYSCLK_EIC);
	/*
	 * Map the interrupt line to the GPIO pin with the right peripheral
	 * function.
	 */
	gpio_enable_module_pin(WAKE_BUTTON_EIC_PIN, WAKE_BUTTON_EIC_FUNCTION);
	/*
	 * Enable the internal pull-up resistor on that pin (because the EIC is
	 * configured such that the interrupt will trigger on low-level, see
	 * eic_options.eic_level).
	 */
	gpio_enable_pin_pull_up(WAKE_BUTTON_EIC_PIN);
	// Init the EIC controller with the options
	eic_init(&AVR32_EIC, &eic_options, sizeof(eic_options) /
			sizeof(eic_options_t));
	// Enable External Interrupt Controller Line
	eic_enable_line(&AVR32_EIC, WAKE_BUTTON_EIC_LINE);

	// Enable the AST clock.
	sysclk_enable_pba_module(SYSCLK_AST);
	// Initialize the AST in Counter mode
	ast_init_counter(&AVR32_AST, AST_OSC_RC, AST_PSEL_RC_1_76HZ,
			ast_counter);
	/*
	 * Configure the AST to wake up the CPU when the counter reaches the
	 * selected alarm0 value.
	 */
	AVR32_AST.WER.alarm0 = 1;
	// Enable the AST
	ast_enable(&AVR32_AST);

	// Initialize the sleep manager, lock initial mode.
	sleepmgr_init();
	sleepmgr_lock_mode(current_sleep_mode);

	while (1) {
		ast_counter = ast_get_counter_value(&AVR32_AST);
		// disable alarm 0
		ast_disable_alarm0(&AVR32_AST);
		// Set Alarm to current time + (6/1.76) seconds
		ast_counter += 6;
		ast_set_alarm0_value(&AVR32_AST, ast_counter);
		// Enable alarm 0
		ast_enable_alarm0(&AVR32_AST);

		/*
		 * Turn the activity status LED off to inform the user that the
		 * device is in a sleep mode.
		 */
		gpio_set_pin_high(LED_ACTIVITY_STATUS_PIN);

		/*
		 * Go to sleep in the deepest allowed sleep mode (i.e. no
		 * deeper than the currently locked sleep mode).
		 */
		sleepmgr_enter_sleep();

		/*
		 * Turn the activity status LED on to inform the user that the
		 * device is active.
		 */
		gpio_set_pin_low(LED_ACTIVITY_STATUS_PIN);

		// After wake up, clear the Alarm0
		AVR32_AST.SCR.alarm0 = 1;

		// Unlock the current sleep mode.
		sleepmgr_unlock_mode(current_sleep_mode);

		// Add a 3s delay
		cpu_delay_ms(3000, sysclk_get_cpu_hz());

		// Clear the External Interrupt Line (in case it was raised).
		eic_clear_interrupt_line(&AVR32_EIC, WAKE_BUTTON_EIC_LINE);

		// Lock the next sleep mode.
		++current_sleep_mode;
		if ((current_sleep_mode >= SLEEPMGR_NR_OF_MODES)
#if UC3L && (BOARD == UC3L_EK)
		/* Note concerning the SHUTDOWN sleep mode: the shutdown sleep
		 * mode can only be used when the UC3L supply mode is the 3.3V
		 * Supply Mode with 1.8V Regulated I/O Lines. That is not how
		 * the UC3L is powered on the ATUC3L-EK so the SHUTDOWN mode
		 * cannot be used on this board. Thus we skip this sleep mode
		 * in this example for this board.
		 */
			|| (current_sleep_mode == SLEEPMGR_SHUTDOWN)
#endif
			) {
			current_sleep_mode = SLEEPMGR_ACTIVE;
		}

		sleepmgr_lock_mode(current_sleep_mode);
	}
}
예제 #10
0
/*
 * \brief main function : do init and loop to wake up CPU through EIC controller
 */
int main(void)
{
	// Structure holding the configuration parameters
	// of the EIC module.
	eic_options_t eic_options;

	// Activate LED0 pin in GPIO output mode and switch LED0 off.
	gpio_set_gpio_pin(LED0_GPIO);

	// Enable level-triggered interrupt.
	eic_options.eic_mode   = EIC_MODE_LEVEL_TRIGGERED;
	// Interrupt will trigger on low-level.
	eic_options.eic_level  = EIC_LEVEL_LOW_LEVEL;
	// Enable filter.
	eic_options.eic_filter = EIC_FILTER_ENABLED;
	// For Wake Up mode, initialize in asynchronous mode
	eic_options.eic_async  = EIC_ASYNCH_MODE;
	// Choose External Interrupt Controller Line
	eic_options.eic_line   = EXT_INT_EXAMPLE_LINE;

	// Map the interrupt line to the GPIO pin with the right peripheral function.
	gpio_enable_module_pin(EXT_INT_EXAMPLE_PIN_LINE, EXT_INT_EXAMPLE_FUNCTION_LINE);
 	/*
	 * Enable the internal pull-up resistor on that pin (because the EIC is
	 * configured such that the interrupt will trigger on low-level, see
	 * eic_options.eic_level).
	 */
	gpio_enable_pin_pull_up(EXT_INT_EXAMPLE_PIN_LINE);

	// Init the EIC controller with the options
	eic_init(&AVR32_EIC, &eic_options,1);

	// Enable External Interrupt Controller Line
	eic_enable_line(&AVR32_EIC, EXT_INT_EXAMPLE_LINE);
	/*
	 * Switch the CPU to static sleep mode.
	 * When the CPU is idle, it is possible to switch off the CPU clock and optionally other
	 * clock domains to save power. This is activated by the sleep instruction, which takes the sleep
	 * mode index number as argument. SLEEP function is defined in \DRIVERS\PM\pm.h.
	 * In static mode, all oscillators, including 32KHz and RC oscillator are stopped.
	 * Bandgap voltage reference BOD detector is turned off.
	 */
	SLEEP(AVR32_PM_SMODE_STATIC);
	/*
	 * Cpu now is in static sleep mode. When the wake-up external interrupt occurs,
	 * the CPU resumes execution here and enter the while(1) loop.
	 */
	while (true)
	{
		// Toggle LED0 for a short while
		toggle_led();

		// Interrupt Line must be cleared to enable next SLEEP action
		eic_clear_interrupt_line(&AVR32_EIC, EXT_INT_EXAMPLE_LINE);

		// re-enter sleep mode.
		SLEEP(AVR32_PM_SMODE_STATIC);
		/*
		 * Cpu now is in static sleep mode. When the wake-up external interrupt occurs,
		 * the CPU resumes execution back from the top of the while loop.
		 */
	}
}
예제 #11
0
파일: init.c 프로젝트: Someone101/aleph
// initialize application timer
extern void init_tc (volatile avr32_tc_t *tc) {
  // waveform options
  static const tc_waveform_opt_t waveform_opt = {
    .channel  = APP_TC_CHANNEL,  // channel
    .bswtrg   = TC_EVT_EFFECT_NOOP, // software trigger action on TIOB
    .beevt    = TC_EVT_EFFECT_NOOP, // external event action
    .bcpc     = TC_EVT_EFFECT_NOOP, // rc compare action
    .bcpb     = TC_EVT_EFFECT_NOOP, // rb compare
    .aswtrg   = TC_EVT_EFFECT_NOOP, // soft trig on TIOA
    .aeevt    = TC_EVT_EFFECT_NOOP, // etc
    .acpc     = TC_EVT_EFFECT_NOOP,
    .acpa     = TC_EVT_EFFECT_NOOP,
    // Waveform selection: Up mode with automatic trigger(reset) on RC compare.
    .wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,
    .enetrg   = false,             // external event trig
    .eevt     = 0,                 // extern event select
    .eevtedg  = TC_SEL_NO_EDGE,    // extern event edge
    .cpcdis   = false,             // counter disable when rc compare
    .cpcstop  = false,            // counter stopped when rc compare
    .burst    = false,
    .clki     = false,
    // Internal source clock 5, connected to fPBA / 128.
    .tcclks   = TC_CLOCK_SOURCE_TC5
  };

  // Options for enabling TC interrupts
  static const tc_interrupt_t tc_interrupt = {
    .etrgs = 0,
    .ldrbs = 0,
    .ldras = 0,
    .cpcs  = 1, // Enable interrupt on RC compare alone
    .cpbs  = 0,
    .cpas  = 0,
    .lovrs = 0,
    .covfs = 0
  };
  // Initialize the timer/counter.
  tc_init_waveform(tc, &waveform_opt);

  // set timer compare trigger.
  // we want it to overflow and generate an interrupt every 1 ms
  // so (1 / fPBA / 128) * RC = 0.001
  // so RC = fPBA / 128 / 1000
  tc_write_rc(tc, APP_TC_CHANNEL, (FPBA_HZ / 128 / 1000));
  // configure the timer interrupt
  tc_configure_interrupts(tc, APP_TC_CHANNEL, &tc_interrupt);
  // Start the timer/counter.
  tc_start(tc, APP_TC_CHANNEL);
}


// initialize usb USARTy
void init_ftdi_usart (void) {
  // GPIO map for USART.
  static const gpio_map_t FTDI_USART_GPIO_MAP = {
    { FTDI_USART_RX_PIN, FTDI_USART_RX_FUNCTION },
    { FTDI_USART_TX_PIN, FTDI_USART_TX_FUNCTION }
  };
  
  // Options for USART.
  static const usart_options_t FTDI_USART_OPTIONS = {
    .baudrate = FTDI_USART_BAUDRATE,
    .charlength = 8,
    .paritytype = USART_NO_PARITY,
    .stopbits = USART_1_STOPBIT,
    .channelmode = USART_NORMAL_CHMODE
  };

  // Set up GPIO for FTDI_USART
  gpio_enable_module(FTDI_USART_GPIO_MAP,
                     sizeof(FTDI_USART_GPIO_MAP) / sizeof(FTDI_USART_GPIO_MAP[0]));

  // Initialize in RS232 mode.
  usart_init_rs232(FTDI_USART, &FTDI_USART_OPTIONS, FPBA_HZ);
}

// initialize spi1: OLED, ADC, SD/MMC
extern void init_spi1 (void) {
  
  static const gpio_map_t OLED_SPI_GPIO_MAP = {
    {OLED_SPI_SCK_PIN,  OLED_SPI_SCK_FUNCTION },
    {OLED_SPI_MISO_PIN, OLED_SPI_MISO_FUNCTION},
    {OLED_SPI_MOSI_PIN, OLED_SPI_MOSI_FUNCTION},
    {OLED_SPI_NPCS0_PIN,  OLED_SPI_NPCS0_FUNCTION },
    {OLED_SPI_NPCS1_PIN,  OLED_SPI_NPCS1_FUNCTION },
    {OLED_SPI_NPCS2_PIN,  OLED_SPI_NPCS2_FUNCTION },
  };

  // SPI options for OLED
  spi_options_t spiOptions = {
    .reg = OLED_SPI_NPCS,
    .baudrate     = 40000000,
    .bits = 8,
    .trans_delay = 0,
    .spck_delay = 0,
    .stay_act = 1,
    .spi_mode = 3,
    .modfdis = 1
  };

  // Assign GPIO to SPI.
  gpio_enable_module(OLED_SPI_GPIO_MAP,
		     sizeof(OLED_SPI_GPIO_MAP) / sizeof(OLED_SPI_GPIO_MAP[0]));
  // Initialize as master.
  spi_initMaster(OLED_SPI, &spiOptions);
  // Set SPI selection mode: variable_ps, pcs_decode, delay.
  spi_selectionMode(OLED_SPI, 0, 0, 0);
  // Enable SPI module.
  spi_enable(OLED_SPI);

  // setup chip register for OLED
  spi_setupChipReg( OLED_SPI, &spiOptions, FPBA_HZ );

  // add ADC chip register
  spiOptions.reg          = ADC_SPI_NPCS;
  spiOptions.baudrate     = 20000000;
  spiOptions.bits         = 16;
  spiOptions.spi_mode     = 2;
  spiOptions.spck_delay   = 0;
  spiOptions.trans_delay  = 5;
  spiOptions.stay_act     = 0;
  spiOptions.modfdis      = 0;

  spi_setupChipReg( ADC_SPI, &spiOptions, FPBA_HZ );

  // add SD/MMC chip register
  spiOptions.reg         = SD_MMC_SPI_NPCS;
  spiOptions.baudrate    = SD_MMC_SPI_MASTER_SPEED; // Defined in conf_sd_mmc_spi.h;
  spiOptions.bits        = SD_MMC_SPI_BITS; // Defined in conf_sd_mmc_spi.h;
  spiOptions.spck_delay  = 0;
  spiOptions.trans_delay = 0;
  spiOptions.stay_act    = 1;
  spiOptions.spi_mode    = 0;
  spiOptions.modfdis     = 1;

  // Initialize SD/MMC driver with SPI clock (PBA).
  sd_mmc_spi_init(spiOptions, FPBA_HZ);
}


// init PDCA (Peripheral DMA Controller A) resources for the SPI transfer and start a dummy transfer
void init_local_pdca(void)
{
  // PDCA channel for SPI RX
  pdca_channel_options_t pdca_options_SPI_RX ={ // pdca channel options
    .addr = (void *)&pdcaRxBuf,
    .size = FS_BUF_SIZE,                      // transfer size
    .r_addr = NULL,                           // next memory address after 1st transfer complete
    .r_size = 0,                              // next transfer counter not used here
    .pid = AVR32_PDCA_CHANNEL_USED_RX,        // select peripheral ID - SPI1 RX
    .transfer_size = PDCA_TRANSFER_SIZE_BYTE  // select size of the transfer: 8,16,32 bits
  };

  // PDCA channel for SPI TX
  pdca_channel_options_t pdca_options_SPI_TX ={ // pdca channel options
    .addr = (void *)&pdcaTxBuf,               // memory address.
    .size = FS_BUF_SIZE,                      // transfer size
    .r_addr = NULL,                           // next memory address after 1st transfer complete
    .r_size = 0,                              // next transfer counter not used here
    .pid = AVR32_PDCA_CHANNEL_USED_TX,        // select peripheral ID - SPI1 TX
    .transfer_size = PDCA_TRANSFER_SIZE_BYTE  // select size of the transfer: 8,16,32 bits
  };

  // Init PDCA transmission channel
  pdca_init_channel(AVR32_PDCA_CHANNEL_SPI_TX, &pdca_options_SPI_TX);

  // Init PDCA Reception channel
  pdca_init_channel(AVR32_PDCA_CHANNEL_SPI_RX, &pdca_options_SPI_RX);
}

// intialize resources for bf533 communication: SPI, GPIO
void init_bfin_resources(void) {
  static const gpio_map_t BFIN_SPI_GPIO_MAP = {
    { BFIN_SPI_SCK_PIN, BFIN_SPI_SCK_FUNCTION },
    { BFIN_SPI_MISO_PIN, BFIN_SPI_MISO_FUNCTION },
    { BFIN_SPI_MOSI_PIN, BFIN_SPI_MOSI_FUNCTION },
    { BFIN_SPI_NPCS0_PIN, BFIN_SPI_NPCS0_FUNCTION },
  };
  
  spi_options_t spiOptions = {
    .reg          = BFIN_SPI_NPCS,
    //// FIXME: 
    //// would prefer fast baudrate / lower trans delay during boot,
    //// but need multiple registers for boot (fast) and run (slow)
    //// investigate if this is possible...
    //   .baudrate     = 20000000,
    //     .baudrate     = 10000000,
    //     .baudrate     = 5000000,
     .baudrate     = 20000000,
    .bits         = 8,
    .spck_delay   = 0,
    //    .trans_delay  = 0,
    .trans_delay = 20,
    .stay_act     = 1,
    .spi_mode     = 1,
    .modfdis      = 1
  };

  // assign pins to SPI.
  gpio_enable_module(BFIN_SPI_GPIO_MAP,
		     sizeof(BFIN_SPI_GPIO_MAP) / sizeof(BFIN_SPI_GPIO_MAP[0]));

  // intialize as master
  spi_initMaster(BFIN_SPI, &spiOptions);

  // set selection mode: variable_ps, pcs_decode, delay.
  spi_selectionMode(BFIN_SPI, 0, 0, 0);

  // enable SPI.
  spi_enable(BFIN_SPI);

  // intialize the chip register
  spi_setupChipReg(BFIN_SPI, &spiOptions, FPBA_HZ);
  // enable pulldown on bfin HWAIT line
  //// shit! not implemented... 
  // gpio_enable_pin_pull_down(BFIN_HWAIT_PIN);
  
  // enable pullup on bfin RESET line
  gpio_enable_pin_pull_up(BFIN_RESET_PIN);
}

// intialize two-wire interface
void init_twi(void) {
  // TWI/I2C GPIO map
  static const gpio_map_t TWI_GPIO_MAP = {
    { TWI_DATA_PIN, TWI_DATA_FUNCTION },
    { TWI_CLOCK_PIN, TWI_CLOCK_FUNCTION }
  };
  gpio_enable_module(TWI_GPIO_MAP, sizeof(TWI_GPIO_MAP) / sizeof(TWI_GPIO_MAP[0]));
}


// initialize USB host stack
void init_usb_host (void) {
  //  pm_configure_usb_clock();
  uhc_start();
}
예제 #12
0
파일: init.c 프로젝트: Someone101/aleph
// initialize non-peripheral GPIO
void init_gpio(void) {
  
  gpio_enable_pin_pull_up(ENC0_S0_PIN);
  gpio_enable_pin_pull_up(ENC0_S1_PIN);
  gpio_enable_pin_pull_up(ENC1_S0_PIN);
  gpio_enable_pin_pull_up(ENC1_S1_PIN);
  gpio_enable_pin_pull_up(ENC2_S0_PIN);
  gpio_enable_pin_pull_up(ENC2_S1_PIN);
  gpio_enable_pin_pull_up(ENC3_S0_PIN);
  gpio_enable_pin_pull_up(ENC3_S1_PIN);

#if 0
  gpio_enable_pin_pull_up(SW0_PIN);
  gpio_enable_pin_pull_up(SW1_PIN);
  gpio_enable_pin_pull_up(SW2_PIN);
  gpio_enable_pin_pull_up(SW3_PIN);
  gpio_enable_pin_pull_up(SW_MODE_PIN);
#endif

  gpio_enable_pin_pull_up(SW_POWER_PIN);

  /// trying this...
  /* gpio_enable_pin_glitch_filter(SW0_PIN); */
  /* gpio_enable_pin_glitch_filter(SW1_PIN); */
  /* gpio_enable_pin_glitch_filter(SW2_PIN); */
  /* gpio_enable_pin_glitch_filter(SW3_PIN); */
  gpio_enable_pin_glitch_filter(SW_MODE_PIN); 
}
예제 #13
0
void sd_mmc_mci_resources_init (void)
{
    static const gpio_map_t SD_MMC_MCI_GPIO_MAP = {
        {SD_SLOT_8BITS_CLK_PIN, SD_SLOT_8BITS_CLK_FUNCTION},    // SD CLK.
        {SD_SLOT_8BITS_CMD_PIN, SD_SLOT_8BITS_CMD_FUNCTION},    // SD CMD.
        {SD_SLOT_8BITS_DATA0_PIN, SD_SLOT_8BITS_DATA0_FUNCTION},    // SD DAT[0].
        {SD_SLOT_8BITS_DATA1_PIN, SD_SLOT_8BITS_DATA1_FUNCTION},    // DATA Pin.
        {SD_SLOT_8BITS_DATA2_PIN, SD_SLOT_8BITS_DATA2_FUNCTION},    // DATA Pin.
        {SD_SLOT_8BITS_DATA3_PIN, SD_SLOT_8BITS_DATA3_FUNCTION},    // DATA Pin.
        {SD_SLOT_8BITS_DATA4_PIN, SD_SLOT_8BITS_DATA4_FUNCTION},    // DATA Pin.
        {SD_SLOT_8BITS_DATA5_PIN, SD_SLOT_8BITS_DATA5_FUNCTION},    // DATA Pin.
        {SD_SLOT_8BITS_DATA6_PIN, SD_SLOT_8BITS_DATA6_FUNCTION},    // DATA Pin.
        {SD_SLOT_8BITS_DATA7_PIN, SD_SLOT_8BITS_DATA7_FUNCTION} // DATA Pin.
    };

    // MCI options.
    static const mci_options_t MCI_OPTIONS = {
        .card_speed = 400000,
        .card_slot = SD_SLOT_8BITS, // Default card initialization.
    };

    // Assign I/Os to MCI.
    gpio_enable_module (SD_MMC_MCI_GPIO_MAP, sizeof (SD_MMC_MCI_GPIO_MAP) / sizeof (SD_MMC_MCI_GPIO_MAP[0]));


    // Enable pull-up for Card Detect.
    // gpio_enable_pin_pull_up(SD_SLOT_8BITS_CARD_DETECT);
    gpio_enable_pin_pull_up (SD_SLOT_8BITS_CARD_DETECT_STICK20);

    // Enable pull-up for Write Protect.
    gpio_enable_pin_pull_up (SD_SLOT_8BITS_WRITE_PROTECT);
    //
    // For STICK20 microSD Sockel
    gpio_enable_pin_pull_up (SD_SLOT_CMD_STICK20);
    gpio_enable_pin_pull_up (SD_SLOT_DATA0_STICK20);
    //
    // Initialize SD/MMC with MCI PB clock.
    sd_mmc_mci_init (&MCI_OPTIONS, pcl_freq_param.pba_f, pcl_freq_param.cpu_f);
}

#endif // SD_MMC_MCI_0_MEM == ENABLE || SD_MMC_MCI_1_MEM == ENABLE

/*******************************************************************************

  TestUart0

  Reviews
  Date      Reviewer        Info
  16.08.13  RB              First review

*******************************************************************************/

#define EXAMPLE_USART               (&AVR32_USART0)
#define EXAMPLE_USART_RX_PIN        AVR32_USART0_RXD_0_0_PIN
#define EXAMPLE_USART_RX_FUNCTION   AVR32_USART0_RXD_0_0_FUNCTION
#define EXAMPLE_USART_TX_PIN        AVR32_USART0_TXD_0_0_PIN
#define EXAMPLE_USART_TX_FUNCTION   AVR32_USART0_TXD_0_0_FUNCTION

int TestUart0 (void)
{
    int i;
    int i1;

    static const gpio_map_t USART_GPIO_MAP = {
        {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION},
        {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION}
    };

    // USART options.
    static const usart_options_t USART_OPTIONS = {
        .baudrate = 57600,
        .charlength = 8,
        .paritytype = USART_NO_PARITY,
        .stopbits = USART_1_STOPBIT,
        .channelmode = USART_NORMAL_CHMODE
    };

    // Switch main clock to external oscillator 0 (crystal).
    // pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

    // Assign GPIO to USART.
    gpio_enable_module (USART_GPIO_MAP, sizeof (USART_GPIO_MAP) / sizeof (USART_GPIO_MAP[0]));

    // Initialize USART in RS232 mode.
    usart_init_rs232 (EXAMPLE_USART, &USART_OPTIONS, FPBA_HZ);  // FOSC0);

    //
    for (i = 0; i < 10000; i++)
    {
        usart_putchar (EXAMPLE_USART, 'a');
        for (i1 = 0; i1 < 10000; i1++);

    }

    return (TRUE);
}

/*******************************************************************************

  SmartCard_test

  Reviews
  Date      Reviewer        Info
  16.08.13  RB              First review

*******************************************************************************/

int Simulation_USB_CCID (void);
int nnn = 0;

void SmartCard_test (void)
{

    // Enable pull-up TX/RX
    // gpio_enable_pin_pull_up(ISO7816_USART_TX_PIN);



    // DelayCounterTest ();
    Test_ISO7816_Usart_Pins ();
    // ISO7816_test ();
    // ISO7816_ResetSC_test ();
    // ISO7816_InitSC ();
    // ISO7816_APDU_Test ();
    // LA_OpenPGP_V20_Test ();
    //
    // if (nnn == 0)
    {
        // Simulation_USB_CCID ();
    }
}
예제 #14
0
파일: i2c_driver.c 프로젝트: JohsBL/MobRob
int32_t i2c_driver_init(uint8_t  i2c_device) 
{
	int32_t i;
	volatile avr32_twim_t *twim;
	
	switch (i2c_device) 
	{
		case 0: 
			twim = &AVR32_TWIM0;
			// Register PDCA IRQ interrupt.
			INTC_register_interrupt( (__int_handler) &pdca_int_handler_i2c0, TWI0_DMA_IRQ, AVR32_INTC_INT0);
			gpio_enable_module_pin(AVR32_TWIMS0_TWCK_0_0_PIN, AVR32_TWIMS0_TWCK_0_0_FUNCTION);
			gpio_enable_module_pin(AVR32_TWIMS0_TWD_0_0_PIN, AVR32_TWIMS0_TWD_0_0_FUNCTION);
		break;
		
		case 1:
			twim = &AVR32_TWIM1;// Register PDCA IRQ interrupt.
			INTC_register_interrupt( (__int_handler) &pdca_int_handler_i2c0, TWI1_DMA_IRQ, AVR32_INTC_INT0);
			gpio_enable_module_pin(AVR32_TWIMS1_TWCK_0_0_PIN, AVR32_TWIMS1_TWCK_0_0_FUNCTION);
			gpio_enable_module_pin(AVR32_TWIMS1_TWD_0_0_PIN, AVR32_TWIMS1_TWD_0_0_FUNCTION);
			gpio_enable_pin_pull_up(AVR32_TWIMS1_TWCK_0_0_PIN);
			gpio_enable_pin_pull_up(AVR32_TWIMS1_TWD_0_0_PIN);
		break;
		
		default: // invalid device ID
			return -1;
	}		
	for (i = 0; i < I2C_SCHEDULE_SLOTS; i++) 
	{
		schedule[i2c_device][i].active = -1;
	}
				
	bool global_interrupt_enabled = cpu_irq_is_enabled ();
	// Disable TWI interrupts
	if (global_interrupt_enabled) 
	{
		cpu_irq_disable ();
	}
	twim->idr = ~0UL;
	// Enable master transfer
	twim->cr = AVR32_TWIM_CR_MEN_MASK;
	// Reset TWI
	twim->cr = AVR32_TWIM_CR_SWRST_MASK;
	
	if (global_interrupt_enabled) 
	{
		cpu_irq_enable ();
	}
	// Clear SR
	twim->scr = ~0UL;
	
	// register Register twim_master_interrupt_handler interrupt on level CONF_TWIM_IRQ_LEVEL
//	irqflags_t flags = cpu_irq_save();
//	irq_register_handler(twim_master_interrupt_handler,
//			CONF_TWIM_IRQ_LINE, CONF_TWIM_IRQ_LEVEL);
//	cpu_irq_restore(flags);
	
	// Select the speed
	if (twim_set_speed(twim, 100000, sysclk_get_pba_hz()) == 
			ERR_INVALID_ARG) 
	{	
		return ERR_INVALID_ARG;
	}
	return STATUS_OK;
}
예제 #15
0
/**
 * \brief Application main loop.
 */
int main(void)
{
	uint32_t state = 0;
	/**
	 * \note the call to sysclk_init() will disable all non-vital
	 * peripheral clocks, except for the peripheral clocks explicitly
	 * enabled in conf_clock.h.
	 */
	sysclk_init();

	/**
	 * Enable the clock to the selected example GPIO peripheral module.
	 */
	sysclk_enable_pba_module(SYSCLK_GPIO);

	// Pull-up is enabled for all used pins
	gpio_enable_pin_pull_up(GPIO_PIN_EXAMPLE_1);
	gpio_enable_pin_pull_up(GPIO_PIN_EXAMPLE_2);
	gpio_enable_pin_pull_up(GPIO_PIN_EXAMPLE_3);


	// Disable all interrupts
	cpu_irq_disable();
	INTC_init_interrupts();
	// Register GPIO Pin Change Interrupt
	INTC_register_interrupt(&gpio_pin_change_interrupt_handler,
			AVR32_GPIO_IRQ_0, AVR32_INTC_INT0);
	// Enable pin change interrupt for GPIO_PIN_EXAMPLE_2
	gpio_enable_pin_interrupt(GPIO_PIN_EXAMPLE_2, GPIO_PIN_CHANGE);
	// Enable all interrupts
	cpu_irq_enable();

	// Based on the variable, GPIO_PIN_EXAMPLE_1 will be changed.
	while (1) {
		switch (state) {
		case 0:
			// Access with GPIO driver gpio.c with clear and set access.
			gpio_clr_gpio_pin(GPIO_PIN_EXAMPLE_1);
			state++;
			break;

		case 1:
			gpio_set_gpio_pin(GPIO_PIN_EXAMPLE_1);
			state++;
			break;

		case 2:
			// Note that it is also possible to use the GPIO toggle feature.
			gpio_tgl_gpio_pin(GPIO_PIN_EXAMPLE_1);
			state++;
			break;

		default:
			gpio_tgl_gpio_pin(GPIO_PIN_EXAMPLE_1);
			state = 0;
			break;
		}

		// Check GPIO_PIN_EXAMPLE_1 value to modify GPIO_PIN_EXAMPLE_2.
		if (gpio_get_pin_value(GPIO_PIN_EXAMPLE_1) == 0)
			gpio_clr_gpio_pin(GPIO_PIN_EXAMPLE_2);
		else
			gpio_set_gpio_pin(GPIO_PIN_EXAMPLE_2);
	}
	while (true) {
		cpu_relax();
	}
}