feat(esp8266): refactor CCOMPARE timer and system time by microseconds

old: CCOMPARE timer triggers when CCOUNT increase to equal to CCOMPARE, then ISR will increase integer of "_xt_tick_divisor"
     to CCOMPARE and wait for next interrupt triggering

now: CCOMPARE timer triggers when CCOUNT increase to equal to CCOMPARE, then ISR will reset CCOUNT to be 0 and reset CCOMPARE
     to be integer of "_xt_tick_divisor", then wait for next interrupt triggering

Using the new method, we may get the CCOUNT value without considing if it has overflowed.
System running microseconds = g_os_ticks * microseconds per tick + CCOUNT.
This commit is contained in:
dongheng
2019-08-16 19:20:06 +08:00
parent 8680849684
commit b061230056
7 changed files with 85 additions and 61 deletions

View File

@ -202,26 +202,7 @@ esp_err_t esp_timer_delete(esp_timer_handle_t timer)
int64_t esp_timer_get_time()
{
extern esp_tick_t g_cpu_ticks;
extern uint64_t g_os_ticks;
extern uint64_t g_esp_os_us;
esp_irqflag_t flag;
esp_tick_t diff_ticks, ticks;
uint64_t time;
flag = soc_save_local_irq();
time = g_os_ticks * portTICK_PERIOD_MS * 1000;
ticks = soc_get_ticks();
if (ticks >= g_cpu_ticks) {
diff_ticks = ticks - g_cpu_ticks;
} else {
diff_ticks = ESP_TICKS_MAX - g_cpu_ticks + ticks;
}
time += diff_ticks / (_xt_tick_divisor * configTICK_RATE_HZ / (1000 * 1000));
soc_restore_local_irq(flag);
return (int64_t)time;
return (int64_t)g_esp_os_us;
}