This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8e83379b84efbbb90e3947e6f473f574cc671f5a Author: Gustavo Henrique Nihei <gustavo.ni...@espressif.com> AuthorDate: Wed Apr 5 20:20:03 2023 -0300 risc-v/espressif: Initialize HR Timer where it is required Signed-off-by: Gustavo Henrique Nihei <gustavo.ni...@espressif.com> --- arch/risc-v/src/espressif/esp_hr_timer.c | 27 ++++++++++++++++------ arch/risc-v/src/espressif/esp_rtc.c | 4 +++- .../esp32c3-generic/src/esp32c3_bringup.c | 12 ---------- .../esp32c6-generic/src/esp32c6_bringup.c | 12 ---------- .../esp32h2-generic/src/esp32h2_bringup.c | 12 ---------- 5 files changed, 23 insertions(+), 44 deletions(-) diff --git a/arch/risc-v/src/espressif/esp_hr_timer.c b/arch/risc-v/src/espressif/esp_hr_timer.c index fbc4dfb104..2732b02655 100644 --- a/arch/risc-v/src/espressif/esp_hr_timer.c +++ b/arch/risc-v/src/espressif/esp_hr_timer.c @@ -648,13 +648,22 @@ void IRAM_ATTR esp_hr_timer_calibration(uint64_t time_us) int esp_hr_timer_init(void) { - struct esp_hr_timer_context_s *priv = &g_hr_timer_context; + static bool g_hr_timer_initialized = false; + struct esp_hr_timer_context_s *priv; + int pid; + + if (g_hr_timer_initialized) + { + tmrinfo("HR Timer already initialized, skipping...\n"); + + return OK; + } - int pid = kthread_create(CONFIG_ESPRESSIF_HR_TIMER_TASK_NAME, - CONFIG_ESPRESSIF_HR_TIMER_TASK_PRIORITY, - CONFIG_ESPRESSIF_HR_TIMER_TASK_STACK_SIZE, - esp_hr_timer_thread, - NULL); + pid = kthread_create(CONFIG_ESPRESSIF_HR_TIMER_TASK_NAME, + CONFIG_ESPRESSIF_HR_TIMER_TASK_PRIORITY, + CONFIG_ESPRESSIF_HR_TIMER_TASK_STACK_SIZE, + esp_hr_timer_thread, + NULL); if (pid < 0) { tmrerr("Failed to create HR Timer task=%d\n", pid); @@ -662,6 +671,8 @@ int esp_hr_timer_init(void) return pid; } + priv = &g_hr_timer_context; + list_initialize(&priv->runlist); list_initialize(&priv->toutlist); @@ -714,5 +725,7 @@ int esp_hr_timer_init(void) up_enable_irq(ESP_IRQ_SYSTIMER_TARGET2_EDGE); - return 0; + g_hr_timer_initialized = true; + + return OK; } diff --git a/arch/risc-v/src/espressif/esp_rtc.c b/arch/risc-v/src/espressif/esp_rtc.c index 57a2b06c5d..cf819ea7f9 100644 --- a/arch/risc-v/src/espressif/esp_rtc.c +++ b/arch/risc-v/src/espressif/esp_rtc.c @@ -863,7 +863,9 @@ int esp_rtc_driverinit(void) return ret; } - /* HR-Timer enabled */ + /* Enable HR-Timer */ + + VERIFY(esp_hr_timer_init()); g_hr_timer_enabled = true; diff --git a/boards/risc-v/espressif/esp32c3-generic/src/esp32c3_bringup.c b/boards/risc-v/espressif/esp32c3-generic/src/esp32c3_bringup.c index 1ed308b374..36ad0dad82 100644 --- a/boards/risc-v/espressif/esp32c3-generic/src/esp32c3_bringup.c +++ b/boards/risc-v/espressif/esp32c3-generic/src/esp32c3_bringup.c @@ -46,10 +46,6 @@ # include "esp_oneshot.h" #endif -#ifdef CONFIG_ESPRESSIF_HR_TIMER -# include "esp_hr_timer.h" -#endif - #ifdef CONFIG_RTC_DRIVER # include "esp_rtc.h" #endif @@ -141,14 +137,6 @@ int esp_bringup(void) } #endif -#ifdef CONFIG_ESPRESSIF_HR_TIMER - ret = esp_hr_timer_init(); - if (ret < 0) - { - _err("Failed to initialize HR timer: %d\n", ret); - } -#endif - #ifdef CONFIG_RTC_DRIVER /* Initialize the RTC driver */ diff --git a/boards/risc-v/espressif/esp32c6-generic/src/esp32c6_bringup.c b/boards/risc-v/espressif/esp32c6-generic/src/esp32c6_bringup.c index 5873847eea..41e1c5231e 100644 --- a/boards/risc-v/espressif/esp32c6-generic/src/esp32c6_bringup.c +++ b/boards/risc-v/espressif/esp32c6-generic/src/esp32c6_bringup.c @@ -46,10 +46,6 @@ # include "esp_oneshot.h" #endif -#ifdef CONFIG_ESPRESSIF_HR_TIMER -# include "esp_hr_timer.h" -#endif - #ifdef CONFIG_RTC_DRIVER # include "esp_rtc.h" #endif @@ -141,14 +137,6 @@ int esp_bringup(void) } #endif -#ifdef CONFIG_ESPRESSIF_HR_TIMER - ret = esp_hr_timer_init(); - if (ret < 0) - { - _err("Failed to initialize HR timer: %d\n", ret); - } -#endif - #ifdef CONFIG_RTC_DRIVER /* Initialize the RTC driver */ diff --git a/boards/risc-v/espressif/esp32h2-generic/src/esp32h2_bringup.c b/boards/risc-v/espressif/esp32h2-generic/src/esp32h2_bringup.c index 8229ca6f7b..3ee4a26c07 100644 --- a/boards/risc-v/espressif/esp32h2-generic/src/esp32h2_bringup.c +++ b/boards/risc-v/espressif/esp32h2-generic/src/esp32h2_bringup.c @@ -46,10 +46,6 @@ # include "esp_oneshot.h" #endif -#ifdef CONFIG_ESPRESSIF_HR_TIMER -# include "esp_hr_timer.h" -#endif - #ifdef CONFIG_RTC_DRIVER # include "esp_rtc.h" #endif @@ -141,14 +137,6 @@ int esp_bringup(void) } #endif -#ifdef CONFIG_ESPRESSIF_HR_TIMER - ret = esp_hr_timer_init(); - if (ret < 0) - { - _err("Failed to initialize HR timer: %d\n", ret); - } -#endif - #ifdef CONFIG_RTC_DRIVER /* Initialize the RTC driver */