From e673817530f2da98183fa97adb0d6291fdb6e12b Mon Sep 17 00:00:00 2001 From: suda-morris <362953310@qq.com> Date: Wed, 20 Nov 2019 23:46:28 +0800 Subject: [PATCH 1/2] ccomp_timer: fix broken unit test --- components/esp32/test/test_intr_alloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/esp32/test/test_intr_alloc.c b/components/esp32/test/test_intr_alloc.c index a372675dd..2b0b63fd8 100644 --- a/components/esp32/test/test_intr_alloc.c +++ b/components/esp32/test/test_intr_alloc.c @@ -214,15 +214,15 @@ TEST_CASE("Can allocate IRAM int only with an IRAM handler", "[esp32]") { } intr_handle_t ih; - esp_err_t err = esp_intr_alloc(ETS_INTERNAL_PROFILING_INTR_SOURCE, + esp_err_t err = esp_intr_alloc(ETS_INTERNAL_SW0_INTR_SOURCE, ESP_INTR_FLAG_IRAM, &dummy, NULL, &ih); TEST_ASSERT_EQUAL_INT(ESP_ERR_INVALID_ARG, err); - err = esp_intr_alloc(ETS_INTERNAL_PROFILING_INTR_SOURCE, + err = esp_intr_alloc(ETS_INTERNAL_SW0_INTR_SOURCE, ESP_INTR_FLAG_IRAM, &dummy_iram, NULL, &ih); TEST_ESP_OK(err); err = esp_intr_free(ih); TEST_ESP_OK(err); - err = esp_intr_alloc(ETS_INTERNAL_PROFILING_INTR_SOURCE, + err = esp_intr_alloc(ETS_INTERNAL_SW0_INTR_SOURCE, ESP_INTR_FLAG_IRAM, &dummy_rtc, NULL, &ih); TEST_ESP_OK(err); err = esp_intr_free(ih); From 6540877f23c83b6089ecb7a889fefd2e89a4abd2 Mon Sep 17 00:00:00 2001 From: Renz Christian Bagaporo Date: Thu, 21 Nov 2019 11:59:46 +0800 Subject: [PATCH 2/2] test_utils: move ccomp timer interrupt allocation/free to init/deinit --- .../components/test_utils/ccomp_timer_impl.c | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/tools/unit-test-app/components/test_utils/ccomp_timer_impl.c b/tools/unit-test-app/components/test_utils/ccomp_timer_impl.c index ac35a59fc..5eed28abf 100644 --- a/tools/unit-test-app/components/test_utils/ccomp_timer_impl.c +++ b/tools/unit-test-app/components/test_utils/ccomp_timer_impl.c @@ -126,29 +126,17 @@ static void set_perfmon_interrupt(bool enable) eri_write(ERI_PERFMON_PMCTRL0 + I_STALL_COUNTER_ID * sizeof(int32_t), i_pmctrl); } -static void intr_alloc(void* params) -{ - int *id = (int*) params; - // Keep track of how many times each counter has overflowed. - esp_intr_alloc(ETS_INTERNAL_PROFILING_INTR_SOURCE, 0, - perf_counter_overflow_handler, NULL, &s_status[*id].intr_handle); -} - -// Linker seems to be smart enough to drop this if ccomp_timer APIs are not used. -static __attribute__((constructor)) void ccomp_timer_impl_start_init(void) -{ -#if !CONFIG_FREERTOS_UNICORE - for (int i = 0; i < portNUM_PROCESSORS; i++) { - esp_ipc_call_blocking(i, intr_alloc, &i); - } -#else - int i = 0; - intr_alloc(&i); -#endif -} esp_err_t ccomp_timer_impl_init(void) { + // Keep track of how many times each counter has overflowed. + esp_err_t err = esp_intr_alloc(ETS_INTERNAL_PROFILING_INTR_SOURCE, 0, + perf_counter_overflow_handler, NULL, &s_status[xPortGetCoreID()].intr_handle); + + if (err != ESP_OK) { + return err; + } + xtensa_perfmon_init(D_STALL_COUNTER_ID, XTPERF_CNT_D_STALL, XTPERF_MASK_D_STALL_BUSY, 0, -1); @@ -164,6 +152,13 @@ esp_err_t ccomp_timer_impl_init(void) esp_err_t ccomp_timer_impl_deinit(void) { set_perfmon_interrupt(false); + + esp_err_t err = esp_intr_free(s_status[xPortGetCoreID()].intr_handle); + + if (err != ESP_OK) { + return err; + } + s_status[xPortGetCoreID()].intr_handle = NULL; s_status[xPortGetCoreID()].state = PERF_TIMER_UNINIT; return ESP_OK;