How to use gpio_isr_register?

User avatar
rudi ;-)
Posts: 1259
Joined: Fri Nov 13, 2015 3:25 pm

Re: How to use gpio_isr_register?

Postby rudi ;-) » Sun Oct 23, 2016 7:52 am

WiFive wrote:Well I guess if you system_restart from CPU1 you cause exception on CPU0. Not a graceful restart.
txs, this sounds plausible. can we choice, which CPU we restart?
can we restart only cpu1?

this would be a nice goal - 'cause then wifi/ble is untouched..

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
rudi ;-)
Posts: 1259
Joined: Fri Nov 13, 2015 3:25 pm

Re: How to use gpio_isr_register?

Postby rudi ;-) » Sun Oct 23, 2016 7:22 pm

at time there are so many things now mixed..
..

Code: Select all


#define ETS_GPIO_INTR_ENABLE() \
        ETS_INTR_ENABLE(ETS_GPIO_INUM)
        

Code: Select all


#define ESP_GPIO_INTR_ENABLE() \
    ESP_INTR_ENABLE(ETS_GPIO_INUM)
    

Code: Select all

esp_err_t gpio_intr_enable(gpio_num_t gpio_num)
{
    if(!is_valid_gpio(gpio_num)) {
        return ESP_ERR_INVALID_ARG;
    }
    if(xPortGetCoreID() == 0) {
        GPIO.pin[gpio_num].int_ena = GPIO_PRO_CPU_INTR_ENA;     //enable pro cpu intr
    } else {
        GPIO.pin[gpio_num].int_ena = GPIO_APP_CPU_INTR_ENA;     //enable pro cpu intr
    }
    return ESP_OK;
}

Code: Select all

esp_err_t gpio_intr_disable(gpio_num_t gpio_num)
{
    if(!is_valid_gpio(gpio_num)) {
        return ESP_ERR_INVALID_ARG;
    }
    GPIO.pin[gpio_num].int_ena = 0;                             //disable GPIO intr
    return ESP_OK;
}
..hope we get a small api/reference soon
But I'm afraid we'll have to pull that out of the headers still a long time at first.
the problem sometime is, that the "system" libs does not have all include, what we have in headers.
so we must wait in parts for update the libs too.
( no hurry guys, know, you are hard at work )

my code seams in part right.
but i have now to debounce the pushes,
because esp32 is so fast, that fired the pushbutton seven times in one push :)

i try just in time combine two esp32 by parallel mode( d0..d7 ) and handshakes by ISR.
it loooks good for first steps

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

jumjum123
Posts: 182
Joined: Mon Oct 17, 2016 3:11 pm

Re: How to use gpio_isr_register?

Postby jumjum123 » Mon Oct 24, 2016 8:36 am

@Rudi, thanks for your detailled tour through gpio interrupts.
I'm working on same problem during porting Javascript(Espruino) to the ESP32.
After reading all your replies I still have some questions
- what is gpio_pad_select_gpio for ? I'm getting a similiar result without this function
- you added a tag for args which is not used anymore later on. I'm using NULL, what is the benefit of your arg ?
- debouncing, hmm. What I get is usually more than one interrupt where value of GPIO is true, without having a value = false between. Is handling of interrupt too slow, and bounces are too fast ?

User avatar
rudi ;-)
Posts: 1259
Joined: Fri Nov 13, 2015 3:25 pm

Re: How to use gpio_isr_register?

Postby rudi ;-) » Mon Oct 24, 2016 9:22 pm

jumjum123 wrote: - what is gpio_pad_select_gpio for ? I'm getting a similiar result without this function
you are right. you need this not if you not use the pads ( example Developer V2 Demo Board has Finger Pads )
see here ->
ESP32-demo-board-front-side_small.jpg
ESP32-demo-board-front-side_small.jpg (50.67 KiB) Viewed 3141 times
jumjum123 wrote: - you added a tag for args which is not used anymore later on. I'm using NULL, what is the benefit of your arg ?
The "arg" parameter specifies the argument to be passed to the handler when it is invoked.

see here

Code: Select all

