Beispiel #1
0
/** \brief Register an external interrupt handler for the touch event.
 *
 */
void at42qt1060_register_eic_int(void (*touch_detect_callback)(void))
{
  eic_options_t eic_options[1];

  at42qt1060.touch_detect_callback = touch_detect_callback;

  gpio_enable_module_pin(AT42QT1060_DETECT_PIN, AT42QT1060_EIC_EXTINT_FUNCTION);

  Disable_global_interrupt();

  INTC_register_interrupt(&at42qt1060_detect_eic_int_handler, AT42QT1060_EIC_EXTINT_IRQ,
    AT42QT1060_EIC_EXTINT_LEVEL);

  eic_options[0].eic_mode = EIC_MODE_EDGE_TRIGGERED;
  eic_options[0].eic_level = EIC_EDGE_FALLING_EDGE;
  eic_options[0].eic_async = EIC_SYNCH_MODE;
  eic_options[0].eic_line = AT42QT1060_EIC_LINE;

  eic_init(&AVR32_EIC, &eic_options[0], 1);
  eic_enable_lines(&AVR32_EIC, (1 << eic_options[0].eic_line));
  eic_enable_interrupt_lines(&AVR32_EIC, (1 << eic_options[0].eic_line));

  Enable_global_interrupt();

  return;
}
void Actividad3(void){
	
pm_switch_to_osc0(&AVR32_PM,FOSC0,OSC0_STARTUP);

Disable_global_interrupt();
//! Structure holding the configuration parameters of the EIC module.
eic_options_t eic_options[2];

// Enable edge-triggered interrupt.
eic_options[0].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[0].eic_edge  = EIC_EDGE_RISING_EDGE;
// Initialize in synchronous mode : interrupt is synchronized to the clock
eic_options[0].eic_async = EIC_SYNCH_MODE;
// Set the interrupt line number.
eic_options[0].eic_line  = QT1081_EIC_EXTINT_INT;


INTC_init_interrupts();
    /* Register the EXTINT1 interrupt handler to the interrupt controller
     */
	INTC_register_interrupt(&touch_button_isr, QT1081_EIC_EXTINT_IRQ, AVR32_INTC_INT0);
 // Init the EIC controller with the options
 eic_init(&AVR32_EIC, eic_options, 1);
 // Enable the EIC lines.
 eic_enable_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));
 // Enable the interrupt for each EIC line.
 eic_enable_interrupt_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));
 
 gpio_enable_module_pin( QT1081_EIC_EXTINT_PIN, QT1081_EIC_EXTINT_FUNCTION);

 Enable_global_interrupt();
 
 while (1){
	 gpio_tgl_gpio_pin(LED0_GPIO);
	 gpio_tgl_gpio_pin(LED1_GPIO);
	 gpio_tgl_gpio_pin(LED2_GPIO);
	 gpio_tgl_gpio_pin(LED3_GPIO);
	 delay_s(100);

 }
 

}
Beispiel #3
0
/*! \brief Enable an EIC interrupt line.
 *
 * This routine maps a GPIO pin and peripheral function to a specified EIC line.
 *
 * \param eic_line      Line number to enable
 * \param eic_pin       GPIO module pin
 * \param eic_func      GPIO module function
 * \param eic_irq       IRQ of the interrupt handler
 * \param eic_handler   Interrupt handler to register
 */
