1、watchdog timer(WDT_A)看门狗定时器?
看门狗定时器32bit定时器,能被用作看门狗或者作为一个间隔定时器。
在看之前,给自己几个问题
a、看门狗依赖于时钟配置吗?
b、多长时间喂狗,软件喂狗(定时器)?时间长短如何配置?
c、看门狗重启和软件重启以及硬件重启的区别?
看门狗定时器模块的主要功能是在软件问题发生时执行系统重启;如果指定的时间到还不喂狗,就会系统复位。
如果在应用中不需要看门狗功能,看门狗模块可以配置成一个间隔定时器并且在指定时间间隔产生中断。
看门狗定时器模块特性:
8个软件选择的时间间隔
看门狗模式
间隔模式
密码保护访问看门狗定时器控制寄存器
可选的时钟源
停止用于节约电力
时钟自动防故障特性
注意:看门狗定时器上电激活
PUC(上电清除复位信号)后, WDT_A模块自动配置成看门狗模式,使用SMCLK为时钟源,~32ms复位间隔;所以用户必须在初始复位间隔超时前设置或者停止WDT_A模块;
Msp430f5438a.cmd (c:\ti\ccsv5\ccs_base\msp430\include)
WDTCTL = 0x015C;
/*! when 0 the watchdog timer and interrupt is used and an invalid password
* is used to reset the part, when 1 the watchdog expiring will cause the micro
* to reset and if ACLK goes away VLOCLK will be used.
*/
#define USE_FAILSAFE_WATCHDOG ( 1 )
#define WDTPW (0x5A00)
#define WDTCNTCL (0x0008) /* WDT - Timer Clear */
#define WDTSSEL__ACLK (1*0x0020u) /* WDT - Timer Clock Source Select: ACLK */
#define WDTIS_3 (3*0x0001u) /* WDT - Timer Interval Select: /512k */
void ResetWatchdog(void)
{
/* set watchdog for 16 second timeout
* write password, select aclk, WDTIS_3 means divide by 512*1024 = 16 s;
* WDTIS_2: 4 mins
* Any write operation to WDTCTL must be a word operation with 05Ah (WDTPW) in the upper byte
*/
#ifUSE_FAILSAFE_WATCHDOG
/* wathdog 看门狗功能 */
WDTCTL = WDTPW + WDTCNTCL + WDTSSEL__ACLK + WDTIS_3;
/* Interrupt Enable Register 中断使能寄存器 ,*/
SFRIE1 &= ~WDTIE; /* disable watchdog timer interrupt */
#else
/* interval timer 间隔定时器 */
WDTCTL = WDTPW + WDTCNTCL + WDTSSEL__ACLK + WDTIS_3 + WDTTMSEL;
/* enable watchdog timer interrupt */
SFRIE1 |= WDTIE;
#endif
}
在idle线程中会调用void ResetWatchdog(void),以及任务耗时的地方等都需要适当喂一下狗