/*================================================================================================== * Project : RTD AUTOSAR 4.4 * Platform : CORTEXM * Peripheral : * Dependencies : none * * Autosar Version : 4.4.0 * Autosar Revision : ASR_REL_4_4_REV_0000 * Autosar Conf.Variant : * SW Version : 0.9.0 * Build Version : S32K3_RTD_0_9_0_P02_D2107_ASR_REL_4_4_REV_0000_20210716 * * (c) Copyright 2020 - 2021 NXP Semiconductors * All Rights Reserved. * * NXP Confidential. This software is owned or controlled by NXP and may only be * used strictly in accordance with the applicable license terms. By expressly * accepting such terms or by downloading, installing, activating and/or otherwise * using the software, you are agreeing that you have read, and that you agree to * comply with and are bound by, such license terms. If you do not agree to be * bound by the applicable license terms, then you may not retain, install, * activate or otherwise use the software. ==================================================================================================*/ #ifdef __cplusplus extern "C" { #endif /*================================================================================================== * INCLUDE FILES * 1) system and project includes * 2) needed interfaces from external units * 3) internal and external interfaces from this unit ==================================================================================================*/ #include "Platform_Types.h" #include "Mcal.h" #include "system.h" #include "core_specific.h" #include "S32K344_SCB.h" #include "S32K344_MPU.h" #include "S32K344_MSCM.h" /*================================================================================================== * FILE VERSION CHECKS ==================================================================================================*/ /*================================================================================================== * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS) ==================================================================================================*/ /*================================================================================================== * LOCAL CONSTANTS ==================================================================================================*/ /*================================================================================================== * LOCAL MACROS ==================================================================================================*/ #define CM7_0 (0UL) #define CM7_1 (1UL) #define SVC_GoToSupervisor() ASM_KEYWORD("svc 0x0") #define SVC_GoToUser() ASM_KEYWORD("svc 0x1") #define S32_SCB_CPACR_CPx_MASK(CpNum) (0x3U << S32_SCB_CPACR_CPx_SHIFT(CpNum)) #define S32_SCB_CPACR_CPx_SHIFT(CpNum) (2U*((uint32)CpNum)) #define S32_SCB_CPACR_CPx(CpNum, x) (((uint32)(((uint32)(x))<CPXNUM & MSCM_CPXNUM_CPN_MASK); } #endif /*================================================================================================*/ /* * system initialization : system clock, interrupt router ... */ void SystemInit(void) { uint32 i; uint32 coreMask; uint8 regionNum = 0U; uint8 coreId = OsIf_GetCoreID(); switch(coreId) { case CM7_0: coreMask = (1UL << MSCM_IRSPRC_M7_0_SHIFT); break; case CM7_1: coreMask = (1UL << MSCM_IRSPRC_M7_1_SHIFT); break; default: coreMask = 0UL; break; } /* Configure MSCM to enable/disable interrupts routing to Core processor */ for (i = 0; i < MSCM_IRSPRC_COUNT; i++) { MSCM->IRSPRC[i] |= coreMask; } /**************************************************************************/ /* FPU ENABLE*/ /**************************************************************************/ #ifdef ENABLE_FPU /* Enable CP10 and CP11 coprocessors */ S32_SCB->CPACR |= (S32_SCB_CPACR_CPx(10U, 3U) | S32_SCB_CPACR_CPx(11U, 3U)); ASM_KEYWORD("dsb"); ASM_KEYWORD("isb"); #endif /* ENABLE_FPU */ /**************************************************************************/ /* DEFAULT MEMORY ENABLE*/ /**************************************************************************/ ASM_KEYWORD("dsb"); ASM_KEYWORD("isb"); /* Set default memory regions */ for (regionNum = 0U; regionNum < CPU_MPU_MEMORY_COUNT; regionNum++) { S32_MPU->RNR = regionNum; S32_MPU->RBAR = rbar[regionNum]; S32_MPU->RASR = rasr[regionNum]; } /* Enable MPU */ S32_MPU->CTRL |= S32_MPU_CTRL_ENABLE_MASK; ASM_KEYWORD("dsb"); ASM_KEYWORD("isb"); /**************************************************************************/ /* ENABLE CACHE */ /**************************************************************************/ sys_m7_cache_init(); } static void sys_m7_cache_init(void) { uint32 ccsidr = 0U; uint32 sets = 0U; uint32 ways = 0U; #ifdef D_CACHE_ENABLE /*init Data caches*/ S32_SCB->CSSELR = 0U; /* select Level 1 data cache */ ASM_KEYWORD("dsb"); ccsidr = S32_SCB->CCSIDR; sets = (uint32)(CCSIDR_SETS(ccsidr)); do { ways = (uint32)(CCSIDR_WAYS(ccsidr)); do { S32_SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); ASM_KEYWORD("dsb"); } while (ways-- != 0U); } while(sets-- != 0U); ASM_KEYWORD("dsb"); S32_SCB->CCR |= (uint32)SCB_CCR_DC_Msk; /* enable D-Cache */ ASM_KEYWORD("dsb"); ASM_KEYWORD("isb"); #endif #ifdef I_CACHE_ENABLE /*init Code caches*/ ASM_KEYWORD("dsb"); ASM_KEYWORD("isb"); S32_SCB->ICIALLU = 0UL; /* invalidate I-Cache */ ASM_KEYWORD("dsb"); ASM_KEYWORD("isb"); S32_SCB->CCR |= (uint32)SCB_CCR_IC_Msk; /* enable I-Cache */ ASM_KEYWORD("dsb"); ASM_KEYWORD("isb"); #endif } #define PLATFORM_STOP_SEC_CODE #include "Platform_MemMap.h" #ifdef __cplusplus } #endif