/**
 * @file    Mcu.h
 * @version
 *
 * @brief   AUTOSAR Mcu module interface
 * @details API implementation for MCU driver
 *
 * @addtogroup MCU_MODULE
 * @{
 */
/*==================================================================================================
 *   Project              : YTMicro AUTOSAR 4.4.0 MCAL
 *   Platform             : ARM
 *   Peripheral           : Mcu
 *   Dependencies         : none
 *
 *   Autosar Version      : V4.4.0
 *   Autosar Revision     : ASR_REL_4_4_REV_0000
 *   Autosar Conf.Variant :
 *   SW Version           : V0.8.0
 *
 *
 *   (c) Copyright 2020-2026 Yuntu Microelectronics co.,ltd.
 *   All Rights Reserved.
==================================================================================================*/
#ifndef MCU_H
#define MCU_H

#ifdef __cplusplus
extern "C"
{
#endif
/*=================================================================================================
 *                                          INCLUDE FILES
=================================================================================================*/
#include "Mcu_Types.h"

/*==================================================================================================
 *                                 SOURCE FILE VERSION INFORMATION
==================================================================================================*/
#define MCU_VENDOR_ID                      (0xB4)
#define MCU_AR_RELEASE_MAJOR_VERSION       (4)
#define MCU_AR_RELEASE_MINOR_VERSION       (4)
#define MCU_AR_RELEASE_REVISION_VERSION    (0)
#define MCU_SW_MAJOR_VERSION               (0)
#define MCU_SW_MINOR_VERSION               (8)
#define MCU_SW_PATCH_VERSION               (0)

/*==================================================================================================
 *                                       FILE VERSION CHECKS
==================================================================================================*/
/* Mcu_Types.h version check */
#if (MCU_VENDOR_ID != MCU_VENDOR_ID)
#error "Mcu.h and Mcu_Types.h have different vendor ids"
#endif

#if ((MCU_AR_RELEASE_MAJOR_VERSION != MCU_AR_RELEASE_MAJOR_VERSION) || \
     (MCU_AR_RELEASE_MINOR_VERSION != MCU_AR_RELEASE_MINOR_VERSION) || \
     (MCU_AR_RELEASE_REVISION_VERSION != MCU_AR_RELEASE_REVISION_VERSION) \
    )
#error "AutoSar Version Numbers of Mcu.h and Mcu_Types.h are different"
#endif

#if ((MCU_SW_MAJOR_VERSION != MCU_SW_MAJOR_VERSION) || \
     (MCU_SW_MINOR_VERSION != MCU_SW_MINOR_VERSION) || \
     (MCU_SW_PATCH_VERSION != MCU_SW_PATCH_VERSION) \
    )
#error "Software Version Numbers of Mcu.h and Mcu_Types.h are different"
#endif

/*==================================================================================================
 *                                        DEFINES AND MACROS
==================================================================================================*/
/** @brief MCU MODULE INSTANCE ID */
#define MCU_INSTANCE_ID                 ((uint8)0U)

/** @brief MCU MODULE ID */
#define MCU_MODULE_ID                   ((uint8)101U)

#if (MCU_DEV_ERROR_DETECT == STD_ON)
/**
 * @defgroup        Mcu_DEV_ERROR
 * @brief           MCU development errors
 * @{
 */
/** @brief MCU API service is called using an invalid pointer (e.g. the pointer should not be NULL).  */
#define MCU_E_PARAM_CONFIG              (0x0AU)
#define MCU_E_PARAM_CLOCK               (0x0BU)
#define MCU_E_PARAM_MODE                (0x0CU)
#define MCU_E_PARAM_RAMSECTION          (0x0DU)
#define MCU_E_PLL_NOT_LOCKED            (0x0EU)
#define MCU_E_UNINIT                    (0x0FU)
#define MCU_E_PARAM_POINTER             (0x10U)
#define MCU_E_INIT_FAILED               (0x11U)
/** @} */
#endif /* (MCU_DEV_ERROR_DETECT == STD_ON) */

