/**********************************************************************************************************************
 *  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.c
 *  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       01Aug2013    Enrique Lizarraga      SDOCM00103171   -Updated version info
 *                                                                    -Traceability comments
 *                                                                    -Dem.h inclusion
 *                                                                    -Removed bitfields
 *                                                                    -Created local API's Mcu_PbistEnable,
 *                                                                     Mcu_PbistDisable, Mcu_EnterDozeMode,
 *                                                                     Mcu_EnterSnoozeMode and Mcu_EnterSleepMode to
 *                                                                     provide better modularity.
 *                                                                    -Removed Mcu_ConfigRamSetting variable
 *                                                                    -Moved some code from Mcu_StcResetHandler to
 *                                                                     Mcu_CpuSelfTest for higher cohesion.
 *                                                                    -MCU_E_CLOCK_FAILURE definition (not used)
 *                                                                    -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
 *                                                                    -Removed MCU_DEM_ERROR_DETECT macro
 *                                                                    -Relocated Enter/Exit critical section macros
 *                                                                    -Add conditional compiling to remove all PLL
 *                                                                     related code when MCU_NO_PLL is set to true
 *                                                                    -Disable clock monitoring when entering LPM
 *                                                                    -Updated Mcu_GetRamState(dummy) to report DET
 *                                                                     error if called before initialization
 *                                                                    -Removed interrupt restoration when exiting
 *                                                                     LPM (handled by upper layer)
 *                                                                    -Remove Mcu_MemoryInit declaration when no
 *                                                                     peripheral memory initialization is selected
 *                                                                    -Remove unused code
 * 02.21.01       26Feb2016    Enrique Lizarraga    SDOCM00115297     -Updated version info
 *                                                                    -Avoid VCKLR being cleared when writing VCLK2R
 *                                                  SDOCM00121367     -Modified Mcu_InitClock to avoid compiler remark
 *                                                                     with DET disabled
 *                                                                    -Updated MISRA justifications to APPROVED
 * 02.30.00       01Dec2016    Sudhakar Singh         None            -Update version info
 * 05.30.00       15Mar2017    Sudhakar Singh       SDOCM00122834      Version supports TMS570LSxx Family of Devices.
 *********************************************************************************************************************/
#define MCU_SOURCE

/**********************************************************************************************************************
 * Standard Header Files
 *********************************************************************************************************************/

/*********************************************************************************************************************
 * Other Header Files
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_001 */
/* DesignId : MCU_DesignId_001 */
/* Requirements : AR_MCU_SR1 */
#include "Mcu.h"
#include "SchM_Mcu.h"
/* SourceId : MCU_SourceId_002 */
/* DesignId : MCU_DesignId_018 */
/* Requirements : AR_MCU_SR101 */
#if (STD_ON == MCU_DEV_ERROR_DETECT)
#include "Det.h"
#endif
/* SourceId : MCU_SourceId_003 */
/* DesignId : MCU_DesignId_001, MCU_DesignId_015 */
/* Requirements : AR_MCU_SR8, AR_MCU_SR33, AR_MCU_SR100 */
#include "Dem.h"

/*********************************************************************************************************************
 * Version Check
 *********************************************************************************************************************/
#define MCU_CFG_C_MAJOR_VERSION               (5U)
#define MCU_CFG_C_MINOR_VERSION               (30U)
#define MCU_CFG_C_PATCH_VERSION               (0U)
 
 /* SourceId : MCU_SourceId_004 */
/* Requirements : AR_MCU_SR15 */
/* AUTOSAR version information check has to match definition in header file */
#if (  (MCU_AR_RELEASE_MAJOR_VERSION    != (0x04U)) \
    || (MCU_AR_RELEASE_MINOR_VERSION    != (0x00U)) \
    || (MCU_AR_RELEASE_REVISION_VERSION != (0x03U)) )
  #error "MCU: AUTOSAR Version Numbers of MCU are different"
#endif

/* vendor specific version information is BCD coded */
#if ((MCU_SW_MAJOR_VERSION != MCU_CFG_C_MAJOR_VERSION) || \
     (MCU_SW_MINOR_VERSION != MCU_CFG_C_MINOR_VERSION))
  #error "Version numbers of Mcu.c and Mcu.h are inconsistent!"
#endif

#if( (MCU_CFG_MAJOR_VERSION != MCU_CFG_C_MAJOR_VERSION) || \
     (MCU_CFG_MINOR_VERSION != MCU_CFG_C_MINOR_VERSION))
   #error "Version numbers of Mcu.c and Mcu_Cfg.h are inconsistent!"
#endif

/*********************************************************************************************************************
 * Local Preprocessor #define Constants
 *********************************************************************************************************************/
/* Primary System Control Registers Base Address */
#define MCU_SYS1_REG_BASE       ((P2VAR(Mcu_Sys1RegisterType,  MCU_CONST, REGSPACE))0xFFFFFF00U)
/* Secondary System Control Registers Base Address */
#define MCU_SYS2_REG_BASE       ((P2VAR(Mcu_Sys2RegisterType,  MCU_CONST, REGSPACE))0xFFFFE100U)
/* Flash Control Registers Base Address */
#define MCU_FLS_REG_BASE        ((P2VAR(Mcu_FlsRegisterType,   MCU_CONST, REGSPACE))0xFFF87000U)
/* CPU Self-Test Controller Control Registers Base Address */
#define MCU_STC_REG_BASE        ((P2VAR(Mcu_StcRegisterType,   MCU_CONST, REGSPACE))0xFFFFE600U)
/* Error Signaling Module Control Registers Base Address */
#define MCU_ESM_REG_BASE        ((P2VAR(Mcu_EsmRegisterType,   MCU_CONST, REGSPACE))0xFFFFF500U)
/* EFUSE Controller Control Registers Base Address */
#define MCU_EFC_REG_BASE        ((P2VAR(Mcu_EfcRegisterType,   MCU_CONST, REGSPACE))0xFFF8C000U)
/* Peripheral Central Resource Control Registers Base Address */
#define MCU_PCR_REG_BASE        ((P2VAR(Mcu_PcrRegisterType,   MCU_CONST, REGSPACE))0xFFFFE000U)
/* Real-Time Interrupt Module Control Registers Base Address */
#define MCU_RTI_REG_BASE        ((P2VAR(Mcu_RtiRegisterType,   MCU_CONST, REGSPACE))0xFFFFFC00U)
/* Programmable Built-In Self-Test Module Control Registers Base Address */
#define MCU_PBIST_REG_BASE      ((P2VAR(Mcu_PbistRegisterType, MCU_CONST, REGSPACE))0xFFFFE560U)
/* FSM Register Write Enable (To setup flash bank 7) */
#define MCU_FSM_WR_ENA          (*(volatile P2VAR(uint32, MCU_CONST, REGSPACE))0xFFF87288U)
/* EEPROM Emulation Configuration Register */
#define EEPROM_CONFIG           (*(volatile P2VAR(uint32, MCU_CONST, REGSPACE))0xFFF872B8U)

/* Initial LPO Trim Value */
#define MCU_OTP_TRIM            ((*(volatile P2VAR(uint32, MCU_CONST, REGSPACE))0xF00801B4U)>>16U)

/* Reset Reason Masks */
#define MCU_EMPTYRST_MASK       ((Mcu_RawResetType)0x00000000U)
#define MCU_PORST_MASK          ((Mcu_RawResetType)0x00008000U)
#define MCU_OSCRST_MASK         ((Mcu_RawResetType)0x00004000U)
#define MCU_WDRST_MASK          ((Mcu_RawResetType)0x00002000U)
#define MCU_CPURST_MASK         ((Mcu_RawResetType)0x00000020U)
#define MCU_SWRST_MASK          ((Mcu_RawResetType)0x00000010U)
#define MCU_EXTRST_MASK         ((Mcu_RawResetType)0x00000008U)
#define MCU_ERRORRST_MASK       ((Mcu_RawResetType)0xFFFF0000U)
#define MCU_CLRRST_MASK         ((Mcu_RawResetType)0x0000FFFEU)

/* Software Reset Mask */
#define MCU_PERFORM_RESET_MASK  ((uint32)0x00008000U)

/* Mask of the bias enable in the LPOMONCTL register */
#define MCU_BIAS_ENABLE         ((uint32)0x01000000U)

/* EFC Definitions */
#define EFC_AUTOLOAD_ERROR_EN    ((uint32)0x00040000U)
#define EFC_INSTRUCTION_ERROR_EN ((uint32)0x00080000U)
#define EFC_INSTRUCTION_INFO_EN  ((uint32)0x00100000U)
#define EFC_SELF_TEST_ERROR_EN   ((uint32)0x00200000U)
#define OUTPUT_ENABLE            ((uint32)0x0003C000U)
#define OUTPUT_DISABLE           ((uint32)0x00000000U)
#define EFC_SELF_TEST_ERROR      ((uint32)0x00004000U)
#define EFC_SELF_TEST_DONE       ((uint32)0x00008000U)
#define SELF_TEST_ERROR          ((uint32)0x18U)

/* Set Mode Masks */
/* This mask is used to disable all the clock sources */
#define MCU_CLRALL_CLKSRC       ((uint32)0x000000FBU)
/* This mask is used to clear the clock domains */
#define MCU_CLRALL_CLKDM        ((uint32)0x0000097FU)
/* This mask is used to clear the clock domains in Doze Mode */
#define MCU_CLRALL_DZCLKDM      ((uint32)0x0000093BU)
/* This mask is used to clear the RTICLK1 clock domain */
#define MCU_CLR_RTICLK1         ((uint32)0x00000040U)
/* This mask is used to clear the VCLK2 clock domain */
#define MCU_CLR_VCLK2           ((uint32)0x00000008U)
/* This mask is used to clear the PLLs bit during the Clock Valid check */
#define MCU_CLR_PLLS            ((uint32)0x00000002U)
/* This mask is used to clear the Low Frequency LPO bit during the Clock Valid check */
#define MCU_CLR_LF              ((uint32)0x00000010U)
/* This mask is used to clear the main oscillator bit during the Clock Valid check */
#define MCU_CLR_MAIN_OSC        ((uint32)0x00000001U)

/* This masks are used to check PLL status */
#define MCU_PLL1_SOURCE         ((uint32)0x00000002U)
#define MCU_PLL2_SOURCE         ((uint32)0x00000040U)
#define MCU_MAX_PLL_DIV         ((uint32)0x1FU)

/* Peripheral Enable Mask */
#define MCU_PENA                ((uint32)0x00000100U)

/* PLL Disable Mask */
#define MCU_PLL_DISABLE         ((uint32)0x00000042U)

/* GLBSTAT Clear Mask */
#define MCU_GLBSTAT_CLEAR       ((uint32)0x00000301U)

/* Bank Active Grace Period */
#define BANK_ACT_GRACE_PERIOD   ((uint32)0x00000700U)

/* VCLKR Clear Mask */
#define MCU_VCLKR_CLR_MASK      ((uint32)0xFFF0FFFFU)

/* VCLKR Set Mask */
#define MCU_VCLKR_SET_MASK      ((uint32)0x000F0000U)

/* VCLK2R Clear Mask */
#define MCU_VCLK2R_CLR_MASK     ((uint32)0xF0FFFFFFU)

/* VCLK2R Set Mask */
#define MCU_VCLK2R_SET_MASK     ((uint32)0x0F000000U)


/* Error Codes in Diagnostic Event Manager */
#ifndef MCU_E_CLOCK_FAILURE
#define MCU_E_CLOCK_FAILURE DemConf_DemEventParameter_MCU_E_CLOCK_FAILURE
#endif

/*********************************************************************************************************************
 * Local Preprocessor #define Macros
 *********************************************************************************************************************/
#define Mcu_GlobalSuspend()     SchM_Enter_Mcu_MCU_EXCLUSIVE_AREA_0()
#define Mcu_GlobalRestore()     SchM_Exit_Mcu_MCU_EXCLUSIVE_AREA_0()

/*********************************************************************************************************************
 * Local Type Declarations
 *********************************************************************************************************************/
