/*!
* @file     EcuM.c
*
* @version  1.0.0
*
* @brief    AUTOSAR EcuM module implementation
*
* @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 "Std_Types.h"
#include "EcuM.h"

#ifdef TEST_GPT
#include "Gpt.h"
#endif

#ifdef TEST_ICU
#include "Icu.h"
#endif

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @defgroup ECUM_Driver
  * @brief ECUM driver modules
  @{
*/

/** @defgroup ECUM_Macros
  @{
*/
/*******************************************************************************
                    VENDOR ID & AUTOSAR VERSION INFO
*******************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define ECUM_VENDOR_ID                     0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ECUM_AR_RELEASE_MAJOR_VERSION      0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ECUM_AR_RELEASE_MINOR_VERSION      0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define ECUM_AR_RELEASE_REVISION_VERSION   0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ECUM_SW_MAJOR_VERSION              0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ECUM_SW_MINOR_VERSION              0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define ECUM_SW_PATCH_VERSION              0x00U

/**@} end of group ECUM_Macros */

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

/* Make sure the vendor id is the same between EcuM.c and EcuM.h */
#if (ECUM_VENDOR_ID != ECUM_H_VENDOR_ID)
    #error "Vendor id mismatch between EcuM.c and EcuM.h"
#endif
/* Make sure the AUTOSAR major version number is the same between EcuM.c and EcuM.h */
#if (ECUM_AR_RELEASE_MAJOR_VERSION != ECUM_H_AR_RELEASE_MAJOR_VERSION)
    #error "AUTOSAR Major Version Number mismatch between EcuM.c and EcuM.h"
#endif
/* Make sure the AUTOSAR minor version number is the same between EcuM.c and EcuM.h */
#if (ECUM_AR_RELEASE_MINOR_VERSION != ECUM_H_AR_RELEASE_MINOR_VERSION)
    #error "AUTOSAR Minor Version Number mismatch between EcuM.c and EcuM.h"
#endif
/* Make sure the AUTOSAR revision version number is the same between EcuM.c and EcuM.h */
#if (ECUM_AR_RELEASE_REVISION_VERSION != ECUM_H_AR_RELEASE_REVISION_VERSION)
    #error "AUTOSAR Revision Version Number mismatch between EcuM.c and EcuM.h"
#endif
/* Make sure the software major version number is the same between EcuM.c and EcuM.h */
#if (ECUM_SW_MAJOR_VERSION != ECUM_H_SW_MAJOR_VERSION)
    #error "Software Major Version Number mismatch between EcuM.c and EcuM.h"
#endif
/* Make sure the software minor version number is the same between EcuM.c and EcuM.h */
#if (ECUM_SW_MINOR_VERSION != ECUM_H_SW_MINOR_VERSION)
    #error "Software Minor Version Number mismatch between EcuM.c and EcuM.h"
#endif
/* Make sure the software patch version number is the same between EcuM.c and EcuM.h */
#if (ECUM_SW_PATCH_VERSION != ECUM_H_SW_PATCH_VERSION)
    #error "Software Patch Version Number mismatch between EcuM.c and EcuM.h"
#endif

/*******************************************************************************
                            GLOBAL VARIABLES
*******************************************************************************/
/** @defgroup ECUM_Variable
  @{
*/

/** Source of the last wakeup event */
VAR(EcuM_WakeupSourceType, ECUM_VAR) g_ecumLastWakeupEvent;

VAR(uint8, ECUM_VAR) g_ecumWakeupEventCounter = 0;

/**@} end of group ECUM_Variable */

/*******************************************************************************
                            GLOBAL FUNCTIONS
*******************************************************************************/
/** @defgroup ECUM_Fuctions
  @{
*/

/*!
* @brief          Check the wakeup source against possible sources of wakeup
*                 This callout is called by the EcuM to poll a wakeup source. It shall
*                 also be called by the ISR of a wakeup source to set up the PLL and
*                 check other wakeup sources that may be connected to the same interrupt.
*
* @param[in]      WakeupSource    wake source id
* @param[out]     None
* @param[in,out]  None
*/
FUNC(void, ECUM_CODE) EcuM_CheckWakeup(VAR(EcuM_WakeupSourceType, AUTOMATIC) WakeupSource)
{
    #ifdef TEST_GPT
        Gpt_CheckWakeup(WakeupSource);
    #endif

    #ifdef TEST_ICU
    #if (( STD_ON == ICU_WAKEUP_FUNCTIONALITY_API_ENABLE ) && \
         ( STD_ON == ICU_REPORT_WAKEUP_SOURCE_ENABLE ) && \
         ( STD_ON == ICU_DISABLE_WAKEUP_API_ENABLE ))
        Icu_CheckWakeup(WakeupSource);
    #endif
    #endif

    (void)WakeupSource;
}

/*!
* @brief          Validate the wakeup event
*                 After wakeup, the ECU State Manager will stop the process during
*                 the WAKEUP VALIDATION state/sequence to wait for validation of the
*                 wakeup event. This API service is used to indicate to the ECU Manager
*                 module that the wakeup events indicated in the sources parameter have
*                 been validated.
*
* @param[in]      Source    wake source id
* @param[out]     None
* @param[in,out]  None
*/
FUNC(void, ECUM_CODE) EcuM_ValidateWakeupEvent(VAR(EcuM_WakeupSourceType, AUTOMATIC) Sources)
{
    (void)Sources;
}

/*!
* @brief          Set the wakeup event
*
* @param[in]      Source    wake source id
* @param[out]     None
* @param[in,out]  None
*/
FUNC(void, ECUM_CODE) EcuM_SetWakeupEvent(VAR(EcuM_WakeupSourceType, AUTOMATIC) Sources)
{
    g_ecumLastWakeupEvent = Sources;
    g_ecumWakeupEventCounter++;
}

/**@} end of group ECUM_Fuctions */

#ifdef __cplusplus
}
#endif

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