<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

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

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

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

          照舊,給出s3c2440的datasheet說明:

          本文引用地址:http://www.ex-cimer.com/article/201611/321723.htm

          概述:
          watchdog timer用于由于噪聲或者系統(tǒng)錯誤引起的程序跑飛了的情況下恢復處理器的正常操作.它可以被用作一個可以請求中斷服務(wù)的普通16bit的內(nèi)部定時器.watchdog timer產(chǎn)生128 PCLK的重啟信號.
          特點:
          有中斷請求的普通內(nèi)部定時器模式
          當定時器計數(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的當前計數(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] 定時器的當前計數(shù)值 0x8000

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

          [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)掉重啟信號
          44. .equWTDAT,0x53000004
          45. .equCount_reload,50000@定時器定為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

          評論


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

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();