arm-linux 看门狗,S3C6410看门狗源码实例

当系统运行受到外部干扰或者系统错误,程序有时会出现跑飞,导致整个系统瘫痪。他会设置一段时间,当超出这段 时间,从程序中跳出进入中断处理程序。WatchDog本质上是一种定时器,那么普通定时器拥有的特性它也应该具备,是的当它计时超时时也会引起事件的发生,只是这个事件除了可以是系统中断外,他也可以是一个系统重启信号(Reset Signal)。可以这么说,能发送系统重启信号的定时器我们就叫它WatchDog。看门狗定时器中断是我们不希望看到的,因此我们要想方设法避免它发生。主要的方法就是在中断发生前,重新对看门狗定时器的寄存器进行赋值,使它的定时器重新开始记时,这种方法俗称喂狗。

S3C6410看门狗定时器的功能:

作为常规时钟,并且可以产生中断

作为看门狗定时器使用,当时钟计数器减为零时,它将产生一个复位信号。

The S3C6410XRISC microprocessor watchdog timer is used to resume the controller operation wheneverit is disturbed by malfunctions such as noise and system errors. The watchdogtimer generates the reset signal.

FEATURES

The WatchdogTimer includes the following features:

? Normal interval timer mode with interruptrequest.

? Internal reset signal is activated when thetimer count value reaches 0 (time-out).

? Level-triggered Interrupt mechanism.

0056744d799c2578396d850db309f4ac.gif

看门狗模块包括一个8位预分频器,一个分频器,一个16bit计数器。它的8位预分频器把PCLK分频后,再被分频得到4种频率,16分频,32分频,64分频,128分频。WatchDog可以选择工作于哪种频率下。S3C2440用3个寄存器对WatchDog进行操作:

看门狗定时器控制寄存器(WTCON)

看门狗定时器数据寄存器(WTDAT)

看门狗定时器计数寄存器(WTCNT)

Figure 34-1shows the functional block diagram of the watchdog timer. The watchdog timeruses only PCLK as its source clock. The PCLK frequency is prescaled to generatethe corresponding watchdog timer clock, and the resulting frequency is dividedagain.

The prescalervalue and the frequency division factor are specified in the watchdog timercontrol (WTCON)register. Valid prescaler values range from 0 to 28-1. Thefrequency division factor can be selected as 16, 32, 64,or 128.

Use thefollowing equation to calculate the watchdog timer clock frequency and theduration of each timer clock cycle:

t_watchdog = 1/( PCLK / (Prescaler value + 1) / Division_factor )

注意:

1、Once the watchdog timer is enabled, the value ofwatchdog timer data (WTDAT) register cannot be automatically reloaded into thetimer counter (WTCNT). For this reason, an initial value must be written to thewatchdog timer count (WTCNT) register, before the watchdog timer starts.

2、When the S3C6410 is in debug mode using EmbeddedICE, the watchdog timer must not operate.The watchdog timer can determinewhether or not it is currently in the debug mode from the CPU coresignal(DBGACK signal). Once the DBGACK signal is asserted, the reset output ofthe watchdog timer is not activated as the watchdog timer is expired.

看门狗寄存器映射:

61439a926379bc071bc67912d3f988bc.gif

1、WATCHDOG TIMER CONTROL(WTCON) REGISTER

WTCON允许用户使能看门狗定时器,从不同四个源选择时钟,使能中断,使能看门狗定时器输出。S3C6410看门狗定时器用于系统故障后复位。如果不希望复位,则使能定时器无效。

The WTCONregister allows the user to enable/disable the watchdog timer, select the clocksignal from 4 different sources, enable/disable interrupts, and enable/disablethe watchdog timer output.

The Watchdogtimer is used to resume the S3C6410 restart on mal-function after its power on.At this time,disable the interrupt generation and enable the Watchdog timeroutput for reset signal.

If controllerrestart is not desired and if the user wants to use the normal timer only,which is provided by the Watchdog timer, enable the interrupt generation anddisable the Watchdog timer output for reset signal.9e80b21f09ccdc8d539eb315a47ceb3a.gif

注意:Initial state of ‘Reset enable/disable’ is 1(reset enable). If user do notdisable this bit, S3C6410 will be rebooted in about 5.63sec (In the case ofPCLK is 12MHz). So at boot loader, this bit should be disabled before undercontrol of Operating System, or Firmware.

2、WATCHDOG TIMER DATA (WTDAT) REGISTER

WTDAT用于确定超时期限。WTDAT的内容在最初的定时器操作时不能自动加载到定时器计数其中。但使用0x8000将驱使第一次超时,在这种情况下,WTDAT的值将自动载入WTCNT。

The WTDATregister is used to specify the time-out duration. The content of WTDAT cannotbe automatically loaded into the timer counter at initial watchdog timeroperation. However, using 0x8000 (initial value of WTCNT)will drive the firsttime-out. Then, the value of WTDAT will be automatically reloaded into WTCNT.69fd255dd597f93b4fb4a4aa4e752ce8.gif

3、WATCHDOG TIMER COUNT(WTCNT) REGISTER

The WTCNT register contains the current count values for the watchdogtimer during normal operation.

注意:The content of the WTDAT register cannot be automatically loaded into thetimer count register when the watchdog timer is enabled initially, so the WTCNTregister must be set to an initial value before enabling it.1345b6ee1776166fbe645f26085c7186.gif

定义寄存器:

//watchdog

#define WTCON    (*(volatile unsigned *)(0x7E004000))

#define WTDAT    (*(volatile unsigned *)(0x7E004004))

#define WTCNT    (*(volatile unsigned *)(0x7E004008))

初始化函数:

voidinit_watchdog()

{

WTDAT = 0xff;

WTCNT = 0x8000;

WTCON = 0XC021;//Prescaler value为6,16分频

}

在mian函数中调用:

init_watchdog();

while(1);

注意:程序通过友善提供的superboot下载到内存并运行,约2秒后系统复位,PCLK=133M

程序下载:

**************************************************************

下载在Linux公社的1号FTP服务器里,下载地址:

用户名:www.linuxidc.com

密码:www.muu.cc

在 2012年LinuxIDC.com\3月\深入理解ARM体系架构(S3C6410)-S3C6410看门狗源码实例

**************************************************************0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值