ARM笔记(看门狗)

来源:互联网 发布:weblogic内存溢出linux 编辑:程序博客网 时间:2024/06/03 06:43
看门狗
特点:不断的接受信号或重新设置计数值,保持计数值不为0,一旦一段时间接受不到信号或者计数值为0,看门狗将发出复位信号或者产生中断。
This section includes:
 WDT operation
 WTDAT and WTCNT
 WDT Start
 Consideration of debugging environment

WDT使用PCLK作为其源时钟。 8位预分频器预分频PCLK频率来产生对应的WDT,再将其分频

Valid prescaler values range from 0 to 255. You can select the frequency division factor as: 16, 32, 64, or 128.
Use this equation to calculate the WDT clock frequency and the duration of each timer clock cycle:
t_watchdog = 1/(PCLK/(Prescaler value(8位分频值) + 1)/Division_factor(4选1的值)) //除数不能为0需+1
                      
WTCON


复位后的初始值为0x8000
WDT.WTDAT= 0x8000;经测试如果给wtdat0x8000会自动装载到WTCNT中,若不是0x8000,内部应该会把0x8000给WTCNT,而不会把其他的值给WTCNT,所以允许我们直接装载WTCNT的值


配置寄存器(这里我们只使用复位操作)
     WDT.WTCON=  WDT.WTCON& (~(0xFF << 8)) | (199 << 8);  配置8位分频值
     WDT.WTCON= WDT.WTCON& (~(0x1 << 5)) | (0x1 << 5);  配置wdt使能位
     WDT.WTCON= WDT.WTCON& (~(0x3 << 3)) | (3 << 3);  配置四选一时钟分频值
     WDT.WTCON= WDT.WTCON  | 0x1;  看门狗产生复位信号使能位
     WDT.WTDAT= 10000;  指定超时时间
     WDT.WTCNT= 10000;  存放计数器的值(每经过一个时钟周期WTCNT数值自动减一, 根据文档可知WTDAT寄存器的内容不能自动将加载到定时器计数寄存器WTCNT中因此,在启用之前,应将WTCNT寄存器设置为初始值。

具体代码
/*
 * main.c
 *
 *  Created on: 2017-12-1
 *      Author: Administrator
 */
#include "exynos_4412.h"


int mydata_ms(int time)
{
int i,j;
while(time--)
{
for(i=0;i<5;i++)
for(j=0;j<514;j++);
}


}
void watchdog_init()
{
WDT.WTCON =  WDT.WTCON & (~(0xFF << 8)) | (199 << 8);
WDT.WTCON = WDT.WTCON & (~(0x1 << 5)) | (0x1 << 5);
WDT.WTCON = WDT.WTCON & (~(0x3 << 3)) | (3 << 3);
WDT.WTCON = WDT.WTCON  | 0x1;
//WDT.WTDAT = 0x8000;
WDT.WTCNT = 10000;


}


void main()
{
//led_init();
GPX1.CON = GPX1.CON & (~(0xf)) | 0x1;
watchdog_init();




while(1)
{
GPX1.DAT = 0x1;
// mydata_ms(1000);
//GPX1.DAT = ~(0x1);
// mydata_ms(1000);
// WDT.WTCNT = 10000;


}
return 0;


}