/*!
* @file     CDD_Rtc.c
*
* @version  1.0.0
*
* @brief    This file provides firmware functions to manage the following
*           functionalities of the Real-Time Clock (RTC) peripheral.
* @attention
*
* Project Name      : AUTOSAR MCAL
*
* Platform          : Arm
*
* Autosar Standard  : Classic Platform 4.4.0
*
* Compiled Version  : G32A10xx_MCAL_1_0_0_15-Nov-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
*
*      CDD_Rtc_c_MISRA_REF1
*          Breaks the required M3CM Rule-2.2 of MISRA 2012 guidelines,
*          A project shall not contain dead code
*/

#ifdef __cplusplus
extern "C"{
#endif

#include "Rtc_Hw.h"
#include "CDD_Rtc.h"
#include "Det.h"
/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup RTC_Driver
  * @brief RTC driver modules
  @{
*/

/*******************************************************************************
                               LOCAL VARIABLE
*******************************************************************************/
/** @defgroup RTC_Variable
  @{
*/
#if (STD_ON == RTC_DEV_ERR_DETECT_ENABLE)
    static Rtc_ModuleStateType s_rtcModuleState = RTC_MODULE_STATE_IS_UNINIT;
#endif
/**@} end of group RTC_Variable */
/*******************************************************************************
                               LOCAL FUNCTIONS
*******************************************************************************/
/** @defgroup RTC_Fuctions
  @{
*/
#if (STD_ON == RTC_DEV_ERR_DETECT_ENABLE)

/*!
* @brief        Report development error to Det module
*
* @param[in]    ServiceId   The service id to be reported
* @param[in]    ErrorId     The error id to be reported
*
* @return       None
*/
LOCAL_INLINE FUNC(void,RTC_CODE) Rtc_E_ReportDevelopment(VAR(uint8,AUTOMATIC) ServiceId,VAR(uint8,AUTOMATIC) ErrorId)
{
    (void)Det_ReportError((uint16)RTC_H_MODULE_ID, (uint8)0U, ServiceId, ErrorId);
}

/*!
* @brief        Validate the given pointer is NULL or not
*
* @param[in]    ServiceId       Service id of the caller function
* @param[in]    Ptr             Pointer to be validated
*
* @return       Std_ReturnType  Standard return type
* @retval       E_OK:           The given pointer is not NULL
* @retval       E_NOT_OK:       The given pointer is NULL
*/
LOCAL_INLINE FUNC(Std_ReturnType, RTC_CODE) Rtc_ValidatePointer(VAR(uint8, AUTOMATIC) ServiceId, \
    P2CONST(void, AUTOMATIC, RTC_APPL_CONST) Ptr)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_OK;
    if (NULL_PTR != Ptr)
    {
        /* No Operation */
    }
    else
    {
        Rtc_E_ReportDevelopment(ServiceId, (uint8)RTC_E_PARAM_POINTER);
        result = (Std_ReturnType)E_NOT_OK;
    }
    return result;
}

/*!
* @brief         This function is used to check RTC module environment.
*
* @param[in]     apiServiceId       -API service id
* @param[out]    None
* @param[in,out] None
*
* @retval        Std_ReturnType:E_OK/E_NOT_OK
*/
LOCAL_INLINE FUNC(Std_ReturnType, RTC_CODE) Rtc_CheckModuleState(VAR(uint8, AUTOMATIC) apiServiceId)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_OK;

    switch (s_rtcModuleState)
    {
        case RTC_MODULE_STATE_IS_UNINIT:
            result = (Std_ReturnType)(((uint8)SID_RTC_INIT != apiServiceId) ? E_NOT_OK : E_OK );
            if ((Std_ReturnType)E_NOT_OK == result)
            {
                (void)Det_ReportError((uint16)RTC_H_MODULE_ID, (uint8)0U,
                                      (uint8)apiServiceId, (uint8)RTC_E_UNINIT);
            }
            else
            {
                /* No error report */
            }
            break;

        default:
            result = (Std_ReturnType)(((uint8)SID_RTC_INIT == apiServiceId) ? E_NOT_OK : E_OK );
            if ((Std_ReturnType)E_NOT_OK == result)
            {
                (void)Det_ReportError((uint16)RTC_H_MODULE_ID, (uint8)0U,
                                      (uint8)apiServiceId, (uint8)RTC_E_ALREADY_INITIALIZED);
            }
            else
            {
                /* No error report */
            }
            break;
    }

    return result;
}

