/*********************************************************************************************************************
 *  COPYRIGHT
 *  ------------------------------------------------------------------------------------------------------------------
 *  \verbatim
 *
 *                 TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
 *
 *                 Property of Texas Instruments, Unauthorized reproduction and/or distribution
 *                 is strictly prohibited.  This product  is  protected  under  copyright  law
 *                 and  trade  secret law as an  unpublished work.
 *                 (C) Copyright Texas Instruments.  All rights reserved.
 *
 *  \endverbatim
 *  ------------------------------------------------------------------------------------------------------------------
 *  FILE DESCRIPTION
 *  ------------------------------------------------------------------------------------------------------------------
 *         File:  Gpt.h
 *    Component:  Tms570_AutosarGptDriver
 *       Module:  GptDriver
 *    Generator:  None
 *
 *  Description:  This module implements RTI driver to provide services for starting and stopping a functional timer
 *                instance (channel) within the hardware timer module. Individual timeout periods (single shot mode) as
 *                well as repeating timeout periods (continuous mode) can be generated. The user can configure, if a
 *                notification shall be invoked, when the requested timeout period has expired. Notifications can be
 *                enabled and disabled at runtime. Both, the relative time elapsed since the last notification occurred
 *                (respectively the channel has been started) and the time remaining until the next notification will
 *                occur, can be queried. The GPT Driver can be used to wakeup the ECU, whenever a predefined timeout
 *                period has expired. A mode switching service is provided to switch the GPT Driver between normal
 *                operation and sleep mode.
 ********************************************************************************************************************/

/*********************************************************************************************************************
 *--------------------------------------------------------------------------------------------------------------------
 * Author:  Vishwanath Reddy
 *--------------------------------------------------------------------------------------------------------------------
 * Revision History
 *--------------------------------------------------------------------------------------------------------------------
 * Version        Date         Author               Change ID        Description
 *--------------------------------------------------------------------------------------------------------------------
 * 02.21.00    30Sep14         Vishwanath Reddy     SDOCM00113130    Initial Version
 * 02.21.01    11Mar16         Enrique Lizarraga    SDOCM00121245    Move inclusion of Std_Types.h from C to H file
 * 02.30.00    01Dec2016       Sudhakar Singh           None         Update version info
 * 05.30.00       15Mar2017    Sudhakar Singh       SDOCM00122834    Version supports TMS570LSxx Family of Devices.
 *********************************************************************************************************************/


/*********************************************************************************************************************
 * INCLUDES
 ********************************************************************************************************************/

#ifndef GPT_H
#define GPT_H 
#include "Std_Types.h"
#include "Gpt_Cfg.h"
#if (GPT_WAKEUP_FUNCTIONALITY_API == STD_ON)
    /* include for Wakeup handling */
    #include "EcuM_Cbk.h"
#endif
/*********************************************************************************************************************
 *  GLOBAL CONSTANT MACROS
 ********************************************************************************************************************/
/* AUTOSAR Release Version Information */
#define GPT_AR_RELEASE_MAJOR_VERSION       (0x04U)
#define GPT_AR_RELEASE_MINOR_VERSION       (0x00U)
#define GPT_AR_RELEASE_REVISION_VERSION    (0x03U)

#define GPT_VENDOR_ID              (44U)
#define GPT_MODULE_ID              (100U)

/* Component Version Information */
#define GPT_SW_MAJOR_VERSION               (5U)
#define GPT_SW_MINOR_VERSION               (30U)
#define GPT_SW_PATCH_VERSION               (0U)

/* SourceId : GPT_SourceId_002 */
/* DesignId : GPT_DesignId_006  */
/* Requirements : AR_GPT_SR22,AR_GPT_SR23,AR_GPT_SR24,AR_GPT_SR25,AR_GPT_SR26,AR_GPT_SR27,AR_GPT_SR28,
 *                AR_GPT_SR29,AR_GPT_SR30,AR_GPT_SR31,AR_GPT_SR32 */
