The difference between hardware and software watchdogs

  When it comes to improving the reliability of the system, engineers who are just getting started know that adding a watchdog is an important means. Watchdogs are divided into software watchdogs and hardware watchdogs, but many people may not have a deep understanding of the differences. They may encounter this PK at work:
Insert image description here
  What is the difference between software and hardware watchdogs? After studying this article, you will be able to solve it easily.

1. Principle of hardware watchdog

The hardware watchdog uses a timer circuit, and its timing output is connected to the reset terminal of the circuit. The program clears the timer within a certain time range (commonly known as "feeding the dog"). Therefore, when the program is working normally, the timer cannot always overflow, the reset signal cannot be generated. If the program fails and the watchdog is not reset within the timing period, the watchdog timer will overflow and generate a reset signal and restart the system.
Let's take Analog Devices' ADM6316 watchdog chip as an example.
Insert image description here
  The main functions of this watchdog chip are:
  1. Can monitor the main power supply VCC, 26 reset threshold options: 2.5 V to 5 V, in 100 mV increments; 2.4
  reset delay options: 1 ms, 20 ms, 140 ms, 1120 ms (minimum value);
  3.4 watchdog timeout options: 6.3 ms, 102 ms, 1600 ms, 25.6 s (typical value);
  4. Support manual reset input;
  5. Reset output stage: push-pull low power Active at low level, open drain at low level, push-pull at high level.
  Reset function description:
  This chip has a built-in reset function. When the device is powered on, once the VCC voltage of the chip reaches the turn-on threshold voltage VTH, the delay timer starts. After the delay time tRP, the reset signal RESET or /RESET can be output to realize the delayed power-on reset of the device; the chip will also monitor the VCC. voltage, once VCC drops below VTH, after the delay time tRD, the reset signal output level flips to realize the reset of the device.
Insert image description here
  Watchdog function description:
  The chip has a built-in watchdog function. When the device is powered on, once the VCC voltage of the chip reaches the turn-on threshold voltage VTH, the delay timer starts. After the delay time tRP, the reset signal RESET or /RESET can be output to realize delayed power-on of the device. Reset; when the dog feeding signal WDI receives the first pulse level, the timer inside the chip is triggered. The software must output the dog feeding signal WDI within the tWD time, otherwise the reset signal RESET or /RESET will arrive at the timing time tWD. When, perform a reset and the device resets again.
Insert image description here

2. Principle of software watchdog

  The principle of software watchdog is the same, except that the timer on the hardware circuit is replaced by the internal timer of the processor, which can simplify the hardware circuit design. Generally, a timer in a chip is used as a watchdog, and the timer is initialized through the program. , write the initial value, and start the timer. The program assigns an initial value to the timer (or resets it) on time to prevent it from getting hungry.
  This kind of watchdog can be disabled (just stop the timer), which is like giving a "sunflower bite" to the dog that just bites you. Most CPUs have built-in watchdogs. For hardware principles, please refer to various Chip data sheet.
  Advantages: The initial time can be changed programmatically or disabled at any time.
  Disadvantages: Initialization is required. If the program runs away before initialization or startup is completed or runs away after being disabled, the watchdog cannot reset the system. In this way, the role of the watchdog is gone and the system recovery ability is reduced.
Insert image description here

3. Main similarities and differences between software and hardware watchdogs

  After learning about the above-mentioned software and hardware watchdogs, let’s summarize the similarities and differences between the two.
  The similarities between the two are as follows:
  1) Both are implemented through timers; they will be reset when the timer expires and no dog is fed.
  2) Dogs need to be fed within the specified time.
  3) Both rely on software to feed dogs.
  The main differences between the two are as follows:
  1) Additional functions: Hardware watchdog chips generally come with delayed reset and power detection functions, but software does not.
  2) Shielding method: The software watchdog is easy to shut down by modifying the registers, but the hardware watchdog cannot be stopped once it is started without power interruption.
  3) Startup method: The software watchdog is easy to start, just modify the registers. The hardware usually starts after receiving the first dog-feeding signal.
  4) Initialization: After the hardware watchdog is powered on, it completes the initialization after receiving the first dog feeding pulse. The software watchdog needs to configure the relevant registers (or call the relevant watchdog subroutine).

4. A case where the software watchdog cannot solve the problem

  The project team developed an outdoor remote collector. The application scenarios include remote suburbs, which require high reliability. It can automatically reset and restart after a failure or remote upgrade. In order to save costs, this product uses the built-in watchdog function of the main chip. After the initialization of other resources of the main chip is completed, the watchdog function is initialized. After the product is batched, during the remote upgrade process, there is about a 5% chance that the equipment will become bricked after the upgrade, and it will need to be manually powered off and on again to return to normal.
  After analysis by the R&D personnel, the software's watchdog process is as shown below. A small number of devices crashed during the program upgrade process. The program has not yet reached the stage of initializing the watchdog, and the watchdog cannot take effect, resulting in The device is in a state of freeze, and returns to normal after a manual power outage and restart.

Figure 5: Software watchdog flow chart
  After improvement and upgrade, the developers used a hardware watchdog. The watchdog is turned on by relying on the high pulse formed by the pull-up resistor at the moment of power-on. The delay of the watchdog is 1.8S at the latest, and the evaluation upgrade + initialization time is the longest. The delay is 1.2S, so the watchdog chip meets the requirements. Once the application cannot feed the dog within 1.8S, it will be reset and restarted, and the problem will be solved.
Figure 6: Hardware watchdog flow chart

5. Summary

  The main difference between software and hardware watchdogs is the timing of turning on the watchdog. The software watchdog must be initialized (configured) before the watchdog can be used. If the software watchdog is an API interface in the SDK provided by the manufacturer, Developers do not have the ability to modify the underlying uboot and kernel, and cannot start and feed the dog during the uboot and kernel stages. The time to turn on the watchdog is very late, and the program may hang before the watchdog is initialized. All the problems in the middle are out of control, just like the above case.
  The hardware watchdog is not constrained by software. When the device is powered on, it can rely on the high pulse provided by the pull-up resistor to turn on the watchdog. As long as the software does not feed the dog in time, it will be reset. This is unconditional. The saying “you get what you pay for” also applies to electronic products.
  Of course, if you can convince the driver engineer to initialize and enable the software watchdog as soon as the main chip is powered on, in theory, the software watchdog can be as reliable as the hardware watchdog.

Guess you like

Origin blog.csdn.net/wjcqwe/article/details/129843783