#endif

/*******************************************************************************
                            GLOBAL FUNCTIONS
*******************************************************************************/

/*!
* @brief       RTC Init
*
* @param[in]    ConfigPtr: Pointer to RTC driver configuration set.
*
* @retval       None
*
* @note
*/
FUNC(void, RTC_CODE) Rtc_Init(P2CONST(Rtc_ConfigType, AUTOMATIC, RTC_APPL_CONST) ConfigPtr)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_INIT);
    if ((Std_ReturnType)E_OK == result)
    {
        if ((const void*)NULL_PTR == ConfigPtr)
        {
             Rtc_E_ReportDevelopment(SID_RTC_INIT, (uint8)RTC_E_PARAM_POINTER);
        }
        /* ConfigPtr invalid */
        else 
#endif 
        {
            /* Disable Write Proctection */
            Rtc_Hw_DisableWriteProtection();

            /* Wait Synchro */
            (void)Rtc_Hw_WaitForSynchro();

            (void)Rtc_Hw_Config(ConfigPtr->Rtc_TimeInit);
            
        #if (STD_ON == RTC_DEV_ERR_DETECT_ENABLE)
            s_rtcModuleState = RTC_MODULE_STATE_IS_IDLE;
        #endif
        }
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief       RTC DeInit
*
* @param       None
*
* @retval      None
*
* @note
*/
FUNC(void, RTC_CODE) Rtc_DeInit(void)
{
#if (STD_ON == RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_DEINIT);
    if ((Std_ReturnType)E_OK == result)
    {
        (void)Rtc_Hw_Reset();
        s_rtcModuleState = RTC_MODULE_STATE_IS_UNINIT;
    }
#else
    (void)Rtc_Hw_Reset();
#endif
}

/*!
* @brief       Config Alarm
*
* @param[in]    ConfigPtr: Pointer to RTC driver configuration set.
*
* @retval       None
*
* @note
*/
FUNC(void, RTC_CODE) Rtc_AlarmsConfig(P2CONST(Rtc_ConfigType, AUTOMATIC, RTC_APPL_CONST) ConfigPtr)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_ALARMSCONFIG);
    if ((Std_ReturnType)E_OK == result)
    {
        if ((const void*)NULL_PTR == ConfigPtr)
        {
             Rtc_E_ReportDevelopment(SID_RTC_ALARMSCONFIG, (uint8)RTC_E_PARAM_POINTER);
        }
        /* ConfigPtr invalid */
        else 
#endif 
        {
            /* Config Alarm */
            Rtc_Hw_ConfigAlarm(RTC_FORMAT_BIN, ConfigPtr->AlarmStruct);
            /* Config Time */
            (void)Rtc_Hw_ConfigTime(RTC_FORMAT_BIN,  ConfigPtr->TimeStruct);
        }
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif

}

#if (STD_ON == RTC_GET_VERSION_INFO_FUNC) 
/*!
* @brief          This function is used to get the version information of RTC MCAL.
*
* @param[in]      None
* @param[inout]   None
* @param[out]     rtcMCALVersionInfo     point to where RTC MCAL version information stores.
* 
* @return         None
*/
FUNC(void, RTC_CODE) Rtc_GetVersionInfo( P2VAR(Std_VersionInfoType , AUTOMATIC, RTC_APPL_DATA) rtcMCALVersionInfo )
{
#if (STD_ON == RTC_DEV_ERR_DETECT_ENABLE)
    switch(Rtc_ValidatePointer(SID_RTC_GET_VERSION_INFO, rtcMCALVersionInfo))
    {
        case E_OK:
        {
            (rtcMCALVersionInfo)->vendorID = (uint16)RTC_H_VENDOR_ID;
            (rtcMCALVersionInfo)->moduleID = (uint16)RTC_H_MODULE_ID;
            (rtcMCALVersionInfo)->sw_major_version = (uint8)RTC_H_SW_MAJOR_VERSION;
            (rtcMCALVersionInfo)->sw_minor_version = (uint8)RTC_H_SW_MINOR_VERSION;
            (rtcMCALVersionInfo)->sw_patch_version = (uint8)RTC_H_SW_PATCH_VERSION;
            break;
        }
        case E_NOT_OK:
        default:
        {
            /* do nothing */
            break;
        }
    }
#else
    (rtcMCALVersionInfo)->vendorID = (uint16)RTC_H_VENDOR_ID;
    (rtcMCALVersionInfo)->moduleID = (uint16)RTC_H_MODULE_ID;
    (rtcMCALVersionInfo)->sw_major_version = (uint8)RTC_H_SW_MAJOR_VERSION;
    (rtcMCALVersionInfo)->sw_minor_version = (uint8)RTC_H_SW_MINOR_VERSION;
    (rtcMCALVersionInfo)->sw_patch_version = (uint8)RTC_H_SW_PATCH_VERSION;
#endif 
}
#endif