/* Primary System Control Registers (SYS) */
typedef volatile struct Mcu_Sys1RegisterTag
{
   uint32 syspc1;                      /* 0x0000 */
   uint32 syspc2;                      /* 0x0004 */
   uint32 syspc3;                      /* 0x0008 */
   uint32 syspc4;                      /* 0x000C */
   uint32 syspc5;                      /* 0x0010 */
   uint32 syspc6;                      /* 0x0014 */
   uint32 syspc7;                      /* 0x0018 */
   uint32 syspc8;                      /* 0x001C */
   uint32 syspc9;                      /* 0x0020 */
   uint32 sswpll1;                     /* 0x0024 */
   uint32 sswpll2;                     /* 0x0028 */
   uint32 sswpll3;                     /* 0x002C */
   uint32 csdis;                       /* 0x0030 */
   uint32 csdisset;                    /* 0x0034 */
   uint32 csdisclr;                    /* 0x0038 */
   uint32 cddis;                       /* 0x003C */
   uint32 cddisset;                    /* 0x0040 */
   uint32 cddisclr;                    /* 0x0044 */
   uint32 ghvsrc;                      /* 0x0048 */
   uint32 vclkasrc;                    /* 0x004C */
   uint32 rclksrc;                     /* 0x0050 */
   uint32 csvstat;                     /* 0x0054 */
   uint32 mstgcr;                      /* 0x0058 */
   uint32 minitgcr;                    /* 0x005C */
   uint32 msinena;                     /* 0x0060 */
   uint32 mstfail;                     /* 0x0064 */
   uint32 mstcgstat;                   /* 0x0068 */
   uint32 ministat;                    /* 0x006C */
   uint32 pllctl1;                     /* 0x0070 */
   uint32 pllctl2;                     /* 0x0074 */
   uint32 syspc10;                     /* 0x0078 */
   uint32 dieidl;                      /* 0x007C */
   uint32 dieidh;                      /* 0x0080 */
   uint32 vrctl;                       /* 0x0084 */
   uint32 lpomonctl;                   /* 0x0088 */
   uint32 clktest;                     /* 0x008C */
   uint32 dftctrlreg1;                 /* 0x0090 */
   uint32 dftctrlreg2;                 /* 0x0094 */
   uint32 sys_unused_98;               /* 0x0098 */
   uint32 sys_unused_9C;               /* 0x009C */
   uint32 gpreg1;                      /* 0x00A0 */
   uint32 sys_unused_A4;               /* 0x00A4 */
   uint32 impfasts;                    /* 0x00A8 */
   uint32 impftadd;                    /* 0x00AC */
   uint32 ssisr1;                      /* 0x00B0 */
   uint32 ssisr2;                      /* 0x00B4 */
   uint32 ssisr3;                      /* 0x00B8 */
   uint32 ssisr4;                      /* 0x00BC */
   uint32 ramgcr;                      /* 0x00C0 */
   uint32 bmmcr1;                      /* 0x00C4 */
   uint32 sys_unused_C8;               /* 0x00C8 */
   uint32 cpurstcr;                    /* 0x00CC */
   uint32 clkcntrl;                    /* 0x00D0 */
   uint32 ecpcntl;                     /* 0x00D4 */
   uint32 sys_unused_D8;               /* 0x00D8 */
   uint32 devcr1;                      /* 0x00DC */
   uint32 sysecr;                      /* 0x00E0 */
   uint32 sysesr;                      /* 0x00E4 */
   uint32 systasr;                     /* 0x00E8 */
   uint32 glbstat;                     /* 0x00EC */
   uint32 devid;                       /* 0x00F0 */
   uint32 ssivec;                      /* 0x00F4 */
   uint32 ssif;                        /* 0x00F8 */
}Mcu_Sys1RegisterType;

/* Secondary System Control Registers (SYS2) */
typedef volatile struct Mcu_Sys2RegisterTag
{
   uint32 pllctl3;                     /* 0x0000 */
   uint32 sys2_unused_04;              /* 0x0004 */
   uint32 stcclkdiv;                   /* 0x0008 */
   uint32 sys2_unused_0C;              /* 0x000C */
   uint32 sys2_unused_10;              /* 0x0010 */
   uint32 sys2_unused_14;              /* 0x0014 */
   uint32 sys2_unused_18;              /* 0x0018 */
   uint32 sys2_unused_1C;              /* 0x001C */
   uint32 sys2_unused_20;              /* 0x0020 */
   uint32 sys2_unused_24;              /* 0x0024 */
   uint32 sys2_unused_28;              /* 0x0028 */
   uint32 sys2_unused_2C;              /* 0x002C */
   uint32 sys2_unused_30;              /* 0x0030 */
   uint32 sys2_unused_34;              /* 0x0034 */
   uint32 sys2_unused_38;              /* 0x0038 */
   uint32 clk2cntrl;                   /* 0x003C */
   uint32 vclkacon1;                   /* 0x0040 */
   uint32 sys2_unused_44;              /* 0x0044 */
   uint32 sys2_unused_48;              /* 0x0048 */
   uint32 sys2_unused_4C;              /* 0x004C */
   uint32 sys2_unused_50;              /* 0x0050 */
   uint32 sys2_unused_54;              /* 0x0054 */
   uint32 sys2_unused_58;              /* 0x0058 */
   uint32 sys2_unused_5C;              /* 0x005C */
   uint32 sys2_unused_60;              /* 0x0060 */
   uint32 sys2_unused_64;              /* 0x0064 */
   uint32 sys2_unused_68;              /* 0x0068 */
   uint32 sys2_unused_6C;              /* 0x006C */
   uint32 clkslip;                     /* 0x0070 */
   uint32 sys2_unused_74;              /* 0x0074 */
   uint32 sys2_unused_78;              /* 0x0078 */
   uint32 sys2_unused_7C;              /* 0x007C */
   uint32 sys2_unused_80;              /* 0x0080 */
   uint32 sys2_unused_84;              /* 0x0084 */
   uint32 sys2_unused_88;              /* 0x0088 */
   uint32 sys2_unused_8C;              /* 0x008C */
   uint32 sys2_unused_90;              /* 0x0090 */
   uint32 sys2_unused_94;              /* 0x0094 */
   uint32 sys2_unused_98;              /* 0x0098 */
   uint32 sys2_unused_9C;              /* 0x009C */
   uint32 sys2_unused_A0;              /* 0x00A0 */
   uint32 sys2_unused_A4;              /* 0x00A4 */
   uint32 sys2_unused_A8;              /* 0x00A8 */
   uint32 sys2_unused_AC;              /* 0x00AC */
   uint32 sys2_unused_B0;              /* 0x00B0 */
   uint32 sys2_unused_B4;              /* 0x00B4 */
   uint32 sys2_unused_B8;              /* 0x00B8 */
   uint32 sys2_unused_BC;              /* 0x00BC */
   uint32 sys2_unused_C0;              /* 0x00C0 */
   uint32 sys2_unused_C4;              /* 0x00C4 */
   uint32 sys2_unused_C8;              /* 0x00C8 */
   uint32 sys2_unused_CC;              /* 0x00CC */
   uint32 sys2_unused_D0;              /* 0x00D0 */
   uint32 sys2_unused_D4;              /* 0x00D4 */
   uint32 sys2_unused_D8;              /* 0x00D8 */
   uint32 sys2_unused_DC;              /* 0x00DC */
   uint32 sys2_unused_E0;              /* 0x00E0 */
   uint32 sys2_unused_E4;              /* 0x00E4 */
   uint32 sys2_unused_E8;              /* 0x00E8 */
   uint32 efc_ctlreg;                  /* 0x00EC */
   uint32 dieidl_reg0;                 /* 0x00F0 */
   uint32 dieidh_reg1;                 /* 0x00F4 */
   uint32 dieidl_reg2;                 /* 0x00F8 */
   uint32 dieidh_reg3;                 /* 0x00FC */
}Mcu_Sys2RegisterType;

/* Flash Control Registers (F021) */
typedef volatile struct Mcu_FlsRegisterTag
{
   uint32 frdcntl;                     /* 0x0000 */
   uint32 fsprd;                       /* 0x0004 */
   uint32 fedacctrl1;                  /* 0x0008 */
   uint32 fedacctrl2;                  /* 0x000C */
   uint32 fcorerrcnt;                  /* 0x0010 */
   uint32 fcorerradd;                  /* 0x0014 */
   uint32 fcorerrpos;                  /* 0x0018 */
   uint32 fedacstatus;                 /* 0x001C */
   uint32 funcerradd;                  /* 0x0020 */
   uint32 fedacsdis;                   /* 0x0024 */
   uint32 fprimaddtag;                 /* 0x0028 */
   uint32 freduaddtag;                 /* 0x002C */
   uint32 fbprot;                      /* 0x0030 */
   uint32 fbse;                        /* 0x0034 */
   uint32 fbbusy;                      /* 0x0038 */
   uint32 fbac;                        /* 0x003C */
   uint32 fbfallback;                  /* 0x0040 */
   uint32 fbprdy;                      /* 0x0044 */
   uint32 fpac1;                       /* 0x0048 */
   uint32 fpac2;                       /* 0x004C */
   uint32 fmac;                        /* 0x0050 */
   uint32 fmstat;                      /* 0x0054 */
   uint32 femudmsw;                    /* 0x0058 */
   uint32 femudlsw;                    /* 0x005C */
   uint32 femuecc;                     /* 0x0060 */
   uint32 flock;                       /* 0x0064 */
   uint32 femuaddr;                    /* 0x0068 */
   uint32 fdiagctrl;                   /* 0x006C */
   uint32 frawdatah;                   /* 0x0070 */
   uint32 frawdatal;                   /* 0x0074 */
   uint32 frawecc;                     /* 0x0078 */
   uint32 fparovr;                     /* 0x007C */
   uint32 fvreadct;                    /* 0x0080 */
   uint32 fvhvct1;                     /* 0x0084 */
   uint32 fvhvct2;                     /* 0x0088 */
   uint32 fvnvct;                      /* 0x008C */
   uint32 fvppct;                      /* 0x0090 */
   uint32 fvwlct;                      /* 0x0094 */
   uint32 fefuse;                      /* 0x0098 */
   uint32 fls_unused_9C;               /* 0x009C */
   uint32 fls_unused_A0;               /* 0x00A0 */
   uint32 fls_unused_A4;               /* 0x00A4 */
   uint32 fls_unused_A8;               /* 0x00A8 */
   uint32 fls_unused_AC;               /* 0x00AC */
   uint32 fls_unused_B0;               /* 0x00B0 */
   uint32 fls_unused_B4;               /* 0x00B4 */
   uint32 fls_unused_B8;               /* 0x00B8 */
   uint32 fls_unused_BC;               /* 0x00BC */
   uint32 fedacsdis2;                  /* 0x00C0 */
   uint32 fls_unused_C4;               /* 0x00C4 */
   uint32 fls_unused_C8;               /* 0x00C8 */
   uint32 fls_unused_CC;               /* 0x00CC */
   uint32 fls_unused_D0;               /* 0x00D0 */
   uint32 fls_unused_D4;               /* 0x00D4 */
   uint32 fls_unused_D8;               /* 0x00D8 */
   uint32 fls_unused_DC;               /* 0x00DC */
   uint32 fls_unused_E0;               /* 0x00E0 */
   uint32 fls_unused_E4;               /* 0x00E4 */
   uint32 fls_unused_E8;               /* 0x00E8 */
   uint32 fls_unused_EC;               /* 0x00EC */
   uint32 fls_unused_F0;               /* 0x00F0 */
   uint32 fls_unused_F4;               /* 0x00F4 */
   uint32 fls_unused_F8;               /* 0x00F8 */
   uint32 fls_unused_FC;               /* 0x00FC */
   uint32 fbstrobes;                   /* 0x0100 */
   uint32 fpstrobes;                   /* 0x0104 */
   uint32 fbmode;                      /* 0x0108 */
   uint32 ftcr;                        /* 0x010C */
   uint32 faddr;                       /* 0x0110 */
   uint32 fwrite;                      /* 0x0114 */
   uint32 fcbitsel;                    /* 0x0118 */
   uint32 ftctrl;                      /* 0x011C */
   uint32 fwpwrite0;                   /* 0x0120 */
   uint32 fwpwrite1;                   /* 0x0124 */
   uint32 fwpwrite2;                   /* 0x0128 */
   uint32 fwpwrite3;                   /* 0x012C */
   uint32 fwpwrite4;                   /* 0x0130 */
}Mcu_FlsRegisterType;

/* CPU Self-Test Controller Control Registers (STC)*/
typedef volatile struct Mcu_StcRegisterTag
{
   uint32 stcgcr0;                     /* 0x0000 */
   uint32 stcgcr1;                     /* 0x0004 */
   uint32 stctpr;                      /* 0x0008 */
   uint32 stccaddr;                    /* 0x000C */
   uint32 stccicr;                     /* 0x0010 */
   uint32 stcgstat;                    /* 0x0014 */
   uint32 stcfstat;                    /* 0x0018 */
   uint32 cpu1_curmisr3;               /* 0x001C */
   uint32 cpu1_curmisr2;               /* 0x0020 */
   uint32 cpu1_curmisr1;               /* 0x0024 */
   uint32 cpu1_curmisr0;               /* 0x0028 */
   uint32 cpu2_curmisr3;               /* 0x002C */
   uint32 cpu2_curmisr2;               /* 0x0030 */
   uint32 cpu2_curmisr1;               /* 0x0034 */
   uint32 cpu2_curmisr0;               /* 0x0038 */
   uint32 stcscscr;                    /* 0x003C */
}Mcu_StcRegisterType;

