/*!
* @file     Icu_Tmr.h
*
* @version  1.0.0
*
* @brief    Header file of AUTOSAR Icu driver by TMR
*
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_01-Otc-25
*
* Copyright (C) 2026 Geehy Semiconductor
*
* You may not use this file except in compliance with the
* GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
*
* The program is only for reference, which is distributed in the hope
* that it will be usefull and instructional for customers to develop
* their software. Unless required by applicable law or agreed to in
* writing, the program is distributed on an "AS IS" BASIS, WITHOUT
* ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
* See the Geehy Semiconductor Software License Agreement for the governing permissions
* and limitations under the License.
*/

#ifndef ICU_TMR_H
#define ICU_TMR_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Icu_TmrTypes.h"
#include "Icu_Types.h"

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
#include "CDD_Pdl.h"
#endif
#endif

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup ICU_Driver
  * @brief ICU driver modules
  @{
*/

/** @defgroup ICU_Macros
  @{
*/
/**************************************************************************
                  VENDOR ID & AUTOSAR VERSION INFO
**************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define ICU_TMR_H_VENDOR_ID                        0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_TMR_H_AR_RELEASE_MAJOR_VERSION         0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_TMR_H_AR_RELEASE_MINOR_VERSION         0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_TMR_H_AR_RELEASE_REVISION_VERSION      0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_TMR_H_SW_MAJOR_VERSION                 0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_TMR_H_SW_MINOR_VERSION                 0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_TMR_H_SW_PATCH_VERSION                 0x00U

/**@} end of group ICU_Macros */

/**************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************/
/* Make sure the vendor id is the same between Icu_Tmr.h and Icu_Types.h */
#if (ICU_TMR_H_VENDOR_ID != ICU_TYPE_H_VENDOR_ID)
    #error "Vendor id mismatch between Icu_Tmr.h and Icu_Types.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Icu_Tmr.h and Icu_Types.h */
#if (ICU_TMR_H_AR_RELEASE_MAJOR_VERSION != ICU_TYPE_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Icu_Tmr.h and Icu_Types.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Icu_Tmr.h and Icu_Types.h */
#if (ICU_TMR_H_AR_RELEASE_MINOR_VERSION != ICU_TYPE_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Icu_Tmr.h and Icu_Types.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Icu_Tmr.h and Icu_Types.h */
#if (ICU_TMR_H_AR_RELEASE_REVISION_VERSION != ICU_TYPE_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Icu_Tmr.h and Icu_Types.h"
#endif
/* Make sure the software major version number is the same between Icu_Tmr.h and Icu_Types.h */
#if (ICU_TMR_H_SW_MAJOR_VERSION != ICU_TYPE_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Icu_Tmr.h and Icu_Types.h"
#endif
/* Make sure the software minor version number is the same between Icu_Tmr.h and Icu_Types.h */
#if (ICU_TMR_H_SW_MINOR_VERSION != ICU_TYPE_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Icu_Tmr.h and Icu_Types.h"
#endif
/* Make sure the software patch version number is the same between Icu_Tmr.h and Icu_Types.h */
#if (ICU_TMR_H_SW_PATCH_VERSION != ICU_TYPE_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Icu_Tmr.h and Icu_Types.h"
#endif

/* Make sure the vendor id is the same between Icu_Tmr.h and Icu_TmrTypes.h */
#if (ICU_TMR_H_VENDOR_ID != ICU_TMR_TYPE_H_VENDOR_ID)
    #error "Vendor id mismatch between Icu_Tmr.h and Icu_TmrTypes.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Icu_Tmr.h and Icu_TmrTypes.h */
#if (ICU_TMR_H_AR_RELEASE_MAJOR_VERSION != ICU_TMR_TYPE_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Icu_Tmr.h and Icu_TmrTypes.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Icu_Tmr.h and Icu_TmrTypes.h */
#if (ICU_TMR_H_AR_RELEASE_MINOR_VERSION != ICU_TMR_TYPE_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Icu_Tmr.h and Icu_TmrTypes.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Icu_Tmr.h and Icu_TmrTypes.h */
#if (ICU_TMR_H_AR_RELEASE_REVISION_VERSION != ICU_TMR_TYPE_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Icu_Tmr.h and Icu_TmrTypes.h"
#endif
/* Make sure the software major version number is the same between Icu_Tmr.h and Icu_TmrTypes.h */
#if (ICU_TMR_H_SW_MAJOR_VERSION != ICU_TMR_TYPE_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Icu_Tmr.h and Icu_TmrTypes.h"
#endif
/* Make sure the software minor version number is the same between Icu_Tmr.h and Icu_TmrTypes.h */
#if (ICU_TMR_H_SW_MINOR_VERSION != ICU_TMR_TYPE_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Icu_Tmr.h and Icu_TmrTypes.h"
#endif
/* Make sure the software patch version number is the same between Icu_Tmr.h and Icu_TmrTypes.h */
#if (ICU_TMR_H_SW_PATCH_VERSION != ICU_TMR_TYPE_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Icu_Tmr.h and Icu_TmrTypes.h"
#endif

/**************************************************************************
                    ENUMERATION DEFINITION
**************************************************************************/
/** @defgroup ICU_Enumerations
  @{
*/

/**
 * @brief    ICU BIT State
 */
typedef enum
{
    ICU_BIT_RESET = 0U,
    ICU_BIT_SET = 1U
} Icu_BitStatusType;

/**
 * @brief   Defines s_icuTmrChFeatureState bit mask value.
 */
typedef enum
{
    TMR_ICU_OVERFLOW_FLAG_MASK_VAL  = (uint16)0x4000,  //!< bit14 mask value

    TMR_ICU_ACTIVE_EDGE_MASK_VAL    = (uint16)0x3C00,  //!< bit13 bit12 bit11 and bit10 mask value

    TMR_ICU_INIT_MASK_VAL           = (uint16)0x0200,  //!< bit9 mask value

    TMR_ICU_MEA_MODE_MASK_VAL       = (uint16)0x01F0,  //!< bit8 bit7 bit6 bit5 and bit4 mask value

    TMR_ICU_MEA_ITEM_MASK_VAL       = (uint16)0x000F   //!<  bit3 bit2 bit1 and bit0 mask value

} Icu_TmrChFeatureBitMaskValType;

/**
 * @brief   Defines s_icuTmrChFeatureState bit offset.
 */
typedef enum
{
    TMR_ICU_OVERFLOW_FLAG_BIT_OFFSET  = 14U,   //!< bit14

    TMR_ICU_ACTIVE_EDGE_BIT_OFFSET    = 10U,   //!< bit10

    TMR_ICU_MEA_MODE_BIT_OFFSET       = 4U,   //!< bit4

    TMR_ICU_MEA_ITEM_BIT_OFFSET       = 0U    //!< bit0

} Icu_TmrChFeatureBitOffsetType;

/**@} end of group ICU_Enumerations */

/**************************************************************************
                    OTHER TYPE DEFINITION
**************************************************************************/
/** @defgroup ICU_Structure
  @{
*/

/** ICU channel function */
typedef  uint8   Icu_TmrChModeType;
/** active edge select */
typedef  uint8   Icu_TmrActiveEdgeType;
/** measurement property configurable item */
typedef  uint8   Icu_TmrMeasurePropertyType;
/** tmr channel state */
typedef  uint16  Icu_TmrChFeatureStateType;

/**@} end of group ICU_Structure */

/**************************************************************************
                    MACRO DEFINITION
**************************************************************************/
/** @defgroup ICU_Macros
  @{
*/

/** Edge detect function */
#define  ICU_TMR_EDGE_DETECT_FUNCTION              ((Icu_TmrChModeType)(0x01U << 0U))
/** Signal measurement function */
#define  ICU_TMR_MEASUREMENT_FUNCTION              ((Icu_TmrChModeType)(0x01U << 1U))
/** Time stamp without DMA function */
#define  ICU_TMR_TIMESTAMP_WITHOUT_DMA_FUNCTION    ((Icu_TmrChModeType)(0x01U << 2U))
/** Edge count function */
#define  ICU_TMR_EDGE_COUNT_FUNCTION               ((Icu_TmrChModeType)(0x01U << 3U))
/** Time stamp with DMA function */
#define  ICU_TMR_TIMESTAMP_WITH_DMA_FUNCTION       ((Icu_TmrChModeType)(0x01U << 4U))

/** Active edge is rising edge */
#define  ICU_TMR_ACTIVE_EDGE_IS_RISING              ((Icu_TmrActiveEdgeType)0x00U)
/** Active edge is falling edge */
#define  ICU_TMR_ACTIVE_EDGE_IS_FALLING             ((Icu_TmrActiveEdgeType)0x02U)
/** Active edge is both edge */
#define  ICU_TMR_ACTIVE_EDGE_IS_BOTH                ((Icu_TmrActiveEdgeType)0x0AU)

/** measure low level elapse time */
#define  ICU_TMR_MEASURE_LOW_LEVEL                  ((Icu_TmrMeasurePropertyType)(0x01U << 0U))
/** measure high level elapse time */
#define  ICU_TMR_MEASURE_HIGH_LEVEL                 ((Icu_TmrMeasurePropertyType)(0x01U << 1U))
/** measure period elapse time */
#define  ICU_TMR_MEASURE_PERIOD_TIME                ((Icu_TmrMeasurePropertyType)(0x01U << 2U))
/** measure duty cycle */
#define  ICU_TMR_MEASURE_DUTYCYCLE                  ((Icu_TmrMeasurePropertyType)(0x01U << 3U))

#define  TMR_CH_CNT_PER_MODULE                      ((uint8)5U)

/** TMR channel id:ICU_TMRn_CH0 - ICU_TMRn_CH4 */
#define  TMR_MOD_ID(ChannelId)                      (ChannelId / TMR_CH_CNT_PER_MODULE)
#define  TMR_CH_ID(ChannelId)                       (ChannelId % TMR_CH_CNT_PER_MODULE)

/**@} end of group ICU_Macros */

/**************************************************************************
                    FUNCTION DECLARATION
**************************************************************************/
#define ICU_START_SEC_CODE
#include "Icu_MemMap.h"

/** @defgroup ICU_Fuctions
  @{
*/

FUNC(void, ICU_CODE) Icu_Tmr_Init(P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) tmrIpConfigPtr);