/*!
* @brief       Enable the RTC ALRMA.
*
* @param       None
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_EnableAlarm(void)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_ENABLEALARM);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Rtc_Hw_EnableAlarm();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief       Disable the the RTC ALRMA.
*
* @param       None
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_DisableAlarm(void)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_DISABLEALARM);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        (void)Rtc_Hw_DisableAlarm();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief       Enable the RTC Initialization mode.
*
* @param       None
*
* @retval      TRUE or FALSE
*/
FUNC(uint8, RTC_CODE) Rtc_EnableInit(void)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    result = Rtc_CheckModuleState((uint8)SID_RTC_ENABLEINIT);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        result = Rtc_Hw_EnableInit();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
    return result;
}

/*!
* @brief       Disable the RTC Initialization mode.
*
* @param       None
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_DisableInit(void)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_DISABLEINIT);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Rtc_Hw_DisableInit();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief       Waits until the RTC Time and Date registers (RTC_TIME and RTC_DATA) are
*              synchronized with RTC APB clock
* @param       None
*
* @retval      TRUE or FALSE
*/
FUNC(uint8, RTC_CODE) Rtc_WaitForSynchro(void)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    result = Rtc_CheckModuleState((uint8)SID_RTC_WAITFORSYNCHRO);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        result = Rtc_Hw_WaitForSynchro();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
    return result;
}

/*!
* @brief       Enable BypassShadow mode for reading calendar values.
*
* @param       None
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_EnableBypassShadow(void)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_ENABLEBYPASSSHADOW);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Rtc_Hw_EnableBypassShadow();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief       Enable Directly mode for reading calendar values
*
* @param       None
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_DisableBypassShadow(void)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_DISABLEBYPASSSHADOW);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Rtc_Hw_DisableBypassShadow();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief       Read the RTC current Time
*
* @param       Format: specifies the format to write
*                      This parameter can be one of the following values:
*                      RTC_FORMAT_BIN: format in Bin
*                      RTC_FORMAT_BCD: format in BCD
*
* @param       TimeStructPtr:  Pointer to a Rtc_TimeType structure that
*                           contains the configuration information for the RTC peripheral
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_ReadTime(VAR(Rtc_FormatType, AUTOMATIC) Format, P2VAR(Rtc_TimeType, AUTOMATIC, RTC_APPL_DATA) TimeStructPtr)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
    result = Rtc_CheckModuleState((uint8)SID_RTC_READTIME);
    if ((Std_ReturnType)E_OK == result)
    {
        result = Rtc_ValidatePointer(SID_RTC_READTIME, TimeStructPtr);
        if((Std_ReturnType)E_OK == result)
        {
#endif
            Rtc_Hw_ReadTime(Format, TimeStructPtr);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
        }
    }
#endif
}

/*!
* @brief       Read the RTC current Calendar Subseconds value
*
* @param       None
*
* @retval      RTC current Calendar Subseconds value
*/
FUNC(uint32, RTC_CODE) Rtc_ReadSubSecond(void)
{
    VAR(uint32, AUTOMATIC) secondData = 0;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
    result = Rtc_CheckModuleState((uint8)SID_RTC_READSUBSECOND);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        secondData = Rtc_Hw_ReadSubSecond();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
    return secondData;
}

