From: mahi Date: Mon, 17 Sep 2012 13:51:38 +0000 (+0200) Subject: More EcuM Sleep changes. Need RC2 of tools X-Git-Url: https://rtime.felk.cvut.cz/gitweb/arc.git/commitdiff_plain/46ff634c2f2df95d1ea647bcf62c4da5ca54e288 More EcuM Sleep changes. Need RC2 of tools --- diff --git a/arch/ppc/mpc55xx/drivers/Mcu.c b/arch/ppc/mpc55xx/drivers/Mcu.c index 13da5609..1a8a4fbb 100644 --- a/arch/ppc/mpc55xx/drivers/Mcu.c +++ b/arch/ppc/mpc55xx/drivers/Mcu.c @@ -14,6 +14,7 @@ * -------------------------------- Arctic Core ------------------------------*/ +/* ----------------------------[includes]------------------------------------*/ #include #include #include "Std_Types.h" @@ -27,12 +28,60 @@ #include "Ramlog.h" #include "Os.h" #include "isr.h" +#include "io.h" //#define USE_LDEBUG_PRINTF 1 #include "debug.h" +/* ----------------------------[private define]------------------------------*/ + #define SYSCLOCK_SELECT_PLL 0x2 + +#if defined(CFG_MPC5516) || defined(CFG_MPC5668) +#define CRP_BASE (0xFFFEC000ul) +#else +#error Please define CRP_BASE +#endif + +#define CRP_CLKSRC (CRP_BASE+0x0) +#define CRP_RTCSC (CRP_BASE+0x10) +#define CRP_RTCCNT (CRP_BASE+0x14) +/* 40--4F differs ALOT */ +#define CRP_Z1VEC (CRP_BASE+0x50) +#define CRP_Z6VEC (CRP_BASE+0x50) +#define CRP_Z0VEC (CRP_BASE+0x54) +#define CRP_RECPTR (CRP_BASE+0x58) +#define CRP_PSCR (CRP_BASE+0x60) + +#define xVEC_xVEC(_x) +#define PSCR_SLEEP 0x00008000ul +#define PSCR_SLP12EN 0x00000800ul +#define PCSR_RAMSEL(_x) ((_x)<<8) +#define xVEC_VLE 0x00000001ul +#define xVEC_xRST 0x00000002ul + +#define RECPTR_FASTREC 0x00000002ul + + +#if defined(CFG_VLE) +#define VLE_VAL xVEC_VLE +#else +#define VLE_VAL 0 +#endif + +#if defined(CFG_MPC5516 ) +#define RAMSEL_VAL 0x7 +#elif defined(CFG_MPC5668) +#define RAMSEL_VAL 0x3 +#else +#error Please define RAMSEL_VAL +#endif + + +/* ----------------------------[private macro]-------------------------------*/ + + #if defined(CFG_MPC5567) #define CALC_SYSTEM_CLOCK(_extal,_emfd,_eprediv,_erfd) \ ( (_extal) * ((_emfd)+4) / (((_eprediv)+1)*(1<<(_erfd))) ) @@ -44,8 +93,26 @@ ( (_extal) * ((_emfd)+16) / (((_eprediv)+1)*((_erfd)+1)) ) #endif +/* ----------------------------[private typedef]-----------------------------*/ + + typedef void (*vfunc_t)(); + +/* ----------------------------[private function prototypes]-----------------*/ +/* ----------------------------[private variables]---------------------------*/ + +#if defined(CFG_MPC5516) +static uint32 Mcu_SavedHaltFlags; +#else +#error Implement halt flags +#endif + + + +/* ----------------------------[private functions]---------------------------*/ +/* ----------------------------[public functions]----------------------------*/ + /* Function declarations. */ static void Mcu_ConfigureFlash(void); @@ -679,6 +746,8 @@ void Mcu_PerformReset(void) //------------------------------------------------------------------- +#if defined(CFG_MPC5516) || defined(CFG_MPC5668) + /** * * Application Notes! @@ -691,75 +760,50 @@ void Mcu_PerformReset(void) */ static void enterLowPower (Mcu_ModeType mcuMode ) { -#if defined(CFG_MPC5668) + + uint32 timeout; - /* Set the sleep bit; following a WAIT instruction, the device will go to sleep */ - CRP.PSCR.B.SLEEP = 1; + /* - Set the sleep bit; following a WAIT instruction, the device will go to sleep + * - enable the 1.2V internal regulator when in sleep mode only + * - MPC5516 + * - 0x1 8k, 0x2 16k, 0x3 32k, 0x6 64k -- RAMs maintain power + * - MPC5668 + * - 0x1 32k, 0x2 64k, 0x3 128k + */ + WRITE32(CRP_PSCR, PSCR_SLEEP | PSCR_SLP12EN | PCSR_RAMSEL(RAMSEL_VAL)); - /* 0x1 32k, 0x2 64k, 0x3 128k -- RAMs maintain power */ - CRP.PSCR.B.RAMSEL = 0x3; // Keep all 128K + /* Set Recover Vector */ +#if defined(CFG_MPC5516) - CRP.Z6VEC.R = (uint32)&McuE_LowPowerRecoverFlash; -#if defined(CFG_VLE) - CRP.Z6VEC.VLE = 1; -#endif - /* If we "Mcu_Wakeup()" is located in RAM, set FASTREC */ - CRP.RECPTR.B.FASTREC = 0; + WRITE32(CRP_Z1VEC, ((uint32)&McuE_LowPowerRecoverFlash) | VLE_VAL ); + READWRITE32(CRP_RECPTR,RECPTR_FASTREC,0 ); + + Mcu_SavedHaltFlags = SIU.HLT.R; /* Halt everything */ - SIU.HLT0.R = 0x037FFF3D; - SIU.HLT1.R = 0x18000F3C; - while((SIU.HLTACK0.R != 0x037FFF3D) && (SIU.HLTACK1.R != 0x18000F3C) && (timeout<3000)){} + 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; - -#elif defined(CFG_MPC5516) - 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; +#elif defined(CFG_MPC5668) + WRITE32(CRP_Z6VEC, ((uint32)&McuE_LowPowerRecoverFlash) | VLE_VAL ); + READWRITE32(CRP_RECPTR,RECPTR_FASTREC,0 ); /* Halt everything */ - SIU.HLT.R = 0x3FFFFFFF; - while((SIU.HLTACK.R != 0x3FFFFFFF) && (timeout<3000)) {} + SIU.HLT0.R = 0x037FFF3D; + SIU.HLT1.R = 0x18000F3C; + while((SIU.HLTACK0.R != 0x037FFF3D) && (SIU.HLTACK1.R != 0x18000F3C) && (timeout<3000)){} +#else +#error CPU not defined +#endif /* 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. + /* Save context and execute wait instruction. * * Things that matter here are * - Z1VEC, determines where TLB0 will point. TLB0 is written with a @@ -774,12 +818,9 @@ static void enterLowPower (Mcu_ModeType mcuMode ) /* Clear sleep flags to allow pads to operate */ CRP.PSCR.B.SLEEPF = 0x1; -#else - /* NOT SUPPORTED */ - (void) mcuMode; -#endif } +#endif void Mcu_SetMode( Mcu_ModeType mcuMode) { @@ -789,6 +830,9 @@ void Mcu_SetMode( Mcu_ModeType mcuMode) #if defined(CFG_MPC5516) || defined(CFG_MPC5668) if( MCU_MODE_RUN == mcuMode ) { + /* Get Most back to "normal" halt flags */ + SIU.HLT.R = Mcu_SavedHaltFlags; + } else if( MCU_MODE_SLEEP == mcuMode ) { /* diff --git a/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx b/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx index 9f6d4919..d79c8d00 100644 --- a/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx +++ b/arch/ppc/mpc55xx/drivers/Mcu_Sleep.sx @@ -102,8 +102,6 @@ McuE_LowPowerRecoverFlash: 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) @@ -112,8 +110,10 @@ McuE_LowPowerRecoverFlash: bl EcuM_CheckWakeup #endif + mtLR r27 - + lmw r2, 0(r1) // Restore GPRs from stack + addi r1,r1,0x94 // Deallocate space on stack /* branch back to Mcu_SetMode().. */ blr diff --git a/arch/ppc/mpc55xx/scripts/linkscript_gcc.ldf b/arch/ppc/mpc55xx/scripts/linkscript_gcc.ldf index 146e6443..65ab9001 100644 --- a/arch/ppc/mpc55xx/scripts/linkscript_gcc.ldf +++ b/arch/ppc/mpc55xx/scripts/linkscript_gcc.ldf @@ -46,7 +46,7 @@ MEMORY SECTIONS { -#if 0 + /* __CALIB_RAM_START, __CALIB_RAM_END, __CALIB_ROM_START are needed by the a2l and the rte generator. CALIBRATION_ENABLED, CALIBRATION_INITIALIZED_RAM, CALIBRATION_FLS_START are generated by rte */ @@ -98,7 +98,7 @@ __FLS_PROG_START__ = 0; /* Must be aligned to a sector start. */ #if !defined(CFG_BOOT) .rcw __FLS_PROG_START__ : { *(.rcw) } > flash #endif -#endif + .text : { crt0.o(.text); diff --git a/include/Gpt.h b/include/Gpt.h index 703d1d1c..7db96b2c 100644 --- a/include/Gpt.h +++ b/include/Gpt.h @@ -97,10 +97,6 @@ typedef uint8_t Gpt_ChannelType; #define GPT_AR_MINOR_VERSION 2 #define GPT_AR_PATCH_VERSION 1 -#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 */ diff --git a/include/io.h b/include/io.h index f0b13e5b..f115d376 100644 --- a/include/io.h +++ b/include/io.h @@ -37,6 +37,11 @@ #define READ16_NA(address ) ( (((uint16_t)(((uint8_t *)address)[0]))<<8) + \ (((uint16_t)(((uint8_t *)address)[1]))) ) +#define READWRITE32(address,mask,val) WRITE32(address,(READ32(address)&~(mask))|val) + + + +/* NA - Not Aligned */ #define WRITE32_NA(address, value ) \ do { \ ((uint8_t *)address)[0] = ((value>>24)&0xff); \ diff --git a/system/EcuM/EcuM_Main.c b/system/EcuM/EcuM_Main.c index 10a9aef2..3fa423bf 100644 --- a/system/EcuM/EcuM_Main.c +++ b/system/EcuM/EcuM_Main.c @@ -185,13 +185,16 @@ static void in_state_goSleep( void ) { /* @req 3.1.5/ECUM2389 */ EcuM_EnableWakeupSources( 1<< source ); + } + #if defined(WDGM) - WdgM_SetMode(sleepModePtr->EcuMSleepModeWdgMMode); + WdgM_SetMode(sleepModePtr->EcuMSleepModeWdgMMode); #endif - /* Let no one else run */ - GetResource(RES_SCHEDULER); - } + /* Let no one else run */ + GetResource(RES_SCHEDULER); + + set_current_state(ECUM_STATE_SLEEP); } else if( EcuM_GetPendingWakeupEvents() != 0 ) { /* We have pending wakeup events, need to startup again */ @@ -383,7 +386,7 @@ void EcuM_MainFunction(void){ break; case ECUM_STATE_SLEEP: in_state_sleep(); - break; + /* Flow Through */ case ECUM_STATE_WAKEUP_ONE: { /* TODO: we must have a normal RUN mode.. can't find any