新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 深入理解ARM體系架構(S3C6410)---S3C6410看門狗源碼實例

        深入理解ARM體系架構(S3C6410)---S3C6410看門狗源碼實例

        作者: 時間:2016-11-09 來源:網絡 收藏
        當系統運行受到外部干擾或者系統錯誤,程序有時會出現跑飛,導致整個系統癱瘓。他會設置一段時間,當超出這段時間,從程序中跳出進入中斷處理程序。WatchDog本質上是一種定時器,那么普通定時器擁有的特性它也應該具備,是的當它計時超時時也會引起事件的發生,只是這個事件除了可以是系統中斷外,他也可以是一個系統重啟信號(Reset Signal)。可以這么說,能發送系統重啟信號的定時器我們就叫它WatchDog。看門狗定時器中斷是我們不希望看到的,因此我們要想方設法避免它發生。主要的方法就是在中斷發生前,重新對看門狗定時器的寄存器進行賦值,使它的定時器重新開始記時,這種方法俗稱喂狗。

        S3C6410看門狗定時器的功能:

        本文引用地址:http://www.104case.com/article/201611/317826.htm

        作為常規時鐘,并且可以產生中斷

        作為看門狗定時器使用,當時鐘計數器減為零時,它將產生一個復位信號。

        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.

        It can be usedas a normal 16-bit interval timer to request interrupt service.Advantagein using WDT instead of PWM timer is that WDT 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.

        看門狗模塊包括一個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.

        看門狗寄存器映射:


        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.

        注意: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.

        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.

        定義寄存器:

        1. //watchdog
        2. #defineWTCON(*(volatileunsigned*)(0x7E004000))
        3. #defineWTDAT(*(volatileunsigned*)(0x7E004004))
        4. #defineWTCNT(*(volatileunsigned*)(0x7E004008))

        初始化函數:

        1. voidinit_watchdog()
        2. {
        3. WTDAT=0xff;
        4. WTCNT=0x8000;
        5. WTCON=0XC021;//Prescalervalue為6,16分頻
        6. }

        在mian函數中調用:

        1. init_watchdog();
        2. while(1);



        評論


        技術專區

        關閉
        主站蜘蛛池模板: 修水县| 碌曲县| 临汾市| 德阳市| 建宁县| 勐海县| 房产| 玛曲县| 泊头市| 黄梅县| 宝兴县| 寿阳县| 寿宁县| 南昌县| 大邑县| 牟定县| 若尔盖县| 旬阳县| 耿马| 三原县| 通江县| 蒙阴县| 建瓯市| 康平县| 庄浪县| 金沙县| 嘉荫县| 沿河| 莱西市| 蚌埠市| 大荔县| 长乐市| 壤塘县| 墨江| 漠河县| 古田县| 遂川县| 绵阳市| 天峻县| 赞皇县| 寻乌县|