/* Error Signaling Module Control Registers (ESM) */
typedef volatile struct Mcu_EsmRegisterTag
{
   uint32 epenaset1;                   /* 0x0000 */
   uint32 epenaclr1;                   /* 0x0004 */
   uint32 intenaset1;                  /* 0x0008 */
   uint32 intenaclr1;                  /* 0x000C */
   uint32 intlvlset1;                  /* 0x0010 */
   uint32 intlvlclr1;                  /* 0x0014 */
   uint32 estatus1[3U];                /* 0x0018, 0x001C, 0x0020 */
   uint32 epstatus;                    /* 0x0024 */
   uint32 intoffh;                     /* 0x0028 */
   uint32 intoffl;                     /* 0x002C */
   uint32 ltc;                         /* 0x0030 */
   uint32 ltcpreload;                  /* 0x0034 */
   uint32 key;                         /* 0x0038 */
   uint32 estatus2emu;                 /* 0x003C */
   uint32 epenaset4;                   /* 0x0040 */
   uint32 epenaclr4;                   /* 0x0044 */
   uint32 intenaset4;                  /* 0x0048 */
   uint32 intenaclr4;                  /* 0x004C */
   uint32 intlvlset4;                  /* 0x0050 */
   uint32 intlvlclr4;                  /* 0x0054 */
   uint32 estatus4[3U];                /* 0x0058, 0x005C, 0x0060 */
   uint32 estatus5emu;                 /* 0x0064 */
}Mcu_EsmRegisterType;

/* EFUSE Control Registers (EFC) */
typedef volatile struct Mcu_EfcRegisterTag
{
   uint32 instruction;                 /* 0x0000 */
   uint32 address;                     /* 0x0004 */
   uint32 data_upper;                  /* 0x0008 */
   uint32 data_lower;                  /* 0x000C */
   uint32 system_config;               /* 0x0010 */
   uint32 system_status;               /* 0x0014 */
   uint32 accumulator;                 /* 0x0018 */
   uint32 boundary;                    /* 0x001C */
   uint32 key_flag;                    /* 0x0020 */
   uint32 key;                         /* 0x0024 */
   uint32 efc_unused_28;               /* 0x0028 */
   uint32 pins;                        /* 0x002C */
   uint32 cra;                         /* 0x0030 */
   uint32 read;                        /* 0x0034 */
   uint32 programme;                   /* 0x0038 */
   uint32 error;                       /* 0x003C */
   uint32 single_bit;                  /* 0x0040 */
   uint32 two_bit_error;               /* 0x0044 */
   uint32 self_test_cycles;            /* 0x0048 */
   uint32 self_test_sign;              /* 0x004C */
}Mcu_EfcRegisterType;

/* Peripheral Central Resource Control Registers (PCR) */
typedef volatile struct Mcu_PcrRegisterTag
{
   uint32 pmprotset0;                  /* 0x0000 */
   uint32 pmprotset1;                  /* 0x0004 */
   uint32 pcr_unused_08;               /* 0x0008 */
   uint32 pcr_unused_0C;               /* 0x000C */
   uint32 pmprotclr0;                  /* 0x0010 */
   uint32 pmprotclr1;                  /* 0x0014 */
   uint32 pcr_unused_18;               /* 0x0018 */
   uint32 pcr_unused_1C;               /* 0x001C */
   uint32 pprotset0;                   /* 0x0020 */
   uint32 pprotset1;                   /* 0x0024 */
   uint32 pprotset2;                   /* 0x0028 */
   uint32 pprotset3;                   /* 0x002C */
   uint32 pcr_unused_30;               /* 0x0030 */
   uint32 pcr_unused_34;               /* 0x0034 */
   uint32 pcr_unused_38;               /* 0x0038 */
   uint32 pcr_unused_3C;               /* 0x003C */
   uint32 pprotclr0;                   /* 0x0040 */
   uint32 pprotclr1;                   /* 0x0044 */
   uint32 pprotclr2;                   /* 0x0048 */
   uint32 pprotclr3;                   /* 0x004C */
   uint32 pcr_unused_50;               /* 0x0050 */
   uint32 pcr_unused_54;               /* 0x0054 */
   uint32 pcr_unused_58;               /* 0x0058 */
   uint32 pcr_unused_5C;               /* 0x005C */
   uint32 pcspwrdwnset0;               /* 0x0060 */
   uint32 pcspwrdwnset1;               /* 0x0064 */
   uint32 pcr_unused_68;               /* 0x0068 */
   uint32 pcr_unused_6C;               /* 0x006C */
   uint32 pcspwrdwnclr0;               /* 0x0070 */
   uint32 pcspwrdwnclr1;               /* 0x0074 */
   uint32 pcr_unused_78;               /* 0x0078 */
   uint32 pcr_unused_7C;               /* 0x007C */
   uint32 pspwrdwnset0;                /* 0x0080 */
   uint32 pspwrdwnset1;                /* 0x0084 */
   uint32 pspwrdwnset2;                /* 0x0088 */
   uint32 pspwrdwnset3;                /* 0x008C */
   uint32 pcr_unused_90;               /* 0x0090 */
   uint32 pcr_unused_94;               /* 0x0094 */
   uint32 pcr_unused_98;               /* 0x0098 */
   uint32 pcr_unused_9C;               /* 0x009C */
   uint32 pspwrdwnclr0;                /* 0x00A0 */
   uint32 pspwrdwnclr1;                /* 0x00A4 */
   uint32 pspwrdwnclr2;                /* 0x00A8 */
   uint32 pspwrdwnclr3;                /* 0x00AC */
} Mcu_PcrRegisterType;

/* Real-Time Interrupt Control Registers (RTI) */
typedef volatile struct Mcu_RtiRegisterTag
{
   uint32 gctrl;                       /* 0x0000 */
   uint32 tbctrl;                      /* 0x0004 */
   uint32 capctrl;                     /* 0x0008 */
   uint32 compctrl;                    /* 0x000C */
   struct
   {
      uint32 frcx;                     /* 0x0010,0x0030 */
      uint32 ucx;                      /* 0x0014,0x0034 */
      uint32 cpucx;                    /* 0x0018,0x0038 */
      uint32 rti_unused_1C_3C;         /* 0x001C,0x003C */
      uint32 cafrcx;                   /* 0x0020,0x0040 */
      uint32 caucx;                    /* 0x0024,0x0044 */
      uint32 rti_unused_28_48;         /* 0x0028,0x0048 */
      uint32 rti_unused_2C_4C;         /* 0x002C,0x004C */
   } cnt[2U]; /*
               * counter x selection:
               *   - 0: counter 0,
               *   - 1: counter 1
               */
   struct
   {
      uint32 compx;                    /* 0x0050,0x0058,0x0060,0x0068 */
      uint32 udcpx;                    /* 0x0054,0x005C,0x0064,0x006C */
   } cmp[4U]; /*
               * compare x selection:
               *  - 0: compare 0
               *  - 1: compare 1
               *  - 2: compare 2
               *  - 3: compare 3
               */
   uint32 tblcomp;                     /* 0x0070 */
   uint32 tbhcomp;                     /* 0x0074 */
   uint32 rti_unused_78;               /* 0x0078 */
   uint32 rti_unused_7C;               /* 0x007C */
   uint32 setint;                      /* 0x0080 */
   uint32 clearint;                    /* 0x0084 */
   uint32 intflag;                     /* 0x0088 */
   uint32 rti_unused_8C;               /* 0x008C */
   uint32 dwdctrl;                     /* 0x0090 */
   uint32 dwdprld;                     /* 0x0094 */
   uint32 wdstatus;                    /* 0x0098 */
   uint32 wdkey;                       /* 0x009C */
   uint32 dwdcntr;                     /* 0x00A0 */
   uint32 wwdrxnctrl;                  /* 0x00A4 */
   uint32 wwdsizectrl;                 /* 0x00A8 */
   uint32 intclrenable;                /* 0x00AC */
   uint32 comp0clr;                    /* 0x00B0 */
   uint32 comp1clr;                    /* 0x00B4 */
   uint32 comp2clr;                    /* 0x00B8 */
   uint32 comp3clr;                    /* 0x00BC */
}Mcu_RtiRegisterType;

/* Programmable Built-In Self Test Control Registers (PBIST) */
typedef volatile struct Mcu_PbistRegisterTag
{
   uint32 ramt;                        /* 0x0160 */
   uint32 dlr;                         /* 0x0164 */
   uint32 pbist_unused_168;            /* 0x0168 */
   uint32 pbist_unused_16C;            /* 0x016C */
   uint32 pbist_unused_170;            /* 0x0170 */
   uint32 pbist_unused_174;            /* 0x0174 */
   uint32 pbist_unused_178;            /* 0x0178 */
   uint32 pbist_unused_17C;            /* 0x017C */
   uint32 pact;                        /* 0x0180 */
   uint32 pbistid;                     /* 0x0184 */
   uint32 over;                        /* 0x0188 */
   uint32 pbist_unused_18C;            /* 0x018C */
   uint32 fsrf0;                       /* 0x0190 */
   uint32 fsrf1;                       /* 0x0194 */
   uint32 fsrc0;                       /* 0x0198 */
   uint32 fsrc1;                       /* 0x019C */
   uint32 fsra0;                       /* 0x01A0 */
   uint32 fsra1;                       /* 0x01A4 */
   uint32 fsrdl0;                      /* 0x01A8 */
   uint32 pbist_unused_1AC;            /* 0x01AC */
   uint32 fsrdl1;                      /* 0x01B0 */
   uint32 pbist_unused_1B4;            /* 0x01B4 */
   uint32 pbist_unused_1B8;            /* 0x01B8 */
   uint32 pbist_unused_1BC;            /* 0x01BC */
   uint32 rom;                         /* 0x01C0 */
   uint32 algo;                        /* 0x01C4 */
   uint32 rinfol;                      /* 0x01C8 */
   uint32 rinfou;                      /* 0x01CC */
} Mcu_PbistRegisterType;

/* PBIST Memory Test Algorithms */
typedef enum
{
   PBIST_TRIPLE_READ_SLOW      = 0x00000001U,
   PBIST_TRIPLE_READ_FAST      = 0x00000002U,
   PBIST_MARCH13N_DP           = 0x00000004U,
   PBIST_MARCH13N_SP           = 0x00000008U,
   PBIST_DOWN1A_DP             = 0x00000010U,
   PBIST_DOWN1A_SP             = 0x00000020U,
   PBIST_MAPCOLUMN_DP          = 0x00000040U,
   PBIST_MAPCOLUMN_SP          = 0x00000080U,
   PBIST_PRECHARGE_DP          = 0x00000100U,
   PBIST_PRECHARGE_SP          = 0x00000200U,
   PBIST_DTXN2A_DP             = 0x00000400U,
   PBIST_DTXN2A_SP             = 0x00000800U,
   PBIST_PMOS_OPEN_DP          = 0x00001000U,
   PBIST_PMOS_OPEN_SP          = 0x00002000U,
   PBIST_PPMOS_OPEN_SLICE_1_DP = 0x00004000U,
   PBIST_PPMOS_OPEN_SLICE_1_SP = 0x00008000U,
   PBIST_PPMOS_OPEN_SLICE_2_DP = 0x00010000U,
   PBIST_PPMOS_OPEN_SLICE_2_SP = 0x00020000U
}Mcu_PbistAlgoType;

/*********************************************************************************************************************
 * Exported Object Definitions
 *********************************************************************************************************************/

/*********************************************************************************************************************
 * Local Object Definitions
 *********************************************************************************************************************/
/* Memory mapping, done via MemMap.h Variables that are not initialized */
#define MCU_START_SEC_VAR_INIT_UNSPECIFIED
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Based on Autosar Memory Map strategy" */
#include "MemMap.h"
/* Pointer to the configuration*/
/*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Pointer initialized as NULL. This is set in Mcu_Init" */
/*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
static P2CONST(Mcu_ConfigType, MCU_DATA, MCU_PBCFG) Mcu_ConfigPtr_pt = NULL_PTR;

#define MCU_STOP_SEC_VAR_INIT_UNSPECIFIED
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Based on Autosar Memory Map strategy" */
#include "MemMap.h"

