/*!
* @file     Icu_PortCi.h
*
* @version  1.0.0
*
* @brief    Header file of AUTOSAR Icu driver by Port
*
* @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_PORT_CI_H
#define ICU_PORT_CI_H

#ifdef __cplusplus
extern "C"{
#endif

#include "Icu_PortCiTypes.h"
#include "Icu.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_PORT_CI_H_VENDOR_ID                      0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_PORT_CI_H_AR_RELEASE_MAJOR_VERSION       0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_PORT_CI_H_AR_RELEASE_MINOR_VERSION       0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ICU_PORT_CI_H_AR_RELEASE_REVISION_VERSION    0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_PORT_CI_H_SW_MAJOR_VERSION               0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_PORT_CI_H_SW_MINOR_VERSION               0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ICU_PORT_CI_H_SW_PATCH_VERSION               0x00U

/**@} end of group ICU_Macros */

/**************************************************************************
                    VERSION INFOMATION VERIFICATION
**************************************************************************/
/* Make sure the vendor id is the same between Icu_PortCi.h and Icu_PortCiTypes.h */
#if (ICU_PORT_CI_H_VENDOR_ID != ICU_PORT_CI_TYPE_H_VENDOR_ID)
    #error "Vendor id mismatch between Icu_PortCi.h and Icu_PortCiTypes.h "
#endif
/* Make sure the AUTOSAR major version number is the same between Icu_PortCi.h and Icu_PortCiTypes.h */
#if (ICU_PORT_CI_H_AR_RELEASE_MAJOR_VERSION != ICU_PORT_CI_TYPE_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Icu_PortCi.h and Icu_PortCiTypes.h "
#endif
/* Make sure the AUTOSAR minor version number is the same between Icu_PortCi.h and Icu_PortCiTypes.h */
#if (ICU_PORT_CI_H_AR_RELEASE_MINOR_VERSION != ICU_PORT_CI_TYPE_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Icu_PortCi.h and Icu_PortCiTypes.h "
#endif
/* Make sure the AUTOSAR revision version number is the same between Icu_PortCi.h and Icu_PortCiTypes.h */
#if (ICU_PORT_CI_H_AR_RELEASE_REVISION_VERSION != ICU_PORT_CI_TYPE_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Icu_PortCi.h and Icu_PortCiTypes.h "
#endif
/* Make sure the software major version number is the same between Icu_PortCi.h and Icu_PortCiTypes.h */
#if (ICU_PORT_CI_H_SW_MAJOR_VERSION != ICU_PORT_CI_TYPE_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Icu_PortCi.h and Icu_PortCiTypes.h "
#endif
/* Make sure the software minor version number is the same between Icu_PortCi.h and Icu_PortCiTypes.h */
#if (ICU_PORT_CI_H_SW_MINOR_VERSION != ICU_PORT_CI_TYPE_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Icu_PortCi.h and Icu_PortCiTypes.h "
#endif
/* Make sure the software patch version number is the same between Icu_PortCi.h and Icu_PortCiTypes.h */
#if (ICU_PORT_CI_H_SW_PATCH_VERSION != ICU_PORT_CI_TYPE_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Icu_PortCi.h and Icu_PortCiTypes.h "
#endif

/** @defgroup ICU_Structure
  @{
*/
/**************************************************************************
                    OTHER TYPE DEFINITION
**************************************************************************/
/** ICU channel function */
typedef  uint8   Icu_Port_CiActiveEdgeType;

/**************************************************************************
                    ENUMERATION DEFINITION
**************************************************************************/
/**
 * @brief   Defines port ci channel active edge.
 */
typedef enum
{
    ICU_PORT_CI_CH_ACTIVE_EDGE_IS_NONE     = (uint8)0U,  //!< no edge select

    ICU_PORT_CI_CH_ACTIVE_EDGE_IS_RISING   = (uint8)1U,  //!< rising edge

    ICU_PORT_CI_CH_ACTIVE_EDGE_IS_FALLING  = (uint8)2U,  //!< falling edge

    ICU_PORT_CI_CH_ACTIVE_EDGE_IS_BOTH     = (uint8)3U   //!< rising and falling edge

} Icu_PortCiActiveEdgeType;

