wdts.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. Watchdogs
  2. =========
  3. Overview
  4. --------
  5. Esp-idf has support for two types of watchdogs: a task watchdog as well as an interrupt watchdog. Both can be
  6. enabled using ``make menuconfig`` and selecting the appropriate options.
  7. Interrupt watchdog
  8. ^^^^^^^^^^^^^^^^^^
  9. The interrupt watchdog makes sure the FreeRTOS task switching interrupt isn't blocked for a long time. This
  10. is bad because no other tasks, including potentially important ones like the WiFi task and the idle task,
  11. can't get any CPU runtime. A blocked task switching interrupt can happen because a program runs into an
  12. infinite loop with interrupts disabled or hangs in an interrupt.
  13. The default action of the interrupt watchdog is to invoke the panic handler. causing a register dump and an opportunity
  14. for the programmer to find out, using either OpenOCD or gdbstub, what bit of code is stuck with interrupts
  15. disabled. Depending on the configuration of the panic handler, it can also blindly reset the CPU, which may be
  16. preferred in a production environment.
  17. The interrupt watchdog is built around the hardware watchdog in timer group 1. If this watchdog for some reason
  18. cannot execute the NMI handler that invokes the panic handler (e.g. because IRAM is overwritten by garbage),
  19. it will hard-reset the SOC.
  20. Task watchdog
  21. ^^^^^^^^^^^^^
  22. Any tasks can elect to be watched by the task watchdog. If such a task does not feed the watchdog within the time
  23. specified by the task watchdog timeout (which is configurable using ``make menuconfig``), the watchdog will
  24. print out a warning with information about which processes are running on the ESP32 CPUs and which processes
  25. failed to feed the watchdog.
  26. By default, the task watchdog watches the idle tasks. The usual cause of idle tasks not feeding the watchdog
  27. is a higher-priority process looping without yielding to the lower-priority processes, and can be an indicator
  28. of badly-written code that spinloops on a peripheral or a task that is stuck in an infinite loop.
  29. Other task can elect to be watched by the task watchdog by calling ``esp_task_wdt_feed()``. Calling this routine
  30. for the first time will register the task to the task watchdog; calling it subsequent times will feed
  31. the watchdog. If a task does not want to be watched anymore (e.g. because it is finished and will call
  32. ``vTaskDelete()`` on itself), it needs to call ``esp_task_wdt_delete()``.
  33. The task watchdog is built around the hardware watchdog in timer group 0. If this watchdog for some reason
  34. cannot execute the interrupt handler that prints the task data (e.g. because IRAM is overwritten by garbage
  35. or interrupts are disabled entirely) it will hard-reset the SOC.
  36. JTAG and watchdogs
  37. ^^^^^^^^^^^^^^^^^^
  38. While debugging using OpenOCD, if the CPUs are halted the watchdogs will keep running, eventually resetting the
  39. CPU. This makes it very hard to debug code; that is why the OpenOCD config will disable both watchdogs on startup.
  40. This does mean that you will not get any warnings or panics from either the task or interrupt watchdog when the ESP32
  41. is connected to OpenOCD via JTAG.
  42. API Reference
  43. -------------
  44. Header Files
  45. ^^^^^^^^^^^^
  46. * :component_file:`esp32/include/esp_int_wdt.h`
  47. * :component_file:`esp32/include/esp_task_wdt.h`
  48. Functions
  49. ---------
  50. .. doxygenfunction:: esp_int_wdt_init
  51. .. doxygenfunction:: esp_task_wdt_init
  52. .. doxygenfunction:: esp_task_wdt_feed
  53. .. doxygenfunction:: esp_task_wdt_delete