/**
 * @defgroup        Mcu_SID
 * @brief           Service ID number for all MCU driver services
 * @{
 */
/** @brief API Service ID for Mcu_DistributePllClock */
#define MCU_SID_DISTRIBUTE_PLL_CLOCK    (0x03U)
/** @brief API Service ID for Mcu_GetPllStatus */
#define MCU_SID_GET_PLL_STATUS          (0x04U)
/** @brief API Service ID for Mcu_GetResetRawValue */
#define MCU_SID_GET_RESET_RAW_VALUE     (0x06U)
/** @brief API Service ID for Mcu_GetResetReason */
#define MCU_SID_GET_RESET_REASON        (0x05U)
/** @brief API Service ID for Mcu_GetVersionInfo */
#define MCU_SID_GET_VERSION_INFO        (0x09U)
/** @brief API Service ID for Mcu_Init */
#define MCU_SID_INIT                    (0x00U)
/** @brief API Service ID for Mcu_InitClock */
#define MCU_SID_INIT_CLOCK              (0x02U)
/** @brief API Service ID for Mcu_InitRamSection */
#define MCU_SID_INIT_RAM_SECTION        (0x01U)
/** @brief API Service ID for Mcu_PerformReset */
#define MCU_SID_PERFORM_RESET           (0x07U)
/** @brief API Service ID for Mcu_SetMode */
#define MCU_SID_SET_MODE                (0x08U)
/** @brief API Service ID for Mcu_GetSxoscStatus */
#define MCU_SID_GET_SXOSC_STATUS        (0x0CU)
/** @brief API Service ID for Mcu_SetCmuChannel2 */
#define MCU_SID_SET_CMU_CHANNEL2        (0x0DU)
/** @} */



/*==================================================================================================
 *                                        EXTERNAL CONSTANTS
==================================================================================================*/

/*==================================================================================================
 *                                              ENUMS
==================================================================================================*/

/*==================================================================================================
 *                                         GLOBAL CONSTANTS
==================================================================================================*/


/*==================================================================================================
 *                                       FUNCTION PROTOTYPES
==================================================================================================*/
#if MCU_NO_PLL == STD_OFF
/**
 * @brief         This service activates the PLL clock to the MCU clock distribution.
 * @autosar       SWS_Mcu_00156
 *
 * @details       Service ID: 0x03
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Mcu.h
 *
 * @return        Std_ReturnType
 *                - E_OK: Command has been accepted;
 *                - E_NOT_OK: Command has not been accepted.
 */
Std_ReturnType Mcu_DistributePllClock(void);
#endif

/**
 * @brief         This function is responsible for resetting the CM33 system. It does not return any value.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Mcu.h
 *
 * @return        void
 */
void Mcu_180_SystemReset(void);

/**
 * @brief         This service provides the lock status of the PLL.
 * @autosar       SWS_Mcu_00157
 *
 * @details       Service ID: 0x04
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Mcu.h
 *
 * @return        Mcu_PllStatusType PLL Status.
 */
Mcu_PllStatusType Mcu_GetPllStatus(void);

#if (MCU_GET_SXOSC_STATUS_API == STD_ON)
/**
 * @brief         This service provides the lock status of the SXOSC.
 * @autosar       N/A
 *
 * @details       Service ID: 0x0C
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Mcu.h
 *
 * @return        Mcu_SxoscStatusType The lock status of the SXOSC.
 */
Mcu_SxoscStatusType Mcu_GetSxoscStatus(void);
#endif

/**
 * @brief         The service reads the reset type from the hardware, if supported.
 * @autosar       SWS_Mcu_00158
 *
 * @details       Service ID: 0x05
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Mcu.h
 *
 * @return        Mcu_ResetType
 *                - Reset reason read from hardware (if supported);
 *                - MCU_POWER_ON_RESET if hardware does not support reset reason detection.
 */
Mcu_ResetType Mcu_GetResetReason(void);

