WDT: Who calls 'mgos_wdt_feed' (ESP32)

The user code does not need to call mgos_wdt_enable or mgos_wdt_set_timeout. The Mongoose OS’s init code takes care of that (it sets the timeout to the value specified by sys.wdt_timeout).

AFAIK, the dog is fed by mongoose_poll in the main task.

When doing some lenghty processing or a tight loop which takes more then sys.wdt_timeout seconds, the WDT exception will be triggered.
To avoid that, one can add a call to mgos_wdt_feed or mongoose_poll.

Simple example:

#include "mgos.h"

static void timer_cb(void *arg) {
  static bool s_tick_tock = false;
  LOG(LL_INFO, ("%s uptime: %.2lf, heap free/min_free: %zu/%zu", __FUNCTION__,
                mgos_uptime(), mgos_get_free_heap_size(),
                mgos_get_min_free_heap_size()));
  s_tick_tock = !s_tick_tock;
  (void) arg;
}

void tight_loop(void) {
  while (true) {
    LOG(LL_INFO, ("%s uptime: %.2lf, heap free/min_free: %zu/%zu", __FUNCTION__,
                  mgos_uptime(), mgos_get_free_heap_size(),
                  mgos_get_min_free_heap_size()));
    mgos_usleep(100000);  // sleep for 100ms, blocking
    // mongoose_poll(0);     // other events will be processed
    // mgos_wdt_feed(); // other events will not be processed
  }
}

void start_tight_loop(void *arg) {
  tight_loop();
}

enum mgos_app_init_result mgos_app_init(void) {
  mgos_set_timer(1000, MGOS_TIMER_REPEAT, timer_cb, NULL);
  mgos_set_timer(10000, 0, start_tight_loop, NULL);
  return MGOS_APP_INIT_SUCCESS;
}

Comment out one of the lines mongoose_poll or mgos_wdt_feed and see how it works. Tested with ESP8266 and ESP32.

1 Like