/**********************************************************************************************************************
 *  COPYRIGHT
 *  -------------------------------------------------------------------------------------------------------------------
 *  \verbatim
 *
 *                 TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
 *
 *                 Property of Texas Instruments, Unauthorized reproduction and/or distribution
 *                 is strictly prohibited.  This product  is  protected  under  copyright  law
 *                 and  trade  secret law as an  unpublished work.
 *                 (C) Copyright Texas Instruments - 2016.  All rights reserved.
 *
 *  \endverbatim
 *  -------------------------------------------------------------------------------------------------------------------
 *  FILE DESCRIPTION
 *  -------------------------------------------------------------------------------------------------------------------
 *  File   :   Mcu.h
 *  Project:   Tms570_AutosarMcuDriver
 *  Module:    Mcu
 *  Generator: None
 *  Description:
 *  The Mcu Driver provides services for basic microcontroller initialization,
 *  power down functionality, reset and microcontroller specific functions
 *  required from other MCAL software modules.
 *
 *---------------------------------------------------------------------------------------------------------------------
 * Author:  Enrique Lizarraga
 *---------------------------------------------------------------------------------------------------------------------
 * Revision History
 *---------------------------------------------------------------------------------------------------------------------
 * Version        Date         Author               Change ID        Description
 *---------------------------------------------------------------------------------------------------------------------
 * 02.10.00       05Feb2013    Enrique Lizarraga    0000000000000    - Based on TMS570LS3 (01.10.00)
 * 02.20.00       08Aug2013    Enrique Lizarraga    SDOCM00103171    - Updated version info
 *                                                                   - Traceability comments
 *                                                                   - Mcu_DistributePllClock defined if MCU_NO_PLL is
 *                                                                     OFF
 *                                                                   - Mcu_RegisterReadback API added
 * 02.21.00       30Sep2014    Enrique Lizarraga    SDOCM00112263    - Updated version info
 *                                                                   - Added traceability info
 *                                                                   - Updated Mcu_GetRamState(dummy) to report DET
 *                                                                     error if called before initialization
 *                                                                    -Added MCU_NO_ERROR value to provide an initial
 *                                                                     value to Safety Error
 * 02.21.01       26Feb2016    Enrique Lizarraga    SDOCM00115297     -Updated version info
 * 02.30.00       01Dec2016    Sudhakar Singh         None            -Update version info
 * 05.30.00       15Mar2017    Sudhakar Singh       SDOCM00122834      Version supports TMS570LSxx Family of Devices.
 *********************************************************************************************************************/
/* Protection against multiple inclusion */
#ifndef MCU_H
#define MCU_H

/*********************************************************************************************************************
 * Standard Header Files
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_018 */
/* DesignId : MCU_DesignId_015 */
/* Requirements : AR_MCU_SR33 */
#include "Std_Types.h"

/*********************************************************************************************************************
 * Other Header Files
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_005 */
/* DesignId : MCU_DesignId_001 */
/* Requirements : AR_MCU_SR2 */
#include "Mcu_Cfg.h"

/*********************************************************************************************************************
 * Version Check (if required)
 *********************************************************************************************************************/
/*
 * TI TMS570 Autosar MCU Driver Version
 * Version format Major.Minor.Patch
 *                    02.21.01
 */

/* Component Version Information */
#define MCU_SW_MAJOR_VERSION               (5U)
#define MCU_SW_MINOR_VERSION               (30U)
#define MCU_SW_PATCH_VERSION               (0U)

/* SourceId : MCU_SourceId_019 */
/* Requirements : AR_MCU_SR15 */
/* AUTOSAR Software Specification Version Information */
#define MCU_AR_RELEASE_MAJOR_VERSION      (0x04U)
#define MCU_AR_RELEASE_MINOR_VERSION      (0x00U)
#define MCU_AR_RELEASE_REVISION_VERSION   (0x03U)

/* vendor and module identification */
#define MCU_VENDOR_ID     (44U)  /* TI */
#define MCU_MODULE_ID     ((uint16)101U)
#define MCU_INSTANCE_ID   ((uint8)0U)

/* AUTOSAR Software Specification Version Information */
#define MCU_AR_MAJOR_VERSION   (0x03U)
#define MCU_AR_MINOR_VERSION   (0x02U)
#define MCU_AR_PATCH_VERSION   (0x00U)

/*********************************************************************************************************************
 * Exported Preprocessor #define Constants
 *********************************************************************************************************************/
/* MCU module API IDs for Development Error Tracing (DET) */
#define MCU_API_INIT                   ((uint8)0x00U)
#define MCU_API_INIT_RAMSECTION        ((uint8)0x01U)
#define MCU_API_INIT_CLOCK             ((uint8)0x02U)
#define MCU_API_DISTRIBUTE_PLL_CLOCK   ((uint8)0x03U)
#define MCU_API_GET_PLL_STATUS         ((uint8)0x04U)
#define MCU_API_GET_RESET_REASON       ((uint8)0x05U)
#define MCU_API_GET_RESET_RAW_VALUE    ((uint8)0x06U)
#define MCU_API_PERFORM_RESET          ((uint8)0x07U)
#define MCU_API_SET_MODE               ((uint8)0x08U)
#define MCU_API_GET_VERSION_INFO       ((uint8)0x09U)
#define MCU_API_GET_RAM_STATE          ((uint8)0x0AU)

