From bedeedafec57870fcfb4b45538c4a65714dc8dce Mon Sep 17 00:00:00 2001 From: morris Date: Mon, 13 Jul 2026 15:32:50 +0800 Subject: [PATCH] refactor(etm): move ETM retention info from HAL to driver layer Move soc_etm_retention_desc_t type definition and soc_etm_retention_info data from hal component to esp_hw_support component, following the pattern of other peripheral retention data (e.g. MWDT). - Create esp_private/etm_retention.h with type and extern declaration - Create port//etm_retention.c for each target with retention data - Remove hal//etm_periph.c and hal/include/hal/etm_periph.h - Update esp_etm.c to include the new header - Update CMakeLists.txt in both components --- components/esp_hw_support/CMakeLists.txt | 3 ++ components/esp_hw_support/etm/esp_etm.c | 2 +- .../include/esp_private/etm_retention.h} | 4 +- .../port/esp32c5/etm_retention.c} | 2 +- .../port/esp32c6/etm_retention.c} | 2 +- .../port/esp32c61/etm_retention.c} | 2 +- .../port/esp32h2/etm_retention.c} | 2 +- .../port/esp32h21/etm_retention.c} | 8 ++-- .../port/esp32h4/etm_retention.c | 44 +++++++++++++++++++ .../port/esp32p4/etm_retention.c} | 2 +- .../port/esp32s31/etm_retention.c | 44 +++++++++++++++++++ .../main/test_etm_core.c | 2 +- components/hal/CMakeLists.txt | 2 +- components/hal/esp32h4/etm_periph.c | 44 ------------------- components/hal/esp32s31/etm_periph.c | 44 ------------------- 15 files changed, 104 insertions(+), 103 deletions(-) rename components/{hal/include/hal/etm_periph.h => esp_hw_support/include/esp_private/etm_retention.h} (93%) rename components/{hal/esp32c5/etm_periph.c => esp_hw_support/port/esp32c5/etm_retention.c} (98%) rename components/{hal/esp32c6/etm_periph.c => esp_hw_support/port/esp32c6/etm_retention.c} (98%) rename components/{hal/esp32c61/etm_periph.c => esp_hw_support/port/esp32c61/etm_retention.c} (98%) rename components/{hal/esp32h2/etm_periph.c => esp_hw_support/port/esp32h2/etm_retention.c} (98%) rename components/{hal/esp32h21/etm_periph.c => esp_hw_support/port/esp32h21/etm_retention.c} (91%) create mode 100644 components/esp_hw_support/port/esp32h4/etm_retention.c rename components/{hal/esp32p4/etm_periph.c => esp_hw_support/port/esp32p4/etm_retention.c} (98%) create mode 100644 components/esp_hw_support/port/esp32s31/etm_retention.c delete mode 100644 components/hal/esp32h4/etm_periph.c delete mode 100644 components/hal/esp32s31/etm_periph.c diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index cc095962784..731b6d3648a 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -112,6 +112,9 @@ if(NOT non_os_build) if(CONFIG_SOC_ETM_SUPPORTED) list(APPEND srcs "etm/esp_etm.c") + if(CONFIG_SOC_PAU_SUPPORTED) + list(APPEND srcs "port/${target}/etm_retention.c") + endif() endif() if(CONFIG_SOC_PAU_SUPPORTED) diff --git a/components/esp_hw_support/etm/esp_etm.c b/components/esp_hw_support/etm/esp_etm.c index 8bb34071ae2..87a14f608ab 100644 --- a/components/esp_hw_support/etm/esp_etm.c +++ b/components/esp_hw_support/etm/esp_etm.c @@ -16,7 +16,7 @@ #endif #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "hal/etm_periph.h" +#include "etm_retention.h" #include "esp_log.h" #include "esp_check.h" #include "esp_heap_caps.h" diff --git a/components/hal/include/hal/etm_periph.h b/components/esp_hw_support/include/esp_private/etm_retention.h similarity index 93% rename from components/hal/include/hal/etm_periph.h rename to components/esp_hw_support/include/esp_private/etm_retention.h index cdaa6c6bbde..69f622e82e7 100644 --- a/components/hal/include/hal/etm_periph.h +++ b/components/esp_hw_support/include/esp_private/etm_retention.h @@ -9,11 +9,9 @@ #include #include "soc/soc_caps.h" #include "soc/regdma.h" - #if SOC_HAS(ETM) #include "hal/etm_ll.h" #endif - #if SOC_HAS(PAU) #include "soc/retention_periph_defs.h" #endif @@ -22,7 +20,7 @@ extern "C" { #endif -#if SOC_HAS(PAU) && SOC_ETM_SUPPORT_SLEEP_RETENTION +#if SOC_HAS(PAU) typedef struct { periph_retention_module_t module; // ID of the ETM as a retention module diff --git a/components/hal/esp32c5/etm_periph.c b/components/esp_hw_support/port/esp32c5/etm_retention.c similarity index 98% rename from components/hal/esp32c5/etm_periph.c rename to components/esp_hw_support/port/esp32c5/etm_retention.c index afc54dbc54e..509dc5139ca 100644 --- a/components/hal/esp32c5/etm_periph.c +++ b/components/esp_hw_support/port/esp32c5/etm_retention.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "hal/etm_periph.h" +#include "etm_retention.h" #include "soc/soc_etm_reg.h" /** diff --git a/components/hal/esp32c6/etm_periph.c b/components/esp_hw_support/port/esp32c6/etm_retention.c similarity index 98% rename from components/hal/esp32c6/etm_periph.c rename to components/esp_hw_support/port/esp32c6/etm_retention.c index afc54dbc54e..509dc5139ca 100644 --- a/components/hal/esp32c6/etm_periph.c +++ b/components/esp_hw_support/port/esp32c6/etm_retention.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "hal/etm_periph.h" +#include "etm_retention.h" #include "soc/soc_etm_reg.h" /** diff --git a/components/hal/esp32c61/etm_periph.c b/components/esp_hw_support/port/esp32c61/etm_retention.c similarity index 98% rename from components/hal/esp32c61/etm_periph.c rename to components/esp_hw_support/port/esp32c61/etm_retention.c index afc54dbc54e..509dc5139ca 100644 --- a/components/hal/esp32c61/etm_periph.c +++ b/components/esp_hw_support/port/esp32c61/etm_retention.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "hal/etm_periph.h" +#include "etm_retention.h" #include "soc/soc_etm_reg.h" /** diff --git a/components/hal/esp32h2/etm_periph.c b/components/esp_hw_support/port/esp32h2/etm_retention.c similarity index 98% rename from components/hal/esp32h2/etm_periph.c rename to components/esp_hw_support/port/esp32h2/etm_retention.c index afc54dbc54e..509dc5139ca 100644 --- a/components/hal/esp32h2/etm_periph.c +++ b/components/esp_hw_support/port/esp32h2/etm_retention.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "hal/etm_periph.h" +#include "etm_retention.h" #include "soc/soc_etm_reg.h" /** diff --git a/components/hal/esp32h21/etm_periph.c b/components/esp_hw_support/port/esp32h21/etm_retention.c similarity index 91% rename from components/hal/esp32h21/etm_periph.c rename to components/esp_hw_support/port/esp32h21/etm_retention.c index 88496453b70..4a96fafee30 100644 --- a/components/hal/esp32h21/etm_periph.c +++ b/components/esp_hw_support/port/esp32h21/etm_retention.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "hal/etm_periph.h" +#include "etm_retention.h" #include "soc/soc_etm_reg.h" /** @@ -19,19 +19,19 @@ static const regdma_entries_config_t etm_regdma_entries[] = { [0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x00), SOC_ETM_CH_ENA_AD0_REG, SOC_ETM_CH_ENA_AD0_SET_REG, 1, 0, 0), - .owner = ENTRY(0) | ENTRY(2), + .owner = ENTRY(0), }, [1] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x01), SOC_ETM_CH_ENA_AD1_REG, SOC_ETM_CH_ENA_AD1_SET_REG, 1, 0, 0), - .owner = ENTRY(0) | ENTRY(2), + .owner = ENTRY(0), }, // backup stage: save configuration registers // restore stage: restore the configuration registers [2] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x02), SOC_ETM_CH0_EVT_ID_REG, SOC_ETM_CH0_EVT_ID_REG, ETM_RETENTION_REGS_CNT, 0, 0), - .owner = ENTRY(0) | ENTRY(2), + .owner = ENTRY(0), }, }; diff --git a/components/esp_hw_support/port/esp32h4/etm_retention.c b/components/esp_hw_support/port/esp32h4/etm_retention.c new file mode 100644 index 00000000000..509dc5139ca --- /dev/null +++ b/components/esp_hw_support/port/esp32h4/etm_retention.c @@ -0,0 +1,44 @@ +/* + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "etm_retention.h" +#include "soc/soc_etm_reg.h" + +/** + * ETM Registers to be saved during sleep retention + * - Channel configuration registers, e.g.: SOC_ETM_CH0_EVT_ID_REG, SOC_ETM_CH0_TASK_ID_REG +*/ +#define ETM_RETENTION_REGS_CNT ((SOC_ETM_CH49_TASK_ID_REG - SOC_ETM_CH0_EVT_ID_REG) / 4 + 1) + +static const regdma_entries_config_t etm_regdma_entries[] = { + // backup stage: save the status of enabled channels + // restore stage: store the enabled channels + [0] = { + .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x00), + SOC_ETM_CH_ENA_AD0_REG, SOC_ETM_CH_ENA_AD0_SET_REG, 1, 0, 0), + .owner = ENTRY(0) | ENTRY(2), + }, + [1] = { + .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x01), + SOC_ETM_CH_ENA_AD1_REG, SOC_ETM_CH_ENA_AD1_SET_REG, 1, 0, 0), + .owner = ENTRY(0) | ENTRY(2), + }, + // backup stage: save configuration registers + // restore stage: restore the configuration registers + [2] = { + .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x02), + SOC_ETM_CH0_EVT_ID_REG, SOC_ETM_CH0_EVT_ID_REG, ETM_RETENTION_REGS_CNT, 0, 0), + .owner = ENTRY(0) | ENTRY(2), + }, +}; + +const soc_etm_retention_desc_t soc_etm_retention_info[1] = { + [0] = { + .module = SLEEP_RETENTION_MODULE_ETM0, + .regdma_entry_array = etm_regdma_entries, + .array_size = ARRAY_SIZE(etm_regdma_entries) + }, +}; diff --git a/components/hal/esp32p4/etm_periph.c b/components/esp_hw_support/port/esp32p4/etm_retention.c similarity index 98% rename from components/hal/esp32p4/etm_periph.c rename to components/esp_hw_support/port/esp32p4/etm_retention.c index bcc91bf6690..e20bed2755d 100644 --- a/components/hal/esp32p4/etm_periph.c +++ b/components/esp_hw_support/port/esp32p4/etm_retention.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "hal/etm_periph.h" +#include "etm_retention.h" #include "soc/soc_etm_reg.h" /** diff --git a/components/esp_hw_support/port/esp32s31/etm_retention.c b/components/esp_hw_support/port/esp32s31/etm_retention.c new file mode 100644 index 00000000000..e39706a036a --- /dev/null +++ b/components/esp_hw_support/port/esp32s31/etm_retention.c @@ -0,0 +1,44 @@ +/* + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "etm_retention.h" +#include "soc/soc_etm_reg.h" + +/** + * ETM Registers to be saved during sleep retention + * - Channel configuration registers, e.g.: SOC_ETM_CH0_EVT_ID_REG, SOC_ETM_CH0_TASK_ID_REG +*/ +#define ETM_RETENTION_REGS_CNT ((SOC_ETM_CH49_TASK_ID_REG - SOC_ETM_CH0_EVT_ID_REG) / 4 + 1) + +static const regdma_entries_config_t etm_regdma_entries[] = { + // backup stage: save the status of enabled channels + // restore stage: store the enabled channels + [0] = { + .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x00), + SOC_ETM_CH_ENA_AD0_REG, SOC_ETM_CH_ENA_AD0_SET_REG, 1, 0, 0), + .owner = ENTRY(0) | ENTRY(2), + }, + [1] = { + .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x01), + SOC_ETM_CH_ENA_AD1_REG, SOC_ETM_CH_ENA_AD1_SET_REG, 1, 0, 0), + .owner = ENTRY(0) | ENTRY(2), + }, + // backup stage: save configuration registers + // restore stage: restore the configuration registers + [2] = { + .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x02), + SOC_ETM_CH0_EVT_ID_REG, SOC_ETM_CH0_EVT_ID_REG, ETM_RETENTION_REGS_CNT, 0, 0), + .owner = ENTRY(0) | ENTRY(2), + }, +}; + +const soc_etm_retention_desc_t soc_etm_retention_info[1] = { + [0] = { + .module = SLEEP_RETENTION_MODULE_ETM0, + .regdma_entry_array = etm_regdma_entries, + .array_size = ARRAY_SIZE(etm_regdma_entries) + }, +}; diff --git a/components/esp_hw_support/test_apps/esp_hw_support_unity_tests/main/test_etm_core.c b/components/esp_hw_support/test_apps/esp_hw_support_unity_tests/main/test_etm_core.c index 2b515210eee..c28fb9b024c 100644 --- a/components/esp_hw_support/test_apps/esp_hw_support_unity_tests/main/test_etm_core.c +++ b/components/esp_hw_support/test_apps/esp_hw_support_unity_tests/main/test_etm_core.c @@ -10,7 +10,7 @@ #include "freertos/task.h" #include "unity.h" #include "esp_etm.h" -#include "hal/etm_periph.h" +#include "hal/etm_ll.h" TEST_CASE("etm_channel_install_uninstall", "[etm]") { diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index f9ab4e27f0c..e5c599455e2 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -38,7 +38,7 @@ if(NOT esp_tee_build AND NOT BOOTLOADER_BUILD) list(APPEND srcs "color_hal.c") if(CONFIG_SOC_ETM_SUPPORTED) - list(APPEND srcs "etm_hal.c" "${target}/etm_periph.c") + list(APPEND srcs "etm_hal.c") endif() if(CONFIG_SOC_MODEM_CLOCK_IS_INDEPENDENT AND CONFIG_SOC_MODEM_CLOCK_SUPPORTED) diff --git a/components/hal/esp32h4/etm_periph.c b/components/hal/esp32h4/etm_periph.c deleted file mode 100644 index 88496453b70..00000000000 --- a/components/hal/esp32h4/etm_periph.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "hal/etm_periph.h" -#include "soc/soc_etm_reg.h" - -/** - * ETM Registers to be saved during sleep retention - * - Channel configuration registers, e.g.: SOC_ETM_CH0_EVT_ID_REG, SOC_ETM_CH0_TASK_ID_REG -*/ -#define ETM_RETENTION_REGS_CNT ((SOC_ETM_CH49_TASK_ID_REG - SOC_ETM_CH0_EVT_ID_REG) / 4 + 1) - -static const regdma_entries_config_t etm_regdma_entries[] = { - // backup stage: save the status of enabled channels - // restore stage: store the enabled channels - [0] = { - .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x00), - SOC_ETM_CH_ENA_AD0_REG, SOC_ETM_CH_ENA_AD0_SET_REG, 1, 0, 0), - .owner = ENTRY(0) | ENTRY(2), - }, - [1] = { - .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x01), - SOC_ETM_CH_ENA_AD1_REG, SOC_ETM_CH_ENA_AD1_SET_REG, 1, 0, 0), - .owner = ENTRY(0) | ENTRY(2), - }, - // backup stage: save configuration registers - // restore stage: restore the configuration registers - [2] = { - .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x02), - SOC_ETM_CH0_EVT_ID_REG, SOC_ETM_CH0_EVT_ID_REG, ETM_RETENTION_REGS_CNT, 0, 0), - .owner = ENTRY(0) | ENTRY(2), - }, -}; - -const soc_etm_retention_desc_t soc_etm_retention_info[1] = { - [0] = { - .module = SLEEP_RETENTION_MODULE_ETM0, - .regdma_entry_array = etm_regdma_entries, - .array_size = ARRAY_SIZE(etm_regdma_entries) - }, -}; diff --git a/components/hal/esp32s31/etm_periph.c b/components/hal/esp32s31/etm_periph.c deleted file mode 100644 index e0c6988c30a..00000000000 --- a/components/hal/esp32s31/etm_periph.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "hal/etm_periph.h" -#include "soc/soc_etm_reg.h" - -/** - * ETM Registers to be saved during sleep retention - * - Channel configuration registers, e.g.: SOC_ETM_CH0_EVT_ID_REG, SOC_ETM_CH0_TASK_ID_REG - */ -#define ETM_RETENTION_REGS_CNT ((SOC_ETM_CH49_TASK_ID_REG - SOC_ETM_CH0_EVT_ID_REG) / 4 + 1) - -static const regdma_entries_config_t etm_regdma_entries[] = { - // backup stage: save the status of enabled channels - // restore stage: store the enabled channels - [0] = { - .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x00), - SOC_ETM_CH_ENA_AD0_REG, SOC_ETM_CH_ENA_AD0_SET_REG, 1, 0, 0), - .owner = ENTRY(0) | ENTRY(2), - }, - [1] = { - .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x01), - SOC_ETM_CH_ENA_AD1_REG, SOC_ETM_CH_ENA_AD1_SET_REG, 1, 0, 0), - .owner = ENTRY(0) | ENTRY(2), - }, - // backup stage: save configuration registers - // restore stage: restore the configuration registers - [2] = { - .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_ETM_LINK(0x02), - SOC_ETM_CH0_EVT_ID_REG, SOC_ETM_CH0_EVT_ID_REG, ETM_RETENTION_REGS_CNT, 0, 0), - .owner = ENTRY(0) | ENTRY(2), - }, -}; - -const soc_etm_retention_desc_t soc_etm_retention_info[1] = { - [0] = { - .module = SLEEP_RETENTION_MODULE_ETM0, - .regdma_entry_array = etm_regdma_entries, - .array_size = ARRAY_SIZE(etm_regdma_entries) - }, -};