From: mahi Date: Sun, 9 Sep 2012 12:25:16 +0000 (+0200) Subject: EcuM: Adding more sleep functionility X-Git-Url: https://rtime.felk.cvut.cz/gitweb/arc.git/commitdiff_plain/f4f4fd3d51fd95d3d7936982a087b49438a8bdf3 EcuM: Adding more sleep functionility --- 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/Mcu.c b/arch/ppc/mpc55xx/drivers/Mcu.c index dae6e09f..7f9b4fc2 100644 --- a/arch/ppc/mpc55xx/drivers/Mcu.c +++ b/arch/ppc/mpc55xx/drivers/Mcu.c @@ -716,6 +716,8 @@ static void enterLowPower (Mcu_ModeType mcuMode ) /* Clear sleep flags to allow pads to operate */ CRP.PSCR.B.SLEEPF = 0x1; + + } diff --git a/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx b/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx index aa6cb3f4..485fa902 100644 --- a/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx +++ b/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx @@ -26,10 +26,13 @@ McuE_EnterLowPower: mfCR r29 mfXER r30 mfCTR r31 - stmw r25, 0x78(r1) #-- Store SPR data to stack + 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 @@ -69,46 +72,46 @@ McuE_LowPowerVector: #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 + * 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 - - -#if 0 - // Setup the SIU again. - li r4,0x0202 - LOAD_ADDR_32(r3,0xfffe8040+(52*2)) // PD4, SIU_PCR - sth r4,0(r3) - - LOAD_ADDR_32(r3,0xfffe8600+52) // PD4, SIU_GPDO - stb 1,0(r3) - - // Release PAD keepers - LOAD_ADDR_32(r3,0xfffec060) // CRP_PSCR - LOAD_ADDR_32(r4,0x1000) - stw r4,0(r3) -#endif - + /* 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 + 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 - blr #-- Branch back to calling function - + 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 @@ -119,9 +122,13 @@ McuE_LowPowerRecoverFlash: #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: diff --git a/include/EcuM.h b/include/EcuM.h index 23e2c5fc..767eb57f 100644 --- a/include/EcuM.h +++ b/include/EcuM.h @@ -120,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) diff --git a/include/EcuM_Cbk.h b/include/EcuM_Cbk.h index 396eeeea..2b07f355 100644 --- a/include/EcuM_Cbk.h +++ b/include/EcuM_Cbk.h @@ -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 56ace85d..4d6b1d6c 100644 --- a/include/EcuM_Types.h +++ b/include/EcuM_Types.h @@ -148,7 +148,7 @@ 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; 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/system/EcuM/EcuM.c b/system/EcuM/EcuM.c index 9cf1c8f1..04d1cf8f 100644 --- a/system/EcuM/EcuM.c +++ b/system/EcuM/EcuM.c @@ -102,6 +102,8 @@ EcuM_GlobalType internal_data; /* ----------------------------[private functions]---------------------------*/ + + /* ----------------------------[public functions]----------------------------*/ #if !defined(USE_DET) && defined(ECUM_DEV_ERROR_DETECT) @@ -362,12 +364,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) @@ -441,13 +476,32 @@ void EcuM_ClearWakeupEvent( EcuM_WakeupSourceType source ) } /** - * TODO: + * 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) */ +} + + +EcuM_WakeupSourceType EcuM_GetValidatedWakeupEvents( void ) { // TODO: - return ECUM_WKSOURCE_INTERNAL_RESET; +} + +EcuM_WakeupStatusType EcuM_GetStatusOfWakeupSource( EcuM_WakeupSourceType sources ) { } + 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 811c1dd4..a96cabef 100644 --- a/system/EcuM/EcuM_Main.c +++ b/system/EcuM/EcuM_Main.c @@ -209,6 +209,16 @@ static void in_state_sleep ( void ) { sleepModePtr = &internal_data.config->EcuMSleepModeConfig[internal_data.sleep_mode]; 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){ @@ -337,6 +347,8 @@ 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){ @@ -361,6 +373,73 @@ void EcuM_MainFunction(void){ 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(FIXME_MODE); +#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 */ + 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 { + /* Shutdown, again */ + /* TODO: + set_current_state(ECUM_STATE_WAKEUP_TWO); + } + break; + } + + case ECUM_STATE_WAKEUP_TWO: + Dem_Init(); + + break; default: //TODO: Report error.