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

@ -94,6 +94,18 @@
#define APB_CLK_FREQ CPU_CLK_FREQ
#define UART_CLK_FREQ APB_CLK_FREQ
#define TIMER_CLK_FREQ (APB_CLK_FREQ >> 8) // divided by 256
#define FREQ_1MHZ (1000 * 1000)
#define FREQ_1KHZ (1000)
#define CPU_FREQ_160MHZ (160 * 1000 * 1000)
#define CPU_FREQ_80MHz (80 * 1000 * 1000)
#define CPU_160M_TICKS_PRT_MS (CPU_FREQ_160MHZ / FREQ_1MHZ)
#define CPU_80M_TICKS_PRT_MS (CPU_FREQ_80MHz / FREQ_1KHZ)
#define CPU_160M_TICKS_PRT_US (CPU_FREQ_160MHZ / FREQ_1MHZ)
#define CPU_80M_TICKS_PRT_US (CPU_FREQ_80MHz / FREQ_1MHZ)
//}}
//Peripheral device base address define{{