mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-09-20 20:57:41 +08:00
feat(newlib): Add guard for time
This commit is contained in:
@ -31,11 +31,15 @@ static void microsecond_overflow_tick(void* arg)
|
|||||||
{
|
{
|
||||||
uint32_t m = system_get_time();
|
uint32_t m = system_get_time();
|
||||||
|
|
||||||
|
vPortEnterCritical();
|
||||||
|
|
||||||
if (m < microsecond_last_overflow_tick) {
|
if (m < microsecond_last_overflow_tick) {
|
||||||
microsecond_overflow_count ++;
|
microsecond_overflow_count ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
microsecond_last_overflow_tick = m;
|
microsecond_last_overflow_tick = m;
|
||||||
|
|
||||||
|
vPortExitCritical();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start a timer which period is 60s to check the overflow of microsecond. */
|
/* Start a timer which period is 60s to check the overflow of microsecond. */
|
||||||
@ -52,24 +56,41 @@ static void microsecond_overflow_set_check_timer(void)
|
|||||||
|
|
||||||
static void set_boot_time(uint64_t time_us)
|
static void set_boot_time(uint64_t time_us)
|
||||||
{
|
{
|
||||||
|
vPortEnterCritical();
|
||||||
|
|
||||||
s_boot_time = time_us;
|
s_boot_time = time_us;
|
||||||
|
|
||||||
|
vPortExitCritical();
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t get_boot_time()
|
static uint64_t get_boot_time()
|
||||||
{
|
{
|
||||||
uint64_t result;
|
uint64_t result;
|
||||||
|
|
||||||
|
vPortEnterCritical();
|
||||||
|
|
||||||
result = s_boot_time;
|
result = s_boot_time;
|
||||||
|
|
||||||
|
vPortExitCritical();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t get_time_since_boot()
|
static uint64_t get_time_since_boot()
|
||||||
{
|
{
|
||||||
uint32_t m = system_get_time();
|
uint32_t m;
|
||||||
uint32_t c = microsecond_overflow_count + ((m < microsecond_last_overflow_tick) ? 1 : 0);
|
uint32_t c;
|
||||||
|
uint64_t microseconds;
|
||||||
|
|
||||||
uint64_t microseconds = c * (1LL << 32) + m;
|
m = system_get_time();
|
||||||
|
|
||||||
|
vPortEnterCritical();
|
||||||
|
|
||||||
|
c = microsecond_overflow_count + ((m < microsecond_last_overflow_tick) ? 1 : 0);
|
||||||
|
|
||||||
|
vPortExitCritical();
|
||||||
|
|
||||||
|
microseconds = c * (1LL << 32) + m;
|
||||||
|
|
||||||
return microseconds;
|
return microseconds;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user