/*
********************************************************************************
COPYRIGHT 2002 STMicroelectronics
Source File Name : timer.h
Group            : IPSW,CMG-IPDF.
Author           : MCD Application Team
Date First Issued: 6/3/2002
********************************Documentation***********************************
General Purpose - This file defines prototypes for all the functions whose 
                  source code appears in timer.c
********************************RevisionHistory*********************************
1. Added necessary comments.
2. Updated the file for release 2.0.
********************************************************************************
Date :6/3/2002            Release:1.0               
Date:23/9/2003           Release:2.0
Date :28/04/04         MISRA changes
________________________________________________________________________________

1. Added Macro for few functions.
2. Removed the prototype for the previous functions.
3. Added necessary comments.
4. Updated the file for release 2.0.
*******************************************************************************/
#ifndef TIMER_H
#define TIMER_H

#include "ST7lib_config.h"    
                
  
/*----------------------------------------------------------------------------*/

/* Enumerated parameters for the function TIMERx_Init                         */
typedef enum {
              TIMER_DEFAULT = (unsigned char) 0x00, /* Default configuration  */
              TIMER_FCPU_2  = (unsigned char) 0x04, /* Timer CLK = Fcpu / 2   */
              TIMER_FCPU_4  = (unsigned char) 0x00, /* Timer CLK = Fcpu / 4   */
              TIMER_FCPU_8  = (unsigned char) 0x08, /* Timer CLK = Fcpu / 8   */
              TIMER_EXCLK_F = (unsigned char) 0x0C, /* EXT CLK at falling edge*/
              TIMER_EXCLK_R = (unsigned char) 0x0D  /* EXT CLK at raising edge*/
             } Typ_Timer_InitParameter;

/*----------------------------------------------------------------------------*/
/* Enumerated parameters for the function TIMERx_IT_Enable                    */
typedef enum {
              TIMER_OCMP_IT_ENABLE = (unsigned char) 0x40, /* Enable CMP int  */
              TIMER_ICAP_IT_ENABLE = (unsigned char) 0x80, /* Enable CAP int  */
              TIMER_OVF_IT_ENABLE  = (unsigned char) 0x20  /* Enable OVF int  */                
             }Typ_Timer_EITParameter;

/*----------------------------------------------------------------------------*/
/* Enumerated parameters for the function TIMERx_IT_Disable                   */
typedef enum {
              TIMER_OCMP_IT_DISABLE = (unsigned char) 0x40, /* Disable CMP int*/
              TIMER_ICAP_IT_DISABLE = (unsigned char) 0x80, /* Disable CAP int*/
              TIMER_OVF_IT_DISABLE  = (unsigned char) 0x20  /* Disable OVF int*/
             } Typ_Timer_DITParameter;
              
/*----------------------------------------------------------------------------*/
/* Enumerated parameters for function TIMERx_Status_Flag,TIMERx_Clear_Flag    */
typedef enum {
              TIMER_FLAG_OCF1,                   /* For Output compare 1 Flag */
              TIMER_FLAG_OCF2,                   /* For Output compare 2 Flag */
              TIMER_FLAG_ICF1,                   /*  For Input Capture 1 Flag */
              TIMER_FLAG_ICF2,                   /*  For Input Capture 2 Flag */
              TIMER_FLAG_OVF                     /*         For Overflow Flag */
             } Timer_Flag;   

/*----------------------------------------------------------------------------*/
/* Enumerated parameters for function TIMERx_OCMP_Mode                        */
typedef enum {                
              TIMER_OCMP_1,                            /* For ouput compare 1 */
              TIMER_OCMP_2,                            /* For ouput compare 2 */
              TIMER_FORCDCMP_1,                       /* For Forced compare 1 */
              TIMER_FORCDCMP_2                        /* For Forced compare 2 */
             } Timer_Compare; 

/*----------------------------------------------------------------------------*/
/* Enumerated parameters for function TIMERx_PWM_Mode and TIMERx_OCMP_Mode    */
/* OUTPUT_F & OUTPUT_R are used for TIMERA_OPM_Mode only                      */                                       
typedef enum {
              TIMER_OUTPUT_F,                           /* OLVL1 or OLVL2 = 0 */     
              TIMER_OUTPUT_R,                           /* OLVL1 or OLVL2 = 1 */
              TIMER_OUTPUT1_F,                                   /* OLVL1 = 0 */
              TIMER_OUTPUT1_R,                                   /* OLVL1 = 1 */
              TIMER_OUTPUT2_F,                                   /* OLVL2 = 0 */
              TIMER_OUTPUT2_R                                    /* OLVL2 = 1 */
             } Timer_Olevel;                                                              

/*----------------------------------------------------------------------------*/
/* Enumerated parameters for function TIMERx_ICAP_Mode,TIMERx_ICAP_Getvalue   */
typedef enum {
              TIMER_ICAP_1,                            /* For Input Capture 1 */
              TIMER_ICAP_2                             /* For Input Capture 2 */
             } Timer_Icap;                                                                

/*----------------------------------------------------------------------------*/
/* Enumerated parameters for function TIMERx_ICAP_Mode                        */
typedef enum {
              TIMER_EDGE_0,                        /* To detect trailing edge */
              TIMER_EDGE_1                           /* To detect rising edge */
             } Timer_Edge;                                                                

