/**********************************************************************************************************************
 *  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:  Icu.h
 *      Project:  Tms570_AutosarIcuDriver
 *       Module:  ICU
 *    Generator:  -
 *
 *  Description:  The ICU driver is a module using the input capture unit (ICU) for demodulation of a PWM signal,
 *                counting pulses, measuring of frequency and duty cycle, generating simple interrupts and wake-up
 *                interrupts.
 *
 *                The ICU driver provides services for
 *                -    Signal edge notification
 *                -    Controlling wake-up interrupts
 *                -    Periodic signal time measurement
 *                -    Edge timestamping, usable for the acquisition of non-periodic signals
 *                -    Edge counting
 *
 *                This module works on pins and ports which are configured by the PORT driver for this purpose. For
 *                this reason there is no configuration and initialization of this port structure in the ICU Driver.
 *********************************************************************************************************************/

/**********************************************************************************************************************
 *---------------------------------------------------------------------------------------------------------------------
 * Author:  Vineeth Thomas Alex
 *---------------------------------------------------------------------------------------------------------------------
 * Revision History
 *---------------------------------------------------------------------------------------------------------------------
 * Version     Date           Author                   Change ID          Description
 *---------------------------------------------------------------------------------------------------------------------
 * 02.21.00    30Sept2014     Vineeth Thomas Alex      SDOCM00113121      Initial version adapted from TMS570LS3137
 * 02.21.01    16Mar2016      Enrique Lizarraga        SDOCM00121723      Rename AUTOSAR Release Version macros
 * 02.30.00    01Dec2016      Sudhakar Singh           None               Update version info
 * 05.30.00    15Mar2017      Sudhakar Singh           SDOCM00122834      Version supports TMS570LSxx Family of Devices.
 *********************************************************************************************************************/

#ifndef ICU_H
#define ICU_H

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

#include "Std_Types.h"
#include "Icu_Cfg.h"
#if (ICU_WAKEUP_FUNCTIONALITY_API == STD_ON)
	/*If wakeup is configured*/
	#include "EcuM_Cbk.h"
#endif

/**********************************************************************************************************************
 *  GLOBAL CONSTANT MACROS
 *********************************************************************************************************************/
/* vendor and module identification */
#define ICU_VENDOR_ID              (44U)
#define ICU_MODULE_ID              (122U)

/* AUTOSAR Software Specification Version Information */
#define ICU_AR_RELEASE_MAJOR_VERSION       (4U)
#define ICU_AR_RELEASE_MINOR_VERSION       (0U)
#define ICU_AR_RELEASE_REVISION_VERSION    (3U)

/* Component Version Information */
#define ICU_SW_MAJOR_VERSION               (5U)
#define ICU_SW_MINOR_VERSION               (30U)
#define ICU_SW_PATCH_VERSION               (0U)

/* ===== Error Codes =============================================================================================== */
/* SourceId : ICU_SourceId_002 */
/* DesignId : ICU_DesignId_06  */
/* Requirements : AR_ICU_SR24,AR_ICU_SR25,AR_ICU_SR26,AR_ICU_SR27,AR_ICU_SR28,AR_ICU_SR29,AR_ICU_SR30,AR_ICU_SR31,
 *                AR_ICU_SR32,AR_ICU_SR33,AR_ICU_SR34,AR_ICU_SR35,AR_ICU_SR101,AR_ICU_SR102 */
/* API Icu_Init service called with wrong parameter */
#ifndef ICU_E_PARAM_CONFIG
#define ICU_E_PARAM_CONFIG          (0x0AU)
#endif
/* API service used with an invalid channel identifier or channel was not
 * configured for the functionality of the calling API */
