static void ICACHE_RAM_ATTR platform_gpio_intr_dispatcher (void *dummy){ uint32 j=0; uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); uint32 now = system_get_time(); UNUSED(dummy); #ifdef GPIO_INTERRUPT_HOOK_ENABLE if (gpio_status & platform_gpio_hook.all_bits) { for (j = 0; j < platform_gpio_hook.count; j++) { if (gpio_status & platform_gpio_hook.entry[j].bits) gpio_status = (platform_gpio_hook.entry[j].func)(gpio_status); } } #endif /* * gpio_status is a bit map where bit 0 is set if unmapped gpio pin 0 (pin3) has * triggered the ISR. bit 1 if unmapped gpio pin 1 (pin10=U0TXD), etc. Since this * is the ISR, it makes sense to optimize this by doing a fast scan of the status * and reverse mapping any set bits. */ for (j = 0; gpio_status>0; j++, gpio_status >>= 1) { if (gpio_status&1) { int i = pin_num_inv[j]; if (pin_int_type[i]) { //disable interrupt gpio_pin_intr_state_set(GPIO_ID_PIN(j), GPIO_PIN_INTR_DISABLE); //clear interrupt status GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(j)); uint32 level = 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(j)); task_post_high (gpio_task_handle, (now << 8) + (i<<1) + level); // We re-enable the interrupt when we execute the callback } } } }
static void ICACHE_RAM_ATTR platform_gpio_intr_dispatcher (void *dummy){ uint32 j=0; uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS); uint32 now = system_get_time(); UNUSED(dummy); #ifdef GPIO_INTERRUPT_HOOK_ENABLE if (gpio_status & platform_gpio_hook.all_bits) { for (j = 0; j < platform_gpio_hook.count; j++) { if (gpio_status & platform_gpio_hook.entry[j].bits) gpio_status = (platform_gpio_hook.entry[j].func)(gpio_status); } } #endif /* * gpio_status is a bit map where bit 0 is set if unmapped gpio pin 0 (pin3) has * triggered the ISR. bit 1 if unmapped gpio pin 1 (pin10=U0TXD), etc. Since this * is the ISR, it makes sense to optimize this by doing a fast scan of the status * and reverse mapping any set bits. */ for (j = 0; gpio_status>0; j++, gpio_status >>= 1) { if (gpio_status&1) { int i = pin_num_inv[j]; if (pin_int_type[i]) { uint16_t diff = pin_counter[i].seen ^ pin_counter[i].reported; pin_counter[i].seen = 0x7fff & (pin_counter[i].seen + 1); if (INTERRUPT_TYPE_IS_LEVEL(pin_int_type[i])) { //disable interrupt gpio_pin_intr_state_set(GPIO_ID_PIN(j), GPIO_PIN_INTR_DISABLE); } //clear interrupt status GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(j)); if (diff == 0 || diff & 0x8000) { uint32 level = 0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(j)); if (!task_post_high (gpio_task_handle, (now << 8) + (i<<1) + level)) { // If we fail to post, then try on the next interrupt pin_counter[i].seen |= 0x8000; } // We re-enable the interrupt when we execute the callback (if level) } } else { // this is an unexpected interrupt so shut it off for now gpio_pin_intr_state_set(GPIO_ID_PIN(j), GPIO_PIN_INTR_DISABLE); GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(j)); } } } }