#if (STD_ON == ICU_DE_INIT_API_ENABLE)
FUNC(void, ICU_CODE) Icu_Tmr_Deinit(P2CONST(Icu_TmrIPCfgType, AUTOMATIC, ICU_APPL_CONST) channelTmrIpConfigPtr);
#endif

#if (STD_ON == ICU_SET_MODE_API_ENABLE)
FUNC(void, ICU_CODE) Icu_Tmr_SetSleepMode(CONST(Icu_TmrChType, AUTOMATIC) ch);
FUNC(void, ICU_CODE) Icu_Tmr_SetNormalMode(CONST(Icu_TmrChType, AUTOMATIC) ch);
#endif

FUNC(void, ICU_CODE) Icu_Tmr_SetActivationCondition(CONST(Icu_TmrChType,AUTOMATIC) ch,
                                                    CONST(Icu_TmrActiveEdgeType,AUTOMATIC) aimEdge);

#if (STD_ON == ICU_GET_INPUT_STATE_API_ENABLE)
FUNC (boolean, ICU_CODE) Icu_Tmr_GetInputState(CONST(Icu_TmrChType, AUTOMATIC) ch);
#endif

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
FUNC(void, ICU_CODE) Icu_Tmr_StartTimestamp(CONST(Icu_TmrChType,AUTOMATIC) ch, CONST(boolean,AUTOMATIC) dmaCap);
FUNC(void, ICU_CODE) Icu_Tmr_StopTimestamp(CONST(Icu_TmrChType, AUTOMATIC) ch);
#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
FUNC(uint32, ICU_CODE) Icu_Tmr_GetStartAddress(CONST(Icu_TmrChType, AUTOMATIC) ch);
FUNC(void, ICU_CODE) Icu_Tmr_SetDmaCh(CONST(Icu_TmrChType, AUTOMATIC) ch, 
                                    P2CONST(Pdl_DmaChHwConfigType, AUTOMATIC, ICU_APPL_CONST) pDmaChConfig, VAR(uint8, AUTOMATIC) dmaChEn);
