/** * @brief * Gpio interrupt func for DR PIN ( PA 1 if Pin set high = transmision complited) * @{ */ void EXTI9_5_IRQHandler(void){ if(__HAL_GPIO_EXTI_GET_FLAG(GPIO_PIN_6)){ __HAL_GPIO_EXTI_CLEAR_FLAG(GPIO_PIN_6); RESET_TX_CE_nRF_RX; //RESET PINU TX_CE data_ready_flag = 1; } }
// Interrupt handler void Handle_EXTI_Irq(uint32_t line) { if (__HAL_GPIO_EXTI_GET_FLAG(1 << line)) { __HAL_GPIO_EXTI_CLEAR_FLAG(1 << line); if (line < EXTI_NUM_VECTORS) { mp_obj_t *cb = &MP_STATE_PORT(pyb_extint_callback)[line]; if (*cb != mp_const_none) { // When executing code within a handler we must lock the GC to prevent // any memory allocations. We must also catch any exceptions. gc_lock(); nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { mp_call_function_1(*cb, MP_OBJ_NEW_SMALL_INT(line)); nlr_pop(); } else { // Uncaught exception; disable the callback so it doesn't run again. *cb = mp_const_none; extint_disable(line); printf("Uncaught exception in ExtInt interrupt handler line %lu\n", line); mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); } gc_unlock(); } } } }
/** * @brief * Gpio interrupt func for DR PIN ( PA 1 if Pin set high = transmision complited) * @{ */ void EXTI1_IRQHandler(void){ //HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1); if(__HAL_GPIO_EXTI_GET_FLAG(GPIO_PIN_1)){ __HAL_GPIO_EXTI_CLEAR_FLAG(GPIO_PIN_1); RESET_TX_EN; //Reset Pinu TX_EN nRF RESET_TX_CE; //Reset Pinu TX_CE nRF } }
/** * gpio irq release * * No longer interrupt when something occurs on the pin. NOTE: this function * does not change the GPIO push/pull setting nor does it change the * SYSCFG EXTICR registers. It also does not disable the NVIC interrupt enable * setting for the irq. * * @param pin */ void hal_gpio_irq_release(int pin) { int index; uint32_t pin_mask; /* Disable the interrupt */ hal_gpio_irq_disable(pin); /* Clear any pending interrupts */ pin_mask = HAL_GPIO_PIN(pin); __HAL_GPIO_EXTI_CLEAR_FLAG(pin_mask); /* Clear out the irq handler */ index = HAL_GPIO_PIN_NUM(pin); hal_gpio_irq[index].arg = NULL; hal_gpio_irq[index].isr = NULL; }
/** * gpio irq release * * No longer interrupt when something occurs on the pin. NOTE: this function * does not change the GPIO push/pull setting nor does it change the * SYSCFG EXTICR registers. It also does not disable the NVIC interrupt enable * setting for the irq. * * @param pin */ void gpio_irq_release(int pin) { int index; uint32_t pin_mask; /* Disable the interrupt */ gpio_irq_disable(pin); /* Clear any pending interrupts */ pin_mask = GPIO_MASK(pin); __HAL_GPIO_EXTI_CLEAR_FLAG(pin_mask); /* Clear out the irq handler */ index = GPIO_INDEX(pin); gpio_irq_handlers[index].arg = NULL; gpio_irq_handlers[index].isr = NULL; }
static void handle_interrupt_in(uint32_t irq_index) { // Retrieve the gpio and pin that generate the irq GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]); uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]); // Clear interrupt flag if (__HAL_GPIO_EXTI_GET_FLAG(pin) != RESET) { __HAL_GPIO_EXTI_CLEAR_FLAG(pin); } if (channel_ids[irq_index] == 0) return; // Check which edge has generated the irq if ((gpio->IDR & pin) == 0) { irq_handler(channel_ids[irq_index], IRQ_FALL); } else { irq_handler(channel_ids[irq_index], IRQ_RISE); } }
/** * gpio irq init * * Initialize an external interrupt on a gpio pin * * @param pin Pin number to enable gpio. * @param handler Interrupt handler * @param arg Argument to pass to interrupt handler * @param trig Trigger mode of interrupt * @param pull Push/pull mode of input. * * @return int */ int hal_gpio_irq_init(int pin, hal_gpio_irq_handler_t handler, void *arg, hal_gpio_irq_trig_t trig, hal_gpio_pull_t pull) { int rc; int irqn; int index; uint32_t pin_mask; uint32_t mode; GPIO_InitTypeDef cfg; /* Configure the gpio for an external interrupt */ rc = 0; switch (trig) { case HAL_GPIO_TRIG_NONE: rc = -1; break; case HAL_GPIO_TRIG_RISING: mode = GPIO_MODE_IT_RISING; break; case HAL_GPIO_TRIG_FALLING: mode = GPIO_MODE_IT_FALLING; break; case HAL_GPIO_TRIG_BOTH: mode = GPIO_MODE_IT_RISING_FALLING; break; case HAL_GPIO_TRIG_LOW: rc = -1; break; case HAL_GPIO_TRIG_HIGH: rc = -1; break; default: rc = -1; break; } /* Check to make sure no error has occurred */ if (!rc) { /* Disable interrupt and clear any pending */ hal_gpio_irq_disable(pin); pin_mask = HAL_GPIO_PIN(pin); __HAL_GPIO_EXTI_CLEAR_FLAG(pin_mask); /* Set the gpio irq handler */ index = HAL_GPIO_PIN_NUM(pin); hal_gpio_irq[index].isr = handler; hal_gpio_irq[index].arg = arg; hal_gpio_irq[index].invoked = 0; /* Configure the GPIO */ cfg.Mode = mode; cfg.Pull = pull; rc = hal_gpio_init_stm(pin, &cfg); if (!rc) { /* Enable interrupt vector in NVIC */ irqn = hal_gpio_pin_to_irq(pin); hal_gpio_set_nvic(irqn); } } return rc; }