/*!
* @brief       Config the RTC current time
*
* @param       Format: specifies the format to write
*                      This parameter can be one of the following values:
*                      RTC_FORMAT_BIN: format in Bin
*                      RTC_FORMAT_BCD: format in BCD
*
* @param       DateStructPtr: Pointer to a Rtc_DateType structure that
*                           contains the configuration DATE information for the RTC peripheral
*
* @retval      None
*/
FUNC(uint8, RTC_CODE) Rtc_ConfigDate(VAR(Rtc_FormatType, AUTOMATIC) Format, P2CONST(Rtc_DateType, AUTOMATIC, RTC_APPL_DATA) DateStructPtr)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    result = Rtc_CheckModuleState((uint8)SID_RTC_CONFIGDATA);
    if ((Std_ReturnType)E_OK == result)
    {
        result = Rtc_ValidatePointer(SID_RTC_CONFIGDATA, DateStructPtr);
        if((Std_ReturnType)E_OK == result)
        {
#endif
            result = Rtc_Hw_ConfigDate(Format, DateStructPtr);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
        }
    }
#endif
    return result;
}

/*!
* @brief       Read the RTC current date
*
* @param       Format: specifies the format to write
*                      This parameter can be one of the following values:
*                      RTC_FORMAT_BIN: format in Bin
*                      RTC_FORMAT_BCD: format in BCD
*
* @param       DateStructPtr:  Pointer to a Rtc_DateType structure that
*                           contains the configuration DATE information for the RTC peripheral
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_ReadDate(VAR(Rtc_FormatType, AUTOMATIC) Format, P2VAR(Rtc_DateType, AUTOMATIC, RTC_APPL_DATA) DateStructPtr)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
    result = Rtc_CheckModuleState((uint8)SID_RTC_READDATE);
    if ((Std_ReturnType)E_OK == result)
    {
        result = Rtc_ValidatePointer(SID_RTC_READDATE, DateStructPtr);
        if((Std_ReturnType)E_OK == result)
        {
#endif
            Rtc_Hw_ReadDate(Format, DateStructPtr);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
        }
    }
#endif
}

/*!
* @brief       Get the RTC ALRMA value and masks
*
* @param       Format: specifies the format to write
*                      This parameter can be one of the following values:
*                      RTC_FORMAT_BIN: format in Bin
*                      RTC_FORMAT_BCD: format in BCD
*
* @param       AlarmStruct: Pointer to a Rtc_AlarmType structure that
*                           contains the configuration ALRMA information for the RTC peripheral
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_ReadAlarm(VAR(Rtc_FormatType, AUTOMATIC) Format, P2VAR(Rtc_AlarmType, AUTOMATIC, RTC_APPL_DATA) AlarmStructPtr)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
    result = Rtc_CheckModuleState((uint8)SID_RTC_READALARM);
    if ((Std_ReturnType)E_OK == result)
    {
        result = Rtc_ValidatePointer(SID_RTC_READALARM, AlarmStructPtr);
        if((Std_ReturnType)E_OK == result)
        {
#endif
            Rtc_Hw_ReadAlarm(Format, AlarmStructPtr);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
        }
    }
#endif
}

/*!
* @brief       Read the RTC ALRMA Subseconds value
*
* @param       val: Specifies the value for ALRMA Sub Second
*                   this value must less than 0x00007FFF
*
* @param       mask: Specifies the mask for ALRMA Sub Second
*                   this value must less than 0x0f
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_ConfigAlarmSubSecond(VAR(uint32, AUTOMATIC) Val, VAR(uint8, AUTOMATIC) Mask)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_CONFIGALARMSUBSECOND);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Rtc_Hw_ConfigAlarmSubSecond(Val,Mask);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief       Read the RTC ALRMA Subseconds value
*
* @param       None
*
* @retval      RTC ALRMA Subseconds value
*/
FUNC(uint32, RTC_CODE) Rtc_ReadAlarmSubSecond(void)
{
    VAR(uint32, AUTOMATIC) alarmSubSecond = 0;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
    result = Rtc_CheckModuleState((uint8)SID_RTC_READALARMSUBSECOND);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        alarmSubSecond = Rtc_Hw_ReadAlarmSubSecond();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
    return alarmSubSecond;
}

