WINCE6.0+S3C6410 watchdog重新启动

本文介绍了S3C6410平台中使用看门狗定时器进行软件复位的方法。通过设置控制寄存器、预分频值及中断使能等参数,实现系统的定时复位功能。

// File: watchdog_sw_rst.c
//
// Samsung SMDK6410 SW_RST using watchdog timer support code.
//
#include <windows.h>
#include <ceddk.h>
#include <oal.h>
#include <s3c6410.h>

// WTCON - control register, bit specifications
#define WTCON_PRESCALE(x) (((x)&0xff)<<8) // bit 15:8, prescale value, 0 <= (x) <= 27
#define WTCON_ENABLE (1<<5) // bit 5, enable watchdog timer
#define WTCON_CLK_DIV16 (0<<3)
#define WTCON_CLK_DIV32 (1<<3)
#define WTCON_CLK_DIV64 (2<<3)
#define WTCON_CLK_DIV128 (3<<3)
#define WTCON_INT_ENABLE (1<<2)
#define WTCON_RESET (1<<0)

// WTCNT - watchdog counter register
#define WTCNT_CNT(x) ((x)&0xffff)

// WTDAT - watchdog reload value register
#define WTDAT_CNT(x) ((x)&0xffff)

// WTCLRINT - watchdog interrupt clear register
#define WTCLRINT_CLEAR (1<<0)

// Watchdog Clock
// PCLK : 66MHz
// PCLK/PRESCALER : 66/66 = 1MHz
// PCLK/PRESCALER/DIVIDER : 1MHz/128 = 7.812 KHz
// MAX Counter = 0xffff = 65535
// Period = 65535/7812 =~ 8.4 sec
#define WD_PRESCALER (66-1)

//------------------------------------------------------------------------------
//
// Function: _OEMSWReset
//
// This is the function to reset S3C6410 using watchdog timer.
//
void _OEMSWReset(void)
{
  volatile S3C6410_WATCHDOG_REG *pWTDogReg = NULL; // VA for Watchdog base
  pWTDogReg = (S3C6410_WATCHDOG_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_WATCHDOG, FALSE);
  if (!pWTDogReg)
  {
  OALMSG (OAL_ERROR, (L"Address of Watch Dog Base Not Defined, WatchDog not enabled!/r/n"));
  }
  else
  {
  pWTDogReg->WTCON = WTCON_PRESCALE(WD_PRESCALER) | WTCON_CLK_DIV128 | WTCON_RESET;
  pWTDogReg->WTDAT = WTDAT_CNT(0x1);
  pWTDogReg->WTCNT = WTCNT_CNT(0x1);
  pWTDogReg->WTCON |= WTCON_ENABLE;
  }
}

相关帖子:http://topic.youkuaiyun.com/u/20101016/21/2c1780dc-4868-449f-8731-ef5479851082.html?seed=82591753&r=69156312#r_69156312

评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值