esp_err_t gpio_isr_register(uint32_t gpio_intr_num, void (*fn)(void*), void * arg)
{
    if(fn == NULL) {
        return ESP_ERR_INVALID_ARG;
    }
    ESP_INTR_DISABLE(gpio_intr_num);
    intr_matrix_set(xPortGetCoreID(), ETS_GPIO_INTR_SOURCE, gpio_intr_num);
    xt_set_interrupt_handler(gpio_intr_num, fn, arg);  // follow this ... 
    ESP_INTR_ENABLE(gpio_intr_num);
    return ESP_OK;
}


and follow it here -example-

Code: Select all


/*
  This function registers a handler for the specified interrupt. The "arg"
  parameter specifies the argument to be passed to the handler when it is
  invoked. The function returns the address of the previous handler.
  On error, it returns 0.
*/
xt_handler xt_set_interrupt_handler(int n, xt_handler f, void * arg)
{
    xt_handler_table_entry * entry;
    xt_handler               old;

    if( n < 0 || n >= XCHAL_NUM_INTERRUPTS )
        return 0;       /* invalid interrupt number */
    if( Xthal_intlevel[n] > XCHAL_EXCM_LEVEL )
        return 0;       /* priority level too high to safely handle in C */

    entry = _xt_interrupt_table + n;
    old   = entry->handler;

    if (f) {
        entry->handler = f;
        entry->arg     = arg;
    }
    else {
        entry->handler = &xt_unhandled_interrupt;
        entry->arg     = (void*)n;
    }

    return ((old == &xt_unhandled_interrupt) ? 0 : old);
}


you are right here too ( see possible 2, and last arg = NULL )
i am on this "mixed " step now too
but careful handling - not quite true - this is WMAC -
only for compare..what arg do.

Code: Select all


/**
  * @brief  Attach an CPU interrupt to a hardware source.
  *         We have 4 steps to use an interrupt:
  *         1.Attach hardware interrupt source to CPU.  intr_matrix_set(0, ETS_WIFI_MAC_INTR_SOURCE, ETS_WMAC_INUM);
  *         2.Set interrupt handler.                    xt_set_interrupt_handler(ETS_WMAC_INUM, func, NULL);
  *         3.Enable interrupt for CPU.                 xt_ints_on(1 << ETS_WMAC_INUM);
  *         4.Enable interrupt in the module.
  *
  * @param  int cpu_no : The CPU which the interrupt number belongs.
  *
  * @param  uint32_t model_num : The interrupt hardware source number, please see the interrupt hardware source table.
  *
  * @param  uint32_t intr_num : The interrupt number CPU, please see the interrupt cpu using table.
  *
  * @return None
  */
void intr_matrix_set(int cpu_no, uint32_t model_num, uint32_t intr_num);

#define _ETSTR(v) # v
#define _ETS_SET_INTLEVEL(intlevel)        ({ unsigned __tmp; \
            __asm__ __volatile__(   "rsil   %0, " _ETSTR(intlevel) "\n" \
                        : "=a" (__tmp) : : "memory" ); \
            })

#ifdef CONFIG_NONE_OS
#define ETS_INTR_LOCK() \
        ets_intr_lock()

#define ETS_INTR_UNLOCK() \
        ets_intr_unlock()

#define ETS_ISR_ATTACH \
        ets_isr_attach

#define ETS_INTR_ENABLE(inum) \
        ets_isr_unmask((1<<inum))

#define ETS_INTR_DISABLE(inum) \
        ets_isr_mask((1<<inum))

#define ETS_WMAC_INTR_ATTACH(func, arg) \
        ETS_ISR_ATTACH(ETS_WMAC_INUM, (func), (void *)(arg))

#define ETS_TG0_T0_INTR_ATTACH(func, arg) \
        ETS_ISR_ATTACH(ETS_TG0_T0_INUM, (func), (void *)(arg))

#define ETS_GPIO_INTR_ATTACH(func, arg) \
        ETS_ISR_ATTACH(ETS_GPIO_INUM, (func), (void *)(arg))

#define ETS_UART0_INTR_ATTACH(func, arg) \
        ETS_ISR_ATTACH(ETS_UART0_INUM, (func), (void *)(arg))

#define ETS_WDT_INTR_ATTACH(func, arg) \
        ETS_ISR_ATTACH(ETS_WDT_INUM, (func), (void *)(arg))

