/*
Watchdog.c : Enables the Watchdog or bypasses the enables Watchdog. 

Compiler: BC++ 3.1,
          Turbo C++ 1.01(3.01) (free from http://cc.codegear.com/free/cpp)
          MSC 6.0,
          MSVC 1.52.

Compile mode: Large

Project: Watchdog.c
         ..\..\Lib\(8000e.Lib, 7188el.Lib or 7186el.Lib)

Hardware: i-7188/uPAC-7186/i-8000

Detail description:
    When user's program call EnableWDT(), the system timer ISR 
    will stop to refresh WDT, and user's program must do it by
    calling RefreshWDT(). Otherwise, the system will be reset by WDT.
    The timeout period of WDT is 0.8 seconds.  
         
    The check what reason cause the CPU been reset, you can 
    type 'diag' in i-7188> or i-8000> prompt.
    There are 3 reasons can reset the CPU
        1. reset by power on
        2. reset by WDT
        3. reset by reset
        
    To test the program
        Step1. download the watchdog.exe to the controller.
        Step2. power off and then power on the controller.
        Step3. type 'diag' in the i-7188> or i-8000> prompt. 
               (it should shows the CPU was reset by power on.)
               
        Step4. type 'watchdog.exe' to run the demo program.
               (you can see many "RefreshWDT" message)
               
        Step5. press any key to stop to refresh the WDT.
               a. you can see a message to count the time tick
                  passed from stoping refreshing the WDT.
               b. The message should be stoped near 800 ms.
               
        Step6. type 'diag' in the i-7188> or i-8000> prompt. 
               (it should shows the CPU was reset by WDT.)
               
[Oct 30, 2008] by Liam
*/

#include "..\..\lib\7186e.h"

void main(void)
{
    unsigned long sw;
    
    InitLib();
    
    EnableWDT();
    
    for(;;)
    {
        if(!Kbhit())
        {
            Print("RefreshWDT!! Press any key to stop refreshing WatchDogTimer.\r\n");
            RefreshWDT();
            sw=GetTimeTicks();
        }
        else
        {
            Print("time: %lu\r\n", GetTimeTicks()-sw);
        }
    }
}
