mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-01 03:34:32 +02:00
newlib: Fix adjtime, returns the amount of time remaining from any previous adjustment
If the olddelta argument is not a null pointer, the adjtime function returns information about any previous time adjustment that has not yet completed. Closes: https://github.com/espressif/esp-idf/issues/5194
This commit is contained in:
@@ -193,6 +193,18 @@ static void adjtime_corr_stop (void)
|
|||||||
int adjtime(const struct timeval *delta, struct timeval *outdelta)
|
int adjtime(const struct timeval *delta, struct timeval *outdelta)
|
||||||
{
|
{
|
||||||
#if defined( WITH_FRC ) || defined( WITH_RTC )
|
#if defined( WITH_FRC ) || defined( WITH_RTC )
|
||||||
|
if(outdelta != NULL){
|
||||||
|
_lock_acquire(&s_adjust_time_lock);
|
||||||
|
adjust_boot_time();
|
||||||
|
if (adjtime_start != 0) {
|
||||||
|
outdelta->tv_sec = adjtime_total_correction / 1000000L;
|
||||||
|
outdelta->tv_usec = adjtime_total_correction % 1000000L;
|
||||||
|
} else {
|
||||||
|
outdelta->tv_sec = 0;
|
||||||
|
outdelta->tv_usec = 0;
|
||||||
|
}
|
||||||
|
_lock_release(&s_adjust_time_lock);
|
||||||
|
}
|
||||||
if(delta != NULL){
|
if(delta != NULL){
|
||||||
int64_t sec = delta->tv_sec;
|
int64_t sec = delta->tv_sec;
|
||||||
int64_t usec = delta->tv_usec;
|
int64_t usec = delta->tv_usec;
|
||||||
@@ -211,18 +223,6 @@ int adjtime(const struct timeval *delta, struct timeval *outdelta)
|
|||||||
adjtime_total_correction = sec * 1000000L + usec;
|
adjtime_total_correction = sec * 1000000L + usec;
|
||||||
_lock_release(&s_adjust_time_lock);
|
_lock_release(&s_adjust_time_lock);
|
||||||
}
|
}
|
||||||
if(outdelta != NULL){
|
|
||||||
_lock_acquire(&s_adjust_time_lock);
|
|
||||||
adjust_boot_time();
|
|
||||||
if (adjtime_start != 0) {
|
|
||||||
outdelta->tv_sec = adjtime_total_correction / 1000000L;
|
|
||||||
outdelta->tv_usec = adjtime_total_correction % 1000000L;
|
|
||||||
} else {
|
|
||||||
outdelta->tv_sec = 0;
|
|
||||||
outdelta->tv_usec = 0;
|
|
||||||
}
|
|
||||||
_lock_release(&s_adjust_time_lock);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
return -1;
|
return -1;
|
||||||
|
Reference in New Issue
Block a user