FRC timer

giksonca
Posts: 17
Joined: Fri Sep 14, 2018 11:30 am

FRC timer

Postby giksonca » Sat Mar 09, 2019 9:48 am

As in esp_timer_esp32.c file ,esp_timer using uses FRC2 (legacy) timer of the ESP32 . and we can see those are hard coded to REG1(1) there as well.Is there more FRC timers which can be used for making multiple soft timers if we change accordingly ?. For example

In frc-timer_reg.h , #define FRC_TIMER_ALARM_REG(i) (REG_FRC_TIMER_BASE(i) + 0x10) // timer alarm value; register only present for i == 1

FRC_TIMER_ALARM_REG(1) is the only FRC timer can be used for alarm ? Also please provide some documentation on FRC timers.

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: FRC timer

Postby ESP_igrr » Sat Mar 09, 2019 12:12 pm

Please have a look at the Timer Group timers — they also provide alarm functionality, plus more flexible prescaler, and are 64-bit (so no need to handle overflows in software!).

FRC1 is a free-running counter without alarm functionality.

FRC2 is used for esp_timer. In fact, esp_timer uses FRC2 instead of the Timer Group timers so that users can have all 4 Timer Group timers to themselves! FRC2 is 32-bit and doesn't have any advantages over the TG timers.

giksonca
Posts: 17
Joined: Fri Sep 14, 2018 11:30 am

Re: FRC timer

Postby giksonca » Mon Mar 11, 2019 4:13 am

Thanks for the reply.

I had a look at TG group timers. But there is no sample code for multiple timer(soft timers) option using TG timer group as like in esp_timer. for example I would like to use TG timer 1 as base for multiple timer like in esp_timer (FRC2 as base). Is there any sample code available for the same implementation for TG ?

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: FRC timer

Postby ESP_igrr » Mon Mar 11, 2019 4:20 am

No, there isn't any sample code for that. It's not too complex, however. You can start by maintaining a linked list (or an array) of timer objects, sorted by timeout time. Each time after changing something in the array, set the TG compare value to the expiry time of the first timer on the list. When an interrupt happens, walk through the list of timers one by one, checking which ones have expired. If the timer has expired, call the callback function, and proceed to the next one. If not expired yet, stop checking timeouts, and update TG compare value.

Who is online

Users browsing this forum: No registered users and 95 guests