I ran into a similar issue where I need to loop very fast to drive some motion control hardware.
I did a bit of digging and found 2 solutions.
- esp_task_wdt_reset() which resets the Tast Watchdog Timer (TWDT) on behalf of the currently running task. This is the correct way of feeding the dog.
#include "esp_task_wdt.h"
esp_task_wdt_reset();
But, this method will not work if there are any other threads that have been registered with esp_task_wdt_add(), because it checks to make sure all threads have called esp_task_wdt_reset() recently, and only feeds the dog if so. If you have a thread that must run so fast it blocks the other threads that are on the same core, then you can
- write to the wdt registers directly:
#include "soc/timer_group_struct.h"
#include "soc/timer_group_reg.h"
void feedTheDog(){
// feed dog 0
TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE; // write enable
TIMERG0.wdt_feed=1; // feed dog
TIMERG0.wdt_wprotect=0; // write protect
// feed dog 1
TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE; // write enable
TIMERG1.wdt_feed=1; // feed dog
TIMERG1.wdt_wprotect=0; // write protect
}
This method is hella fast, but it is also bypasses and underminds the rtos's ability to catch other threads when they enter unstable states. So, it should not be used unless you are running a simple application, and don't care about blocking the other threads... which I am...