From 5a32ca10ad2288cf1b2d88187353cd80b95c97fb Mon Sep 17 00:00:00 2001 From: Omar Chebib Date: Mon, 5 Feb 2024 16:54:42 +0800 Subject: [PATCH] feat(lp_core): add a public function to get the timer cycle count Closes https://github.com/espressif/esp-idf/issues/13101 --- .../lp_core/shared/include/ulp_lp_core_lp_timer_shared.h | 9 ++++++++- .../ulp/lp_core/shared/ulp_lp_core_lp_timer_shared.c | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/components/ulp/lp_core/shared/include/ulp_lp_core_lp_timer_shared.h b/components/ulp/lp_core/shared/include/ulp_lp_core_lp_timer_shared.h index 284e8d39049e..dda58dc843c5 100644 --- a/components/ulp/lp_core/shared/include/ulp_lp_core_lp_timer_shared.h +++ b/components/ulp/lp_core/shared/include/ulp_lp_core_lp_timer_shared.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -11,6 +11,13 @@ extern "C" { #endif +/** + * @brief Get the number of cycle count for the LP timer + * + * @return current timer cycle count + */ +uint64_t ulp_lp_core_lp_timer_get_cycle_count(void); + /** * @brief Sets the next wakeup alarm * diff --git a/components/ulp/lp_core/shared/ulp_lp_core_lp_timer_shared.c b/components/ulp/lp_core/shared/ulp_lp_core_lp_timer_shared.c index 32a7690f7ff9..ff1c4edc9788 100644 --- a/components/ulp/lp_core/shared/ulp_lp_core_lp_timer_shared.c +++ b/components/ulp/lp_core/shared/ulp_lp_core_lp_timer_shared.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -21,7 +21,7 @@ static void lp_timer_hal_set_alarm_target(uint64_t value) lp_timer_ll_set_target_enable(lp_timer_context.dev, TIMER_ID, true); } -static uint64_t lp_timer_hal_get_cycle_count(void) +uint64_t ulp_lp_core_lp_timer_get_cycle_count(void) { lp_timer_ll_counter_snapshot(lp_timer_context.dev); @@ -38,7 +38,7 @@ static uint64_t lp_timer_hal_get_cycle_count(void) void ulp_lp_core_lp_timer_set_wakeup_time(uint64_t sleep_duration_us) { - uint64_t cycle_cnt = lp_timer_hal_get_cycle_count(); + uint64_t cycle_cnt = ulp_lp_core_lp_timer_get_cycle_count(); uint64_t alarm_target = cycle_cnt + sleep_duration_us * (1 << RTC_CLK_CAL_FRACT) / clk_ll_rtc_slow_load_cal(); lp_timer_hal_set_alarm_target(alarm_target);