From: mahi Date: Tue, 11 Sep 2012 19:56:17 +0000 (+0200) Subject: Merge with 88ca177adfa9c286cb1f95a85e54ea11a9fec4f4 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/arc.git/commitdiff_plain/c426610dd1e53d489907fce457459c9fa83e5850?hp=c90d196d25f1e37e29487a2688778da5cc8c7c57 Merge with 88ca177adfa9c286cb1f95a85e54ea11a9fec4f4 --- diff --git a/arch/arm/arm_cm3/drivers/Mcu.c b/arch/arm/arm_cm3/drivers/Mcu.c index 075ed34c..17b391f9 100644 --- a/arch/arm/arm_cm3/drivers/Mcu.c +++ b/arch/arm/arm_cm3/drivers/Mcu.c @@ -497,7 +497,6 @@ void Mcu_SetMode(const Mcu_ModeType McuMode) //VALIDATE( ( McuMode <= Mcu_Global.config->McuNumberOfMcuModes ), MCU_SETMODE_SERVICE_ID, MCU_E_PARAM_MODE ); (void) McuMode; - /* NOT SUPPORTED */ } //------------------------------------------------------------------- diff --git a/arch/ppc/mpc55xx/drivers/Fls.c b/arch/ppc/mpc55xx/drivers/Fls.c index 9ffb2f87..adceda9d 100644 --- a/arch/ppc/mpc55xx/drivers/Fls.c +++ b/arch/ppc/mpc55xx/drivers/Fls.c @@ -548,6 +548,10 @@ void Fls_MainFunction(void) { // ( we are reading directly from flash so it makes no sense ) memcpy( (void *)Fls_Global.ramAddr, (void *) Fls_Global.flashAddr, Fls_Global.length); + if( Os_EccError ) { + + + } Fls_Global.jobResultType = MEMIF_JOB_OK; Fls_Global.status = MEMIF_IDLE; Fls_Global.jobType = FLS_JOB_NONE; diff --git a/arch/ppc/mpc55xx/drivers/Gpt.c b/arch/ppc/mpc55xx/drivers/Gpt.c index 9676cf12..d71bd691 100644 --- a/arch/ppc/mpc55xx/drivers/Gpt.c +++ b/arch/ppc/mpc55xx/drivers/Gpt.c @@ -581,82 +581,82 @@ void Gpt_DisableNotification(Gpt_ChannelType channel) #if ( GPT_WAKEUP_FUNCTIONALITY_API == STD_ON ) - void Gpt_SetMode(Gpt_ModeType mode) - { - int i; +void Gpt_SetMode(Gpt_ModeType mode) +{ + int i; - VALIDATE( (Gpt_Global.initRun == STD_ON), GPT_SETMODE_SERVIVCE_ID, GPT_E_UNINIT ); - VALIDATE( ( mode <= GPT_MODE_SLEEP ), GPT_SETMODE_SERVIVCE_ID, GPT_E_PARAM_MODE ); + VALIDATE( (Gpt_Global.initRun == STD_ON), GPT_SETMODE_SERVIVCE_ID, GPT_E_UNINIT ); + VALIDATE( ( mode <= GPT_MODE_SLEEP ), GPT_SETMODE_SERVIVCE_ID, GPT_E_PARAM_MODE ); #if defined(CFG_MPC560X) - if (mode == GPT_MODE_NORMAL) - { - PIT.PITMCR.B.MDIS = 0; - // Do NOT restart channels - } - else if (mode == GPT_MODE_SLEEP) + if (mode == GPT_MODE_NORMAL) + { + PIT.PITMCR.B.MDIS = 0; + // Do NOT restart channels + } + else if (mode == GPT_MODE_SLEEP) + { + PIT.PITMCR.B.MDIS = 0; + // Disable all but RTI + for (i= 0; i <= GPT_CHANNEL_PIT_LAST; i++) { - PIT.PITMCR.B.MDIS = 0; - // Disable all but RTI - for (i= 0; i <= GPT_CHANNEL_PIT_LAST; i++) - { - Gpt_StopTimer(i); - } + Gpt_StopTimer(i); } + } #else - if (mode == GPT_MODE_NORMAL) - { - PIT.CTRL.B.MDIS = 0; - // Do NOT restart channels - } - else if (mode == GPT_MODE_SLEEP) - { - - PIT.CTRL.B.MDIS = 1; - // Disable all but RTI - for (i= 0; i <= GPT_CHANNEL_PIT_LAST; i++) - { - Gpt_StopTimer(i); - } - } -#endif + if (mode == GPT_MODE_NORMAL) + { + PIT.CTRL.B.MDIS = 0; + // Do NOT restart channels } - - void Gpt_DisableWakeup(Gpt_ChannelType channel) + else if (mode == GPT_MODE_SLEEP) { - VALIDATE( (Gpt_Global.initRun == STD_ON), GPT_DISABLEWAKEUP_SERVICE_ID, GPT_E_UNINIT ); - VALIDATE( VALID_CHANNEL(channel), GPT_DISABLEWAKEUP_SERVICE_ID, GPT_E_PARAM_CHANNEL ); - // Only RTI have system wakeup - if (channel == GPT_CHANNEL_RTI) - { - Gpt_Global.wakeupEnabled = STD_OFF; - } - else + + PIT.CTRL.B.MDIS = 1; + // Disable all but RTI + for (i= 0; i <= GPT_CHANNEL_PIT_LAST; i++) { - // TODO: - //assert(0); + Gpt_StopTimer(i); } } +#endif +} - void Gpt_EnableWakeup(Gpt_ChannelType channel) +void Gpt_DisableWakeup(Gpt_ChannelType channel) +{ + VALIDATE( (Gpt_Global.initRun == STD_ON), GPT_DISABLEWAKEUP_SERVICE_ID, GPT_E_UNINIT ); + VALIDATE( VALID_CHANNEL(channel), GPT_DISABLEWAKEUP_SERVICE_ID, GPT_E_PARAM_CHANNEL ); + // Only RTI have system wakeup + if (channel == GPT_CHANNEL_RTI) { - VALIDATE( (Gpt_Global.initRun == STD_ON), GPT_ENABLEWAKEUP_SERVICE_ID, GPT_E_UNINIT ); - VALIDATE( VALID_CHANNEL(channel),GPT_ENABLEWAKEUP_SERVICE_ID, GPT_E_PARAM_CHANNEL ); - if (channel == GPT_CHANNEL_RTI) - { - Gpt_Global.wakeupEnabled = STD_ON; - } - else - { - // TODO: - //assert(0); - } + Gpt_Global.wakeupEnabled = STD_OFF; } - - void Gpt_Cbk_CheckWakeup(EcuM_WakeupSourceType wakeupSource) + else { + // TODO: + //assert(0); + } +} +void Gpt_EnableWakeup(Gpt_ChannelType channel) +{ + VALIDATE( (Gpt_Global.initRun == STD_ON), GPT_ENABLEWAKEUP_SERVICE_ID, GPT_E_UNINIT ); + VALIDATE( VALID_CHANNEL(channel),GPT_ENABLEWAKEUP_SERVICE_ID, GPT_E_PARAM_CHANNEL ); + if (channel == GPT_CHANNEL_RTI) + { + Gpt_Global.wakeupEnabled = STD_ON; + } + else + { + // TODO: + //assert(0); } +} + +void Gpt_Cbk_CheckWakeup(EcuM_WakeupSourceType wakeupSource) +{ + +} #endif diff --git a/arch/ppc/mpc55xx/drivers/Mcu.c b/arch/ppc/mpc55xx/drivers/Mcu.c index be6d308e..5b14c60c 100644 --- a/arch/ppc/mpc55xx/drivers/Mcu.c +++ b/arch/ppc/mpc55xx/drivers/Mcu.c @@ -677,13 +677,101 @@ void Mcu_PerformReset(void) //------------------------------------------------------------------- -void Mcu_SetMode(const Mcu_ModeType McuMode) +/** + * + * Application Notes! + * - AN3584, "MPC5510 Family Low Power Features" + * Since it's not complete also check MPC5668 + * - AN4150 , "Using Sleep Mode on the MPC5668x" and it's code + * + * + * @param LPM + */ +static void enterLowPower (Mcu_ModeType mcuMode ) +{ + uint32 timeout; + /* Set the sleep bit; following a WAIT instruction, the device will go to sleep */ + CRP.PSCR.B.SLEEP = 1; + /* enable the 1.2V internal regulator when in sleep mode only */ + CRP.PSCR.B.STOP12EN = 1; + /* 0x1 8k, 0x2 16k, 0x3 32k, 0x6 64k -- RAMs maintain power */ + CRP.PSCR.B.RAMSEL = 0x7; // Keep all 80K + + CRP.Z1VEC.R = (uint32)&McuE_LowPowerRecoverFlash; +#if defined(CFG_VLE) + CRP.VLE = 1; +#endif + + /* If we "Mcu_Wakeup()" is located in RAM, set FASTREC */ + CRP.RECPRTR.B.FASTREC = 0; + + /* Halt everything */ + SIU.HLT.R = 0x3FFFFFFF; + while((SIU.HLTACK.R != 0x3FFFFFFF) && (timeout<3000)) {} + + /* put Z0 in reset if not used for wakeup */ + CRP.Z0VEC.B.Z0RST = 1; + + // TODO: Enable_all_internal_pull_devices (PULL_DOWN); + + /* Save context and execute wait instruction. + * + * Things that matter here are + * - Z1VEC, determines where TLB0 will point. TLB0 is written with a + * value at startup that 4K aligned to this address. + * - LowPower_Sleep() will save a interrupt context so we will return + * intact. + * - For devices with little RAM we don't want to impose the alignment + * requirements there. Almost as we have to occupy a 4K block for this.. + * although the code does not take that much space. + * */ + McuE_EnterLowPower(mcuMode); + + /* Clear sleep flags to allow pads to operate */ + CRP.PSCR.B.SLEEPF = 0x1; + + +} + + +void Mcu_SetMode( Mcu_ModeType mcuMode) { VALIDATE( ( 1 == Mcu_Global.initRun ), MCU_SETMODE_SERVICE_ID, MCU_E_UNINIT ); // VALIDATE( ( McuMode <= Mcu_Global.config->McuNumberOfMcuModes ), MCU_SETMODE_SERVICE_ID, MCU_E_PARAM_MODE ); - (void) McuMode; + +#if defined(CFG_MPC5516) + if( MCU_MODE_RUN == mcuMode ) { + + } else if( MCU_MODE_SLEEP == mcuMode ) { + /* + * Follows the AN3548 from Freescale + * + */ +#if defined(USE_DMA) + Dma_StopAll(); +#endif + + + /* Set system clock to 16Mhz IRC */ + SIU.SYSCLK.B.SYSCLKSEL = 0; + + /* Put flash in low-power mode */ + // TODO + + /* Put QQADC in low-power mode */ + // TODO + + /* Set us in SLEEP mode */ + CRP.PSCR.B.SLEEP = 1; + + + enterLowPower(mcuMode); + } +#else /* NOT SUPPORTED */ + (void) McuMode; +#endif } //------------------------------------------------------------------- diff --git a/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx b/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx new file mode 100644 index 00000000..485fa902 --- /dev/null +++ b/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx @@ -0,0 +1,189 @@ +#define _ASSEMBLER_ +#include "asm_ppc.h" + + +#if defined(__CWCC__) && defined(CFG_VLE) +.section .text_vle,text_vle +#elif defined(__DCC__) + // Must be indented (diab) + .section .text_vle,x +#elif defined(__GNUC__) +.section .text +#endif + + +#define CRP_RECPTR 0xfffec058 + + .global McuE_EnterLowPower + +McuE_EnterLowPower: + subi r1, r1, 0x94 // Allocate space on stack 0x94 = 148 r2--r31 + 7 SPRs + stmw r2, 0(r1) // Save registers r2-r31 to stack + mfSRR1 r25 + mfSRR0 r26 + mfLR r27 + mfmsr r28 + mfCR r29 + mfXER r30 + mfCTR r31 + stmw r25, 0x78(r1) // Store SPR data to stack + + LOAD_ADDR_32(r4,CRP_RECPTR) + stw r1,0x0(r4) // Save stack pointer to CRP to be preserved during LPM + +/* Note! You cannot step over the wait instruction with the debugger */ + + .long 0x7C00007C // Wait instruction + + + blr + + +/* + * Low Power Vector...needs to be on 4K + 0xffc + * We only have 1 instruction before we are outside TLB0 so just jump + */ +#if defined(__GNUC__) +.section ".lowpower_vector","ax" +#elif defined(__CWCC__) +#if defined(CFG_VLE) +.section .lowpower_vector,text_vle +#else +.section .lowpower_vector,4,"rw" +#endif +#elif defined(__DCC__) + .section .text_vle,x +#endif + + .global McuE_LowPowerVector + +McuE_LowPowerVector: + b McuE_LowPowerRecoverFlash + + +#if defined(__GNUC__) +.section ".lowpower_text","ax" +#elif defined(__CWCC__) +#if defined(CFG_VLE) +.section .lowpower_text,text_vle +#else +.section .lowpower_text,4,"rw" +#endif +#elif defined(__DCC__) + .section .text_vle,x +#endif + + .extern EcuM_CheckWakeup + .global McuE_LowPowerRecoverFlash + +/* + * When we come back here only TLB0 is setup for flash and then only 4K. + * + * Debuggers: + * - WinIDEA : Hardware->Emulation Options->CPU Setup->MPC55xx->Low Power Debug + * This will make the debugger stop on the function below. + * - UDE: No support for this yet. It just runs through the "wait" instruction. + */ +McuE_LowPowerRecoverFlash: + + bl cfg_MMU + +/* Recover the stack */ + LOAD_ADDR_32(r4,CRP_RECPTR) + lwz r1,0x0(r4) // Restore stack pointer from CRP + lmw r25,0x78(r1) // Load SPR values back into GPRs + mtSRR1 r25 + mtSRR0 r26 + mtLR r27 + mtmsr r28 + mtCR r29 + mtXER r30 + mtCTR r31 // Load SPRs with GPR values + lmw r2, 0(r1) // Restore GPRs from stack + addi r1,r1,0x94 // Deallocate space on stack + +#if defined(USE_ECUM) + + /* We have no idea what made us wakeup, pass all */ + LOAD_ADDR_32(r3,0x3fffffff); // EcuM_WakeupSourceType + bl EcuM_CheckWakeup + +#endif + + + + /* branch back to Mcu_SetMode().. */ + blr + + + #if defined(CFG_VLE) + #define VLE_VAL MAS2_VLE + #else + #define VLE_VAL 0 + #endif + +#if defined(CFG_MPC5516) +#define SRAM_START 0x40000000 +#define FLASH_START 0x00000000 +#define PERIPHERAL_START 0xfff00000 +#else +#error No support for this MCU +#endif + + + cfg_MMU: + +#***************************************************/ +# setup MMU */ +#***************************************************/ + +#TLB Entry 0 = 1M Internal flash + LOAD_ADDR_32(5, 0x10000000 + (0<<16)) + mtspr SPR_MAS0,r5 + LOAD_ADDR_32(5, 0xC0000000 + MAS1_TSIZE_4M ) + mtspr SPR_MAS1,r5 + LOAD_ADDR_32(5, FLASH_START + VLE_VAL ) + mtspr SPR_MAS2,r5 + LOAD_ADDR_32(5, FLASH_START + MAS3_FULL_ACCESS ) + mtspr SPR_MAS3,r5 + msync + isync + tlbwe + isync + + +#TLB Entry 1 = Peripheral bridge and BAM + LOAD_ADDR_32(5, 0x10000000 + (1<<16)) + mtspr SPR_MAS0,r5 + LOAD_ADDR_32(5, 0xC0000000 + MAS1_TSIZE_1M) + mtspr SPR_MAS1,r5 + LOAD_ADDR_32(5, PERIPHERAL_START + VLE_VAL + MAS2_I) + mtspr SPR_MAS2,r5 + LOAD_ADDR_32(5, PERIPHERAL_START + MAS3_FULL_ACCESS ) + mtspr SPR_MAS3,r5 + msync + isync + tlbwe + isync + + +#TLB Entry 2 = External RAM. Skip this. + +#TLB Entry 3 = Internal SRAM + LOAD_ADDR_32(5, 0x10000000+(3<<16)) + mtspr SPR_MAS0,r5 + LOAD_ADDR_32(5, 0xC0000000 + MAS1_TSIZE_256K ) + mtspr SPR_MAS1,r5 + LOAD_ADDR_32(5, SRAM_START + VLE_VAL ) + mtspr SPR_MAS2,r5 + LOAD_ADDR_32(5, SRAM_START + MAS3_FULL_ACCESS ) + mtspr SPR_MAS3,r5 + msync + isync + tlbwe + isync + blr + + + + diff --git a/arch/ppc/mpc55xx/scripts/linkscript_gcc.ldf b/arch/ppc/mpc55xx/scripts/linkscript_gcc.ldf index f8f90100..146e6443 100644 --- a/arch/ppc/mpc55xx/scripts/linkscript_gcc.ldf +++ b/arch/ppc/mpc55xx/scripts/linkscript_gcc.ldf @@ -142,6 +142,15 @@ __FLS_PROG_START__ = 0; /* Must be aligned to a sector start. */ *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*); __TEXT_END = .; } > flash + +#if defined(CFG_MPC5516) + .McuE_LowPowerRecoverFlash 0x000ff000: { + *(.lowpower_text); + } + .lowpower_vector 0x000ffffc: { + *(.lowpower_vector); + } +#endif .data : { diff --git a/boards/board_common.mk b/boards/board_common.mk index f44697a0..f52e4e79 100644 --- a/boards/board_common.mk +++ b/boards/board_common.mk @@ -37,7 +37,9 @@ endif obj-$(USE_ECUM) += EcuM.o obj-$(USE_ECUM) += EcuM_Main.o obj-$(USE_ECUM) += EcuM_PBcfg.o +ifneq ($(filter EcuM_Callout_Stubs.o,$(obj-y)),) obj-$(USE_ECUM) += EcuM_Callout_Stubs.o +endif obj-$(USE_ECUM)-$(CFG_ECUM_USE_SERVICE_COMPONENT) += EcuM_ServiceComponent.o inc-$(USE_ECUM) += $(ROOTDIR)/system/EcuM vpath-$(USE_ECUM) += $(ROOTDIR)/system/EcuM @@ -59,6 +61,7 @@ inc-$(USE_DMA) += $(ROOTDIR)/$(ARCH_PATH-y)/drivers # Mcu obj-$(USE_MCU) += Mcu.o obj-$(USE_MCU) += Mcu_Cfg.o +obj-$(USE_MCU) += Mcu_Sleep.o #obj-$(CFG_MPC55XX)-$(USE_MCU) += Mcu_Exceptions.o # Flash @@ -113,7 +116,7 @@ vpath-$(USE_NVM) += $(ROOTDIR)/system/Crc obj-$(USE_NVM) += Crc_32.o obj-$(USE_NVM) += Crc_16.o -# SchM +# SchM, always find the include files. inc-y += $(ROOTDIR)/system/SchM vpath-$(USE_SCHM) += $(ROOTDIR)/system/SchM obj-$(USE_SCHM) += SchM.o diff --git a/boards/generic/EcuM_Callout_Stubs.c b/boards/generic/EcuM_Callout_Stubs.c index 28d99186..a56f1f28 100644 --- a/boards/generic/EcuM_Callout_Stubs.c +++ b/boards/generic/EcuM_Callout_Stubs.c @@ -291,7 +291,7 @@ void EcuM_AL_DriverInitThree(const EcuM_ConfigType* ConfigPtr) #endif } -void EcuM_OnEnterRUN(void) +void EcuM_OnEnterRun(void) { } diff --git a/boards/mpc5516it/build_config.mk b/boards/mpc5516it/build_config.mk index 880b8279..c3e5d74b 100644 --- a/boards/mpc5516it/build_config.mk +++ b/boards/mpc5516it/build_config.mk @@ -13,7 +13,7 @@ CFG=PPC BOOKE E200Z1 MPC55XX MPC5516 BRD_MPC5516IT # Memory + Peripherals MOD_AVAIL+=ADC DIO DMA CAN GPT LIN MCU PORT PWM WDG NVM MEMIF FEE FLS SPI EEP # System + Communication + Diagnostic -MOD_AVAIL+=CANIF CANTP LINIF COM DCM DEM DET ECUM IOHWAB KERNEL PDUR WDGM RTE J1939TP +MOD_AVAIL+=CANIF CANTP LINIF COM DCM DEM DET ECUM IOHWAB KERNEL PDUR WDGM WDGIF RTE J1939TP # Network management MOD_AVAIL+=COMM NM CANNM CANSM EA LINSM # Additional diff --git a/boards/mpc5516it/config/Wdg_Cfg.h b/boards/mpc5516it/config/Wdg_Cfg.h new file mode 100644 index 00000000..29c26c43 --- /dev/null +++ b/boards/mpc5516it/config/Wdg_Cfg.h @@ -0,0 +1,45 @@ +/* -------------------------------- Arctic Core ------------------------------ + * Arctic Core - the open source AUTOSAR platform http://arccore.com + * + * Copyright (C) 2009 ArcCore AB + * + * This source code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by the + * Free Software Foundation; See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * -------------------------------- Arctic Core ------------------------------*/ + +#ifndef WDG_CFG_H_ +#define WDG_CFG_H_ + +#include "Std_Types.h" +#include "WdgIf_Types.h" + +typedef struct +{ + uint32 ReloadValue; + uint8 ActivationBit; +}Wdg_SettingsType; + +typedef struct +{ + WdgIf_ModeType Wdg_DefaultMode; + Wdg_SettingsType WdgSettingsFast; + Wdg_SettingsType WdgSettingsSlow; + Wdg_SettingsType WdgSettingsOff; +}Wdg_ModeConfigType; + +typedef struct +{ + const Wdg_GeneralType *Wdg_General; + const Wdg_ModeConfigType *Wdg_ModeConfig; +}Wdg_ConfigType; + + extern const Wdg_GeneralType WdgGeneral; + extern const Wdg_ConfigType WdgConfig; + +#endif /* WDG_CFG_H_ */ diff --git a/boards/mpc5516it/config/Wdg_Lcfg.c b/boards/mpc5516it/config/Wdg_Lcfg.c new file mode 100644 index 00000000..b948ed69 --- /dev/null +++ b/boards/mpc5516it/config/Wdg_Lcfg.c @@ -0,0 +1,52 @@ +/* -------------------------------- Arctic Core ------------------------------ + * Arctic Core - the open source AUTOSAR platform http://arccore.com + * + * Copyright (C) 2009 ArcCore AB + * + * This source code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by the + * Free Software Foundation; See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * -------------------------------- Arctic Core ------------------------------*/ + +#include "Wdg.h" + +const Wdg_ModeConfigType WdgModeConfig = +{ + .Wdg_DefaultMode = WDGIF_OFF_MODE, + .WdgSettingsFast = + { + .ReloadValue = 0x200, + .ActivationBit = 1, + }, + .WdgSettingsSlow = + { + .ReloadValue = 0x7D00, + .ActivationBit = 1, + }, + .WdgSettingsOff = + { + .ReloadValue = 0x7D00, + .ActivationBit = 0, + }, +}; + +const Wdg_GeneralType WdgGeneral = +{ + .Wdg_Index = 1, + .Wdg_TriggerLocationPtr = Wdg_Trigger, + .Wdg_SetModeLocationPtr = Wdg_SetMode, +}; + + +const Wdg_ConfigType WdgConfig = +{ + .Wdg_General = &WdgGeneral, + .Wdg_ModeConfig = &WdgModeConfig, +}; + + diff --git a/include/EcuM.h b/include/EcuM.h index f7455885..767eb57f 100644 --- a/include/EcuM.h +++ b/include/EcuM.h @@ -80,8 +80,8 @@ #define ECUM_AR_MINOR_VERSION 2 #define ECUM_AR_PATCH_VERSION 2 -#include "EcuM_Types.h" #include "EcuM_Cfg.h" +#include "EcuM_Types.h" #include "EcuM_Cbk.h" #if defined(USE_COM) @@ -92,7 +92,6 @@ #include "ComM.h" #endif - /** @name Error Codes */ //@{ #define ECUM_E_NOT_INITIATED (0x10) @@ -121,6 +120,7 @@ #define ECUM_GETAPPMODE_ID (0x11) #define ECUM_SELECT_BOOTARGET_ID (0x12) #define ECUM_GET_BOOTARGET_ID (0x13) +#define ECUM_VALIDATE_WAKEUP_EVENT_ID 0x14 #define ECUM_MAINFUNCTION_ID (0x18) #define ECUM_COMM_HASREQUESTEDRUN_ID (0x1b) #define ECUM_ARC_STARTUPTWO_ID (0x20) @@ -168,7 +168,7 @@ Std_ReturnType EcuM_GetShutdownTarget(EcuM_StateType* shutdownTarget, uint8* sle Std_ReturnType EcuM_GetLastShutdownTarget(EcuM_StateType* shutdownTarget, uint8* sleepMode); EcuM_WakeupSourceType EcuM_GetPendingWakeupEvents(void); -void EcuM_ClearWakeupEvent(EcuM_WakeupSourceType sources); +void EcuM_ClearWakeupEvent(EcuM_WakeupSourceType source ); EcuM_WakeupSourceType EcuM_GetValidatedWakeupEvents(void); EcuM_WakeupSourceType EcuM_GetExpiredWakeupEvents(void); EcuM_WakeupStatusType EcuM_GetStatusOfWakeupSource(EcuM_WakeupSourceType sources); @@ -183,5 +183,6 @@ void EcuM_SetWakeupEvent(EcuM_WakeupSourceType sources); void EcuM_MainFunction(void); + #endif /*ECUM_H_*/ /** @} */ diff --git a/include/EcuM_Cbk.h b/include/EcuM_Cbk.h index 06f18c3e..2b07f355 100644 --- a/include/EcuM_Cbk.h +++ b/include/EcuM_Cbk.h @@ -35,7 +35,7 @@ void EcuM_ErrorHook(Std_ReturnType reason); void EcuM_OnRTEStartup(void); -void EcuM_OnEnterRUN(void); +void EcuM_OnEnterRun(void); void EcuM_OnExitRun(void); void EcuM_OnExitPostRun(void); @@ -45,13 +45,13 @@ void EcuM_OnGoOffOne(void); void EcuM_OnGoOffTwo(void); void EcuM_EnableWakeupSources(EcuM_WakeupSourceType wakeupSource); -void Ecum_DisableWakeupSources(EcuM_WakeupSourceType wakeupSource); +void EcuM_DisableWakeupSources(EcuM_WakeupSourceType wakeupSource); void EcuM_GenerateRamHash(void); uint8 EcuM_CheckRamHash(void); void EcuM_AL_SwitchOff(void); -void Ecum_AL_DriverRestart(void); +void EcuM_AL_DriverRestart(void); void EcuM_StartWakeupSources(EcuM_WakeupSourceType wakeupSource); void EcuM_CheckValidation(EcuM_WakeupSourceType wakeupSource); diff --git a/include/EcuM_Types.h b/include/EcuM_Types.h index 9dbc7df7..860044c2 100644 --- a/include/EcuM_Types.h +++ b/include/EcuM_Types.h @@ -35,6 +35,7 @@ #include "Rte_Type.h" #endif + #if !defined(_DEFINED_TYPEDEF_FOR_EcuM_StateType_) /** Possible states */ typedef enum { @@ -66,12 +67,14 @@ typedef enum { #endif + #if !defined(_DEFINED_TYPEDEF_FOR_EcuM_UserType_) typedef uint8 EcuM_UserType; #define _DEFINED_TYPEDEF_FOR_EcuM_UserType_ #endif +#if 0 enum { /** Internal reset of µC (bit 2). * The internal reset typically only resets the µC @@ -102,8 +105,11 @@ enum { ECUM_WKSOURCE_RESET = 0x02 }; + typedef uint32 EcuM_WakeupSourceType; +#endif + typedef enum { ECUM_WKSTATUS_NONE = 0, /**< No pending wakeup event was detected */ @@ -114,11 +120,12 @@ typedef enum typedef enum { - ECUM_WWKACT_RUN = 0, /**< Initialization into RUN state */ + ECUM_WKACT_RUN = 0, /**< Initialization into RUN state */ ECUM_WKACT_TTII = 2, /**< Execute time triggered increased inoperation protocol and shutdown */ ECUM_WKACT_SHUTDOWN = 3 /**< Immediate shutdown */ } EcuM_WakeupReactionType; + #if !defined(_DEFINED_TYPEDEF_FOR_EcuM_BootTargetType_) typedef enum { @@ -128,5 +135,44 @@ typedef enum #define _DEFINED_TYPEDEF_FOR_EcuM_BootTargetType_ #endif + +#if defined(USE_WDGM) +#include "WdgM.h" +#endif + +#include "Mcu.h" + +#if defined(USE_WDGM) +typedef struct EcuM_WdgM +{ + WdgM_SupervisedEntityIdType EcuMSupervisedEntity; + WdgM_ModeType EcuMWdgMWakeupMode; + WdgM_ModeType EcuMWdgMStartupMode; + WdgM_ModeType EcuMWdgMRunMode; + WdgM_ModeType EcuMWdgMPostRunMode; + WdgM_ModeType EcuMWdgMShutdownMode; +} EcuM_WdgMType; +#endif + +typedef struct EcuM_WakeupSourceConfig { + EcuM_WakeupSourceType EcuMWakeupSourceId; + uint32 EcuMValidationTimeout; + Mcu_ResetType EcuMResetReason; + boolean EcuMWakeupSourcePolling; + uint8 EcuMComMChannel; +} EcuM_WakeupSourceConfigType; + +typedef struct EcuM_SleepMode +{ + uint8 EcuMSleepModeId; + EcuM_WakeupSourceType EcuMWakeupSourceMask; + Mcu_ModeType EcuMSleepModeMcuMode; +#if defined(USE_WDGM) + WdgM_ModeType EcuMSleepModeWdgMMode; +#endif + } EcuM_SleepModeType; + + + #endif /* ECUM_TYPES_H_ */ /** @} */ diff --git a/include/Gpt.h b/include/Gpt.h index 9879842d..f0ce66db 100644 --- a/include/Gpt.h +++ b/include/Gpt.h @@ -13,6 +13,19 @@ * for more details. * -------------------------------- Arctic Core ------------------------------*/ + +/* + * Include structure: + * + * + * Gpt.h + * ^ + * | + * `---------- Gpt_xxx.c ---> Memmap.h + * + * + */ + /** @addtogroup Gpt GPT Driver * @{ */ @@ -24,7 +37,7 @@ #define GPT_H_ #include "Std_Types.h" -//#include "EcuM.h" mahi: What for ??? + /** @name Error Codes */ //@{ @@ -54,9 +67,6 @@ #define GPT_CBK_CHECKWAKEUP_SERVICE_ID 0x0c //@} -/** Channel id type */ -typedef uint8_t Gpt_ChannelType; - /** Channel time value type */ typedef uint32_t Gpt_ValueType; @@ -73,6 +83,8 @@ typedef enum GPT_MODE_SLEEP } Gpt_ModeType; +/** Channel id type */ +typedef uint8_t Gpt_ChannelType; #define GPT_VENDOR_ID 1 #define GPT_MODULE_ID 1 @@ -85,7 +97,14 @@ typedef enum #define GPT_AR_MINOR_VERSION 2 #define GPT_AR_PATCH_VERSION 1 -#include "Gpt_Cfg.h" +//#if (GPT_REPORT_WAKEUP_SOURCE==STD_ON) +#include "EcuM_Cbk.h" /* @req 4.0.3/GPT271 */ +//#endif + +/* Needs Gpt_ConfigType */ +#include "Gpt_Cfg.h" /* @req 4.0.3/GPT259 */ + +/* The config needs EcuM_WakeupSourceType from EcuM */ #if (GPT_VERSION_INFO_API == STD_ON) #define Gpt_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,GPT) diff --git a/include/Gpt_ConfigTypes.h b/include/Gpt_ConfigTypes.h index 33b07881..9f9680b5 100644 --- a/include/Gpt_ConfigTypes.h +++ b/include/Gpt_ConfigTypes.h @@ -23,7 +23,10 @@ typedef struct { void (*GptNotification)(); uint8 GptNotificationPriority; uint32 GptChannelPrescale; - boolean GptEnableWakeup; + boolean GptEnableWakeup; // ? +#if (GPT_REPORT_WAKEUP_SOURCE == STD_ON) + EcuM_WakeupSourceType GptWakeupSource; +#endif } Gpt_ConfigType; #endif /* GPT_CONFIGTYPES_H */ diff --git a/include/Mcu.h b/include/Mcu.h index 2989a9e3..0ffa2a5b 100644 --- a/include/Mcu.h +++ b/include/Mcu.h @@ -76,10 +76,6 @@ typedef enum { } Mcu_PllStatusType; -typedef enum { - MCU_MODE_NORMAL=0 -} Mcu_ModeType; - //TODO typedef uint8_t Mcu_RamSectionType; @@ -195,5 +191,8 @@ uint32_t McuE_GetSystemClock( void ); uint32_t McuE_GetPeripheralClock( McuE_PeriperalClock_t type ); #endif +void McuE_EnterLowPower( int mode ); +void McuE_LowPowerRecoverFlash( void ); + #endif /*MCU_H_*/ /** @} */ diff --git a/include/WdgM.h b/include/WdgM.h index ad12445d..dcafadd6 100644 --- a/include/WdgM.h +++ b/include/WdgM.h @@ -26,6 +26,11 @@ #define WDGM_SW_PATCH_VERSION 0 #include "Std_Types.h" +/* "forward" declare types due to circular dependency chain */ +typedef uint8 WdgM_SupervisedEntityIdType; +typedef uint8 WdgM_ModeType; + + #include "WdgM_Cfg.h" // API Service ID's diff --git a/include/WdgM_ConfigTypes.h b/include/WdgM_ConfigTypes.h index cc85acd8..d5fef146 100644 --- a/include/WdgM_ConfigTypes.h +++ b/include/WdgM_ConfigTypes.h @@ -100,17 +100,21 @@ typedef struct const float32 WdgM_TriggerCycle; }WdgM_ActivationSchMType; +#if (WDGM_GPT_USED == STD_ON) typedef struct { const uint32 WdgM_GptCycle; const Gpt_ChannelType WdgM_GptChannelRef; }WdgM_ActivationGPTType; +#endif typedef struct { const boolean WdgM_IsGPTActivated; const WdgM_ActivationSchMType WdgM_ActivationSchM; +#if (WDGM_GPT_USED == STD_ON) const WdgM_ActivationGPTType WdgM_ActivationGPT; +#endif }WdgM_ActivationType; typedef struct diff --git a/include/ppc/asm_ppc.h b/include/ppc/asm_ppc.h index ddf1c518..cd434b78 100644 --- a/include/ppc/asm_ppc.h +++ b/include/ppc/asm_ppc.h @@ -60,6 +60,14 @@ #define SPR_SPEFSCR 512 #define SPR_MCSR 572 +#define SPR_MAS0 624 +#define SPR_MAS1 625 +#define SPR_MAS2 626 +#define SPR_MAS3 627 +#define SPR_MAS4 628 +#define SPR_MAS6 630 + + #define ESR_PTR (1<<(38-32)) #define SPR_XER 1 @@ -67,6 +75,34 @@ #define INTC_SSCIR7 0xFFF48027 +/* MAS bits */ +#define MAS1_TSIZE_4K (1<<8) +#define MAS1_TSIZE_16K (2<<8) +#define MAS1_TSIZE_64K (3<<8) +#define MAS1_TSIZE_256K (4<<8) +#define MAS1_TSIZE_1M (5<<8) +#define MAS1_TSIZE_4M (6<<8) +#define MAS1_TSIZE_16M (7<<8) +#define MAS1_TSIZE_64M (8<<8) +#define MAS1_TSIZE_256M (8<<9) + +#define MAS2_VLE (1<<5) +#define MAS2_W (1<<4) +#define MAS2_I (1<<3) +#define MAS2_M (1<<2) +#define MAS2_G (1<<1) +#define MAS2_E (1<<0) + +#define MAS3_UX (1<<5) +#define MAS3_SX (1<<4) +#define MAS3_UW (1<<3) +#define MAS3_SW (1<<2) +#define MAS3_UR (1<<1) +#define MAS3_SR (1<<0) + +#define MAS3_FULL_ACCESS (MAS3_UX+MAS3_UW+MAS3_UR+MAS3_SX+MAS3_SW+MAS3_SR) + + #if defined(_ASSEMBLER_) /* * PPC vs VLE assembler: diff --git a/system/EcuM/EcuM.c b/system/EcuM/EcuM.c index 48b48ea8..a7129716 100644 --- a/system/EcuM/EcuM.c +++ b/system/EcuM/EcuM.c @@ -13,8 +13,59 @@ * for more details. * -------------------------------- Arctic Core ------------------------------*/ + +/** @reqSettings DEFAULT_SPECIFICATION_REVISION=3.1.5 */ + +/* ----------------------------[information]----------------------------------*/ +/* + * Author: ?+mahi + * + * Part of Release: + * 3.1.5 + * + * Description: + * Implements the Can Driver module + * + * Support: + * General Have Support + * ------------------------------------------- + * ECUM_TTII_ENABLED N + * ECUM_DEV_ERROR_DETECT Y + * ECUM_VERSION_INFO_API Y + * ECUM_INCLUDE_DEM N (controlled by USE_x macro's instead) + * ECUM_INCLUDE_NVRAM_MGR N (controlled by USE_x macro's instead) + * ECUM_INLCUDE_DET N (controlled by USE_x macro's instead) + * ECUM_MAIN_FUNCTION_PERDIOD Y + * ECUM_TTII_WKSOURCE N + * + * Configuration Have Support + * ------------------------------------------- + * ECUM_SLEEP_ACTIVITY_PERIOD ? + * ECUM_CONFIGCONSISTENCY_HASH N + * ECUM_RUN_SELF_REQUEST_PERIOD ? + * ECUM_NVRAM_WRITEALL_TIMEOUT Y + * ECUM_DEFAULT_APP_MODE ? + * + * + * DefaultShutdownTarget + * ------------------------------------------- + * ECUM_DEFAULT_SHUTDOWN_TARGET N + * + * + * Things to start with: + * - EcuM2181 + * - EcuM2861 , Watchdog + * - ComM_EcuM_RunModeIndication() not called, See Figure 8 (Seems that the ComM does not do much either) + * + * + * + */ + //lint -emacro(904,VALIDATE,VALIDATE_RV,VALIDATE_NO_RV) //904 PC-Lint exception to MISRA 14.7 (validate macros). + +/* ----------------------------[includes]------------------------------------*/ + #include "Std_Types.h" #include "EcuM.h" #include "Modules.h" @@ -42,9 +93,19 @@ #endif +/* ----------------------------[private define]------------------------------*/ +/* ----------------------------[private macro]-------------------------------*/ +/* ----------------------------[private typedef]-----------------------------*/ +/* ----------------------------[private function prototypes]-----------------*/ +/* ----------------------------[private variables]---------------------------*/ EcuM_GlobalType internal_data; +/* ----------------------------[private functions]---------------------------*/ + + +/* ----------------------------[public functions]----------------------------*/ + #if !defined(USE_DET) && defined(ECUM_DEV_ERROR_DETECT) #error EcuM configuration error. DET is not enabled when ECUM_DEV_ERROR_DETECT is set #endif @@ -66,6 +127,7 @@ void EcuM_Init( void ) // Determine PostBuild configuration internal_data.config = EcuM_DeterminePbConfiguration(); + // TODO: Check consistency of PB configuration // Initialize drivers needed before the OS-starts @@ -124,6 +186,10 @@ void EcuM_StartupTwo(void) SchM_Init(); #endif +#if defined(USE_WDGM) + WdgM_SetMode(internal_data.config->EcuMWdgMConfig->EcuMWdgMStartupMode); +#endif + // Initialize drivers that don't need NVRAM data EcuM_AL_DriverInitTwo(internal_data.config); @@ -302,12 +368,45 @@ Std_ReturnType EcuM_ReleaseRUN(EcuM_UserType user) return E_OK; } +/** + * + */ void EcuM_KillAllRUNRequests( void ) { /* NOT IMPLEMENTED */ } + +/** + * + * @param sources + */ void EcuM_SetWakeupEvent(EcuM_WakeupSourceType sources) { - /* NOT IMPLEMENTED */ + /* @req 3.1.5/EcuM2826 The function exists */ + /* @req 3.1.5/EcuM2171 */ + + /* @req 3.1.5/EcuM2867 */ +#if ( ECUM_DEV_ERROR_DETECT == STD_ON ) + { + EcuM_WakeupSourceType wkSource; + const EcuM_SleepModeType *sleepModePtr; + + sleepModePtr = &internal_data.config->EcuMSleepModeConfig[internal_data.sleep_mode]; + wkSource = sleepModePtr->EcuMWakeupSourceMask; + + if( !((sources | wkSource) == wkSource)) { + Det_ReportError(MODULE_ID_ECUM, 0, ECUM_VALIDATE_WAKEUP_EVENT_ID, ECUM_E_UNKNOWN_WAKEUP_SOURCE ); + return; + } + } +#endif + + + /* @req 3.1.5/EcuM1117 */ + internal_data.wakeupEvents |= sources; + + /* @req 3.1.5/EcuM2707 @req 3.1.5/EcuM2709*/ +// internal_data.wakeupTimer = ECUM_VALIDATION_TIMEOUT; + } #if defined(USE_COMM) || defined(USE_ECUM_COMM) @@ -360,3 +459,55 @@ Std_ReturnType EcuM_ReleasePOST_RUN(EcuM_UserType user) return E_OK; } +/* + * TODO: Don't yet understand the use + */ +void EcuM_ClearWakeupEvent( EcuM_WakeupSourceType source ) +{ + switch(source) { + case ECUM_WKSTATUS_NONE: + /* Seems quite pointless */ + break; + case ECUM_WKSTATUS_PENDING: + break; + case ECUM_WKSTATUS_VALIDATED: + break; + case ECUM_WKSTATUS_EXPIRED: + break; + default: + break; + } +} + +/** + * Get the pending wakeup events. + * + * @return + */ +EcuM_WakeupSourceType EcuM_GetPendingWakeupEvents( void ) { + /* @req 3.1.5/EcuM2827 API + * @req 3.1.5/EcuM2172 Callable from interrupt context + * */ + + /* @req 3.1.5/EcuM1156 */ + return internal_data.wakeupEvents; + +} + + +void EcuM_CheckValidation(EcuM_WakeupSourceType wakeupSource) { + /* Used only if CanIf is used ? CanIf_Checkvalidation(wakeupSource) */ + (void)wakeupSource; +} + + +EcuM_WakeupSourceType EcuM_GetValidatedWakeupEvents( void ) { + // TODO: + return 0; +} + +EcuM_WakeupStatusType EcuM_GetStatusOfWakeupSource( EcuM_WakeupSourceType sources ) { + return 0; +} + + diff --git a/system/EcuM/EcuM_Internals.h b/system/EcuM/EcuM_Internals.h index 4139c4c6..d1dd4e4e 100644 --- a/system/EcuM/EcuM_Internals.h +++ b/system/EcuM/EcuM_Internals.h @@ -67,6 +67,8 @@ typedef struct #endif uint32 run_requests; uint32 postrun_requests; + EcuM_WakeupSourceType wakeupEvents; + uint32 wakeupTimer; } EcuM_GlobalType; extern EcuM_GlobalType internal_data; diff --git a/system/EcuM/EcuM_Main.c b/system/EcuM/EcuM_Main.c index fa586383..128a871d 100644 --- a/system/EcuM/EcuM_Main.c +++ b/system/EcuM/EcuM_Main.c @@ -33,6 +33,8 @@ static uint32 internal_data_go_off_one_state_timeout = 0; static NvM_RequestResultType writeAllResult; #endif +static uint32 internal_data_go_sleep_state_timeout = 0; + #ifdef CFG_ECUM_USE_SERVICE_COMPONENT /** @req EcuM2749 */ static Rte_ModeType_EcuM_Mode currentMode; @@ -89,19 +91,136 @@ void set_current_state(EcuM_StateType state) { #endif +/** + * RUN II entry + * - Called from EcuM_StartupTwo() + * - Called from + * + * + */ void EcuM_enter_run_mode(void){ set_current_state(ECUM_STATE_APP_RUN); - EcuM_OnEnterRUN(); /** @req EcuM2308 */ - //TODO: Call ComM_EcuM_RunModeIndication(NetworkHandleType Channel) for all channels that have requested run. + EcuM_OnEnterRun(); /** @req EcuM2308 */ + +#if defined(USE_WDGM) + /* This seems strange, should be in FW instead */ + WdgM_SetMode(internal_data.config->EcuMWdgMConfig->EcuMWdgMRunMode); +#endif + +#if defined(USE_COMM) + /* + * Loop over all channels that have requested run, + * ie EcuM_ComM_RequestRUN() + */ + { + uint32 cMask = internal_data.run_comm_requests; + uint8 channel; + + for (; cMask; cMask &= ~(1ul << channel)) { + channel = ilog2(cMask); + ComM_EcuM_RunModeIndication(channel); + } + } +#endif + + /* We have a configurable minimum time (EcuMRunMinimumDuration) + * we have to stay in RUN state */ internal_data_run_state_timeout = internal_data.config->EcuMRunMinimumDuration / ECUM_MAIN_FUNCTION_PERIOD; /** @req EcuM2310 */ } //--------- Local functions ------------------------------------------------------------------------------------------------ + + +/** + * Enter GO SLEEP state ( soon in state ECUM_STATE_GO_SLEEP) + */ static inline void enter_go_sleep_mode(void){ + EcuM_WakeupSourceType wakeupSource; set_current_state(ECUM_STATE_GO_SLEEP); + EcuM_OnGoSleep(); + +#if defined(USE_NVM) + NvM_WriteAll(); + + /* Start timer */ + internal_data_go_sleep_state_timeout = internal_data.config->EcuMNvramWriteAllTimeout / ECUM_MAIN_FUNCTION_PERIOD; + + wakeupSource = EcuM_GetPendingWakeupEvents(); +#else + wakeupSource = EcuM_GetPendingWakeupEvents(); +#endif +} + +/** + In GO SLEEP state (in state ECUM_STATE_GO_SLEEP) + */ +static void in_state_goSleep( void ) { + + /* We only wait for NvM_WriteAll() for so long */ + if (internal_data_go_sleep_state_timeout){ + internal_data_go_sleep_state_timeout--; + } + + if( (internal_data_go_sleep_state_timeout == 0) ) { + /* + * We should go to sleep , enable source that should wake us + * */ + uint32 cMask; + uint8 source; + const EcuM_SleepModeType *sleepModePtr; + + /* Get the current sleep mode */ + + sleepModePtr = &internal_data.config->EcuMSleepModeConfig[internal_data.sleep_mode]; + + cMask = sleepModePtr->EcuMWakeupSourceMask; + + /* Loop over the WKSOURCE for this sleep mode */ + for (; cMask; cMask &= ~(1ul << source)) { + source = ilog2(cMask); + /* @req 3.1.5/ECUM2389 */ + EcuM_EnableWakeupSources( 1<< source ); + +#if defined(WDGM) + WdgM_SetMode(sleepModePtr->EcuMSleepModeWdgMMode); +#endif + + /* Let no one else run */ + GetResource(RES_SCHEDULER); + } + + } else if( EcuM_GetPendingWakeupEvents() != 0 ) { + /* We have pending wakeup events, need to startup again */ +#if defined(USE_NVM) + NvM_CancelWriteAll(); +#endif + } +} + + +/** + * In "Sleep Sequence I" (in state ECUM_STATE_SLEEP) + */ +static void in_state_sleep ( void ) { + const EcuM_SleepModeType *sleepModePtr; + sleepModePtr = &internal_data.config->EcuMSleepModeConfig[internal_data.sleep_mode]; + + EcuM_GenerateRamHash(); + + Mcu_SetMode(sleepModePtr->EcuMSleepModeMcuMode); + + /* @req 3.1.5/ECUM2863 */ + if( EcuM_CheckRamHash() == 0) { +#if defined(USE_DEM) + // + EcuM_ErrorHook(ECUM_E_RAM_CHECK_FAILED); +#endif + } + + set_current_state(ECUM_STATE_WAKEUP_ONE); } static inline void enter_go_off_one_mode(void){ @@ -137,7 +256,10 @@ static inline boolean hasPostRunRequests(void){ } - +/** + * RUN II Loop (in state ECUM_STATE_APP_RUN) + * - The entry to RUN II is done in + */ static inline void in_state_appRun(void){ if (internal_data_run_state_timeout){ internal_data_run_state_timeout--; @@ -145,29 +267,49 @@ static inline void in_state_appRun(void){ if ((!hasRunRequests()) && (internal_data_run_state_timeout == 0)){ EcuM_OnExitRun(); /** @req EcuM2865 */ + +#if defined(USE_WDGM) + WdgM_SetMode(internal_data.config->EcuMWdgMConfig->EcuMWdgMPostRunMode); +#endif + +#if defined(USE_RTE) && defined(CFG_ECUM_USE_SERVICE_COMPONENT) + Rte_Switch_currentMode_currentMode(RTE_MODE_EcuM_Mode_POSTRUN); +#endif + set_current_state(ECUM_STATE_APP_POST_RUN);/** @req EcuM2865 */ } } +/** + * RUN III states (in state ECUM_STATE_APP_POST_RUN) + */ static inline void in_state_appPostRun(void){ + + /* @req 3.1.5/ECUM2866 */ if (hasRunRequests()){ - set_current_state(ECUM_STATE_APP_RUN);/** @req EcuM2866 */ /** @req EcuM2308 */ - EcuM_OnEnterRUN(); /** @req EcuM2308 */ - //TODO: Call ComM_EcuM_RunModeIndication(NetworkHandleType Channel) for all channels that have requested run. - internal_data_run_state_timeout = internal_data.config->EcuMRunMinimumDuration / ECUM_MAIN_FUNCTION_PERIOD; /** @req EcuM2310 */ + /* We have run requests, return to RUN II */ + EcuM_enter_run_mode(); } else if (!hasPostRunRequests()){ EcuM_OnExitPostRun(); /** @req EcuM2761 */ set_current_state(ECUM_STATE_PREP_SHUTDOWN);/** @req EcuM2761 */ - - EcuM_OnPrepShutdown(); } else { - // TODO: Do something? + /* TODO: We have postrun requests */ } } + +/** + * PREP SHUTDOWN state (in state ECUM_STATE_PREP_SHUTDOWN) + */ static inline void in_state_prepShutdown(void){ + + // TODO: The specification does not state what events to clear + EcuM_ClearWakeupEvent(ECUM_WKSTATUS_NONE); + + EcuM_OnPrepShutdown(); + #if defined(USE_DEM) // DEM shutdown Dem_Shutdown(); @@ -197,9 +339,17 @@ static inline void in_state_goOffOne(void){ // Wait for the NVM job (NvmWriteAll) to terminate NvM_GetErrorStatus(0, &writeAllResult); if ((writeAllResult != NVM_REQ_PENDING) || (internal_data_go_off_one_state_timeout == 0)){ + +#if defined(USE_WDGM) + WdgM_SetMode(internal_data.config->EcuMWdgMConfig->EcuMWdgMShutdownMode); +#endif ShutdownOS(E_OK); } #else + +#if defined(USE_WDGM) + WdgM_SetMode(internal_data.config->EcuMWdgMConfig->EcuMWdgMShutdownMode); +#endif ShutdownOS(E_OK); #endif } @@ -207,14 +357,18 @@ static inline void in_state_goOffOne(void){ //----- MAIN ----------------------------------------------------------------------------------------------------------------- void EcuM_MainFunction(void){ + EcuM_WakeupSourceType wMask; + VALIDATE_NO_RV(internal_data.initiated, ECUM_MAINFUNCTION_ID, ECUM_E_NOT_INITIATED); switch(internal_data.current_state){ case ECUM_STATE_APP_RUN: + /* RUN II state */ in_state_appRun(); break; case ECUM_STATE_APP_POST_RUN: + /* RUN III state */ in_state_appPostRun(); break; case ECUM_STATE_PREP_SHUTDOWN: @@ -224,8 +378,83 @@ void EcuM_MainFunction(void){ in_state_goOffOne(); break; case ECUM_STATE_GO_SLEEP: - // TODO: Fill out + in_state_goSleep(); + break; + case ECUM_STATE_SLEEP: + in_state_sleep(); break; + case ECUM_STATE_WAKEUP_ONE: + { + /* TODO: we must have a normal RUN mode.. can't find any + * in the A3.1.5 spec. */ + Mcu_SetMode(MCU_MODE_NORMAL); + +#if defined(USE_WDGM) + WdgM_SetMode(internal_data.config->EcuMWdgMConfig->EcuMWdgMWakeupMode); +#endif + + wMask = EcuM_GetPendingWakeupEvents(); + + EcuM_DisableWakeupSources(wMask); + + EcuM_AL_DriverRestart(); + + ReleaseResource(RES_SCHEDULER); + + set_current_state(ECUM_STATE_WAKEUP_VALIDATION); + + break; + } + + case ECUM_STATE_WAKEUP_VALIDATION: + { + wMask = EcuM_GetPendingWakeupEvents(); + + EcuM_StartWakeupSources(wMask); + + EcuM_CheckValidation( wMask ); + + // TODO: + // ComM_EcuM_WakeupIndication( network handle ) + + set_current_state(ECUM_STATE_WAKEUP_REACTION); + break; + } + + case ECUM_STATE_WAKEUP_REACTION: + { + /* + * At this stage we want to know how to react to the wakeup, e.g. go + * back to RUN or SHUTDOWN, etc. + */ + EcuM_WakeupReactionType wReaction; + + wMask = EcuM_GetValidatedWakeupEvents(); + + /* TODO: We have skipped the TTII timer here */ + + /* If the wakeup mask here is != 0 we have a validated wakeup event -> + * go back to RUN */ + wReaction = ( 0 == wMask ) ? ECUM_WKACT_SHUTDOWN : ECUM_WKACT_RUN; + wReaction = EcuM_OnWakeupReaction(wReaction); + + if( wReaction == ECUM_WKACT_RUN) { + set_current_state(ECUM_STATE_WAKEUP_TWO); + } else { + /* From figure 28 it seems that we should go to SHUTDOWN/GO SLEEP) again from wakeup + * not going up to RUN/RUN II state again. */ + set_current_state(ECUM_STATE_GO_SLEEP); + } + break; + } + + case ECUM_STATE_WAKEUP_TWO: +#if defined(USE_DEM) + Dem_Init(); +#endif + set_current_state(ECUM_STATE_RUN); + break; + default: //TODO: Report error. break; diff --git a/system/SchM/SchM.c b/system/SchM/SchM.c index 655b8c74..cab78fc7 100644 --- a/system/SchM/SchM.c +++ b/system/SchM/SchM.c @@ -314,6 +314,8 @@ SCHM_DECLARE(NVM); SCHM_DECLARE(FEE); SCHM_DECLARE(EA); SCHM_DECLARE(FLS); +SCHM_DECLARE(WDGM_TRIGGER); +SCHM_DECLARE(WDGM_ALIVESUPERVISION); @@ -346,8 +348,6 @@ TASK(SchM_Startup){ /* At this point EcuM == ECUM_STATE_STARTUP_ONE */ - /* Schedule memory task more often that usaul so that EcuM_StartupTwo() may return quicker */ - ActivateTask(TASK_ID_SchM_BswService); /* Set events on TASK_ID_BswService_Mem */ SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 2); @@ -360,6 +360,7 @@ TASK(SchM_Startup){ EcuM_StartupTwo(); /* Start to schedule BSW parts */ + CancelAlarm(ALARM_ID_Alarm_BswService); SetRelAlarm(ALARM_ID_Alarm_BswService, 10, 5); EcuM_RequestRUN(ECUM_USER_User_1); @@ -408,7 +409,8 @@ TASK(SchM_BswService) { SCHM_MAINFUNCTION_NM(); SCHM_MAINFUNCTION_CANNM(); SCHM_MAINFUNCTION_CANSM(); - SCHM_MAINFUNCTION_WDMG(); + SCHM_MAINFUNCTION_WDGM_TRIGGER(); + SCHM_MAINFUNCTION_WDGM_ALIVESUPERVISION(); break; } diff --git a/system/SchM/SchM_WdgM.h b/system/SchM/SchM_WdgM.h new file mode 100644 index 00000000..0fac7f0a --- /dev/null +++ b/system/SchM/SchM_WdgM.h @@ -0,0 +1,25 @@ +/* -------------------------------- Arctic Core ------------------------------ + * Arctic Core - the open source AUTOSAR platform http://arccore.com + * + * Copyright (C) 2009 ArcCore AB + * + * This source code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by the + * Free Software Foundation; See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * -------------------------------- Arctic Core ------------------------------*/ + + +#ifndef SCHM_WDGM_H_ +#define SCHM_WDGM_H_ + +#define SCHM_MAINFUNCTION_WDGM_TRIGGER() SCHM_MAINFUNCTION(WDGM_TRIGGER,WdgM_MainFunction_Trigger()) +#define SCHM_MAINFUNCTION_WDGM_ALIVESUPERVISION() SCHM_MAINFUNCTION(WDGM_ALIVESUPERVISION,WdgM_MainFunction_AliveSupervision()) + +#define SCHM_MAINFUNCTION_WDGM() SCHM_MAINFUNCTION(WDGM,Dcm_MainFunction()) + +#endif /* SCHM_WDGM_H_ */ diff --git a/system/SchM/SchM_cfg.h b/system/SchM/SchM_cfg.h index 04e80465..b45eb991 100644 --- a/system/SchM/SchM_cfg.h +++ b/system/SchM/SchM_cfg.h @@ -52,6 +52,8 @@ #define SCHM_MAINFUNCTION_CYCLE_PDUR SCHM_CYCLE_MAIN #define SCHM_MAINFUNCTION_CYCLE_SPI SCHM_CYCLE_MAIN #define SCHM_MAINFUNCTION_CYCLE_WDGM SCHM_CYCLE_MAIN +#define SCHM_MAINFUNCTION_CYCLE_WDGM_TRIGGER SCHM_CYCLE_MAIN +#define SCHM_MAINFUNCTION_CYCLE_WDGM_ALIVESUPERVISION SCHM_CYCLE_MAIN /* * Schedule BSW memory