Hardware watchdog is very important in industrial control. The FEZ Cerberus main board /FEZ Cerb40 module are good choose for low cost design. Unfortunately, it is not support watchdog in firmware! (also, The GHI guy said : Open Source "OSHW" is not support!)
I read the STM32F405 reference manual to find out the solution ... And I try to write the low leve CPU register setting to enable watchdog ... It is working !
The C# source code as follows :
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.OSHW.Hardware.LowLevel;
class iWatchDog
{
public uint TimeOut = 4000; // default 4000 units
private uint AccKey = 0x5555;
private uint RstKey = 0xAAAA;
private uint EnableKey = 0xCCCC;
//----------------------------------------------------------------
Register IWDG_KR = new Register(0x40003000);
Register IWDG_PR = new Register(0x40003004);
Register IWDG_RLR = new Register(0x40003008);
Register IWDG_SR = new Register(0x4000300C);
//-----------------------------------------------------------------
public void Init()
{
IWDG_KR.Write(AccKey); // open the access key
IWDG_PR.Write(4); // write the Prescaler for 2ms (One unit)
IWDG_KR.Write(AccKey); // open again
IWDG_RLR.Write(TimeOut); // write the down counter
}
//--------------------------------------------------------------
public void Enable()
{
IWDG_KR.Write(AccKey); // open access key
IWDG_KR.Write(EnableKey); // enable counter
}
//---------------------------------------------------------------
public void Reset()
{
IWDG_KR.Write(AccKey); // open access key
IWDG_KR.Write(RstKey); // reload counter
}
}
//--------------------------------------------
// your main program as follows:
//--------------------------------------------.
.
iWatchDog Wdog = new iWatchDog();
Wdog.TimeOut = 2500; // for 5 second time out
Wdog.Init();
Wdog.Enable(); // enable watch dog
.
.
//-------- the easy way to reset the watchdos counter -----------------
void timer500_Tick(GT.Timer timer)// 500mS timer tick
{
Wdog.Reset(); // reload the watchdog timeout counter
}
沒有留言:
張貼留言