/*!
* @file     Mcu.h
*
* @version  1.0.0
*
* @brief    Contains all the public functions and data types that are used by the higher layer.
*
* @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.
*/

#ifndef MCU_H
#define MCU_H

#ifdef __cplusplus
extern "C" {
#endif

 
#include "StdRegMacros.h"
#include "Mcu_RcmTypes.h"
#include "Mcu_SysCfgTypes.h"
#include "Mcu_PmuTypes.h"
#include "Mcu_DbgmcuTypes.h"
#include "Std_Types.h"
#include "Mcu_Cfg.h"

/** @addtogroup G32A10xx_StdPeriphDriver
  @{
*/

/** @addtogroup MCU_Driver
  @{
*/

/** @defgroup MCU_Macros
  @{
*/
/*******************************************************************************
                        VENDOR ID & AUTOSAR VERSION INFO
*******************************************************************************/
/** Vendor ID (vendorId) of the dedicated implementation of this module according to the AUTOSAR vendor list. */
#define MCU_H_VENDOR_ID                       0x00C1U
/** Major version number of AUTOSAR release on which the appropriate implementation is based on. */
#define MCU_H_AR_RELEASE_MAJOR_VERSION        0x04U
/** Minor version number of AUTOSAR release on which the appropriate implementation is based on. */
#define MCU_H_AR_RELEASE_MINOR_VERSION        0x04U
/** Revision version number of AUTOSAR release on which the appropriate implementation is based on. */
#define MCU_H_AR_RELEASE_REVISION_VERSION     0x00U
/** Major version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define MCU_H_SW_MAJOR_VERSION                0x01U
/** Minor version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define MCU_H_SW_MINOR_VERSION                0x00U
/** Patch level version number of the vendor specific implementation of the module. The numbering is vendor specific. */
#define MCU_H_SW_PATCH_VERSION                0x00U

/*******************************************************************************
                            STRUCT DEFINITION
*******************************************************************************/
/** The status of the MCU driver is uninitialized */
#define MCU_DRIVER_UNINIT   0x3U
  
/** The status of the MCU driver is idle */
#define MCU_DRIVER_IDLE     0xCU
  
/** The status of the MCU driver is busy */
#define MCU_DRIVER_BUSY     0xAU
/*******************************************************************************
                            API Service ID List
*******************************************************************************/
/* Instance ID of mcu driver */
#define MCU_INIT_SID                    ((uint8)0x00U)

#define MCU_INITRAMSECTION_SID          ((uint8)0x01U)
#define MCU_INITCLOCK_SID               ((uint8)0x02U)
#define MCU_DISTRIBUTEPLLCLOCK_SID      ((uint8)0x03U)
#define MCU_GETPLLSTATUS_SID            ((uint8)0x04U)
#define MCU_GETRESETREASON_SID          ((uint8)0x05U)
#define MCU_GETRESETRAWVALUE_SID        ((uint8)0x06U)
#define MCU_PERFORMRESET_SID            ((uint8)0x07U)
#define MCU_SETMODE_SID                 ((uint8)0x08U)
#define MCU_GETVERSIONINFO_SID          ((uint8)0x09U)
#define MCU_GETRAMSTATE_SID             ((uint8)0x0AU)
/**@} end of group MCU_Macros */


/** @defgroup MCU_Enumerations
  @{
*/

#if (MCU_GET_RAM_STATE_API == STD_ON)
typedef enum
{
    MCU_RAMSTATE_INVALID = 0U,   /* RAM content is not valid or unknown (default). */
    MCU_RAMSTATE_VALID           /* RAM content is valid. */
} Mcu_RamStateType;
#endif

/**@} end of group MCU_Enumerations */

/** @defgroup MCU_Typedef
  @{
*/

typedef uint8 Mcu_StatusType;

/**
* @brief   This type specifies the identification (ID) for a RAM section.
*/
typedef uint32  Mcu_RamSectionType;

/**
* @brief   The type specifies the RAM section size
*/
typedef uint32  Mcu_RamSecSizeType;

/**
* @brief   The Mcu_RamWrtSecSizeType specifies the RAM section write size.
*/
typedef uint32  Mcu_RamWrtSecSizeType;

/**
* @brief   This type specifies the index of the RAM sections.
*/
typedef uint32  Mcu_RamIdType;

#if (MCU_INITCLK_ENABLED == STD_ON)
/**
* @brief          Defines the identification (ID) for clock setting configured via the configuration structure.
* @details        The type shall be uint8, uint16 or uint32, depending on uC platform.
*
* @implements Mcu_ClockType_typedef
*/
typedef uint32 Mcu_ClockType;
#endif

/**
* @brief   This type specifies the mcu mode.
*/
typedef uint32 Mcu_ModeType;

/**@} end of group MCU_Typedef */

/** @defgroup MCU_Structure
  @{
*/

/**
* @brief   The configuration structure of a RAM section.
*/
typedef struct
{
    VAR(Mcu_RamSectionType, MCU_VAR) mcuRamSectorId;
    VAR(uint8, MCU_VAR) (*mcuRamSectionBaseAddress)[1U];
    VAR(Mcu_RamSecSizeType, MCU_VAR) mcuRamSectionSize;
    VAR(uint64, MCU_VAR) mcuRamDefaultValue; 
    VAR(Mcu_RamWrtSecSizeType, MCU_VAR) mcuRamSectionWriteSize;
} Mcu_RamConfigType;


/**
* @brief    This structure contains the data used to initialize the MCU.
*/
typedef struct
{
    CONST(Mcu_Pmu_CfgType, MCU_CONST) * mcuPmuCfg;  //!< mcu pmu module config
    CONST(Mcu_Sysc_CfgTypes, MCU_CONST) * mcuSyscCfg;  //!< mcu sysc module config
    CONST(Mcu_Rcm_ConfigType, MCU_CONST) * mcuRcmCfg;  //!< mcu rcm module config
    CONST(Mcu_DbgMcu_CfgTypes, MCU_CONST) * mcuDbgMcuCfg;  //!< mcu dbgmcu module config
    CONST(Mcu_RamConfigType, MCU_CONST) (*Mcu_RamCfg)[MCU_MAXRAMCONFIGS_COUNT];    //!< Configuration of RAM data
#if (MCU_INITCLK_ENABLED == STD_ON)
    CONST(Mcu_Rcm_SysClockCfgType, MCU_CONST) (*Mcu_ClockCfg)[MCU_MAX_CLK_CONFIGS_COUNT];    //!< Configuration of clock
#endif
#if (MCU_CMU_MODE_ENABLE == STD_ON)
    CONST(Mcu_Cmu_ConfigType, MCU_CONST) (*McuCmuCfg)[MCU_MAX_CMU_CONFIGS_COUNT];    //!< Configuration of cmu
#endif
} Mcu_ConfigType;

/**@} end of group MCU_Structure */
/*******************************************************************************
                             CONSTANT DEFINITION
*******************************************************************************/
#define MCU_START_SEC_CONFIG_DATA_UNSPECIFIED
#include "Mcu_MemMap.h"

/** @defgroup MCU_Variable
  @{
*/

extern const Mcu_ConfigType g_mcuConfig;

/**@} end of group MCU_Variable */

#define MCU_STOP_SEC_CONFIG_DATA_UNSPECIFIED
#include "Mcu_MemMap.h"
/*******************************************************************************
                            FUNCTION DECLARATION
*******************************************************************************/
#define MCU_START_SEC_CODE
#include "Mcu_MemMap.h"

/** @defgroup MCU_Fuctions
  @{
*/

FUNC(void, MCU_CODE) Mcu_Init(const Mcu_ConfigType * ConfigPtr);
FUNC(void, MCU_CODE) Mcu_SetMode(const Mcu_ModeType McuMode);

#if (MCU_VERSINFO_API == STD_ON)
FUNC(void, MCU_CODE) Mcu_GetVersionInfo(P2VAR(Std_VersionInfoType, AUTOMATIC, MCU_APPL_DATA) VersionInfo);
#endif

#if (MCU_INITCLK_ENABLED == STD_ON)
FUNC(Std_ReturnType, MCU_CODE) Mcu_InitClock(Mcu_ClockType ClockSetting);
#endif

FUNC(Mcu_RawResetType, MCU_CODE) Mcu_GetResetRawValue(void);
FUNC(Mcu_PllStatusType, MCU_CODE) Mcu_GetPllStatus(void);

#if (MCU_PLL_NONE == STD_ON)
FUNC(Std_ReturnType, MCU_CODE) Mcu_DistributePllClock(void);
#endif

#if (MCU_PERRST_API == STD_ON)
FUNC(void, MCU_CODE) Mcu_PerformReset(void);
#endif

FUNC(Std_ReturnType, MCU_CODE) Mcu_InitRamSection(VAR(Mcu_RamSectionType, AUTOMATIC) RamSection);

#if (MCU_GET_RAM_STATE_API == STD_ON)
FUNC( Mcu_RamStateType, MCU_CODE) Mcu_GetRamState(VAR( void, AUTOMATIC));
#endif

#if (MCU_CMU_MODE_ENABLE == STD_ON)
FUNC(void, MCU_CODE) Mcu_ClockMeasurement(uint32 cmuCfgCount);
FUNC(uint16, MCU_CODE) Mcu_GetMeasValue(uint32 cmuCfgCount);
#endif

/**@} end of group MCU_Fuctions */

#define MCU_STOP_SEC_CODE
#include "Mcu_MemMap.h"

#ifdef __cplusplus
}
#endif

#endif

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