Embedded System watchdog implementation, embedded system watchdog

Source: Internet
Author: User

Embedded System watchdog implementation, embedded system watchdog

The work of the embedded system is often affected by external electromagnetic fields, causing the program to run and run into an endless loop. the normal operation of the program is interrupted, causing the entire system to be stuck, unexpected consequences occur, so real-time monitoring of the running status of the embedded system is required.A chip used to monitor the running status of an embedded system, called a "Watchdog ".

Linux comes with a watchdog implementation for monitoring system running, including a kernel watchdog module and a user space watchdog program. The kernel watchdog module communicates with the user space through the/dev/watchdog character device. Once the/dev/watchdog device is enabled for a user space program, a one-minute timer is enabled in the kernel, the user space program needs to ensure that data is written to the device within one minute, and each write operation will cause the timer to be reset. If the user space program does not write in 1 minute, the timer will cause a systemRebootOperation.

Watchdogtimer (WDT), also known as watchdogtimer, is a timer circuit. It generally has an input, which is called a dog Feed and an output to the MCU (Microcontroller Unit, also known as a single chip microcomputer) when the MCU works normally, a signal is output to the dog Feed End at intervals, and the WDT is cleared,If a dog is not fed after the specified time (generally when the program is running) and the WDT time exceeds, a reset signal is given to the MCU to reset the MCU to prevent the MCU from crashing.

The Watchdog Circuit enables the embedded system to work continuously without human intervention. The working principle is that the watchdog chip is connected to an I/O pin of the microcontroller,The I/O pin uses a program to control it regularly to send high (or low) to the dog's pin)This Program Statement is distributed among other control statements in the embedded system. Once the microcontroller enters an endless loop after the program runs due to interference, the program that writes the watchdog pin cannot be executed. At this time,Because the signal sent by the embedded system is not obtained, the Watchdog Circuit sends a reset signal to the Pin connected to the reset pin of the single chip microcomputer to reset the single chip microcomputer.That is, the program starts to execute from the starting position of the program memory, so as to realize the automatic reset of the microcontroller.

Common WDT chips, such as MAX813, 5045, and IMP 813, are priced at 4 ~ 10 yuan.

Differences between Hardware and Software watchdog

1. The hardware watchdog must support hardware circuits. The device node/dev/watchdog corresponds to real physical devices. Different types of hardware watchdog devices are managed by corresponding hardware drivers.

The software watchdog is implemented by a kernel module softdog. ko through the timer mechanism./dev/watchdog does not correspond to real physical devices, but provides an interface that is the same as the operating hardware watchdog.

2. The hardware watchdog has better reliability than the Software watchdog.The software watchdog is implemented based on the kernel timer. When the kernel or interrupt encounters an exception, the Software watchdog will become invalid.The hardware watchdog is controlled by its own hardware circuit and is independent of the kernel. Regardless of the current system status, the hardware watchdog will restart the system if it is not written at the specified interval.

Some Hardware watchdog cards such as WDT501P and some Berkshire cards can also monitor system temperature and provide/dev/temperature interfaces.

/Dev/watchdog is a device node with a master device number of 10 characters starting from device number 130.

Before using watchdog in Linux to develop applications, make sure that the kernel has been correctly configured to support watchdog. The drivers/char/watchdog/Kconfig file in the kernel source code provides a detailed description of Various watchdog configuration options.

If the Kernel configuration option 'config _ watchdog_nowayout' is set to 'y', watchdog cannot be stopped after startup by default. If the nowayout parameter of the module is set to 0, write the 'V' character to/dev/watchdog to stop the watchdog operation.

Code snippet for starting watchdog

Int wd_fd =-1;

Fd = open ("/dev/watchdog", O_WRONLY );

If (wd_fd =-1)

{

// Fail to open watchdog device

}

Code segment for stopping watchdog

 if (wd_fd != -1)
 {
 write(wd_fd, "V", 1);
 close(wd_fd);
 wd_fd = -1;
 } 

Code segment that keeps watchdog running

if (wdt_fd != -1)
 write(wdt_fd, "a", 1);

If WDT is used in a single chip embedded system based on Xilinx stmq, You need to configure the Device Tree.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.