2169 views|6 replies

4771

Posts

12

Resources
The OP
 

[Transfer] Some thoughts on using watchdog in freeRTOS [Copy link]

 

I believe that all embedded software developers should be familiar with watchdogs. In embedded software development, watchdogs are often used to monitor whether the CPU program is running normally. If the CPU program runs abnormally, the watchdog will trigger a reset when the set threshold is reached, so that the entire CPU will be reset and restarted.

The essence of a watchdog is a counter. At the beginning, it is configured to a specific value, and then the counter will keep counting down. When it reaches 0, it will trigger a system reset. Therefore, in order to avoid being reset, it is necessary to reset the watchdog count value at a certain interval, which is what we often call "feeding the dog".

This "feeding the dog" action should occur within the interval of the watchdog's reset threshold. Otherwise, exceeding or reaching this threshold will cause the system to be reset, which is something we do not want to see.

Regarding the use of watchdog in the program, it can be discussed in two situations:

1)裸机中使用看门狗;
2)RTOS环境中使用看门狗。

1. Using watchdog in bare metal

When using a watchdog in a bare metal machine, due to the influence of bare metal programming and the way the program executes, developers usually perform the "feeding" operation of the watchdog in the main loop.

At this time, developers need to reasonably evaluate the execution flow of the code they write and estimate the worst execution time value in the entire main loop, so as to set the threshold time of the watchdog to ensure that in the worst case, the watchdog does not reset the system.

There are two common ways to use watchdog for system monitoring in bare metal:

(1) Insert a dog feed into the code execution flow

This is the simplest way. When developing, the "feeding the dog" of the watchdog is usually inserted into the program execution flow, especially for the program segments that take a long time to execute. For the program segments that take less time to execute, you can add "feeding the dog" in the main loop process.

(2) Use a timer to feed the dog regularly

In a bare metal machine, you can also use a timer to feed the dog regularly. Compared with inserting "feeding the dog" operations in multiple places in the code, this method makes the code look simpler, but it generally requires the use of hardware resources for hardware timing and more timer interrupts. If the program itself is relatively complex, adding more abnormal interrupts may cause some unpredictable problems to system maintenance and stability.

Of course, there are other ways to implement and use it. For the bare metal watchdog "feeding the dog", it is generally simpler, there are relatively fewer things to consider, and it is easier to implement.

2. Using watchdog in RTOS

Using a watchdog in an RTOS is much more complicated, and there are many issues to consider. Because of the existence of the multi-tasking mechanism in the RTOS, in theory, the more complex the program, the more complex the system operation, and the existence of multi-tasking may lead to more changes, some of which may be difficult to predict.

In multitasking, when using a watchdog, we hope to be able to implement the watchdog to monitor the health and survival of each task in the entire system. If a task in the system dies, the watchdog can be used to reset the system, thereby resetting the system to restart the system. When each task is normal, do not reset the watchdog, so as not to affect the normal execution of the system.

Let's briefly discuss how to implement the watchdog "feeding the dog" under RTOS:

(1) Insert "Feed the Dog" into the execution flow of the code

This method is to insert the "feed the dog" operation in the scheduling flow of each task, and then implement the "feed the dog" operation through the scheduling execution of the task. This method is relatively easy to understand and not complicated. As long as the developer is familiar with the code and knows the execution sequence flow of the code, then insert the "feed the dog" operation in the program.

What are the advantages and disadvantages of this method?

advantage:

It is easy to implement. Just call the "feed the dog" operation in each task, and pay attention to "feeding the dog" in the program segment that occupies a long CPU execution time.

shortcoming:

It is not possible to monitor the survival of each task. Because when this method is used, there are multiple places where the dog feeding operation can be performed. At this time, if a task has died, it cannot be fed because it has died, but other tasks can be fed, and the entire system will not be reset, so it is impossible to know whether a task has a problem.

(2) Monitor the survival status of each task and feed the dog

This method is more practical than calling the watchdog feeding operation everywhere. It feeds the watchdog only after confirming that each task is alive and well. If a task is no longer running due to a fault, it will cause the watchdog to time out and fail to feed the watchdog, which will cause the system to be reset by the watchdog.

There are many ways to implement this method, such as using event flag groups, which is easier to implement.

The method is:

