Posts: 9
Joined: Wed Mar 11, 2020 4:10 pm


Postby mriksman » Wed Apr 22, 2020 9:09 pm


I'm trying to understand all the timers in ESP8266 RTOS SDK. When I used the PWM library, it caused my esp-homekit clients to disconnect. Nothing in the debug logs, they just dropped connections. Perhaps an issue with secure connections, perhaps an issue with Wi-Fi (although the ESP stays connected to the AP). People are successfully using PWM with FRC1 alongside esp-homekit, so this WDEV TSF0 interrupt must be causing an issue.

Doing some research, I have found;
[*] FreeRTOS System Tick uses CCOUNT and the CCOMPARE0(TIMER0) timer. Initialised in freertos/port/esp8266/os_cpu_a.S
[*] FreeRTOS Timers (xTimerCreate) uses this System Tick (defaults to 10ms ticks; 100Hz)
[*] FRC1 is available to the user via the hw_timer library
[*] PWM uses WDEV TSF0 Interrupt (??). Initialised in startup.c user_init_entry()

ESP32 up until 4.1 used FRC2 for their high resolution hardware timer library esp-timer. This allowed timers to be created that had shorter times than the System Tick.
Looking at ESP8266 RTOS SDK, the esp-timer library seems to just be a wrapper for FreeRTOS Timers; so it isn't using FRC2.

[*] What is this WDEV TSF0 interrupt? Does it affect Wi-Fi or secure connections? Where is the documentation for it?
[*] What is FRC2 used for in ESP8266 RTOS SDK? It is exposed in esp-open-rtos and in the esp-idf sdk, but nothing in the ESP8266 RTOS SDK exposes it.

Posts: 9
Joined: Wed Mar 11, 2020 4:10 pm

Re: Timers (CCOMPARE0, FRC1, FRC2, WDEV TSF0)?

Postby mriksman » Thu Apr 23, 2020 12:32 am

Also, the KCONFIG has the following;

Code: Select all

        prompt "Timers used for gettimeofday function"
        default ESP8266_TIME_SYSCALL_USE_FRC1
            This setting defines which hardware timers are used to
            implement 'gettimeofday' and 'time' functions in C library.

            - If high-resolution timer is used, gettimeofday will
              provide time at microsecond resolution.
              Time will not be preserved when going into deep sleep mode.
            - If no timers are used, gettimeofday and time functions
              return -1 and set errno to ENOSYS.

However, when CONFIG_ESP8266_TIME_SYSCALL is defined in time.c, it uses esp_timer_get_time(). This function uses soc_get_ccount() function, which returns the CCOUNT register.

Code: Select all

int64_t esp_timer_get_time(void) {
    extern uint64_t g_esp_os_us;
    return (int64_t)(g_esp_os_us + soc_get_ccount() / g_esp_ticks_per_us);

How is that related to FRC1?

Who is online

Users browsing this forum: No registered users and 6 guests