/* SourceId : MCU_SourceId_020 */
/* DesignId : MCU_DesignId_007 */
/* Requirements : AR_MCU_SR17, AR_MCU_SR18 */
/* Error Codes in Development Mode */
#ifndef MCU_E_PARAM_CONFIG
#define MCU_E_PARAM_CONFIG       ((uint8)0x0AU)
#endif
#ifndef MCU_E_PARAM_CLOCK
#define MCU_E_PARAM_CLOCK        ((uint8)0x0BU)
#endif
#ifndef MCU_E_PARAM_MODE
#define MCU_E_PARAM_MODE         ((uint8)0x0CU)
#endif
#ifndef MCU_E_PARAM_RAMSECTION
#define MCU_E_PARAM_RAMSECTION   ((uint8)0x0DU)
#endif
#ifndef MCU_E_PLL_NOT_LOCKED
#define MCU_E_PLL_NOT_LOCKED     ((uint8)0x0EU)
#endif
#ifndef MCU_E_UNINIT
#define MCU_E_UNINIT             ((uint8)0x0FU)
#endif
#ifndef MCU_E_PARAM_POINTER
#define MCU_E_PARAM_POINTER      ((uint8)0x10U)
#endif

/* SourceId : MCU_SourceId_021 */
/* DesignId : MCU_DesignId_006 */
/* Requirements : AR_MCU_SR14 */
/* MCU Power Modes */
#define MCU_DOZE_MODE     ((uint8)0U)
#define MCU_SNOOZE_MODE   ((uint8)1U)
#define MCU_SLEEP_MODE    ((uint8)2U)

/*********************************************************************************************************************
 * Exported Preprocessor #define Macros
 *********************************************************************************************************************/

/*********************************************************************************************************************
 * Exported Type Declarations
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_022 */
/* DesignId : MCU_DesignId_016 */
/* Requirements : AR_MCU_SR41, AR_MCU_SR42 */
typedef uint8   Mcu_ClockType;
/* SourceId : MCU_SourceId_023 */
/* DesignId : MCU_DesignId_016 */
/* Requirements : AR_MCU_SR45, AR_MCU_SR46 */
typedef uint32  Mcu_RawResetType;
/* SourceId : MCU_SourceId_024 */
/* DesignId : MCU_DesignId_016 */
/* Requirements : AR_MCU_SR49, AR_MCU_SR50 */
typedef uint8   Mcu_RamSectionType;
/* SourceId : MCU_SourceId_025 */
/* DesignId : MCU_DesignId_016 */
/* Requirements : AR_MCU_SR47, AR_MCU_SR48 */
typedef uint8   Mcu_ModeType;

/* SourceId : MCU_SourceId_026 */
/* DesignId : MCU_DesignId_016 */
/* Requirements : AR_MCU_SR43, AR_MCU_SR44 */
typedef enum
{
   MCU_POWER_ON_RESET = 0,   /* Power On reset */
   MCU_WATCHDOG_RESET,       /* Watchdog reset */
   MCU_ICEPICK_RESET,        /* Debug reset */
   MCU_OSCILLATOR_RESET,     /* Oscillator failure or PLL cycle slip reset */
   MCU_CPU_RESET,            /* CPU reset */
   MCU_SOFTWARE_RESET,       /* Software reset */
   MCU_EXTERNAL_RESET,       /* External reset */
   MCU_RESET_UNDEFINED       /* Undefined reset */
}Mcu_ResetType;

/* SourceId : MCU_SourceId_027 */
/* DesignId : MCU_DesignId_016 */
/* Requirements : AR_MCU_SR39, AR_MCU_SR40 */
typedef enum
{
   MCU_PLL_LOCKED = 0,
   MCU_PLL_UNLOCKED,
   MCU_PLL_STATUS_UNDEFINED
}Mcu_PllStatusType;

/* SourceId : MCU_SourceId_028 */
/* DesignId : MCU_DesignId_016 */
/* Requirements : AR_MCU_SR51 */
typedef enum
{
   MCU_RAMSTATE_INVALID,
   MCU_RAMSTATE_VALID
}Mcu_RamStateType;

typedef enum
{
   MCU_NO_ERROR,
   MCU_ESM_GROUP3_ERROR,
   MCU_EFC_ERROR,
   MCU_STC_SELF_CHECK_ERROR,
   MCU_STC_ERROR,
   MCU_PBIST_SELF_CHECK_ERROR,
   MCU_PBIST_ERROR
}Mcu_SafetyInitErrorType;