#define ETS_SLC_INTR_ATTACH(func, arg) \
        ETS_ISR_ATTACH(ETS_SLC_INUM, (func), (void *)(arg))

#define ETS_BB_INTR_ENABLE() \
        ETS_INTR_ENABLE(ETS_BB_INUM)

#define ETS_BB_INTR_DISABLE() \
        ETS_INTR_DISABLE(ETS_BB_INUM)

#define ETS_UART0_INTR_ENABLE() \
        ETS_INTR_ENABLE(ETS_UART0_INUM)

#define ETS_UART0_INTR_DISABLE() \
        ETS_INTR_DISABLE(ETS_UART0_INUM)

#define ETS_GPIO_INTR_ENABLE() \
        ETS_INTR_ENABLE(ETS_GPIO_INUM)

#define ETS_GPIO_INTR_DISABLE() \
        ETS_INTR_DISABLE(ETS_GPIO_INUM)

#define ETS_WDT_INTR_ENABLE() \
        ETS_INTR_ENABLE(ETS_WDT_INUM)

#define ETS_WDT_INTR_DISABLE() \
        ETS_INTR_DISABLE(ETS_WDT_INUM)

#define ETS_TG0_T0_INTR_ENABLE() \
        ETS_INTR_ENABLE(ETS_TG0_T0_INUM)

#define ETS_TG0_T0_INTR_DISABLE() \
        ETS_INTR_DISABLE(ETS_TG0_T0_INUM)

#define ETS_SLC_INTR_ENABLE() \
        ETS_INTR_ENABLE(ETS_SLC_INUM)

#define ETS_SLC_INTR_DISABLE() \
        ETS_INTR_DISABLE(ETS_SLC_INUM)
#endif


jumjum123 wrote: - debouncing, hmm. What I get is usually more than one interrupt where value of GPIO is true, without having a value = false between. Is handling of interrupt too slow, and bounces are too fast ?
this is the same question i have.
i have mean, that my finger dip is to sensitive - so i change to buttons and pulled up with 10k.
sometimes i get valu= high, but i have set INTR to low. ( NEGEDGE ) so i ask me, why this can happens that i get high valu in the isr.
at this time i work just in time to search why this is. i have change the code too :
on minimal for testings steps by enable/disable gpio isr in each variations.
and start simple what happens for debouncing / or INTR Slow, or bounces are too fast..

Code: Select all


/******************************************************************************
 * FunctionName : gpioCallback
 * Description  : 
 * Parameters   : void* arg
 * Returns      :  
*******************************************************************************/
void gpioCallback(void* arg)
{
   gpio_intr_disable(PIR_GPIO);
   gpio_intr_disable(BTN_GPIO);
   
    uint32_t gpio_intr_status = READ_PERI_REG(GPIO_STATUS_REG);   //read status to get interrupt status for GPIO0-31
    SET_PERI_REG_MASK(GPIO_STATUS_W1TC_REG, gpio_intr_status);    //Clear intr for gpio0-gpio31
    
	switch (gpio_intr_status) {
		
		// GPIO 18
		// 0b1000000000000000000
		case 262144:	// gpio_intr_disable(PIR_GPIO);
							// gpio_intr_disable(BTN_GPIO);
							ets_printf("GPIO 18 pushed\n"); 
							break;

		
		// GPIO 17
		// 0b100000000000000000
		case 131072:	// gpio_intr_disable(PIR_GPIO);
							// gpio_intr_disable(BTN_GPIO);
							ets_printf("GPIO 17 pushed\n");
							break;
						
		
		default:			ets_printf("handler : %lu fired\n", gpio_intr_status);

	}
	
	gpio_intr_enable(PIR_GPIO);
	gpio_intr_enable(BTN_GPIO);
	
}


i am just in time on this testings.
at first without valu ( high, low), only fire.

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

User avatar
rudi ;-)
Posts: 1259
Joined: Fri Nov 13, 2015 3:25 pm

Re: How to use gpio_isr_register?

Postby rudi ;-) » Tue Oct 25, 2016 1:01 am

this is the same question i have.
i have mean, that my finger dip is to sensitive - so i change to buttons and pulled up with 10k.
sometimes i get valu= high, but i have set INTR to low. ( NEGEDGE ) so i ask me, why this can happens that i get high valu in the isr.
at this time i work just in time to search why this is.
simple answere
ok runs for me now on this fast selftest:

