/*!
* @file     Icu_Types.h
*
* @version  1.0.0
*
* @brief    This file contains the ICU type definitions and other parameters used by other files
*
* @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.
*/

/*
* MISRA-C:2012 compliance checks
*
*     Icu_Types_h_MISRA_REF1
*          Breaks the required Dir-4.9 of MISRA 2012 guidelines,
*          A function should be used in preference to a function-like macro where they are interchangeable.
*
*/

#ifndef ICU_TYPE_H
#define ICU_TYPE_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Std_Types.h"
#include "Icu_TmrTypes.h"
#include "Icu_PortCiTypes.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_TYPE_H_VENDOR_ID                       0x00C1U
/** Module ID of this module, as defined in the BSW Module List. */
#define ICU_TYPE_H_MODULE_ID                       0x007AU
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_TYPE_H_AR_RELEASE_MAJOR_VERSION        0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_TYPE_H_AR_RELEASE_MINOR_VERSION        0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_TYPE_H_AR_RELEASE_REVISION_VERSION     0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_TYPE_H_SW_MAJOR_VERSION                0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_TYPE_H_SW_MINOR_VERSION                0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_TYPE_H_SW_PATCH_VERSION                0x00U

/**@} end of group ICU_Macros */

/**************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************/
#ifdef ENABLE_INTERMODULE_MCAL_CHECK
    /* Make sure the AUTOSAR major version number is the same between Icu_Types.h and Std_Types.h */
    #if (ICU_TYPE_H_AR_RELEASE_MAJOR_VERSION != STD_TYPES_H_AR_RELEASE_MAJOR_VERSION)
        #error "AUTOSAR Major Version Number mismatch between Icu_Types.h and Std_Types.h "
    #endif
    /* Make sure the AUTOSAR minor version number is the same between Icu_Types.h and Std_Types.h */
    #if (ICU_TYPE_H_AR_RELEASE_MINOR_VERSION != STD_TYPES_H_AR_RELEASE_MINOR_VERSION)
        #error "AUTOSAR Minor Version Number mismatch between Icu_Types.h and Std_Types.h "
    #endif
#endif

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

/** Channels ID base TMR IP */
#define TMR_ICU_CH_ID_BASE_TMR(ch) ((ch))
/** Channels ID base self IP */
#define ICU_TMR_CH_ID_BASE_TMR(ch) ((ch))
#define ICU_PORT_CI_CH_ID_BASE_PORT_CI(ch) (ch)

/** Max channels of each IP */
#define ICU_TMR_MAX_CH_NUMBER     (25U)
#define ICU_PORT_CI_MAX_CH_NUMBER (96U)

/** The max number of ICU channel */
#define ICU_TOTAL_CHANNELS_NUMBER (121U)

/**@} end of group ICU_Macros */

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

/**
 * @brief    Icu channel function
 */
typedef enum
{
    ICU_MODE_SIGNAL_EDGE_DETECT  = 0x01U,   //!< Edge detect function
    ICU_MODE_SIGNAL_MEASUREMENT  = 0x02U,   //!< Signal measurement function
    ICU_MODE_TIMESTAMP           = 0x04U,   //!< Time stamp function
    ICU_MODE_EDGE_COUNTER        = 0x08U    //!< Edge count function
} Icu_MeasurementModeType;

/**
 * @brief    select active edge
 */
typedef enum
{
    ICU_FALLING_EDGE = 0x0U,    //!< active edge is falling edge  
    ICU_RISING_EDGE  = 0x1U,    //!< active edge is rising edge 
    ICU_BOTH_EDGES   = 0x2U     //!< falling edge and rising edge are active edge
} Icu_ActivationType;

/**
 * @brief    Icu channel active/idle state
 */
typedef enum
{
    ICU_ACTIVE = 0x0U,         //!< active edge discovered
    ICU_IDLE   = 0x1U          //!< active edge doesn't discovered
} Icu_InputStateType;

#if (STD_ON == ICU_DUAL_CLOCK_MODE_API_ENABLE)
/**
 * @brief    select clock division 
 */
