从单片机起,watchdog便是必不可少的.在各种运用环境中,程序很可能跑飞或死掉,这时分就需要经过watchdog来确保整个体系从头康复到正常状况.
照常,给出s3c2440的datasheet阐明:
概述:
watchdog timer用于由于噪声或许体系过错引起的程序跑飞了的情况下康复处理器的正常操作.它能够被用作一个能够恳求中止服务的一般16bit的内部定时器.watchdog timer发生128 PCLK的重启信号.
特色:
有中止恳求的一般内部定时器形式
当定时器计数为0(超时)时,发生内部的长达128PCLK周期的重启信号
watchdog timer的操作:
F18-1显现watchdog timer的功用框图.watchdog timer只运用PCLK作为它的时钟源.PCLK先由一个8bit的prescaler进行分频,接下来还会再次分频.
Prescaler的值和分频因子由watchdog timer操控寄存器(WTCON)决议.有用的预分频值的规模是(0–2^8-1),由于是8bit的分频器.分频因子可选为16,32,64,128.
WTDAT&WTCNT
一旦watchdog timer启用了,watchdog timer数据寄存器(WTDAT)的值不会主动的从头加载到计数寄存器(WTCNT).所以,在watchdog timer发动前必定要向watchdog timer的计数寄存器(WTCNT)中写入一个初始值.
watchdog timer special registers
WTCON
WTCON答应user翻开或封闭watchdog timer,从4个不同的源中挑选时钟信号,开关中止以及开关watchdog timer的输出.watchdog timer用来s3c2440发动后的重启,假如不想处理器重启,watchdog timer要被禁用.在loader开端时,watchdog timer又没初始化的时分,应该将watchdog timer禁用.
假如user想运用watchdog timer供给的正常定时器功用,那就翻开中止,封闭watchdog timer.
Register Address R/W Description Reset Value
WTCON 0x53000000 R/W Watchdog timer control register 0x8021
Bit Descrition Initial State
Prescaler value [15:8] 预分频的值(0–255) 0x80
Watchdog timer [5] watchdog timer的开关位 1(开)
Clock select [4:3] 时钟分频因子 00:16 01:32 00
10:64 11:128
Interrupt generation [2] 中止的开关位 0
Reset enable/diaable [0] 输出重启信号的开关 1
WTDAT
WTDAT用来指定超时的期限.在最开端的操作中WTDAT的值不会主动的加载到计数器中.运用初始值0x8000就能够驱动第一次超时.今后的话,WTDAT的值就会主动重加载到WTCNT中.
Register Address R/W Description Reset Value
WTDAT 0x53000004 R/W Watchdog timer data register 0x8000
Bit Description Initial State
Count reload value [15:0] 重加载的计数值 0x8000
WTCNT
WTCNT包括正常操作下watchdog timer的当时计数值.值得注意的是,在watchdog timer开始被启用的时分,WTDAT的内容不会主动的加载到WTCNT中,所以WTCNT必定要给一个初始值.
Register Address R/W Description Reset Value
WTCNT 0x53000008 R/W Watchdog timer count register 0x8000
Bit Description Initial State
Count value [15:0] 定时器的当时计数值 0x8000
咱们先将watchdog的输出重启信号的开关关掉,将中止翻开,把watchdog timer当一个一般的定时器来用.规划如下:
- /*
- watchdogtimerwithdisablereset
- copyleft@dndxhej@gmail.com
- */
- .equNOINT,0xc0
- .equGPBCON,0x56000010@led
- .equGPBDAT,0x56000014@led
- .equGPBUP,0x56000018@led
- .equGPFCON,0x56000050@interruptconfig
- .equEINTMASK,0x560000a4
- .equEXTINT0,0x56000088
- .equEXTINT1,0x5600008c
- .equEXTINT2,0x56000090
- .equINTMSK,0x4A000008
- .equEINTPEND,0x560000a8
- .equSUBSRCPND,0x4a000018
- .equINTSUBMSK,0x4a00001c
- .equSRCPND,0X4A000000
- .equINTPND,0X4A000010
- .equGPB5_out,(1<<(5*2))
- .equGPB6_out,(1<<(6*2))
- .equGPB7_out,(1<<(7*2))
- .equGPB8_out,(1<<(8*2))
- .equGPBVALUE,(GPB5_out|GPB6_out|GPB7_out|GPB8_out)
- .equLOCKTIME,0x4c000000
- .equMPLLCON,0x4c000004
- .equUPLLCON,0x4c000008
- .equM_MDIV,92
- .equM_PDIV,1
- .equM_SDIV,1
- .equU_MDIV,56
- .equU_PDIV,2
- .equU_SDIV,2
- .equCLKDIVN,0x4c000014
- .equDIVN_UPLL,0
- .equHDIVN,1
- .equPDIVN,1@FCLK:HCLK:PCLK=1:2:4
- .equWTCON,0x53000000
- .equPre_scaler,249
- .equwd_timer,1
- .equclock_select,00@316
- .equint_gen,1@开中止
- .equreset_enable,0@关掉重启信号
- .equWTDAT,0x53000004
- .equCount_reload,50000@定时器定为2SPCLK=100MPCLK/(Pre_scaler+1)/clock_select=100M/(249+1)/16=25k50000/25k=2s
- .equWTCNT,0x53000008
- .equCount,50000
- .global_start
- _start:breset
- ldrpc,_undefined_instruction
- ldrpc,_software_interrupt
- ldrpc,_prefetch_abort
- ldrpc,_data_abort
- ldrpc,_not_used
- @birq
- ldrpc,_irq
- ldrpc,_fiq
- _undefined_instruction:.wordundefined_instruction
- _software_interrupt:.wordsoftware_interrupt
- _prefetch_abort:.wordprefetch_abort
- _data_abort:.worddata_abort
- _not_used:.wordnot_used
- _irq:.wordirq
- _fiq:.wordfiq
- .balignl16,0xdeadbeef
- reset:
- ldrr3,=WTCON
- movr4,#0x0
- strr4,[r3]@disablewatchdog
- ldrr0,=GPBCON
- ldrr1,=0x15400
- strr1,[r0]
- ldrr2,=GPBDAT
- ldrr1,=0x160
- strr1,[r2]
- blclock_setup
- bldelay
-