#ifndef ICU_E_PARAM_CHANNEL
#define ICU_E_PARAM_CHANNEL         (0x0BU)
#endif
/* API service used with an invalid or not feasible activation */
#ifndef ICU_E_PARAM_ACTIVATION
#define ICU_E_PARAM_ACTIVATION      (0x0CU)
#endif
/* API service used with an invalid application-buffer pointer */
#ifndef ICU_E_PARAM_BUFFER_PTR
#define ICU_E_PARAM_BUFFER_PTR      (0x0DU)
#endif
/* API service used with an invalid buffer size */
#ifndef ICU_E_PARAM_BUFFER_SIZE
#define ICU_E_PARAM_BUFFER_SIZE     (0x0EU)
#endif
/* API service used with an invalid buffer size */
#ifndef ICU_E_PARAM_NOTIFY_INTERVAL
#define ICU_E_PARAM_NOTIFY_INTERVAL (0x18U)
#endif
/* API service Icu_SetMode used with an invalid mode */
#ifndef ICU_E_PARAM_MODE
#define ICU_E_PARAM_MODE            (0x0FU)
#endif
/* API service used without module initialization */
#ifndef ICU_E_UNINIT
#define ICU_E_UNINIT                (0x14U)
#endif
/* API service Icu_StopTimestamp called on a channel which was not started
 * or already stopped */
#ifndef ICU_E_NOT_STARTED
#define ICU_E_NOT_STARTED           (0x15U)
#endif
/* API service Icu_SetMode is called during a running operation */
#ifndef ICU_E_BUSY_OPERATION
#define ICU_E_BUSY_OPERATION        (0x16U)
#endif
/* The service Icu_Init() is called while the driver is already initialized */
#ifndef ICU_E_ALREADY_INITIALIZED
#define ICU_E_ALREADY_INITIALIZED   (0x17U)
#endif
/* API service Icu_GetVersionInfo() called with wrong parameter */
#ifndef ICU_E_PARAM_VINFO
#define ICU_E_PARAM_VINFO           (0x19U)
#endif


/* Instance ID */
#define ICU_INSTANCE_ID            (0U)

/* ===== Service IDs =============================================================================================== */
#define ICU_SID_INIT                        (0x00U)
#define ICU_SID_DE_INIT                     (0x01U)
#define ICU_SID_SET_MODE                    (0x02U)
#define ICU_SID_DISABLE_WAKEUP              (0x03U)
#define ICU_SID_ENABLE_WAKEUP               (0x04U)
#define ICU_SID_SET_ACTIVATION_CONDITION    (0x05U)
#define ICU_SID_DISABLE_NOTIFICATION        (0x06U)
#define ICU_SID_ENABLE_NOTIFICATION         (0x07U)
#define ICU_SID_GET_INPUT_STATE             (0x08U)
#define ICU_SID_START_TIMESTAMP             (0x09U)
#define ICU_SID_STOP_TIMESTAMP              (0x0AU)
#define ICU_SID_GET_TIMESTAMP_INDEX         (0x0BU)
#define ICU_SID_RESET_EDGE_COUNT            (0x0CU)
#define ICU_SID_ENABLE_EDGE_COUNT           (0x0DU)
#define ICU_SID_DISABLE_EDGE_COUNT          (0x0EU)
#define ICU_SID_START_SIG_MEASUREMENT       (0x13U)
#define ICU_SID_STOP_SIG_MEASUREMENT        (0x14U)
#define ICU_SID_CHECK_WAKEUP                (0x15U)
#define ICU_SID_ENABLE_EDGE_DETECT          (0x16U)
#define ICU_SID_DISABLE_EDGE_DETECT         (0x17U)
#define ICU_SID_GET_EDGE_NUMBERS            (0x0FU)
#define ICU_SID_GET_TIME_ELAPSED            (0x10U)
#define ICU_SID_GET_DUTY_CYCLE_VALUES       (0x11U)
#define ICU_SID_GET_VERSION_INFO            (0x12U)

#define ICU_HET1_RAM_ADDR             ((uint32)0xFF460000U)
#define ICU_HET1_REG_ADDR             ((uint32)0xFFF7B800U)

