From b5e979d58fda80c48e17cd4276432e4885744804 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 14 Dec 2016 13:30:07 -0600 Subject: [PATCH] ESP32: Fix a couple of bugs associated with handling of CPU interrupts. --- arch/xtensa/include/esp32/irq.h | 8 ++++---- arch/xtensa/src/esp32/esp32_cpuint.c | 12 ++++++++---- arch/xtensa/src/esp32/esp32_serial.c | 6 ++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/arch/xtensa/include/esp32/irq.h b/arch/xtensa/include/esp32/irq.h index 4c8e6c47ca..a3cbab72c1 100644 --- a/arch/xtensa/include/esp32/irq.h +++ b/arch/xtensa/include/esp32/irq.h @@ -378,7 +378,7 @@ #define ESP32_CPUINT_NEDGEPERIPHS 4 #define EPS32_CPUINT_EDGESET 0x50400400 -#define ESP32_CPUINT_NNMIPERIPHS 4 +#define ESP32_CPUINT_NNMIPERIPHS 1 #define EPS32_CPUINT_NMISET 0x00004000 #define ESP32_CPUINT_TIMER0 6 @@ -388,11 +388,11 @@ #define ESP32_CPUINT_TIMER2 16 #define ESP32_CPUINT_SOFTWARE1 29 -#define ESP32_CPUINT_NINTERNAL 5 +#define ESP32_CPUINT_NINTERNAL 6 #define ESP32_CPUINT_MAX 31 -#define EPS32_CPUINT_PERIPHSET 0xdffe6f3f -#define EPS32_CPUINT_INTERNALSET 0x200180c0 +#define EPS32_CPUINT_PERIPHSET 0xdffe773f +#define EPS32_CPUINT_INTERNALSET 0x200188c0 /* Priority 1: 0-10, 12-13, 17-18 (15) * Priority 2: 19-21 (3) diff --git a/arch/xtensa/src/esp32/esp32_cpuint.c b/arch/xtensa/src/esp32/esp32_cpuint.c index 571c7fd074..2324e7fe3c 100644 --- a/arch/xtensa/src/esp32/esp32_cpuint.c +++ b/arch/xtensa/src/esp32/esp32_cpuint.c @@ -165,9 +165,11 @@ static uint32_t g_intenable[1]; #endif -/* Bitsets for free, unallocated CPU interrupts */ +/* Bitsets for free, unallocated CPU interrupts available to peripheral + * devices. + */ -static uint32_t g_free_cpuints = 0xffffffff; +static uint32_t g_free_cpuints = EPS32_CPUINT_PERIPHSET; /* Bitsets for each interrupt priority 1-5 */ @@ -188,7 +190,9 @@ static const uint32_t g_priority[5] = * Name: esp32_alloc_cpuint * * Description: - * Allocate a CPU interrupt + * Allocate a CPU interrupt for a peripheral device. This function will + * not allocate any of the pre-allocated CPU interrupts for internal + * devices. * * Input Parameters: * intmask - mask of candidate CPU interrupts. The CPU interrupt will be @@ -224,7 +228,7 @@ int esp32_alloc_cpuint(uint32_t intmask) */ for (cpuint = 0, bitmask = 0xff; - cpuint <= ESP32_CPUINT_MAX; + cpuint <= ESP32_CPUINT_MAX && (intset & bitmask) == 0; cpuint += 8, bitmask <<= 8); /* Search for an unallocated CPU interrupt number in the remaining diff --git a/arch/xtensa/src/esp32/esp32_serial.c b/arch/xtensa/src/esp32/esp32_serial.c index 34846e89e8..36c66dcc09 100644 --- a/arch/xtensa/src/esp32/esp32_serial.c +++ b/arch/xtensa/src/esp32/esp32_serial.c @@ -455,8 +455,8 @@ static void esp32_disableallints(struct esp32_dev_s *priv, uint32_t *intena) static int esp32_setup(struct uart_dev_s *dev) { - struct esp32_dev_s *priv = (struct esp32_dev_s *)dev->priv; #ifndef CONFIG_SUPPRESS_UART_CONFIG + struct esp32_dev_s *priv = (struct esp32_dev_s *)dev->priv; uint32_t clkdiv; uint32_t regval; uint32_t conf0; @@ -655,7 +655,9 @@ static int esp32_attach(struct uart_dev_s *dev) priv->cpuint = esp32_alloc_levelint(1); if (priv->cpuint < 0) { - ret = priv->cpuint; + /* Failed to allocate a CPU interrupt of this type */ + + return priv->cpuint; } /* Set up to receive peripheral interrupts on the current CPU */