/*!
* @brief       Adds or substract one hour from the current time
*
* @param       Sav:   specifies the DayLightSaving
*                     This parameter can be one of the following values:
*                     RTC_DLS_SUB1H
*                     RTC_DLS_ADD1H
*
* @param       Bit:   specifies the DayLightSaving
*                     This parameter can be one of the following values:
*                     RTC_SO_RESET
*                     RTC_SO_SET
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_ConfigDayLightSaving(VAR(Rtc_DayLightSavingType, AUTOMATIC) Sav, VAR(Rtc_StoreOperationType, AUTOMATIC) Bit)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_CONFIGDAYLIGHTSAVING);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Rtc_Hw_ConfigDayLightSaving(Sav,Bit);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief       Returns the RTC Day Light Saving stored operation
*
* @param       None
*
* @retval      RTC Day Light Saving stored operation
*/
FUNC(uint32, RTC_CODE) Rtc_ReadStoreOperation(void)
{
    VAR(uint32, AUTOMATIC) storeData = 0;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_READSTOREOPERATION);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        storeData = Rtc_Hw_ReadStoreOperation();
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
    return storeData;
}

/*!
* @brief       Configures the Synchronization Shift Control Settings.
*
* @param       Period: Select the Smooth Calibration period.
*                      This parameter can be can be one of the following values:
*                      RTC_SCP_16SEC: The smooth calibration periode is 16.
*                      RTC_SCP_8SEC:  The smooth calibartion periode is 8s.
*
* @param       Bit:    Select to Set or reset the CALP bit.
*                      This parameter can be one of the following values:
*                      RTC_SCPP_RESET: Add one RTCCLK puls every 211 pulses.
*                      RTC_SCPP_SET:   No RTCCLK pulses are added.
*
* @param       Value:  Select the value of CALM[8:0] bits.
*                      This parameter can be one any value from 0 to 0x000001FF.
*
* @retval         TRUE or FALSE
*/
FUNC(uint8, RTC_CODE) Rtc_ConfigSmoothCalib(VAR(Rtc_ScpType, AUTOMATIC) Period, VAR(Rtc_ScppType, AUTOMATIC) Bit, VAR(uint32, AUTOMATIC) Value)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    result = Rtc_CheckModuleState((uint8)SID_RTC_CONFIGSMOOTHCALIB);
    if ((Std_ReturnType)E_OK == result)
    {

#endif
        result = Rtc_Hw_ConfigSmoothCalib(Period, Bit, Value);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
    return result;
}

/*!
* @brief       Configures the Synchronization Shift Control Settings.
*
* @param       add1S:  Select to add or not 1 second to the time Calendar.
*                      This parameter can be one of the following values :
*                      RTC_SHIFTADD1S_SET: Add one second to the clock calendar.
*                      RTC_SHIFTADD1S_RESET:   No effect.
*
* @param       subFS:  Select the number of Second Fractions to Substitute.
*                      This parameter can be one any value from 0 to 0x7FFF.
*
* @retval      TRUE or FALSE
*/
FUNC(uint8, RTC_CODE) Rtc_ConfigSynchroShift(VAR(Rtc_ShiftAdd1sType, AUTOMATIC) Add1S, VAR(uint32, AUTOMATIC) SubFS)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    result = Rtc_CheckModuleState((uint8)SID_RTC_CONFIGSYNCHROSHIFT);
    if ((Std_ReturnType)E_OK == result)
    {

#endif
        result = Rtc_Hw_ConfigSynchroShift(Add1S, SubFS);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
    return result;
}

/*!
* @brief       Enable RTC interrupts.
*
* @param       interrupt: specifies the RTC interrupt sources to be enabled
*                       This parameter can be any combination of the following values:
*                       RTC_INT_ALR:  ALRMA A interrupt mask
*                       RTC_INT_WT:  WakeUp Timer interrupt mask
*
* @retval      None
*/
FUNC(void, RTC_CODE) Rtc_EnableInterrupt(VAR(uint32, AUTOMATIC) Interrupt)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_ENABLEINTERRUPT);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Rtc_Hw_EnableInterrupt(Interrupt);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief     Disable RTC interrupts.
*
* @param     interrupt: specifies the RTC interrupt sources to be disable
*                       This parameter can be any combination of the following values:
*                       RTC_INT_ALR:  ALRMA A interrupt mask
*                       RTC_INT_WT:   WakeUp Timer interrupt mask
*
* @retval    None
*/
FUNC(void, RTC_CODE) Rtc_DisableInterrupt(VAR(uint32, AUTOMATIC) Interrupt)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_DISABLEINTERRUPT);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Rtc_Hw_DisableInterrupt(Interrupt);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief     Read interrupt flag bit is set
*
* @param     Flag: specifies the flag to read.
*                  This parameter can be one of the following values:
*                  RTC_INT_FLAG_ALR: ALRMA interrupt
*                  RTC_INT_FLAG_WT: WakeUp Timer interrupt
* @retval    The new state of flag (TRUE or FALSE).
*/
FUNC(uint8, RTC_CODE) Rtc_ReadIntFlag(VAR(Rtc_IntFlagType, AUTOMATIC) Flag)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    result = Rtc_CheckModuleState((uint8)SID_RTC_READINTFLAG);
    if ((Std_ReturnType)E_OK == result)
    {

#endif
        result = Rtc_Hw_ReadIntFlag(Flag);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
    return result;
}

