Interrupt handler for gpio_isr_register()

chegewara
Posts: 2380
Joined: Wed Jun 14, 2017 9:00 pm

Interrupt handler for gpio_isr_register()

Postby chegewara » Sat Jul 01, 2017 5:17 pm

Hi guys, i would like to ask you what do you think about this interrupt handler. Its a little bit faster than the one in gpio.h but is it good programmed? In addition interrupts for pins 1,2,3 or pins 30-ish are faster than for pins 20-ish (less iterations).

Code: Select all

void IRAM_ATTR gpio_intr_service_2(void* arg)
{
    //read status to get interrupt status for GPIO0-31
    uint32_t gpio_intr_status;
    gpio_intr_status = GPIO.status;
    //read status1 to get interrupt status for GPIO32-39
    uint32_t gpio_intr_status_h;
    gpio_intr_status_h = GPIO.status1.intr_st;

    if (gpio_isr_func == NULL) {
        return;
    }

//clear intr status for all bit in one call
    GPIO.status_w1tc = gpio_intr_status;
	GPIO.status1_w1tc.intr_st = gpio_intr_status_h;

	uint8_t x = 0;
	while (gpio_intr_status) { //check if we have any interrupts for gpio0-gpio31
		if (gpio_intr_status & BIT(0)) { 
			if (gpio_isr_func[x].fn != NULL) {
				gpio_isr_func[x].fn(gpio_isr_func[x].args);
			}
		}
		gpio_intr_status = gpio_intr_status>>1;
		x++;
    } ;
	x=32;
	while (gpio_intr_status_h) {//check if we have any interrupts for gpio32-gpio39
		if (gpio_intr_status_h & BIT(0)) { 
			if (gpio_isr_func[x].fn != NULL) {
				gpio_isr_func[x].fn(gpio_isr_func[x].args);
			}
		}
		gpio_intr_status_h = gpio_intr_status_h>>1;
		x++;
    } ;
}
And this is original(https://github.com/espressif/esp-idf/bl ... #L342-L373):

Code: Select all

void IRAM_ATTR gpio_intr_service(void* arg)
{
    //GPIO intr process
    uint32_t gpio_num = 0;
    //read status to get interrupt status for GPIO0-31
    uint32_t gpio_intr_status;
    gpio_intr_status = GPIO.status;
    //read status1 to get interrupt status for GPIO32-39
    uint32_t gpio_intr_status_h;
    gpio_intr_status_h = GPIO.status1.intr_st;

    if (gpio_isr_func == NULL) {
        return;
    }
    do {
        if (gpio_num < 32) {
            if (gpio_intr_status & BIT(gpio_num)) { //gpio0-gpio31
                if (gpio_isr_func[gpio_num].fn != NULL) {
                    gpio_isr_func[gpio_num].fn(gpio_isr_func[gpio_num].args);
                }
                GPIO.status_w1tc = BIT(gpio_num);
            }
        } else {
            if (gpio_intr_status_h & BIT(gpio_num - 32)) {
                if (gpio_isr_func[gpio_num].fn != NULL) {
                    gpio_isr_func[gpio_num].fn(gpio_isr_func[gpio_num].args);
                }
                GPIO.status1_w1tc.intr_st = BIT(gpio_num - 32);
            }
        }
    } while (++gpio_num < GPIO_PIN_COUNT);
}

Who is online

Users browsing this forum: No registered users and 118 guests