色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > GNU ARM匯編--(八)s3c2440的watchdog

          GNU ARM匯編--(八)s3c2440的watchdog

          作者: 時(shí)間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
          從單片機(jī)起,watchdog就是必不可少的.在各種應(yīng)用環(huán)境中,程序很可能跑飛或死掉,這時(shí)候就需要通過watchdog來保證整個(gè)系統(tǒng)重新恢復(fù)到正常狀態(tài).

          照舊,給出s3c2440的datasheet說明:

          本文引用地址:http://cafeforensic.com/article/201611/321723.htm

          概述:
          watchdog timer用于由于噪聲或者系統(tǒng)錯(cuò)誤引起的程序跑飛了的情況下恢復(fù)處理器的正常操作.它可以被用作一個(gè)可以請(qǐng)求中斷服務(wù)的普通16bit的內(nèi)部定時(shí)器.watchdog timer產(chǎn)生128 PCLK的重啟信號(hào).
          特點(diǎn):
          有中斷請(qǐng)求的普通內(nèi)部定時(shí)器模式
          當(dāng)定時(shí)器計(jì)數(shù)為0(超時(shí))時(shí),產(chǎn)生內(nèi)部的長達(dá)128PCLK周期的重啟信號(hào)


          watchdog timer的操作:
          F18-1顯示watchdog timer的功能框圖.watchdog timer只使用PCLK作為它的時(shí)鐘源.PCLK先由一個(gè)8bit的prescaler進(jìn)行分頻,接下來還會(huì)再次分頻.


          Prescaler的值和分頻因子由watchdog timer控制寄存器(WTCON)決定.有效的預(yù)分頻值的范圍是(0--2^8-1),因?yàn)槭?bit的分頻器.分頻因子可選為16,32,64,128.


          WTDAT&WTCNT
          一旦watchdog timer啟用了,watchdog timer數(shù)據(jù)寄存器(WTDAT)的值不會(huì)自動(dòng)的重新加載到計(jì)數(shù)寄存器(WTCNT).所以,在watchdog timer啟動(dòng)前一定要向watchdog timer的計(jì)數(shù)寄存器(WTCNT)中寫入一個(gè)初始值.


          watchdog timer special registers
          WTCON
          WTCON允許user打開或關(guān)閉watchdog timer,從4個(gè)不同的源中選擇時(shí)鐘信號(hào),開關(guān)中斷以及開關(guān)watchdog timer的輸出.watchdog timer用來s3c2440啟動(dòng)后的重啟,如果不想處理器重啟,watchdog timer要被禁用.在loader開始時(shí),watchdog timer又沒初始化的時(shí)候,應(yīng)該將watchdog timer禁用.
          如果user想使用watchdog timer提供的正常定時(shí)器功能,那就打開中斷,關(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] 時(shí)鐘分頻因子 00:16 01:32 00
          10:64 11:128
          Interrupt generation [2] 中斷的開關(guān)位 0
          Reset enable/diaable [0] 輸出重啟信號(hào)的開關(guān) 1


          WTDAT
          WTDAT用來指定超時(shí)的期限.在最開始的操作中WTDAT的值不會(huì)自動(dòng)的加載到計(jì)數(shù)器中.使用初始值0x8000就可以驅(qū)動(dòng)第一次超時(shí).以后的話,WTDAT的值就會(huì)自動(dòng)重加載到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] 重加載的計(jì)數(shù)值 0x8000


          WTCNT
          WTCNT包含正常操作下watchdog timer的當(dāng)前計(jì)數(shù)值.值得注意的是,在watchdog timer最初被啟用的時(shí)候,WTDAT的內(nèi)容不會(huì)自動(dòng)的加載到WTCNT中,所以WTCNT一定要給一個(gè)初始值.
          Register Address R/W Description Reset Value
          WTCNT 0x53000008 R/W Watchdog timer count register 0x8000
          Bit Description Initial State
          Count value [15:0] 定時(shí)器的當(dāng)前計(jì)數(shù)值 0x8000

          我們先將watchdog的輸出重啟信號(hào)的開關(guān)關(guān)掉,將中斷打開,把watchdog timer當(dāng)一個(gè)普通的定時(shí)器來用.設(shè)計(jì)如下:

          [cpp]view plaincopy
          1. /*
          2. watchdogtimerwithdisablereset
          3. copyleft@dndxhej@gmail.com
          4. */
          5. .equNOINT,0xc0
          6. .equGPBCON,0x56000010@led
          7. .equGPBDAT,0x56000014@led
          8. .equGPBUP,0x56000018@led
          9. .equGPFCON,0x56000050@interruptconfig
          10. .equEINTMASK,0x560000a4
          11. .equEXTINT0,0x56000088
          12. .equEXTINT1,0x5600008c
          13. .equEXTINT2,0x56000090
          14. .equINTMSK,0x4A000008
          15. .equEINTPEND,0x560000a8
          16. .equSUBSRCPND,0x4a000018
          17. .equINTSUBMSK,0x4a00001c
          18. .equSRCPND,0X4A000000
          19. .equINTPND,0X4A000010
          20. .equGPB5_out,(1<<(5*2))
          21. .equGPB6_out,(1<<(6*2))
          22. .equGPB7_out,(1<<(7*2))
          23. .equGPB8_out,(1<<(8*2))
          24. .equGPBVALUE,(GPB5_out|GPB6_out|GPB7_out|GPB8_out)
          25. .equLOCKTIME,0x4c000000
          26. .equMPLLCON,0x4c000004
          27. .equUPLLCON,0x4c000008
          28. .equM_MDIV,92
          29. .equM_PDIV,1
          30. .equM_SDIV,1
          31. .equU_MDIV,56
          32. .equU_PDIV,2
          33. .equU_SDIV,2
          34. .equCLKDIVN,0x4c000014
          35. .equDIVN_UPLL,0
          36. .equHDIVN,1
          37. .equPDIVN,1@FCLK:HCLK:PCLK=1:2:4
          38. .equWTCON,0x53000000
          39. .equPre_scaler,249
          40. .equwd_timer,1
          41. .equclock_select,00@316
          42. .equint_gen,1@開中斷
          43. .equreset_enable,0@關(guān)掉重啟信號(hào)
          44. .equWTDAT,0x53000004
          45. .equCount_reload,50000@定時(shí)器定為2SPCLK=100MPCLK/(Pre_scaler+1)/clock_select=100M/(249+1)/16=25k50000/25k=2s
          46. .equWTCNT,0x53000008
          47. .equCount,50000
          48. .global_start
          49. _start:breset
          50. ldrpc,_undefined_instruction
          51. ldrpc,_software_interrupt
          52. ldrpc,_prefetch_abort
          53. ldrpc,_data_abort
          54. ldrpc,_not_used
          55. @birq
          56. ldrpc,_irq
          57. ldrpc,_fiq
          58. _undefined_instruction:.wordundefined_instruction
          59. _software_interrupt:.wordsoftware_interrupt
          60. _prefetch_abort:.wordprefetch_abort
          61. _data_abort:.worddata_abort
          62. _not_used:.wordnot_used
          63. _irq:.wordirq
          64. _fiq:.wordfiq
          65. .balignl16,0xdeadbeef
          66. reset:
          67. ldrr3,=WTCON
          68. movr4,#0x0
          69. strr4,[r3]@disablewatchdog
          70. ldrr0,=GPBCON
          71. ldrr1,=0x15400
          72. strr1,[r0]
          73. ldrr2,=GPBDAT
          74. ldrr1,=0x160
          75. strr1,[r2]
          76. blclock_setup
          77. bldelay

          78. 上一頁 1 2 下一頁

          關(guān)鍵詞: ARM匯編s3c2440watchdo

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