From 237aebb7e1f220bac8ba2d84de9d1d431e130f81 Mon Sep 17 00:00:00 2001 From: Abdelatif Guettouche Date: Tue, 17 Aug 2021 20:37:49 +0200 Subject: [PATCH] arch/xtensa/esp32_cpuint.c: Refactor retrieving the intmap and register address of a peripheral. Signed-off-by: Abdelatif Guettouche --- arch/xtensa/src/esp32/esp32_cpuint.c | 56 +++++++++++++++------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/arch/xtensa/src/esp32/esp32_cpuint.c b/arch/xtensa/src/esp32/esp32_cpuint.c index ddd8c3cdee..398ff4740b 100644 --- a/arch/xtensa/src/esp32/esp32_cpuint.c +++ b/arch/xtensa/src/esp32/esp32_cpuint.c @@ -208,6 +208,34 @@ static inline void xtensa_disable_all(void) ); } +/**************************************************************************** + * Name: esp32_intinfo + * + * Description: + * Return the CPU interrupt map of the given CPU and the register map + * of the given peripheral. + * + ****************************************************************************/ + +static void esp32_intinfo(int cpu, int periphid, + uintptr_t *regaddr, uint8_t **intmap) +{ +#ifdef CONFIG_SMP + DEBUGASSERT(cpu >= 0 && cpu < CONFIG_SMP_NCPUS); + + if (cpu != 0) + { + *regaddr = DPORT_APP_MAP_REGADDR(periphid); + *intmap = g_cpu1_intmap; + } + else +#endif + { + *regaddr = DPORT_PRO_MAP_REGADDR(periphid); + *intmap = g_cpu0_intmap; + } +} + /**************************************************************************** * Name: esp32_getcpuint * @@ -531,20 +559,8 @@ int esp32_setup_irq(int cpu, int periphid, int priority, int type) DEBUGASSERT(periphid >= 0 && periphid < ESP32_NPERIPHERALS); DEBUGASSERT(cpuint >= 0 && cpuint <= ESP32_CPUINT_MAX); -#ifdef CONFIG_SMP - DEBUGASSERT(cpu >= 0 && cpu < CONFIG_SMP_NCPUS); - if (cpu != 0) - { - regaddr = DPORT_APP_MAP_REGADDR(periphid); - intmap = g_cpu1_intmap; - } - else -#endif - { - regaddr = DPORT_PRO_MAP_REGADDR(periphid); - intmap = g_cpu0_intmap; - } + esp32_intinfo(cpu, periphid, ®addr, &intmap); DEBUGASSERT(intmap[cpuint] == CPUINT_UNASSIGNED); @@ -598,20 +614,8 @@ void esp32_teardown_irq(int cpu, int periphid, int cpuint) irq = ESP32_PERIPH2IRQ(periphid); DEBUGASSERT(periphid >= 0 && periphid < ESP32_NPERIPHERALS); -#ifdef CONFIG_SMP - DEBUGASSERT(cpu >= 0 && cpu < CONFIG_SMP_NCPUS); - if (cpu != 0) - { - regaddr = DPORT_APP_MAP_REGADDR(periphid); - intmap = g_cpu1_intmap; - } - else -#endif - { - regaddr = DPORT_PRO_MAP_REGADDR(periphid); - intmap = g_cpu0_intmap; - } + esp32_intinfo(cpu, periphid, ®addr, &intmap); DEBUGASSERT(intmap[cpuint] != CPUINT_UNASSIGNED); intmap[cpuint] = CPUINT_UNASSIGNED;