// register interrupts void register_interrupts(void) { // enable interrupts on GPIO inputs // gpio_enable_pin_interrupt( NMI, GPIO_PIN_CHANGE); // gpio_enable_pin_interrupt( B06, GPIO_PIN_CHANGE); // gpio_enable_pin_interrupt( B07, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( B08, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( B09, GPIO_PIN_CHANGE); // gpio_enable_pin_interrupt( B10, GPIO_PIN_CHANGE); // PA08 - PA15 // INTC_register_interrupt( &irq_port0_line1, AVR32_GPIO_IRQ_0 + (AVR32_PIN_PA08 / 8), UI_IRQ_PRIORITY); // PB00 - PB07 // INTC_register_interrupt( &irq_port1_line0, AVR32_GPIO_IRQ_0 + (AVR32_PIN_PB00 / 8), UI_IRQ_PRIORITY); // PB08 - PB15 INTC_register_interrupt( &irq_port1_line1, AVR32_GPIO_IRQ_0 + (AVR32_PIN_PB08 / 8), UI_IRQ_PRIORITY); // register TC interrupt INTC_register_interrupt(&irq_tc, APP_TC_IRQ, UI_IRQ_PRIORITY); // register uart interrupt // INTC_register_interrupt(&irq_usart, AVR32_USART0_IRQ, UI_IRQ_PRIORITY); }
void Actividad2(void){ pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); //osc0 a 12Mhz center=0; //Interrupciones Disable_global_interrupt(); INTC_init_interrupts(); INTC_register_interrupt(&tecla_lrc_isr, 71, 0); INTC_register_interrupt(&tecla_lrc_isr, 70,0); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_LEFT,GPIO_RISING_EDGE); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_RIGHT,GPIO_RISING_EDGE); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_ENTER,GPIO_RISING_EDGE); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_UP,GPIO_RISING_EDGE); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_DOWN,GPIO_RISING_EDGE); Enable_global_interrupt(); while (1){} }
/*! * \brief Init the push button 3 sensor. * * \return true upon success, false if error. */ bool b_pushb3_init ( void ) { portCHAR token[6]; // Get the xCFGMutex. if( pdTRUE == x_supervisor_SemaphoreTake( xCFGMutex, 20 ) ) { // get the field if (config_file_get_value(SENSOR_PB3_CONFIG_FILE, "alarm" , token) >= 0) { // update value if (!strcmp(token, "on")) { bAlarm3 = pdTRUE; } } // Release the xCFGMutex. x_supervisor_SemaphoreGive( xCFGMutex ); } /* configure push button to produce IT on input change */ gpio_enable_pin_interrupt(PB3_POSITION , GPIO_PIN_CHANGE); /* Disable all interrupts */ Disable_global_interrupt(); /* register push button 3 handler on level 3 */ INTC_register_interrupt( (__int_handler)&vpushb_ISR, AVR32_GPIO_IRQ_0 + (PB3_POSITION/8), AVR32_INTC_INT3); /* Enable all interrupts */ Enable_global_interrupt(); return (true); }
void controller_init(int cpu_hz, int hsb_hz, int pba_hz, int pbb_hz) { Disable_global_interrupt(); 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); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_UP, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_DOWN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_RIGHT, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_LEFT, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_ENTER, GPIO_PIN_CHANGE); // Enable interrupts globally. Enable_global_interrupt(); static_fcpu_hz = cpu_hz; cpu_set_timeout(cpu_ms_2_cy(JOYSTICK_KEY_DEBOUNCE_MS, static_fcpu_hz), &joystick_key_sensibility_timer); }
void board_init(void) { gpio_configure_pin(LED0_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(LED1_GPIO,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); #if defined (CONF_BOARD_AT86RFX) // AT86RFX SPI GPIO options. static gpio_map_t AT86RFX_SPI_GPIO_MAP = { {AT86RFX_SPI_SCK_PIN, AT86RFX_SPI_SCK_FUNCTION }, {AT86RFX_SPI_MISO_PIN, AT86RFX_SPI_MISO_FUNCTION}, {AT86RFX_SPI_MOSI_PIN, AT86RFX_SPI_MOSI_FUNCTION}, {AT86RFX_SPI_NPCS_PIN, AT86RFX_SPI_NPCS_FUNCTION} }; // Assign GPIO to SPI. gpio_enable_module(AT86RFX_SPI_GPIO_MAP, sizeof(AT86RFX_SPI_GPIO_MAP) / sizeof(AT86RFX_SPI_GPIO_MAP[0])); gpio_enable_pin_interrupt(AT86RFX_IRQ_PIN, GPIO_RISING_EDGE); gpio_clear_pin_interrupt_flag(AT86RFX_IRQ_PIN); gpio_configure_pin(AT86RFX_RST_PIN, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(AT86RFX_SLP_PIN, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); #endif }
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 function to configure push button to generate IT upon rising edge */ void dip204_example_configure_push_buttons_IT(void) { gpio_enable_pin_interrupt(GPIO_CHARSET , GPIO_RISING_EDGE); gpio_enable_pin_interrupt(GPIO_BACKLIGHT_PLUS , GPIO_RISING_EDGE); gpio_enable_pin_interrupt(GPIO_BACKLIGHT_MINUS , GPIO_RISING_EDGE); /* Disable all interrupts */ Disable_global_interrupt(); /* register PB0 handler on level 1 */ INTC_register_interrupt( &dip204_example_PB_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_BACKLIGHT_PLUS/8), AVR32_INTC_INT1); INTC_register_interrupt( &dip204_example_PB_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_BACKLIGHT_MINUS/8), AVR32_INTC_INT1); INTC_register_interrupt( &dip204_example_PB_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_CHARSET/8), AVR32_INTC_INT1); /* Enable all interrupts */ Enable_global_interrupt(); }
/*! * \brief function to configure joystick to generate IT upon falling edge */ void dip204_example_configure_joystick_IT(void) { gpio_enable_pin_interrupt(GPIO_JOYSTICK_UP , GPIO_FALLING_EDGE); gpio_enable_pin_interrupt(GPIO_JOYSTICK_DOWN , GPIO_FALLING_EDGE); gpio_enable_pin_interrupt(GPIO_JOYSTICK_RIGHT , GPIO_FALLING_EDGE); gpio_enable_pin_interrupt(GPIO_JOYSTICK_PUSH , GPIO_FALLING_EDGE); gpio_enable_pin_interrupt(GPIO_JOYSTICK_LEFT , GPIO_FALLING_EDGE); /* Disable all interrupts */ Disable_global_interrupt(); /* register PB0 handler on level 1 */ INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_UP/8), AVR32_INTC_INT1); INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_DOWN/8), AVR32_INTC_INT1); INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_RIGHT/8), AVR32_INTC_INT1); INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_LEFT/8), AVR32_INTC_INT1); INTC_register_interrupt( &dip204_example_Joy_int_handler, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_PUSH/8), AVR32_INTC_INT1); /* Enable all interrupts */ Enable_global_interrupt(); }
//! //! @brief Suspend callback. //! //! This function enables the interrupts in order to send a remote wakeup to the host. //! void usb_suspend(void) { if(remote_wakeup_feature) { // Enable ISR on switches #if BOARD == EVK1105 gpio_clear_pin_interrupt_flag(QT1081_TOUCH_SENSOR_ENTER); gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_ENTER, GPIO_RISING_EDGE); #endif } }
/*! * \brief Init the joystick sensor. * * \return true upon success, false if error. */ bool b_joystick_init ( void ) { portCHAR token[6]; // Get the xCFGMutex. if( pdTRUE == x_supervisor_SemaphoreTake( xCFGMutex, 0 ) ) { // get the field if (config_file_get_value(SENSOR_JS_CONFIG_FILE, "alarm" , token) >= 0) { // update value if (!strcmp(token, "on")) { bAlarm = pdTRUE; } } // Release the xCFGMutex. x_supervisor_SemaphoreGive( xCFGMutex ); } /* configure joystick up to produce IT on all state change */ gpio_enable_pin_interrupt(GPIO_JOYSTICK_UP , GPIO_PIN_CHANGE); /* configure joystick down to produce IT on all state change */ gpio_enable_pin_interrupt(GPIO_JOYSTICK_DOWN , GPIO_PIN_CHANGE); /* configure joystick right to produce IT on all state change */ gpio_enable_pin_interrupt(GPIO_JOYSTICK_RIGHT , GPIO_PIN_CHANGE); /* configure joystick left to produce IT on all state change */ gpio_enable_pin_interrupt(GPIO_JOYSTICK_LEFT , GPIO_PIN_CHANGE); /* configure joystick press to produce IT on all state change */ gpio_enable_pin_interrupt(GPIO_JOYSTICK_PUSH , GPIO_PIN_CHANGE); /* Disable all interrupts */ Disable_global_interrupt(); /* register joystick handler on level 3 */ INTC_register_interrupt( (__int_handler)&vjoystick_ISR, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_UP/8), AVR32_INTC_INT3); INTC_register_interrupt( (__int_handler)&vjoystick_ISR, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_PUSH/8), AVR32_INTC_INT3); /* Enable all interrupts */ Enable_global_interrupt(); return (true); }
/** * \brief Main entry point for GPIO example. */ int main(void) { /* Initialize the SAM system */ sysclk_init(); board_init(); /* Initialize the console uart */ configure_console(); /* Output example information */ printf("\r\n\r\n-- GPIO interrupt and event example --\r\n"); printf("-- %s\r\n", BOARD_NAME); printf("-- Compiled: %s %s --\r\n", __DATE__, __TIME__); //! [config_button_0_trig_fall] /* Configure push button 0 to trigger an interrupt on falling edge */ //! [config_button_0_trig_fall_1] ioport_set_pin_dir(EXAMPLE_BUTTON_INT, IOPORT_DIR_INPUT); ioport_set_pin_mode(EXAMPLE_BUTTON_INT, IOPORT_MODE_PULLUP | IOPORT_MODE_GLITCH_FILTER); ioport_set_pin_sense_mode(EXAMPLE_BUTTON_INT, IOPORT_SENSE_FALLING); //! [config_button_0_trig_fall_1] //! [config_button_0_trig_fall_2] if (!gpio_set_pin_callback(EXAMPLE_BUTTON_INT, pb0_callback, 1)) { printf("Set pin callback failure!\r\n"); while (1) { } } //! [config_button_0_trig_fall_2] //! [enable_pin_interrupt] gpio_enable_pin_interrupt(EXAMPLE_BUTTON_INT); //! [enable_pin_interrupt] //! [config_button_0_trig_fall] printf("Press %s to trigger LED.\r\n", BUTTON_0_NAME); /* Configure pin to trigger an event on falling edge */ ioport_set_pin_mode(EXAMPLE_PIN_EVENT, IOPORT_MODE_PULLUP | IOPORT_MODE_MUX_C); ioport_disable_pin(EXAMPLE_PIN_EVENT); ioport_set_pin_sense_mode(EXAMPLE_PIN_EVENT, IOPORT_SENSE_FALLING); gpio_enable_pin_periph_event(EXAMPLE_PIN_EVENT); printf("Connect %s to %s to trigger an event.\r\n", EXAMPLE_PIN_NAME, EXAMPLE_GND_NAME); init_pevc(); init_pdca(); while (1) { } }
int main(){ init(); gpio_configure_pin(TEST_A, GPIO_DIR_INPUT); gpio_configure_pin(RESPONSE_A, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(TEST_B, GPIO_DIR_INPUT); gpio_configure_pin(RESPONSE_B, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(TEST_C, GPIO_DIR_INPUT); gpio_configure_pin(RESPONSE_C, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_enable_pin_interrupt(TEST_A, GPIO_FALLING_EDGE ); gpio_enable_pin_interrupt(TEST_B, GPIO_FALLING_EDGE ); gpio_enable_pin_interrupt(TEST_C, GPIO_FALLING_EDGE ); while(1){ if (A){ A = false; gpio_set_pin_low(RESPONSE_A); busy_delay_us(5); gpio_set_pin_high(RESPONSE_A); } if (B){ B = false; gpio_set_pin_low(RESPONSE_B); busy_delay_us(5); gpio_set_pin_high(RESPONSE_B); } if (C){ C = false; gpio_set_pin_low(RESPONSE_C); busy_delay_us(5); gpio_set_pin_high(RESPONSE_C); } } }
/** \brief Register a normal pin interrupt for the touch event. * */ void at42qt1060_register_int(void (*touch_detect_callback)(void)) { at42qt1060.touch_detect_callback = touch_detect_callback; Disable_global_interrupt(); INTC_register_interrupt(&at42qt1060_detect_int_handler, AVR32_GPIO_IRQ_0 + AT42QT1060_DETECT_PIN/8, 0 ); // For now we only react on falling edge // Actually this is a level interrupt (low active) gpio_enable_pin_interrupt(AT42QT1060_DETECT_PIN, GPIO_FALLING_EDGE); gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN); Enable_global_interrupt(); return; }
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 /* 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); /* 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 }
/** * \brief Test GPIO interrupt. * * \param test Current test case. */ static void run_gpio_int_test(const struct test_case *test) { /* Configure an input pin to trigger an interrupt on falling edge */ ioport_set_pin_dir(CONF_TEST_GPIO_IN, IOPORT_DIR_INPUT); ioport_set_pin_mode(CONF_TEST_GPIO_IN, IOPORT_MODE_PULLUP | IOPORT_MODE_GLITCH_FILTER); ioport_set_pin_sense_mode(CONF_TEST_GPIO_IN, IOPORT_SENSE_FALLING); gpio_set_pin_callback(CONF_TEST_GPIO_IN, gpio_pin_callback, 1); gpio_enable_pin_interrupt(CONF_TEST_GPIO_IN); /* Configure an output pin */ ioport_set_pin_dir(CONF_TEST_GPIO_OUT, IOPORT_DIR_OUTPUT); ioport_set_pin_level(CONF_TEST_GPIO_OUT, IOPORT_PIN_LEVEL_HIGH); /* Trigger an interrupt */ gpio_int_happened = false; ioport_set_pin_level(CONF_TEST_GPIO_OUT, IOPORT_PIN_LEVEL_LOW); delay_ms(5); test_assert_true(test, gpio_int_happened, "No interrupt has been triggered!"); }
/********************************************************************* Functions *********************************************************************/ int main (void) { int i; // initialize init(); gpio_configure_pin(TEST_A, GPIO_DIR_INPUT | GPIO_INIT_HIGH); gpio_configure_pin(TEST_B, GPIO_DIR_INPUT | GPIO_INIT_HIGH); gpio_configure_pin(TEST_C, GPIO_DIR_INPUT | GPIO_INIT_HIGH); gpio_configure_pin(RESPONSE_A, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(RESPONSE_B, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); gpio_configure_pin(RESPONSE_C, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH); // ASS C gpio_enable_pin_interrupt(TEST_A, GPIO_FALLING_EDGE ); gpio_enable_pin_interrupt(TEST_B, GPIO_FALLING_EDGE ); gpio_enable_pin_interrupt(TEST_C, GPIO_FALLING_EDGE ); // start code from here while(1) { //gpio_toggle_pin(LED0_GPIO); /* if(gpio_pin_is_low(TEST_A)){ gpio_set_pin_low(RESPONSE_A); busy_delay_us(5); gpio_set_pin_high(RESPONSE_A); } if(gpio_pin_is_low(TEST_B)){ gpio_set_pin_low(RESPONSE_B); busy_delay_us(5); gpio_set_pin_high(RESPONSE_B); } if (gpio_pin_is_low(TEST_C)){ gpio_set_pin_low(RESPONSE_C); busy_delay_us(5); gpio_set_pin_high(RESPONSE_C); } */ //gpio_set_pin_high(LED0_GPIO); //busy_delay_ms(500); //gpio_set_pin_low(LED0_GPIO); //busy_delay_ms(500); // INTERRUPTS // AssD if (A_FLAG){ gpio_set_pin_low(RESPONSE_A); busy_delay_us(5); gpio_set_pin_high(RESPONSE_A); gpio_clear_pin_interrupt_flag(TEST_A); A_FLAG = false; } else if(B_FLAG){ gpio_set_pin_low(RESPONSE_B); busy_delay_us(5); gpio_set_pin_high(RESPONSE_B); gpio_clear_pin_interrupt_flag(TEST_B); B_FLAG = false; } else if(C_FLAG){ gpio_set_pin_low(RESPONSE_C); busy_delay_us(5); gpio_set_pin_high(RESPONSE_C); gpio_clear_pin_interrupt_flag(TEST_C); C_FLAG = false; } } }
// 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; }
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 }
// register interrupts void register_interrupts(void) { #if 1 #else // enable interrupts on GPIO inputs // BFIN_HWAIT gpio_enable_pin_interrupt( BFIN_HWAIT_PIN, GPIO_RISING_EDGE); // encoders gpio_enable_pin_interrupt( ENC0_S0_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( ENC0_S1_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( ENC1_S0_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( ENC1_S1_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( ENC2_S0_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( ENC2_S1_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( ENC3_S0_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( ENC3_S1_PIN, GPIO_PIN_CHANGE); // switches gpio_enable_pin_interrupt( SW0_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( SW1_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( SW2_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( SW3_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( FS0_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( FS1_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( SW_MODE_PIN, GPIO_PIN_CHANGE); gpio_enable_pin_interrupt( SW_POWER_PIN, GPIO_PIN_CHANGE); // PA24 - PA31 INTC_register_interrupt( &irq_port0_line3, AVR32_GPIO_IRQ_0 + (AVR32_PIN_PA24 / 8), UI_IRQ_PRIORITY); // PB00 - PB07 INTC_register_interrupt( &irq_port1_line0, AVR32_GPIO_IRQ_0 + (AVR32_PIN_PB00 / 8), UI_IRQ_PRIORITY); // PB08 - PB15 INTC_register_interrupt( &irq_port1_line1, AVR32_GPIO_IRQ_0 + (AVR32_PIN_PB08 / 8), UI_IRQ_PRIORITY); // PB16 - PB23 INTC_register_interrupt( &irq_port1_line2, AVR32_GPIO_IRQ_0 + (AVR32_PIN_PB16 / 8), UI_IRQ_PRIORITY); // PB24 - PB31 INTC_register_interrupt( &irq_port1_line3, AVR32_GPIO_IRQ_0 + (AVR32_PIN_PB24 / 8), UI_IRQ_PRIORITY); // register IRQ for PDCA transfer INTC_register_interrupt(&irq_pdca, AVR32_PDCA_IRQ_0, SYS_IRQ_PRIORITY); // register TC interrupt INTC_register_interrupt(&irq_tc, APP_TC_IRQ, APP_TC_IRQ_PRIORITY); // register uart interrupt INTC_register_interrupt(&irq_usart, AVR32_USART0_IRQ, UI_IRQ_PRIORITY); #endif }
//! Basic SMTP client task definition portTASK_FUNCTION( vBasicSMTPClient, pvParameters ) { struct sockaddr_in stServeurSockAddr; portLONG lRetval; portLONG lSocket = -1; // configure push button 0 to produce IT on falling edge gpio_enable_pin_interrupt(GPIO_PUSH_BUTTON_0 , GPIO_FALLING_EDGE); // Disable all interrupts vPortEnterCritical(); // register push button 0 handler on level 3 INTC_register_interrupt( (__int_handler)&vpushb_ISR, AVR32_GPIO_IRQ_0 + (GPIO_PUSH_BUTTON_0/8), AVR32_INTC_INT3); // Enable all interrupts vPortExitCritical(); for (;;) { // wait for a signal to send a mail while (bSendMail != pdTRUE) vTaskDelay(200); // Disable all interrupts vPortEnterCritical(); // clear the flag bSendMail = pdFALSE; // Enable all interrupts vPortExitCritical(); // clear the LED vParTestSetLED( 3 , pdFALSE ); // Set up port memset(&stServeurSockAddr, 0, sizeof(stServeurSockAddr)); stServeurSockAddr.sin_len = sizeof(stServeurSockAddr); stServeurSockAddr.sin_addr.s_addr = inet_addr(cServer); stServeurSockAddr.sin_port = htons(SMTP_PORT); stServeurSockAddr.sin_family = AF_INET; // socket as a stream if ( (lSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { // socket failed, blink a LED and stay here for (;;) { vParTestToggleLED( 4 ); vTaskDelay( 200 ); } } // connect to the server if(connect(lSocket,(struct sockaddr *)&stServeurSockAddr, sizeof(stServeurSockAddr)) < 0) { // connect failed, blink a LED and stay here for (;;) { vParTestToggleLED( 6 ); vTaskDelay( 200 ); } } else { //Server: 220 SMTP Ready // wait for SMTP Server answer do { lRetval = recv(lSocket, cTempBuffer, sizeof(cTempBuffer), 0); }while (lRetval <= 0); if (strncmp(cTempBuffer, SMTP_EHLO_STRING, sizeof(cTempBuffer)) >= 0) { //Client: EHLO smtp.domain.com // send ehlo send(lSocket, "HELO ", 5, 0); send(lSocket, cServer, strlen(cServer), 0); send(lSocket, "\r\n", 2, 0); //Server: 250 // wait for SMTP Server answer do { lRetval = recv(lSocket, cTempBuffer, sizeof(cTempBuffer), 0); }while (lRetval <= 0); if (strncmp(cTempBuffer, SMTP_OK_STRING, sizeof(cTempBuffer)) >= 0) { //Client: MAIL FROM:<*****@*****.**> // send MAIL FROM send(lSocket, cMailfrom, strlen(cMailfrom), 0); //Server: 250 OK // wait for SMTP Server answer do { lRetval = recv(lSocket, cTempBuffer, sizeof(cTempBuffer), 0); }while (lRetval <= 0); if (strncmp(cTempBuffer, SMTP_OK_STRING, sizeof(cTempBuffer)) >= 0) { //Client: RCPT TO:<*****@*****.**> // send RCPT TO send(lSocket, cMailto, strlen(cMailto), 0); //Server: 250 OK // wait for SMTP Server answer do { lRetval = recv(lSocket, cTempBuffer, sizeof(cTempBuffer), 0); }while (lRetval <= 0); if (strncmp(cTempBuffer, SMTP_OK_STRING, sizeof(cTempBuffer)) >= 0) { //Client: DATA<CRLF> // send DATA send(lSocket, SMTP_DATA_STRING, 6, 0); //Server: 354 Start mail input; end with <CRLF>.<CRLF> // wait for SMTP Server answer do { lRetval = recv(lSocket, cTempBuffer, sizeof(cTempBuffer), 0); }while (lRetval <= 0); if (strncmp(cTempBuffer, SMTP_START_OF_TRANSMISSION_STRING, sizeof(cTempBuffer)) >= 0) { // send content send(lSocket, cMailcontent, strlen(cMailcontent), 0); //Client: <CRLF>.<CRLF> // send "<CRLF>.<CRLF>" send(lSocket, SMTP_MAIL_END_STRING, 5, 0); //Server: 250 OK // wait for SMTP Server answer do { lRetval = recv(lSocket, cTempBuffer, sizeof(cTempBuffer), 0); }while (lRetval <= 0); if (strncmp(cTempBuffer, SMTP_OK_STRING, sizeof(cTempBuffer)) >= 0) { //Client: QUIT<CRLFCRLF> // send QUIT send(lSocket, SMTP_QUIT_STRING, 8, 0); //Server: 221 smtp.domain.com closing transmission do { lRetval = recv(lSocket, cTempBuffer, sizeof(cTempBuffer), 0); }while (lRetval <= 0); if (strncmp(cTempBuffer, SMTP_END_OF_TRANSMISSION_STRING, sizeof(cTempBuffer)) >= 0) { vParTestSetLED( 3 , pdTRUE ); } } } } } } // close socket close(lSocket); } } } }
static void twi_init(U32 fpba_hz) { const gpio_map_t AT42QT1060_TWI_GPIO_MAP = { {AT42QT1060_TWI_SCL_PIN, AT42QT1060_TWI_SCL_FUNCTION}, {AT42QT1060_TWI_SDA_PIN, AT42QT1060_TWI_SDA_FUNCTION} }; const twi_options_t AT42QT1060_TWI_OPTIONS = { .pba_hz = 24000000, .speed = AT42QT1060_TWI_MASTER_SPEED, .chip = AT42QT1060_TWI_ADDRESS }; // Assign I/Os to SPI. gpio_enable_module(AT42QT1060_TWI_GPIO_MAP, sizeof(AT42QT1060_TWI_GPIO_MAP) / sizeof(AT42QT1060_TWI_GPIO_MAP[0])); // Initialize as master. twi_master_init(AT42QT1060_TWI, &AT42QT1060_TWI_OPTIONS); } /*! \brief Callback function for a detect event of the touch sensor device. */ void touch_detect_callback(void) { touch_detect = true; } struct at42qt1060_data touch_data; void controller_task(void) { // if a touch is detected we read the status if(touch_detect) { touch_data.detect_status = at42qt1060_read_reg(AT42QT1060_DETECTION_STATUS); // need to read input port status too to reset CHG line at42qt1060_read_reg(AT42QT1060_INPUT_PORT_STATUS); touch_detect = false; } } static void controller_detect_int_handler(void) { if(gpio_get_pin_interrupt_flag(AT42QT1060_DETECT_PIN)) { gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN); touch_detect_callback(); } } void controller_init(U32 fcpu_hz, U32 fhsb_hz, U32 fpbb_hz, U32 fpba_hz) { // Disable all interrupts Disable_global_interrupt(); twi_init(fpba_hz); // wait until the device settles its CHG line cpu_delay_ms(230, fcpu_hz); at42qt1060_init(fcpu_hz); BSP_INTC_IntReg(&controller_detect_int_handler, AVR32_GPIO_IRQ_0 + AT42QT1060_DETECT_PIN/8, AVR32_INTC_INT1); // For now we only react on falling edge // Actually this is a level interrupt (low active) gpio_enable_pin_interrupt(AT42QT1060_DETECT_PIN, GPIO_FALLING_EDGE); gpio_clear_pin_interrupt_flag(AT42QT1060_DETECT_PIN); //static_fcpu_hz = fcpu_hz; cpu_set_timeout(cpu_ms_2_cy(JOYSTICK_KEY_DEBOUNCE_MS, static_fcpu_hz), &joystick_key_sensibility_timer); // Enable global interrupts Enable_global_interrupt(); }
/*! \internal Enable a general purpose I/O pin interrupt. * * This routine enables interrupts on a specified general purpose I/O pin. * * \param gpio_pin GPIO pin interface to the MCU * \param gpio_irq IRQ of the interrupt handler */ static void gpio_irq_connect(uint32_t gpio_pin, uint32_t gpio_irq) { irq_register_handler(gpio_irq_handler, gpio_irq, GPIO_INT_LVL); gpio_enable_pin_interrupt(gpio_pin, GPIO_RISING_EDGE); }
int main (void) { // Initialize CPU clock to 48 MHz (configured in conf_clock.h) sysclk_init(); // Initialize the EVK1100 and its pin configuration board_init(); // Enable LED1 and LED2 as GPIO output gpio_enable_gpio_pin(LED0_GPIO); gpio_enable_gpio_pin(LED1_GPIO); gpio_configure_pin(LED0_GPIO, GPIO_DIR_OUTPUT); gpio_configure_pin(LED1_GPIO, GPIO_DIR_OUTPUT); // Define USART GPIO pin map static const gpio_map_t USART_GPIO_MAP = { {USART_RXD_PIN, USART_RXD_FUNCTION}, {USART_TXD_PIN, USART_TXD_FUNCTION} }; // Define USART options static usart_options_t usart_options = { .baudrate = 9600, .charlength = 8, .paritytype = USART_NO_PARITY, .stopbits = USART_1_STOPBIT, .channelmode = USART_NORMAL_CHMODE }; // Assign GPIO gpio_enable_module( USART_GPIO_MAP, sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]) ); // Initialize USART usart_init_rs232(USART, &usart_options, sysclk_get_pba_hz()); // Disable all interrupts Disable_global_interrupt(); // Initialize interrupt module INTC_init_interrupts(); // Define handler and configure interrupt with INT1 priority INTC_register_interrupt(&push_button_interrupt_handler, AVR32_GPIO_IRQ_0 + (GPIO_PUSH_BUTTON_1/8), AVR32_INTC_INT1); // Enable falling edge interrupt on Push Button 1 gpio_enable_pin_interrupt(GPIO_PUSH_BUTTON_1, GPIO_FALLING_EDGE); // Enable global interrupts Enable_global_interrupt(); // Set initial state // STATE_1 = LED0 On, LED1 Off // STATE_2 = LED0 Off, LED1 On gpio_set_pin_low(LED0_GPIO); gpio_set_pin_high(LED1_GPIO); while (1) { // If an interrupt has happened and run_once is true... if (run_once) { switch (state_indicator) { // ... and if current state is STATE_1... case STATE_1: // Activate LED0 and deactivate LED1 gpio_set_pin_low(LED0_GPIO); gpio_set_pin_high(LED1_GPIO); // Send debug message over USART usart_write_line(USART,"--------------\r\n"); usart_write_line(USART,"Interrupt detected on PB1\r\n"); usart_write_line(USART,"STATE_1 engaged!\r\n"); usart_write_line(USART,"LED1 = ON\r\n"); usart_write_line(USART,"LED2 = OFF\r\n"); usart_write_line(USART,"--------------\r\n"); break; // ... and if current state is STATE_2... case STATE_2: // Activate LED1 and deactivate LED0 gpio_set_pin_low(LED1_GPIO); gpio_set_pin_high(LED0_GPIO); // Send debug message over USART usart_write_line(USART,"--------------\r\n"); usart_write_line(USART,"Interrupt detected on PB1\r\n"); usart_write_line(USART,"STATE_2 engaged!\r\n"); usart_write_line(USART,"LED1 = OFF\r\n"); usart_write_line(USART,"LED2 = ON\r\n"); usart_write_line(USART,"--------------\r\n"); break; } // Reset run_once to false run_once = FALSE; } // Otherwise, do nothing! } }
static void inline rtouch_enable_detect_int(void) { /* Enable interrupt for Y lines */ gpio_enable_pin_interrupt(rtouch_gpio_ymap[0].pin, GPIO_FALLING_EDGE); }
void init_PWM(int velocidad, int direccion){ int auxiliar; switch(velocidad){ case 9: auxiliar = 2; break; case 8: auxiliar = 4; break; case 7: auxiliar = 6; break; case 6: auxiliar = 8; break; case 5: auxiliar = 10; break; case 4: auxiliar = 12; break; case 3: auxiliar = 14; break; case 2: auxiliar = 16; break; case 1: auxiliar = 18; break; }//SWITCH pwm_opt_t pwm_opt = { .diva = AVR32_PWM_DIVA_CLK_OFF, .divb = AVR32_PWM_DIVB_CLK_OFF, .prea = AVR32_PWM_PREA_MCK, .preb = AVR32_PWM_PREB_MCK }; avr32_pwm_channel_t pwm_channel = { .ccnt = 0 }; pwm_channel.cdty = auxiliar; /* Channel duty cycle, should be < CPRD. */ pwm_channel.cprd = 20; /* Channel period. */ pwm_channel.cupd = 0; /* Channel update is not used here. */ pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED; /* Channel mode. */ pwm_channel.CMR.cpol = PWM_POLARITY_LOW; /* Channel polarity. */ pwm_channel.CMR.cpd = PWM_UPDATE_DUTY; /* Not used the first time. */ pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_256; /* Channel prescaler. */ gpio_enable_module_pin(PWM_PIN_3, PWM_PIN_Function); gpio_enable_module_pin(PWM_PIN_1, PWM_PIN_Function); pwm_init(&pwm_opt); if(direccion == 1){//FORWARD pwm_channel_init(PWM_ID_3, &pwm_channel); pwm_start_channels(1 << PWM_ID_3); } if(direccion == 0){//REVERSE pwm_channel_init(PWM_ID_1, &pwm_channel); pwm_start_channels(1 << PWM_ID_1); } } void update_PWM(int velocidad, int direccion){ int auxiliar; switch(velocidad){ case 9: auxiliar = 2; break; case 8: auxiliar = 4; break; case 7: auxiliar = 6; break; case 6: auxiliar = 8; break; case 5: auxiliar = 10; break; case 4: auxiliar = 12; break; case 3: auxiliar = 14; break; case 2: auxiliar = 16; break; case 1: auxiliar = 18; break; }//SWITCH avr32_pwm_channel_t pwm_channel = { .ccnt = 0 }; pwm_channel.cdty = auxiliar; /* Channel duty cycle, should be < CPRD. */ pwm_channel.cprd = 20; /* Channel period. */ pwm_channel.cupd = 0; /* Channel update is not used here. */ pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED; /* Channel mode. */ pwm_channel.CMR.cpol = PWM_POLARITY_LOW; /* Channel polarity. */ pwm_channel.CMR.cpd = PWM_UPDATE_DUTY; /* Not used the first time. */ pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_256; /* Channel prescaler. */ if(direccion == 1){//FORWARD pwm_stop_channels(1<<PWM_ID_1); pwm_stop_channels(1<<PWM_ID_3); pwm_channel_init(PWM_ID_3, &pwm_channel); pwm_start_channels(1 << PWM_ID_3); } if(direccion == 0){//REVERSE pwm_stop_channels(1<<PWM_ID_1); pwm_stop_channels(1<<PWM_ID_3); pwm_channel_init(PWM_ID_1, &pwm_channel); pwm_start_channels(1 << PWM_ID_1); } bandera = 0; } static void handler_interrupt(void){ if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_UP)){ direccion = 1; gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP); } if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_DOWN)){ direccion = 0; gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN); } bandera = 1; } void init_INTC(void){ gpio_enable_pin_interrupt(GPIO_JOYSTICK_UP , GPIO_FALLING_EDGE); gpio_enable_pin_interrupt(GPIO_JOYSTICK_DOWN , GPIO_FALLING_EDGE); Disable_global_interrupt(); INTC_init_interrupts(); INTC_register_interrupt( &handler_interrupt, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_UP/8), AVR32_INTC_INT1); INTC_register_interrupt( &handler_interrupt, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_DOWN/8), AVR32_INTC_INT1); Enable_global_interrupt(); }
/** * \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(); } }