static void eic_irq_connect(uint32_t eic_line, uint32_t eic_pin,
		uint32_t eic_func, uint32_t eic_irq, __int_handler eic_handler)
{
	eic_options_t const eic_options = {
		.eic_line   = eic_line,
		.eic_mode   = EIC_MODE_EDGE_TRIGGERED,
		.eic_edge   = EIC_EDGE_RISING_EDGE,
		.eic_level  = EIC_LEVEL_HIGH_LEVEL,
		.eic_filter = EIC_FILTER_ENABLED,
		.eic_async  = EIC_ASYNCH_MODE
	};

	sysclk_enable_pba_module(SYSCLK_EIC);

	gpio_enable_module_pin(eic_pin, eic_func);
	irq_register_handler(eic_handler, eic_irq, 0);

	eic_init(&AVR32_EIC, &eic_options, 1);
	eic_enable_line(&AVR32_EIC, eic_line);
	eic_enable_interrupt_line(&AVR32_EIC, eic_line);
}
Beispiel #4
0
// main function
int main(void) {

	pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

	// Enable edge-triggered interrupt.
	eic_options[0].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[0].eic_edge  = EIC_EDGE_RISING_EDGE;
	// Initialize in synchronous mode : interrupt is synchronized to the clock
	eic_options[0].eic_async = EIC_SYNCH_MODE;
	// Set the interrupt line number.
	eic_options[0].eic_line  = QT1081_EIC_EXTINT_INT;

	// Activate LED0 & LED1 & LED2 & LED3 pins in GPIO output mode and switch them off.
	gpio_set_gpio_pin(LED0_GPIO);
	gpio_set_gpio_pin(LED1_GPIO);
	gpio_set_gpio_pin(LED2_GPIO);
	gpio_set_gpio_pin(LED3_GPIO);

	gpio_enable_module_pin( QT1081_EIC_EXTINT_PIN, QT1081_EIC_EXTINT_FUNCTION);

#if( INT_MODE == INT_MODE_GPIO)
	Disable_global_interrupt();

#if __GNUC__
	INTC_init_interrupts();
    /* Register interrupt handler to the interrupt controller
     * up, down buttons on PB22, PB23 -> GPIO_IRQ_6
     */
	INTC_register_interrupt(&touch_button_isr, AVR32_GPIO_IRQ_6, 0);//AVR32_INTC_INT0);
	/* Other buttons on PB[24..26] -> GPIO_IRQ_7 (PB23 - PB31) */
	INTC_register_interrupt(&touch_button_isr, AVR32_GPIO_IRQ_7, 0);
#endif
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_0, GPIO_RISING_EDGE);
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_1, GPIO_RISING_EDGE);
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_2, GPIO_RISING_EDGE);
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_3, GPIO_RISING_EDGE);
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_4, GPIO_RISING_EDGE);

	Enable_global_interrupt();
#endif

#if(INT_MODE == INT_MODE_EIC)
	Disable_global_interrupt();

#if __GNUC__
	INTC_init_interrupts();
    /* Register the EXTINT1 interrupt handler to the interrupt controller
     */
	INTC_register_interrupt(&touch_button_isr, QT1081_EIC_EXTINT_IRQ, AVR32_INTC_INT0);
#endif

	  // Init the EIC controller with the options
	  eic_init(&AVR32_EIC, eic_options, 1);
	  // Enable the EIC lines.
	  eic_enable_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));
	  // Enable the interrupt for each EIC line.
	  eic_enable_interrupt_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));

	Enable_global_interrupt();
