/*!
* @file     Ocu_Ipw.c
*
* @version  1.0.0
*
* @brief    The Ipw API of Ocu moudle.
*           This file includes OCU IWP API implementation.
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_15-Nov-2
*
* 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.
*/

#ifdef __cplusplus
extern "C"{
#endif  /* ifdef __cplusplus */

#include "Ocu_Ipw_Types.h"
#include "Ocu_Ipw.h"
#include "Ocu_Tmr.h"
/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup OCU_Driver
  * @brief OCU driver modules
  @{
*/

/** @defgroup OCU_Macros
  @{
*/
/***********************************************************************************************************************
                                    VENDOR ID & AUTOSAR VERSION INFO
***********************************************************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define OCU_IPW_VENDOR_ID                                  0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define OCU_IPW_AR_RELEASE_MAJOR_VERSION                   0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define OCU_IPW_AR_RELEASE_MINOR_VERSION                   0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define OCU_IPW_AR_RELEASE_REVISION_VERSION                0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */ 
#define OCU_IPW_SW_MAJOR_VERSION                           0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define OCU_IPW_SW_MINOR_VERSION                           0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define OCU_IPW_SW_PATCH_VERSION                           0x00U
/**@} end of group OCU_Macros */
/***********************************************************************************************************
                                  VERSION INFOMATION VERIFICATION
*************************************************************************************************************/
/* Make sure the vendor ids are the same between Ocu_Ipw.c and Ocu_Ipw.h */
#if (OCU_IPW_VENDOR_ID != OCU_IPW_H_VENDOR_ID)
    #error "Vendor ids mismatch between Ocu_Ipw.c and Ocu_Ipw.h"
#endif  /* {if (OCU_IPW_VENDOR_ID != OCU_IPW_H_VENDOR_ID)} */

/* Make sure the AUTOSAR major version number is the same between Ocu_Ipw.c and Ocu_Ipw.h */
#if (OCU_IPW_AR_RELEASE_MAJOR_VERSION    != OCU_IPW_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Ocu_Ipw.c and Ocu_Ipw.h */
#if (OCU_IPW_AR_RELEASE_MINOR_VERSION    != OCU_IPW_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Ocu_Ipw.c and Ocu_Ipw.h */
#if (OCU_IPW_AR_RELEASE_REVISION_VERSION != OCU_IPW_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw.h"
#endif

/* Make sure the software major version number is the same between Ocu_Ipw.c and Ocu_Ipw.h */
#if (OCU_IPW_SW_MAJOR_VERSION != OCU_IPW_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw.h"
#endif
/* Make sure the software minor version number is the same between Ocu_Ipw.c and Ocu_Ipw.h */
#if (OCU_IPW_SW_MINOR_VERSION != OCU_IPW_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw.h"
#endif
/* Make sure the software patch version number is the same between Ocu_Ipw.c and Ocu_Ipw.h */
#if (OCU_IPW_SW_PATCH_VERSION != OCU_IPW_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw.h"
#endif

/* Make sure the vendor ids are the same between Ocu_Ipw.c and Ocu_Ipw_Types.h */
#if (OCU_IPW_VENDOR_ID != OCU_IPW_TYPES_H_VENDOR_ID)
    #error "Vendor ids mismatch between Ocu_Ipw.c and Ocu_Ipw_Types.h"
#endif  /* {if (OCU_IPW_VENDOR_ID != OCU_IPW_TYPES_H_VENDOR_ID)} */

/* Make sure the AUTOSAR major version number is the same between Ocu_Ipw.c and Ocu_Ipw_Types.h */
#if (OCU_IPW_AR_RELEASE_MAJOR_VERSION    != OCU_IPW_TYPES_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw_Types.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Ocu_Ipw.c and Ocu_Ipw_Types.h */
#if (OCU_IPW_AR_RELEASE_MINOR_VERSION    != OCU_IPW_TYPES_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw_Types.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Ocu_Ipw.c and Ocu_Ipw_Types.h */
#if (OCU_IPW_AR_RELEASE_REVISION_VERSION != OCU_IPW_TYPES_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw_Types.h"
#endif

/* Make sure the software major version number is the same between Ocu_Ipw.c and Ocu_Ipw_Types.h */
#if (OCU_IPW_SW_MAJOR_VERSION != OCU_IPW_TYPES_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw_Types.h"
#endif
/* Make sure the software minor version number is the same between Ocu_Ipw.c and Ocu_Ipw_Types.h */
#if (OCU_IPW_SW_MINOR_VERSION != OCU_IPW_TYPES_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw_Types.h"
#endif
/* Make sure the software patch version number is the same between Ocu_Ipw.c and Ocu_Ipw_Types.h */
#if (OCU_IPW_SW_PATCH_VERSION != OCU_IPW_TYPES_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Ocu_Ipw.c and Ocu_Ipw_Types.h"
#endif

/* Make sure the vendor ids are the same between Ocu_Ipw.c and Ocu_Tmr.h */
#if (OCU_IPW_VENDOR_ID != OCU_TMR_H_VENDOR_ID)
    #error "Vendor ids mismatch between Ocu_Ipw.c and Ocu_Tmr.h"
#endif  /* {if (OCU_IPW_VENDOR_ID != OCU_TMR_H_VENDOR_ID)} */

/* Make sure the AUTOSAR major version number is the same between Ocu_Ipw.c and Ocu_Tmr.h */
#if (OCU_IPW_AR_RELEASE_MAJOR_VERSION    != OCU_TMR_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between Ocu_Ipw.c and Ocu_Tmr.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between Ocu_Ipw.c and Ocu_Tmr.h */
#if (OCU_IPW_AR_RELEASE_MINOR_VERSION    != OCU_TMR_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between Ocu_Ipw.c and Ocu_Tmr.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between Ocu_Ipw.c and Ocu_Tmr.h */
#if (OCU_IPW_AR_RELEASE_REVISION_VERSION != OCU_TMR_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between Ocu_Ipw.c and Ocu_Tmr.h"
#endif

/* Make sure the software major version number is the same between Ocu_Ipw.c and Ocu_Tmr.h */
#if (OCU_IPW_SW_MAJOR_VERSION != OCU_TMR_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between Ocu_Ipw.c and Ocu_Tmr.h"
#endif
/* Make sure the software minor version number is the same between Ocu_Ipw.c and Ocu_Tmr.h */
#if (OCU_IPW_SW_MINOR_VERSION != OCU_TMR_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between Ocu_Ipw.c and Ocu_Tmr.h"
#endif
/* Make sure the software patch version number is the same between Ocu_Ipw.c and Ocu_Tmr.h */
#if (OCU_IPW_SW_PATCH_VERSION != OCU_TMR_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between Ocu_Ipw.c and Ocu_Tmr.h"
#endif

/***********************************************************************************************************
                                            LOCAL VARIABLE
************************************************************************************************************/
/** @defgroup OCU_Variable
  @{
*/
#define OCU_START_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Ocu_MemMap.h"

static P2CONST(Ocu_HwConfigType, AUTOMATIC, OCU_APPL_CONST) g_hwConfigPtr;

#define OCU_STOP_SEC_VAR_NO_INIT_UNSPECIFIED
#include "Ocu_MemMap.h"
/**@} end of group OCU_Variable */
/**********************************************************************************************************************
                                                    GLOBAL FUNCTION
***********************************************************************************************************************/
/** @defgroup OCU_Fuctions
  @{
*/
#define OCU_START_SEC_CODE
#include "Ocu_MemMap.h"

#if (STD_ON == OCU_SET_CLOCK_MODE_API_ENABLE)
/*!
 * @brief         The function is to set the clock mode of the Ocu Tmr.
 *
 * @param[in]     OcuHwConfigurationPtr      The pointer of the Ocu Tmr configuration parameters
 * @param[in]     OcuPrescalerType            The prescaler type of Ocu Tmr
 *
 * @retval        void
 */
FUNC (void, OCU_CODE) Ocu_Ipw_SetClkPsc(CONSTP2CONST(Ocu_HwConfigType, AUTOMATIC, OCU_APPL_CONST) OcuHwConfigurationPtr,\
    VAR(Ocu_TmrPrescalerType, AUTOMATIC) OcuPrescalerType)
{
    if (NULL_PTR != OcuHwConfigurationPtr->ocuTmrHwConfigPtr)
    { 
        Ocu_Tmr_HwSetClkPsc(OcuHwConfigurationPtr->ocuTmrHwConfigPtr, (Ocu_TmrPrescalerType)OcuPrescalerType);
    }
    else
    {
        /* do nothing */
    }
}
#endif  /* {if (STD_ON == OCU_SET_CLOCK_MODE_API_ENABLE)} */

#if ((STD_ON == OCU_SET_RELATIVE_THRESHOLD_API) || (STD_ON == OCU_SET_ABSOLUTE_THRESHOLD_API))
/*!
 * @brief         The function is to get the max counter value of the Ocu Tmr channel.
 *
 * @param[in]     ChannelNumber          The index of the channel configuration parameters
 *
 * @retval        Ocu_ValueType           The max counter value of the Ocu Tmr channel
 */
FUNC (Ocu_ValueType, OCU_CODE) Ocu_Ipw_GetMaxCntVal(VAR(Ocu_ChannelType, AUTOMATIC) ChannelNumber)
{
    return (Ocu_Tmr_GetMaxCntVal((Ocu_ChannelType)((*g_hwConfigPtr->ocuHwChConfigPtr)[ChannelNumber].chConfigIndexList)));
}
#endif  /* {if ((STD_ON == OCU_SET_RELATIVE_THRESHOLD_API) || (STD_ON == OCU_SET_ABSOLUTE_THRESHOLD_API))} */

#if (STD_ON == OCU_SET_ABSOLUTE_THRESHOLD_API)
/*!
 * @brief         The function is to set the value of the channel threshold with an absolute input data.
 *
 * @param[in]     OcuChannelNumber             The Ocu channel index
 * @param[in]     ReferenceCompareValue    The reference compare value
 * @param[in]     AbsoluteCompareValue     The absolute compare value
 *
 * @retval        OCU_CM_OUT_REF_INTERVAL: The compare match event will not occur inside the current
 *                reference interval.
 *                OCU_CM_IN_REF_INTERVAL: The compare match event will occur inside the current reference interval.
 */
FUNC (Ocu_ReturnType, OCU_CODE) Ocu_Ipw_SetAbsThrd(VAR(Ocu_ChannelType, AUTOMATIC) OcuChannelNumber,\
    VAR(Ocu_ValueType, AUTOMATIC) ReferenceCompareValue,\
    VAR(Ocu_ValueType, AUTOMATIC) AbsoluteCompareValue)
{
    return (Ocu_Tmr_SetAbsThrd((*g_hwConfigPtr->ocuHwChConfigPtr)[OcuChannelNumber].chConfigIndexList, \
                                           ReferenceCompareValue, \
                                           AbsoluteCompareValue,\
                                           g_hwConfigPtr->ocuTmrHwConfigPtr));
}
#endif /* {if (STD_ON == OCU_SET_ABSOLUTE_THRESHOLD_API)} */

#if (STD_ON == OCU_SET_RELATIVE_THRESHOLD_API)
/*!
 * @brief         The function is to set the value of the channel relative threshold with an input data.
 *
 * @param[in]     OcuChannelNumber            The Ocu channel index
 * @param[in]     RelativeCompareValue        The relative compare value
 *
 * @retval        OCU_CM_OUT_REF_INTERVAL: The compare match event will not occur inside the current
 *                reference interval.
 *                OCU_CM_IN_REF_INTERVAL: The compare match event will occur inside the current reference interval.
 */
FUNC (Ocu_ReturnType, OCU_CODE) Ocu_Ipw_SetRelThrd(VAR(Ocu_ChannelType, AUTOMATIC) OcuChannelNumber,\
    VAR(Ocu_ValueType, AUTOMATIC) RelativeCompareValue)
{
    return (Ocu_Tmr_HwSetRelThrd((*g_hwConfigPtr->ocuHwChConfigPtr)[OcuChannelNumber].chConfigIndexList, \
                                           RelativeCompareValue,\
                                           g_hwConfigPtr->ocuTmrHwConfigPtr));
}
#endif /* {if (STD_ON == OCU_SET_RELATIVE_THRESHOLD_API)} */

/*!
 * @brief         The function is to initialize the registers and variables of the Ocu Ipw driver.
 *
 * @param[in]     OcuHwConfigurationPtr     The configuration parameters pointer of the Ocu IPW driver.
 *
 * @retval        void
 */
FUNC (void, OCU_CODE) Ocu_Ipw_Init(\
    CONSTP2CONST(Ocu_HwConfigType, AUTOMATIC, OCU_APPL_CONST) OcuHwConfigurationPtr)
{
    if(NULL_PTR != OcuHwConfigurationPtr->ocuTmrHwConfigPtr)
    {
        g_hwConfigPtr = OcuHwConfigurationPtr;
        Ocu_Tmr_HwInit(g_hwConfigPtr->ocuTmrHwConfigPtr);
    }
    else
    {
        /* do nothing */
    }
}

#if (STD_ON == OCU_DEINIT_API_ENABLE)
/*!
 * @brief         The function is to deinitialize the registers and variables of the Ocu Ipw driver.
 *
 * @param[in]     OcuHwConfigurationPtr     The configuration parameters pointer of the Ocu IPW driver.
 *
 * @retval        void
 */
FUNC (void, OCU_CODE) Ocu_Ipw_DeInit(\
    CONSTP2CONST(Ocu_HwConfigType, AUTOMATIC, OCU_APPL_CONST) OcuHwConfigurationPtr)
{
    if(NULL_PTR != OcuHwConfigurationPtr->ocuTmrHwConfigPtr)
    {
        g_hwConfigPtr = OcuHwConfigurationPtr;
        Ocu_Tmr_HwDeInit(g_hwConfigPtr->ocuTmrHwConfigPtr);
    }
    else
    {
        /* do nothing */
    }
}
#endif /* {if (STD_ON == OCU_DEINIT_API_ENABLE)} */

/*!
 * @brief         The function is to start the IP channel of the Ocu driver.
 *
 * @param[in]     OcuChannelNumber     The Ocu channel id of the Ocu driver.
 *               
 * @retval        void
 */
FUNC (void, OCU_CODE) Ocu_Ipw_StartCh(VAR(Ocu_ChannelType,  AUTOMATIC) OcuChannelNumber)
{  
    Ocu_Tmr_HwStartCh((*g_hwConfigPtr->ocuHwChConfigPtr)[OcuChannelNumber].chConfigIndexList, \
                           g_hwConfigPtr->ocuTmrHwConfigPtr);
}

/*!
 * @brief         The function is to stop the IP channel of the Ocu driver.
 *
 * @param[in]     OcuChannelNumber     The Ocu channel id of the Ocu driver.
 *               
 * @retval        void
 */
FUNC (void, OCU_CODE) Ocu_Ipw_StopCh(VAR(Ocu_ChannelType,  AUTOMATIC) OcuChannelNumber)
{    
    Ocu_Tmr_StopChannel((*g_hwConfigPtr->ocuHwChConfigPtr)[OcuChannelNumber].chConfigIndexList, \
                          g_hwConfigPtr->ocuTmrHwConfigPtr);
}

#if (STD_ON == OCU_SET_PIN_STATE_API)
/*!
 * @brief         The function is to set the pin state linked to the IP channel.
 *
 * @param[in]     OcuChannelNumber     The Ocu channel id of the Ocu driver.
 * @param[in]     OcuPinState          The output pin state linked to the Ocu channel
 *               
 * @retval        void
 */
FUNC (void, OCU_CODE) Ocu_Ipw_SetPinState(VAR(Ocu_ChannelType,  AUTOMATIC) OcuChannelNumber,\
    VAR(Ocu_PinStateType, AUTOMATIC) OcuPinState)
{
    Ocu_Tmr_HwSetPinState((*g_hwConfigPtr->ocuHwChConfigPtr)[OcuChannelNumber].chConfigIndexList, \
                          OcuPinState, \
                          g_hwConfigPtr->ocuTmrHwConfigPtr);
}
#endif /* {if (STD_ON == OCU_SET_PIN_STATE_API)} */

#if (STD_ON == OCU_SET_PIN_ACTION_API)
/*!
 * @brief         The function is to set the pin action linked to the Ocu channel.
 *
 * @param[in]     OcuChannelNumber        The Ocu channel id
 * @param[in]     OcuPinAction            The output pin action linked to the Ocu channel
 * @param[in]     ChannelIsRunning        The flag of the channel running state
 *
 * @retval        void
 */
FUNC(void, OCU_CODE) Ocu_Ipw_SetPinAction(VAR(Ocu_ChannelType, AUTOMATIC) OcuChannelNumber,\
    VAR(Ocu_PinActionType, AUTOMATIC) OcuPinAction,\
    VAR(boolean, AUTOMATIC) ChannelIsRunning)
{
    Ocu_Tmr_HwSetPinAct((*g_hwConfigPtr->ocuHwChConfigPtr)[OcuChannelNumber].chConfigIndexList, \
                           OcuPinAction, ChannelIsRunning, g_hwConfigPtr->ocuTmrHwConfigPtr);    
}
#endif /* {if (STD_ON == OCU_SET_PIN_ACTION_API)} */

#if (STD_ON == OCU_GET_COUNTER_API)
/*!
 * @brief         The function is to get the counter value of the Ocu Tmr channel.
 *
 * @param[in]     OcuChannelNumber        The channel id of the Ocu driver
 *
 * @retval        Ocu_ValueType           The counter value of the Ocu Tmr channel
 */
FUNC (Ocu_ValueType, OCU_CODE) Ocu_Ipw_GetCnt(VAR(Ocu_ChannelType, AUTOMATIC) OcuChannelNumber)
{
    return (Ocu_Tmr_HwGetCnt((*g_hwConfigPtr->ocuHwChConfigPtr)[OcuChannelNumber].chConfigIndexList, \
                                 g_hwConfigPtr->ocuTmrHwConfigPtr));
}
#endif /* {if (STD_ON == OCU_GET_COUNTER_API)} */

#define OCU_STOP_SEC_CODE
#include "Ocu_MemMap.h"
/**@} end of group OCU_Fuctions */
#ifdef __cplusplus
}
#endif  /* ifdef __cplusplus */
/**@} end of group OCU_Driver */
/**@} end of group G32A10xx_StdPeriphDriver */