/*********************************************************************************************************************
 *  Local Function Prototypes
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_SystemInit1(void);
STATIC FUNC(void, MCU_CODE) Mcu_SystemInit2(void);
#if (STD_OFF == MCU_NO_PLL)
STATIC FUNC(void, MCU_CODE) Mcu_SetupPLL(void);
#endif /* STD_OFF == MCU_NO_PLL */
STATIC FUNC(void, MCU_CODE) Mcu_PeriphInit(void);
STATIC FUNC(void, MCU_CODE) Mcu_SetupFlash(void);
STATIC FUNC(void, MCU_CODE) Mcu_TrimLpo(void);
STATIC FUNC(void, MCU_CODE) Mcu_MapClocks(void);
#if (STD_ON == MCU_EFUSE_SELF_TEST)
STATIC FUNC(void, MCU_CODE) Mcu_EfcCheck(void);
STATIC FUNC(boolean, MCU_CODE) Mcu_EfcStuckZeroTest(void);
STATIC FUNC(void, MCU_CODE) Mcu_EfcSelfTest(void);
STATIC FUNC(boolean, MCU_CODE) Mcu_EfcCheckSelfTest(void);
#endif /* STD_ON == MCU_EFUSE_SELF_TEST */
#if(STD_ON == MCU_CPU_SELFTEST)
STATIC FUNC(void, MCU_CODE) Mcu_StcSelfCheck(void);
STATIC FUNC(void, MCU_CODE) Mcu_CpuSelfTest(void);
STATIC FUNC(boolean, MCU_CODE)Mcu_StcResetHandler(void);
#endif /* STD_ON == MCU_CPU_SELFTEST */
#if(STD_ON == MCU_PBIST_SELFTEST)
STATIC FUNC(void, MCU_CODE) Mcu_PbistSelfCheck(void);
#endif /* STD_ON == MCU_PBIST_SELFTEST */
#if(0x00000000U != PERIPHERAL_RAM_INIT)
STATIC FUNC(void, MCU_CODE) Mcu_MemoryInit(uint32 ram);
#endif /* 0x00000000U != PERIPHERAL_RAM_INIT */
#if((0x00000000U != DUAL_PORT_RAM_GROUP_PBIST)   ||  \
    (0x00000000U != SINGLE_PORT_RAM_GROUP_PBIST) ||  \
    (STD_ON == MCU_PBIST_SELFTEST))
STATIC FUNC(Std_ReturnType, MCU_CODE) Mcu_PbistRun(uint32 raminfoL, Mcu_PbistAlgoType algomask);
STATIC FUNC(void, MCU_CODE) Mcu_PbistEnable(void);
STATIC FUNC(void, MCU_CODE) Mcu_PbistDisable(void);
#endif
STATIC FUNC(void, MCU_CODE) Mcu_CpuIdle(void);
STATIC FUNC(void, MCU_CODE) Mcu_EnterDozeMode(void);
STATIC FUNC(void, MCU_CODE) Mcu_EnterSnoozeMode(void);
STATIC FUNC(void, MCU_CODE) Mcu_EnterSleepMode(void);
#if((0x00000000U != DUAL_PORT_RAM_GROUP_PBIST)   ||  \
    (0x00000000U != SINGLE_PORT_RAM_GROUP_PBIST) ||  \
    (STD_ON == MCU_PBIST_SELFTEST)               ||  \
    (STD_ON == MCU_CPU_SELFTEST))
STATIC FUNC(void, MCU_CODE) Mcu_WaitClockCycles(uint32 cycles);
#endif

/*********************************************************************************************************************
 *  External Functions Definition
 *********************************************************************************************************************/
#define MCU_START_SEC_CODE
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Based on Autosar Memory Map strategy" */
#include "MemMap.h"

#if (STD_ON == MCU_GET_VERSION_INFO_API)
/*********************************************************************************************************************
 * Function name:  Mcu_GetVersionInfo(Std_VersionInfoType* versioninfo)
 *********************************************************************************************************************/
/** \brief This service returns the version information of this module.
 *
 * This service returns the version information of this module.
 *
 * \param[in] None
 * \param[out] versioninfo - Pointer to where to store the version information of this module.
 * \pre None
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_006 */
/* DesignId : MCU_DesignId_008 */
/* Requirements : AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR92, AR_MCU_SR93, AR_MCU_SR96, AR_MCU_SR102 */
FUNC(void, MCU_CODE) Mcu_GetVersionInfo(Std_VersionInfoType* versioninfo)
{
#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == versioninfo)
   {
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_GET_VERSION_INFO, MCU_E_PARAM_POINTER);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
      versioninfo->vendorID         = (MCU_VENDOR_ID);
      versioninfo->moduleID         = (MCU_MODULE_ID);
      versioninfo->sw_major_version = (uint8)(MCU_SW_MAJOR_VERSION);
      versioninfo->sw_minor_version = (uint8)(MCU_SW_MINOR_VERSION);
      versioninfo->sw_patch_version = (uint8)(MCU_SW_PATCH_VERSION);
   }
}   /* Mcu_GetVersionInfo()*/
#endif  /* STD_ON == MCU_GET_VERSION_INFO_API */

/*********************************************************************************************************************
 * Function name:  Mcu_Init(const Mcu_ConfigType* ConfigPtr)
 *********************************************************************************************************************/
/** \brief This service initializes the MCU driver.
 *
 * Performs MCU general initialization, PLL setup and distribution, invokes STC and PBIST tests.
 *
 * \param[in] ConfigPtr - Pointer to MCU driver configuration set.
 * \param[out] None
 * \pre None
 * \post Global pointer Mcu_ConfigPtr_pt is set
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_007 */
/* DesignId : MCU_DesignId_005 */
/* Requirements : AR_MCU_SR12, AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR52, AR_MCU_SR53, AR_MCU_SR56,
 * AR_MCU_SR103, AR_MCU_SR111, AR_MCU_SR143, AR_MCU_SR150, AR_MCU_SR151, AR_MCU_SR152, AR_MCU_SR153, AR_MCU_SR154,
 * AR_MCU_SR155, AR_MCU_SR156, AR_MCU_SR157, AR_MCU_SR158, AR_MCU_SR159 */
FUNC(void, MCU_CODE) Mcu_Init(P2CONST(Mcu_ConfigType, AUTOMATIC, MCU_APPL_CONST)ConfigPtr)
{
#if (STD_ON == MCU_CPU_SELFTEST)
   Mcu_ResetType reset_reason;
   VAR(boolean, MCU_VAR) stc_completed = FALSE;
#endif /* STD_ON == MCU_CPU_SELFTEST */

#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == ConfigPtr)
   {
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID, MCU_API_INIT, MCU_E_PARAM_CONFIG);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
      /* Save the pointer to configuration */
      /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Pointer is checked for null if DET is enabled" */
      Mcu_ConfigPtr_pt = ConfigPtr;

#if(STD_ON == MCU_CPU_SELFTEST) /*INIT: 6*/
      /* Get the Reset reason */
      reset_reason = Mcu_GetResetReason();
      /* Last reset caused by CPU STC? */
      if(MCU_CPU_RESET == reset_reason)
      {
         stc_completed = Mcu_StcResetHandler();
      }
#endif /* STD_ON == MCU_CPU_SELFTEST */

#if(STD_ON == MCU_ESM_GROUP3_CHECK)
      /* Check for ESM Group3 errors (High severity CPU based diagnostics) */
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      if(0U != MCU_ESM_REG_BASE->estatus1[2]) /*INIT: 7*/
      {
         /* ESM Group3 error present */
         Mcu_SafetyInitErrorCbk(MCU_ESM_GROUP3_ERROR);
      }
#endif /* STD_ON == MCU_ESM_GROUP3_CHECK */

#if(STD_ON == MCU_CPU_SELFTEST)
      if(stc_completed)
      {
         Mcu_SystemInit2();
      }
      else
      {
         Mcu_SystemInit1();
      }
#else
      Mcu_SystemInit1();
      Mcu_SystemInit2();
#endif /* STD_ON == MCU_CPU_SELFTEST */
   }
} /*end of Mcu_Init()*/

#if(STD_ON == MCU_INIT_RAM_API)
/*********************************************************************************************************************
 * Function name:  Mcu_InitRamSection(Mcu_RamSectionType RamSection)
 *********************************************************************************************************************/
/** \brief This service initializes the RAM section wise
 *
 * This service initializes the RAM section wise
 *
 * \param[in] RamSection - Selects RAM memory section provided in configuration set.
 * \param[out] None
 * \pre MCU_INIT_RAM_API shall be enabled. This function shall be called after the call of Mcu_Init()
 * \post None
 * \return Std_ReturnType
 * \retval E_OK - Ram initialization completed correctly
 * \retval E_NOT_OK - Ram initialization not completed correctly
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_008 */
/* DesignId : MCU_DesignId_009 */
/* Requirements : AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR60, AR_MCU_SR61, AR_MCU_SR62, AR_MCU_SR102,
 * AR_MCU_SR106, AR_MCU_SR108 */
FUNC(Std_ReturnType, MCU_CODE) Mcu_InitRamSection( Mcu_RamSectionType RamSection)
{

   Std_ReturnType init_ram_section_return = E_NOT_OK;
   /* RAM destination pointer */
   P2VAR(uint8, AUTOMATIC, MCU_APPL_DATA) Mcu_RamDestination;
   /* Local word counter */
   VAR(uint32, MCU_VAR) Mcu_RamBytes;

#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == Mcu_ConfigPtr_pt)
   {
      /* API is being called before calling Mcu_Init */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_INIT_RAMSECTION, MCU_E_UNINIT);
   }
   else if ( RamSection >= Mcu_ConfigPtr_pt->Mcu_NumberOfRamSectors)
   {
      /* API is being called with an invalid parameter */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_INIT_RAMSECTION, MCU_E_PARAM_RAMSECTION);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
      /* Check for Ram Section Base Address pointer validity*/
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
      if(NULL_PTR != Mcu_ConfigPtr_pt->Mcu_ConfigRamSection[RamSection].Mcu_RamSectionBaseAddress)
      {
         /*Load the RAM Section Base address from the configuration*/
         /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Mcu_RamSectionBaseAddress was already checked" */
         Mcu_RamDestination =  Mcu_ConfigPtr_pt->Mcu_ConfigRamSection[RamSection].Mcu_RamSectionBaseAddress;
         /*Load the RamSection Size*/
         Mcu_RamBytes = Mcu_ConfigPtr_pt->Mcu_ConfigRamSection[RamSection].Mcu_RamSectionBytes;

         while(0U < Mcu_RamBytes)
         {
            /* Initialize the RAM with selected default value */
            /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Mcu_RamSectionBaseAddress was already checked" */
            *Mcu_RamDestination = Mcu_ConfigPtr_pt->Mcu_ConfigRamSection[RamSection].Mcu_RamDefaultValue;
            /* Point to next address*/
            /*SAFETYMCUSW 567 S <APPROVED> "Pointer arithmetic is always bytewise (8 bit) and depends on parameter" */
            Mcu_RamDestination++;
            /* Reduce Byte counter */
            Mcu_RamBytes--;
         }
         init_ram_section_return = E_OK;
      }
   }

   return(init_ram_section_return);
}
#endif /* STD_ON == MCU_INIT_RAM_API */

/*********************************************************************************************************************
 * Function name:  Mcu_GetPllStatus(void)
 *********************************************************************************************************************/
/** \brief This service provides the lock status of the PLL.
 *
 * This service provides the lock status of the PLL.
 *
 * \param[in] None
 * \param[out] None
 * \pre This function shall be called after the call of Mcu_Init()
 * \post None
 * \return Mcu_PllStatusType
 * \retval MCU_PLL_LOCKED -
 * \retval MCU_PLL_UNLOCKED -
 * \retval MCU_PLL_STATUS_UNDEFINED -
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_009 */
/* DesignId : MCU_DesignId_010 */
/* Requirements : AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR74, AR_MCU_SR75, AR_MCU_SR76, AR_MCU_SR77,
 * AR_MCU_SR102, AR_MCU_SR108 */
FUNC(Mcu_PllStatusType, MCU_CODE) Mcu_GetPllStatus(void)
{
   Mcu_PllStatusType pll_status = MCU_PLL_STATUS_UNDEFINED;

#if (STD_OFF == MCU_NO_PLL)
   uint32 csdis_local;
   uint32 csvstat_local;
#endif /* STD_OFF == MCU_NO_PLL */

#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == Mcu_ConfigPtr_pt)
   {
      /* API is being called before calling Mcu_Init */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_GET_PLL_STATUS, MCU_E_UNINIT);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
#if (STD_OFF == MCU_NO_PLL)
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      csdis_local = MCU_SYS1_REG_BASE->csdis;
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      csvstat_local = MCU_SYS1_REG_BASE->csvstat;

      if((((csdis_local & MCU_PLL1_SOURCE) == MCU_PLL1_SOURCE) &&    /* Both PLL's disabled */
          ((csdis_local & MCU_PLL2_SOURCE) == MCU_PLL2_SOURCE))   ||
         (((csdis_local & MCU_PLL1_SOURCE) == 0x00000000U) &&        /* PLL1 enabled and unlocked */
          ((csvstat_local & MCU_PLL1_SOURCE) == 0x00000000U))     ||
         (((csdis_local & MCU_PLL2_SOURCE) == 0x00000000U) &&        /* PLL2 enabled and unlocked */
          ((csvstat_local & MCU_PLL2_SOURCE) == 0x00000000U))
        )
      {
         pll_status = MCU_PLL_UNLOCKED;
      }
      else
      {
         pll_status = MCU_PLL_LOCKED;
      }
#endif /* STD_OFF == MCU_NO_PLL */
   }

   return (pll_status);
} /* end of Mcu_GetPllStatus */

#if(STD_ON == MCU_INIT_CLOCK_API)
/*********************************************************************************************************************
 * Function name:  Mcu_InitClock(Mcu_ClockType ClockSetting)
 *********************************************************************************************************************/