/*----------------------------------------------------------------------------*/
/* Enumerated parameters for function TIMERx_Mode_Disable                     */
typedef enum { 
              TIMER_MODE_1,                          /* To disable OCMP1 mode */
              TIMER_MODE_2,                          /* To disable OCMP2 mode */
              TIMER_MODE_3,                          /* To disable ICAP1 mode */
              TIMER_MODE_4,                          /* To disable ICAP2 mode */
              TIMER_MODE_5,                            /* To disable PWM mode */
              TIMER_MODE_6,                            /* To disable OPM mode */
              TIMER_MODE_7,                           /* To disable FORCDCMP1 */
              TIMER_MODE_8,                           /* To disable FORCDCMP2 */
              TIMER_MODE_9     /* Disable timer prescalar,counter and outputs */
             } Timer_Mode;

/*----------------------------------------------------------------------------*/
#ifdef USE_TIMERA  
#if (defined TIMER16_72F521 || defined TIMER16_72F63 || defined TIMER16_72F60 ||defined TIMER16_72F65\
     ||defined TIMER16_72F264 ||defined TIMER16_72F561 ||defined TIMER16_72F34x )
                                                                                
/************************ MACROS **********************************************/
#define  TIMERA_IT_Enable(EITValue)  (TACR1 |= (EITValue))/*Enables interrupt */

/*Disables  interrupt*/                      
#define  TIMERA_IT_Disable(DITValue) (TACR1 &= ((unsigned char)(~(DITValue))))

/*****************************************************************************/

void TIMERA_Init(Typ_Timer_InitParameter InitValue);    /* Initialises TIMERA */
                                 /* Enables TIMERA in the Output compare mode */
void TIMERA_OCMP_Mode(Timer_Compare CMP,unsigned int OCR_VALUE,
                                                       Timer_Olevel OUTPUT_L);
BOOL TIMERA_Status_Flag(Timer_Flag FLAG_F);       /* Checks status of the flag*/
void TIMERA_Clear_Flag(Timer_Flag FLAG_F);         /* Clears the required flag*/
void TIMERA_Mode_Disable(Timer_Mode MODE_M);                  /* Disables mode*/
#endif
#if (defined TIMER16_72F521 || defined TIMER16_72F63 ||defined TIMER16_72F34x\
     || defined TIMER16_72F60 || defined TIMER16_72F264 ||defined TIMER16_72F561  )
                                                          /* Enables ICAP mode*/
void TIMERA_ICAP_Mode(Timer_Icap ICAP_I,Timer_Edge EDGE_SELECT_Y); 
                                                    /* Get Input Capture value*/      
unsigned int TIMERA_ICAP_Getvalue(Timer_Icap ICAP_I); 
                                                    
/* Enables TIMERA in the PWM mode                                             */
void TIMERA_PWM_Mode(Timer_Olevel OUTPUT1_L,Timer_Olevel OUTPUT2_L,
                             unsigned int OCR1_VALUE,unsigned int OCR2_VALUE);
/* Enables TIMERA in the OPM mode                                             */
void TIMERA_OPM_Mode(Timer_Edge EDGE_SELECT_Y,Timer_Olevel OUTPUT1_L,
                              Timer_Olevel OUTPUT2_L, unsigned int OCR_VALUE);
#endif
#endif 
#ifdef USE_TIMERB  
#if (defined TIMER16_72F521 || defined TIMER16_72F264 ||defined TIMER16_72F34x )

/********************** MACROS ************************************************/

#define TIMERB_IT_Enable(EITValue)  (TBCR1 |= (EITValue)) /*Enables interrupt */
                                                         /*Disables interrupt */
#define TIMERB_IT_Disable(DITValue) (TBCR1 &= (unsigned char)(~(DITValue)))

/******************************************************************************/

void TIMERB_Init(Typ_Timer_InitParameter InitValue);    /* Initialises TIMERB */
/* Enables TIMERB in the Output compare mode                                  */
void TIMERB_OCMP_Mode(Timer_Compare CMP,unsigned int OCR_VALUE,
                                                    Timer_Olevel OUTPUT_L);
                                                          /* Enables ICAP mode*/
void TIMERB_ICAP_Mode(Timer_Icap ICAP_I,Timer_Edge EDGE_SELECT_Y); 
                                                   /* Get Input Capture value */      
unsigned int TIMERB_ICAP_Getvalue(Timer_Icap ICAP_I); 
                                                   
/* Enables TIMERB in the PWM mode                                             */
void TIMERB_PWM_Mode(Timer_Olevel OUTPUT1_L,Timer_Olevel OUTPUT2_L,\
                             unsigned int OCR1_VALUE,unsigned int OCR2_VALUE);
/* Enables TIMERB in the OPM mode                                             */
void TIMERB_OPM_Mode(Timer_Edge EDGE_SELECT_Y,Timer_Olevel OUTPUT1_L,
                               Timer_Olevel OUTPUT2_L,unsigned int OCR_VALUE);
BOOL TIMERB_Status_Flag(Timer_Flag FLAG_F);        /* Checks status of a flag */
void TIMERB_Clear_Flag(Timer_Flag FLAG_F);        /* Clears the required flag */
void TIMERB_Mode_Disable(Timer_Mode MODE_M);                 /* Disables mode */
#endif
#endif
#endif  /* TIMER_H */
/**********   (c) 2002  ST Microelectronics **************END OF FILE *********/
