esp_system: introduce system time functions
- Introduce system time function and concept of system time provider. esp_timer is system time provider when present. - Set the reference point for system time, g_startup_time. - Use the system time functions in newlib instead of calling esp_timer functions directly
This commit is contained in:
@@ -97,7 +97,6 @@ static StaticQueue_t s_timer_semaphore_memory;
|
||||
static portMUX_TYPE s_timer_lock = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
|
||||
|
||||
esp_err_t esp_timer_create(const esp_timer_create_args_t* args,
|
||||
esp_timer_handle_t* out_handle)
|
||||
{
|
||||
@@ -349,7 +348,6 @@ static IRAM_ATTR bool is_initialized(void)
|
||||
return s_timer_task != NULL;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_timer_init(void)
|
||||
{
|
||||
esp_err_t err;
|
||||
@@ -380,6 +378,11 @@ esp_err_t esp_timer_init(void)
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = esp_timer_timekeeping_impl_init();
|
||||
if (err != ESP_OK) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
out:
|
||||
@@ -505,4 +508,4 @@ int64_t IRAM_ATTR esp_timer_get_next_alarm(void)
|
||||
}
|
||||
timer_list_unlock();
|
||||
return next_alarm;
|
||||
}
|
||||
}
|
||||
45
components/esp_timer/src/timekeeping.c
Normal file
45
components/esp_timer/src/timekeeping.c
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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
|
||||
Reference in New Issue
Block a user