/** * \brief Process an interrupt request on the given PIO controller. * * \param p_pio PIO controller base address. * \param ul_id PIO controller ID. */ void pio_handler_process(Pio *p_pio, uint32_t ul_id) { uint32_t status; uint32_t i; /* Read PIO controller status */ status = pio_get_interrupt_status(p_pio); status &= pio_get_interrupt_mask(p_pio); /* Check pending events */ if (status != 0) { /* Find triggering source */ i = 0; while (status != 0) { /* Source is configured on the same controller */ if (gs_interrupt_sources[i].id == ul_id) { /* Source has PIOs whose statuses have changed */ if ((status & gs_interrupt_sources[i].mask) != 0) { gs_interrupt_sources[i].handler(gs_interrupt_sources[i].id, gs_interrupt_sources[i].mask); status &= ~(gs_interrupt_sources[i].mask); } } i++; } } }
void gpio_irq(Pio *p_pio, uint32_t ul_id) { uint32_t status; uint32_t i; /* Read PIO controller status */ status = pio_get_interrupt_status(p_pio); status &= pio_get_interrupt_mask(p_pio); /* Check pending events */ if (status != 0) { /* Find triggering source */ i = 0; while (status != 0) { /* Source is configured on the same controller */ if (gpio_irq_data[i].id == ul_id) { /* Source has PIOs whose statuses have changed */ if ((status & gpio_irq_data[i].mask) != 0) { void * arg = gpio_irq_data[i].arg; /* avoids undefined order of access to volatiles */ gpio_irq_data[i].handler(arg); status &= ~(gpio_irq_data[i].mask); } } i++; if (i >= MAX_INTERRUPT_SOURCES) { break; } } } }
/** * \brief Disables interrupt pin change */ static void ui_disable_asynchronous_interrupt(void) { /* Disable interrupt for button pin */ pio_disable_pin_interrupt(GPIO_PUSH_BUTTON_2); pio_get_interrupt_status(PIOB); /* Enable fastwakeup for button pin */ pmc_clr_fast_startup_input(PMC_FSMR_FSTT14); }
/** * \brief Disables interrupt pin change */ static void ui_disable_asynchronous_interrupt(void) { /* Disable interrupt for button pin */ pio_disable_pin_interrupt(RESUME_PIN); pio_get_interrupt_status(RESUME_PIO); /* Enable fast wakeup for button pin */ pmc_clr_fast_startup_input(RESUME_PMC_FSTT); }
//done void PIOA_Handler (void) { ButtonStatus = pio_get_interrupt_status(PIOA); ButtonStatus &= pio_get_interrupt_mask(PIOA); if(ButtonStatus&Push1 || ButtonStatus&Push2) xSemaphoreGiveFromISR(CMDFRAMEsem,NULL); else { sendDebugString("UpdateSemCalled\n"); xSemaphoreGiveFromISR(PIOAsem,NULL); } }
/** * \brief Initialize PIO interrupt management logic. * * \note The desired priority of PIO must be provided. * Calling this function multiple times result in the reset of currently * configured interrupt on the provided PIO. * * \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) { /* Configure PIO interrupt sources */ pio_get_interrupt_status(p_pio); pio_disable_interrupt(p_pio, 0xFFFFFFFF); NVIC_DisableIRQ(ul_irqn); NVIC_ClearPendingIRQ(ul_irqn); NVIC_SetPriority(ul_irqn, ul_priority); NVIC_EnableIRQ(ul_irqn); }
/* * @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_get_interrupt_status(CONF_WINC_SPI_INT_PIO); 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 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); }
/* * @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_get_interrupt_status(CONF_WINC_SPI_INT_PIO); 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); }
/** * \brief Process an interrupt request on the given PIO controller. * * \param p_pio PIO controller base address. * \param ul_id PIO controller ID. */ void pio_handler_process(Pio *p_pio, uint32_t ul_id) { uint32_t status; uint32_t i; /* Read PIO controller status */ status = pio_get_interrupt_status(p_pio); status &= pio_get_interrupt_mask(p_pio); /* Check pending events */ if (status != 0) { /* Find triggering source */ i = 0; while (status != 0) { /* Source is configured on the same controller */ if (gs_interrupt_sources[i].id == ul_id) { /* Source has PIOs whose statuses have changed */ if ((status & gs_interrupt_sources[i].mask) != 0) { gs_interrupt_sources[i].handler(gs_interrupt_sources[i].id, gs_interrupt_sources[i].mask); status &= ~(gs_interrupt_sources[i].mask); } } i++; if (i >= MAX_INTERRUPT_SOURCES) { break; } } } /* Check capture events */ #if (SAM3S || SAM4S || SAM4E) if (pio_capture_enable_flag) { if (pio_capture_handler) { pio_capture_handler(p_pio); } } #endif }
/** * \name Main user interface functions * @{ */ void ui_init(void) { /* Enable PIO clock for button inputs */ pmc_enable_periph_clk(ID_PIOB); pmc_enable_periph_clk(ID_PIOE); /* Set handler for wakeup */ pio_handler_set(RESUME_PIO, RESUME_PIO_ID, RESUME_PIO_MASK, RESUME_PIO_ATTR, ui_wakeup_handler); /* Enable IRQ for button (PIOB) */ NVIC_EnableIRQ((IRQn_Type)RESUME_PIO_ID); /* Enable interrupt for button pin */ pio_get_interrupt_status(RESUME_PIO); pio_configure_pin(RESUME_PIN, RESUME_PIO_ATTR); pio_enable_pin_interrupt(RESUME_PIN); /* Enable fastwakeup for button pin */ pmc_set_fast_startup_input(RESUME_PMC_FSTT); /* Initialize LEDs */ LED_Off(LED0_GPIO); LED_Off(LED1_GPIO); LED_Off(LED2_GPIO); LED_Off(LED3_GPIO); }