static long prvPHY_ISR_NonNakedBehaviour(void) { // Variable definitions can be made now. volatile unsigned long ulIntStatus, ulEventStatus; long xSwitchRequired = false; // read Phy Interrupt register Status ulIntStatus = ulReadMDIO(&AVR32_MACB, PHY_MISR); // read Phy status register ulEventStatus = ulReadMDIO(&AVR32_MACB, PHY_BMSR); // dummy read ulEventStatus = ulReadMDIO(&AVR32_MACB, PHY_BMSR); if(ulEventStatus & BMSR_LSTATUS) { prvSetupMACBConfig(&AVR32_MACB); } #if EXTPHY_MACB_USE_EXTINT eic_clear_interrupt_line(&AVR32_EIC, EXTPHY_MACB_INTERRUPT); #else volatile avr32_gpio_t *gpio = &AVR32_GPIO; volatile avr32_gpio_port_t *gpio_port = &gpio->port[EXTPHY_MACB_INTERRUPT_PIN/32]; // clear interrupt flag on GPIO gpio_port->ifrc = 1 << (EXTPHY_MACB_INTERRUPT_PIN%32); #endif return ( xSwitchRequired ); }
void eic_nmi_handler( void ) { //int32_t i = 0; __asm__ __volatile__ ( /* Save registers not saved upon NMI exception. */ "pushm r0-r12, lr\n\t" ); //interrupt_counter++; if (sample_counter < ADC_BUFFER_SIZE) { spi_buffered_trigger_DMA(0, 12); } else { //eic_disable_interrupt_line(&AVR32_EIC,eic_options[0].eic_line); } eic_clear_interrupt_line(&AVR32_EIC, EXT_NMI); __asm__ __volatile__ ( /* Restore the registers. */ "popm r0-r12, lr\n\t" /* Leaving the exception handler. */ "rete" ); }
__interrupt #endif void at42qt1060_detect_eic_int_handler(void) { eic_clear_interrupt_line(&AVR32_EIC, AT42QT1060_EIC_LINE); if(at42qt1060.touch_detect_callback) at42qt1060.touch_detect_callback(); }
void touch_button_isr(void){ if(is_touch_up()){ gpio_tgl_gpio_pin(LED0_GPIO); } if(is_touch_down()){ gpio_tgl_gpio_pin(LED1_GPIO); } if(is_touch_right()){ gpio_tgl_gpio_pin(LED1_GPIO); } if(is_touch_left()){ gpio_tgl_gpio_pin(LED2_GPIO); } if(is_touch_center()){ gpio_tgl_gpio_pin(LED2_GPIO); } eic_clear_interrupt_line(&AVR32_EIC, QT1081_EIC_EXTINT_INT); }
///< 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); } }
/* * \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. */ } }
__attribute__ ((__interrupt__)) void touch_button_isr(void){ eic_clear_interrupt_line(&AVR32_EIC, QT1081_EIC_EXTINT_INT); // UP if(gpio_get_pin_value(QT1081_TOUCH_SENSOR_UP)) { //gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_UP); //gpio_tgl_gpio_pin(LED0_GPIO); pm_switch_to_clock(&AVR32_PM,0); //cambia al RC pm_pll_disable(&AVR32_PM,0); // deshabilita el el PLL 0 pm_pll_setup(&AVR32_PM,0,vel++,1,0,16); // lockcount in main clock for the PLL wait lock //_______________________________________________________________________________ // Establece la frecuencia de salida del PLL pm_pll_set_option(&AVR32_PM,0,1,0,0);//1 Star-up faster, Start-up normal //_______________________________________________________________________________ //Habilita el PLL 0 pm_pll_enable(&AVR32_PM,0); //_______________________________________________________________________________ //Espera a que se establesca el PLL pm_wait_for_pll0_locked(&AVR32_PM) ; //_______________________________________________________________________________ // Set one wait-state (WS) for flash controller flashc_set_wait_state(1); //habilita la salida del PLL0 con 2 y el OSC0 con 1 pm_switch_to_clock(&AVR32_PM, 2); if (vel>=6) { vel=6; } } // DOWN if(gpio_get_pin_value(QT1081_TOUCH_SENSOR_DOWN)) { //gpio_tgl_gpio_pin(LED1_GPIO); pm_switch_to_clock(&AVR32_PM,0); //cambia al RC pm_pll_disable(&AVR32_PM,0); // deshabilita el el PLL 0 pm_pll_setup(&AVR32_PM,0,vel--,1,0,16); // lockcount in main clock for the PLL wait lock //_______________________________________________________________________________ // Establece la frecuencia de salida del PLL pm_pll_set_option(&AVR32_PM,0,1,0,0);//1 Star-up faster, Start-up normal //_______________________________________________________________________________ //Habilita el PLL 0 pm_pll_enable(&AVR32_PM,0); //_______________________________________________________________________________ //Espera a que se establesca el PLL pm_wait_for_pll0_locked(&AVR32_PM) ; //_______________________________________________________________________________ // Set one wait-state (WS) for flash controller flashc_set_wait_state(1); //habilita la salida del PLL0 con 2 y el OSC0 con 1 pm_switch_to_clock(&AVR32_PM, 2); if (vel<=2) { vel=2; } } }
/*! \internal Sensor Board external interrupt handler - PIN5 * * This is the ISR for the Xplained Sensor board GPIO PIN5 for configurations * in which it can generate an external interrupt. * * \return Nothing. */ ISR(eic_pin5_handler, AVR32_EIC_IRQ_GROUP, EIC_INT_LVL) { sensor_pin5_handler(sensor_pin5_arg); /* call handler in driver */ eic_clear_interrupt_line(&AVR32_EIC, SENSOR_PIN5_EIC_LINE); }