lpm.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:7k
- #include "stsys.h"
- #include "SysServReg.h"
- #define MODE_LOW_POWER 2
- #define MODE_REDUCED_POWER 4
- #define MODE_FULL_POWER 8
- #define SHUTDOWN_MODE MODE_REDUCED_POWER
- /* The IRBBaseAddress is: 0x2081 8000. for 5105 & 5100 */
- #define IRB_RX_CLOCK_SELECT 0x20818070 /* same for 5105 */
- #define IRB_RX_EN 0x20818050 /* same for 5105 */
- #define IRB_RX_INT_EN 0x20818048 /* same for 5105 */
- #define IRB_RX_ON_TIME 0x20818040 /* same for 5105 */
- #define IRB_RX_SYM_PERIOD 0x20818044 /* same for 5105 */
- #define IRB_RX_STATUS 0x2081806c /* same for 5105 */
- #define IRB_RX_NOISE_SUPPRESS_WIDTH 0x2081805c /* same for 5105 */
- /* The ILCBaseAddress is: 0x2080 0000. */
- #define ILC_WAKEUP_ENABLE 0x20800608 /* same for 5105 */
- #define ILC_WAKEUP_ACTIVE_LEVEL 0x20800688 /* same for 5105 */
- #define ILC_STATUS 0x2080020c /* same for 5105 */
- #define ILC_ENABLE 0x20800400 /* kc-060112pm - 5105 datasheet */
- /* #define ILC_ENABLE 0x20800408 ??? */
- #define ILC_MODE68 0x20800A24 /*ILCBaseAddress + 0x800 + (n x 0x008) + 0x004*/
- #define ILC_MODE19 0x2080089c /*ILCBaseAddress + 0x800 + (n x 0x008) + 0x004*/
- /* #define ILC_SET_ENABLE 0x20800508 ??? */
- #define ILC_SET_ENABLE_1 0x20800500 /* kc-060112pm - 5105 datasheet */
- #define ILC_SET_ENABLE_5105 0x2080050C
- /* PIO3 is at 0x2082 3000 */ /* same for 5105 */
- #define PIO3_PNC0_SET 0x20823024 /* 5105 - 0x2082 3000 + 0x24 => set */
- #define PIO3_PNC1_SET 0x20823034
- #define PIO3_PNC2_SET 0x20823044
- #define PIO3_PNC0_CLEAR 0x20823028
- #define PIO3_PNC1_CLEAR 0x20823038
- #define PIO3_PNC2_CLEAR 0x20823048
- //#pragma ST_section (LPM_LowPowerMode, "lowpower_section")
- void LPM_LowPowerMode(void)
- {
- #if(SHUTDOWN_MODE == MODE_FULL_POWER)
- /* Do nothing, just use reset default parameters */
- return;
- #elif(SHUTDOWN_MODE == MODE_LOW_POWER)
- UINT32 i;
- /*Lock registers*/
- /*disable watchdog and LPA*/
- /*set PIO for IR as input*/
- /*Suppress filter for IR*/
- /*enable IR*/
- /*Enable IR interrupt*/
- for(i=0; i<0x0ff; i++)
- {
- /* do nothing */
- }
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x00F0);
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x000F);
- STSYS_WriteRegDev32LE(WATCHDOG_COUNTER_CFG1, 0x0); /* disable watchdog reset */
- STSYS_WriteRegDev32LE(LP_MODE_COUNTER_CFG1, 0x0); /* disable LP counter */
- STSYS_WriteRegDev8(IRB_RX_NOISE_SUPPRESS_WIDTH, 0x00);
- STSYS_WriteRegDev8(IRB_RX_EN, 0x01);
- STSYS_WriteRegDev8(IRB_RX_INT_EN, 0x01);
-
- STSYS_WriteRegDev32LE(ILC_ENABLE, 0x10);
- /* STSYS_WriteRegDev32LE(ILC_SET_ENABLE_1, 0x10); */
- STSYS_WriteRegDev32LE(ILC_SET_ENABLE_5105, 0x10);
-
- /*Enable 27Mhz clock in IR*/
-
- STSYS_WriteRegDev32LE(ILC_MODE68, 0x03);
- STSYS_WriteRegDev32LE(ILC_WAKEUP_ACTIVE_LEVEL, 0x0010);
- STSYS_WriteRegDev32LE(ILC_WAKEUP_ENABLE, 0x0010);
-
- STSYS_WriteRegDev8(IRB_RX_CLOCK_SELECT, 0x00);
- /* Set Low Power Mode Registers */
-
- STSYS_WriteRegDev32LE(LP_MODE_DIS0, 0x07F7);
- STSYS_WriteRegDev32LE(LP_MODE_DIS1, 0x03FF);
- STSYS_WriteRegDev32LE(CKG_MODE_CONTROL, 0x02);
- /*
- STSYS_WriteRegDev32LE(LP_MODE_COUNTER_CFG0, 0x0020); -- 32 secs
- STSYS_WriteRegDev32LE(LP_MODE_COUNTER_CFG1, 0x0010);
- */
- /* turn off LP counter for production / release */
- STSYS_WriteRegDev32LE(LP_MODE_COUNTER_CFG0, 0x0020);
- STSYS_WriteRegDev32LE(LP_MODE_COUNTER_CFG1, 0x0000);
- for(i=0; i<0x1ff; i++)
- {
- /* do nothing */
- }
- while(1)
- {
- STSYS_WriteRegDev32LE(CKG_MODE_CONTROL, 0x03);
-
- if(STSYS_ReadRegDev32LE(CKG_MODE_CONTROL)==0x03)
- break;
- }
- for(i=0; i<0x1ff; i++)
- {
- /* wait for chip has been into standby mode */
- }
- STSYS_WriteRegDev32LE(CKG_MODE_CONTROL, 0x00);
- while(STSYS_ReadRegDev32LE(CKG_MODE_CONTROL) != 0x00)
- {
- for(i=0; i<0x1ff; i++)
- {
- /*do nothing, just wait*/
- }
-
- if(STSYS_ReadRegDev32LE(CKG_MODE_CONTROL) == 0x01)
- break;
- }
- for(i=0; i<0x1ff; i++)
- {
- /* wait for chip has been out of standby mode */
- }
-
- /*wake up*/ /*This section of code is important if not the board will not reset!!*/
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x00F0);
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x000F);
- STSYS_WriteRegDev32LE(WATCHDOG_COUNTER_CFG1, 0x0); /* disable watchdog reset */
- STSYS_WriteRegDev32LE(LP_MODE_COUNTER_CFG1, 0x0); /* disable LP counter */
- for(i=0; i<0x1ff; i++)
- {
- /* wait for chip has been out of standby mode */
- }
- STSYS_WriteRegDev32LE(CKG_MODE_CONTROL, 0x02);
- /*Enable the watchdog reset*/
- STSYS_WriteRegDev32LE(CKG_RESET_STATUS, 0x0180);
- STSYS_WriteRegDev32LE(WATCHDOG_COUNTER_CFG0, 0x02);
- STSYS_WriteRegDev32LE(WATCHDOG_COUNTER_CFG1, 0x10);
- return;
-
- #elif(SHUTDOWN_MODE == MODE_REDUCED_POWER)
- UINT16 dat, dat2;
- volatile UINT32 NumberRead; /*No. of frames*/
- //STSYS_WriteRegDev8(PIO3_PNC0_CLEAR, 0x40);
- //STSYS_WriteRegDev8(PIO3_PNC1_CLEAR, 0x40);
- //STSYS_WriteRegDev8(PIO3_PNC2_CLEAR, 0x40);
-
- //STSYS_WriteRegDev8(IRB_RX_NOISE_SUPPRESS_WIDTH, 200);
- //STSYS_WriteRegDev8(IRB_RX_EN, 0x01);
- //STSYS_WriteRegDev8(IRB_RX_INT_EN, 0x01);
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x00F0);
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x000F);
- //STSYS_WriteRegDev32LE(ILC_SET_ENABLE_1, 0x80000);
- //STSYS_WriteRegDev32LE(ILC_MODE19, 0x03);
-
- //STSYS_WriteRegDev8(IRB_RX_CLOCK_SELECT, 0x01);
- /*go into reduced power mode*/
- /*STSYS_WriteRegDev32LE(REDUCED_POWER_CONTROL, 0x144);*/
- #if 1 /* BLOCK COMMENTED OUT by ilyas fakrudeen on 11/22/2005 */
- STSYS_WriteRegDev32LE(REDUCED_POWER_CTRL, 0x1Dc);
- //STSYS_WriteRegDev32LE(REDUCED_POWER_CTRL, 0x000);
- #else
- STSYS_WriteRegDev32LE(REDUCED_POWER_CTRL, 0x1FE);
- #endif /* BLOCK COMMENT */
- /*
- while (1)
- {
- while(STSYS_ReadRegDev16LE(IRB_RX_STATUS) & 0x700)
- {
- dat = STSYS_ReadRegDev16LE(IRB_RX_SYM_PERIOD);
- dat = STSYS_ReadRegDev16LE(IRB_RX_ON_TIME);
- }
- for(NumberRead = 0; NumberRead < 0xFFFFF; NumberRead++);
-
- dat = STSYS_ReadRegDev16LE(IRB_RX_STATUS);
- dat = dat & 0x700;
- if (dat == 0x700)
- {
- NumberRead = 0;
- while(STSYS_ReadRegDev16LE(IRB_RX_STATUS) & 0x700)
- {
- dat = STSYS_ReadRegDev16LE(IRB_RX_SYM_PERIOD);
- dat2 = STSYS_ReadRegDev16LE(IRB_RX_ON_TIME);
- NumberRead++;
- }
- if(NumberRead > 0) break;
- }
- }
- */
-
- /*wake up*/
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x00F0);
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x000F);
- STSYS_WriteRegDev32LE(CKG_MODE_CONTROL, 0x02);
- STSYS_WriteRegDev32LE(CKG_RESET_STATUS, 0x0180);
- STSYS_WriteRegDev32LE(WATCHDOG_COUNTER_CFG0, 0x02);
- STSYS_WriteRegDev32LE(WATCHDOG_COUNTER_CFG1, 0x10);
- return;
-
- #endif
- }
- /* EOF */