/*!
* @file     Icu.h
*
* @version  1.0.0
*
* @brief    Header file of AUTOSAR Icu driver
*
* @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_H
#define ICU_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Std_Types.h"
#include "Icu_Types.h"
#if (STD_ON == ICU_REPORT_WAKEUP_SOURCE_ENABLE)
    #include "EcuM_Cbk.h"
#endif
#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
    #include "CDD_Pdl.h"
#endif

#include "Icu_Tmr.h"

/** @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_H_VENDOR_ID                        0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define ICU_H_MODULE_ID                        0x007AU
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_H_AR_RELEASE_MAJOR_VERSION         0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_H_AR_RELEASE_MINOR_VERSION         0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_H_AR_RELEASE_REVISION_VERSION      0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_H_SW_MAJOR_VERSION                 0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_H_SW_MINOR_VERSION                 0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_H_SW_PATCH_VERSION                 0x00U

/**@} end of group ICU_Macros */

/**************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************/
/* Make sure the vendor id is the same between Icu.h and Icu_Cfg.h */
#if (ICU_H_VENDOR_ID != ICU_CFG_H_VENDOR_ID)
    #error "Vendor id mismatch between Icu.h and Icu_Cfg.h"
#endif
/* Make sure the AUTOSAR major version number is the same between Icu.h and Icu_Cfg.h */
#if (ICU_H_AR_RELEASE_MAJOR_VERSION != ICU_CFG_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Icu.h and Icu_Cfg.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Icu.h and Icu_Cfg.h */
#if (ICU_H_AR_RELEASE_MINOR_VERSION != ICU_CFG_H_AR_RELEASE_MINOR_VERSION) 
    #error "AUTOSAR Minor Version Number mismatch between Icu.h and Icu_Cfg.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Icu.h and Icu_Cfg.h */
#if (ICU_H_AR_RELEASE_REVISION_VERSION != ICU_CFG_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Icu.h and Icu_Cfg.h"
#endif
/* Make sure the software major version number is the same between Icu.h and Icu_Cfg.h */
#if (ICU_H_SW_MAJOR_VERSION != ICU_CFG_H_SW_MAJOR_VERSION) 
    #error "Software Major Version Number mismatch between Icu.h and Icu_Cfg.h"
#endif
/* Make sure the software minor version number is the same between Icu.h and Icu_Cfg.h */
#if (ICU_H_SW_MINOR_VERSION != ICU_CFG_H_SW_MINOR_VERSION) 
    #error "Software Minor Version Number mismatch between Icu.h and Icu_Cfg.h"
#endif
/* Make sure the software patch version number is the same between Icu.h and Icu_Cfg.h */
#if (ICU_H_SW_PATCH_VERSION != ICU_CFG_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Icu.h and Icu_Cfg.h"
#endif

#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
    #ifdef ENABLE_INTERMODULE_MCAL_CHECK
        /* Make sure the AUTOSAR major version number is the same between Icu.h and CDD_Pdl.h */
        #if (ICU_H_AR_RELEASE_MAJOR_VERSION != CDD_PDL_H_AR_RELEASE_MAJOR_VERSION) 
            #error "AUTOSAR Major Version Number mismatch between Icu.h and CDD_Pdl.h"
        #endif
        /* Make sure the AUTOSAR minor version number is the same between Icu.h and CDD_Pdl.h */
        #if (ICU_H_AR_RELEASE_MINOR_VERSION != CDD_PDL_H_AR_RELEASE_MINOR_VERSION)
            #error "AUTOSAR Minor Version Number mismatch between Icu.h and CDD_Pdl.h"
        #endif
    #endif
#endif

#if (STD_ON == ICU_REPORT_WAKEUP_SOURCE_ENABLE)
    #ifdef ENABLE_INTERMODULE_MCAL_CHECK
        /* Make sure the AUTOSAR major version number is the same between Icu.h and EcuM_Cbk.h */
        #if (ICU_H_AR_RELEASE_MAJOR_VERSION != ECUM_CBK_H_AR_RELEASE_MAJOR_VERSION) 
            #error "AUTOSAR Major Version Number mismatch between Icu.h and EcuM_Cbk.h"
        #endif
        /* Make sure the AUTOSAR minor version number is the same between Icu.h and EcuM_Cbk.h */
        #if (ICU_H_AR_RELEASE_MINOR_VERSION != ECUM_CBK_H_AR_RELEASE_MINOR_VERSION)
            #error "AUTOSAR Minor Version Number mismatch between Icu.h and EcuM_Cbk.h"
        #endif
    #endif