#endif

	while(true);

	return 0;
}
Beispiel #5
0
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
}
Beispiel #6
0
///< Initializes ADC (configures Pins, starts Clock, sets defaults)
void ads1274_init_DAC(void) 
{
	function_generator = NULL;
	
	///< set mode to "high resolution"
	gpio_configure_pin(ADC_MODE0,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_MODE1,GPIO_DIR_OUTPUT | GPIO_INIT_LOW);	
	
	///< set Format to Fixed-position TDM via SPI
	gpio_configure_pin(ADC_FORMAT0,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_FORMAT1,GPIO_DIR_OUTPUT | GPIO_INIT_LOW);	
	gpio_configure_pin(ADC_FORMAT2,GPIO_DIR_OUTPUT | GPIO_INIT_LOW);	
	
	///< configure the four channels
	gpio_configure_pin(ADC_PWDN1,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_PWDN2,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_PWDN3,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_PWDN4,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	

	//gpio_configure_pin(AVR32_TC1_B0_0_0_PIN,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	//gpio_configure_pin(AVR32_PIN_PC19, GPIO_DIR_OUTPUT| GPIO_INIT_HIGH);	

	ads1274_ADC_switch_clock(true);	
	
	//tc_init_waveform(tc, &waveform_opt);  ///< Initialize the timer/counter .

	///< Set the compare triggers.
	//tc_write_rb(tc, EXAMPLE_TC_CHANNEL_ID, 0x1);     ///< Set RA value.
	//tc_write_rc(tc, EXAMPLE_TC_CHANNEL_ID, 0x2);     ///< Set RC value.
	
	///< Start the timer/counter.
	//tc_start(tc, EXAMPLE_TC_CHANNEL_ID);
	
	///< Enable edge-triggered interrupt.
	eic_options[0].eic_mode   = EIC_MODE_EDGE_TRIGGERED;
	///< Interrupt will trigger on falling edge.
	eic_options[0].eic_edge  = EIC_EDGE_FALLING_EDGE;
	///< Initialize in synchronous mode : interrupt is synchronized to the clock
	eic_options[0].eic_async  = EIC_SYNCH_MODE;
	///< Set the interrupt line number.
	eic_options[0].eic_line   = EXT_NMI;
	
	gpio_enable_module_pin(AVR32_EIC_EXTINT_0_1_PIN, AVR32_EIC_EXTINT_0_1_FUNCTION);
	
	///<Disable_global_interrupt();
	///< Initialize interrupt vectors.
	
	eic_init(&AVR32_EIC, eic_options, 1);

	///<INTC_init_interrupts();
	///< initialize SPI0 interface
	spi_buffered_init(&AVR32_SPI0, ADC_SPI_INDEX);
	spi_buffered_init_DMA(0, 12);
	spi_buffered_set_callback(ADC_SPI_INDEX, &process_data);
	
	///< Register the EIC interrupt handlers to the interrupt controller.
	//INTC_register_interrupt(&eic_int_handler1, AVR32_EIC_IRQ_1, AVR32_INTC_INT1);
	///< Enable the chosen lines and their corresponding interrupt feature.
	eic_enable_line(&AVR32_EIC, eic_options[0].eic_line);
	eic_enable_interrupt_line(&AVR32_EIC, eic_options[0].eic_line);
	
	///< Enable_global_interrupt();
	eic_clear_interrupt_line(&AVR32_EIC, EXT_NMI);
	
	///< activate sync and clkdiv
	gpio_configure_pin(ADC_CLKDIV,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
}
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);
	}
}
Beispiel #8
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.
		 */
	}
}
Beispiel #9
0
int main(void) {
    if (PM->RCAUSE.reg & (PM_RCAUSE_POR | PM_RCAUSE_BOD12 | PM_RCAUSE_BOD33)) {
        // On powerup, force a clean reset of the MT7620
        pin_low(PIN_SOC_RST);
        pin_out(PIN_SOC_RST);

        // turn off 3.3V to SoC
        pin_low(PIN_SOC_PWR);
        pin_out(PIN_SOC_PWR);

        // pull 1.8V low
        pin_low(PIN_18_V);
        pin_out(PIN_18_V);

        clock_init_crystal(GCLK_SYSTEM, GCLK_32K);
        timer_clock_enable(TC_BOOT);

        // hold everything low
        boot_delay_ms(50); // power off for 50ms

        pin_high(PIN_SOC_PWR);

        boot_delay_ms(2); // 2ms until 1.8 rail comes on

        pin_high(PIN_18_V);

        boot_delay_ms(50); // 50ms before soc rst comes on
    } else {
        clock_init_crystal(GCLK_SYSTEM, GCLK_32K);
    }

    pin_mux(PIN_USB_DM);
    pin_mux(PIN_USB_DP);
    usb_init();
    usb_attach();
    NVIC_SetPriority(USB_IRQn, 0xff);

    pin_high(PIN_LED);
    pin_out(PIN_LED);

    pin_in(PIN_SOC_RST);

    pin_high(PIN_SOC_PWR);
    pin_out(PIN_SOC_PWR);

    pin_low(PORT_A.power);
    pin_out(PORT_A.power);

    pin_low(PORT_B.power);
    pin_out(PORT_B.power);

    pin_pull_up(PIN_BRIDGE_CS);
    pin_pull_up(PIN_FLASH_CS);

    pin_pull_up(PIN_SERIAL_TX);
    pin_pull_up(PIN_SERIAL_RX);

    dma_init();
    NVIC_EnableIRQ(DMAC_IRQn);
    NVIC_SetPriority(DMAC_IRQn, 0xff);

    eic_init();
    NVIC_EnableIRQ(EIC_IRQn);
    NVIC_SetPriority(EIC_IRQn, 0xff);

    evsys_init();
    NVIC_EnableIRQ(EVSYS_IRQn);
    NVIC_SetPriority(EVSYS_IRQn, 0);

    adc_init(GCLK_SYSTEM, ADC_REFCTRL_REFSEL_INTVCC1);
    dac_init(GCLK_32K);

    bridge_init();

    port_init(&port_a, 1, &PORT_A, GCLK_PORT_A,
        TCC_PORT_A, DMA_PORT_A_TX, DMA_PORT_A_RX);
    port_init(&port_b, 2, &PORT_B, GCLK_PORT_B,
        TCC_PORT_B, DMA_PORT_B_TX, DMA_PORT_B_RX);

    __enable_irq();
    SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;
    
    init_systick();

    while (1) { __WFI(); }
}