#define ICU_HET2_RAM_ADDR             ((uint32)0xFF440000U)
#define ICU_HET2_REG_ADDR             ((uint32)0xFFF7B900U)
/**********************************************************************************************************************
 *  GLOBAL FUNCTION MACROS
 *********************************************************************************************************************/

/**********************************************************************************************************************
 *  GLOBAL DATA TYPES AND STRUCTURES
 *********************************************************************************************************************/

/* ===== Architecture-independent types ============================================================================ */

/* This type is only used in service Icu_SetMode() */
#if ( ICU_SET_MODE_API == STD_ON )

/* SourceId : ICU_SourceId_001 */
/* DesignId : ICU_DesignId_12  */
/* Requirements : AR_ICU_SR18 */
/* Allow enabling / disabling of all interrupts which are not required
 * for the ECU wakeup. */
typedef enum
{
    ICU_MODE_NORMAL = 0U,
    ICU_MODE_SLEEP
} Icu_ModeType;

#endif  /*  STD_ON == ICU_SET_MODE_API ) */

/* SourceId : ICU_SourceId_004 */
/* DesignId : ICU_DesignId_12  */
/* Requirements : AR_ICU_SR41,AR_ICU_SR54 */
/* Input state of an ICU channel */
typedef uint8 Icu_InputStateType;
#define ICU_IDLE            (0U)     /* Elements of Icu_InputStateType */
#define ICU_ACTIVE          (1U)

/* Type which shall contain the values, needed for calculating duty cycles */
typedef struct
{
    Icu_ValueType ActiveTime;
    Icu_ValueType PeriodTime;
}Icu_DutyCycleType;

/* ===== Architecture-dependent types ============================================================================== */

/* SourceId : ICU_SourceId_003 */
/* DesignId : ICU_DesignId_12  */
/* Requirements : AR_ICU_SR40,AR_ICU_SR56 */
/* Numeric identifier of an ICU channel */
typedef uint8 Icu_ChannelType;

typedef uint32 Icu_EdgeNumberType;

#if(STD_ON == ICU_SAFETI_API)
/*HET Type*/
typedef enum
{
	NHETCLR = 0U,
	NHET1 = 1U,
    NHET2 = 2U
}Icu_HetType;
/* ICU Config registers */
typedef struct IcuConfigRegTag
{
	uint32              Icu_ReadBack_GCR;                 /* NHET Global Control Register      */
	uint32              Icu_ReadBack_PFR;                 /* NHET Pre-scale Factor Register    */
	uint32              Icu_ReadBack_PRY;                 /* NHET Interrupt Priority Register  */
	uint32              Icu_ReadBack_DIR;                 /* NHET Direction Register           */
	uint32              Icu_ReadBack_PDR;                 /* NHET Open Drain Register          */
	uint32              Icu_ReadBack_PDIS;           	  /* NHET Pull Disable Register        */
	uint32              Icu_ReadBack_PSL;                 /* NHET Pull Select Register         */
} IcuConfigReg;
#endif
/**********************************************************************************************************************
 *  GLOBAL DATA PROTOTYPES
 *********************************************************************************************************************/

/**********************************************************************************************************************
 *  GLOBAL FUNCTION PROTOTYPES
 *********************************************************************************************************************/


  FUNC(void, ICU_CODE) Icu_DoNothing(void);

  FUNC(void, ICU_CODE) Icu_Init(P2CONST( Icu_ConfigType, AUTOMATIC, ICU_PBCFG) ConfigPtr);

#if ( ICU_DE_INIT_API == STD_ON )
  FUNC(void, ICU_CODE) Icu_DeInit(void);
#endif

#if ( ICU_SET_MODE_API == STD_ON )
  FUNC(void, ICU_CODE) Icu_SetMode(Icu_ModeType Mode);
#endif

#if ( ICU_DISABLE_WAKEUP_API == STD_ON )
  FUNC(void, ICU_CODE) Icu_DisableWakeup(Icu_ChannelType Channel);
#endif

