From 01fb28b65bb9fb485c50a24acfaaefece6ec907d Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Tue, 13 Jun 2023 20:36:28 +0800 Subject: [PATCH] Power Management: move lp_timer_hal.c to upper hal layer for esp32h2 and esp32c6 --- components/hal/CMakeLists.txt | 6 +-- .../hal/esp32h2/include/hal/lp_timer_hal.h | 45 ------------------ components/hal/esp32h2/lp_timer_hal.c | 46 ------------------- .../{esp32c6 => }/include/hal/lp_timer_hal.h | 3 +- components/hal/{esp32c6 => }/lp_timer_hal.c | 0 5 files changed, 2 insertions(+), 98 deletions(-) delete mode 100644 components/hal/esp32h2/include/hal/lp_timer_hal.h delete mode 100644 components/hal/esp32h2/lp_timer_hal.c rename components/hal/{esp32c6 => }/include/hal/lp_timer_hal.h (91%) rename components/hal/{esp32c6 => }/lp_timer_hal.c (100%) diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 1c6997902c..8ceb53b3aa 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -30,10 +30,6 @@ if(NOT CONFIG_APP_BUILD_TYPE_PURE_RAM_APP) endif() endif() -if(${target} STREQUAL "esp32c6") - list(APPEND srcs "esp32c6/lp_timer_hal.c") -endif() - if(NOT BOOTLOADER_BUILD) list(APPEND srcs "rtc_io_hal.c" @@ -143,7 +139,7 @@ if(NOT BOOTLOADER_BUILD) endif() if(CONFIG_SOC_LP_TIMER_SUPPORTED) - list(APPEND srcs "${target}/lp_timer_hal.c") + list(APPEND srcs "lp_timer_hal.c") endif() if(CONFIG_SOC_PAU_SUPPORTED) diff --git a/components/hal/esp32h2/include/hal/lp_timer_hal.h b/components/hal/esp32h2/include/hal/lp_timer_hal.h deleted file mode 100644 index 39fa017ab5..0000000000 --- a/components/hal/esp32h2/include/hal/lp_timer_hal.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include -#include -#include -#include "soc/soc.h" -#include "hal/lp_timer_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * @brief set alarm target value - * - * @param timer_id timer num of lp_timer, 0 or 1 for esp32h2 - * - * @param value when counter reaches alarm value, alarm event will be triggered - */ -void lp_timer_hal_set_alarm_target(uint8_t timer_id, uint64_t value); - -/** - * @brief get current counter value - */ -uint64_t lp_timer_hal_get_cycle_count(void); - -/** - * @brief clear alarm interrupt status - */ -void lp_timer_hal_clear_alarm_intr_status(void); - -/** - * @brief clear overflow interrupt status - */ -void lp_timer_hal_clear_overflow_intr_status(void); - -#ifdef __cplusplus -} -#endif diff --git a/components/hal/esp32h2/lp_timer_hal.c b/components/hal/esp32h2/lp_timer_hal.c deleted file mode 100644 index c27e7bcc2d..0000000000 --- a/components/hal/esp32h2/lp_timer_hal.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include "sdkconfig.h" -#include "esp_attr.h" -#include "soc/soc.h" -#include "hal/lp_timer_ll.h" - -static DRAM_ATTR struct { - lp_timer_dev_t *dev; -} lp_timer_context = { .dev = &LP_TIMER }; - -void IRAM_ATTR lp_timer_hal_set_alarm_target(uint8_t timer_id, uint64_t value) -{ - lp_timer_ll_clear_alarm_intr_status(lp_timer_context.dev); - lp_timer_ll_set_alarm_target(lp_timer_context.dev, timer_id, value); - lp_timer_ll_set_target_enable(lp_timer_context.dev, timer_id, true); -} - -uint64_t IRAM_ATTR lp_timer_hal_get_cycle_count(void) -{ - lp_timer_ll_counter_snapshot(lp_timer_context.dev); - uint32_t lo = lp_timer_ll_get_counter_value_low(lp_timer_context.dev, 0); - uint32_t hi = lp_timer_ll_get_counter_value_high(lp_timer_context.dev, 0); - lp_timer_counter_value_t result = { - .lo = lo, - .hi = hi - }; - return result.val; -} - -void IRAM_ATTR lp_timer_hal_clear_alarm_intr_status(void) -{ - lp_timer_ll_clear_alarm_intr_status(lp_timer_context.dev); -} - -void IRAM_ATTR lp_timer_hal_clear_overflow_intr_status(void) -{ - lp_timer_ll_clear_overflow_intr_status(lp_timer_context.dev); -} diff --git a/components/hal/esp32c6/include/hal/lp_timer_hal.h b/components/hal/include/hal/lp_timer_hal.h similarity index 91% rename from components/hal/esp32c6/include/hal/lp_timer_hal.h rename to components/hal/include/hal/lp_timer_hal.h index 6acc565f51..b9e551c5dd 100644 --- a/components/hal/esp32c6/include/hal/lp_timer_hal.h +++ b/components/hal/include/hal/lp_timer_hal.h @@ -19,7 +19,7 @@ extern "C" { /* * @brief set alarm target value * - * @param timer_id timer num of lp_timer, 0 or 1 for esp32c6 + * @param timer_id timer num of lp_timer, 0 or 1 for esp32c6 and esp32h2 * * @param value when counter reaches alarm value, alarm event will be triggered */ @@ -27,7 +27,6 @@ void lp_timer_hal_set_alarm_target(uint8_t timer_id, uint64_t value); /** * @brief get current counter value - * */ uint64_t lp_timer_hal_get_cycle_count(void); diff --git a/components/hal/esp32c6/lp_timer_hal.c b/components/hal/lp_timer_hal.c similarity index 100% rename from components/hal/esp32c6/lp_timer_hal.c rename to components/hal/lp_timer_hal.c