From 06290d44c3849702cfa74400d141116847f5ceec Mon Sep 17 00:00:00 2001 From: zwl Date: Fri, 25 Nov 2022 12:35:36 +0800 Subject: [PATCH] Fixed interrupt latency when cache is disable on ESP32-C2 --- components/bt/controller/esp32c2/bt.c | 7 +++++-- components/bt/controller/esp32h2/bt.c | 8 ++++++-- components/bt/porting/mem/bt_osi_mem.c | 4 ++-- components/esp_rom/esp32c2/ld/esp32c2.rom.ld | 1 - 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index 80ad5c9068..32b35a5004 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -50,6 +50,8 @@ #include "esp_private/periph_ctrl.h" #include "esp_sleep.h" +#include "soc/syscon_reg.h" +#include "soc/dport_access.h" /* Macro definition ************************************************************************ */ @@ -223,7 +225,8 @@ struct ext_funcs_t ext_funcs_ro = { static void IRAM_ATTR esp_reset_rpa_moudle(void) { - periph_module_reset(PERIPH_MODEM_RPA_MODULE); + DPORT_SET_PERI_REG_MASK(SYSTEM_CORE_RST_EN_REG, BLE_RPA_REST_BIT); + DPORT_CLEAR_PERI_REG_MASK(SYSTEM_CORE_RST_EN_REG, BLE_RPA_REST_BIT); } static void IRAM_ATTR osi_assert_wrapper(const uint32_t ln, const char *fn, uint32_t param1, uint32_t param2) @@ -390,7 +393,7 @@ static int ble_hci_unregistered_hook(void*, void*) static int esp_intr_alloc_wrapper(int source, int flags, intr_handler_t handler, void *arg, void **ret_handle_in) { - int rc = esp_intr_alloc(source, flags, handler, arg, (intr_handle_t *)ret_handle_in); + int rc = esp_intr_alloc(source, flags | ESP_INTR_FLAG_IRAM, handler, arg, (intr_handle_t *)ret_handle_in); return rc; } diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index c0bee51261..797bef6580 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -50,6 +50,9 @@ #include "esp_private/periph_ctrl.h" #include "esp_sleep.h" +#include "soc/syscon_reg.h" +#include "soc/dport_access.h" + /* Macro definition ************************************************************************ */ @@ -216,7 +219,8 @@ struct ext_funcs_t ext_funcs_ro = { static int IRAM_ATTR esp_reset_rpa_moudle(void) { - periph_module_reset(PERIPH_MODEM_RPA_MODULE); + DPORT_SET_PERI_REG_MASK(SYSTEM_MODEM_RST_EN_REG, SYSTEM_BLE_SEC_AAR_RST); + DPORT_CLEAR_PERI_REG_MASK(SYSTEM_MODEM_RST_EN_REG, SYSTEM_BLE_SEC_AAR_RST); return 0; } @@ -385,7 +389,7 @@ static int ble_hci_unregistered_hook(void*, void*) static int esp_intr_alloc_wrapper(int source, int flags, intr_handler_t handler, void *arg, void **ret_handle_in) { - int rc = esp_intr_alloc(source, flags, handler, arg, (intr_handle_t *)ret_handle_in); + int rc = esp_intr_alloc(source, flags | ESP_INTR_FLAG_IRAM, handler, arg, (intr_handle_t *)ret_handle_in); return rc; } diff --git a/components/bt/porting/mem/bt_osi_mem.c b/components/bt/porting/mem/bt_osi_mem.c index 6cdbd20490..69c656dd6a 100644 --- a/components/bt/porting/mem/bt_osi_mem.c +++ b/components/bt/porting/mem/bt_osi_mem.c @@ -36,12 +36,12 @@ IRAM_ATTR void *bt_osi_mem_calloc(size_t n, size_t size) IRAM_ATTR void *bt_osi_mem_malloc_internal(size_t size) { - return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT|MALLOC_CAP_DMA); } IRAM_ATTR void *bt_osi_mem_calloc_internal(size_t n, size_t size) { - return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT|MALLOC_CAP_DMA); } IRAM_ATTR void bt_osi_mem_free(void *ptr) diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld index 40bd047a71..82671e0a54 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld @@ -1364,7 +1364,6 @@ r_get_max_skip = 0x40001950; r_get_peer_id_offset = 0x40001954; r_get_peer_irk_offset = 0x40001958; r_get_peer_rpa_offset = 0x4000195c; -r_hal_rtc_irq_handler = 0x40001964; r_hal_timer_disable_irq = 0x4000196c; r_hal_timer_process = 0x40001978; r_hal_timer_read = 0x4000197c;