/** \brief This service initializes the PLL and other MCU specific clock options.
 *
 * This function is provided as dummy. All Clock initialization activities being performed in
 * Mcu_Init() to improve performance.
 *
 * \param[in] ClockSetting - Clock setting ID number
 * \param[out] None
 * \pre This function shall be called after the call of Mcu_Init()
 * \post None
 * \return Std_ReturnType
 * \retval E_OK - Clock initialization completed correctly
 * \retval E_NOT_OK - Clock initialization not completed correctly
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_010 */
/* DesignId : MCU_DesignId_011 */
/* Requirements : AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR63, AR_MCU_SR66, AR_MCU_SR67, AR_MCU_SR102,
 * AR_MCU_SR104, AR_MCU_SR108 */
FUNC(Std_ReturnType, MCU_CODE) Mcu_InitClock(Mcu_ClockType ClockSetting)
{
   Std_ReturnType initclock_return = E_NOT_OK;
#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == Mcu_ConfigPtr_pt)
   {
      /* API is being called before calling Mcu_Init */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_INIT_CLOCK, MCU_E_UNINIT);
   }
   else if(ClockSetting != Mcu_ConfigPtr_pt->Mcu_ClockSetting)
   {
      /* API is being called with an invalid parameter */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_INIT_CLOCK, MCU_E_PARAM_CLOCK);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
      /* To avoid compiler remark with DET disabled */
      ClockSetting = ClockSetting;

      initclock_return = E_OK;
   }
   return (initclock_return);
}  /* end of the Mcu_InitClock */
#endif /* STD_ON == MCU_INIT_CLOCK_API */

#if(STD_OFF == MCU_NO_PLL)
/*********************************************************************************************************************
 * Function name:  Mcu_DistributePllClock(void)
 *********************************************************************************************************************/
/** \brief This service activates the PLL clock to the MCU clock distribution.
 *
 * This function is provided as dummy. All PLL distribution activities being performed in
 * Mcu_Init() to improve performance.
 *
 * \param[in] None
 * \param[out] None
 * \pre None
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_011 */
/* DesignId : MCU_DesignId_012 */
/* Requirements : AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR68, AR_MCU_SR73, AR_MCU_SR102, AR_MCU_SR107,
 * AR_MCU_SR108 */
FUNC(void, MCU_CODE) Mcu_DistributePllClock(void)
{
   /* Development Error Detection */
#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == Mcu_ConfigPtr_pt)
   {
      /* API is being called before calling Mcu_Init */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_DISTRIBUTE_PLL_CLOCK, MCU_E_UNINIT);
   }
   else if(MCU_PLL_LOCKED != Mcu_GetPllStatus())
   {
      /* API is being called before PLL is locked */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_DISTRIBUTE_PLL_CLOCK, MCU_E_PLL_NOT_LOCKED);
   }
   else
   {
      /* Do nothing */
   }
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
} /*end of the Mcu_DistributePllClock()*/
#endif /* STD_OFF == MCU_NO_PLL */

/*********************************************************************************************************************
 * Function name:  Mcu_GetResetReason(void)
 *********************************************************************************************************************/
/** \brief The service reads the reset type from the hardware.
 *
 * The service reads the reset type from the hardware.
 *
 * \param[in] None
 * \param[out] None
 * \pre This function shall be called after the call of Mcu_Init()
 * \post None
 * \return Mcu_ResetType
 * \retval MCU_POWER_ON_RESET
 * \retval MCU_WATCHDOG_RESET
 * \retval MCU_ICEPICK_RESET
 * \retval MCU_OSCILLATOR_RESET
 * \retval MCU_CPU_RESET
 * \retval MCU_SOFTWARE_RESET
 * \retval MCU_EXTERNAL_RESET
 * \retval MCU_RESET_UNDEFINED
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_012 */
/* DesignId : MCU_DesignId_003 */
/* Requirements : AR_MCU_SR11, AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR78, AR_MCU_SR79,
 * AR_MCU_SR80, AR_MCU_SR102, AR_MCU_SR108, AR_MCU_SR147 */
FUNC(Mcu_ResetType, MCU_CODE) Mcu_GetResetReason(void)
{
   Mcu_ResetType reset_reason = MCU_RESET_UNDEFINED;
   Mcu_RawResetType reset_raw;

#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == Mcu_ConfigPtr_pt)
   {
      /* API is being called before calling Mcu_Init */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_GET_RESET_REASON, MCU_E_UNINIT);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
      /* Get raw reset reason */
      reset_raw = Mcu_GetResetRawValue();

      /* Power On Reset */
      if((MCU_PORST_MASK == (MCU_PORST_MASK & reset_raw)) ||
         (MCU_EMPTYRST_MASK == (MCU_CLRRST_MASK & reset_raw)))
      {
         /* Clear reset reason to be able to identify other reset reasons */
         /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
         /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
         MCU_SYS1_REG_BASE->sysesr = MCU_CLRRST_MASK;
         reset_reason = MCU_POWER_ON_RESET;
      }
      /* Oscillator Failure Reset */
      else if(MCU_OSCRST_MASK == (MCU_OSCRST_MASK & reset_raw))
      {
         reset_reason = MCU_OSCILLATOR_RESET;
      }
      /* CPU Reset */
      else if(MCU_CPURST_MASK == (MCU_CPURST_MASK & reset_raw))
      {
         reset_reason = MCU_CPU_RESET;
      }
      /* Watchdog Reset */
      else if(MCU_WDRST_MASK == (MCU_WDRST_MASK & reset_raw))
      {
         /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
         /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
         if(0x00000000U == MCU_RTI_REG_BASE->wdstatus)
         {
            reset_reason = MCU_ICEPICK_RESET;
         }
         else
         {
            reset_reason = MCU_WATCHDOG_RESET;
         }
      }
      /* Software Reset */
      else if(MCU_SWRST_MASK == (MCU_SWRST_MASK & reset_raw))
      {
         reset_reason = MCU_SOFTWARE_RESET;
      }
      /* External Reset */
      else if(MCU_EXTRST_MASK == (MCU_EXTRST_MASK & reset_raw))
      {
         reset_reason = MCU_EXTERNAL_RESET;
      }
      /* Undefined Reset */
      else
      {
         /* Do nothing */
      }
   }

   return(reset_reason);
} /* end of Mcu_GetResetReason() */

/*********************************************************************************************************************
 * Function name:  Mcu_SetMode(Mcu_ModeType McuMode)
 *********************************************************************************************************************/
/** \brief This service activates the MCU power modes.
 *
 * Supported modes are Doze, Snooze and Sleep.
 *
 * \param[in] McuMode
 * \param[out] None
 * \pre This function shall be called after the call of Mcu_Init()
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_013 */
/* DesignId : MCU_DesignId_006 */
/* Requirements : AR_MCU_SR13, AR_MCU_SR14, AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR89, AR_MCU_SR90,
 * AR_MCU_SR91, AR_MCU_SR102, AR_MCU_SR105, AR_MCU_SR108 */
FUNC(void, MCU_CODE) Mcu_SetMode(Mcu_ModeType McuMode)
{

#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == Mcu_ConfigPtr_pt)
   {
      /* API is being called before calling Mcu_Init */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID, MCU_API_SET_MODE, MCU_E_UNINIT);
   }
   else if(Mcu_ConfigPtr_pt->Mcu_ModesNumber <= McuMode)
   {
      /* API is being called with an invalid mode parameter */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID, MCU_API_SET_MODE, MCU_E_PARAM_MODE);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
      if (Mcu_ConfigPtr_pt->Mcu_ModeConfig[McuMode].Mcu_PowerMode_u8 == MCU_DOZE_MODE)
      {
         Mcu_EnterDozeMode();
      }
      else if (Mcu_ConfigPtr_pt->Mcu_ModeConfig[McuMode].Mcu_PowerMode_u8 == MCU_SNOOZE_MODE)
      {
         Mcu_EnterSnoozeMode();
      }
      else if (Mcu_ConfigPtr_pt->Mcu_ModeConfig[McuMode].Mcu_PowerMode_u8 == MCU_SLEEP_MODE)
      {
         Mcu_EnterSleepMode();
      }
      else
      {
         /* Do nothing. Invalid power mode */
      }
   }
} /*end of the Mcu_SetMode()*/

/*********************************************************************************************************************
 * Function name:  Mcu_GetResetRawValue(void)
 *********************************************************************************************************************/
/** \brief The service reads the reset type from the hardware register.
 *
 * The service reads the reset type from the hardware register.
 *
 * \param[in] None
 * \param[out] None
 * \pre This function shall be called after the call of Mcu_Init()
 * \post None
 * \return Mcu_RawResetType - Returns SYSESR register value
 * \retval None
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_014 */
/* DesignId : MCU_DesignId_004 */
/* Requirements : AR_MCU_SR11, AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR81, AR_MCU_SR82,
 * AR_MCU_SR83, AR_MCU_SR102, AR_MCU_SR108, AR_MCU_SR147 */
FUNC(Mcu_RawResetType, MCU_CODE)Mcu_GetResetRawValue(void)
{
   Mcu_RawResetType reset_raw_value = MCU_ERRORRST_MASK;
#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == Mcu_ConfigPtr_pt)
   {
      /* API is being called before calling Mcu_Init */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_GET_RESET_RAW_VALUE, MCU_E_UNINIT);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      /*SAFETYMCUSW 134 S <APPROVED> "Read System Exception Status register" */
      reset_raw_value = (Mcu_RawResetType)MCU_SYS1_REG_BASE->sysesr;
   }
   return(reset_raw_value);
}  /*end of the Mcu_ResetRawValue()*/

#if (STD_ON == MCU_PERFORM_RESET_API)
/*********************************************************************************************************************
 * Function name:  Mcu_PerformReset(void)
 *********************************************************************************************************************/
/** \brief The service performs a microcontroller reset.
 *
 * The service performs a microcontroller reset.
 *
 * \param[in] None
 * \param[out] None
 * \pre This function shall be called after the call of Mcu_Init()
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_015 */
/* DesignId : MCU_DesignId_002 */
/* Requirements : AR_MCU_SR10, AR_MCU_SR18, AR_MCU_SR23, AR_MCU_SR24, AR_MCU_SR84, AR_MCU_SR85,
 * AR_MCU_SR86, AR_MCU_SR87, AR_MCU_SR88, AR_MCU_SR102, AR_MCU_SR108 */
FUNC(void, MCU_CODE) Mcu_PerformReset(void)
{
#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == Mcu_ConfigPtr_pt)
   {
      /* API is being called before calling Mcu_Init */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_PERFORM_RESET, MCU_E_UNINIT);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
      /* Perform a sofware reset */
      Mcu_GlobalSuspend();
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      MCU_SYS1_REG_BASE->sysecr |= MCU_PERFORM_RESET_MASK;
      Mcu_GlobalRestore();
   }
} /*end of the Mcu_PerformReset()*/
#endif /* STD_ON == MCU_PERFORM_RESET_API */

#if (STD_ON == MCU_CLEAR_RESET_REASON_API)
/*********************************************************************************************************************
 * Function name:  Mcu_ClearResetReason(void)
 *********************************************************************************************************************/
/** \brief The service clears reset reasons on SYSESR register.
 *
 * The service clears reset reasons on SYSESR register.
 *
 * \param[in] None
 * \param[out] None
 * \pre It's recommended to call this function after obtaining the reset reset from Mcu_GetResetReason or
 *      Mcu_GetResetRawValue
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_016 */
/* DesignId : MCU_DesignId_013 */
/* Requirements : AR_MCU_SR80, AR_MCU_SR83 */
FUNC(void, MCU_CODE) Mcu_ClearResetReason(void)
{
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->sysesr = MCU_CLRRST_MASK;

} /* end of Mcu_ClearResetReason() */
#endif /* STD_ON == MCU_CLEAR_RESET_REASON_API */

#if(STD_ON == MCU_GET_RAM_STATE_API)
/*********************************************************************************************************************
 * Function name:  Mcu_GetRamState(void)
 *********************************************************************************************************************/
/** \brief This service provides the actual status of the microcontroller Ram
 *
 * This function is provided as dummy.
 *
 * \param[in] None
 * \param[out] None
 * \pre This function shall be called after the call of the Mcu_Init()
 * \post None
 * \return Mcu_RamStateType
 * \retval MCU_RAMSTATE_INVALID
 * \retval MCU_RAMSTATE_VALID
 *
 *********************************************************************************************************************/
/* SourceId : MCU_SourceId_042 */
/* DesignId : MCU_DesignId_025 */
/* Requirements : AR_MCU_SR97, AR_MCU_SR98, AR_MCU_SR99 */
FUNC(Mcu_RamStateType, MCU_CODE)Mcu_GetRamState(void)
{
   Mcu_RamStateType getramstate_return = MCU_RAMSTATE_INVALID;
#if (STD_ON == MCU_DEV_ERROR_DETECT)
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == Mcu_ConfigPtr_pt)
   {
      /* API is being called before calling Mcu_Init */
      (void)Det_ReportError(MCU_MODULE_ID, MCU_INSTANCE_ID,  MCU_API_GET_RAM_STATE, MCU_E_UNINIT);
   }
   else
