esp_system: link time, not runtime, dependency on esp_timer

This commit is contained in:
Renz Bagaporo
2020-07-14 14:46:13 +08:00
parent 346cf4430d
commit da88671491
12 changed files with 73 additions and 103 deletions

View File

@@ -24,10 +24,27 @@
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/xtensa_api.h"
#include "soc/spinlock.h"
#include "esp_timer.h"
#include "esp_timer_impl.h"
#include "esp_private/startup_internal.h"
#include "esp_private/esp_timer_private.h"
#if CONFIG_IDF_TARGET_ESP32
#include "esp32/rtc.h"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/rtc.h"
#endif
#include "sdkconfig.h"
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 ) || \
defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 ) || \
defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_FRC1 ) || \
defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_RTC_FRC1 )
#define WITH_FRC 1
#endif
#ifdef CONFIG_ESP_TIMER_PROFILING
#define WITH_PROFILING 1
@@ -378,10 +395,11 @@ esp_err_t esp_timer_init(void)
goto out;
}
err = esp_timer_timekeeping_impl_init();
if (err != ESP_OK) {
goto out;
}
#if WITH_FRC
// [refactor-todo] this logic, "esp_rtc_get_time_us() - g_startup_time", is also
// the weak definition of esp_system_get_time; find a way to remove this duplication.
esp_timer_private_advance(esp_rtc_get_time_us() - g_startup_time);
#endif
return ESP_OK;
@@ -508,4 +526,27 @@ int64_t IRAM_ATTR esp_timer_get_next_alarm(void)
}
timer_list_unlock();
return next_alarm;
}
}
int64_t IRAM_ATTR esp_timer_get_time(void)
{
if(is_initialized()) {
return esp_timer_impl_get_time();
} else {
return 0;
}
}
// Provides strong definition for system time functions relied upon
// by core components.
#if WITH_FRC
int64_t IRAM_ATTR esp_system_get_time(void)
{
return esp_timer_get_time();
}
uint32_t IRAM_ATTR esp_system_get_time_resolution(void)
{
return 1;
}
#endif

View File

@@ -209,8 +209,6 @@ int64_t IRAM_ATTR esp_timer_impl_get_time(void)
return result;
}
int64_t esp_timer_get_time(void) __attribute__((alias("esp_timer_impl_get_time")));
void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp)
{
portENTER_CRITICAL_SAFE(&s_time_update_lock);

View File

@@ -149,8 +149,6 @@ int64_t IRAM_ATTR esp_timer_impl_get_time(void)
return esp_timer_impl_get_counter_reg() / TICKS_PER_US;
}
int64_t esp_timer_get_time(void) __attribute__((alias("esp_timer_impl_get_time")));
void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp)
{
portENTER_CRITICAL_SAFE(&s_time_update_lock);

View File

@@ -68,9 +68,6 @@ int64_t IRAM_ATTR esp_timer_impl_get_time(void)
return systimer_hal_get_time(SYSTIMER_COUNTER_0);
}
// Xtensa architecture doesn't have tail call optimization, using alias here can improve performance somehow
int64_t esp_timer_get_time(void) __attribute__((alias("esp_timer_impl_get_time")));
void IRAM_ATTR esp_timer_impl_set_alarm(uint64_t timestamp)
{
portENTER_CRITICAL_SAFE(&s_time_update_lock);

View File

@@ -1,45 +0,0 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "esp_timer.h"
#include "esp_private/esp_timer_private.h"
#include "esp_private/system_internal.h"
#include "sdkconfig.h"
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 ) || \
defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 ) || \
defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_FRC1 ) || \
defined( CONFIG_ESP32S2_TIME_SYSCALL_USE_RTC_FRC1 )
#define WITH_FRC 1
#endif
#if WITH_FRC
void esp_timer_timekeeping_impl_init(void)
{
// esp_system_get_time here calls the previous system time provider.
// This should add the time elapsed from g_startup_time up to esp_timer_init,
// therefore keeping it as the point of reference (g_startup_time, that is).
esp_timer_private_advance(esp_system_get_time());
// esp_timer provides microsecond-resolution timers to the system
esp_system_set_time_provider(esp_timer_get_time, 1);
}
#else
void esp_timer_timekeeping_impl_init(void)
{
// Do not override default system time provider
}
#endif