/*
*******************************************************************************
COPYRIGHT 2002 STMicroelectronics
Source File Name : wdg.c
Group            : IPSW, CMG - IPDF
Author           : MCD Application Team
Date First Issued: 5/3/2002
********************************Documentation**********************************
General Purpose - This file conatains the functions for WDG
********************************RevisionHistory********************************
_______________________________________________________________________________
Date : 5/3/2002                  Release: 1.0
Date : 23/9/2003                release: 2.0
Date : 28/04/04                 MISRA changes 
******************************************************************************/

#include "ST7lib_Config.h"                               /*Configuration File*/
#include "WDG_hr.h"                            /*Mapping of WDG H/W registers*/
#include "WDG.h"                               /*Declaration of WDG functions*/   

#define TOSC2  (1000000000/Fosc2)
#define TCPU   (1000000000/Fcpu)

/*-----------------------------------------------------------------------------
ROUTINE NAME : WDG_ComputeTimeout
INPUT        : 1.WDG_Timeout 
OUTPUT       : None
DESCRIPTION  : Computes the counter value for the selected timeout,Loads the
               vlaue in the counter & activates the Watchdog.
COMMENTS     : None
-----------------------------------------------------------------------------*/ 
/* RBuilder will override this function by adding 
                                              #define REM_WGD_COMPUTETIMEOUT */
#ifndef REM_WGD_COMPUTETIMEOUT
void WDG_ComputeTimeout(unsigned long WDG_Timeout)
{ 

   unsigned char CNT;
   unsigned long temp;

   temp = ((WDG_Timeout * 1000)/WDG_PRESEC);   

#if (defined WDG_72F521 || defined WDG_72F264 || defined WDG_72F561)
   CNT = (unsigned char)(temp / TOSC2); 

#else
   CNT = (unsigned char)((temp) / TCPU);
   
#endif    
   ((CNT <= WDG_MAX_VALUE) ? (WDGCR = ((unsigned char)((unsigned char)
                             WDG_MAX_VALUE & CNT))) : (WDGCR = WDG_MAX_VALUE));
                                                    /*Load the counter value*/
   WDGCR |= 0xc0;                                   /*Activate The Watchdog*/
                                        
}
#endif /* REM_WGD_COMPUTETIMEOUT */
/**** (c) 2002   STMicroelectronics *************************** END OF FILE **/





