Change Pin Interrupt Allocator

This commit is contained in:
me-no-dev 2017-09-28 12:27:10 +08:00
parent 28b7b4e287
commit 7991161f06

View File

@ -24,8 +24,6 @@
#include "soc/gpio_struct.h" #include "soc/gpio_struct.h"
#include "soc/rtc_io_reg.h" #include "soc/rtc_io_reg.h"
#define ETS_GPIO_INUM 12
const int8_t esp32_adc2gpio[20] = {36, -1, -1, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26}; const int8_t esp32_adc2gpio[20] = {36, -1, -1, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26};
const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={ const DRAM_ATTR esp32_gpioMux_t esp32_gpioMux[GPIO_PIN_COUNT]={
@ -193,6 +191,7 @@ extern int IRAM_ATTR __digitalRead(uint8_t pin)
return 0; return 0;
} }
static intr_handle_t gpio_intr_handle = NULL;
static void IRAM_ATTR __onPinInterrupt(void *arg) static void IRAM_ATTR __onPinInterrupt(void *arg)
{ {
@ -229,38 +228,29 @@ static void IRAM_ATTR __onPinInterrupt(void *arg)
extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type) extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int intr_type)
{ {
static bool interrupt_initialized = false; static bool interrupt_initialized = false;
static int core_id = 0;
if(!interrupt_initialized) { if(!interrupt_initialized) {
interrupt_initialized = true; interrupt_initialized = true;
core_id = xPortGetCoreID(); esp_intr_alloc(ETS_GPIO_INTR_SOURCE, (int)ESP_INTR_FLAG_IRAM, __onPinInterrupt, NULL, &gpio_intr_handle);
ESP_INTR_DISABLE(ETS_GPIO_INUM);
intr_matrix_set(core_id, ETS_GPIO_INTR_SOURCE, ETS_GPIO_INUM);
xt_set_interrupt_handler(ETS_GPIO_INUM, &__onPinInterrupt, NULL);
ESP_INTR_ENABLE(ETS_GPIO_INUM);
} }
__pinInterruptHandlers[pin] = userFunc; __pinInterruptHandlers[pin] = userFunc;
//lock gpio esp_intr_disable(gpio_intr_handle);
ESP_INTR_DISABLE(ETS_GPIO_INUM); if(esp_intr_get_cpu(gpio_intr_handle)) { //APP_CPU
if(core_id) { //APP_CPU
GPIO.pin[pin].int_ena = 1; GPIO.pin[pin].int_ena = 1;
} else { //PRO_CPU } else { //PRO_CPU
GPIO.pin[pin].int_ena = 4; GPIO.pin[pin].int_ena = 4;
} }
GPIO.pin[pin].int_type = intr_type; GPIO.pin[pin].int_type = intr_type;
ESP_INTR_ENABLE(ETS_GPIO_INUM); esp_intr_enable(gpio_intr_handle);
//unlock gpio
} }
extern void __detachInterrupt(uint8_t pin) extern void __detachInterrupt(uint8_t pin)
{ {
//lock gpio esp_intr_disable(gpio_intr_handle);
ESP_INTR_DISABLE(ETS_GPIO_INUM);
__pinInterruptHandlers[pin] = NULL; __pinInterruptHandlers[pin] = NULL;
GPIO.pin[pin].int_ena = 0; GPIO.pin[pin].int_ena = 0;
GPIO.pin[pin].int_type = 0; GPIO.pin[pin].int_type = 0;
ESP_INTR_ENABLE(ETS_GPIO_INUM); esp_intr_enable(gpio_intr_handle);
//unlock gpio
} }