typedef struct
{
   uint32 Mcu_CsDis;        /* Clock Source Disable Register */
   uint32 Mcu_CdDis;        /* Clock Domain Disable Register */
   uint32 Mcu_GhvSrc;       /* GCLK, HCLK, VCLK, and VCLK2 Source Register */
   uint32 Mcu_VclkASrc;     /* Peripheral Asynchronous Clock Source Register */
   uint32 Mcu_RclkSrc;      /* RTI Clock Source Register */
   uint32 Mcu_PllCtl1;      /* PLL Control Register 1 */
   uint32 Mcu_PllCtl2;      /* PLL Control Register 2 */
   uint32 Mcu_LpoMonCtl;    /* LPO/Clock Monitor Control Register */
   uint32 Mcu_ClkCntrl;     /* Clock Control Register */
   uint32 Mcu_PllCtl3;      /* PLL Control Register 3 */
   uint32 Mcu_Clk2Cntrl;    /* Clock 2 Control Register */
   uint32 Mcu_VclkACon1;    /* Peripheral Asynchronous Clock Configuration 1 Register */
   uint32 Mcu_PsPwrDwnClr0; /* Peripheral Power-Down Clear Register 0 */
   uint32 Mcu_PsPwrDwnClr1; /* Peripheral Power-Down Clear Register 1 */
   uint32 Mcu_PsPwrDwnClr2; /* Peripheral Power-Down Clear Register 2 */
   uint32 Mcu_PsPwrDwnClr3; /* Peripheral Power-Down Clear Register 3 */
   uint32 Mcu_FrdCntl;      /* Flash Option Control Register */
   uint32 Mcu_FbFallBack;   /* Flash Bank Fallback Power Register */
   uint32 Mcu_EeCfg;        /* EEPROM Emulation Configuration Register */
}Mcu_RegisterReadbackType;

/*********************************************************************************************************************
 *  Exported Object Declarations
 *********************************************************************************************************************/


/*********************************************************************************************************************
 *  Exported Function Prototypes
 *********************************************************************************************************************/
FUNC(void, MCU_CODE) Mcu_Init(P2CONST(Mcu_ConfigType, AUTOMATIC, MCU_PBCFG) ConfigPtr);

#if(STD_ON == MCU_INIT_RAM_API)
FUNC(Std_ReturnType, MCU_CODE) Mcu_InitRamSection(Mcu_RamSectionType RamSection);
#endif /* MCU_INIT_RAM_API */

#if(STD_ON == MCU_INIT_CLOCK_API)
FUNC(Std_ReturnType, MCU_CODE) Mcu_InitClock(Mcu_ClockType ClockSetting);
#endif /* MCU_INIT_CLOCK_API */

FUNC(void, MCU_CODE) Mcu_SetMode(Mcu_ModeType McuMode);

#if(STD_OFF == MCU_NO_PLL)
FUNC(void, MCU_CODE) Mcu_DistributePllClock (void);
#endif /* MCU_NO_PLL */

#if (STD_ON == MCU_PERFORM_RESET_API)
FUNC(void, MCU_CODE) Mcu_PerformReset(void);
#endif /* MCU_PERFORM_RESET_API */

FUNC(Mcu_PllStatusType, MCU_CODE) Mcu_GetPllStatus(void);

FUNC(Mcu_ResetType, MCU_CODE) Mcu_GetResetReason(void);

FUNC(Mcu_RawResetType, MCU_CODE) Mcu_GetResetRawValue(void);

#if (STD_ON == MCU_CLEAR_RESET_REASON_API)
FUNC(void, MCU_CODE) Mcu_ClearResetReason(void);
#endif /* MCU_CLEAR_RESET_REASON_API */

#if(STD_ON == MCU_GET_RAM_STATE_API)
FUNC(Mcu_RamStateType,  MCU_CODE) Mcu_GetRamState(void);
#endif /* MCU_GET_RAM_STATE_API */

#if (STD_ON == MCU_GET_VERSION_INFO_API)
FUNC(void, MCU_CODE) Mcu_GetVersionInfo(P2VAR(Std_VersionInfoType, AUTOMATIC, MCU_APPL_DATA) versioninfo);
#endif /* MCU_GET_VERSION_INFO_API */

#if (STD_ON == MCU_REGISTER_READBACK_API)
FUNC(Std_ReturnType, MCU_CODE) Mcu_RegisterReadback
   (
      P2VAR(Mcu_RegisterReadbackType, AUTOMATIC, MCU_APPL_DATA) RegisterReadbackPtr
   );
#endif

#if((0x00000000U != DUAL_PORT_RAM_GROUP_PBIST)   ||  \
    (0x00000000U != SINGLE_PORT_RAM_GROUP_PBIST) ||  \
    (STD_ON == MCU_PBIST_SELFTEST)               ||  \
    (STD_ON == MCU_CPU_SELFTEST)                 ||  \
    (STD_ON == MCU_ESM_GROUP3_CHECK)             ||  \
    (STD_ON == MCU_EFUSE_SELF_TEST))
FUNC(void, MCU_CODE) Mcu_SafetyInitErrorCbk(Mcu_SafetyInitErrorType SafetyInitError);
#endif

/*********************************************************************************************************************
 *  Exported Inline Function Definitions and Function-Like Macros
 *********************************************************************************************************************/

#endif /* MCU_H */
/*********************************************************************************************************************
 *  End of File: Mcu.h
 *********************************************************************************************************************/