#endif

#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Icu.h and Std_Types.h */
    #if (ICU_H_AR_RELEASE_MAJOR_VERSION != STD_TYPES_H_AR_RELEASE_MAJOR_VERSION) 
        #error "AUTOSAR Major Version Number mismatch between Icu.h and Std_Types.h"
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Icu.h and Std_Types.h */
    #if (ICU_H_AR_RELEASE_MINOR_VERSION != STD_TYPES_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR Minor Version Number mismatch between Icu.h and Std_Types.h"
    #endif
#endif

/* Make sure the vendor id is the same between Icu.h and Icu_Tmr.h */
#if (ICU_H_VENDOR_ID != ICU_TMR_H_VENDOR_ID)
    #error "Vendor id mismatch between Icu.h and Icu_Tmr.h "
#endif
/* Make sure the AUTOSAR major version number is the same between Icu.h and Icu_Tmr.h */
#if (ICU_H_AR_RELEASE_MAJOR_VERSION != ICU_TMR_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Icu.h and Icu_Tmr.h "
#endif
/* Make sure the AUTOSAR minor version number is the same between Icu.h and Icu_Tmr.h */
#if (ICU_H_AR_RELEASE_MINOR_VERSION != ICU_TMR_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Icu.h and Icu_Tmr.h "
#endif
/* Make sure the AUTOSAR revision version number is the same between Icu.h and Icu_Tmr.h */
#if (ICU_H_AR_RELEASE_REVISION_VERSION != ICU_TMR_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Icu.h and Icu_Tmr.h "
#endif
/* Make sure the software major version number is the same between Icu.h and Icu_Tmr.h */
#if (ICU_H_SW_MAJOR_VERSION != ICU_TMR_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Icu.h and Icu_Tmr.h "
#endif
/* Make sure the software minor version number is the same between Icu.h and Icu_Tmr.h */
#if (ICU_H_SW_MINOR_VERSION != ICU_TMR_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Icu.h and Icu_Tmr.h "
#endif
/* Make sure the software patch version number is the same between Icu.h and Icu_Tmr.h */
#if (ICU_H_SW_PATCH_VERSION != ICU_TMR_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Icu.h and Icu_Tmr.h "
#endif

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

/** wakeup capability type definition */
typedef  uint8  Icu_WakeupCapabilityType;

/**@} end of group ICU_Structure */

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

/** Have no wakeup capability */
#define  ICU_WAKEUP_CAPABLE_NO         ((Icu_WakeupCapabilityType)0x00U)
/** Have wakeup capability */
#define  ICU_WAKEUP_CAPABLE_YES        ((Icu_WakeupCapabilityType)0x01U)

/** Icu driver error detection capability */
#define ICU_CHECK_GLOBAL_CALL          (ICU_DEV_ERROR_DETECT_ENABLE)
#define ICU_CHECK_CALL_AND_CHANNEL     (ICU_DEV_ERROR_DETECT_ENABLE)
#define ICU_CHECK_PARAMS               (ICU_DEV_ERROR_DETECT_ENABLE)

/**@} end of group ICU_Macros */

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

/**
 * @brief   Defines ICU module development and runtime errors.
 */