/**
 * @brief         This service initializes the MCU driver.
 * @autosar       SWS_Mcu_00153
 *
 * @details       Service ID: 0x00
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Mcu.h
 *
 * @param[in]     ConfigPtr: Pointer to MCU driver configuration set.
 * @return void
 */
void Mcu_Init(const Mcu_ConfigType *ConfigPtr);

#if (MCU_INIT_CLOCK == STD_ON)
/**
 * @brief         This service initializes the PLL and other MCU specific clock options.
 * @autosar       SWS_Mcu_00155
 *
 * @details       Service ID: 0x02
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Mcu.h
 *
 * @param[in]     ClockSetting: Clock setting.
 * @return        Std_ReturnType
 *                - E_OK: Command has been accepted;
 *                - E_NOT_OK: Command has not been accepted.
 */
Std_ReturnType Mcu_InitClock(Mcu_ClockType ClockSetting);

/**
 * @brief         Get the current MCU core clock frequency, must call Mcu_InitClock() first.
 * @autosar       N/A
 *
 * @details       Service ID: N/A
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Mcu.h
 *
 * @return        uint32 The current MCU core clock frequency.
 */
uint32 Mcu_180_GetCoreClockFrequency(void);
#endif

/**
 * @brief         This service initializes the RAM section wise.
 * @autosar       SWS_Mcu_00154
 *
 * @details       Service ID: 0x01
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Mcu.h
 *
 * @param[in]     RamSection: Selects RAM memory section provided in configuration set.
 * @return        Std_ReturnType
 *                - E_NOT_OK: command has not been accepted e.g. due to parameter error;
 *                - E_OK: command has been accepted.
 */
Std_ReturnType Mcu_InitRamSection(Mcu_RamSectionType RamSection);

/**
 * @brief         The service performs a microcontroller reset.
 * @autosar       SWS_Mcu_00160
 *
 * @details       Service ID: 0x07
 *                Sync/Async: Synchronous
 *                Reentrancy: Non Reentrant
 *                Available via: Mcu.h
 *
 * @return        void
 */
void Mcu_PerformReset(void);

/**
* @brief         This service activates the MCU power modes.
* @autosar       SWS_Mcu_00161
*
* @details       Service ID: 0x08
*                Sync/Async: Synchronous
*                Reentrancy: Reentrant
*                Available via: Mcu.h
*
* @param[in]     McuMode: Set different MCU power modes configured in the configuration set.
* @return        void
*/
void Mcu_SetMode(Mcu_ModeType McuMode);

/**
 * @brief         The service reads the reset type from the hardware register, if supported.
 * @autosar       SWS_Mcu_00159
 *
 * @details       Service ID: 0x06
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Mcu.h
 *
 * @return        Mcu_RawResetType
 *                - Reset raw value read from hardware register (if supported);
 *                - 0x0 if hardware has no reset status register.
 */
Mcu_RawResetType Mcu_GetResetRawValue(void);

#if (MCU_VERSION_INFO_API == STD_ON)
/**
 * @brief         This service returns the version information of this module.
 * @autosar       SWS_Mcu_00162
 *
 * @details       Service ID: 0x09
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Mcu.h
 *
 * @param[out]    versioninfo: Pointer to where to store the version information of this module.
 * @return        void
 */
void Mcu_GetVersionInfo(Std_VersionInfoType *VersionInfo);
#endif

#if (MCU_NO_PLL == STD_OFF)
/**
 * @brief         This service provides the enable for CMU channel2, if the PLL is enbaled and not choosen as system clock, this function is needed for relative CMU channel enable
 * @autosar       N/A
 *
 * @details       Service ID: 0x0D
 *                Sync/Async: Synchronous
 *                Reentrancy: Reentrant
 *                Available via: Mcu.h
 *
 * @return Std_ReturnType Whether the enable is ok.
*/
Std_ReturnType Mcu_SetCmuChannel2(void);
#endif

#ifdef __cplusplus
}
#endif

#endif /* MCU_H */

/** @} */

