如何防止看门狗定时器任务启动之前系统挂起 [英] How to prevent system hang before watchdog timer task kicks in

查看:138
本文介绍了如何防止看门狗定时器任务启动之前系统挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用带rtos和文件系统的基于ARM AM1808的嵌入式系统。我们正在使用C语言。我们在应用程序代码内部实现了看门狗计时器。因此,只要应用程序代码出了问题,看门狗定时器就会照顾好系统。

We are using an ARM AM1808 based Embedded System with an rtos and a File System. We are using C language. We have a watchdog timer implemented inside the Application code. So, whenever something goes wrong in the Application code, the watchdog timer takes care of the system.

但是,我们遇到了一个问题,即在看门狗定时器任务启动之前系统挂起。系统挂起,因为文件系统代码编码错误,循环次数如此之多。有时由于NAND错误(或至少文件系统代码认为它不好)而导致代码挂在while循环中并且永远不会消失。我们得到的是一块烂木板。

However, we are experiencing an issue where the system hangs before the watchdog timer task starts. The system hangs because the File System code is badly coded with so many number of while loops. And sometimes due to a bad NAND(or atleast the File System code thinks it is bad) the code hangs in a while loop and never gets out of it. And what we get is a dead board.

因此,提供所有信息的目的是要问你们是否有任何可以在代码中实现的机制在应用程序代码之前运行?有硬件看门狗吗?可以采取什么步骤来确保我们不会因为某些while循环而陷入僵局。

So, the point of giving all the information is to ask you guys whether there is any mechanism which could be implemented in the code that runs before the application code? Is there any hardware watchdog? What steps can be taken in order to make sure we don't get a dead board caused by some while loop.

推荐答案

专业嵌入式系统的设计如下:

Professional embedded systems are designed like this:


  • 选择具有上电复位中断和片上看门狗的MCU。这是所有现代MCU上的标准。

  • 从复位中断向量内部执行以下步骤。

  • 如果MCU存储器易于设置,例如仅设置堆栈指针,然后首先执行重置操作。这样就可以进行C语言编程。

  • 如果内存设置很复杂-有MMU设置或类似设置-它将不得不等待,并且您必须坚持使用汇编程序以防止引起意外堆栈

  • 设置最基本的寄存器,例如模式寄存器,看门狗和系统时钟。

  • 设置低压检测硬件(如果适用)。希望MCU上LVD的复位状态是正确的。

  • 应从此处设置特定于应用的关键寄存器,如GPIO方向和内部上拉电阻寄存器。默认情况下,许多MCU都将引脚用作输入,因此容易受到攻击。如果不打算将它们用作应用程序的输入,则应将其保持复位状态的时间最小化,以避免出现噪声,瞬态和ESD问题。

  • 设置MMU

  • CRT以外的所有内容,例如 .data .bss

  • 调用 main()

  • Pick a MCU with power-on-reset interrupt and on-chip watchdog. This is standard on all modern MCUs.
  • Implement the below steps from inside the reset interrupt vector.
  • If the MCU memory is simple to setup, such as just setting the stack pointer, then do so the first thing you do out of reset. This enables C programming.
  • If the memory setup is complex - there is a MMU setup or similar - it will have to wait and you'll have to stick to assembler to prevent accidental stacking caused by C code.
  • Setup the most fundamental registers, such as mode registers, watchdog and system clock.
  • Setup the low-voltage detect hardware, if applicable. Hopefully the out-of-reset state for LVD on the MCU is a sound one.
  • Application-specific, critical registers such as GPIO direction and internal pull resistor registers should be set from here. Many MCU have pins as inputs by default, making them vulnerable. If they are not meant to be inputs in the application, the time they are kept as such out of reset should be minimized, to avoid problems with noise, transients and ESD.
  • Setup the MMU, if applicable.
  • Everything else "CRT", such as initialization of .data and .bss.
  • Call main().

请注意,MCU的预制启动代码不一定是专业人士编写的!工具链附带一个业余级别的 CRT,这很常见,它无法及早设置看门狗和时钟。这当然是不可接受的,因为:

Please note that pre-made startup code for your MCU is not necessarily made by professionals! It is fairly common that there's an amateur-level "CRT" delivered with your toolchain, which fails to setup the watchdog and clock early on. This is of course unacceptable since:


  1. 如果在 CRT情况下,这会使在该平台上运行的任何程序均面临明显的安全/不良质量风险。 会由于任何原因崩溃/挂起。

  2. 这将初始化 .data .bss 不必要的,痛苦的缓慢,因为它通常是在默认的片上RC振荡器或类似时钟上运行时才执行的。

  1. This makes any program running on that platform a notable safety/poor quality hazard, in case the "CRT" will crash/hang for whatever reason.
  2. This makes the initialization of .data and .bss needlessly, painfully slow, as it is then typically executed with the clock running on the default on-chip RC oscillator or similar.

请注意,即使是事实上的行业启动代码(如ARM CMSIS)也无法完成上述某些特定于MCU的硬件设置。这可能是问题,也可能不是问题。

Please note that even industry de facto startup code such as ARM CMSIS fails to do some of the MCU-specific hardware setups mentioned above. This may or may not be a problem.

这篇关于如何防止看门狗定时器任务启动之前系统挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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