/******************************************************************************* ** KPIT Technologies Limited ** ** ** ** KPIT Technologies Limited owns all the rights to this work. This ** ** work shall not be copied, reproduced, used, modified or its information ** ** disclosed without the prior written authorization of KPIT Technologies ** ** Limited. ** ** ** ** SRC-MODULE: main ** ** ** ** TARGET : All ** ** ** ** PRODUCT : Application Integrated Stack ** ** ** ** PURPOSE : This application file contains execution sequences to test ** ** the integrated stack functionality. ** ** ** ** PLATFORM DEPENDANT [yes/no]: no ** ** ** ** TO BE CHANGED BY USER [yes/no]: no ** ** ** *******************************************************************************/ /******************************************************************************* ** Revision History ** ******************************************************************************** ** Revision Date By Description ** ******************************************************************************** ** 1.0.2 09-Feb-2023 KPIT Gpt timers start function added in ** ** OsTaskAutostart_0 ** ** 1.0.1 07-Feb-2022 KPIT ErrorHook, ProtectionHook api updated ** ** OS application Hook api's newly added ** ** 1.0.0 29-Aug-2019 KPIT Initial Version ** *******************************************************************************/ /******************************************************************************* ** MISRA-C:2012 violations Section ** *******************************************************************************/ /** #section main_c_REF_1 * Violates MISRA C:2012 Rule-11.4 (Advisory),Cast between a pointer to volatile * object and an integral type. * This type of operation is required in embedded software applications where * memory mapped registers must be addressed **/ /** #section main_c_REF_2 * Violates MISRA C:2012 Rule-20.1 (Advisory),Use of #include directive * after code fragment. * Since Autosar supports use of #include directive after code fragment **/ /** #section main_c_REF_3 * Violates MISRA C:2012 Rule-2.2 (Required), This is stub being used and hence * does not affect functionality. **/ /** #section main_c_REF_4 * Violates MISRA C:2012 (Required), This is used as per Autosar and * hence does not affect functionality **/ /** #section main_c_REF_5 * Violates MISRA 2012 (Required) Rule 10.3. The value of an expression *shall not be assigned to an object with a narrower *essential type or of a different essential type category. **/ /* Violates #ref main_c_REF_1, MISRA C:2012 Rule-11.4 (Advisory) */ /* PRQA S 0303 EOF */ /* Violates #ref main_c_REF_2, MISRA C:2012 Rule-20.1 (Advisory) */ /* PRQA S 5087 EOF */ /******************************************************************************* ** Include Section ** *******************************************************************************/ #include "Stub.h" #include "Mcu.h" #include "Rte.h" #include "Can.h" #include "Fee.h" #include "Fls.h" #include "main.h" #include "Os.h" #include "BswM.h" #include "NvM.h" #include "EcuM.h" #include "Rte_Main.h" #include "CanNm_InternalTypes.h" #include "CanNm_Cfg.h" #include "ComM_Cfg.h" #include "ComM_Ram.h" #include "Rte_ComM_Type.h" #include "Rte_Type.h" #include "Stub_Port.h" #include "sys_init.h" #include "CanIf_Cbk.h" #include "SchM_Dcm.h" #include "SchM_Dem.h" #include "CanIf.h" #include "CanTp.h" #include "PduR.h" #include "Dcm.h" #include "EcuM_Cbk.h" #include "Fls_PBcfg.h" #include "SleepMode.h" #include "Fls_InternalLib.h" #include "Cdd_Nm.h" #include "Port.h" #include "Adc.h" #include "Pwm.h" #include "Dio.h" #include "Gpt.h" #include "IoHwAb.h" #include "CddSpi.h" #include "Xcp.h" #include "Wdg.h" #include "WdgCallout.h" #include "WdgM.h" #define RTE_ALLOW_CROSS_HEADER_INCLUSION #include "Rte_Report_OS_Error.h" #include "Rte_Swc_Services.h" #include "Cdd_Nm.h" #include "../Adapter/CddBoost_Adapter.h" #ifdef OS_HAS_GLIWA_T1 #include /* GLIWA KPIT OS to T1 header file */ #endif /******************************************************************************* ** Global Data Section ** *******************************************************************************/ #define APPL_START_SEC_VAR_NO_INIT_32 #include "MemMap.h" uint32 Cdd_GulRandomNumber; #define APPL_STOP_SEC_VAR_NO_INIT_32 #include "MemMap.h" #define RESET_REASON_APPL_NO_INIT_16_START #include "MemMap.h" uint16 Cdd_GusEccFaultLog; #define RESET_REASON_APPL_NO_INIT_16_STOP #include "MemMap.h" /******************************************************************************* ** Function Name : Main ** ** ** ** Service ID : None ** ** ** ** Description : Function to call all other function ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Re-entrant ** ** ** ** Input Parameters : None ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ #define APPL_START_SEC_CODE #include "MemMap.h" int main(void) { /*Required to pause OS Counter, For Debug purpose only */ SETOSCOUNTERCLOCK(TIMER0_PCLK_NO, SYSCLK_16BIT_DIVIDER, DIVIDER_NUM, DIVIDER_VALUE) MAP_SYS_INTERRUPT(CAN_SYS_INTR_NO, CAN_CPU_INTR_NO) MAP_SYS_INTERRUPT(EXT_WDG_TIMER_SYS_INTR_NO, EXT_WDG_CPU_INTR_NO) MAP_SYS_INTERRUPT(GPT_SYS_INT_TCPWM0_2, GPT_CPU_INTR_NO) MAP_SYS_INTERRUPT(GPT_SYS_INT_TCPWM0_3, IOHWABUSER_CPU_INTR_NO) MAP_SYS_INTERRUPT(SPI_SYS_INT_SCB_3, SPI_SCB_3_CPU_INTR_NO) MAP_SYS_INTERRUPT(SPI_SYS_INT_SCB_4, SPI_SCB_4_CPU_INTR_NO) Mcu_Init(&McuConf_McuModuleConfiguration_McuModuleConfiguration_0); Fls_Init(&Fls_Config_0); Fee_Init(); EcuM_Init(); return 0; } #define APPL_STOP_SEC_CODE #include "MemMap.h" #define OS_START_SEC_CODE #include "Os_MemMap.h" /******************************************************************************* ** Function Name : ErrorHook ** ** ** ** Service ID : None ** ** ** ** Description : Function to call ErrorHook ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : Error ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ void ErrorHook(StatusType Error) { if (Error != E_OS_LIMIT) { (void)Rte_Call_ppaclReportCriticalOsError_SysMon_ReportCriticalOsError(Error); } /* Violates #ref main_c_REF_3, MISRA C:2012 Rule-2.2 (Required) */ /* PRQA S 3112 1 */ #if(Mpu_Testing == App_One) /* Illegal object access*/ if (Error == E_OS_ACCESS) { if (AppGucNonTrusted == App_One) { Mpu_GucLstPduInfo.length = App_Eight; Mpu_GucLstPduInfo.sdu = &GaaNTVar[0]; Mpu_GucLstPduInfo.swPduHandle = swPduHandleValue; Mpu_GucLstPduInfo.id = 0xEF; (void)Can_Write(20, (const Can_PduType *) &Mpu_GucLstPduInfo); } else if (AppGucNonTrusted == App_Two) { Mpu_GucLstPduInfo.length = App_Eight; Mpu_GucLstPduInfo.sdu = &GaaVar[0]; Mpu_GucLstPduInfo.swPduHandle = swPduHandleValue; Mpu_GucLstPduInfo.id = 0xEF; (void)Can_Write(20, (const Can_PduType *) &Mpu_GucLstPduInfo); } else { } } #endif /* Violates #ref main_c_REF_3, MISRA C:2012 Rule-2.2 (Required) */ /* PRQA S 3112 1 */ UNUSED(Error); } #define OS_STOP_SEC_CODE #include "Os_MemMap.h" #define EcucPartition_NonTrusted_START_SEC_CODE #include "Rte_MemMap.h" /******************************************************************************* ** Function Name : ErrorHook_OsApplication_NT_0 ** ** ** ** Service ID : None ** ** ** ** Description : Function to call ErrorHook ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : Error ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ void ErrorHook_OsApplication_NT_0(StatusType Error) { /* Violates #ref main_c_REF_3, MISRA C:2012 Rule-2.2 (Required) */ /* PRQA S 3112 1 */ UNUSED(Error); } /******************************************************************************* ** Function Name : ShutdownHook_OsApplication_NT_0 ** ** ** ** Service ID : None ** ** ** ** Description : Function to call ErrorHook ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : Error ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ void ShutdownHook_OsApplication_NT_0(StatusType Fatalerror) { /* Violates #ref main_c_REF_3, MISRA C:2012 Rule-2.2 (Required) */ /* PRQA S 3112 1 */ UNUSED(Fatalerror); } /******************************************************************************* ** Function Name : StartupHook_OsApplication_NT_0 ** ** ** ** Service ID : None ** ** ** ** Description : Function to call ErrorHook ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : Error ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ void StartupHook_OsApplication_NT_0(void) { } #define EcucPartition_NonTrusted_STOP_SEC_CODE #include "Rte_MemMap.h" #define EcucPartition_Trusted_START_SEC_CODE #include "Rte_MemMap.h" /******************************************************************************* ** Function Name : ErrorHook_OsApplication_T_0 ** ** ** ** Service ID : None ** ** ** ** Description : Function to call ErrorHook ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : Error ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ void ErrorHook_OsApplication_T_0(StatusType Error) { /* Violates #ref main_c_REF_3, MISRA C:2012 Rule-2.2 (Required) */ /* PRQA S 3112 1 */ UNUSED(Error); } /******************************************************************************* ** Function Name : ShutdownHook_OsApplication_T_0 ** ** ** ** Service ID : None ** ** ** ** Description : Function to call ErrorHook ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : Error ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ void ShutdownHook_OsApplication_T_0(StatusType Fatalerror) { /* Violates #ref main_c_REF_3, MISRA C:2012 Rule-2.2 (Required) */ /* PRQA S 3112 1 */ UNUSED(Fatalerror); } /******************************************************************************* ** Function Name : StartupHook_OsApplication_T_0 ** ** ** ** Service ID : None ** ** ** ** Description : Function to call ErrorHook ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : Error ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ void StartupHook_OsApplication_T_0(void) { } #define EcucPartition_Trusted_STOP_SEC_CODE #include "Rte_MemMap.h" /******************************************************************************* ** Function Name : ProtectionHook ** ** ** ** Service ID : None ** ** ** ** Description : Function to call ProtectionHook ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : Fatalerror ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : ProtectionReturnType ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ #define OS_START_SEC_CODE #include "Os_MemMap.h" FUNC(ProtectionReturnType, OS_CODE) ProtectionHook(StatusType Fatalerror) { ProtectionReturnType LddReturnValue = PRO_IGNORE; (void)Rte_Call_ppaclReportCriticalOsError_SysMon_ReportCriticalOsError(Fatalerror); #if(Mpu_Testing == App_One) if ((Fatalerror == E_OS_PROTECTION_MEMORY) && (AppGucNonTrusted == App_One)) { if ((GaaNTVar[0] == 0xF6u) || (GaaNTVar[0] == 0xF7u)) { Mpu_GucLstPduInfo.length = App_Eight; Mpu_GucLstPduInfo.sdu = &GaaNTVar[0]; Mpu_GucLstPduInfo.swPduHandle = swPduHandleValue; Mpu_GucLstPduInfo.id = 0xEF; (void)Can_Write(20, (const Can_PduType *) &Mpu_GucLstPduInfo); } else { Mpu_GucLstPduInfo.length = App_Eight; Mpu_GucLstPduInfo.sdu = &GaaNTVar[0]; Mpu_GucLstPduInfo.swPduHandle = swPduHandleValue; Mpu_GucLstPduInfo.id = 0xEF; (void)Can_Write(20, (const Can_PduType *) &Mpu_GucLstPduInfo); } } else { Mpu_GucLstPduInfo.length = App_Eight; Mpu_GucLstPduInfo.sdu = &GaaVar[0]; Mpu_GucLstPduInfo.swPduHandle = swPduHandleValue; Mpu_GucLstPduInfo.id = 0xEF; (void)Can_Write(20, (const Can_PduType *) &Mpu_GucLstPduInfo); } #endif /* Violates #ref main_c_REF_3, MISRA C:2012 Rule-2.2 (Required) */ /* PRQA S 3112 1 */ UNUSED(Fatalerror); return(LddReturnValue); } #define OS_STOP_SEC_CODE #include "Os_MemMap.h" /******************************************************************************* ** Function Name : Task call to start AutoStart Task ** ** ** ** Service ID : None ** ** ** ** Description : Function to call ProtectionHook ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : None ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ #define RTE_START_SEC_CODE #include "Rte_MemMap.h" TASK(OsTaskAutostart_0) { InitECC(); #if(ECC_TEST == STD_ON) ECC_Fault_Injection_Test(); #endif EcuM_StartupTwo(); Cdd_StartWatchdogInWdwMode(); #ifdef OS_HAS_GLIWA_T1 T1_TraceEvent(T1_STOPWATCH_START, T1_SW_NvM_ReadAll); #endif do { Fee_MainFunction(); Fls_MainFunction(); if (Fls_JobRequest.Fls_MainFunctionTime > (sint32)ZERO) { /*Implemented as per JIRA: FLMT-960*/ Fls_JobRequest.Fls_MainFunctionTime += (sint32)TWO; } }while(Fee_GetStatus() != MEMIF_IDLE); Cdd_NvMRead(); #ifdef OS_HAS_GLIWA_T1 T1_TraceEvent(T1_STOPWATCH_STOP, T1_SW_NvM_ReadAll); #endif Cdd_DiagnosticsInit(); /* KPIT */ Cdd_GucWdgMInitialised = 1; WdgM_Init(NULL_PTR); (void)Rte_Start(); /*JIRA : HIGHIB-47 */ Gpt_StartTimer(GptConf_GptChannelConfiguration_FreeRunTimer0,0xffffffffuL); Gpt_StartTimer(GptConf_GptChannelConfiguration_TraceTimer0,0xffffffffuL); Gpt_StartTimer(GptConf_GptChannelConfiguration_CryptoTimer0,0xffffffffuL); #if(GPT_TESTING == STD_ON) Gpt_StartTimer(GptConf_GptChannelConfiguration_StpTimer0,10000); Gpt_EnableNotification(GptConf_GptChannelConfiguration_StpTimer0); #endif (void) TerminateTask(); } #define RTE_STOP_SEC_CODE #include "Rte_MemMap.h" #define RTE_START_SEC_CODE #include "Rte_MemMap.h" /******************************************************************************* ** Function Name : Cdd_MainFunction ** ** ** ** Service ID : None ** ** ** ** Description : Schedulable entity to check avalability of NM frame ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : None ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : CddSbc_SetSleepMode ** ** ** *******************************************************************************/ void Cdd_MainFunction(void) { static volatile uint16 can_swk = APP_ZERO; if (can_swk == CDD_2MS) /*2000ms*/ { can_swk++; SuspendAllInterrupts(); if (((Cdd_GblNmMessageReceived) == ((boolean)APP_ZERO)) && (ComM_GaaCurComMode[0] == COMM_NO_COMMUNICATION)) { (void)CddSpi_Stop(); (void)CddBoost_Adapter_Shutdown(); (void)CddSbc_SetSleepMode(); } ResumeAllInterrupts(); } else if (can_swk < CDD_2MS) { can_swk++; } else { } } /******************************************************************************* ** Function Name : ISR(ecc_codeflash_CPUSS_FAULT_IRQ_2_cat2) ** ** ** ** Service ID : None ** ** ** ** Description : CAT 2 ISR to handle Code Flash double bit ECC faults** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : None ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ ISR(ecc_codeflash_CPUSS_FAULT_IRQ_2_cat2) { /* Violates #ref main_c_REF_4, MISRA C:2012 (Required) */ /* PRQA S 4800 1 */ volatile stc_FAULT_STRUCT_t *ptscSYSFLT; uint32 LddFaultIdx; ptscSYSFLT = FAULT_STRUCT0; /*#violates #ref main_c_REF_5 Violates MISRA 2012 Required Rule 10.3(Required)*/ /* PRQA S 4442 1 */ LddFaultIdx = ptscSYSFLT->unSTATUS.stcField.u7IDX; if(ptscSYSFLT->unSTATUS.stcField.u1VALID == 1u) { if((LddFaultIdx == (uint32)CY_SYSFLT_FLASHC_MAIN_BUS_ERROR) || (LddFaultIdx == (uint32)CY_SYSFLT_FLASHC_MAIN_NC_ECC)) { volatile uint16* LpECCPunRetRam = (volatile uint16*)ECC_RET_RAM_VAR; *LpECCPunRetRam = ECC_RESET_REASON_VAL ; Mcu_PerformReset(); /*To do: AL*/ } } ptscSYSFLT->unINTR.u32Register |= 1UL; } /******************************************************************************* ** Function Name : Watchdog_Disable ** ** ** ** Service ID : None ** ** ** ** Description : Function to disable Watchdog ** ** ** ** Sync/Async : Sync ** ** ** ** Re-entrancy : Non-Reentrant ** ** ** ** Input Parameters : None ** ** ** ** InOut Parameters : None ** ** ** ** Output Parameters : None ** ** ** ** Return parameter : None ** ** ** ** Preconditions : None ** ** ** ** Remarks : Global Variable(s) : None ** ** Function(s) invoked : None ** ** ** *******************************************************************************/ void Watchdog_Disable(void) { /*Unlock Watchdog: Write 1 to WDT_LOCK*/ (*(volatile uint32*)0x4026C040) = (((*(volatile uint32*)0x4026C040uL) &\ ((uint32)0xFFFFFFFCuL)) | (uint32)0x00000001uL); /*Unlock Watchdog: Write 2 to WDT_LOCK*/ (*(volatile uint32*)0x4026C040) = (((*(volatile uint32*)0x4026C040uL) &\ ((uint32)0xFFFFFFFCuL)) | (uint32)0x00000002uL); /*Disable WatchDog : Write 0 to WDT_CTL register, Enable bit*/ (*(volatile uint32*)0x4026C000) &= ((uint32) 0x7FFFFFFFuL); /*lock Watchdog: Write 3 to WDT_LOCK*/ (*(volatile uint32*)0x4026C040) = (((*(volatile uint32*)0x4026C040uL) &\ ((uint32)0xFFFFFFFCuL)) | (uint32)0x00000003uL); } #define RTE_STOP_SEC_CODE #include "Rte_MemMap.h" /******************************************************************************* ** End of File ** *******************************************************************************/