From 81a641d437d3990bf76aa9294c5e12a56807e08e Mon Sep 17 00:00:00 2001 From: morris Date: Sat, 1 Jul 2023 23:12:38 +0800 Subject: [PATCH] feat(gptimer): add gptimer linker.lf to control the placement of driver and hal since the linker placement of the hal functions are controlled by the Kconfig in the driver component, we should create the linker.lf in the driver component, not in the hal component. --- components/driver/CMakeLists.txt | 2 +- components/driver/gptimer/linker.lf | 17 +++++++++++ components/hal/CMakeLists.txt | 2 +- components/hal/esp32/include/hal/timer_ll.h | 2 ++ components/hal/esp32c2/include/hal/timer_ll.h | 2 ++ components/hal/esp32c3/include/hal/timer_ll.h | 2 ++ components/hal/esp32c6/include/hal/timer_ll.h | 2 ++ components/hal/esp32h2/include/hal/timer_ll.h | 2 ++ components/hal/esp32s2/include/hal/timer_ll.h | 2 ++ components/hal/esp32s3/include/hal/timer_ll.h | 2 ++ components/hal/linker.lf | 2 -- components/hal/timer_hal.c | 24 ++++++++++++++- components/hal/timer_hal_iram.c | 30 ------------------- 13 files changed, 56 insertions(+), 35 deletions(-) create mode 100644 components/driver/gptimer/linker.lf delete mode 100644 components/hal/timer_hal_iram.c diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 564814091f1..be80ecc4e73 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -216,7 +216,7 @@ else() INCLUDE_DIRS ${includes} PRIV_REQUIRES efuse esp_timer REQUIRES esp_pm esp_ringbuf freertos soc hal esp_hw_support - LDFRAGMENTS linker.lf) + LDFRAGMENTS linker.lf gptimer/linker.lf) endif() # If system needs to monitor USJ connection status, then usb_serial_jtag_connection_monitor object file has to be linked diff --git a/components/driver/gptimer/linker.lf b/components/driver/gptimer/linker.lf new file mode 100644 index 00000000000..1e80c4b0bda --- /dev/null +++ b/components/driver/gptimer/linker.lf @@ -0,0 +1,17 @@ +[mapping:gptimer_driver] +archive: libdriver.a +entries: + if GPTIMER_CTRL_FUNC_IN_IRAM = y: + gptimer: gptimer_set_raw_count (noflash) + gptimer: gptimer_get_raw_count (noflash) + gptimer: gptimer_get_captured_count (noflash) + gptimer: gptimer_set_alarm_action (noflash) + gptimer: gptimer_start (noflash) + gptimer: gptimer_stop (noflash) + +[mapping:gptimer_hal] +archive: libhal.a +entries: + if GPTIMER_CTRL_FUNC_IN_IRAM = y: + timer_hal: timer_hal_set_counter_value (noflash) + timer_hal: timer_hal_capture_and_get_counter_value (noflash) diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 892a368377b..41624358382 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -59,7 +59,7 @@ if(NOT BOOTLOADER_BUILD) endif() if(CONFIG_SOC_GPTIMER_SUPPORTED) - list(APPEND srcs "timer_hal.c" "timer_hal_iram.c") + list(APPEND srcs "timer_hal.c") endif() if(CONFIG_SOC_LEDC_SUPPORTED) diff --git a/components/hal/esp32/include/hal/timer_ll.h b/components/hal/esp32/include/hal/timer_ll.h index 63ba28801a8..98cf9038f74 100644 --- a/components/hal/esp32/include/hal/timer_ll.h +++ b/components/hal/esp32/include/hal/timer_ll.h @@ -193,6 +193,7 @@ static inline void timer_ll_set_reload_value(timg_dev_t *hw, uint32_t timer_num, * @param timer_num Timer number in the group * @return reload count value */ +__attribute__((always_inline)) static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_num) { return ((uint64_t)hw->hw_timer[timer_num].loadhi.tx_load_hi << 32) | (hw->hw_timer[timer_num].loadlo.tx_load_lo); @@ -204,6 +205,7 @@ static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_ * @param hw Timer Group register base address * @param timer_num Timer number in the group */ +__attribute__((always_inline)) static inline void timer_ll_trigger_soft_reload(timg_dev_t *hw, uint32_t timer_num) { hw->hw_timer[timer_num].load.tx_load = 1; diff --git a/components/hal/esp32c2/include/hal/timer_ll.h b/components/hal/esp32c2/include/hal/timer_ll.h index f77d5fc6417..7336306f713 100644 --- a/components/hal/esp32c2/include/hal/timer_ll.h +++ b/components/hal/esp32c2/include/hal/timer_ll.h @@ -193,6 +193,7 @@ static inline void timer_ll_set_reload_value(timg_dev_t *hw, uint32_t timer_num, * @param timer_num Timer number in the group * @return reload count value */ +__attribute__((always_inline)) static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_num) { return ((uint64_t)hw->hw_timer[timer_num].loadhi.tx_load_hi << 32) | (hw->hw_timer[timer_num].loadlo.tx_load_lo); @@ -204,6 +205,7 @@ static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_ * @param hw Timer Group register base address * @param timer_num Timer number in the group */ +__attribute__((always_inline)) static inline void timer_ll_trigger_soft_reload(timg_dev_t *hw, uint32_t timer_num) { hw->hw_timer[timer_num].load.tx_load = 1; diff --git a/components/hal/esp32c3/include/hal/timer_ll.h b/components/hal/esp32c3/include/hal/timer_ll.h index 2c9ed9395d4..817387cebaf 100644 --- a/components/hal/esp32c3/include/hal/timer_ll.h +++ b/components/hal/esp32c3/include/hal/timer_ll.h @@ -193,6 +193,7 @@ static inline void timer_ll_set_reload_value(timg_dev_t *hw, uint32_t timer_num, * @param timer_num Timer number in the group * @return reload count value */ +__attribute__((always_inline)) static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_num) { return ((uint64_t)hw->hw_timer[timer_num].loadhi.tx_load_hi << 32) | (hw->hw_timer[timer_num].loadlo.tx_load_lo); @@ -204,6 +205,7 @@ static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_ * @param hw Timer Group register base address * @param timer_num Timer number in the group */ +__attribute__((always_inline)) static inline void timer_ll_trigger_soft_reload(timg_dev_t *hw, uint32_t timer_num) { hw->hw_timer[timer_num].load.tx_load = 1; diff --git a/components/hal/esp32c6/include/hal/timer_ll.h b/components/hal/esp32c6/include/hal/timer_ll.h index a9403c4bd48..592cf60e6c3 100644 --- a/components/hal/esp32c6/include/hal/timer_ll.h +++ b/components/hal/esp32c6/include/hal/timer_ll.h @@ -235,6 +235,7 @@ static inline void timer_ll_set_reload_value(timg_dev_t *hw, uint32_t timer_num, * @param timer_num Timer number in the group * @return reload count value */ +__attribute__((always_inline)) static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_num) { return ((uint64_t)hw->hw_timer[timer_num].loadhi.tx_load_hi << 32) | (hw->hw_timer[timer_num].loadlo.tx_load_lo); @@ -246,6 +247,7 @@ static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_ * @param hw Timer Group register base address * @param timer_num Timer number in the group */ +__attribute__((always_inline)) static inline void timer_ll_trigger_soft_reload(timg_dev_t *hw, uint32_t timer_num) { hw->hw_timer[timer_num].load.tx_load = 1; diff --git a/components/hal/esp32h2/include/hal/timer_ll.h b/components/hal/esp32h2/include/hal/timer_ll.h index 70d0e4f8dae..17574d6457d 100644 --- a/components/hal/esp32h2/include/hal/timer_ll.h +++ b/components/hal/esp32h2/include/hal/timer_ll.h @@ -235,6 +235,7 @@ static inline void timer_ll_set_reload_value(timg_dev_t *hw, uint32_t timer_num, * @param timer_num Timer number in the group * @return reload count value */ +__attribute__((always_inline)) static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_num) { return ((uint64_t)hw->hw_timer[timer_num].loadhi.tx_load_hi << 32) | (hw->hw_timer[timer_num].loadlo.tx_load_lo); @@ -246,6 +247,7 @@ static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_ * @param hw Timer Group register base address * @param timer_num Timer number in the group */ +__attribute__((always_inline)) static inline void timer_ll_trigger_soft_reload(timg_dev_t *hw, uint32_t timer_num) { hw->hw_timer[timer_num].load.tx_load = 1; diff --git a/components/hal/esp32s2/include/hal/timer_ll.h b/components/hal/esp32s2/include/hal/timer_ll.h index 42daa564e3f..f50a27cb2b2 100644 --- a/components/hal/esp32s2/include/hal/timer_ll.h +++ b/components/hal/esp32s2/include/hal/timer_ll.h @@ -197,6 +197,7 @@ static inline void timer_ll_set_reload_value(timg_dev_t *hw, uint32_t timer_num, * @param timer_num Timer number in the group * @return reload count value */ +__attribute__((always_inline)) static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_num) { return ((uint64_t)hw->hw_timer[timer_num].loadhi.tx_load_hi << 32) | (hw->hw_timer[timer_num].loadlo.tx_load_lo); @@ -208,6 +209,7 @@ static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_ * @param hw Timer Group register base address * @param timer_num Timer number in the group */ +__attribute__((always_inline)) static inline void timer_ll_trigger_soft_reload(timg_dev_t *hw, uint32_t timer_num) { hw->hw_timer[timer_num].load.tx_load = 1; diff --git a/components/hal/esp32s3/include/hal/timer_ll.h b/components/hal/esp32s3/include/hal/timer_ll.h index f6bebcceea2..f72a67efe62 100644 --- a/components/hal/esp32s3/include/hal/timer_ll.h +++ b/components/hal/esp32s3/include/hal/timer_ll.h @@ -196,6 +196,7 @@ static inline void timer_ll_set_reload_value(timg_dev_t *hw, uint32_t timer_num, * @param timer_num Timer number in the group * @return reload count value */ +__attribute__((always_inline)) static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_num) { return ((uint64_t)hw->hw_timer[timer_num].loadhi.tn_load_hi << 32) | (hw->hw_timer[timer_num].loadlo.tn_load_lo); @@ -207,6 +208,7 @@ static inline uint64_t timer_ll_get_reload_value(timg_dev_t *hw, uint32_t timer_ * @param hw Timer Group register base address * @param timer_num Timer number in the group */ +__attribute__((always_inline)) static inline void timer_ll_trigger_soft_reload(timg_dev_t *hw, uint32_t timer_num) { hw->hw_timer[timer_num].load.tn_load = 1; diff --git a/components/hal/linker.lf b/components/hal/linker.lf index 07f6e5d51fe..4f8003e87b2 100644 --- a/components/hal/linker.lf +++ b/components/hal/linker.lf @@ -30,8 +30,6 @@ entries: twai_hal_iram (noflash) if IDF_TARGET_ESP32 = n: spi_flash_hal_gpspi (noflash) - if GPTIMER_CTRL_FUNC_IN_IRAM = y: - timer_hal_iram (noflash) if GPIO_CTRL_FUNC_IN_IRAM = y: gpio_hal: gpio_hal_intr_disable (noflash) if LCD_RGB_ISR_IRAM_SAFE = y: diff --git a/components/hal/timer_hal.c b/components/hal/timer_hal.c index ae4e55467d0..39f466bca9d 100644 --- a/components/hal/timer_hal.c +++ b/components/hal/timer_hal.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -38,3 +38,25 @@ void timer_hal_deinit(timer_hal_context_t *hal) #endif hal->dev = NULL; } + +void timer_hal_set_counter_value(timer_hal_context_t *hal, uint64_t load_val) +{ + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // - `timer_ll_set_reload_value()` will only indicate the `reload_value` + // - `timer_ll_set_reload_value()` + ``timer_ll_trigger_soft_reload()` can update the HW counter value by software + // Therefore, after updating the HW counter value, we need to restore the previous `reload_value`. + // Attention: The following process should be protected by a lock in the driver layer. + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // save current reload value + uint64_t old_reload = timer_ll_get_reload_value(hal->dev, hal->timer_id); + timer_ll_set_reload_value(hal->dev, hal->timer_id, load_val); + timer_ll_trigger_soft_reload(hal->dev, hal->timer_id); + // restore the previous reload value + timer_ll_set_reload_value(hal->dev, hal->timer_id, old_reload); +} + +uint64_t timer_hal_capture_and_get_counter_value(timer_hal_context_t *hal) +{ + timer_ll_trigger_soft_capture(hal->dev, hal->timer_id); + return timer_ll_get_counter_value(hal->dev, hal->timer_id); +} diff --git a/components/hal/timer_hal_iram.c b/components/hal/timer_hal_iram.c deleted file mode 100644 index 43bac81e72e..00000000000 --- a/components/hal/timer_hal_iram.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "hal/timer_hal.h" -#include "hal/timer_ll.h" - -void timer_hal_set_counter_value(timer_hal_context_t *hal, uint64_t load_val) -{ - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - `timer_ll_set_reload_value()` will only indicate the `reload_value` - // - `timer_ll_set_reload_value()` + ``timer_ll_trigger_soft_reload()` can update the HW counter value by software - // Therefore, after updating the HW counter value, we need to restore the previous `reload_value`. - // Attention: The following process should be protected by a lock in the driver layer. - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // save current reload value - uint64_t old_reload = timer_ll_get_reload_value(hal->dev, hal->timer_id); - timer_ll_set_reload_value(hal->dev, hal->timer_id, load_val); - timer_ll_trigger_soft_reload(hal->dev, hal->timer_id); - // restore the previous reload value - timer_ll_set_reload_value(hal->dev, hal->timer_id, old_reload); -} - -uint64_t timer_hal_capture_and_get_counter_value(timer_hal_context_t *hal) -{ - timer_ll_trigger_soft_capture(hal->dev, hal->timer_id); - return timer_ll_get_counter_value(hal->dev, hal->timer_id); -}