set up gpio 17, 18 for input and ISR
set up gpio 16, 23 for output and connect 16->17 and 23->18
create push1 task ( delay times arbitrarily )
create push2 task ( delay times arbitrarily )

setup the INTR to NEGEDGE for test no valu=high in ISR

-> debouncing is recommendable must be done if you push by finger, buttons on all occasions
( here for fast test by gpio outputs as "pushes" not done )


simple output:

Code: Select all


2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
2 Intr GPIO131072 ,val: 0<\r><\n>
GPIO 17 [PIR] pushed<\r><\n>
1 Intr GPIO262144 ,val: 0<\r><\n>
GPIO 18 [BTN] pushed<\r><\n>
result:
no high in the ISR = ok
no bouncing = ok


here the simple ( not cleaned ) code :

Code: Select all

/******************************************************************************
 * 
 * Espressif IoT Development Framework with the ESP32  
 *
 * ESP-IDF - 
 * the new Espressif IoT Development Framework with ESP32 from espressif 
 * github              : https://github.com/espressif/esp-idf                       
 *
 *
*******************************************************************************/

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "driver/gpio.h"


#define PUSH1_GPIO 16   // connected to PIR_GPIO '17
#define PUSH2_GPIO 23	// connected to BTN_GPIO '18
#define PIR_GPIO 17
#define BTN_GPIO 18
#define INT_NUMB 17 // 22

#define TAG 3 // still i used here 


void gpioCallback (void* arg);


/******************************************************************************
 * FunctionName : main_task
 * Description  : 
 * Parameters   : void* pvParameter
 * Returns      : void
*******************************************************************************/
void main_task(void* pvParameter)
{
       
	  /* Set the GPIO as a input */
      gpio_set_direction(PIR_GPIO, GPIO_MODE_INPUT);
	  gpio_set_direction(BTN_GPIO, GPIO_MODE_INPUT);
	  
	  /* Set the GPIO pull */
      gpio_set_pull_mode(PIR_GPIO, GPIO_PULLUP_ONLY);
	  gpio_set_pull_mode(BTN_GPIO, GPIO_PULLUP_ONLY);
  
       
      // gpio_set_intr_type(INPUT_GPIO, GPIO_INTR_NEGEDGE);
	  // gpio_set_intr_type(PIR_GPIO, GPIO_INTR_ANYEDGE);
	  
	  // gpio_set_intr_type(PIR_GPIO, GPIO_INTR_ANYEDGE);
	  // gpio_set_intr_type(BTN_GPIO, GPIO_INTR_ANYEDGE);	  
  
	  gpio_set_intr_type(PIR_GPIO, GPIO_INTR_NEGEDGE);
	  gpio_set_intr_type(BTN_GPIO, GPIO_INTR_NEGEDGE);	  


  
      // ETS_GPIO_INTR_DISABLE() ;
  
      gpio_intr_enable(PIR_GPIO);
      gpio_intr_enable(BTN_GPIO);
	
      // gpio_intr_enable();
	  // ETS_GPIO_INTR_ENABLE();  
	  // ETS_INTR_ENABLE();  
	
  
      // Intterrupt number see below
      gpio_isr_register(INT_NUMB, gpioCallback, (void *)TAG); 
	  
      
	  
  
      while(1) {
      //   printf( "Loop...\n" );
      //  vTaskDelay(1000 / portTICK_RATE_MS);
  }
}
 
 
 /******************************************************************************
 * FunctionName : gpioCallback
 * Description  : 
 * Parameters   : void* arg
 * Returns      :  
*******************************************************************************/
void gpioCallback(void* arg)
{
	
	gpio_intr_disable(PIR_GPIO);
	gpio_intr_disable(BTN_GPIO);
	
    uint32_t gpio_intr_status = READ_PERI_REG(GPIO_STATUS_REG);   //read status to get interrupt status for GPIO0-31
    SET_PERI_REG_MASK(GPIO_STATUS_W1TC_REG, gpio_intr_status);    //Clear intr for gpio0-gpio31
    
	switch (gpio_intr_status) {
		
		// BTN_GPIO
		// GPIO 18
		// 1000000000000000000
		case 262144:	// gpio_intr_disable(PIR_GPIO);
						// gpio_intr_disable(BTN_GPIO);
						ets_printf("1 Intr GPIO%d ,val: %d\n",gpio_intr_status,gpio_get_level(BTN_GPIO));
						ets_printf("GPIO 18 [BTN] pushed\n"); 
						break;

		// PIR_GPIO
		// GPIO 17
		// 100000000000000000
		case 131072:	// gpio_intr_disable(PIR_GPIO);
						// gpio_intr_disable(BTN_GPIO);
						ets_printf("2 Intr GPIO%d ,val: %d\n",gpio_intr_status,gpio_get_level(PIR_GPIO));
						ets_printf("GPIO 17 [PIR] pushed\n");
						break;
						
		
		default:		ets_printf("handler : %lu fired\n", gpio_intr_status);

	}
	
	gpio_intr_enable(PIR_GPIO);
    gpio_intr_enable(BTN_GPIO);
	
}

 
 