/*!
* @brief     Checks whether the specified RTC flag is set or not.
*
* @param     Flag: specifies the flag to check.
*                  This parameter can be one of the following values:
*                  RTC_FLAG_AWF:  Alarm Write Flag 
*                  RTC_FLAG_SOPF:  Shift Operation Pending Flag 
*                  RTC_FLAG_ISF:  Initialization State Flag 
*                  RTC_FLAG_RSF:  Registers Synchronization Flag 
*                  RTC_FLAG_INTF:  Register Initialization Flag 
*                  RTC_FLAG_ALRF:   Alarm Match Flag 
*                  RTC_FLAG_RPF:  Recalibration Pending Flag 
* @retval    The new state of RTC_FLAG (TRUE or FALSE).
*/
FUNC(uint8, RTC_CODE) Rtc_ReadStatusFlag(VAR(Rtc_FlagType, AUTOMATIC) Flag)
{
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    result = Rtc_CheckModuleState((uint8)SID_RTC_READSTATUSFLAG);
    if ((Std_ReturnType)E_OK == result)
    {

#endif
        result = Rtc_Hw_ReadStatusFlag(Flag);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
    return result;
}

/*!
* @brief     Clears the RTC's status flags.
* @param     flag: specifies the RTC flag to clear.
*                  This parameter can be any combination of the following values:
*                  RTC_FLAG_AWF:  Alarm Write Flag 
*                  RTC_FLAG_SOPF:  Shift Operation Pending Flag 
*                  RTC_FLAG_ISF:  Initialization State Flag 
*                  RTC_FLAG_RSF:  Registers Synchronization Flag 
*                  RTC_FLAG_INTF:  Register Initialization Flag 
*                  RTC_FLAG_ALRF:   Alarm Match Flag 
*                  RTC_FLAG_RPF:  Recalibration Pending Flag 
*/
FUNC(void, RTC_CODE) Rtc_ClearStatusFlag(VAR(uint32, AUTOMATIC) Flag)
{
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    VAR(Std_ReturnType, AUTOMATIC) result = (Std_ReturnType)E_NOT_OK;

    result = Rtc_CheckModuleState((uint8)SID_RTC_CLEARSTATUSFLAG);
    if ((Std_ReturnType)E_OK == result)
    {
#endif
        Rtc_Hw_ClearStatusFlag(Flag);
#if (STD_OFF !=  RTC_DEV_ERR_DETECT_ENABLE)
    }
#endif
}

/*!
* @brief    Interrupt service routine to process the command
*/
ISR(RTC_IRQHandler)
{
    /* Add callback func */
    Rtc_ProcessInterrupt();
    EXIT_INTERRUPT();
}

#if defined(__GNUC__) || defined(__clang__) || defined(__ARMCC_VERSION)
__attribute__((weak))
#endif
#if defined(__ICCARM__)
#pragma weak Rtc_AlarmNotification
#endif
void Rtc_AlarmNotification(void)
{
    /* Overridden by application (e.g. RTC_Timer-style tick counter). */
}

/*!
* @brief Interrupt service routine
*/
FUNC(void, RTC_CODE) Rtc_ProcessInterrupt(void)
{
    /*** @warning CDD_Rtc_c_MISRA_REF1 This function call produces no side effects and is redundant. */
    Rtc_AlarmNotification();
    Rtc_Hw_ClearStatusFlag((uint32)RTC_FLAG_ALRF);
}

/**@} end of group RTC_Fuctions */
#ifdef __cplusplus
}
#endif

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