GNU ARM匯編--(八)s3c2440的watchdog
照舊,給出s3c2440的datasheet說明:
本文引用地址:http://m.butianyuan.cn/article/201611/321723.htm概述:
watchdog timer用于由于噪聲或者系統(tǒng)錯誤引起的程序跑飛了的情況下恢復(fù)處理器的正常操作.它可以被用作一個可以請求中斷服務(wù)的普通16bit的內(nèi)部定時器.watchdog timer產(chǎn)生128 PCLK的重啟信號.
特點:
有中斷請求的普通內(nèi)部定時器模式
當(dāng)定時器計數(shù)為0(超時)時,產(chǎn)生內(nèi)部的長達128PCLK周期的重啟信號
watchdog timer的操作:
F18-1顯示watchdog timer的功能框圖.watchdog timer只使用PCLK作為它的時鐘源.PCLK先由一個8bit的prescaler進行分頻,接下來還會再次分頻.
Prescaler的值和分頻因子由watchdog timer控制寄存器(WTCON)決定.有效的預(yù)分頻值的范圍是(0--2^8-1),因為是8bit的分頻器.分頻因子可選為16,32,64,128.
WTDAT&WTCNT
一旦watchdog timer啟用了,watchdog timer數(shù)據(jù)寄存器(WTDAT)的值不會自動的重新加載到計數(shù)寄存器(WTCNT).所以,在watchdog timer啟動前一定要向watchdog timer的計數(shù)寄存器(WTCNT)中寫入一個初始值.
watchdog timer special registers
WTCON
WTCON允許user打開或關(guān)閉watchdog timer,從4個不同的源中選擇時鐘信號,開關(guān)中斷以及開關(guān)watchdog timer的輸出.watchdog timer用來s3c2440啟動后的重啟,如果不想處理器重啟,watchdog timer要被禁用.在loader開始時,watchdog timer又沒初始化的時候,應(yīng)該將watchdog timer禁用.
如果user想使用watchdog timer提供的正常定時器功能,那就打開中斷,關(guān)閉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] 預(yù)分頻的值(0--255) 0x80
Watchdog timer [5] watchdog timer的開關(guān)位 1(開)
Clock select [4:3] 時鐘分頻因子 00:16 01:32 00
10:64 11:128
Interrupt generation [2] 中斷的開關(guān)位 0
Reset enable/diaable [0] 輸出重啟信號的開關(guān) 1
WTDAT
WTDAT用來指定超時的期限.在最開始的操作中WTDAT的值不會自動的加載到計數(shù)器中.使用初始值0x8000就可以驅(qū)動第一次超時.以后的話,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] 重加載的計數(shù)值 0x8000
WTCNT
WTCNT包含正常操作下watchdog timer的當(dāng)前計數(shù)值.值得注意的是,在watchdog timer最初被啟用的時候,WTDAT的內(nèi)容不會自動的加載到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] 定時器的當(dāng)前計數(shù)值 0x8000
我們先將watchdog的輸出重啟信號的開關(guān)關(guān)掉,將中斷打開,把watchdog timer當(dāng)一個普通的定時器來用.設(shè)計如下:
- /*
- 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@關(guān)掉重啟信號
- .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
-
評論