typedef enum
{
    ICU_CLK_DIV_DEFAULT    = 0x0U,      //!< clock division is default 
    ICU_CLK_DIV_ALTERNATE  = 0x1U       //!< clock division is alternate
} Icu_ClockDivisionType;
#endif

/**
 * @brief    configurable item when channel is in measure mode
 */
typedef enum
{
    ICU_LOW_TIME     = 0x01U,    //!< measure low level time
    ICU_HIGH_TIME    = 0x02U,    //!< measure high level time
    ICU_PERIOD_TIME  = 0x04U,    //!< measure period time
    ICU_DUTY_CYCLE   = 0x08U     //!< measure duty cycle
} Icu_SignalMeasurementPropertyType;

/**
 * @brief    Icu mode normal/sleep
 */
typedef enum
{
    ICU_MODE_NORMAL = 0x0U,   //!< all interrupts work normally
    ICU_MODE_SLEEP  = 0x1U    //!< interrupt doesn't work except wakeup interrupt
} Icu_ModeType;

/**
 * @brief    buffer type configurable item when channel is in time stamp function
 */
typedef enum
{
    ICU_LINEAR_BUFFER    = 0x0U,     //!< linear buffer
    ICU_CIRCULAR_BUFFER  = 0x1U      //!< circular buffer
} Icu_TimestampBufferType;

/**
 * @brief   Bit offset used for configuration variable.
 */
typedef enum
{
    ICU_CH_WAKEUP_BIT_OFFSET = (uint32)31U, //!< bit31

    ICU_CH_ACTIVE_EDGE_BIT_OFFSET = (uint32)29U //!< bit29

} Icu_CfgVarBitOffsetType;

/**
 * @brief   Mask value used for configuration variable.
 */
typedef enum
{
/*** @warning Icu_Type_h_MISRA_REF1  [C] Enumeration constants must have values representable as 'int's. */
    ICU_CH_WAKEUP_MASK_VAL = (uint32)0x80000000UL, //!< bit31 mask value

    ICU_CH_ACTIVE_EDGE_MASK_VAL = (uint32)0x60000000UL //!< bit30 and bit29 mask value

} Icu_CfgVarMaskValType;

/**
 * @brief   Defines channel IP type.
 */
typedef enum
{
    ICU_TMR_CH_TYPE = 0U,    //!< TMR
    ICU_PORT_CI_CH_TYPE = 1U //!< Port
} Icu_IPChType;

/**@} end of group ICU_Enumerations */

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

/** used to embellish g_icuChFeatureState value */
typedef uint8 Icu_StateByteType;

typedef Icu_HWRealEdgeNumberType Icu_EdgeNumberType;

typedef uint32 Icu_EdgeAndWakeupFlagType;

typedef uint32 Icu_WakeupfeatureValueType;

typedef Icu_TimeRegBitNumberType Icu_ValueType;

typedef void (*Icu_NotifyFunctionType)(void);

typedef uint16 Icu_ModeCfgItemType;

typedef Icu_HWRealIndexType Icu_IndexType;

typedef uint8 Icu_ChannelType;

/**
 * @brief    ICU channel reality way and id
 */
typedef struct
{
    CONST(Icu_IPChType, ICU_CONST) channelCountIPSelect; //!< ICU channel type
    CONST(uint8, ICU_CONST) channelWorkingId; //!< ICU working channel id
} Icu_WorkingCHCfgType;

/**
 * @brief    ICU channel reality type
 */
typedef struct
{
    CONSTP2CONST(Icu_TmrIPCfgType, ICU_CONST, ICU_APPL_CONST)
    channelTmrIpConfigPtr; //!< ICU channel IP: TMR
    CONSTP2CONST(Icu_Port_CiIPCfgType, ICU_CONST, ICU_APPL_CONST)
    channelPORT_CIIpConfigPtr; //!< ICU channel IP: PORT
    CONST(Icu_WorkingCHCfgType, ICU_CONST)
    (*channelWorkingIpAndIdPtr)[];
} Icu_IpCfgType;

typedef struct
{
    Icu_ValueType ActiveTime;   //!< active level time elapse
    Icu_ValueType PeriodTime;   //!< period time elapse
} Icu_DutyCycleType;

/**@} end of group ICU_Structure */

#ifdef __cplusplus
}
#endif

#endif

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