/** * \brief Configure the Pushbuttons * * Configure the PIO as inputs and generate corresponding interrupt when * pressed or released. */ static void configure_buttons(void) { // [main_button1_configure] /* Configure Pushbutton 1 */ pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID); pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10); /* Interrupt on rising edge */ pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR, Button1_Handler); NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID); pio_handler_set_priority(PIN_PUSHBUTTON_1_PIO, (IRQn_Type) PIN_PUSHBUTTON_1_ID, IRQ_PRIOR_PIO); pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK); // [main_button1_configure] #ifndef BOARD_NO_PUSHBUTTON_2 // [main_button2_configure] /* Configure Pushbutton 2 */ pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID); pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 10); /* Interrupt on falling edge */ pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR, Button2_Handler); NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_2_ID); pio_handler_set_priority(PIN_PUSHBUTTON_2_PIO, (IRQn_Type) PIN_PUSHBUTTON_2_ID, IRQ_PRIOR_PIO); pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK); // [main_button2_configure] #endif }
/** * \brief Configure the push buttons. * * Configure the PIOs as inputs and generate corresponding interrupt when * the push buttons are pressed or released. */ static void configure_buttons(void) { /* Enable the pmc clocks of the push buttons for all SAM3. */ pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID); pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID); /* Adjust PIO debouncing filter patameters, using 10 Hz filter. */ pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10); pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 10); /* Initialize PIOs interrupt handlers (see PIO definition in board.h). */ pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR, Int1Handler); /* Interrupt on rising edge. */ pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR, Int2Handler); /* Interrupt on falling edge. */ /* Enable PIO controller IRQs. */ NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID); NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_2_ID); /* PIO configuration for Buttons. */ pio_handler_set_priority(PIN_PUSHBUTTON_1_PIO, (IRQn_Type) PIN_PUSHBUTTON_1_ID, 0); pio_handler_set_priority(PIN_PUSHBUTTON_2_PIO, (IRQn_Type) PIN_PUSHBUTTON_2_ID, 0); /* Enable PIO line interrupts. */ pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK); pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK); }
int main (void) { // Insert system clock initialization code here (sysclk_init()). sysclk_init(); board_init(); // Insert application code here, after the board has been initialized. pmc_enable_periph_clk(ID_PIOA); pio_set_input(PIOA, PIO_PA16, PIO_DEFAULT); pio_pull_down(PIOA, (PIO_PA16), ENABLE); pio_handler_set(PIOA, ID_PIOA, PIO_PA16, PIO_IT_RISE_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA,PIO_PA16); pio_set_input(PIOA, PIO_PA17, PIO_DEFAULT); pio_pull_down(PIOA, (PIO_PA17), ENABLE); pio_handler_set(PIOA, ID_PIOA, PIO_PA17, PIO_IT_RISE_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA,PIO_PA17); NVIC_EnableIRQ(PIOA_IRQn); gpio_set_pin_low(LED0_GPIO); gpio_set_pin_high(LED1_GPIO); while(1){ } }
/** * \brief Start capture process. * */ static void ov7740_test_capture_process_run(const struct test_case* const test) { if (g_ul_init_error_flag == true) { /* Return error if previous test about initialization failed */ test_assert_true(test, 0, "OV7740 capture test failed!"); } else { /* Enable vsync interrupt */ pio_enable_interrupt(OV7740_VSYNC_PIO, OV7740_VSYNC_MASK); /* Capture acquisition will start on rising edge of Vsync * signal. * So wait vsync_flag = 1 before starting the process */ while (!g_ul_vsync_flag) { } /* Enable vsync interrupt */ pio_disable_interrupt(OV7740_VSYNC_PIO, OV7740_VSYNC_MASK); /* Reset vsync flag */ g_ul_vsync_flag = false; /* Configure the PDC Buffer and next Buffer for image capture */ pio_capture_to_buffer(OV7740_VSYNC_PIO, g_auc_capture_buffer, sizeof(g_auc_capture_buffer)); /* Enable PIO capture */ pio_capture_enable(OV7740_DATA_BUS_PIO); /* Wait for the end of capture of the g_auc_capture_buffer */ while (!((OV7740_DATA_BUS_PIO->PIO_PCISR & PIO_PCIMR_ENDRX) == PIO_PCIMR_ENDRX)) { } } }
/** * \brief Configure the Pushbuttons * * Configure the PIO as inputs and generate corresponding interrupt when * pressed or released. */ static void configure_buttons(void) { pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID); pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID); pio_set_input(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, PIO_PULLUP | PIO_DEBOUNCE); pio_set_input(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, PIO_PULLUP | PIO_DEBOUNCE); pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10); pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 10); pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK, PIO_IT_FALL_EDGE | PIO_PULLUP, Button1_Handler); pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK, PIO_IT_FALL_EDGE | PIO_PULLUP, Button2_Handler); pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO , PIN_PUSHBUTTON_1_MASK); pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO , PIN_PUSHBUTTON_2_MASK); NVIC_SetPriority((IRQn_Type) PIN_PUSHBUTTON_1_ID, 0); NVIC_SetPriority((IRQn_Type) PIN_PUSHBUTTON_2_ID, 0); NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID); NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_2_ID); }
/* * @fn nm_bsp_interrupt_ctrl * @brief Enable/Disable interrupts * @param[IN] u8Enable * '0' disable interrupts. '1' enable interrupts */ void nm_bsp_interrupt_ctrl(uint8 u8Enable) { if (u8Enable) { pio_enable_interrupt(CONF_WINC_SPI_INT_PIO, CONF_WINC_SPI_INT_MASK); } else { pio_disable_interrupt(CONF_WINC_SPI_INT_PIO, CONF_WINC_SPI_INT_MASK); } }
/** * \brief Configure the Pushbuttons * * Configure the PIO as inputs and generate corresponding interrupt when * pressed or released. */ static void configure_buttons(void) { pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID); pio_set_input(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR); pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 100); pio_handler_set(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK,PIO_IT_FALL_EDGE, Button1_Handler); pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK); NVIC_SetPriority(PIN_PUSHBUTTON_1_ID,0); NVIC_EnableIRQ(PIN_PUSHBUTTON_1_ID); pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID); pio_set_input(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR); pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 100); pio_handler_set(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK,PIO_IT_FALL_EDGE, Button2_Handler); pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK); NVIC_SetPriority(PIN_PUSHBUTTON_2_ID,1); NVIC_EnableIRQ(PIN_PUSHBUTTON_2_ID); }
/** * \brief Configure the Pushbuttons * * Configure the PIO as inputs and generate corresponding interrupt when * pressed or released. */ static void configure_buttons(void) { pmc_enable_periph_clk(ID_BUT_2); pmc_enable_periph_clk(ID_BUT_1); pio_set_input(PORT_BUT_2, MASK_BUT_2, PIO_PULLUP | PIO_DEBOUNCE); pio_set_input(PORT_BUT_1, MASK_BUT_1, PIO_PULLUP | PIO_DEBOUNCE); pio_set_debounce_filter(PORT_BUT_2, MASK_BUT_2, 20); pio_set_debounce_filter(PORT_BUT_1, MASK_BUT_1, 20); pio_handler_set(PORT_BUT_2, ID_BUT_2, MASK_BUT_2, PIO_IT_FALL_EDGE , Button1_Handler ); pio_handler_set(PORT_BUT_1, ID_BUT_1, MASK_BUT_1, PIO_IT_FALL_EDGE , Button2_Handler ); pio_enable_interrupt(PORT_BUT_2, MASK_BUT_2); pio_enable_interrupt(PORT_BUT_1, MASK_BUT_1); NVIC_SetPriority((IRQn_Type) ID_PIOB, 2); NVIC_SetPriority((IRQn_Type) ID_PIOC, 2); NVIC_EnableIRQ(ID_BUT_2); NVIC_EnableIRQ(ID_BUT_1); }
/************************************************************************** Configure the interrupt. Digital Pin 12 **************************************************************************/ void configure_interrupt_pio_RightWheel(void) { pmc_enable_periph_clk(ID_PIOD); //Enable the module clock pio_set_input(PIOD, PIO_PD8,PIO_PULLUP); pio_handler_set(PIOD,ID_PIOD,PIO_PD8,PIO_IT_EDGE,pin_edge_handler); pio_enable_interrupt(PIOD,PIO_PD8); NVIC_EnableIRQ(PIOD_IRQn); }
void button_init(uint32_t ul_id, Pio *p_pio, const uint32_t ul_mask, IRQn_Type IRQn, void (*p_handler) (uint32_t, uint32_t)) { pmc_enable_periph_clk(ul_id); pio_set_input(p_pio, ul_mask, PIO_PULLUP | PIO_DEBOUNCE); pio_set_debounce_filter(p_pio, ul_mask, DEBOUNCE_FREQ); pio_handler_set(p_pio, ul_id, ul_mask, PIO_IT_FALL_EDGE, p_handler); pio_enable_interrupt(p_pio, ul_mask); NVIC_EnableIRQ(IRQn); }
void config_hall_interrupt (void){ pmc_enable_periph_clk(ID_HALL); pio_set_input(PIOA, GPIO_HALLB, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_HALLB, ENABLE); pio_handler_set(PIOA, ID_HALL, GPIO_HALLB, PIO_IT_RISE_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA, GPIO_HALLB); pio_set_input(PIOA, GPIO_HALLC, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_HALLC, ENABLE); pio_handler_set(PIOA, ID_HALL, GPIO_HALLC, PIO_IT_FALL_EDGE, pin_riseedge_handler); pio_enable_interrupt(PIOA, GPIO_HALLC); NVIC_DisableIRQ(PIOA_IRQn); NVIC_ClearPendingIRQ(PIOA_IRQn); NVIC_SetPriority(PIOA_IRQn, PRIORITY_MEASURE); NVIC_EnableIRQ(PIOA_IRQn); }
void configure_botao(void) { pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID); pio_set_input(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR); pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10); pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID,PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR ,push_button_handle); pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK); NVIC_SetPriority((IRQn_Type) PIN_PUSHBUTTON_1_ID, 0); NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID); }
static void irq_init(void) { pio_configure_pin(DW_IRQ_IDX, DW_IRQ_FLAGS); pio_pull_down(DW_IRQ_PIO, DW_IRQ_MASK, true); pio_handler_set(DW_IRQ_PIO, DW_IRQ_PIO_ID, DW_IRQ_MASK, DW_IRQ_ATTR, irq_handler); pio_enable_interrupt(DW_IRQ_PIO, DW_IRQ_MASK); pio_handler_set_priority(DW_IRQ_PIO, DW_IRQ_IRQ, 0); pmc_enable_periph_clk(DW_IRQ_PIO_ID); }
/** * \brief Configure the Pushbuttons * * Configure the PIO as inputs and generate corresponding interrupt when * pressed or released. */ static void configure_buttons(void) { pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID); pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID); /** * Configura entrada */ pio_set_input(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_MASK , PIO_PULLUP | PIO_DEBOUNCE); pio_set_input(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_MASK , PIO_PULLUP | PIO_DEBOUNCE); /* * Configura divisor do clock para debounce */ pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_MASK ,20); pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_MASK ,20); /* * Configura interrupção para acontecer em borda de descida. */ pio_handler_set(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_ID,PIN_PUSHBUTTON_1_MASK ,PIN_PUSHBUTTON_1_ATTR ,Button1_Handler); pio_handler_set(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_ID,PIN_PUSHBUTTON_2_MASK ,PIN_PUSHBUTTON_2_ATTR ,Button2_Handler); /* * Ativa interrupção no periférico B porta do botão */ pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_MASK); pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_MASK); /* * Configura a prioridade da interrupção no pORTB */ NVIC_SetPriority(ID_PIOB,2); NVIC_SetPriority(ID_PIOC,2); /* * Ativa interrupção no port B */ NVIC_EnableIRQ(ID_PIOB); NVIC_EnableIRQ(ID_PIOC); }
static void configure_buttons(void) { pmc_enable_periph_clk(ID_BUT_2); pmc_enable_periph_clk(ID_BUT_3); /** * Configura entrada */ pio_set_input(PORT_BUT_2, MASK_BUT_2, PIO_PULLUP | PIO_DEBOUNCE); pio_set_input(PORT_BUT_3, MASK_BUT_3, PIO_PULLUP | PIO_DEBOUNCE); /* * Configura divisor do clock para debounce */ pio_set_debounce_filter(PORT_BUT_2,MASK_BUT_2, 100); pio_set_debounce_filter(PORT_BUT_3,MASK_BUT_3, 100); /* * Configura interrupção para acontecer em borda de descida. */ pio_handler_set(PORT_BUT_2,ID_BUT_2,MASK_BUT_2,PIO_IT_FALL_EDGE,Button2_Handler); pio_handler_set(PORT_BUT_3,ID_BUT_3,MASK_BUT_3,PIO_IT_FALL_EDGE,Button3_Handler); /* * Ativa interrupção no periférico B porta do botão */ pio_enable_interrupt(PORT_BUT_2,MASK_BUT_2); pio_enable_interrupt(PORT_BUT_3,MASK_BUT_3); /* * Configura a prioridade da interrupção no PORTB E PORTC */ NVIC_SetPriority(PIOB_IRQn, 10); NVIC_SetPriority(PIOC_IRQn, 10); /* * Ativa interrupção no port B e C */ NVIC_EnableIRQ(PIOB_IRQn); NVIC_EnableIRQ(PIOC_IRQn); }
/** * ISR that handles the target chip asserting a data ready signal. */ void AJ_WSL_SPI_CHIP_SPI_ISR(uint32_t id, uint32_t mask) { if (ID_PIOC != id || AJ_WSL_SPI_CHIP_SPI_INT_BIT != mask) { return; } pio_disable_interrupt(PIOC, AJ_WSL_SPI_CHIP_SPI_INT_BIT); if (mask & AJ_WSL_SPI_CHIP_SPI_INT_BIT) { g_b_spi_interrupt_data_ready = TRUE; AJ_ResumeTask(AJ_WSL_MBoxListenHandle, TRUE); } pio_enable_interrupt(PIOC, AJ_WSL_SPI_CHIP_SPI_INT_BIT); }
OSStatus gpio_irq_enable( gpio_port_t gpio_port, gpio_pin_number_t gpio_pin_number, gpio_irq_trigger_t trigger, gpio_irq_handler_t handler, void* arg ) { //gpio_irq_data_t *pSource; uint32_t ul_attr; if (gs_ul_nb_sources >= MAX_INTERRUPT_SOURCES) return 1; //Pio *p_pio = (Pio *)ioport_port_to_base(gpio_port); Pio *p_pio = arch_ioport_port_to_base(gpio_port); //ioport_pin_t pin = CREATE_IOPORT_PIN(gpio_port, gpio_pin_number); ioport_port_mask_t ul_mask = ioport_pin_to_mask(CREATE_IOPORT_PIN(gpio_port, gpio_pin_number)); if ( gpio_irq_management_initted == 0 ) { memset( (void*)gpio_irq_data, 0, sizeof( gpio_irq_data ) ); gpio_irq_management_initted = 1; } if (trigger == IRQ_TRIGGER_RISING_EDGE ) { ul_attr = PIO_IT_RISE_EDGE; } else if (trigger == IRQ_TRIGGER_FALLING_EDGE ) { ul_attr = PIO_IT_FALL_EDGE; } else if (trigger == IRQ_TRIGGER_BOTH_EDGES ) { ul_attr = PIO_IT_EDGE; } //pSource = &(gpio_irq_data[gs_ul_nb_sources]); gpio_irq_data[gs_ul_nb_sources].owner_port = gpio_port; if ( gpio_port == PORTA) { gpio_irq_data[gs_ul_nb_sources].id = ID_PIOA; // pmc_enable_periph_clk(ID_PIOA); } else if (gpio_port == PORTB) { gpio_irq_data[gs_ul_nb_sources].id = ID_PIOB; // pmc_enable_periph_clk(ID_PIOB); } gpio_irq_data[gs_ul_nb_sources].mask = ul_mask; gpio_irq_data[gs_ul_nb_sources].handler = handler; gpio_irq_data[gs_ul_nb_sources].arg = arg; gs_ul_nb_sources++; /* Configure interrupt mode */ pio_configure_interrupt(p_pio, ul_mask, ul_attr); if ( gpio_port == PORTA){ NVIC_EnableIRQ( PIOA_IRQn ); pio_handler_set_priority(PIOA, PIOA_IRQn, IRQ_PRIORITY_PIO); } else if (gpio_port == PORTB) { NVIC_EnableIRQ( PIOB_IRQn); pio_handler_set_priority(PIOB, PIOB_IRQn, IRQ_PRIORITY_PIO); } pio_enable_interrupt(p_pio, ul_mask); return kGeneralErr; }
/** * \brief Initialize PIO interrupt management logic. * * \param p_pio PIO controller base address. * \param ul_irqn NVIC line number. * \param ul_priority PIO controller interrupts priority. */ void pio_handler_set_priority(Pio *p_pio, IRQn_Type ul_irqn, uint32_t ul_priority) { uint32_t bitmask = 0; bitmask = pio_get_interrupt_mask(p_pio); pio_disable_interrupt(p_pio, 0xFFFFFFFF); pio_get_interrupt_status(p_pio); NVIC_DisableIRQ(ul_irqn); NVIC_ClearPendingIRQ(ul_irqn); NVIC_SetPriority(ul_irqn, ul_priority); NVIC_EnableIRQ(ul_irqn); pio_enable_interrupt(p_pio, bitmask); }
/** * \brief Configure the Pushbuttons. * * Configure the PIO as inputs and generate corresponding interrupt when * pressed or released. */ static void configure_buttons(void) { /* Configure Pushbutton 1. */ pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID); pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10); pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR, Button1_Handler); NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID); pio_handler_set_priority(PIN_PUSHBUTTON_1_PIO, (IRQn_Type) PIN_PUSHBUTTON_1_ID, IRQ_PRIOR_PIO); pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK); /* Configure Pushbutton 2. */ pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID); pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 10); pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR, Button2_Handler); NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_2_ID); pio_handler_set_priority(PIN_PUSHBUTTON_2_PIO, (IRQn_Type) PIN_PUSHBUTTON_2_ID, IRQ_PRIOR_PIO); pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK); /* Configure Pushbutton 3. */ pmc_enable_periph_clk(PIN_PUSHBUTTON_3_ID); pio_set_debounce_filter(PIN_PUSHBUTTON_3_PIO, PIN_PUSHBUTTON_3_MASK, 10); pio_handler_set(PIN_PUSHBUTTON_3_PIO, PIN_PUSHBUTTON_3_ID, PIN_PUSHBUTTON_3_MASK, PIN_PUSHBUTTON_3_ATTR, Button3_Handler); NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_3_ID); pio_handler_set_priority(PIN_PUSHBUTTON_3_PIO, (IRQn_Type) PIN_PUSHBUTTON_3_ID, IRQ_PRIOR_PIO); pio_enable_interrupt(PIN_PUSHBUTTON_3_PIO, PIN_PUSHBUTTON_3_MASK); /* Configure SD card detection. */ pmc_enable_periph_clk(SD_MMC_0_CD_ID); pio_set_debounce_filter(SD_MMC_0_CD_PIO, SD_MMC_0_CD_MASK, 10); pio_handler_set(SD_MMC_0_CD_PIO, SD_MMC_0_CD_ID, SD_MMC_0_CD_MASK, SD_MMC_0_CD_ATTR, SD_Detect_Handler); NVIC_EnableIRQ((IRQn_Type) SD_MMC_0_CD_ID); pio_handler_set_priority(SD_MMC_0_CD_PIO, (IRQn_Type) SD_MMC_0_CD_ID, IRQ_PRIOR_PIO); pio_enable_interrupt(SD_MMC_0_CD_PIO, SD_MMC_0_CD_MASK); }
/* * @fn nm_bsp_register_isr * @brief Register interrupt service routine * @param[IN] pfIsr * Pointer to ISR handler */ void nm_bsp_register_isr(tpfNmBspIsr pfIsr) { gpfIsr = pfIsr; /* Configure PGIO pin for interrupt from SPI slave, used when slave has data to send. */ sysclk_enable_peripheral_clock(CONF_WINC_SPI_INT_PIO_ID); pio_configure_pin(CONF_WINC_SPI_INT_PIN, PIO_TYPE_PIO_INPUT); pio_pull_up(CONF_WINC_SPI_INT_PIO, CONF_WINC_SPI_INT_MASK, PIO_PULLUP); // pio_set_debounce_filter(CONF_WINC_SPI_INT_PIO, CONF_WINC_SPI_INT_MASK, 10); pio_handler_set_pin(CONF_WINC_SPI_INT_PIN, PIO_IT_LOW_LEVEL, chip_isr); pio_enable_interrupt(CONF_WINC_SPI_INT_PIO, CONF_WINC_SPI_INT_MASK); pio_handler_set_priority(CONF_WINC_SPI_INT_PIO, (IRQn_Type)CONF_WINC_SPI_INT_PIO_ID, CONF_WINC_SPI_INT_PRIORITY); }
int initMPU60X0(void) { twi_options_t twi_options; twi_options.master_clk = BOARD_MCK; twi_options.speed = MPU60X0_SPEED; twi_options.chip = MPU60X0_BASE_ADDRESS; // Enable External Interrupt Controller Line. // Enable interrupts with priority higher than USB. pio_set_input(PIOA, MPU60X0_BODY_INT_PIN, MPU60X0_BODY_INT_FUNCTION); pio_configure_interrupt(PIOA, MPU60X0_BODY_INT_PIN, MPU60X0_BODY_INT_FUNCTION); pio_handler_set(PIOA, ID_PIOA, MPU60X0_BODY_INT_PIN, PIO_IT_RISE_EDGE, MPU60X0BodyInterrupt); pio_set_input(PIOA, MPU60X0_HEAD_INT_PIN, MPU60X0_HEAD_INT_FUNCTION); pio_configure_interrupt(PIOA, MPU60X0_HEAD_INT_PIN, MPU60X0_HEAD_INT_FUNCTION); pio_handler_set(PIOA, ID_PIOA, MPU60X0_HEAD_INT_PIN, PIO_IT_RISE_EDGE, MPU60X0HeadInterrupt); NVIC_EnableIRQ(PIOA_IRQn); pio_enable_interrupt(PIOA, MPU60X0_BODY_INT_PIN); pio_enable_interrupt(PIOA, MPU60X0_HEAD_INT_PIN); // Initialize TWI driver with options. if (TWI_SUCCESS != twi_master_init(TWI0, &twi_options)) { // Disable the interrupts. pio_disable_interrupt(PIOA, MPU60X0_BODY_INT_PIN); pio_disable_interrupt(PIOA, MPU60X0_HEAD_INT_PIN); return(-1); } // Enable both RX and TX TWI0->TWI_IER = TWI_IER_TXRDY | TWI_IER_RXRDY; return(0); }
/** * \brief Configure the push button 1. * * \note Configure the PIO as input and generate corresponding interrupt * when pressed or released. */ static void dsp_configure_button2(void) { /* Configure Pushbutton 1. */ pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID); pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 10); pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR, dsp_event_button2); /* Take care of NVIC_SetPriority. */ pio_handler_set_priority(PIN_PUSHBUTTON_2_PIO, (IRQn_Type) PIN_PUSHBUTTON_2_ID, INT_PRI_PUSHBUTTON); pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK); }
/** * \brief Configure the push button. * * Configure the PIO as inputs and generate corresponding interrupt when * pressed or released. */ static void configure_button(void) { /* Adjust PIO debounce filter parameters, using 10 Hz filter. */ pio_set_debounce_filter(PIN_PUSHBUTTON_WAKEUP_PIO, PIN_PUSHBUTTON_WAKEUP_MASK, 10); /* Initialize PIO interrupt handlers, see PIO definition in board.h. */ pio_handler_set(PIN_PUSHBUTTON_WAKEUP_PIO, PIN_PUSHBUTTON_WAKEUP_ID, PIN_PUSHBUTTON_WAKEUP_MASK, PIN_PUSHBUTTON_WAKEUP_ATTR, button_handler); /* Enable PIO controller IRQs. */ NVIC_EnableIRQ((IRQn_Type)PIN_PUSHBUTTON_WAKEUP_ID); /* Enable PIO line interrupts. */ pio_enable_interrupt(PIN_PUSHBUTTON_WAKEUP_PIO, PIN_PUSHBUTTON_WAKEUP_MASK); }
/** * \brief Configure the push button. * * Configure the PIOs as inputs and generate corresponding interrupt when * pressed or released. */ static void configure_button(void) { /* Configure PIO clock. */ pmc_enable_periph_clk(PUSH_BUTTON_ID); /* Adjust pio debounce filter parameters, uses 10 Hz filter. */ pio_set_debounce_filter(PUSH_BUTTON_PIO, PUSH_BUTTON_PIN_MSK, 10); /* Initialize pios interrupt handlers, see PIO definition in board.h. */ pio_handler_set(PUSH_BUTTON_PIO, PUSH_BUTTON_ID, PUSH_BUTTON_PIN_MSK, PUSH_BUTTON_ATTR, button_handler); /* Enable PIO controller IRQs. */ NVIC_EnableIRQ((IRQn_Type)PUSH_BUTTON_ID); /* Enable PIO line interrupts. */ pio_enable_interrupt(PUSH_BUTTON_PIO, PUSH_BUTTON_PIN_MSK); }
/** * \brief Configure the push button. * * Configure the PIOs as inputs and generate corresponding interrupt when * pressed or released. */ void Mifi_ConfigInt(void) { /* Configure PIO clock. */ //pmc_enable_periph_clk(CC1101_INT_ID); /* Adjust pio debounce filter parameters, uses 10 Hz filter. */ //pio_set_debounce_filter(CC1101_INT_PIO, CC1101_INT_PIN_MSK, 10); /* Initialize pios interrupt handlers, see PIO definition in board.h. */ pio_handler_set(CC1101_GPIO0_PIO, CC1101_INT_ID, CC1101_GPIO0, CC1101_INT_ATTR, button_handler); /* Enable PIO controller IRQs. */ NVIC_EnableIRQ((IRQn_Type)CC1101_INT_ID); /* Enable PIO line interrupts. */ pio_enable_interrupt(CC1101_GPIO0_PIO, CC1101_GPIO0); }
/** * \brief Configure the Push buttons * * Configure the PIO as inputs and generate corresponding interrupt when * pressed or released. */ static void configure_buttons(void) { /* Enable the peripheral clock for PCK and push button */ pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID); /* Adjust PIO debounce filter parameters, using 10 Hz filter. */ pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10); /* Initialize PIOs interrupt handlers, see PIO definition in board.h. */ /* Interrupt on rising edge */ pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR, button1_handler); /* Enable PIO controller IRQs. */ NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID); /* Enable PIO line interrupts. */ pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK); }
/** * \brief Configure the INTN interrupt. */ void configure_intn(void (*p_handler) (uint32_t, uint32_t)) { /* Configure PIO clock. */ pmc_enable_periph_clk(INTN_ID); /* Adjust PIO debounce filter parameters, uses 10 Hz filter. */ pio_set_debounce_filter(INTN_PIO, INTN_PIN_MSK, 10); /* Initialize PIO interrupt handlers, see PIO definition in board.h. */ pio_handler_set(INTN_PIO, INTN_ID, INTN_PIN_MSK, INTN_ATTR, p_handler); /* Enable NVIC interrupts. */ NVIC_SetPriority(INTN_IRQn, INT_PRIORITY_PIO); NVIC_EnableIRQ((IRQn_Type)INTN_ID); /* Enable PIO interrupts. */ pio_enable_interrupt(INTN_PIO, INTN_PIN_MSK); }
/** * \brief Handler for INT1, rising edge interrupt. In INT1, it will trigger * INT2. */ static void Int1Handler(uint32_t ul_id, uint32_t ul_mask) { if (PIN_PUSHBUTTON_1_ID != ul_id || PIN_PUSHBUTTON_1_MASK != ul_mask) return; pio_disable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK); /* Trigger INT1 & Delay for a while. */ puts("===================================================\r"); puts("Enter _Int1Handler.\r"); gpio_set_pin_low(LED0_GPIO); delay_ticks(2000); gpio_set_pin_high(LED0_GPIO); puts("Exit _Int1Handler.\r"); puts("===================================================\r"); pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK); }
/** * \brief Handler for INT2, rising edge interrupt. */ static void Int2Handler(uint32_t ul_id, uint32_t ul_mask) { if (PIN_PUSHBUTTON_2_ID != ul_id || PIN_PUSHBUTTON_2_MASK != ul_mask) return; pio_disable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK); puts("***************************************************\r"); puts("Enter _Int2Handler.\r"); /* Enter INT2. */ gpio_set_pin_low(LED1_GPIO); /* Delay for a while. */ delay_ticks(2000); /* Exit INT2. */ gpio_set_pin_high(LED1_GPIO); puts("Exit _Int2Handler.\r"); puts("***************************************************\r"); pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK); }
int main (void) { /* Insert system clock initialization code here (sysclk_init()). */ sysclk_init(); board_init(); /* Insert application code here, after the board has been initialized. */ if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) { puts("-E- Systick configuration error\r"); while (1) { /* Capture error */ gpio_set_pin_low(LED2_GPIO); } } config_lcd(); pmc_enable_periph_clk(ID_ENC); //Interrupt for A: pio_set_input(PIOA, GPIO_A, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_A, ENABLE); pio_handler_set(PIOA, ID_ENC, GPIO_A, PIO_IT_RISE_EDGE, pin_handler); pio_enable_interrupt(PIOA, GPIO_A); //Interrupt for B: pio_set_input(PIOA, GPIO_B, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_B, ENABLE); pio_handler_set(PIOA, ID_ENC, GPIO_B, PIO_IT_RISE_EDGE, pin_handler); pio_enable_interrupt(PIOA, GPIO_B); //Interrupt for C: pio_set_input(PIOA, GPIO_C, PIO_DEFAULT); pio_pull_down(PIOA, GPIO_C, ENABLE); //pio_handler_set(PIOA, ID_ENC, GPIO_C, PIO_IT_RISE_EDGE, pin_handler); pio_handler_set(PIOA, ID_ENC, GPIO_C, PIO_IT_FALL_EDGE, pin_handler); pio_enable_interrupt(PIOA, GPIO_C); //Enable Interrupt GPIO: NVIC_DisableIRQ(PIOA_IRQn); NVIC_ClearPendingIRQ(PIOA_IRQn); NVIC_SetPriority(PIOA_IRQn, 0); NVIC_EnableIRQ(PIOA_IRQn); ili9225_set_foreground_color(COLOR_BLACK); ili9225_draw_string(10,10, (uint8_t *)"Encoder Test"); while (1){ ili9225_set_foreground_color(COLOR_WHITE); ili9225_draw_filled_rectangle(0,30,ILI9225_LCD_WIDTH,ILI9225_LCD_HEIGHT); ili9225_set_foreground_color(COLOR_BLACK); graus = ((float)round/ENC_RES)*VOLTA_COMP; snprintf(buf, sizeof(buf), "Graus:%.3f", graus ); ili9225_draw_string(10,50, buf); snprintf(buf, sizeof(buf), "Round:%d", round ); ili9225_draw_string(10,80, buf); mdelay(500); } }