typedef enum
{
    ICU_E_PARAM_POINTER             = (uint8)0x0AU,  //!< APIs called with buffer pointer is NULL_PTR

    ICU_E_PARAM_CHANNEL             = (uint8)0x0BU,  //!< APIs called with illegal channel

    ICU_E_PARAM_ACTIVATION          = (uint8)0x0CU,  //!< Icu_SetActivationCondition() called with a undefined parameter

    ICU_E_INIT_FAILED               = (uint8)0x0DU,  //!< Icu_Init() called with parameter is NULL_PTR

    ICU_E_PARAM_BUFFER_SIZE         = (uint8)0x0EU,  //!< Icu_StartTimestamp() called with buffer size is 0

    ICU_E_PARAM_MODE                = (uint8)0x0FU,  //!< Icu_SetMode() called with a undefined parameter

    ICU_E_UNINIT                    = (uint8)0x14U,  //!< APIs called while ICU module has not been initialized

    ICU_E_NOT_STARTED               = (uint8)0x15U,  //!< Icu_StopTimestamp() called when channel is not working

    ICU_E_BUSY_OPERATION            = (uint8)0x16U,  //!< Icu_SetMode() called with Icu channel is running

    ICU_E_ALREADY_INITIALIZED       = (uint8)0x17U,  //!< Icu_Init() called two times

    ICU_E_PARAM_NOTIFY_INTERVAL     = (uint8)0x18U,  //!< Icu_StartTimestamp() called with NotifyInterval is 0

    ICU_E_PARAM_VINFO               = (uint8)0x19U,  //!< Icu_GetVersionInfo() called with parameter is NULL_PTR

    ICU_E_CLK_MODE_BEYOND           = (uint8)0x20U,  //!< Icu_SetClkPrescaler() called with a undefined parameter

    ICU_E_EDGECOUNT_OVER_MAX        = (uint8)0x21U,  //!< Edge count over 0xFFFF

    ICU_E_TIMESTAMP_RESULT_OVER_MAX = (uint8)0x22U,  //!< Icu_GetTimestampIndex() called with result over MAX value

    ICU_E_MEASURE_CHNV_REG_OVER     = (uint8)0x23U,  //!< Time elapsed over in signal measurement mode

    ICU_E_API_RUN_SLEEP_MODE        = (uint8)0x24U   //!< Call APIs when ICU mode is in ICU_MODE_SLEEP

} Icu_ErrorIdType;

/**
 * @brief   API Service ID define according to AUTOSAR ICU Driver software spec.
 */
typedef enum
{
    ICU_INIT_SERVICE_ID                     = (uint8)0x00U,    //!< Service ID: Icu_Init()

    ICU_DEINIT_SERVICE_ID                   = (uint8)0x01U,    //!< Service ID: Icu_DeInit()

    ICU_SETMODE_SERVICE_ID                  = (uint8)0x02U,    //!< Service ID: Icu_SetMode()

    ICU_DISABLEWAKEUP_SERVICE_ID            = (uint8)0x03U,    //!< Service ID: Icu_DisableWakeup()

    ICU_ENABLEWAKEUP_SERVICE_ID             = (uint8)0x04U,    //!< Service ID: Icu_EnableWakeup()

    ICU_SETACTIVATIONCONDITION_SERVICE_ID   = (uint8)0x05U,    //!< Service ID: Icu_SetActivationCondition()

    ICU_DISABLENOTIFICATION_SERVICE_ID      = (uint8)0x06U,    //!< Service ID: Icu_DisableNotification()

    ICU_ENABLENOTIFICATION_SERVICE_ID       = (uint8)0x07U,    //!< Service ID: Icu_EnableNotification()

    ICU_GETINPUTSTATE_SERVICE_ID            = (uint8)0x08U,    //!< Service ID: Icu_GetInputState()

    ICU_STARTTIMESTAMP_SERVICE_ID           = (uint8)0x09U,    //!< Service ID: Icu_StartTimestamp()

    ICU_STOPTIMESTAMP_SERVICE_ID            = (uint8)0x0AU,    //!< Service ID: Icu_StopTimestamp()

    ICU_GETTIMESTAMPINDEX_SERVICE_ID        = (uint8)0x0BU,    //!< Service ID: Icu_GetTimestampIndex()

    ICU_RESETEDGECOUNT_SERVICE_ID           = (uint8)0x0CU,    //!< Service ID: Icu_ResetEdgeCount()

    ICU_ENABLEEDGECOUNT_SERVICE_ID          = (uint8)0x0DU,    //!< Service ID: Icu_EnableEdgeCount()

    ICU_DISABLEEDGECOUNT_SERVICE_ID         = (uint8)0x0EU,    //!< Service ID: Icu_DisableEdgeCount()

    ICU_GETEDGENUMBERS_SERVICE_ID           = (uint8)0x0FU,    //!< Service ID: Icu_GetEdgeNumbers()

    ICU_GETTIMEELAPSED_SERVICE_ID           = (uint8)0x10U,    //!< Service ID: Icu_GetTimeElapsed()

    ICU_GETDUTYCYCLEVALUES_SERVICE_ID       = (uint8)0x11U,    //!< Service ID: Icu_GetDutyCycleValues()

    ICU_GETVERSIONINFO_SERVICE_ID           = (uint8)0x12U,    //!< Service ID: Icu_GetVersionInfo()

    ICU_STARTSIGNALMEASUREMENT_SERVICE_ID   = (uint8)0x13U,    //!< Service ID: Icu_StartSignalMeasurement()

    ICU_STOPSIGNALMEASUREMENT_SERVICE_ID    = (uint8)0x14U,    //!< Service ID: Icu_StopSignalMeasurement()

    ICU_CHECKWAKEUP_SERVICE_ID              = (uint8)0x15U,    //!< Service ID: Icu_CheckWakeup()

    ICU_ENABLEEDGEDETECTION_SERVICE_ID      = (uint8)0x16U,    //!< Service ID: Icu_EnableEdgeDetection()

    ICU_DISABLEEDGEDETECTION_SERVICE_ID     = (uint8)0x17U,    //!< Service ID: Icu_DisableEdgeDetection()

    ICU_SETCLOCKMODE_SERVICE_ID             = (uint8)0x18U,    //!< Service ID: Icu_SetClkPrescaler()

    ICU_GETCHVREGVALUE_SERVICE_ID           = (uint8)0x19U     //!< Service ID: Icu_Tmr_ReadTmrCCnRegValue()

} Icu_ServiceIdType;

