WINCE6.0+S3C6410 watchdog从新启动

2022年01月13日 阅读数:7
这篇文章主要向大家介绍WINCE6.0+S3C6410 watchdog从新启动,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。


// File: watchdog_sw_rst.cwindows

//ide

// Samsung SMDK6410 SW_RST using watchdog timer support code.code

//ci

#include <windows.h>it

#include <ceddk.h>io

#include <oal.h>function

#include <s3c6410.h>class


// WTCON - control register, bit specificationsim

#define WTCON_PRESCALE(x) (((x)&0xff)<<8) // bit 15:8, prescale value, 0 <= (x) <= 27di

#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;

  }

}