SysPower.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:11k
- //
- // (C)版权2007 深圳市键桥通讯有限公司
- //
- // 文件名称: SysPower.c
- //
- // 创建日期: 2007.07.31
- //
- // 创建人 : Neil
- //
- // 修改人 : Neil
- //
- // 描 述: 系统定时开关机实现, 本任务以简洁为好, 尽量不要添加其他操作, 特别是信号量不宜在本任务使用
- //
- // 版 本:1.0.0
- //
- //--------------------------------------------------------------------
- #include <string.h>
- #include "stsys.h"
- #include <task.h>
- #include <initfuncs.h>
- #include "Eprom.h"
- #include "Osp.h"
- #include "db.h"
- #include "sipsi.h"
- #include "Av.h"
- #include "Machblue_defines.h"
- #include "Timeclk.h"
- #include "Dmd.h"
- #include "SysPower.h"
- //#include "Osd.h"
- //#include "KB_OSD.h"
- //#include "RcKeyMap.h"
- static BOOL SysPowerTaskSusFlag = FALSE;
- static BOOL SysPowerShutedDownFlag = FALSE;
- static UINT32 SysPower_taskid;
- static time_t g_SysPowerTime;
- static void KB_SysPowerTask(void);
- extern KB_DBE2PDATA gE2pData;
- extern mb_error_t kb_machblue_movie_close(BOOL Menu_Exit);
- extern void KB_DCStop_Service(void);
-
- BOOL KB_SystemShutDown(UINT16 Hour,
- UINT16 Minute,
- KB_SYS_POWER_TIME_TYPE eType)
- {
- UINT16 nType = eType;
-
- //一天最大小时标识23, 最大分钟标识59
- if (Hour > 23 || Minute > 59 || nType > 2)
- {
- printf("nKB_SystemShutDown::input error! hour(%d), minute(%d), eType(%d)",
- Hour, Minute, eType);
- return FALSE;
- }
- gE2pData.gSysPara.ShutDownInfo = (Minute | (Hour<<6) | (nType<<11));
- if (KB_E2PWrite(KB_NVM_SYS_PARA_ADDR, (UINT8 *)&gE2pData.gSysPara, sizeof(KB_DBSysInfo), NULL) != RETOK)
- {
- printf("nKB_SystemShutDown::KB_E2PWrite fail");
- return FALSE;
- }
- if (TRUE == SysPowerTaskSusFlag)
- {
- if (Ret_OK == KB_OSPTaskRes(SysPower_taskid))
- {
- SysPowerTaskSusFlag = FALSE;
- }
- }
-
- return TRUE;
- }
- BOOL KB_SystemSetUp(UINT16 Hour,
- UINT16 Minute,
- KB_SYS_POWER_TIME_TYPE eType)
- {
- UINT16 nType = eType;
-
- //一天最大小时标识23, 最大分钟标识59
- if (Hour > 23 || Minute > 59 || nType > 2)
- {
- printf("nKB_SystemSetUp::input error! hour(%d), minute(%d), eType(%d)",
- Hour, Minute, eType);
- return FALSE;
- }
- gE2pData.gSysPara.SetUpInfo = (Minute | (Hour<<6) | (nType<<11));
- if (KB_E2PWrite(KB_NVM_SYS_PARA_ADDR, (UINT8 *)&gE2pData.gSysPara, sizeof(KB_DBSysInfo), NULL) != RETOK)
- {
- printf("nKB_SystemSetUp::KB_E2PWrite fail");
- return FALSE;
- }
- if (TRUE == SysPowerTaskSusFlag)
- {
- if (Ret_OK == KB_OSPTaskRes(SysPower_taskid))
- {
- SysPowerTaskSusFlag = FALSE;
- }
- }
-
- return TRUE;
- }
- void KB_SystemShutDownNow(void)
- {
- UINT16 tmp = (UINT16)(INVALID_SETTING);
- if (ONCE_ONLY == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11))
- {
- //将关机标志设置为INVALID_SETTING
- gE2pData.gSysPara.ShutDownInfo = tmp<<11;
- if (KB_E2PWrite(KB_NVM_SYS_PARA_ADDR, (UINT8 *)&gE2pData.gSysPara, sizeof(KB_DBSysInfo), NULL) != RETOK)
- {
- printf("nKB_SystemShutDownNow::KB_E2PWrite fail");
- }
- }
- SysPowerShutedDownFlag = TRUE;
-
- if (KB_AVGetIFrameFlag())
- {
- KB_AVStopIFrame();
- }
- KB_AVStop();
- KB_DCStop_Service(); //shriek
- //KB_OSDClearScreen();
-
- kb_machblue_movie_close(TRUE);
- return;
- }
- void KB_SystemSetUpNow(void)
- {
- UINT16 tmp = (UINT16)(INVALID_SETTING);
- if (ONCE_ONLY == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11))
- {
- //将开机标志设置为INVALID_SETTING
- gE2pData.gSysPara.SetUpInfo = tmp<<11;
- if (KB_E2PWrite(KB_NVM_SYS_PARA_ADDR, (UINT8 *)&gE2pData.gSysPara, sizeof(KB_DBSysInfo), NULL) != RETOK)
- {
- printf("nKB_SystemSetUpNow::KB_E2PWrite fail");
- }
- }
- SysPowerShutedDownFlag = FALSE;
-
- #if 0
- {
- KB_OSPMsgNode ospMsg;
- KB_OSPMsgNode ospMsgt;
-
- ospMsg.Word1= MOD_KEY;
- ospMsg.Word3= rc_KeyMenu;
- KB_MENUTranslateMsg(&ospMsg);
- ospMsgt.Word1= MOD_KEY;
- ospMsgt.Word3= rc_KeyMenu;
- KB_MENUTranslateMsg(&ospMsgt);
-
- task_reschedule();
- }
- #endif
- KD_Restart();
- }
- static void KB_SysPowerTask(void)
- {
- time_t CurTime;
- UINT16 destHour = 0;
- UINT16 destMinute = 0;
- UINT32 destTotalSec = 0;
- static int count = 3000;
- task_status_t status;
- while(1)
- {
- if ((INVALID_SETTING == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11) || TIME_TYPE_MAX == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11))
- && (INVALID_SETTING == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11) || TIME_TYPE_MAX == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11)))
- {
- printf("nKB_SysPowerTask::task_suspend");
- SysPowerTaskSusFlag = TRUE;
- task_suspend(NULL);
- }
-
- if (KB_DB_DTV_SUCCESS == KB_TimeGetCurTime(&CurTime))
- {
- //取ShutDownInfo的第11~12位比较
- if (ONCE_ONLY == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11)
- || ONCE_A_DAY == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11))
- {
- //取ShutDownInfo的第6~10位
- destHour = (gE2pData.gSysPara.ShutDownInfo & 0x7c0)>>6;
- //取ShutDownInfo的第0~5位
- destMinute = gE2pData.gSysPara.ShutDownInfo & 0x3f;
- destTotalSec = destHour*3600 + destMinute*60;
- CurTime = CurTime % 86400;
- //printf("nKB_SysPowerTask::destHour0(%d), destMinute0(%d)",
- // destHour, destMinute);
- //printf("nKB_SysPowerTask::destTotalSec0(%ld), CurTime0(%ld)",
- // destTotalSec, CurTime);
- //允许向后2秒的误差
- if (CurTime == destTotalSec
- || CurTime == destTotalSec + 1
- || CurTime == destTotalSec + 2)
- {
- KB_SystemShutDownNow();
- }
- }
- //取SetUpInfo的第11~12位比较
- if (ONCE_ONLY == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11)
- || ONCE_A_DAY == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11))
- {
- //取SetUpInfo的第6~10位
- destHour = (gE2pData.gSysPara.SetUpInfo & 0x7c0)>>6;
- //取SetUpInfo的第0~5位
- destMinute = gE2pData.gSysPara.SetUpInfo & 0x3f;
- destTotalSec = destHour*3600 + destMinute*60;
- CurTime = CurTime % 86400;
- //printf("nKB_SysPowerTask::destHour1(%d), destMinute1(%d)",
- // destHour, destMinute);
- //printf("nKB_SysPowerTask::destTotalSec1(%ld), CurTime1(%ld)n",
- // destTotalSec, CurTime);
-
- //允许向后2秒的误差
- if (CurTime == destTotalSec
- || CurTime == destTotalSec + 1
- || CurTime == destTotalSec + 2)
- {
- KB_SystemSetUpNow();
- }
- }
- #if 0
- task_status((task_t *)SysPower_taskid,
- &status,
- task_status_flags_stack_used);
- printf("nKB_SysPowerTask::task_stack_base(0x%x, 0x%x), task_stack_size(0x%x), task_stack_used(0x%x), task_time(0x%x)",
- status.task_stack_base,
- SysPower_taskid,
- status.task_stack_size,
- status.task_stack_used,
- status.task_time);
- #endif
- }
- else
- {
- if (TRUE == KB_DMDQuerySignalStatus())
- {
- if (3000 == count)
- {
- printf("nKB_SysPowerTask::KB_SIGetTime");
- KB_SIGetTime(&g_SysPowerTime);
- }
-
- --count;
-
- if (0 == count)
- {
- count = 3000;
- }
- }
- #if 0
- task_status((task_t *)SysPower_taskid,
- &status,
- task_status_flags_stack_used);
- printf("nKB_SysPowerTask::task_stack_base(0x%x, 0x%x), task_stack_size(0x%x), task_stack_used(0x%x), task_time(0x%x)",
- status.task_stack_base,
- SysPower_taskid,
- status.task_stack_size,
- status.task_stack_used,
- status.task_time);
- #endif
- }
-
- KB_OSPTaskDelay(1000);
- }
- }
- void KB_SysPowerInit(void)
- {
- #if 0
- printf("nKB_SysPowerInit::----------ShutDownInfo-----");
- printf("nKB_SysPowerInit::hour(%d)", (gE2pData.gSysPara.ShutDownInfo & 0x7c0)>>6);
- printf("nKB_SysPowerInit::minute(%d)", gE2pData.gSysPara.ShutDownInfo & 0x3f);
- printf("nKB_SysPowerInit::type(%d)", (gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11);
- printf("nKB_SysPowerInit::----------SetUpInfo-----");
- printf("nKB_SysPowerInit::hour(%d)", (gE2pData.gSysPara.SetUpInfo & 0x7c0)>>6);
- printf("nKB_SysPowerInit::minute(%d)", gE2pData.gSysPara.SetUpInfo & 0x3f);
- printf("nKB_SysPowerInit::type(%d)", (gE2pData.gSysPara.SetUpInfo & 0x1800)>>11);
- KB_DBPwdInfo tmp;
- KB_DBGetPwdInfo(&tmp);
- printf("nKB_SysPowerInit::PwdSwitch(%d)", tmp.PwdSwitch);
- printf("nKB_SysPowerInit::PSW: %d %d %d %d %d %d",
- tmp.Password[0],
- tmp.Password[1],
- tmp.Password[2],
- tmp.Password[3],
- tmp.Password[4],
- tmp.Password[5]);
- #endif
- KB_OSPTaskInit("SysP", 0x500, (void(*)(void *))KB_SysPowerTask,
- SYSPOWER_PRIORITY, NULL, &SysPower_taskid);
- return;
- }
- ST_ErrorCode_t KD_Restart(void)
- {
- U32 CodeReceived;
- STTBX_Print(("ENTERING SingapplRestart ...... n"));
-
- STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x300, 0x00F0);
- STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x300, 0x000F);
-
- CodeReceived = STSYS_ReadRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x300);
- STTBX_Print(("***LOCK STATUS = %08Xn", CodeReceived));
- STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x110, 0x02);
- CodeReceived = STSYS_ReadRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x140) | 0x0180;
- STTBX_Print(("***RESET STATUS = %08X ---changed to = ", CodeReceived));
- STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x140, 0x0180);
- CodeReceived = STSYS_ReadRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x140);
- STTBX_Print(("%08Xn", CodeReceived));
-
- STTBX_Print(("Enabling WATCHDOG...n"));
- STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x130, 0x01);
- STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x134, 0x10);
- return ST_NO_ERROR;
- }
- BOOL KB_SysPowerIsDown(void)
- {
- return SysPowerShutedDownFlag;
- }