#if ((STD_ON == ICU_CHECK_GLOBAL_CALL) || (STD_ON == ICU_CHECK_CALL_AND_CHANNEL))
typedef enum
{
    ICU_MODULE_STATE_IS_UNINIT = 0x00,

    ICU_MODULE_STATE_IS_IDLE   = 0x01

} Icu_ModuleStateType;
#endif

/**
 * @brief   Defines channel identification.
 */
typedef enum
{
    ICU_TMR0_CH0 = 0U,
    ICU_TMR0_CH1,
    ICU_TMR0_CH2,
    ICU_TMR0_CH3,
    ICU_TMR0_CH4,

    ICU_TMR1_CH0 = 5U,
    ICU_TMR1_CH1,
    ICU_TMR1_CH2,
    ICU_TMR1_CH3,
    ICU_TMR1_CH4,

    ICU_TMR2_CH0 = 10U,
    ICU_TMR2_CH1,
    ICU_TMR2_CH2,
    ICU_TMR2_CH3,
    ICU_TMR2_CH4,

    ICU_TMR3_CH0 = 15U,
    ICU_TMR3_CH1,
    ICU_TMR3_CH2,
    ICU_TMR3_CH3,
    ICU_TMR3_CH4,

    ICU_TMR4_CH0 = 20U,
    ICU_TMR4_CH1,
    ICU_TMR4_CH2,
    ICU_TMR4_CH3,
    ICU_TMR4_CH4,

    ICU_PORT0_CH0 = 25U,
    ICU_PORT0_CH1,
    ICU_PORT0_CH2,
    ICU_PORT0_CH3,
    ICU_PORT0_CH4,
    ICU_PORT0_CH5,
    ICU_PORT0_CH6,
    ICU_PORT0_CH7,
    ICU_PORT0_CH8,
    ICU_PORT0_CH9,
    ICU_PORT0_CH10,
    ICU_PORT0_CH11,
    ICU_PORT0_CH12,
    ICU_PORT0_CH13,
    ICU_PORT0_CH14,
    ICU_PORT0_CH15,

    ICU_PORT1_CH0 = 41U,
    ICU_PORT1_CH1,
    ICU_PORT1_CH2,
    ICU_PORT1_CH3,
    ICU_PORT1_CH4,
    ICU_PORT1_CH5,
    ICU_PORT1_CH6,
    ICU_PORT1_CH7,
    ICU_PORT1_CH8,
    ICU_PORT1_CH9,
    ICU_PORT1_CH10,
    ICU_PORT1_CH11,
    ICU_PORT1_CH12,
    ICU_PORT1_CH13,
    ICU_PORT1_CH14,
    ICU_PORT1_CH15,

    ICU_PORT2_CH0 = 57U,
    ICU_PORT2_CH1,
    ICU_PORT2_CH2,
    ICU_PORT2_CH3,
    ICU_PORT2_CH4,
    ICU_PORT2_CH5,
    ICU_PORT2_CH6,
    ICU_PORT2_CH7,
    ICU_PORT2_CH8,
    ICU_PORT2_CH9,
    ICU_PORT2_CH10,
    ICU_PORT2_CH11,
    ICU_PORT2_CH12,
    ICU_PORT2_CH13,
    ICU_PORT2_CH14,
    ICU_PORT2_CH15,

    ICU_PORT3_CH0 = 73U,
    ICU_PORT3_CH1,
    ICU_PORT3_CH2,
    ICU_PORT3_CH3,
    ICU_PORT3_CH4,
    ICU_PORT3_CH5,
    ICU_PORT3_CH6,
    ICU_PORT3_CH7,
    ICU_PORT3_CH8,
    ICU_PORT3_CH9,
    ICU_PORT3_CH10,
    ICU_PORT3_CH11,
    ICU_PORT3_CH12,
    ICU_PORT3_CH13,
    ICU_PORT3_CH14,
    ICU_PORT3_CH15,

    ICU_PORT4_CH0 = 89U,
    ICU_PORT4_CH1,
    ICU_PORT4_CH2,
    ICU_PORT4_CH3,
    ICU_PORT4_CH4,
    ICU_PORT4_CH5,
    ICU_PORT4_CH6,
    ICU_PORT4_CH7,
    ICU_PORT4_CH8,
    ICU_PORT4_CH9,
    ICU_PORT4_CH10,
    ICU_PORT4_CH11,
    ICU_PORT4_CH12,
    ICU_PORT4_CH13,
    ICU_PORT4_CH14,
    ICU_PORT4_CH15,

    ICU_PORT5_CH0 = 105U,
    ICU_PORT5_CH1,
    ICU_PORT5_CH2,
    ICU_PORT5_CH3,
    ICU_PORT5_CH4,
    ICU_PORT5_CH5,
    ICU_PORT5_CH6,
    ICU_PORT5_CH7,
    ICU_PORT5_CH8,
    ICU_PORT5_CH9,
    ICU_PORT5_CH10,
    ICU_PORT5_CH11,
    ICU_PORT5_CH12,
    ICU_PORT5_CH13,
    ICU_PORT5_CH14,
    ICU_PORT5_CH15

} Icu_ChIdType;

