微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > DSP学习交流 > + 巩固系统稳定性---看门狗

+ 巩固系统稳定性---看门狗

时间:10-02 整理:3721RD 点击:
为了增加系统的运行稳定性,看门狗是必不可少的。在系统运行以后也就启动了看门狗的计数器,看门狗就开始自动计数,如果到了一定的时间还不去清看门狗,那么看门狗计数器就会溢出从而引起看门狗中断,造成系统复位,所以在使用有看门狗的芯片时要注意清看门狗。
以官方例程为例
初始化看门狗的程序如下

  1. void TimerWatchDogInit(void)
  2. {
  3.     // 配置 定时器 / 计数器 1 为 看门狗模式
  4.         TimerConfigure(SOC_TMR_1_REGS, TMR_CFG_64BIT_WATCHDOG);
  5.        
  6.     // 设置周期 64位
  7.     TimerPeriodSet(SOC_TMR_1_REGS, TMR_TIMER12, TMR_PERIOD_LSB32);
  8.     TimerPeriodSet(SOC_TMR_1_REGS, TMR_TIMER34, TMR_PERIOD_MSB32);

  9.     // 使能看门狗定时器
  10.     TimerWatchdogActivate(SOC_TMR_1_REGS);
  11. }

复制代码

其中

  1. #define SOC_TMR_1_REGS                      (0x01C21000)

复制代码


这个地址的确定在数据手册中。


TimerConfigure函数的原型为:

  1. void TimerConfigure(unsigned int baseAddr, unsigned int config)
  2. {

  3.     /*
  4.     ** Set the timer control register. This will only affect the clock
  5.     ** selection bits. All other fields will be reset and the timer counting
  6.     ** will be disabled.
  7.     */
  8.     HWREG(baseAddr + TMR_TCR) = (config & (TMR_TCR_CLKSRC12 | TMR_TCR_CLKSRC34));

  9.     /* Clear the Timer Counters */
  10.     HWREG(baseAddr + TMR_TIM12) = 0x0;
  11.     HWREG(baseAddr + TMR_TIM34) = 0x0;

  12.     /* Clear the TIMMODE bits and Reset bits */
  13.     HWREG(baseAddr + TMR_TGCR) &= ~( TMR_TGCR_TIMMODE | TMR_TGCR_TIM34RS |
  14.                                      TMR_TGCR_TIM12RS);

  15.     /*
  16.     ** Select the timer mode and disable the timer module from Reset
  17.     ** Timer Plus features are enabled.
  18.     */
  19.     HWREG(baseAddr + TMR_TGCR) |= (config &
  20.                                    (TMR_TGCR_TIMMODE | TMR_TGCR_TIM34RS |
  21.                                     TMR_TGCR_TIM12RS | TMR_TGCR_PLUSEN));
  22. }

复制代码


其中主要设置了TMR_TGCR寄存器,设为看门狗模式


TimerPeriodSet函数的原型为:

  1. void TimerPeriodSet(unsigned int baseAddr, unsigned int timer,
  2.                     unsigned int period)
  3. {
  4.     if(TMR_TIMER12 & timer)
  5.     {
  6.         /* Write the period for Timer12 */
  7.         HWREG(baseAddr + TMR_PRD12) = period;
  8.     }

  9.     if(TMR_TIMER34 & timer)
  10.     {
  11.         /* Write the period for Timer34 */
  12.         HWREG(baseAddr + TMR_PRD34) = period;
  13.     }
  14. }

复制代码


主要设置定时器的周期为

  1. #define TMR_PERIOD_LSB32  (0x07270E00)

复制代码

0x07270E00/24000000=5
定时时间为5秒.
包括看门狗定时器(定时器 / 计数器 1)的时钟来源于 PLL 旁路时钟,即 晶体振荡器的时钟 24MHz。
TimerWatchdogActivate函数的原型为:

  1. void TimerWatchdogActivate(unsigned int baseAddr)
  2. {
  3.     /* Enable the watchdog timer. Write the keys in the order */
  4.     HWREG(baseAddr + TMR_WDTCR) = ((TMR_WDTCR_WDEN | TMR_WDTCR_WDFLAG) |
  5.                                   (WDT_KEY_PRE_ACTIVE << TMR_WDTCR_WDKEY_SHIFT));
  6.     HWREG(baseAddr + TMR_WDTCR) = ((HWREG(baseAddr + TMR_WDTCR) &
  7.                                     (~TMR_WDTCR_WDKEY)) |
  8.                                    (WDT_KEY_ACTIVE << TMR_WDTCR_WDKEY_SHIFT));
  9.                                        
  10. }

复制代码


对TMR_WDTCR寄存器的配置:


而这些寄存器的偏移量在手册中


以上就是看门狗的配置流程。

广告吧     还是      看着不错

不是广告,小编是6748试用者里的大神

在线调试的时候看门狗是不是要影响复位?

调试时肯定要关看门狗的。要不总是复件,没法调试

,我当时就是开了看门狗,在线调试,想想真傻!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top