void push1_task(void *pvParameter)
{
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(PUSH1_GPIO, GPIO_MODE_OUTPUT);
	while(1) {
        /* Push1 off (output low) */
        gpio_set_level(PUSH1_GPIO, 0);
        vTaskDelay(732 / portTICK_RATE_MS);
        /* Push1 on (output high) */
        gpio_set_level(PUSH1_GPIO, 1);
        vTaskDelay(492 / portTICK_RATE_MS);
    }
} 
 


void push2_task(void *pvParameter)
{
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(PUSH2_GPIO, GPIO_MODE_OUTPUT);
	while(1) {
        /* Push2 off (output low) */
        gpio_set_level(PUSH2_GPIO, 0);
        vTaskDelay(472 / portTICK_RATE_MS);
        /* Push2 on (output high) */
        gpio_set_level(PUSH2_GPIO, 1);
        vTaskDelay(839 / portTICK_RATE_MS);
    }
} 
 

/******************************************************************************
 * * * * * * * *: main of ESP32 
 * FunctionName : app_main
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void app_main()  
{
  nvs_flash_init();
  system_init();
      
  xTaskCreate(&main_task, "main_task", 2048, NULL, 5, NULL);
   
  xTaskCreate(&push1_task, "push1_task", 512, NULL, 5, NULL);
  
  xTaskCreate(&push2_task, "push2_task", 512, NULL, 5, NULL);
  
  
}

runs for me now like i need and controlled by eyes,
next step comes with RÌGOL / LOGANALYSER

thanks WiFive for INTR_NUM info,
have now understand what ESP_Sprite have warned with explanation :)
INTR_NUMB 17 and GPIO 17 was coincidence that works.

this only a simple test here.
i will test with fast handshakes and d0..d7 between 2 esp32 and more.
think the base in ISR/INTR now understand.

have noted, that we have now more function
example if we enable each
gpio_intr_enable(GPIO_XX);
gpio_intr_enable(GPIO_YY);
then we can "Evaluate only one of the two" in the ISR, because the INTR Fired onetimes to this time..
if we want "Evaluate all " / we can "Evaluate all" in the ISR because the INTR Fired onetimes, and if was "pushed" the other before, we can see this if we READ_PERI_REG(GPIO_STATUS_REG);

this is very fine if we example make INTR on SDA ( I2C ) and want check SCL too on a certaintime for a CMD ( START, STOP ) without a INTR enable on this.

best wishes
rudi ;-)

btw:
one question is for me open:
what is the best for use and what is real the difference of this?

17 extern level

22 extern edge
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

ESP_Sprite
Posts: 2073
Joined: Thu Nov 26, 2015 4:08 am

Re: How to use gpio_isr_register?

Postby ESP_Sprite » Tue Oct 25, 2016 2:29 am

Rudi: As far as I can see, the main differences are:

22 has level 3, it will have a higher priority than 17, which is level 1. That is, if an interrupt routine is finished or interrupts are re-enabled after a critical section,if both int 17 and 22 are triggered, the CPU will handle 22 before 17.

22 is an edge interrupt, 17 is a level interrupt. In theory, there are some differences, mostly related to the way the interrupt controller works... but due to the fact that the line is internal to the ESP32, I'm not sure if this makes any difference in practice, unless you connect two peripherals to the same interrupt.

WiFive
Posts: 2088
Joined: Tue Dec 01, 2015 7:35 am

Re: How to use gpio_isr_register?

Postby WiFive » Tue Oct 25, 2016 2:31 am

rudi ;-) wrote:
jumjum123 wrote: - what is gpio_pad_select_gpio for ? I'm getting a similiar result without this function
you are right. you need this not if you not use the pads ( example Developer V2 Demo Board has Finger Pads )
No I don't think this has anything to do with finger pads. It is for setting IOMUX. Really means gpio_function_select_gpio. This is for pin (aka pad) that have default function other than gpio.
Last edited by WiFive on Tue Oct 25, 2016 2:39 am, edited 1 time in total.

WiFive
Posts: 2088
Joined: Tue Dec 01, 2015 7:35 am

Re: How to use gpio_isr_register?

Postby WiFive » Tue Oct 25, 2016 2:39 am

ESP_Sprite wrote:Rudi: As far as I can see, the main differences are:

22 has level 3, it will have a higher priority than 17, which is level 1. That is, if an interrupt routine is finished or interrupts are re-enabled after a critical section,if both int 17 and 22 are triggered, the CPU will handle 17 before 22.

22 is an edge interrupt, 17 is a level interrupt. In theory, there are some differences, mostly related to the way the interrupt controller works... but due to the fact that the line is internal to the ESP32, I'm not sure if this makes any difference in practice, unless you connect two peripherals to the same interrupt.
Yes this is interesting because you set the gpio interrupt type when configuring the gpio interrupt (edge, level, ...) and then it goes through the matrix. You pick a CPU interrupt which seems really only priority is important. Edge/level for CPU interrupt is just like a sub priority as level 1 edge will trigger before level 1 level? Maybe it makes a difference for very low latency interrupt response?

jumjum123
Posts: 182
Joined: Mon Oct 17, 2016 3:11 pm

Re: How to use gpio_isr_register?

Postby jumjum123 » Tue Oct 25, 2016 11:05 am

Thanks a lot for detailled feedback. Even simple things can be very complex :o

User avatar
rudi ;-)
Posts: 1259
Joined: Fri Nov 13, 2015 3:25 pm

Re: How to use gpio_isr_register?

Postby rudi ;-) » Tue Oct 25, 2016 7:53 pm

thank you jeroen for the precise explanation on int.
we start slowly and then step up.
perhabs i have to go back to this point later again.
i will try to try different constellations (edge, level)
and try to see if I notice anything.
due to the number of possible interrupts -have to be counted 76? -
it is possible through this precision to precisely tune.
whether it has an impact :) we will see then :)
thank you so much!
WiFive wrote:
rudi ;-) wrote:
jumjum123 wrote: - what is gpio_pad_select_gpio for ? I'm getting a similiar result without this function
you are right. you need this not if you not use the pads ( example Developer V2 Demo Board has Finger Pads )
No I don't think this has anything to do with finger pads. It is for setting IOMUX. Really means gpio_function_select_gpio. This is for pin (aka pad) that have default function other than gpio.
Ok I agree with you, perhabs i was not detailed enough and has also wrongly justified it.
:?: We can agree that we do not need that "gpio_pad_select_gpio" if the GPIO we want to use is in the first function a GPIO.
and IOMUX is not need? ok?

example from here taken:
GPIO16, GPIO17, GPIO18, GPIO23, are in Function1 Pin List pure GPIO, so IOMUX aka "gpio_pad_select_gpio" ala "gpio_function_select_gpio" is not need.

the detail makes the difference :)
think we have now understand this- thank you WiFive.
it is interesting.
I'm going to drill a bit deeper if there is a difference between equal priority and different kind (edge, level "value"). Times when I will come to. I will feel the time "on the tooth"

@ jumjum123
yes, it is like WiFive spoke. sry for the undetailed unswere in pad. this was my first thinking for "pad" :)
detailed look up, there is a relationship to the PIN LIST and First Function of the GPIO and doing by IOMUX.

ok?
Are we in agreement?

where is the next theme?
:mrgreen:

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Who is online

Users browsing this forum: No registered users and 10 guests