1)创建一个“喂狗”的独立任务;
2)申请一个事件标志组,并为每个任务留一个标志位;
3)在每个单独的任务中执行的时候置位属于这个任务的标志位;
4)在“喂狗”的独立任务中检测这些所有的任务所关联的标志位,
如果所有的标志位都置位成立,说明所有的任务都正常,进行一次喂狗操作。反之则引发一次复位。

There is also a problem that needs to be noted in this approach:

Other tasks can be monitored by this independent task of "feeding the dog". Who will monitor this independent task of "feeding the dog"? The answer is definitely the watchdog.

In this independent "feeding the dog" task, in addition to monitoring the event flags of other tasks, it must also be able to perform the "feeding the dog" operation regularly to prevent the system from resetting due to long-term non-feeding of the dog. In this way, the watchdog can monitor the "feeding the dog" task, while the "feeding the dog" task monitors the status of other tasks.

Special note: Because software development under RTOS environment is different from bare metal development after all, RTOS has operations such as blocking, suspending, deleting, and resuming tasks, so the use of watchdog will be more difficult and needs to be considered comprehensively in the actual usage scenarios.

Of course, the article only briefly analyzes some ideas for using watchdogs. There are many ways to do it. If you think the analysis in the article is wrong, please point it out! If you have better ideas, please share them! ! !

Latest reply

What the boss shares must be good stuff, collection   Details Published on 2023-8-14 19:11
 

6777

Posts

2

Resources
2
 

We have been looking for a solution to the ROTS dog feeding problem for a while.

 
 
 

1w

Posts

16

Resources
3
 

It is not advisable to use a timer to feed the dog on a bare metal machine. The reason is very simple. The program runs away, but the timer does not run and is still feeding the dog.

Comments

Thumbs up~ The timer clicks, the dog is gone  Details Published on 2023-8-15 14:59
 
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 

1972

Posts

0

Resources
4
 

I am now using the same solution as the original poster said, setting the watchdog task to the highest priority, regularly judging the flags of each task, and performing detection

 
 
 

331

Posts

0

Resources
5
 

I learned...

 
 
 

91

Posts

0

Resources
6
 

What the boss shares must be good stuff, collection

 
 
 

4771

Posts

12

Resources
7
 
It is not advisable to use a timer to feed the dog on a bare metal machine. The reason is very simple. The program runs away, but the timer does not run and is still feeding the dog.
Like it ~ The timer feeds, and the dog is gone
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
EBAZ4205 mining board transformation based on Z7010

This post was last edited by chenzhufly on 2019-6-11 00:32 The main changes were to the power supply, adding a serial ...

Prize-giving Event | Tektronix High Precision Power Supply Test Knowledge Planet

Welcome to the Tektronix high-precision power supply test knowledge planet, uncover the fog of noise and discover the re ...

J-linK connection problem

J-link connection problem 1. Keil5 can connect to J-link and burn to the board, but J-falsh cannot connect to J-link, ...

[Flower carving hands-on] Interesting and fun music visualization series of small projects (03) --- RGB rhythmic lights

This post was last edited by eagler8 on 2021-10-7 21:28 I suddenly had the urge to do a series of topics on sound visua ...

Summary: RCSN experience W806 Lianshengde 9.9 yuan development board

@RCSN W806 Lianshengde 9.9 yuan development board experience --- Linux environment development W806 Lianshengde 9.9 yua ...

If signal modulation was like this back then, would you still not be able to learn it?

In previous articles, we have talked about the beauty of electromagnetic waves many times, but can we communicate with e ...

Design and simulation of inout port circuit in Verilog

// Module function description // When the direction control signal "wr_" is "1", y_ is used as output and its value is ...

40 "Millions" of Raspberry Pi Cars - ROS Learning (C Language Programming to Control the Turtle)

This post was last edited by lb8820265 on 2022-11-1 14:52 In the previous section, we introduced how to run the "tu ...

[BIGTREETECH CB1 Core Board & PI4B Trial] Part 5 Performance Test

Performance benchmark test One Pi running score $ time echo "scale=4000;4*a(1)"|bc -l -q 669156 Raspberry Pi 3B take ...

[ST multiple development boards return to the field evaluation] STM32F767 Nucleo-144 UVC-based FRAMEBUFFER-artistic pictures

This post was last edited by qinyunti on 2023-11-1 22:03 Preface Previously, we implemented UVC display in NV12 format. ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list