watchdog.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:2k
- #include "stsys.h"
- #include "sti5105.h"
- #include "gendef.h"
- #include "sysserv.h"
- #include "SysServReg.h"
- #define WD_TICKS_PER_SEC (1)
- #define WD_RESET_CPU_PERIOD (1) /* 1 sec */
- typedef struct wd_control_s
- {
- volatile int wd_count_0 : 16; /* [15:0]: watchdog count */
- volatile int reserved_0 : 16;
- volatile int wd_count_1 : 4; /* [19:16]: watchdog count */
- volatile int wd_count_en: 1; /* watchdog counter enable */
- volatile int reserved_1 : 27;
- } wd_control_t;
- static wd_control_t *wd_reg = (wd_control_t*)WATCHDOG_COUNTER_CFG0;
- static void KD_WDPeriod(UINT32 time); /* in second */
- static void WatchdogResetEnable(void);
- static void WatchdogResetDisable(void);
- /* Ref the register RESET_STATUS: SysServBaseAddress + 0x140
- ** Bit[11] RESET_SELECT_ALT:
- ** Bit[6] Mask for watchdog reset
- ** Bit[4] PAD_RESET_STATUS
- */
- #define WD_MASK_BITS (0x850)
- static UINT8 isWDResetEn = 0;
- static void WatchdogResetEnable(void)
- {
- UINT32 tmp;
- if(isWDResetEn) return;
-
- tmp = STSYS_ReadRegDev32LE(CKG_RESET_STATUS);
- /*Enable the watchdog reset*/
- tmp &= (~WD_MASK_BITS);
- STSYS_WriteRegDev32LE(CKG_RESET_STATUS, tmp);
- isWDResetEn = 1;
- }
- static void WatchdogResetDisable(void)
- {
- UINT32 tmp;
- if(!isWDResetEn) return;
-
- tmp = STSYS_ReadRegDev32LE(CKG_RESET_STATUS);
- /* Disable the watchdog reset*/
- tmp |= WD_MASK_BITS;
- STSYS_WriteRegDev32LE(CKG_RESET_STATUS, tmp);
- isWDResetEn = 0;
- }
- void KB_SysWDEnable(UINT32 timeout)
- {
- KB_SysWDDisable();
- KD_WDPeriod(timeout);
- wd_reg->wd_count_en = 1;
- WatchdogResetEnable();
- }
- void KB_SysWDDisable(void)
- {
- WatchdogResetDisable();
- wd_reg->wd_count_en = 0;
- }
- static void KD_WDPeriod(UINT32 time)
- {
- UINT32 ticks;
-
- ticks = WD_TICKS_PER_SEC * time;
- wd_reg->wd_count_1 = (int)((ticks >> 16) & 0xF);
- wd_reg->wd_count_0 = (int)(ticks & 0xFFFF);
- }
- void KB_SysWDReset(void)
- {
- /* force a watchdog timeout. */
- KB_SysWDEnable(WD_RESET_CPU_PERIOD);
- KD_WDPeriod(0) ;
- while(1) ;
- }
- /* EOF */