/* Error codes */
#ifndef GPT_E_UNINIT
#define GPT_E_UNINIT                (0x0AU)   /* API service used without init */
#endif
#ifndef GPT_E_BUSY
#define GPT_E_BUSY                  (0x0BU)   /* Timer is already running */
#endif
#ifndef GPT_E_ALREADY_INITIALIZED
#define GPT_E_ALREADY_INITIALIZED   (0x0DU)   /* Gpt_Init is called but the module is already initialized */
#endif
#ifndef GPT_E_PARAM_CHANNEL
#define GPT_E_PARAM_CHANNEL         (0x14U)   /* API called with invalid channel */
#endif
#ifndef GPT_E_PARAM_VALUE
#define GPT_E_PARAM_VALUE           (0x15U)   /* Invalid start timer parameter */
#endif
#ifndef GPT_E_PARAM_POINTER
#define GPT_E_PARAM_POINTER         (0x16U)   /* Api called with Null_Ptr */
#endif
#ifndef GPT_E_PARAM_MODE
#define GPT_E_PARAM_MODE            (0x1FU)   /* Gpt_SetMode is called with wrong mode parameter */
#endif


/* Service Id's */
#define GPT_SID_GET_VERSION_INFO    (0x00U)   /* Service Id of Gpt_GetVersionInfo() */
#define GPT_SID_INIT                (0x01U)   /* Service Id of Gpt_Init() */
#define GPT_SID_DEINIT              (0x02U)   /* Service Id of Gpt_DeInit() */
#define GPT_SID_GET_TIME_ELAPSED    (0x03U)   /* Service Id of Gpt_GetTimeElapsed() */
#define GPT_SID_GET_TIME_REMAINING  (0x04U)   /* Service Id of Gpt_GetTimeRemaining() */
#define GPT_SID_START_TIMER         (0x05U)   /* Service Id of Gpt_StartTimer() */
#define GPT_SID_STOP_TIMER          (0x06U)   /* Service Id of Gpt_StopTimer() */
#define GPT_SID_ENABLE_NOTIFY       (0x07U)   /* Service Id of Gpt_EnableNotification() */
#define GPT_SID_DISABLE_NOTIFY      (0x08U)   /* Service Id of Gpt_DisableNotification() */
#define GPT_SID_SET_MODE            (0x09U)   /* Service Id of Gpt_SetMode() */
#define GPT_SID_DISABLE_WAKEUP      (0x0AU)   /* Service Id of Gpt_DisableWakeup() */
#define GPT_SID_ENABLE_WAKEUP       (0x0BU)   /* Service Id of Gpt_EnableWakeup() */
#define GPT_SID_CBK_CHECK_WAKEUP    (0x0CU)   /* Service Id of Gpt_Cbk_CheckWakeup() */

/* Defines for channel mode and the ISR_Function Array Indices */
#define GPT_CH_MODE_CONTINUOUS     (0U)
#define GPT_CH_MODE_ONESHOT        (1U)
#define GPT_CH_MODE_CONT_WAKEUP    (2U)
#define GPT_CH_MODE_ONESHOT_WAKEUP (3U)

#define MAX_RESOLUTION    0x0FFFFFFFU /*maximum timer resolution */


/*Gpt Channels */
#define RTI1_CHANNEL1    (0U)
#define RTI1_CHANNEL2    (1U)

/*********************************************************************************************************************
 *  GLOBAL FUNCTION MACROS
 ********************************************************************************************************************/

/********************************************************************************************************************
 *  GLOBAL DATA TYPES AND STRUCTURES
 ********************************************************************************************************************/
/* SourceId : GPT_SourceId_003 */
/* DesignId : GPT_DesignId_007  */
/* Requirements : AR_GPT_SR41,AR_GPT_SR42,AR_GPT_SR43,AR_GPT_SR44,AR_GPT_SR45 */
/* type describing the timeout value */
typedef uint32 Gpt_ValueType;

/* List of process modes */
typedef enum
{
   GPT_MODE_UNITIALIZED = 0U,
   GPT_MODE_NORMAL,
   GPT_MODE_SLEEP
} Gpt_ModeType;

typedef enum
{
   GPT_UNINITIALIZED = 0U,
   GPT_INITIALIZED,
   GPT_RUNNING,
   GPT_STOPPED,
   GPT_EXPIRED
}Gpt_ChannelStateType;

