feat(esp_timer): Move esp_timer-related init steps into the component

This commit is contained in:
Konstantin Kondrashov
2024-01-23 20:10:20 +02:00
committed by BOT
parent 10f14d5cca
commit 49ba674fb5
11 changed files with 80 additions and 50 deletions

View File

@@ -4,6 +4,7 @@ if(${target} STREQUAL "linux")
idf_component_register(INCLUDE_DIRS include)
else()
set(srcs "src/esp_timer.c"
"src/esp_timer_init.c"
"src/ets_timer_legacy.c"
"src/system_time.c"
"src/esp_timer_impl_common.c")
@@ -21,4 +22,7 @@ else()
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS include
PRIV_INCLUDE_DIRS private_include)
# Forces the linker to include esp_timer_init.c
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_timer_init_include_func")
endif()

View File

@@ -514,15 +514,6 @@ static IRAM_ATTR inline bool is_initialized(void)
return s_timer_task != NULL;
}
esp_err_t esp_timer_early_init(void)
{
esp_timer_impl_early_init();
#if CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER
esp_timer_impl_init_system_time();
#endif
return ESP_OK;
}
static esp_err_t init_timer_task(void)
{
esp_err_t err = ESP_OK;
@@ -582,7 +573,14 @@ esp_err_t esp_timer_init(void)
#define ESP_TIMER_INIT_MASK ESP_SYSTEM_INIT_ALL_CORES
#endif // CONFIG_ESP_TIMER_ISR_AFFINITY_*
ESP_SYSTEM_INIT_FN(esp_timer_startup_init, SECONDARY, ESP_TIMER_INIT_MASK, 100)
/*
* This function initializes a task and ISR that esp_timer uses.
*
* We keep the esp_timer initialization function here to allow the linker
* to automatically include esp_timer_init_os if other components call esp_timer APIs.
* If no other code calls esp_timer APIs, then esp_timer_init_os will be skipped.
*/
ESP_SYSTEM_INIT_FN(esp_timer_init_os, SECONDARY, ESP_TIMER_INIT_MASK, 100)
{
return esp_timer_init();
}

View File

@@ -0,0 +1,35 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_private/startup_internal.h"
#include "esp_timer_impl.h"
#include "sdkconfig.h"
esp_err_t esp_timer_early_init(void)
{
esp_timer_impl_early_init();
#if CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER
esp_timer_impl_init_system_time();
#endif
return ESP_OK;
}
/*
* This function starts a timer, which is used by esp_timer
* to count time from the very start of the application.
*
* Another initialization function, esp_timer_init_nonos (which initializes ISR and task),
* is called only if other code calls the esp_timer API.
*/
ESP_SYSTEM_INIT_FN(esp_timer_init_nonos, CORE, BIT(0), 101)
{
return esp_timer_early_init();
}
void esp_timer_init_include_func(void)
{
// Hook to force the linker to include this file
}