在多任务环境中饲养看门狗的策略 [英] Strategy for feeding a watchdog in a multitask environment

查看:247
本文介绍了在多任务环境中饲养看门狗的策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将一些嵌入式代码移植到FreeRTOS后,我对这个看门狗留下了一个有趣的困境。看门狗定时器是我们应用的必需品。使用FreeRTOS对我们来说也是一个巨大的福音。当应用程序更加单一的任务时,它会及时地向监督机构提供逻辑流程,以便我们能够及时确保任务正在顺利进行。



有多个任务,但这并不容易。一个任务可能由于某种原因而不能取得进展,但另一个任务是做得很好,并且取得了足够的进展,以便让监督者高兴地进入。



有一种想法是启动一个单独的任务,只是为了给看门狗喂食,然后使用一些计数器,其他任务定期增加,当看门狗任务打勾时,它将确保所有的计数器看起来都像所有其他任务一样进行,如果所以,继续喂养看门狗。



我很好奇别人在这样的情况下做了什么?

解决方案

监视所有其他任务的状态的看门狗任务是一个很好的解决方案。但是,代替计数器,请考虑为每个任务使用状态标志。状态标志应有三个可能的值:UNKNOWN,ALIVE和ASLEEP。当周期性任务运行时,它将标志设置为ALIVE。阻止异步事件的任务应在其运行之前阻止和ALIVE时将其标志设置为ASLEEP。当看门狗监视器任务运行时,如果每个任务都是ALIVE或ASLEEP,它应该启动看门狗。然后看门狗监视器任务应将所有ALIVE标志设置为UNKNOWN。 (ASLEEP标志应保持ASLEEP)。在监视器任务再次启动看门狗之前,具有UNKNOWN标志的任务必须运行并将其标志设置为ALIVE或ASLEEP。



有关详细信息,请参阅本文的多任务部分: http://www.embedded .com / design / debug-and-optimization / 4402288 /看门狗定时器


Having moved some embedded code to FreeRTOS, I'm left with an interesting dilemma about the watchdog. The watchdog timer is a must for our application. Using FreeRTOS has been a huge boon for us too. When the application was more single-tasked, it fed the watchdog at timely points in its logic flow so that we could make sure the task was making logical progress in a timely fashion.

With multiple tasks though, that's not easy. One task could be bound up for some reason, not making progress, but another is doing just fine and making enough progress to keep the watchdog fed happily.

One thought was to launch a separate task solely to feed the watchdog, and then use some counters that the other tasks increment regularly, when the watchdog task ticks, it would make sure that all the counters looked like progress was being made on all the other tasks, and if so, go ahead and feed the watchdog.

I'm curious what others have done in situations like this?

解决方案

A watchdog task that monitors the status of all the other tasks is a good solution. But instead of a counter, consider using a status flag for each task. The status flag should have three possible values: UNKNOWN, ALIVE, and ASLEEP. When a periodic task runs, it sets the flag to ALIVE. Tasks that block on an asynchronous event should set their flag to ASLEEP before they block and ALIVE when the run. When the watchdog monitor task runs it should kick the watchdog if every task is either ALIVE or ASLEEP. Then the watchdog monitor task should set all of the ALIVE flags to UNKNOWN. (ASLEEP flags should remain ASLEEP.) The tasks with the UNKNOWN flag must run and set their flags to ALIVE or ASLEEP again before the monitor task will kick the watchdog again.

See the "Multitasking" section of this article for more details: http://www.embedded.com/design/debug-and-optimization/4402288/Watchdog-Timers

这篇关于在多任务环境中饲养看门狗的策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