Как работает сторожевая защита

In order to make the transmission of networking equipment such as industrial routers, DTUs, and serial servers more stable, these devices will be equipped with anti-surge, anti-static, anti-pulse and watchdog protection. Among these hardware protections, there is one that can keep the internal processes of the device from going down for 24 hours – watchdog technology. How does the watchdog work and calculate?

Watchdog chip, also called watchdog timer. It is a piece of hardware in a microcontroller. If the system gets stuck somewhere then the watchdog timer is used to generate a system reset and if the system gets into an infinite loop of execution then the watchdog timer will reset the system to get out of the infinite loop. Watchdog is a safety mechanism in embedded systems that makes your system reliable, but it depends on how the watchdog timer is used.

Как работает сторожевая защита

How watchdog works

A watchdog is basically a counter that starts counting from zero and reaches a certain value. If the counter reaches a certain value, the watchdog hardware will generate a watchdog reset. To avoid system reset, the software needs to start the watchdog, which means the counter needs to be reset to zero. In case the software gets stuck in an endless loop, the system will not be able to kick the watchdog, so the counter reaches a certain value and resets the system.

The watchdog is initially loaded with certain values. This value is calculated based on the watchdog’s timeout (further instructions on how to calculate the counter value based on the timeout value are provided). Before timing out, the system should reset the counter.

For example, if your system executes 3 tasks regularly and it takes 500 milliseconds to execute 3 tasks. Then consider the timeout as 600 ms (considering the worst case scenario), calculate the counter value for 600 ms and load it into the watchdog.

watchdog computing

Consider the system in Watchdog is operating with a 4 kHz clock. The system completes the work in 450 milliseconds, and in the worst case, it takes 500 milliseconds to complete the work. Let’s use 500 milliseconds as the timeout.

1/4 kHz = 0.25 milliseconds

1 clock tick = 0.25 milliseconds.

500 milliseconds = 2000 ticks.

When the clock ticks 2000 times, it completes 500 milliseconds. The technical value associated with timeout is 2000.

If the watchdog counter reaches 2000, it will generate a reset signal. The system needs to reset the counter to 0 before reaching 2000.

Advanced use cases for watchdog timers

In the case of operating systems (multitasking systems), watchdog plays an important role. Watchdogs can monitor program flow and monitor the frequency of task execution (activity supervision). A watchdog reset is generated if the watchdog detects a program flow conflict or if a task is executed too frequently or infrequently. In the case of online supervision, each task has a flag set to indicate that the task is online, that is, executed. The watchdog monitor function will check whether each task has reported an active indication. If the task is not set to activate indication, the watchdog monitor function will never kick the watchdog and eventually the watchdog will reset the system.

Ключевые слова: 4gdtu

Свяжитесь с нами