tag 标签: watchdog

相关博文
  • 热度 1
    2019-4-3 16:55
    1224 次阅读|
    0 个评论
    By Toradex 胡珊逢 1). 简介 在嵌入式领域中 Watchdog 看门狗通常被作为用于应对系统或者应用意外崩溃的有效手段。其可以在程序执行出错并无法恢复的情况下,自动重启应用甚至复位整个系统,从而使系统脱离宕机状态,恢复正常业务执行。这对于涉及到人身、财产安全的应用,显得极为重要。本文将基于 NXP iMX6 嵌入式平台如何使用看门狗进行介绍,应对 Linux 系统或者应用程序意外崩溃。 本文所演示的 iMX6 平台来自于 ToradexColibri iMX6 计算机模块, iMX6 芯片自带看门狗功能,其硬件和早期的 iMX2 一致,所以看门狗驱动仍然沿用 imx2-wdt 。看门狗只支持单用户操作,即只能有一个实例来使用看门狗。因此在 Linux 系统中,用户可以选择由自己的应用直接使用看门狗,但只限于一个进程。看门狗只监控该应用,对于 Linux 本身或者其他应用则无法在意外崩溃的情况下触发看门狗复位。或者使用 systemd (183 以后的版本 ) 来操作硬件看门狗,同时为用 systemd 所管理的单元提供软件逻辑看门狗。硬件看门狗主要应对 Linux 内核以及 systemd 自身的崩溃,软件逻辑看门狗则可以用于用户自己的应用,且不受数量限制。 2). 用户应用操作 ./ 首先在 U-Boot 中设置看门狗超时时间,这里设置为 60 秒。 ------------------------ setenv defargs $defargs imx2-wdt.timeout=60 saveenv ------------------------ ./ 编译完成后运行 测试程序 。 ------------------------ root@colibri-imx6:~# ./wdt-sample-app & 627 ------------------------ ./ 终结该测试程序进程。当进程被终结后,看门狗仍旧保持运行,但是无法定时喂狗。因此,在 60s 超时后,看门狗会复位系统。 ------------------------ root@colibri-imx6:~# kill 627 root@colibri-imx6:~# watchdog: watchdog0: watchdog did not stop! + Terminated ./wdt-sample-app ------------------------ ./ 当模块由于看门狗复位时,可以从 U-Boot 启动的串口日志发现复位的原因。 ------------------------ U-Boot 2016.11-2.8.5+g02735f4004 (Dec 28 2018 - 01:54:12 +0000) CPU: Freescale i.MX6DL rev1.1 at 792 MHz Reset cause: WDOG I2C: ready DRAM: 512 MiB ------------------------ 3). Systemd 操作 a). 对于需要使用看门狗监控多个应用,可以使用 systemd 来操作。 Systemd 提供硬件看门狗和软件看门狗支持。硬件看门狗用于监控 Linux 内核以及 systemd 自身的运行,一旦出现内核崩溃的情况,看门狗超时将触发系统复位。在 systemd 中使用硬件看门狗非常简单,只需要配置 /etc/systemd/system.conf 中的 RuntimeWatchdogSec= 参数,将其设置超时时间即可。在规定时间如果没有喂狗,将触发复位。 systemd 通常会在所设置时间的一半为间隔进行喂狗。 ShutdownWatchdogSec= 则可以设置关机超时时间,如果系统在该时间内没有完成关机,也将系统复位。 ./ 为了触发内核崩溃的情况,我们需要开启内核调试的 MAGIC_SYSRQ 功能,该选项在 Toradex 默认的 Linux BSP 中是关闭的。打开后重新编译内核。 ------------------------ CONFIG_MAGIC_SYSRQ=y CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE=0x1 CONFIG_DEBUG_KERNEL=y ------------------------ ./ 设置超时时间为 60 秒, RuntimeWatchdogSec=60 。 启动查看系统日志,显示硬件看门狗超时时间被设置为 1 分钟。 ------------------------ root@colibri-imx6:/etc/systemd# dmesg|grep watchdog systemd : Hardware watchdog 'imx2+ watchdog', version 0 systemd : Set hardware watchdog to 1min. ------------------------ ./ 然后我们用下面命令触发内核崩溃。 ------------------------ /proc/sysrq-trigger ------------------------ ./ 一分钟以后,由于 systemd 没有对进行喂狗操作,系统将复位后重新启动。 b). 除了硬件看门狗外, sytemd 还提供软件看门狗,每个 systemd service 都可以使用。 service 需要读取 WATCHDOG_USEC= 参数,确定看门狗超时时间,并在该时间范围内使用 sd_notify("WATCHDOG=1") 喂狗,同样喂狗的时间间隔为 WATCHDOG_USEC= 所设置的一半。 ./ 用户只要在对应的 systemd service 文件中设置 WatchdogSec= 参数即可,而 WATCHDOG_USEC= 将根据前面的参数自动被设置。在应用程序中以 WatchdogSec/2 的间隔调用 sd_notify 函数发送 "WATCHDOG=1" 进行喂狗操作。例如 ------------------------ // Systemd servier 文件 (/etc/systemd/system/test.service) ,用于启动用户应用 Description=Watchdog Test service ExecStart=/home/root/wdt-sw-test WatchdogSec=30s Restart=on-failure StartLimitInterval=5min StartLimitBurst=4 StartLimitAction=reboot WantedBy=multi-user.target ------------------------ ./ 用户应用 wdt-sw-test.c ,并定期执行喂狗操作(编译的时候需要使用 -lsystemd 链接 systemd 库文件)。 在应用初始化后需要通知 systemd 管理器本应用正常启动, sd_notify (0, "READY=1"); 。然后根据 WATCHDOG_USEC 变量设置喂狗间隔。在应用中我们将模拟一次超时喂狗,从而引起应用重启。 ./ 下面是运行日志。起初应用程序 wdt-sw-test 由 systemd 加载启动, PID=396 ,并以 15s 间隔喂狗(该时间源自 WatchdogSec=30s )。当喂狗超时后, systemd 会发送信号 SIGABRT 终止该进程,并重启该应用,新 PID=647 。 ​ ./ 在 service 文件中,我们还配置了 StartLimitBurst 和 StartLimitInterval 以及 StartLimitAction 参数。这使得在 StartLimitInterval 时间内应用启动次数超过 StartLimitBurst 后,将不被允许再次启动,并触发 StartLimitAction 的操作。具体描述请参考 systemd.unit 。 3). 总结 看门狗对于关键应用,以及大多数的一般应用来讲是一个很重要的功能,其能够应对 Linux 系统或者应用崩溃的情况,避免用户设备处于失控的状态。当整个系统只有一个嵌入式设备作为决策控制单元时,对于关键的安全应用,根据单一故障准则,我们还建议引入辅助控制单元,例如额外的 MCU 等做同步监测,或者使用保险丝、热电偶等,当出现超限情况,能够执行紧急操作,从而进一步提高设备的安全性。
  • 热度 18
    2016-3-14 19:02
    1173 次阅读|
    1 个评论
    I have written extensively about designing ultra-low power systems that operate from coin cells. Unfortunately, a lot of vendor information is gilded with marketing malarkey; we engineers have to separate fact from aspiration and design using worst-case analysis.   Quite a few people have written asking about using watchdog timers (WDT) in battery-operated systems that achieve years-long life by snoozing 99+ percent of the time. The system may be dead to the world for hours – how does one service a WDT when the code isn’t running?   Why would you want to? How can the software crash when it’s not running?   The answer is that the code can fail while awake and accidently enter a sleep state. Running the WDT during sleep ensures the system will recover.   One could wake up once a minute or so and tickle the watchdog. Generally that only requires a handful of instructions. Even when running from a 32 kHz clock (typical for ultra-low power sleep modes) the tickle will only need a ms or so of awake time. If the MCU consumes 50 uA while servicing the WDT that’s just 7.5 uAh per year of operation. Given that a CR2032 coin cell has about 220 mAh of capacity, the energy needed for managing the WDT is insignificant.   But the reality is a bit more complex. We have to work with real parts, not idealized devices.   I looked at a typical microcontroller from Microchip, picked at random from their incredibly diverse selection of “XLP” (extremely low power) devices. The PIC16LF1704/8 is a nice 8 bitter with gobs on on-board I/O, including a watchdog timer. In the low-power sleep mode the WDT consumes 14-17 uA. I started engineering when a microprocessor needed a huge honking power supply, so this is an incredibly small number. But it’s too much for long-lived coin cell operation. That compendium I referenced demonstrates that for 10 years of life from a coin cell the average current consumed can’t exceed 2.5 uA. That watchdog is unusable in this environment.   (I didn’t do an exhaustive search; possibly other MCUs from Microchip have lower-current WDTs. And I commend them for publishing these worst-case numbers; too many other vendors don’t.)   A competing MCU from TI, the MSP430F11x1a, takes only 1 to 3.4 uA in the lowest-power sleep that still has an oscillator running (to support the WDT). Nice, but 3.4 uA is far too much for these applications. The better figures assume Vdd is 2.2 volts and it’s not hot. No incremental current is listed for turning on the watchdog, which suggests that is included in these figures. However, the user’s guide reads “When the watchdog timer is not required, the WDTHOLD bit can be used to hold the WDTCNT, reducing power consumption.” That sounds like there is some undocumented hit for using that peripheral. Is it a nanoamp or do you have to run jumper cables to a car battery? Sans data, engineers are left adrift.   Other vendors are equally vague.   Since the code can’t crash while sleeping, leave the WDT turned off during those long periods. Enable it while awake. Running, a crash will be mediated by the operating WDT. The upside of this approach is that, since the MCU is awake for such short periods, the current consumed by the WDT is insignificant and won’t drain the battery.   While awake, of course, a crash could vector to the code that disables the watchdog before going to sleep. Instead, structure the code to initialize a variable to a known value, and add offsets to it while running. That could be done in functions that are always called. Before executing the SLEEP instruction check to see if that variable contains a value that indicates the code executed correctly. Take recovery action if the variable is not correct. Or, if basically the same code runs during each awake cycle, use a timer to measure execution time; error if it deviates much from nominal.   There are other failure modes. The firmware could be perfect, but an external event – EMI or a cosmic ray impact – may scramble the MCU’s neurons. Perhaps the program counter gets altered. When the MCU wakes up it will resume operation at a random address without re-enabling the WDT. Or maybe the event flips a bit in the sleep logic so the microcontroller never wakes up.   Essentially, one would need a watchdog that operates during sleep times to counter these threats. Internal WDTs use too much current. I can’t come up with a circuit that would consume the microamp or less one can budget to a watchdog. Some of you are building long-lived battery-operated devices that sleep most of the time. For high-reliability applications, how do you implement a watchdog timer?