#endif
#endif

#if (STD_ON == ICU_EDGE_COUNT_API_ENABLE)
    FUNC(void, ICU_CODE) Icu_Tmr_ResetEdgeCount(CONST(Icu_TmrChType, AUTOMATIC) ch);
FUNC(void, ICU_CODE) Icu_Tmr_EnableEdgeCount(CONST(Icu_TmrChType, AUTOMATIC) ch);
FUNC(void, ICU_CODE) Icu_Tmr_DisableEdgeCount(CONST(Icu_TmrChType, AUTOMATIC) ch);
FUNC(uint16, ICU_CODE) Icu_Tmr_GetEdgeNumbers(CONST(Icu_TmrChType, AUTOMATIC) ch);
#endif

#if (STD_ON == ICU_EDGE_DETECT_API_ENABLE)
FUNC(void, ICU_CODE) Icu_Tmr_EnableEdgeDetection(CONST(Icu_TmrChType, AUTOMATIC) ch);
FUNC(void, ICU_CODE) Icu_Tmr_DisableEdgeDetection(CONST(Icu_TmrChType, AUTOMATIC) ch);
#endif

#if (STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE)
FUNC(void, ICU_CODE) Icu_Tmr_StartSignalMeasurement(CONST(Icu_TmrChType, AUTOMATIC) ch, 
                                                    CONST(Icu_TmrMeasurePropertyType, AUTOMATIC) meaItem);

