/** ###################################################################
**     THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : HSyncTimeout.C
**     Project   : vga2scart
**     Processor : MC9S08QD4CPC
**     Component : FreeCntr
**     Version   : Component 01.112, Driver 01.09, CPU db: 3.00.002
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 1.8.2010, 16:12
**     Abstract  :
**         This device "FreeCntr" implements a free running counter for
**         time measurement.
**     Settings  :
**         Timer name                  : TPM2 (16-bit)
**         Compare name                : TPM20
**         Counter shared              : No
**
**         High speed mode
**             Prescaler               : divide-by-1
**             Clock                   : 8000000 Hz
**           Period
**             Xtal ticks              : 2
**             microseconds            : 77
**             seconds (real)          : 0.000077
**             Hz                      : 12987
**             kHz                     : 13
**           Frequency of counting (Bus clock / prescaler)
**             Hz                      : 8000000
**
**         Initialization:
**              Timer                  : Enabled
**
**         Timer registers
**              Counter                : TPM2CNT   [$0021]
**              Mode                   : TPM2SC    [$0020]
**              Run                    : TPM2SC    [$0020]
**              Prescaler              : TPM2SC    [$0020]
**              Compare                : TPM2C0V   [$0026]
**
**         Interrupt name              : Vtpm2ch0
**         Priority                    : 
**         User handling procedure     : HSyncTimeout_OnInterrupt
**         This event is called when the counter is reinitialized
**     Contents  :
**         Reset - byte HSyncTimeout_Reset(void);
**
**     Copyright : 1997 - 2009 Freescale Semiconductor, Inc. All Rights Reserved.
**     
**     http      : www.freescale.com
**     mail      : support@freescale.com
** ###################################################################*/

/* MODULE HSyncTimeout. */

#include "Events.h"
#include "HSyncTimeout.h"


/*** Internal macros and method prototypes ***/

/*
** ===================================================================
**     Method      :  SetCV (component FreeCntr)
**
**     Description :
**         The method computes and sets compare/modulo/reload value for 
**         time measuring.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#define HSyncTimeout_SetCV(_Val) ( \
  TPM2C0V = (HSyncTimeout_TTimerValue)(_Val) )


/*** End of Internal methods declarations ***/


/*
** ===================================================================
**     Method      :  HSyncTimeout_Reset (component FreeCntr)
**
**     Description :
**         This method resets the timer-counter (sets to zero for
**         up-counting HW or to appropriate value for down-counting HW).
**         The method is available only if the counter register can be
**         set by software and the counter is not shared.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
/*
byte HSyncTimeout_Reset(word *Value)

**      This method is implemented as a macro. See header module. **
*/

/*
** ===================================================================
**     Method      :  HSyncTimeout_Init (component FreeCntr)
**
**     Description :
**         Initializes the associated peripheral(s) and the bean internal 
**         variables. The method is called automatically as a part of the 
**         application initialization code.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void HSyncTimeout_Init(void)
{
  /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */
  setReg8(TPM2SC, 0x00);               /* Stop HW; disable overflow interrupt and set prescaler to 0 */ 
  /* TPM2MOD: BIT15=0,BIT14=0,BIT13=0,BIT12=0,BIT11=0,BIT10=0,BIT9=0,BIT8=0,BIT7=0,BIT6=0,BIT5=0,BIT4=0,BIT3=0,BIT2=0,BIT1=0,BIT0=0 */
  setReg16(TPM2MOD, 0x00U);            /* Clear modulo register: e.g. set free-running mode */ 
  /* TPM2C0SC: CH0F=0,CH0IE=1,MS0B=0,MS0A=1,ELS0B=0,ELS0A=0,??=0,??=0 */
  setReg8(TPM2C0SC, 0x50);             /* Set output compare mode and enable compare interrupt */ 
  HSyncTimeout_SetCV(0x0268U);         /* Inicialize appropriate value to the compare/modulo/reload register */
  /* TPM2CNTH: BIT15=0,BIT14=0,BIT13=0,BIT12=0,BIT11=0,BIT10=0,BIT9=0,BIT8=0 */
  setReg8(TPM2CNTH, 0x00);             /* Reset HW Counter */ 
  /* TPM2SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=1,PS2=0,PS1=0,PS0=0 */
  setReg8(TPM2SC, 0x08);               /* Set prescaler and run counter */ 
}


/*
** ===================================================================
**     Method      :  HSyncTimeout_Interrupt (component FreeCntr)
**
**     Description :
**         The method services the interrupt of the selected peripheral(s)
**         and eventually invokes event(s) of the bean.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
ISR(HSyncTimeout_Interrupt)
{
  /* TPM2C0SC: CH0F=0 */
  clrReg8Bits(TPM2C0SC, 0x80);         /* Reset compare interrupt request flag */ 
  HSyncTimeout_OnInterrupt();          /* Invoke user event */
}


/* END HSyncTimeout. */

/*
** ###################################################################
**
**     This file was created by Processor Expert 3.07 [04.34]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/