相关资源
  • 所需E币: 1
    时间: 2022-7-23 10:51
    大小: 188.18KB
    上传者: Argent
    PLCtoPLCHeartbeatWatchdog
  • 所需E币: 5
    时间: 2020-6-25 16:23
    大小: 573.05KB
    上传者: kaidi2003
    AND9992-D_ONSEMI_UsingtheWindowWatchdogTimerFunctionoftheNCV97200.PDF
  • 所需E币: 5
    时间: 2019-12-25 21:44
    大小: 62.02KB
    上传者: 238112554_qq
    新型双路微功率处理器监控电路TPS3306系列设计用于DSP和处理器系统要求两个电源电压的电路初始化和定时监控。TPS3306集成Watchdog(WDI)功能,来监视处理器工作。……
  • 所需E币: 3
    时间: 2019-12-24 19:34
    大小: 103.03KB
    上传者: 16245458_qq.com
    摘要:看门狗定时器用于监视和尽量减少代码执行错误。内部看门狗定时器会遵守执行问题的代码,使外部看门狗电路宝贵在防止系统锁定。Maxim>AppNotes>AUTOMOTIVEMICROPROCESSORSUPERVISORCIRCUITSKeywords:watchdogtimer,watchdogcircuit,windowed,reset,adjustablewatchdog,capacitoradjustableMar13,2003watchdogAPPLICATIONNOTE1926WatchdogsImproveSystemReliability―HowtoChoosetheRightPartAbstract:Watchdogtimersareusedtomonitorandminimizecodeexecutionerrors.Internalwatchdogtimersaresubjecttocodeexecutionproblems,makingexternalwatchdogcircuitsinvaluableinpreventingsystemlockup.Thisdocumentprovidesassistanceinselectingtherighttimeofwatchdog/supervisoryproductfordifferenttypeofapplicationsandhowtoapplythecircuitwithoutthesoftwarecode.Manycircuitfunctionspreviouslyrealizedwithdedicatedhardwarearenowimplementedinsoftware,du……
  • 所需E币: 4
    时间: 2019-12-24 19:29
    大小: 74.85KB
    上传者: 二不过三
    摘要:了解µP主管来确保适当的系统操作期间通电、电源关闭和灯火情况(欠压监控)的价值。此外,提供有关过电压和窗口的监测信息。描述手动重置、看门狗定时器、备用电池和芯片启用浇注等附加功能。讨论需要多电压监测。Maxim>AppNotes>AUTOMOTIVEMICROPROCESSORSUPERVISORCIRCUITSKeywords:POR,poweronreset,uPreset,uPsupervisors,voltagemonitor,resettimeout,undervoltage,Sep01,2000overvoltage,monitoring,windowedreset,batterybackup,watchdogcircuit,microprocessorsupervisorsAPPLICATIONNOTE279SupervisoryCircuitsKeepYourMicroprocessorUnderControlAbstract:UnderstandthevalueofaPsupervisortoensurepropersystemoperationduringpower-up,power-down,andbrownoutsituations(undervoltagemonitoring).Inaddition,providesinformationaboutovervoltageandwindowedmonitoring.Describesadditionalfeaturessuchasmanualreset,watchdogtimer,batterybackup,andchipenablegating.Discussestheneedformulti-voltagemonitoring.Microprocessor-superviso……
  • 所需E币: 3
    时间: 2019-12-24 19:04
    大小: 57.49KB
    上传者: 2iot
    摘要:添加看门狗保护的充电器的输入电路免受损害了手机卫士,当基带处理档或停止软件的执行。Maxim>AppNotes>BATTERYMANAGEMENTMICROPROCESSORSUPERVISORCIRCUITSKeywords:mobilephones,batterycharging,microprocessorsupervisors,pulse-widthmodulation,watchdogSep16,2005protectionAPPLICATIONNOTE3623Battery-ChargerPWMInputHasWatchdogProtectionAbstract:Addingwatchdogprotectiontothecharger-inputcircuitryofamobilephoneguardsagainstdamagewhenthebasebandprocessorstallsorceasessoftwareexecution.Mobile-phonebatteriesareusuallychargedthroughaproprietarychargingalgorithminthebasebandcontroller.Thephone'schargerinputisconnectedtotheinternalbatterythroughap-channelswitchoflowon-resistance,controlledbyapulse-widthmodulation(PWM)signalfromthebasebandcontroller(Figure1).Tominimizepowerdissi……
  • 所需E币: 4
    时间: 2019-12-24 18:35
    大小: 68.94KB
    上传者: wsu_w_hotmail.com
    摘要:随着电子系统的许多在机械功能采取的汽车范围从发动机正转向和制动,是关于容错的日益关注。不应该有一个单点故障会阻止一辆车至少“一瘸一拐”偏离了道路,或到就近的服务站。用于重新路由信号,并执行其他功能,以确保车辆可以安全地使其偏离了道路发生故障时的冗余系统,看门狗定时器,和其他控制电路。Maxim>DesignSupport>TechnicalDocuments>ApplicationNotes>CircuitProtection>APP4210Keywords:limphome,faulttolerance,highvoltage,watchdogtimer,ECU,automotivesafety,redundantsystemJan05,2012APPLICATIONNOTE4210High-VoltageWatchdogTimersEnhanceAutomotiveSystemSafetyBy:RobertRegensburger,AutomotiveSpecialist,AutomotiveProductDefinitions,MaximIntegratedProducts,GermanyJan05,2012Abstract:Aselectronicsystemstakeovermanyofthemechanicalfunctionsinacar―rangingfromenginetimingtosteeringandbraking―thereisagrowingconcernaboutfaulttolerance.Thereshouldnotbeasinglepointoffailurethatwould……
  • 所需E币: 4
    时间: 2019-12-24 18:34
    大小: 56.51KB
    上传者: 238112554_qq
    摘要:基于对μP-supervisor/watchdogIC(MAX6749),该电路在输入脉冲流的损失提供了一个锁定的失效指示。该电路可以监控风扇(根据风扇的转速输出),一个振荡器,或微处理器的软件执行。Maxim>AppNotes>CircuitprotectionMicroprocessorsupervisorcircuitsKeywords:watchdogtimers,latchedwatchdogtimers,microprocessorsupervisorsJan05,2011APPLICATIONNOTE4558SimpleLatchingWatchdogTimerBy:EricSchlaepfer,ApplicationsEngineerAbstract:BasedonaP-supervisor/watchdogIC(MAX6749),thiscircuitprovidesalatchedfailureindicationinresponsetoalossoftheinputpulsestream.Thecircuitcanmonitorafan(basedonthefan'stachometeroutput),anoscillator,orthesoftwareexecutionofamicroprocessor.AsimilarversionofthisarticleappearedintheApril2007issueofPowerElectronicsTechnologymagazine.Mostwatchdog-timerICsproduceasingle,limited-durationoutputpulsewhenthewatchdogtime……
  • 所需E币: 3
    时间: 2019-12-24 17:57
    大小: 53.64KB
    上传者: givh79_163.com
    摘要:日前,Teridian71M6515H,3相电能仪表IC,电源故障输入引脚(VFLT)控制IC的看门狗定时器。本应用笔记介绍本VFLT引脚连接正确。71M6515HEnergyMeterICAMaximIntegratedProductsBrandAPPLICATIONNOTEAN_6515H_004JANUARY2011ConnectingtheVFLTPinofthe71M6515HThisdocumentdescribestheproperconnectionoftheVFLTpincontrollingthebuilt-inwatchdogtimerofthe71M6515HEnergyMeterICs.BackgroundTheVFLTpinisusedtomonitoranexternalDCvoltagerepresentativeoftheon-boardDCsupplyvoltage……
  • 所需E币: 3
    时间: 2020-1-15 13:34
    大小: 106.99KB
    上传者: 16245458_qq.com
    看好您的watchdog广州周立功单片机发展有限公司Tel:(020)38730916387309173873097638730977Fax:38730925看好您的WATCHDOG1引子当系统处于一些比较的恶劣环境工控底层采集现象这时硬件电路并没有损坏听中的单片机出现死机单片机出现死机除死机死机问题如果系统的抗干扰没有作好则容易出现死机必须复位才能恢复如果是洗衣机或随身只是内部程序运行出现错误那么重新开机一次就可以了影响不大但如果是复费率电度表或温控仪中的一般情况下呢设计者会采用看门狗来解决灵则会影响电度表的计量或造成温度失控的事故因此了解死机产生的原因并消看门那就取决于您怎么设计和使用它了挥之即去其二的影响是单片机系统抗干扰设计中重要的一个环节但是您的看门狗是不是在乖乖地帮您WDTEWDSE来控制它可以使您事半功倍驯服活使用LPC900系列FLASH单片机的看门狗字里专门开辟了两个位只有一个字节简单好用其一LPC900系列单片机在芯片的配置它的控制寄存器使得它呼之则来下面就一起来看看如何我们的看门狗2看门狗功能与介绍看门狗定时器子系统可通过复位使系统从错误的操作中恢复当软件没能在定时器溢出之前将其清零看门狗定时器就会导致系统产生一次复位2.1看门狗功能相关寄存器LPC900系列单片机有4个SFR用于看门狗功能看门狗控制寄存器7PRE26PRE1WDCON5PRE0地址A7H432WDRUN1WDTOF0WDCLKPRE2PRE1PRE0时钟预分频器节拍选择保留位看门狗运行控制序列将清零该位详见表2.2为0时看门狗停止一个……
  • 所需E币: 4
    时间: 2019-12-29 00:03
    大小: 54.5KB
    上传者: 微风DS
    Addingwatchdogprotectiontothecharger-inputcircuitryofamobilephoneguardsagainstdamagewhenthebasebandprocessorstallsorceasessoftwareexecution.……
  • 所需E币: 5
    时间: 2019-12-24 17:04
    大小: 36.88KB
    上传者: 16245458_qq.com
    摘要:操作无需使用微控制器的数字电位。手动增加一个简单的按钮电路向上/向下。完善的手动控制,需要设置一个特定的水平,成本敏感的应用。Maxim/Dallas>AppNotes>DIGITALPOTENTIOMETERSGENERALENGINEERINGTOPICSKeywords:digitalpotentiometer,digipot,watchdogtimer,switchdebouncer,esdprotection,digitalpots,Jun01,2001potentiometers,pushbuttoncircuitAPPLICATIONNOTE1118ManuallyOperatedDigitalPotentiometerDoesn'tNeedaMicroprocessorOperateadigitalpotentiometerwithouttheuseofamicrocontroller.Manuallyincrementup/downwithasimplepush-buttoncircuit.Perfectforcostsensitiveapplicationswheremanualcontrolsarerequiredtosetaparticularlevel.DigitalpotentiometerICssuchastheMAX5160andMAX5161aregoodreplacementsformechanicaltypes.ButtheseICsaredesignedtoworkwithmicrocontrollers.Inthismanuallyoperateddigitalpotentiometer,twopushbuttonsc……