#if ( ICU_ENABLE_WAKEUP_API == STD_ON )
  FUNC(void, ICU_CODE) Icu_EnableWakeup(Icu_ChannelType Channel);
#endif

#if (STD_ON == ICU_WAKEUP_FUNCTIONALITY_API)
  FUNC(void, ICU_CODE) Icu_CheckWakeup ( EcuM_WakeupSourceType wakeupSource );
#endif

  FUNC(void, ICU_CODE) Icu_SetActivationCondition
(
    Icu_ChannelType Channel,
    Icu_ActivationType Activation
);

  FUNC(void, ICU_CODE) Icu_DisableNotification(Icu_ChannelType Channel);
  FUNC(void, ICU_CODE) Icu_EnableNotification(Icu_ChannelType Channel);

#if ( ICU_GET_INPUT_STATE_API == STD_ON )
  FUNC(Icu_InputStateType, ICU_CODE) Icu_GetInputState(Icu_ChannelType Channel);
#endif

#if ( ICU_TIMESTAMP_API == STD_ON )
  FUNC(void, ICU_CODE) Icu_StartTimestamp
(
    Icu_ChannelType Channel,
    P2VAR(Icu_ValueType, ICU_VAR_FAST, ICU_APPL_DATA) BufferPtr,
    Icu_IndexType BufferSize,
    Icu_IndexType NotifyInterval
);

  FUNC(void, ICU_CODE) Icu_StopTimestamp(Icu_ChannelType Channel);
  FUNC(Icu_IndexType, ICU_CODE) Icu_GetTimestampIndex(Icu_ChannelType Channel);
#endif

#if ( ICU_EDGE_COUNT_API == STD_ON )
  FUNC(void, ICU_CODE) Icu_ResetEdgeCount(Icu_ChannelType Channel);
  FUNC(void, ICU_CODE) Icu_EnableEdgeCount(Icu_ChannelType Channel);
  FUNC(void, ICU_CODE) Icu_DisableEdgeCount(Icu_ChannelType Channel);
  FUNC(Icu_EdgeNumberType, ICU_CODE) Icu_GetEdgeNumbers(Icu_ChannelType Channel);
#endif

#if ( ICU_SIGNAL_MEASUREMENT_API == STD_ON )
  FUNC(void, ICU_CODE) Icu_StartSignalMeasurement(Icu_ChannelType Channel);
  FUNC(void, ICU_CODE) Icu_StopSignalMeasurement(Icu_ChannelType Channel);
#endif

#if ( ICU_GET_TIME_ELAPSED_API == STD_ON )
  FUNC(Icu_ValueType, ICU_CODE) Icu_GetTimeElapsed(Icu_ChannelType Channel);
#endif

#if ( ICU_GET_DUTY_CYCLE_VALUES_API == STD_ON )
  FUNC(void, ICU_CODE) Icu_GetDutyCycleValues
(
    Icu_ChannelType Channel,
    P2VAR(Icu_DutyCycleType, ICU_VAR_FAST, ICU_APPL_DATA) DutyCycleValues
);
#endif

#if (ICU_EDGE_DETECTION_API == STD_ON)
  FUNC(void, ICU_CODE) Icu_EnableEdgeDetection(Icu_ChannelType Channel);
  FUNC(void, ICU_CODE) Icu_DisableEdgeDetection(Icu_ChannelType Channel);
#endif

#if ( ICU_GET_VERSION_INFO_API == STD_ON )
  FUNC(void, ICU_CODE) Icu_GetVersionInfo
(
    P2VAR(Std_VersionInfoType, AUTOMATIC, ICU_APPL_DATA) versioninfo
);
#endif

#if(STD_ON == ICU_SAFETI_API)
   /*Readback of configuration registers*/
  FUNC(Std_ReturnType, ICU_CODE) Icu_ConfigRegReadBack(Icu_HetType Het, IcuConfigReg* IcuConfigReg_pt);
#endif


#endif

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