/*Type for Register readback of configuration registers*/
typedef struct GptConfigRegTag
{
    uint32 GPT_GCTRL;/* RTI Global Control Register*/
    uint32 GPT_TBCTRL;/* RTI Timebas Control Register*/
    uint32 GPT_COMPCTRL;/* RTI Compare Control Register*/
    uint32 GPT_UDCP0;/*RTI Update Compare 0 Register*/
    uint32 GPT_UDCP1;/*RTI Update Compare 1 Register*/
    uint32 GPT_UDCP2;/*RTI Update Compare 2 Register*/
    uint32 GPT_UDCP3;/*RTI Update Compare 3 Register*/
} GptConfigReg;

/*********************************************************************************************************************
 *  GLOBAL DATA PROTOTYPES
 ********************************************************************************************************************/
extern P2CONST(Gpt_ConfigType, GPT_DATA, GPT_PBCFG)  Gpt_Config_pt;
/*********************************************************************************************************************
 *  GLOBAL FUNCTION PROTOTYPES
 *********************************************************************************************************************/


#if (STD_ON == GPT_VERSION_INFO_API)
FUNC(void, GPT_CODE) Gpt_GetVersionInfo( P2VAR(Std_VersionInfoType, AUTOMATIC, GPT_APPL_DATA) versioninfo );
#endif /*(STD_ON == GPT_VERSION_INFO_API)*/

FUNC(void, GPT_CODE) Gpt_Init( P2CONST( Gpt_ConfigType, AUTOMATIC, GPT_CONST) configPtr );

#if (STD_ON == GPT_DEINIT_API)
FUNC(void, GPT_CODE) Gpt_DeInit( void );
#endif /*(STD_ON == GPT_DEINIT_API)*/

#if (STD_ON == GPT_TIME_ELAPSED_API)
FUNC(Gpt_ValueType, GPT_CODE) Gpt_GetTimeElapsed( Gpt_ChannelType channel );
#endif /*(STD_ON == GPT_TIME_ELAPSED_API)*/

#if (STD_ON == GPT_TIME_REMAINING_API)
FUNC(Gpt_ValueType, GPT_CODE) Gpt_GetTimeRemaining( Gpt_ChannelType channel );
#endif /*(STD_ON == GPT_TIME_REMAINING_API)*/

FUNC(void, GPT_CODE) Gpt_StartTimer( Gpt_ChannelType channel, Gpt_ValueType value );

FUNC(void, GPT_CODE) Gpt_StopTimer( Gpt_ChannelType channel );

#if (STD_ON == GPT_ENABLE_DISABLE_NOTIFICATION_API)
FUNC(void, GPT_CODE) Gpt_EnableNotification( Gpt_ChannelType channel );
#endif /*(STD_ON == GPT_ENABLE_DISABLE_NOTIFICATION_API)*/

#if (STD_ON == GPT_ENABLE_DISABLE_NOTIFICATION_API)
FUNC(void, GPT_CODE) Gpt_DisableNotification( Gpt_ChannelType channel );
#endif /*(STD_ON == GPT_ENABLE_DISABLE_NOTIFICATION_API)*/

#if (STD_ON == GPT_WAKEUP_FUNCTIONALITY_API)
FUNC(void, GPT_CODE) Gpt_SetMode( Gpt_ModeType mode );
#endif /*(STD_ON == GPT_WAKEUP_FUNCTIONALITY_API)*/

#if (STD_ON == GPT_WAKEUP_FUNCTIONALITY_API)
FUNC(void, GPT_CODE) Gpt_DisableWakeup( Gpt_ChannelType channel );
#endif /*(STD_ON == GPT_WAKEUP_FUNCTIONALITY_API)*/

#if (STD_ON == GPT_WAKEUP_FUNCTIONALITY_API)
FUNC(void, GPT_CODE) Gpt_EnableWakeup( Gpt_ChannelType channel );
#endif /*(STD_ON == GPT_WAKEUP_FUNCTIONALITY_API)*/

#if (STD_ON == GPT_WAKEUP_FUNCTIONALITY_API)
FUNC(void, GPT_CODE) Gpt_CheckWakeup( EcuM_WakeupSourceType wakeupSource );
#endif /*(STD_ON == GPT_WAKEUP_FUNCTIONALITY_API)*/

#if (STD_ON == GPT_SAFETI_API)
FUNC(Std_ReturnType, ICU_CODE) Gpt_ConfigRegReadBack( GptConfigReg* GptConfigReg_pt );
#endif


#endif  /* GPT_H */

/*********************************************************************************************************************
 *  END OF FILE: Gpt.h
 ********************************************************************************************************************/