/**
 * @brief   Defines g_icuChFeatureState feature bit.
 */
typedef enum
{
    ICU_WAKEUP_SOURCE_FEATURE_BIT = (Icu_StateByteType)0x80, //!< bit7: wakeup source state

    ICU_BOTH_EDGE_FEATURE_BIT = (Icu_StateByteType)0x60, //!< bit5 and bit6: both edge

    ICU_FALLING_EDGE_FEATURE_BIT = (Icu_StateByteType)0x40, //!< bit6: falling edge

    ICU_RISING_EDGE_FEATURE_BIT = (Icu_StateByteType)0x20, //!< bit5: rising edge

    ICU_OVERFLOW_FEATURE_BIT = (Icu_StateByteType)0x10, //!< bit4: overflow state

    ICU_RUNNING_FEATURE_BIT = (Icu_StateByteType)0x08, //!< bit3: channel's running state

    ICU_NOTIFICATION_FEATURE_BIT = (Icu_StateByteType)0x04, //!< bit2: notification state

    ICU_IDLE_FEATURE_BIT = (Icu_StateByteType)0x02, //!< bit1: channel's IDLE / ACTIVE state

    ICU_WAKEUP_FEATURE_BIT = (Icu_StateByteType)0x01 //!< bit0: wakeup state

} Icu_ChFeatureBitType;