#endif /* STD_ON == MCU_DEV_ERROR_DETECT */
   {
      getramstate_return = MCU_RAMSTATE_VALID;
   }
   return (getramstate_return);
}  /*end of the Mcu_GetRamState()*/
#endif /*STD_ON == MCU_GET_RAM_STATE_API */


#if (STD_ON == MCU_REGISTER_READBACK_API)
/*******************************************************************************************************************
 *  Mcu_RegisterReadback
 *******************************************************************************************************************/
/*! \brief      This method is Mcu_RegisterReadback Api.
 *  \param[in]  Mcu_RegisterReadbackType       RegisterReadbackPtr
 *  \param[out] none
 *  \return     E_OK, E_NOT_OK
 *  \context    Function could be called from from task level
 *******************************************************************************************************************/
/* SourceId : MCU_SourceId_017 */
/* DesignId : MCU_DesignId_014 */
/* Requirements : AR_MCU_SR145, AR_MCU_SR146, AR_MCU_SR148, AR_MCU_SR149, AR_MCU_SR160, AR_MCU_SR161, AR_MCU_SR162 */
FUNC(Std_ReturnType, MCU_CODE) Mcu_RegisterReadback
(
    P2VAR(Mcu_RegisterReadbackType, AUTOMATIC, MCU_APPL_DATA) RegisterReadbackPtr
)
{
   Std_ReturnType register_readback_return = E_NOT_OK;

   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Null pointer definition" */
   if(NULL_PTR == RegisterReadbackPtr)
   {
      /* Do nothing. Incorrect pointer. */
   }
   else
   {
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_CsDis        = MCU_SYS1_REG_BASE->csdis;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_CdDis        = MCU_SYS1_REG_BASE->cddis;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_GhvSrc       = MCU_SYS1_REG_BASE->ghvsrc;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_VclkASrc     = MCU_SYS1_REG_BASE->vclkasrc;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_RclkSrc      = MCU_SYS1_REG_BASE->rclksrc;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_PllCtl1      = MCU_SYS1_REG_BASE->pllctl1;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_PllCtl2      = MCU_SYS1_REG_BASE->pllctl2;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_LpoMonCtl    = MCU_SYS1_REG_BASE->lpomonctl;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_ClkCntrl     = MCU_SYS1_REG_BASE->clkcntrl;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_PllCtl3      = MCU_SYS2_REG_BASE->pllctl3;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_Clk2Cntrl    = MCU_SYS2_REG_BASE->clk2cntrl;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_VclkACon1    = MCU_SYS2_REG_BASE->vclkacon1;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_PsPwrDwnClr0 = MCU_PCR_REG_BASE->pspwrdwnclr0;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_PsPwrDwnClr1 = MCU_PCR_REG_BASE->pspwrdwnclr1;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_PsPwrDwnClr2 = MCU_PCR_REG_BASE->pspwrdwnclr2;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_PsPwrDwnClr3 = MCU_PCR_REG_BASE->pspwrdwnclr3;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_FrdCntl      = MCU_FLS_REG_BASE->frdcntl;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_FbFallBack   = MCU_FLS_REG_BASE->fbfallback;
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      RegisterReadbackPtr->Mcu_EeCfg        = EEPROM_CONFIG;

      register_readback_return = E_OK;
   }

   return(register_readback_return);
}
#endif /*STD_ON == MCU_REGISTER_READBACK_API*/
/*********************************************************************************************************************
 *  Local Functions Definition
 *********************************************************************************************************************/

/*********************************************************************************************************************
 * Function name:  Mcu_SystemInit1(void)
 *********************************************************************************************************************/
/** \brief  Local function to start system initialization
 *
 *  Local function to start system initialization
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_Init()
 * \post If STC enabled, a software reset is caused at the end of this function
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_SystemInit1(void)
{
#if (STD_OFF == MCU_NO_PLL)
   /* Configure PLL control registers and enable PLLs.
    * The PLL takes (127 + 1024 * NR) oscillator cycles to acquire lock.
    * This initialization sequence performs all the tasks that are not
    * required to be done at full application speed while the PLL locks.
    */
   Mcu_SetupPLL(); /*INIT: 8,9*/
#endif /* STD_OFF == MCU_NO_PLL */

#if (STD_ON == MCU_EFUSE_SELF_TEST)
   /* Run eFuse controller start-up checks and start eFuse controller ECC self-test.
    * This includes a check for the eFuse controller error outputs to be stuck-at-zero.
    */
   Mcu_EfcCheck(); /*INIT: 10*/
#endif /* STD_ON == MCU_EFUSE_SELF_TEST */

   /* Enable clocks to peripherals and release peripheral reset */
   Mcu_PeriphInit(); /*INIT: 11*/

#if (STD_ON == MCU_EFUSE_SELF_TEST)
   /* Wait for eFuse controller self-test to complete and check results */
   if (!Mcu_EfcCheckSelfTest()) /*INIT: 13*/
   {
      /* eFuse controller ECC logic self-test failed, device operation is not reliable */
      Mcu_SafetyInitErrorCbk(MCU_EFC_ERROR);
   }
#endif /* STD_ON == MCU_EFUSE_SELF_TEST */

   /*
    * Set up flash address and data wait states based on the target CPU clock frequency.
    * The number of address and data wait states for the target CPU clock frequency are specified
    * in the specific part's datasheet.
    */
   Mcu_SetupFlash(); /*INIT: 14, 15*/

   /* Configure the LPO such that HF LPO is as close to 10MHz as possible */
   Mcu_TrimLpo(); /*INIT: 16*/

   /* Wait for PLLs to start up and map clock domains to desired clock sources */
   Mcu_MapClocks(); /*INIT: 18, 19, 20*/

#if(STD_ON == MCU_CPU_SELFTEST)
   /* Make sure that the CPU self-test controller can actually detect a fault inside CPU */
   Mcu_StcSelfCheck(); /*INIT: 21*/
#endif /* STD_ON == MCU_CPU_SELFTEST */

}

/*********************************************************************************************************************
 * Function name:  Mcu_SystemInit2(void)
 *********************************************************************************************************************/
/** \brief  Local function to continue system initialization
 *
 *  Local function to continue system initialization
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_Init()
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_SystemInit2(void)
{
#if((0x00000000U != DUAL_PORT_RAM_GROUP_PBIST)   || \
    (0x00000000U != SINGLE_PORT_RAM_GROUP_PBIST) || \
    (0x00000000U != PERIPHERAL_RAM_INIT))
   uint32 ram_groups;
#endif

#if(STD_ON == MCU_PBIST_SELFTEST)
   Mcu_PbistSelfCheck(); /*INIT: 24*/
#endif /* STD_ON == MCU_PBIST_SELFTEST */

#if(0x00000000U != DUAL_PORT_RAM_GROUP_PBIST)
   ram_groups = DUAL_PORT_RAM_GROUP_PBIST;
   /* Start PBIST on all dual-port memories */
   if (E_NOT_OK == Mcu_PbistRun(ram_groups, PBIST_MARCH13N_DP)) /*INIT: 28, 31*/
   {
      /* Failure found */
      Mcu_SafetyInitErrorCbk(MCU_PBIST_ERROR);
   }
#endif /* 0x00000000U != DUAL_PORT_RAM_GROUP_PBIST */

#if(0x00000000U != SINGLE_PORT_RAM_GROUP_PBIST)
   ram_groups = SINGLE_PORT_RAM_GROUP_PBIST;
   /* Start PBIST on all single-port memories */
   if (E_NOT_OK == Mcu_PbistRun(ram_groups, PBIST_MARCH13N_SP)) /*INIT: 32, 33*/
   {
   /* Failure found */
      Mcu_SafetyInitErrorCbk(MCU_PBIST_ERROR);
   }
#endif /* 0x00000000U != SINGLE_PORT_RAM_GROUP_PBIST */

#if(0x00000000U != PERIPHERAL_RAM_INIT)
   ram_groups = PERIPHERAL_RAM_INIT;
   /* Initialize Peripherals RAM */
   Mcu_MemoryInit(ram_groups); /*INIT: 34, 35*/
#endif /* 0x00000000U != PERIPHERAL_RAM_INIT */
}

#if (STD_OFF == MCU_NO_PLL)
/*********************************************************************************************************************
 * Function name:  Mcu_SetupPLL(void)
 *********************************************************************************************************************/
/** \brief  Local function to setup PLL
 *
 *  Local function to setup PLL
 *
 * \param[in] None
 * \param[out] None
 * \pre This can be enable/disabled at module configuration. This function is called from Mcu_SystemInit1
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_SetupPLL(void)
{
   /* Configure PLL control registers */

   /* Disable PLL1 and PLL2 */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->csdisset = MCU_PLL_DISABLE;
   /*SAFETYMCUSW 28 D MR:NA <APPROVED> "Hardware status bit read check" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   /*SAFETYMCUSW 134 S MR:12.2 <APPROVED> "Pointer to register definition" */
   while((MCU_SYS1_REG_BASE->csdis & MCU_PLL_DISABLE) != MCU_PLL_DISABLE)
   {
      /* Wait */
   }

   /* Clear Global Status Register */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->glbstat = MCU_GLBSTAT_CLEAR;

   /*
    * Setup Pll control register 1
    * Maximum R divider value is used at this point.
    * User defined value is set at Mcu_MapClocks()
    */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->pllctl1 = Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_PllCtl1Reg | (MCU_MAX_PLL_DIV << 24U);

   /* Setup pll control register 2 */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->pllctl2 = Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_PllCtl2Reg;

   /*
    * Setup Pll control register 3
    * Maximum R divider value is used at this point.
    * User defined value is set at Mcu_MapClocks()
    */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS2_REG_BASE->pllctl3 = Mcu_ConfigPtr_pt->Mcu_Sys2RegConfig->Mcu_PllCtl3Reg | (MCU_MAX_PLL_DIV << 24U);

   /** - Enable PLL(s) to start up or Lock */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Pointer validity checked at Mcu_Init" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->csdis = ~(Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_CSDisClrReg);
}
#endif /* STD_OFF == MCU_NO_PLL */

/*********************************************************************************************************************
 * Function name:  Mcu_PeriphInit(void)
 *********************************************************************************************************************/
/** \brief  Local function to power up required peripherals
 *
 *  Local function to power up required peripherals
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit1
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_PeriphInit(void)
{
   /* Disable Peripherals before peripheral powerup */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->clkcntrl &= ~(MCU_PENA);

   /* Release peripherals from reset and enable clocks to all peripherals */
   /* Power-up required peripherals */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 45 D <APPROVED> "Pointer checked for NULL before calling this function" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_PCR_REG_BASE->pspwrdwnclr0 = Mcu_ConfigPtr_pt->Mcu_PcrRegConfig->Mcu_PsPwrDwnClr0Reg;
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 45 D <APPROVED> "Pointer checked for NULL before calling this function" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_PCR_REG_BASE->pspwrdwnclr1 = Mcu_ConfigPtr_pt->Mcu_PcrRegConfig->Mcu_PsPwrDwnClr1Reg;
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 45 D <APPROVED> "Pointer checked for NULL before calling this function" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_PCR_REG_BASE->pspwrdwnclr2 = Mcu_ConfigPtr_pt->Mcu_PcrRegConfig->Mcu_PsPwrDwnClr2Reg;
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 45 D <APPROVED> "Pointer checked for NULL before calling this function" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_PCR_REG_BASE->pspwrdwnclr3 = Mcu_ConfigPtr_pt->Mcu_PcrRegConfig->Mcu_PsPwrDwnClr3Reg;

   /* Enable Peripherals */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->clkcntrl |= MCU_PENA;
}
/*********************************************************************************************************************
 * Function name:  Mcu_SetupFlash(void)
 *********************************************************************************************************************/
/** \brief  Local function to setup flash read mode and wait states
 *
 *  Local function to setup flash read mode and wait states
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit1
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_SetupFlash(void)
{
   /* Setup flash read mode, address wait states and data wait states */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FLS_REG_BASE->frdcntl = Mcu_ConfigPtr_pt->Mcu_FlsRegConfig->Mcu_FrdCntlReg;

   /* Setup flash access wait states for bank 7 */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FSM_WR_ENA = 0x5U;
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   EEPROM_CONFIG = Mcu_ConfigPtr_pt->Mcu_FlsRegConfig->Mcu_EepConfig;

   /* Disable write access to flash state machine registers */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FSM_WR_ENA = 0xAU;

   /* Setup flash bank power modes */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Pointer validity checked at Mcu_Init" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FLS_REG_BASE->fbfallback = Mcu_ConfigPtr_pt->Mcu_FlsRegConfig->Mcu_FbFallback;
}

/*********************************************************************************************************************
 * Function name:  Mcu_TrimLpo(void)
 *********************************************************************************************************************/