/**@} end of group ICU_Structure */

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

/** pin mask value */
#define PORT_CI_GET_PIN_MASK_VAL               ((uint16)(0x0FU))
/** Used to know the pin id on the port type */
#define GET_PORT_CI_CH_PIN_ID(ch)              ((ch - ((uint16)ICU_PORT0_CH0)) & ((uint16)PORT_CI_GET_PIN_MASK_VAL))
/** Used to know which type port the channel belongs to:A,B,C,D,F */
#define GET_PORT_CI_CH_PORT_ID(ch)             ((ch - ((uint16)ICU_PORT0_CH0)) >> 4U)

/** PORT IP active edge select */
#define ICU_PORT_CI_ACTIVE_EDGE_IS_FALLING  ((Icu_Port_CiActiveEdgeType)0U)
#define ICU_PORT_CI_ACTIVE_EDGE_IS_RISING   ((Icu_Port_CiActiveEdgeType)1U)
#define ICU_PORT_CI_ACTIVE_EDGE_IS_BOTH     ((Icu_Port_CiActiveEdgeType)2U)

/**@} end of group ICU_Macros */

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

/** @defgroup ICU_Fuctions
  @{
*/

#if (STD_ON == ICU_EINT_NOTIFICATION_SUPPORT)
FUNC(void, ICU_CODE) Icu_PortCi_ProcessInterrupt(CONST(Icu_EintChType, AUTOMATIC) pinMask);
#endif

FUNC(void, ICU_CODE) Icu_PortCi_Init
                     (P2CONST(Icu_Port_CiIPCfgType, AUTOMATIC, ICU_APPL_CONST) channelPORTCIIpConfigPtr);

#if (STD_ON == ICU_DE_INIT_API_ENABLE)
FUNC(void, ICU_CODE) Icu_PortCi_DeInit
                     (P2CONST(Icu_Port_CiIPCfgType, AUTOMATIC, ICU_APPL_CONST) channelPORTCIIpConfigPtr);
#endif

#if (STD_ON == ICU_SET_MODE_API_ENABLE)
FUNC(void, ICU_CODE) Icu_PortCi_SetSleepMode(VAR(Icu_Port_CiCHType, AUTOMATIC) ch, 
    VAR(Icu_PortPinModeType, AUTOMATIC) portPinMode);
FUNC(void, ICU_CODE) Icu_PortCi_SetNormalMode(VAR(Icu_Port_CiCHType, AUTOMATIC) ch, 
    VAR(Icu_PortPinModeType, AUTOMATIC) portPinMode);
#endif

FUNC(void, ICU_CODE) Icu_PortCi_SetActivationCondition(VAR(Icu_Port_CiCHType, AUTOMATIC) ch,
    VAR(Icu_Port_CiActiveEdgeType, AUTOMATIC) aimEdge, VAR(Icu_PortPinModeType, AUTOMATIC) portPinMode);

#if (STD_ON == ICU_GET_INPUT_STATE_API_ENABLE)
FUNC (boolean, ICU_CODE) Icu_PortCi_GetInputState(VAR(Icu_Port_CiCHType, AUTOMATIC) ch);
#endif

#if (STD_ON == ICU_EDGE_DETECT_API_ENABLE)
FUNC(void, ICU_CODE) Icu_PortCi_EnableEdgeDetection(VAR(Icu_Port_CiCHType, AUTOMATIC) ch, 
    VAR(Icu_PortPinModeType, AUTOMATIC) portPinMode);
FUNC(void, ICU_CODE) Icu_PortCi_DisableEdgeDetection(VAR(Icu_Port_CiCHType, AUTOMATIC) ch, 
    VAR(Icu_PortPinModeType, AUTOMATIC) portPinMode);
#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 */