/**
 * @brief   Defines g_icuChFeatureState bit offset.
 */
typedef enum
{
    ICU_WAKEUP_SOURCE_BIT_OFFSET = 7U, //!< bit7

    ICU_BOTH_EDGE_BIT_OFFSET = 5U, //!< bit5

    ICU_FALLING_EDGE_BIT_OFFSET = 6U, //!< bit6

    ICU_RISING_EDGE_BIT_OFFSET = 5U, //!< bit5

    ICU_OVERFLOW_BIT_OFFSET = 4U, //!< bit4

    ICU_RUNNING_BIT_OFFSET = 3U, //!< bit3

    ICU_NOTIFICATION_BIT_OFFSET = 2U, //!< bit2

    ICU_IDLE_BIT_OFFSET = 1U, //!< bit1

    ICU_WAKEUP_BIT_OFFSET = 0U //!< bit0

} Icu_ChFeatureBitOffsetType;

/**
 * @brief   Defines g_icuChFeatureState bit mask value.
 */
typedef enum
{
    ICU_WAKEUP_SOURCE_BIT_MASK_VAL = (Icu_StateByteType)0x80, //!< bit7 mask value

    ICU_BOTH_EDGE_BIT_MASK_VAL = (Icu_StateByteType)0x60, //!< bit5 and bit6 mask value

    ICU_FALLING_EDGE_BIT_MASK_VAL = (Icu_StateByteType)0x40, //!< bit6 mask value

    ICU_RISING_EDGE_BIT_MASK_VAL = (Icu_StateByteType)0x20, //!< bit5 mask value

    ICU_OVERFLOW_BIT_MASK_VAL = (Icu_StateByteType)0x10, //!< bit4 mask value

    ICU_RUNNING_BIT_MASK_VAL = (Icu_StateByteType)0x08, //!< bit3 mask value

    ICU_NOTIFICATION_BIT_MASK_VAL = (Icu_StateByteType)0x04, //!< bit2 mask value

    ICU_IDLE_BIT_MASK_VAL = (Icu_StateByteType)0x02, //!< bit1 mask value

    ICU_WAKEUP_BIT_MASK_VAL = (Icu_StateByteType)0x01 //!< bit0 mask value

} Icu_ChFeatureBitMaskValType;

/**@} end of group ICU_Enumerations */

/**************************************************************************
                    STRUCT DEFINITION
**************************************************************************/
/** @defgroup ICU_Structure
  @{
*/

/**
 * @brief    This structure used to contains ICU channel configuration parameters
 */