/** \brief  Local function to trim the Low Power Oscillator
 *
 *  Local function to trim the Low Power Oscillator
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit1
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_TrimLpo(void)
{
    /* Get TRIM value from OTP */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   VAR(uint32, MCU_VAR) initial_trim_value = MCU_OTP_TRIM;
    /* Load TRIM values from OTP if present else load user defined values */
#if(STD_ON == MCU_COPY_TRIM_FROM_OTP)
   if(initial_trim_value != (uint32)0x0000FFFFU)
   {
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      MCU_SYS1_REG_BASE->lpomonctl = MCU_BIAS_ENABLE | MCU_OTP_TRIM;
   }
   else
#endif /* STD_ON == MCU_COPY_TRIM_FROM_OTP */
   {
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
      MCU_SYS1_REG_BASE->lpomonctl = Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_LpoMonCtlReg;
   }
}

/*********************************************************************************************************************
 * Function name:  Mcu_MapClocks(void)
 *********************************************************************************************************************/
/** \brief  Local function to setup clocks
 *
 *  Local function to setup clocks
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit1
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_MapClocks(void)
{
   /* Disable / Enable clock domain */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Pointer validity checked at Mcu_Init" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->cddis = ~(Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_CDDisClrReg);

#if (STD_OFF == MCU_NO_PLL)
   /* Wait for until clocks are locked */
   /*SAFETYMCUSW 28 D <INSPECTED> "Wait Hardware to lock PLL's" */
   while(MCU_PLL_LOCKED != Mcu_GetPllStatus())
   {

   }

   /* Now the PLLs are locked and the PLL outputs can be speed up */
   /* The R-divider was programmed to be 0x1F. Now this divider is changed to programmed value */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->pllctl1 = Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_PllCtl1Reg;
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS2_REG_BASE->pllctl3 = Mcu_ConfigPtr_pt->Mcu_Sys2RegConfig->Mcu_PllCtl3Reg;
#endif /* STD_OFF == MCU_NO_PLL */

   /* Map device clock domains to desired sources and configure top-level dividers */
   /* All clock domains are working off the default clock sources until now */

   /* Setup GCLK, HCLK and VCLK clock source for normal operation, power down mode and after wakeup */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->ghvsrc = Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_GHVSrcReg;

   /* Write the configuration for VCLK2 */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   /*SAFETYMCUSW 134 S MR:12.2 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->clkcntrl = ((MCU_SYS1_REG_BASE->clkcntrl & MCU_VCLK2R_CLR_MASK)|
                                  (Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_ClkCntlReg & MCU_VCLK2R_SET_MASK));
   /* Write the configuration for VCLK */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   /*SAFETYMCUSW 134 S MR:12.2 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->clkcntrl = ((MCU_SYS1_REG_BASE->clkcntrl & MCU_VCLKR_CLR_MASK)|
                                  (Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_ClkCntlReg & MCU_VCLKR_SET_MASK));
   /* Write the configuration for VCLK3 */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS2_REG_BASE->clk2cntrl = Mcu_ConfigPtr_pt->Mcu_Sys2RegConfig->Mcu_Clk2CntlReg;

   /* Setup RTICLK1 and RTICLK2 clocks */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->rclksrc = Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_RClkSrcReg;

   /* Setup asynchronous peripheral clock sources for VCLKA1 and VCLKA2 */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->vclkasrc = Mcu_ConfigPtr_pt->Mcu_Sys1RegConfig->Mcu_VClkASrcReg;

   /* Setup asynchronous peripheral clock sources for VCLKA4 */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS2_REG_BASE->vclkacon1 = Mcu_ConfigPtr_pt->Mcu_Sys2RegConfig->Mcu_VClkACon1Reg;
}

#if (STD_ON == MCU_EFUSE_SELF_TEST)
/*********************************************************************************************************************
 * Function name:  Mcu_EfcCheck(void)
 *********************************************************************************************************************/
/** \brief  Local function to perform a Efuse Self Test
 *
 *  Local function to perform a Efuse Self Test
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit1
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_EfcCheck(void)
{
   VAR(uint32, MCU_VAR) efcStatus = 0U;

   /* read the EFC Error Status Register */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   efcStatus = MCU_EFC_REG_BASE->error;

   if (0x00U == efcStatus)
   {
       /* run stuck-at-zero test and check if it passed */
      if (Mcu_EfcStuckZeroTest())
      {
          /* start EFC ECC logic self-test */
         Mcu_EfcSelfTest();
      }
      else
      {
          /* EFC output is stuck-at-zero, device operation unreliable */
         Mcu_SafetyInitErrorCbk(MCU_EFC_ERROR);
      }
   }
   /* EFC Error Register is not zero */
   else
   {
      /* one-bit error detected during autoload */
      if (0x15U == efcStatus)
      {
          /* start EFC ECC logic self-test */
         Mcu_EfcSelfTest();
      }
      else
      {
          /* Some other EFC error was detected */
         Mcu_SafetyInitErrorCbk(MCU_EFC_ERROR);
      }
   }
}

/*********************************************************************************************************************
 * Function name:  Mcu_EfcStuckZeroTest(void)
 *********************************************************************************************************************/
/** \brief  Local function to perform a Efuse Self Test
 *
 *  Local function to perform a Efuse Self Test
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_EfcCheck
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(boolean, MCU_CODE) Mcu_EfcStuckZeroTest(void)
{
   VAR(boolean, MCU_VAR) result = FALSE;
   VAR(uint32, MCU_VAR) error_checks = EFC_INSTRUCTION_INFO_EN  |
                                       EFC_INSTRUCTION_ERROR_EN |
                                       EFC_AUTOLOAD_ERROR_EN    |
                                       EFC_SELF_TEST_ERROR_EN;
   VAR(uint32, MCU_VAR) pins_local;

   /*
    * Configure the output enable for auto load error , instruction info,
    * instruction error, and self test error using boundary register
    * and drive values one across all the errors
    */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_EFC_REG_BASE->boundary = (OUTPUT_ENABLE | error_checks);

   /* Read from the pin register. This register holds the current values
    * of above errors. This value should be 0x5c00.If not at least one of
    * the above errors is stuck at 0.
    */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   pins_local = MCU_EFC_REG_BASE->pins;

   if ((pins_local & 0x5C00U) == 0x5C00U)
   {
      /* Check if the ESM group1 channels 40 is set and group3 channel 2 is set */
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      if (((MCU_ESM_REG_BASE->estatus4[0] & 0x200U) == 0x200U) && ((MCU_ESM_REG_BASE->estatus1[2] & 0x2U) == 0x2U))
      {
           /* stuck-at-zero test passed */
         result = TRUE;
      }
   }

   /* put the pins back low */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_EFC_REG_BASE->boundary = OUTPUT_ENABLE;

   /* clear group1 flags */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_ESM_REG_BASE->estatus4[0] = 0x300U;

   /* clear group3 flag */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_ESM_REG_BASE->estatus1[2] = 0x2U;

   /* The nERROR pin will become inactive once the LTC counter expires */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_ESM_REG_BASE->key = 0x5U;

   return result;
}

/*********************************************************************************************************************
 * Function name:  Mcu_EfcSelfTest(void)
 *********************************************************************************************************************/
/** \brief  Local function to perform a Efuse Self Test
 *
 *  Local function to perform a Efuse Self Test
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_EfcCheck
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_EfcSelfTest(void)
{
   /* configure self-test cycles */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_EFC_REG_BASE->self_test_cycles = 0x258U;

   /* configure self-test signature */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_EFC_REG_BASE->self_test_sign = 0x5362F97FU;

   /* configure boundary register to start ECC self-test */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_EFC_REG_BASE->boundary = 0x0000200FU;
}

/*********************************************************************************************************************
 * Function name:  Mcu_EfcCheckSelfTest(void)
 *********************************************************************************************************************/
/** \brief  Local function to check Efuse Self Test results
 *
 *  Local function to check Efuse Self Test results
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit1
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(boolean, MCU_CODE) Mcu_EfcCheckSelfTest(void)
{
   VAR(boolean, MCU_VAR) efc_st_result = FALSE;
   uint32 pins_local;
   uint32 error_local;
   uint32 estatus4_local;

   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 28 D <APPROVED> "Wait Hardware to report test is completed" */
   /*SAFETYMCUSW 134 S <APPROVED> "Wait Hardware to report test is completed" */
   while((MCU_EFC_REG_BASE->pins & EFC_SELF_TEST_DONE) != EFC_SELF_TEST_DONE)
   {
      /* wait until EFC self-test is done */
   }

   /* check if EFC self-test error occurred */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   pins_local = MCU_EFC_REG_BASE->pins;
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   error_local = MCU_EFC_REG_BASE->error;

   if (((pins_local & EFC_SELF_TEST_ERROR) != EFC_SELF_TEST_ERROR) &&
       ((error_local & SELF_TEST_ERROR) != SELF_TEST_ERROR))
   {
      /* check if EFC self-test error is set */
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      estatus4_local = MCU_ESM_REG_BASE->estatus4[0];

      if ((estatus4_local & 0x100U) != 0x100U)
      {
         efc_st_result = TRUE;
      }
   }
   return efc_st_result;
}
#endif /* STD_ON == MCU_EFUSE_SELF_TEST */



#if(STD_ON == MCU_CPU_SELFTEST)
/*********************************************************************************************************************
 * Function name:  Mcu_StcSelfCheck(void)
 *********************************************************************************************************************/
/** \brief  Local function to start STC Self Test
 *
 *  Local function to start STC Self Test
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit1
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_StcSelfCheck(void)
{
   /* Run a diagnostic check on the CPU self-test controller */
   /* First set up the STC clock divider as STC is only supported up to 90MHz */

   /* STC clock is now normal mode CPU clock frequency/2 */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_SYS2_REG_BASE->stcclkdiv = 0x01000000U;

   /* Select one test interval, restart self-test next time, 0x00010001 */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_STC_REG_BASE->stcgcr0 = 0x00010001U;

   /* Enable comparator self-check and stuck-at-0 fault insertion in CPU, 0x1A */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_STC_REG_BASE->stcscscr = 0x1AU;

   /* Maximum time-out period */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_STC_REG_BASE->stctpr = 0xFFFFFFFFU;

   /* wait for 16 VBUS clock cycles at least */
   Mcu_WaitClockCycles(16U);

   /* Enable self-test */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_STC_REG_BASE->stcgcr1 = 0xAU;

   /* wait for 16 VBUS clock cycles at least */
   Mcu_WaitClockCycles(16U);

   /* Idle the CPU so that the self-test can start */
   Mcu_CpuIdle();
}

/*********************************************************************************************************************
 * Function name:  Mcu_CpuSelfTest(void)
 *********************************************************************************************************************/
/** \brief  Local function to perform CPU Self Test
 *
 *  Local function to perform CPU Self Test
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_StcResetHandler
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_CpuSelfTest(void)
{
   /* clear self-check mode */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_STC_REG_BASE->stcscscr = 0x05U;

   /* clear STC global status flags */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_STC_REG_BASE->stcgstat = 0x3U;

   /* clear ESM group1 channel 27 status flag */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_ESM_REG_BASE->estatus1[0U] = 0x08000000U;

   /* STC Self Check reset, clear reset flags */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_SYS1_REG_BASE->sysesr = MCU_CLRRST_MASK;   /* Run all 24 test intervals starting from interval 0 */

   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_STC_REG_BASE->stcgcr0 = 0x00180001U;

   /* Wait for 16 VBUS clock cycles at least */
   Mcu_WaitClockCycles(16U);

   /* Enable self-test */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_STC_REG_BASE->stcgcr1 = 0xAU;

   /* Idle the CPU so that the self-test can start */
   Mcu_CpuIdle();
}

/*********************************************************************************************************************
 * Function name:  Mcu_StcResetHandler(void)
 *********************************************************************************************************************/
/** \brief  Local function to check STC results after reset
 *
 *  Local function to check STC results after reset
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_Init
 * \post If error is detected, callback notification functions are called
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(boolean, MCU_CODE) Mcu_StcResetHandler(void)
{
   VAR(boolean, MCU_VAR) stc_finished = FALSE;
   /* Check if reset caused by stcSelfCheck run */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   if ((MCU_STC_REG_BASE->stcscscr & 0xFU) == 0xAU)
   {
      /* check if the self-test fail bit is set */
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      if ((MCU_STC_REG_BASE->stcgstat & 0x3U) != 0x3U)
      {
         /* STC self-check has failed */
         Mcu_SafetyInitErrorCbk(MCU_STC_SELF_CHECK_ERROR);
         /*
          * Continue initialization sequence after CPU STC completed.
          * User can avoid this at previous callback function
          */
         stc_finished = TRUE;
      }
      /* STC self-check has passed */
      else
      {
         /* Start CPU Self-Test */
         Mcu_CpuSelfTest(); /*INIT: 22*/
      }
   }
   /* CPU reset caused by CPU self-test completion */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   else if ((MCU_STC_REG_BASE->stcgstat & 0x1U) == 0x1U)
   {
      /* Self-Test Fail flag is set */
      /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
      if ((MCU_STC_REG_BASE->stcgstat & 0x2U) == 0x2U)
      {
         /* Call CPU self-test failure handler */
         Mcu_SafetyInitErrorCbk(MCU_STC_ERROR);
         /*
          * Continue initialization sequence after CPU STC completed.
          * User can avoid this at previous notification function
          */
         stc_finished = TRUE;
      }
      /* CPU self-test completed successfully */
      else
      {
         /* Clear reset reason to be able to identify other reset reasons */
         /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
         MCU_SYS1_REG_BASE->sysesr = MCU_CLRRST_MASK;
         /* Continue start-up sequence after CPU STC completed */
         stc_finished = TRUE;
      }
   }
   else
   {
      /* Reset not caused by STC */
   }

   return stc_finished;
}
#endif /* STD_ON == MCU_CPU_SELFTEST */

