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

@ -26,20 +26,6 @@ extern "C" {
typedef uint32_t esp_tick_t;
typedef uint32_t esp_irqflag_t;
static inline esp_tick_t soc_get_ticks(void)
{
esp_tick_t ticks;
__asm__ __volatile__(
"rsr %0, ccount\n"
: "=a"(ticks)
:
: "memory"
);
return ticks;
}
static inline esp_irqflag_t soc_save_local_irq(void)
{
esp_irqflag_t flag;
@ -102,6 +88,16 @@ static inline uint32_t soc_get_ccount(void)
return ticks;
}
static inline void soc_set_ccount(uint32_t ticks)
{
__asm__ __volatile__(
"wsr %0, ccount\n"
:
: "a"(ticks)
: "memory"
);
}
static inline void soc_clear_int_mask(uint32_t mask)
{
__asm__ __volatile__(