FUNC(void, ICU_CODE) Icu_Tmr_StopSignalMeasurement(CONST(Icu_TmrChType, AUTOMATIC) ch);
#endif

FUNC(uint16, ICU_CODE) Icu_Tmr_ReadTmrCCnRegValue(CONST(Icu_TmrHwChType, AUTOMATIC) tmrHwCh, 
                                                  CONST(Icu_TmrModuleType, AUTOMATIC) tmrModule);

#if (STD_ON == ICU_DUAL_CLOCK_MODE_API_ENABLE)
FUNC(void, ICU_CODE) Icu_Tmr_SetClkPrescaler(CONST(Icu_TmrModuleType, AUTOMATIC) moduleId,VAR(Icu_TmrPscType, AUTOMATIC) preMode);
#endif

FUNC (boolean, ICU_CODE) Icu_Tmr_GetOverflow(CONST(Icu_TmrChType, AUTOMATIC) ch);

#if (STD_OFF == ICU_TMR_CUSTOM_FEATURE_ENABLE)
FUNC(void, ICU_CODE) Icu_Tmr_ProcessInterrupt(CONST(Icu_TmrModuleType, AUTOMATIC) tmrModule);

FUNC(void, ICU_CODE) Icu_Tmr_Tmr1ProcessOfInterrupt(CONST(Icu_TmrModuleType, AUTOMATIC) tmrModule);
#endif

#if (STD_ON == ICU_TMR_CUSTOM_FEATURE_ENABLE)
FUNC(void, ICU_CODE) Icu_Tmr_CustomFunctionOvfIrq(CONST(Icu_TmrModuleType, AUTOMATIC) tmrModule);
FUNC(void, ICU_CODE) Icu_Tmr_CustomFunctionIrq(CONST(Icu_TmrModuleType, AUTOMATIC) tmrModule);
FUNC(void, ICU_CODE) Icu_Tmr_InterruptSet(CONST(Icu_TmrHwChType, AUTOMATIC) tmrChannel, CONST(Icu_TmrModuleType, AUTOMATIC) tmrModule, 
                                          CONST(Icu_TmrIcInterruptType, AUTOMATIC) interrupt, CONST(uint8, AUTOMATIC) enable);
FUNC(void, ICU_CODE) Icu_Tmr_SetHwChActiveEdge(CONST(Icu_TmrHwChType, AUTOMATIC) tmrHwCh, CONST(Icu_TmrModuleType, AUTOMATIC) tmrModule, 
                                                 VAR(Icu_TmrActiveEdgeType, AUTOMATIC) icuActiveEdge);
#endif

/**@} end of group ICU_Fuctions */

#define ICU_STOP_SEC_CODE
#include "Icu_MemMap.h"

#ifdef __cplusplus
}
#endif

#endif

/**@} end of group ICU_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