typedef struct
{
    //!< Active edge and wakeup capability:
    //!< Bit29-Bit30:Active edge:
    //!< ICU_FALLING_EDGE,
    //!< ICU_RISING_EDGE,
    //!< ICU_BOTH_EDGES
    //!< Bit31:Wakeup capability:
    //!< ICU_WAKEUP_CAPABLE_NO,
    //!< ICU_WAKEUP_CAPABLE_YES
    CONST(Icu_EdgeAndWakeupFlagType, ICU_CONST)    icuCHActiveEdgeAndWakeup;
    //!< Indicate channel function:
    //!< ICU_MODE_SIGNAL_EDGE_DETECT,
    //!< ICU_MODE_SIGNAL_MEASUREMENT,
    //!< ICU_MODE_TIMESTAMP,
    //!< ICU_MODE_EDGE_COUNTER
    CONST(Icu_MeasurementModeType, ICU_CONST)      icuChModeSelect;
    //!< Indicate configurable item based on channel function
    //!< eg:For ICU_MODE_SIGNAL_MEASUREMENT channel function:
    //!<    ICU_PERIOD_TIME,
    //!<    ICU_LOW_TIME,
    //!<    ICU_HIGH_TIME,
    //!<    ICU_DUTY_CYCLE
    //!<
    //!<    For ICU_MODE_TIMESTAMP channel function:
    //!<    ICU_CIRCULAR_BUFFER,
    //!<    ICU_LINEAR_BUFFER
    CONST(Icu_ModeCfgItemType, ICU_CONST)         icuChModeCfgItem;

    CONST(Icu_NotifyFunctionType, ICU_CONST)      icuChNotifyFunctionPtr; //!<    Point to channel notification function
#if (STD_ON == ICU_TIMESTAMP_USES_DMA_ENABLE)
    //!< The Icu channel DMA configuration:if the ICU_TIMESTAMP_USES_DMA_ENABLE is enabled,
    //!< the DMA channel number should be configured:
    //!< ICU_TMR1_CH1 - DMA_HW_CH2
    //!< ICU_TMR1_CH2 - DMA_HW_CH3
    //!< ICU_TMR1_CH3 - DMA_HW_CH5
    //!< ICU_TMR1_CH4 - DMA_HW_CH4
    //!< ICU_TMR2_CH1 - DMA_HW_CH1
    //!< ICU_TMR2_CH2 - DMA_HW_CH3
    //!< ICU_TMR2_CH3 - DMA_HW_CH5
    //!< ICU_TMR2_CH4 - DMA_HW_CH2
    //!< ICU_TMR3_CH1 - DMA_HW_CH4
    //!< ICU_TMR3_CH2 - DMA_HW_CH5
    //!< ICU_TMR3_CH3 - DMA_HW_CH2
    //!< ICU_TMR3_CH4 - DMA_HW_CH3
    //!< ICU_TMR4_CH1 - DMA_HW_CH3
    //!< ICU_TMR4_CH2 - DMA_HW_CH2
    //!< ICU_TMR4_CH3 - DMA_HW_CH1
    //!< ICU_TMR4_CH4 - DMA_HW_CH4
    CONST(Pdl_ChType, ICU_CONST) icuChDmaChId;
#endif

#if defined(ICU_OVERFLOW_NOTIFICATION_API_ENABLE) && (STD_ON == ICU_OVERFLOW_NOTIFICATION_API_ENABLE)
    CONST(Icu_NotifyFunctionType, ICU_CONST)   icuCHOverflowNotifyFunctionPtr; //!< Point to channel overflow notification function
#endif

#if (STD_ON == ICU_REPORT_WAKEUP_SOURCE_ENABLE)
    CONST(Icu_WakeupfeatureValueType, ICU_CONST)   icuCHWakeupfeatureValue;    //!< indicate wakeup feature value
#endif
}Icu_ChCfgType;

/**
 * @brief    This structure contains all information about initialization
 */
typedef struct
{
    CONST (Icu_ChannelType, ICU_CONST)  totalNumberChannel;    //!< indicate total number of configurate channel
    CONST (Icu_ChCfgType,   ICU_CONST)  (*icuChCfgPtr)[];      //!< point to channel configuration
    CONST (Icu_IpCfgType,   ICU_CONST)   moduleAchieveWayCfg;  //!< indicate icu achieve way
    CONST (Icu_ChannelType, ICU_CONST)  (*icuHwMapPtr)[ICU_TOTAL_CHANNELS_NUMBER];  //!< point to icu channel map
}Icu_ConfigType;

/**@} end of group ICU_Structure */

/**************************************************************************
                    GLOBAL VARIABLE
**************************************************************************/
#define ICU_START_SEC_CONFIG_DATA_UNSPECIFIED
#include "Icu_MemMap.h"

/** @defgroup ICU_Variable
  @{
*/

ICU_CONFIG_PB

/**@} end of group ICU_Variable */

#define ICU_STOP_SEC_CONFIG_DATA_UNSPECIFIED
#include "Icu_MemMap.h"

#define ICU_START_SEC_VAR_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

/** @defgroup ICU_Variable
  @{
*/

extern  P2CONST(Icu_ConfigType, ICU_VAR, ICU_APPL_CONST) g_icuCfgPtr;

/**@} end of group ICU_Variable */

#define ICU_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Icu_MemMap.h"

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

/** @defgroup ICU_Fuctions
  @{
*/

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

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