#if(STD_ON == MCU_PBIST_SELFTEST)
/*********************************************************************************************************************
 * Function name:  Mcu_PbistSelfCheck(void)
 *********************************************************************************************************************/
/** \brief  Local function to perform PBIST Self Check
 *
 *  Local function to perform PBIST Self Check
 *
 * \param[in] None
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit2 if enabled at Mcu_Cfg.h
 * \post If error is detected, callback notification functions are called
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_PbistSelfCheck(void)
{
   /* Check for the failure */
   if (E_OK == Mcu_PbistRun(PBIST_ROM_PBIST, PBIST_MARCH13N_DP))
   {
      /* no failure was indicated even if the march13n algorithm was run on a ROM */
      Mcu_SafetyInitErrorCbk(MCU_PBIST_SELF_CHECK_ERROR);
   }
   else
   {
      /* Do nothing */
    }
}
#endif /* STD_ON == MCU_PBIST_SELFTEST */

#if(0x00000000U != PERIPHERAL_RAM_INIT)
/*********************************************************************************************************************
 * Function name:  Mcu_MemoryInit(void)
 *********************************************************************************************************************/
/** \brief  Local function to perform RAM initialization via Hardware
 *
 *  Local function to perform RAM initialization via Hardware
 *
 * \param[in] ram : Ram sections to be initialized
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit2
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_MemoryInit(uint32 ram)
{
   /* Enable Memory Hardware Initialization */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->minitgcr = 0xAU;

   /* Enable Memory Hardware Initialization for selected RAM's */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->msinena = ram;

   /* Wait until Memory Hardware Initialization complete */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 28 D <APPROVED> "Wait Hardware to report memory initialization is completed" */
   /*SAFETYMCUSW 134 S <APPROVED> "Wait Hardware to report memory initialization is completed" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   while((MCU_SYS1_REG_BASE->mstcgstat & 0x00000100U) != 0x00000100U)
   {

   }

   /* Disable Memory Hardware Initialization */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->minitgcr = 0x5U;

}
#endif /* 0x00000000U != PERIPHERAL_RAM_INIT */

#if((0x00000000U != DUAL_PORT_RAM_GROUP_PBIST)   ||  \
    (0x00000000U != SINGLE_PORT_RAM_GROUP_PBIST) ||  \
    (STD_ON == MCU_PBIST_SELFTEST))
/*********************************************************************************************************************
 * Function name:  Mcu_PbistRun(uint32 raminfoL, Mcu_PbistAlgoType algomask)
 *********************************************************************************************************************/
/** \brief  Local function to perform PBIST
 *
 *  Local function to perform PBIST
 *
 * \param[in] raminfoL : Ram sections to be tested
 * \param[in] algomask : PBIST algorithm
 * \param[out] None
 * \pre This function is called from Mcu_SystemInit2 and Mcu_PbistSelfCheck
 * \post None
 * \return Std_ReturnType
 * \retval E_OK: Successful test
 * \retval E_NOT_OK: Error detected
 *
 *********************************************************************************************************************/
STATIC FUNC(Std_ReturnType, MCU_CODE) Mcu_PbistRun(uint32 raminfoL, Mcu_PbistAlgoType algomask)
{
   Std_ReturnType pbistrun_return = E_NOT_OK;
   uint32 fsrf0_local;
   uint32 fsrf1_local;

   /* Enable PBIST module */
   Mcu_PbistEnable();

   /* Select all algorithms to be tested */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_PBIST_REG_BASE->algo = algomask;

   /* Select RAM groups */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_PBIST_REG_BASE->rinfol = raminfoL;

   /* Select all RAM groups */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_PBIST_REG_BASE->rinfou = 0x00000000U;

   /* ROM contents will not override RINFOx settings */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_PBIST_REG_BASE->over = 0x0U;

   /* Algorithm code is loaded from ROM */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_PBIST_REG_BASE->rom = 0x03U;

   /* Start PBIST */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_PBIST_REG_BASE->dlr = 0x14U;

   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 28 D <APPROVED> "Wait Hardware to complete PBIST" */
   /*SAFETYMCUSW 134 S <APPROVED> "Wait Hardware to complete PBIST" */
   while ((MCU_SYS1_REG_BASE->mstcgstat & 0x1U) != 0x1U)
   {
      /* Wait */
   }

   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   fsrf0_local = MCU_PBIST_REG_BASE->fsrf0;
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   fsrf1_local = MCU_PBIST_REG_BASE->fsrf1;

   if((0x00U == fsrf0_local) && (0x00U == fsrf1_local))
   {
      pbistrun_return = E_OK;
   }

   /* Disable PBIST module */
   Mcu_PbistDisable();

   return(pbistrun_return);
}

/*********************************************************************************************************************
 * Function name:  Mcu_PbistEnable(void)
 *********************************************************************************************************************/
/** \brief  Enable PBIST module
 *
 *  Enable PBIST module
 *
 * \param[in] None
 * \param[out] None
 * \pre None
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_PbistEnable(void)
{
   /* PBIST ROM clock frequency = HCLK frequency /2 */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_SYS1_REG_BASE->mstgcr |= 0x00000100U;

   /* Enable PBIST controller */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_SYS1_REG_BASE->msinena = 0x01U;

   /* clear MSTGENA field */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_SYS1_REG_BASE->mstgcr &= ~(0xFU);

   /* Enable PBIST self-test */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_SYS1_REG_BASE->mstgcr |= 0xAU;

   /* wait up to 64 VBUS clock cycles, based on HCLK to VCLK ratio */
   Mcu_WaitClockCycles(64U);

   /* Enable PBIST clocks and ROM clock */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_PBIST_REG_BASE->pact = 0x03U;

}

/*********************************************************************************************************************
 * Function name:  Mcu_PbistDisable(void)
 *********************************************************************************************************************/
/** \brief  Disable PBIST module
 *
 *  Enable PBIST module
 *
 * \param[in] None
 * \param[out] None
 * \pre None
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_PbistDisable(void)
{
   /* Disable PBIST clocks and ROM clock */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_PBIST_REG_BASE->pact = 0x0U;

   /* Disable PBIST */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_SYS1_REG_BASE->mstgcr &= ~(0xFU);

   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   MCU_SYS1_REG_BASE->mstgcr |= 0x5U;
}

#endif /* PBIST required */

/*********************************************************************************************************************
 * Function name:  Mcu_CpuIdle(void)
 *********************************************************************************************************************/
/** \brief  Local function to suspend execution
 *
 *  Local function to suspend execution
 *
 * \param[in] None
 * \param[out] None
 * \pre None
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_CpuIdle(void)
{
   asm(" WFI");
   asm(" NOP");
}

#if((0x00000000U != DUAL_PORT_RAM_GROUP_PBIST)   ||  \
    (0x00000000U != SINGLE_PORT_RAM_GROUP_PBIST) ||  \
    (STD_ON == MCU_PBIST_SELFTEST)               ||  \
    (STD_ON == MCU_CPU_SELFTEST))
/*********************************************************************************************************************
 * Function name:  Mcu_WaitClockCycles(uint32 cycles)
 *********************************************************************************************************************/
/** \brief  Local function to delay execution by the desired cpu cycles
 *
 *  Local function to delay execution by the desired cpu cycles
 *
 * \param[in] cycles : CPU cycles
 * \param[out] None
 * \pre None
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_WaitClockCycles(uint32 cycles)
{
   volatile VAR(uint32, MCU_VAR) i;

   /*SAFETYMCUSW 134 S MR:12.2 <APPROVED> "Volatile variable used to avoid optimization" */
   /*SAFETYMCUSW 134 S MR:12.2 <APPROVED> "Volatile variable used to avoid optimization" */
   for (i=0U; i<cycles; i++)
   {

   }
}
#endif

/*********************************************************************************************************************
 * Function name:  Mcu_EnterDozeMode(void)
 *********************************************************************************************************************/
/** \brief  Local function to enter Doze Mode
 *
 *  Local function to enter Doze Mode
 *
 * \param[in] None
 * \param[out] None
 * \pre None
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_EnterDozeMode(void)
{
   /* Set Bank Grace Period */
   MCU_FLS_REG_BASE->fbac |= BANK_ACT_GRACE_PERIOD;

   /* Set Flash Banks to sleep mode */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FLS_REG_BASE->fbfallback = 0U;

   /* Set Flash Pump to sleep mode */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FLS_REG_BASE->fpac1 = 0U;

   /* Disable Clock Monitoring */
   MCU_SYS1_REG_BASE->clktest |= 0x01000000U;
   MCU_SYS1_REG_BASE->clktest &= 0xFDFFFFFFU;

   /* Disable the all clock sources except main oscillator */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->csdisset = ((MCU_CLRALL_CLKSRC) &
                                  (~MCU_CLR_MAIN_OSC));

   /* Disable all clock domains except RTI */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->cddisset = ((MCU_CLRALL_CLKDM) &
                                  (~MCU_CLR_RTICLK1));

   /* Core enters low power mode */
   Mcu_CpuIdle();
}

/*********************************************************************************************************************
 * Function name:  Mcu_EnterSnoozeMode(void)
 *********************************************************************************************************************/
/** \brief  Local function to enter Snooze Mode
 *
 *  Local function to enter Snooze Mode
 *
 * \param[in] None
 * \param[out] None
 * \pre None
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_EnterSnoozeMode(void)
{
   /* Set Bank Grace Period */
   MCU_FLS_REG_BASE->fbac |= BANK_ACT_GRACE_PERIOD;

   /* Set Flash Banks to sleep mode */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FLS_REG_BASE->fbfallback = 0U;

   /* Set Flash Pump to sleep mode */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FLS_REG_BASE->fpac1 = 0U;

   /* Disable Clock Monitoring */
   MCU_SYS1_REG_BASE->clktest |= 0x01000000U;
   MCU_SYS1_REG_BASE->clktest &= 0xFDFFFFFFU;

   /* Disable all the clock sources except Low Frequency LPO */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->csdisset = ((MCU_CLRALL_CLKSRC) &
                                  (~MCU_CLR_LF));

   /* Disable all clock domains except RTI */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->cddisset = ((MCU_CLRALL_CLKDM) &
                                  (~MCU_CLR_RTICLK1));

   /* Core enters low power mode */
   Mcu_CpuIdle();
}

/*********************************************************************************************************************
 * Function name:  Mcu_EnterSleepMode(void)
 *********************************************************************************************************************/
/** \brief  Local function to enter Sleep Mode
 *
 *  Local function to enter Sleep Mode
 *
 * \param[in] None
 * \param[out] None
 * \pre None
 * \post None
 * \return None
 * \retval None
 *
 *********************************************************************************************************************/
STATIC FUNC(void, MCU_CODE) Mcu_EnterSleepMode(void)
{
   /* Set Bank Grace Period */
   MCU_FLS_REG_BASE->fbac |= BANK_ACT_GRACE_PERIOD;

   /* Set Flash Banks to sleep mode */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FLS_REG_BASE->fbfallback = 0U;

   /* Set Flash Pump to sleep mode */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_FLS_REG_BASE->fpac1 = 0U;

   /* Disable Clock Monitoring */
   MCU_SYS1_REG_BASE->clktest |= 0x01000000U;
   MCU_SYS1_REG_BASE->clktest &= 0xFDFFFFFFU;

   /* Disable all the clock sources */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->csdisset = MCU_CLRALL_CLKSRC;

   /* Disable all the cock domains */
   /*SAFETYMCUSW 184 S <APPROVED> "Problem caused by LDRA code reformatting" */
   /*SAFETYMCUSW 440 S MR:11.3 <APPROVED> "Pointer to register definition" */
   MCU_SYS1_REG_BASE->cddisset = ((MCU_CLRALL_CLKDM) &
                                  (~MCU_CLR_VCLK2));

   /* Core enters low power mode */
   Mcu_CpuIdle();
}

#define MCU_STOP_SEC_CODE
/*SAFETYMCUSW 338 S MR:19.1 <APPROVED> "Based on Autosar Memory Map strategy" */
#include "MemMap.h"
/*********************************************************************************************************************
 *  End of File: Mcu.c
 *********************************************************************************************************************/
