/*!
* @file     CDD_Irme.c
*
* @version  1.0.0
*
* @brief    This source file includes the API implementation of the IRME module
*
* @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.
*/

#ifdef __cplusplus
extern "C"{
#endif

#include "CDD_Irme.h"
#include "Irme_Sms.h"

#if (IRME_DEV_ERR_DETECT_ENABLE == STD_ON)
  #include "Det.h"
#endif

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup IRME_Driver
  * @brief IRME driver modules
  @{
*/

/** @defgroup IRME_Macros
  @{
*/
/**********************************************************************************************************************
                                    VENDOR ID & AUTOSAR VERSION INFO
***********************************************************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define CDD_IRME_VENDOR_ID                                 0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CDD_IRME_AR_RELEASE_MAJOR_VERSION                  0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CDD_IRME_AR_RELEASE_MINOR_VERSION                  0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define CDD_IRME_AR_RELEASE_REVISION_VERSION               0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */   
#define CDD_IRME_SW_MAJOR_VERSION                          0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CDD_IRME_SW_MINOR_VERSION                          0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define CDD_IRME_SW_PATCH_VERSION                          0x00U

/**@} end of group IRME_Macros */

/**********************************************************************************************************************           
                                      VERSION INFOMATION VERIFICATION
***********************************************************************************************************************/
/* Make sure the vendor ids are the same between CDD_Irme.c and CDD_Irme.h */
#if (CDD_IRME_VENDOR_ID != CDD_IRME_H_VENDOR_ID)
    #error "Vendor ids mismatch between CDD_Irme.c and CDD_Irme.h"
#endif
/* Make sure the AUTOSAR major version number is the same between CDD_Irme.c and CDD_Irme.h */
#if (CDD_IRME_AR_RELEASE_MAJOR_VERSION    != CDD_IRME_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between CDD_Irme.c and CDD_Irme.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between CDD_Irme.c and CDD_Irme.h */
#if (CDD_IRME_AR_RELEASE_MINOR_VERSION    != CDD_IRME_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between CDD_Irme.c and CDD_Irme.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between CDD_Irme.c and CDD_Irme.h */
#if (CDD_IRME_AR_RELEASE_REVISION_VERSION != CDD_IRME_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between CDD_Irme.c and CDD_Irme.h"
#endif
/* Make sure the software major version number is the same between CDD_Irme.c and CDD_Irme.h */
#if (CDD_IRME_SW_MAJOR_VERSION != CDD_IRME_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between CDD_Irme.c and CDD_Irme.h"
#endif
/* Make sure the software minor version number is the same between CDD_Irme.c and CDD_Irme.h */
#if (CDD_IRME_SW_MINOR_VERSION != CDD_IRME_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between CDD_Irme.c and CDD_Irme.h"
#endif
/* Make sure the software patch version number is the same between CDD_Irme.c and CDD_Irme.h */
#if (CDD_IRME_SW_PATCH_VERSION != CDD_IRME_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between CDD_Irme.c and CDD_Irme.h"
#endif

/* Make sure the vendor ids are the same between CDD_Irme.c file and Irme_Sms.h */
#if (CDD_IRME_VENDOR_ID != IRME_SMS_H_VENDOR_ID)
    #error "Vendor ids mismatch between CDD_Irme.c and Irme_Sms.h"
#endif
/* Make sure the AUTOSAR major version number is the same between CDD_Irme.c and Irme_Sms.h */
#if (CDD_IRME_AR_RELEASE_MAJOR_VERSION != IRME_SMS_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between CDD_Irme.c and Irme_Sms.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between CDD_Irme.c and Irme_Sms.h */
#if (CDD_IRME_AR_RELEASE_MINOR_VERSION != IRME_SMS_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between CDD_Irme.c and Irme_Sms.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between CDD_Irme.c and Irme_Sms.h */
#if (CDD_IRME_AR_RELEASE_REVISION_VERSION != IRME_SMS_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between CDD_Irme.c and Irme_Sms.h"
#endif
/* Make sure the software major version number is the same between CDD_Irme.c and Irme_Sms.h */
#if (CDD_IRME_SW_MAJOR_VERSION != IRME_SMS_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between CDD_Irme.c and Irme_Sms.h"
#endif
/* Make sure the software minor version number is the same between CDD_Irme.c and Irme_Sms.h */
#if (CDD_IRME_SW_MINOR_VERSION != IRME_SMS_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between CDD_Irme.c and Irme_Sms.h"
#endif
/* Make sure the software patch version number is the same between CDD_Irme.c and Irme_Sms.h */
#if (CDD_IRME_SW_PATCH_VERSION != IRME_SMS_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between CDD_Irme.c and Irme_Sms.h"
#endif

/* Make sure the AUTOSAR version numbers are the same between CDD_Irme.c and Det.h */
#if (IRME_DEV_ERR_DETECT_ENABLE == STD_ON)
    #ifdef ENABLE_INTERMODULE_MCAL_CHECK
        /* Make sure the AUTOSAR major version number is the same between CDD_Irme.c and Det.h */
        #if (CDD_IRME_AR_RELEASE_MAJOR_VERSION != DET_H_AR_RELEASE_MAJOR_VERSION)
            #error "AUTOSAR Major Version Number mismatch between CDD_Irme.c and Det.h"
        #endif
        /* Make sure the AUTOSAR minor version number is the same between CDD_Irme.c and Det.h */
        #if (CDD_IRME_AR_RELEASE_MINOR_VERSION != DET_H_AR_RELEASE_MINOR_VERSION)
            #error "AUTOSAR Minor Version Number mismatch between CDD_Irme.c and Det.h"
        #endif
    #endif
#endif

/**********************************************************************************************************************
                                             GLOBAL VARIABLE
***********************************************************************************************************************/
#define IRME_START_SEC_VAR_INIT_UNSPECIFIED
#include "Irme_MemMap.h"

/** @defgroup IRME_Variable
  @{
*/

#if (IRME_DEV_ERR_DETECT_ENABLE == STD_ON)
/**
*   The array contains the state of every public api and changes every time when the api 
*   is called from IRME_API_IDLE_STATE to IRME_API_BUSY_STATE, and return IRME_API_IDLE_STATE state
*   after the api executed completly.
*/
static VAR(Irme_ApiStateType, IRME_VAR) g_irmeApiState[] = {
    IRME_API_IDLE_STATE, IRME_API_IDLE_STATE, 
    IRME_API_IDLE_STATE, IRME_API_IDLE_STATE,
    IRME_API_IDLE_STATE, IRME_API_IDLE_STATE
};
#endif

/**
*    The IRME driver refreshes the state when the launching or running stage from IRME_STATE_UINIT to IRME_STATE_INITIALIZED.
*    When enabled the lockable configuration, the driver will lock the configuration and set its state to be IRME_STATE_LOCKED. 
*/
static VAR(Irme_StateType, IRME_VAR) g_irmeDriverState = IRME_STATE_UNINIT;

/**@} end of group IRME_Variable */

#define IRME_STOP_SEC_VAR_INIT_UNSPECIFIED
#include "Irme_MemMap.h"

/**********************************************************************************************************************
                                                  LOCAL FUNCTION
***********************************************************************************************************************/
#define IRME_START_SEC_CODE
#include "Irme_MemMap.h"

/** @defgroup IRME_Fuctions
  @{
*/

#if (IRME_DEV_ERR_DETECT_ENABLE == STD_ON)
/*!
* @brief          The function is to verify that an API should ensure it is not pre-empting itself, and the driver is
 *                in the expected state,otherwise the API should report an error to DET moudle.
*
* @param[in]      FunctionId       The function service id.
* @param[out]     None
* @param[in,out]  None
*
* @retval         E_OK: the funciton is in expected state.
*                 E_NOT_OK:the function is in unexpected state.
*/
LOCAL_INLINE FUNC(Std_ReturnType,IRME_CODE) Irme_VerifyApiState(VAR(uint8, AUTOMATIC) FunctionId)
{
    VAR(Std_ReturnType,IRME_VAR) returnValue = (Std_ReturnType)E_OK;

    if ( IRME_API_BUSY_STATE == g_irmeApiState[FunctionId] )
    {
        returnValue = (Std_ReturnType)E_NOT_OK;
        (void)Det_ReportError(CDD_IRME_H_MODULE_ID, CDD_IRME_INSTANCE_ID, FunctionId, (uint8)CDD_IRME_E_REENTRANT);
    }
    else
    {
        if((uint8)SID_IRME_INIT == FunctionId)
        {
            switch(g_irmeDriverState)
            {
                case IRME_STATE_LOCKED:
                {
                    returnValue = (Std_ReturnType)E_NOT_OK;
                    (void)Det_ReportError(CDD_IRME_H_MODULE_ID, CDD_IRME_INSTANCE_ID, FunctionId, (uint8)CDD_IRME_E_PROHIBIT_RUN);
                    break;
                }
                default:
                    /* Intentionally Empty */
                break;
            }
        }
        else if((uint8)SID_IRME_INJECT_FAULT == FunctionId)
        {
            switch(g_irmeDriverState)
            {
                case IRME_STATE_UNINIT:
                {
                    returnValue = (Std_ReturnType)E_NOT_OK;
                    (void)Det_ReportError(CDD_IRME_H_MODULE_ID, CDD_IRME_INSTANCE_ID, FunctionId, (uint8)CDD_IRME_E_UNINIT);
                    break;
                }
                default:
                    /* Intentionally Empty */
                break;
            }

        }
        else
        {
            /* Intentionally Empty */
        }
    }

    switch(returnValue)
    {
        case (Std_ReturnType)E_OK:
        {
            /* if the funciton is in expected state, set API state busy */
            g_irmeApiState[FunctionId] = IRME_API_BUSY_STATE;
            break;
        }

        default:
        /* Intentionally Empty */
        break;
    }

    return returnValue;
}

/*!
* @brief          The function verify the initializing parameter pointer.
*
* @param[in]      ConfigPtr       The pointer of configuration parameters.
* @param[out]     None
* @param[in,out]  None
*
* @retval         E_OK: the pointer is valid.
*                 E_NOT_OK:the pointer is invalid.
*/
LOCAL_INLINE FUNC(Std_ReturnType,IRME_CODE) Irme_VerifyInitParameter(P2CONST(Irme_ConfigType, AUTOMATIC, IRME_APPL_CONST) ConfigPtr)
{
    VAR(Std_ReturnType,IRME_VAR) returnValue = (Std_ReturnType)E_NOT_OK;

    if(NULL_PTR != ConfigPtr)
    {
        returnValue = (Std_ReturnType)E_OK;
    }
    else
    {
        (void)Det_ReportError(CDD_IRME_H_MODULE_ID, CDD_IRME_INSTANCE_ID, (uint8)SID_IRME_INIT, (uint8)CDD_IRME_E_PARAM_SET);
    }

    return returnValue;
}

/*!
* @brief          The function is to verify that the fault pool pointer is not NULL, otherwise report error to Det.
*
* @param[in]      FaultsPoolPtr       The pointer of fault pool.
* @param[out]     None
* @param[in,out]  None
*
* @retval         E_OK: the pointer is valid.
*                 E_NOT_OK:the pointer is invalid.
*/
LOCAL_INLINE FUNC(Std_ReturnType,IRME_CODE) Irme_VerifyErrorPtr(P2CONST(Irme_FaultPoolType, AUTOMATIC, IRME_APPL_VAR) FaultsPoolPtr)
{
    VAR(Std_ReturnType,IRME_VAR) returnValue = (Std_ReturnType)E_NOT_OK;

    if(NULL_PTR != FaultsPoolPtr)
    {
        returnValue = (Std_ReturnType)E_OK;
    }
    else
    {
        /* do nothing */
    }

    if(NULL_PTR == FaultsPoolPtr)
    {
        (void)Det_ReportError(CDD_IRME_H_MODULE_ID, CDD_IRME_INSTANCE_ID, (uint8)SID_IRME_ACQUIRE_ERRORS, (uint8)CDD_IRME_E_PARAM_FAULT);
    }
    else
    {
        /* do nothing */
    }

    return returnValue;
}

/*!
* @brief          The function is to verify that the fault id is in acceptable range.
*
* @param[in]      InjectBitErr       The fault inject type.
* @param[out]     None
* @param[in,out]  None
*
* @retval         E_OK: the fault id is in range.
*                 E_NOT_OK:the fault id is outof range.
*/
LOCAL_INLINE FUNC(Std_ReturnType,IRME_CODE) Irme_VerifyFaultInject(VAR(Irme_InjectBitErrType, AUTOMATIC) InjectBitErr, 
                  VAR(uint8, AUTOMATIC) FunctionId)
{
    VAR(Std_ReturnType,IRME_VAR) returnValue = (Std_ReturnType)E_NOT_OK;
    VAR(boolean,IRME_VAR) validFaultIdFlag = (boolean)FALSE;

    validFaultIdFlag = Irme_Sms_CheckValidFault(InjectBitErr);

    if((boolean)TRUE == validFaultIdFlag)
    {
        returnValue = (Std_ReturnType)E_OK;
    }
    else
    {
        (void)Det_ReportError(CDD_IRME_H_MODULE_ID, CDD_IRME_INSTANCE_ID, FunctionId, (uint8)CDD_IRME_E_PARAM_FAULT);
    }

    return returnValue;
}

#endif

/**********************************************************************************************************************
                                                    GLOBAL FUNCTION
***********************************************************************************************************************/
#if (STD_ON == IRME_VERSION_INFO_API_ENABLE)
/*!
* @brief          The function is to get the version of the software.
*
* @param[in]      VersionInfoPtr       The pointer of storing the version information.
* @param[out]     None
* @param[in,out]  None
*/
FUNC(void, IRME_CODE) Irme_GetVersionInfo(P2VAR(Std_VersionInfoType,AUTOMATIC,IRME_APPL_DATA) VersionInfoPtr)
{    
    if (NULL_PTR != VersionInfoPtr)
    {
        (VersionInfoPtr)->vendorID         = (uint16)CDD_IRME_H_VENDOR_ID;
        (VersionInfoPtr)->moduleID         = (uint16)CDD_IRME_H_MODULE_ID;
        (VersionInfoPtr)->sw_major_version = (uint8)CDD_IRME_H_SW_MAJOR_VERSION;
        (VersionInfoPtr)->sw_minor_version = (uint8)CDD_IRME_H_SW_MINOR_VERSION;
        (VersionInfoPtr)->sw_patch_version = (uint8)CDD_IRME_H_SW_PATCH_VERSION;
    }
    else
    {
#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
        (void)Det_ReportError(CDD_IRME_H_MODULE_ID, CDD_IRME_INSTANCE_ID, (uint8)SID_IRME_GET_VERSION_INFO, (uint8)CDD_IRME_E_PARAM_VERSION_INFO);
#else
        /* do nothing */
#endif
    }
}
#endif

/*!
* @brief          The function is to inject a fault  
*
* @param[in]      InjectBitErr       The type of the injecting fault.
* @param[out]     None
* @param[in,out]  None
*/
FUNC(void, IRME_CODE) Irme_InjectFaults(VAR(Irme_InjectBitErrType, AUTOMATIC) InjectBitErr)
{
#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType,IRME_VAR) apiValidFlag = E_NOT_OK;
    VAR(Std_ReturnType,IRME_VAR) faultValidFlag = E_NOT_OK;

    apiValidFlag = Irme_VerifyApiState((uint8)SID_IRME_INJECT_FAULT);
    
    if((Std_ReturnType)E_OK == apiValidFlag)
    {
        faultValidFlag = Irme_VerifyFaultInject(InjectBitErr, (uint8)SID_IRME_INJECT_FAULT);
    }
    else
    {
        /* do nothing */
    } 

    if (((Std_ReturnType)E_OK == apiValidFlag) && ((Std_ReturnType)E_OK == faultValidFlag))
    {
#endif
        /* Inject the fault */
        Irme_Sms_InjectFault(InjectBitErr);
#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }

    if((Std_ReturnType)E_OK == apiValidFlag)
    {
        g_irmeApiState[SID_IRME_INJECT_FAULT] = IRME_API_IDLE_STATE;
    }  
    else
    {
        /* do nothing */
    }  
#endif
}

/*!
* @brief          This function is to get the status of collected fault by a call to the Irme_Geterrors() API. 
*
* @param[in]      ErrorPtr The Collected fault status structure of Irme_FaultPoolType.
* @param[in]      FaultId  The fault id to be gotten:
*                          0: RD_ERR_SIN_ID
*                          1: RD_ERR_DBL_ID
*                          2: RMW_ERR_SIN_ID
*                          3: RMW_ERR_DBL_ID
* @param[out]     None
* @param[in,out]  None
*
* @retval         0   The inputting fault id is not asserted or the fault id is invalid. 
*                 !=0 The inputting fault id is asserted.
*/
FUNC(Std_ReturnType, IRME_CODE)  Irme_FaultPending(P2CONST(Irme_FaultPoolType, AUTOMATIC, IRME_APPL_DATA) ErrorPtr, 
                                                   VAR(Irme_FaultIdType, AUTOMATIC) FaultId)
{
  uint32 midVal = 0;
  Std_ReturnType returnValue = 0;

  #if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
  if ((Std_ReturnType)E_OK == Irme_VerifyErrorPtr(ErrorPtr))
  {
  #endif 

    if(IRME_FAULT_ID_WITHIN_SCOPE(FaultId))
    {
      midVal = (((ErrorPtr)->faultPool[(uint8)FaultId >> IRME_FAULT_POOL_SHIFT]) & (1UL << ((uint8)FaultId & IRME_FAULT_POOL_MASK)));
    }
    else
    {
        /* do nothing */
    }
  
  #if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
  }
  else
  {
      /* do nothing */
  }
  #endif
  
  if(0UL != midVal)
  {
      returnValue = 1;
  }
  else
  {
      returnValue = 0;
  }

  return returnValue;
}

/*!
* @brief          The function is to get the errors.
*
* @param[in]      FaultPoolPtr       the pool to putting the fault information into it:
*                                    FaultPoolPtr->faultPool[0]: The bit map of the faults:
*                                    Bit 0: RD_ERR_SIN_ID
*                                    Bit 1: RD_ERR_DBL_ID
*                                    Bit 2: RMW_ERR_SIN_ID
*                                    Bit 3: RMW_ERR_DBL_ID
* @param[out]     None
* @param[in,out]  None
*
* @retval         E_OK:                     There is no pending fault.
*                 E_PENDING_FAULT_DETECTED: There is at least one pending fault.
*                 E_NOT_OK:                 The driver is in wrong state or an error occured when the API executing.
*/
FUNC(Std_ReturnType, IRME_CODE) Irme_AcquireErrors(P2VAR(Irme_FaultPoolType, AUTOMATIC, IRME_APPL_DATA) FaultPoolPtr)
{
    VAR(Std_ReturnType,IRME_VAR) returnVal = (Std_ReturnType)E_NOT_OK;
    
#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType,IRME_VAR) apiValidFlag = E_NOT_OK;
    VAR(Std_ReturnType,IRME_VAR) errValidFlag = E_NOT_OK;
    
    apiValidFlag = Irme_VerifyApiState((uint8)SID_IRME_ACQUIRE_ERRORS);
    
    if((Std_ReturnType)E_OK == apiValidFlag)
    {
        errValidFlag = Irme_VerifyErrorPtr(FaultPoolPtr);
    }  
    else
    {
        /* do nothing */
    }  

    if (((Std_ReturnType)E_OK == apiValidFlag) && ((Std_ReturnType)E_OK == errValidFlag))
    {
#endif
        MCAL_FAULT_INJECTION_POINT(FIP_T_IRME_ACQUIRE_ERRORS_FP1);

        returnVal = (Std_ReturnType)Irme_Sms_GetErrors(&(FaultPoolPtr->faultPool[0U]));

        if ((Std_ReturnType)E_OK != returnVal)
        {
            /* At least one fault has occured */
            returnVal = (Std_ReturnType)E_PENDING_FAULT_DETECTED;
        }
        else
        {
           /* do nothing */
        }
    
    /* Store the fault status */
    FaultPoolPtr->errStatus = returnVal;

#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }

    if((Std_ReturnType)E_OK == apiValidFlag)
    {
        g_irmeApiState[SID_IRME_ACQUIRE_ERRORS] = IRME_API_IDLE_STATE;
    } 
    else
    {
        /* do nothing */
    }
#endif

    return returnVal;
}

/*!
* @brief          The function is to initializes the IRME driver 
*
* @param[in]      ConfigPtr       Post-build: the Configuration pointer.
*                                 Pre-compile: NULL_PTR.
* @param[out]     None
* @param[in,out]  None
*
* @retval         E_OK: the IRME moudle initialized successfully.
*                 E_NOT_OK: initialized failed.
*/
FUNC(Std_ReturnType, IRME_CODE) Irme_Init(P2CONST(Irme_ConfigType, AUTOMATIC, IRME_APPL_CONST) ConfigPtr)
{
    VAR(Std_ReturnType,IRME_VAR) returnValue = (Std_ReturnType)E_NOT_OK;
    
#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)  
    VAR(Std_ReturnType,IRME_VAR) paraValidFlag = E_NOT_OK;
    VAR(Std_ReturnType,IRME_VAR) apiValidFlag = E_NOT_OK;

    paraValidFlag = Irme_VerifyInitParameter(ConfigPtr);

    if ((Std_ReturnType)E_OK == paraValidFlag)
#endif
    {
#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
        apiValidFlag = Irme_VerifyApiState((uint8)SID_IRME_INIT);

        if ((Std_ReturnType)E_OK == apiValidFlag)
        {
#endif
            g_irmeDriverState = IRME_STATE_INITIALIZED;

            MCAL_FAULT_INJECTION_POINT(FIP_T_IRME_INIT_FP1);
            returnValue = Irme_Sms_Init(ConfigPtr->smsModConfigPtr);
            MCAL_FAULT_INJECTION_POINT(FIP_T_IRME_INIT_STATE);

            if ( (Std_ReturnType)E_OK == returnValue )
            {
                if ((boolean)TRUE == ConfigPtr->configLock)
                {                    
                    g_irmeDriverState = IRME_STATE_LOCKED;
                }
                else
                {
                    /* do nothing */
                }
            }
            else
            {
                /* do nothing */
            }
#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)          
            g_irmeApiState[SID_IRME_INIT] = IRME_API_IDLE_STATE;
        }
        else
        {
            /* do nothing */
        }
#endif
    }
#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE) 
    else
    {
        /* do nothing */
    }
#endif

    return returnValue;
}

/*!
* @brief          The function is to clear the software recoverable fault 
*
* @param[in]      None
* @param[out]     None
* @param[in,out]  None
*
* @retval         E_OK: the is cleared successfully.
*                 E_NOT_OK: the fault is cleared failed.
*/
FUNC(Std_ReturnType, IRME_CODE) Irme_ClearFaults(void)
{
    VAR(Std_ReturnType,IRME_VAR) returnValue = (Std_ReturnType)E_NOT_OK;
    
#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType,IRME_VAR) apiValidFlag = E_NOT_OK;

    apiValidFlag = Irme_VerifyApiState((uint8)SID_IRME_CLEAR_FAULTS);

    if ((Std_ReturnType)E_OK == apiValidFlag)
    {
#endif

        MCAL_FAULT_INJECTION_POINT(FIP_T_IRME_CLEAR_FAULTS_FP1);
        returnValue = Irme_Sms_ClearFault();

#if (STD_ON == IRME_DEV_ERR_DETECT_ENABLE)
    }
    else
    {
        /* do nothing */
    }
    if((Std_ReturnType)E_OK == apiValidFlag)
    {
        g_irmeApiState[SID_IRME_CLEAR_FAULTS] = IRME_API_IDLE_STATE;
    }
    else
    {
        /* do nothing */
    }
#endif
    return returnValue;
}

/*!
* @brief          The function is to get the error address of the last detected error.
*
* @param[in]      None
* @param[out]     None
* @param[in,out]  None
*
* @retval         The error address of the last detected error.
*/
FUNC(uint32, IRME_CODE) Irme_GetErrorAddr(void)
{
    VAR(uint32,IRME_VAR) errorAddress = 0U;

    errorAddress = Irme_Sms_GetErrorAddr();

    return errorAddress;
}

/**@} end of group IRME_Fuctions */

#define IRME_STOP_SEC_CODE
#include "Irme_MemMap.h"

#ifdef __cplusplus
}
#endif

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