#if (STD_ON == ICU_SET_MODE_API_ENABLE)
FUNC (void, ICU_CODE) Icu_SetMode(VAR(Icu_ModeType, AUTOMATIC) Mode);
#endif

#if (STD_ON == ICU_DISABLE_WAKEUP_API_ENABLE)
FUNC (void, ICU_CODE) Icu_DisableWakeup(VAR(Icu_ChannelType, AUTOMATIC) Channel);
#endif

#if (STD_ON == ICU_ENABLE_WAKEUP_API_ENABLE)
FUNC (void, ICU_CODE) Icu_EnableWakeup(VAR(Icu_ChannelType, AUTOMATIC) Channel);
#endif

#if ((STD_ON == ICU_WAKEUP_FUNCTIONALITY_API_ENABLE) && \
     (STD_ON == ICU_REPORT_WAKEUP_SOURCE_ENABLE) && \
     (STD_ON == ICU_ENABLE_WAKEUP_API_ENABLE))
FUNC (void, ICU_CODE) Icu_CheckWakeup(VAR(EcuM_WakeupSourceType, AUTOMATIC) WakeupSource);
#endif

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

FUNC (void, ICU_CODE) Icu_DisableNotification(VAR(Icu_ChannelType, AUTOMATIC) Channel);

FUNC (void, ICU_CODE) Icu_EnableNotification(VAR(Icu_ChannelType, AUTOMATIC) Channel);

#if (STD_ON == ICU_GET_INPUT_STATE_API_ENABLE)
FUNC (Icu_InputStateType, ICU_CODE) Icu_GetInputState(VAR(Icu_ChannelType, AUTOMATIC) Channel);
#endif

#if (STD_ON == ICU_TIMESTAMP_API_ENABLE)
FUNC (void, ICU_CODE) Icu_StartTimestamp(VAR(Icu_ChannelType, AUTOMATIC) Channel,
                                         P2VAR(Icu_ValueType, AUTOMATIC, ICU_APPL_DATA) BufferPtr,
                                         VAR(uint16, AUTOMATIC) BufferSize, VAR(uint16, AUTOMATIC) NotifyInterval);
FUNC (void, ICU_CODE) Icu_StopTimestamp(VAR(Icu_ChannelType, AUTOMATIC) Channel);
FUNC (Icu_IndexType, ICU_CODE) Icu_GetTimestampIndex(VAR(Icu_ChannelType, AUTOMATIC) Channel);
#endif

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

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

#if (STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE)
FUNC (void, ICU_CODE) Icu_StartSignalMeasurement(VAR(Icu_ChannelType, AUTOMATIC) Channel);
FUNC (void, ICU_CODE) Icu_StopSignalMeasurement(VAR(Icu_ChannelType, AUTOMATIC) Channel);

#if (STD_ON == ICU_GET_TIME_ELAPSED_API_ENABLE)
FUNC (Icu_ValueType, ICU_CODE) Icu_GetTimeElapsed(VAR(Icu_ChannelType, AUTOMATIC) Channel);
#endif

#if (STD_ON == ICU_GET_DUTY_CYCLE_VALUES_API_ENABLE)
FUNC (void, ICU_CODE) Icu_GetDutyCycleValues(VAR(Icu_ChannelType, AUTOMATIC) Channel,
                                             P2VAR(Icu_DutyCycleType, AUTOMATIC, ICU_APPL_DATA) DutyCycleValues);
#endif

#endif

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

#if ((STD_ON == ICU_READ_CCN_REG_API_ENABLE) && \
    ((STD_ON == ICU_SIGNAL_MEASUREMENT_API_ENABLE) || (STD_ON == ICU_TIMESTAMP_API_ENABLE)))
FUNC (Icu_ValueType, ICU_CODE) Icu_ReadCCnRegValue(VAR(Icu_ChannelType, AUTOMATIC) ch);
#endif

#if (STD_ON == ICU_DUAL_CLOCK_MODE_API_ENABLE)
FUNC (void, ICU_CODE) Icu_SetClkPrescaler(VAR(Icu_ClockDivisionType, AUTOMATIC) divMode);
#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 */
