SysPower.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:11k
源码类别:

DVD

开发平台:

C/C++

  1. //
  2. // (C)版权2007 深圳市键桥通讯有限公司
  3. // 
  4. // 文件名称: SysPower.c
  5. // 
  6. // 创建日期: 2007.07.31
  7. //
  8. // 创建人 : Neil
  9. //
  10. // 修改人 : Neil
  11. //
  12. // 描 述:  系统定时开关机实现, 本任务以简洁为好, 尽量不要添加其他操作, 特别是信号量不宜在本任务使用
  13. //
  14. // 版 本:1.0.0
  15. //
  16. //--------------------------------------------------------------------
  17. #include <string.h>
  18. #include "stsys.h"
  19. #include <task.h>
  20. #include <initfuncs.h>
  21. #include "Eprom.h"
  22. #include "Osp.h"
  23. #include "db.h"
  24. #include "sipsi.h"  
  25. #include "Av.h"
  26. #include "Machblue_defines.h"
  27. #include "Timeclk.h"
  28. #include "Dmd.h"
  29. #include "SysPower.h"
  30. //#include "Osd.h"
  31. //#include "KB_OSD.h"
  32. //#include "RcKeyMap.h"
  33. static BOOL     SysPowerTaskSusFlag = FALSE;
  34. static BOOL     SysPowerShutedDownFlag = FALSE;
  35. static UINT32   SysPower_taskid;
  36. static time_t   g_SysPowerTime;
  37. static void KB_SysPowerTask(void);
  38. extern KB_DBE2PDATA gE2pData;
  39. extern mb_error_t kb_machblue_movie_close(BOOL Menu_Exit);
  40. extern void KB_DCStop_Service(void);
  41.   
  42. BOOL KB_SystemShutDown(UINT16 Hour, 
  43.                             UINT16 Minute, 
  44.                             KB_SYS_POWER_TIME_TYPE eType)
  45. {
  46.     UINT16 nType = eType;
  47.     
  48.     //一天最大小时标识23, 最大分钟标识59
  49.     if (Hour > 23 || Minute > 59 || nType > 2)
  50.     {
  51.         printf("nKB_SystemShutDown::input error! hour(%d), minute(%d), eType(%d)",
  52.                 Hour, Minute, eType);
  53.         return FALSE;
  54.     }
  55.     gE2pData.gSysPara.ShutDownInfo = (Minute | (Hour<<6) | (nType<<11));
  56.     if (KB_E2PWrite(KB_NVM_SYS_PARA_ADDR, (UINT8 *)&gE2pData.gSysPara, sizeof(KB_DBSysInfo), NULL) != RETOK)
  57.     {
  58.         printf("nKB_SystemShutDown::KB_E2PWrite fail");
  59.         return FALSE;
  60.     }
  61.     if (TRUE == SysPowerTaskSusFlag)
  62.     {
  63.         if (Ret_OK == KB_OSPTaskRes(SysPower_taskid))
  64.         {
  65.             SysPowerTaskSusFlag = FALSE;
  66.         }
  67.     }
  68.             
  69.     return TRUE;
  70. }
  71. BOOL KB_SystemSetUp(UINT16 Hour, 
  72.                        UINT16 Minute, 
  73.                        KB_SYS_POWER_TIME_TYPE eType)
  74. {
  75.     UINT16 nType = eType;
  76.     
  77.     //一天最大小时标识23, 最大分钟标识59
  78.     if (Hour > 23 || Minute > 59 || nType > 2)
  79.     {
  80.         printf("nKB_SystemSetUp::input error! hour(%d), minute(%d), eType(%d)",
  81.                 Hour, Minute, eType);
  82.         return FALSE;
  83.     }
  84.     gE2pData.gSysPara.SetUpInfo = (Minute | (Hour<<6) | (nType<<11));
  85.     if (KB_E2PWrite(KB_NVM_SYS_PARA_ADDR, (UINT8 *)&gE2pData.gSysPara, sizeof(KB_DBSysInfo), NULL) != RETOK)
  86.     {
  87.         printf("nKB_SystemSetUp::KB_E2PWrite fail");
  88.         return FALSE;
  89.     }
  90.     if (TRUE == SysPowerTaskSusFlag)
  91.     {
  92.         if (Ret_OK == KB_OSPTaskRes(SysPower_taskid))
  93.         {
  94.             SysPowerTaskSusFlag = FALSE;
  95.         }
  96.     }
  97.         
  98.     return TRUE;
  99. }
  100. void KB_SystemShutDownNow(void)
  101. {
  102.     UINT16 tmp = (UINT16)(INVALID_SETTING);
  103.     if (ONCE_ONLY == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11))
  104.     {
  105.         //将关机标志设置为INVALID_SETTING
  106.         gE2pData.gSysPara.ShutDownInfo = tmp<<11;
  107.         if (KB_E2PWrite(KB_NVM_SYS_PARA_ADDR, (UINT8 *)&gE2pData.gSysPara, sizeof(KB_DBSysInfo), NULL) != RETOK)
  108.         {
  109.             printf("nKB_SystemShutDownNow::KB_E2PWrite fail");
  110.         }
  111.     }
  112.     SysPowerShutedDownFlag = TRUE;
  113.     
  114.     if (KB_AVGetIFrameFlag())
  115.     {
  116.         KB_AVStopIFrame();
  117.     }
  118.     KB_AVStop();
  119.     KB_DCStop_Service(); //shriek 
  120.     //KB_OSDClearScreen();
  121.     
  122.     kb_machblue_movie_close(TRUE);
  123.     return;
  124. }
  125. void KB_SystemSetUpNow(void)
  126. {
  127.     UINT16 tmp = (UINT16)(INVALID_SETTING);
  128.     if (ONCE_ONLY == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11))
  129.     {
  130.         //将开机标志设置为INVALID_SETTING
  131.         gE2pData.gSysPara.SetUpInfo = tmp<<11;
  132.         if (KB_E2PWrite(KB_NVM_SYS_PARA_ADDR, (UINT8 *)&gE2pData.gSysPara, sizeof(KB_DBSysInfo), NULL) != RETOK)
  133.         {
  134.             printf("nKB_SystemSetUpNow::KB_E2PWrite fail");
  135.         }
  136.     }
  137.     SysPowerShutedDownFlag = FALSE;
  138.     
  139.     #if 0
  140.     {
  141.         KB_OSPMsgNode ospMsg;
  142.         KB_OSPMsgNode ospMsgt;
  143.         
  144.         ospMsg.Word1=   MOD_KEY;
  145.      ospMsg.Word3=   rc_KeyMenu;
  146.      KB_MENUTranslateMsg(&ospMsg);
  147.         ospMsgt.Word1=   MOD_KEY;
  148.      ospMsgt.Word3=   rc_KeyMenu;
  149.      KB_MENUTranslateMsg(&ospMsgt);
  150.         
  151.         task_reschedule();  
  152.     }
  153.     #endif
  154.     KD_Restart();
  155. }
  156. static void KB_SysPowerTask(void)
  157. {
  158.     time_t CurTime;
  159.     UINT16 destHour   = 0;
  160.     UINT16 destMinute = 0;
  161.     UINT32 destTotalSec = 0;
  162.     static int count = 3000;
  163.     task_status_t status;
  164.     while(1)
  165.     {
  166.         if ((INVALID_SETTING == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11) || TIME_TYPE_MAX == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11))
  167.              && (INVALID_SETTING == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11) || TIME_TYPE_MAX == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11)))
  168.         {
  169.             printf("nKB_SysPowerTask::task_suspend");
  170.             SysPowerTaskSusFlag = TRUE;
  171.             task_suspend(NULL);
  172.         }
  173.     
  174.         if (KB_DB_DTV_SUCCESS == KB_TimeGetCurTime(&CurTime))
  175.         {
  176.             //取ShutDownInfo的第11~12位比较
  177.             if (ONCE_ONLY == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11)
  178.                 || ONCE_A_DAY == ((gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11))
  179.             {
  180.                 //取ShutDownInfo的第6~10位
  181.                 destHour   = (gE2pData.gSysPara.ShutDownInfo & 0x7c0)>>6;
  182.                 //取ShutDownInfo的第0~5位
  183.                 destMinute = gE2pData.gSysPara.ShutDownInfo & 0x3f;
  184.                 destTotalSec = destHour*3600 + destMinute*60;
  185.                 CurTime = CurTime % 86400;
  186.                 //printf("nKB_SysPowerTask::destHour0(%d), destMinute0(%d)",
  187.                 //        destHour, destMinute);
  188.                 //printf("nKB_SysPowerTask::destTotalSec0(%ld), CurTime0(%ld)",
  189.                 //        destTotalSec, CurTime);
  190.                 //允许向后2秒的误差
  191.                 if (CurTime == destTotalSec
  192.                     || CurTime == destTotalSec + 1
  193.                     || CurTime == destTotalSec + 2)
  194.                 {
  195.                     KB_SystemShutDownNow();
  196.                 }
  197.             }
  198.             //取SetUpInfo的第11~12位比较
  199.             if (ONCE_ONLY == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11)
  200.                 || ONCE_A_DAY == ((gE2pData.gSysPara.SetUpInfo & 0x1800)>>11))
  201.             {
  202.                 //取SetUpInfo的第6~10位
  203.                 destHour   = (gE2pData.gSysPara.SetUpInfo & 0x7c0)>>6;
  204.                 //取SetUpInfo的第0~5位
  205.                 destMinute = gE2pData.gSysPara.SetUpInfo & 0x3f;
  206.                 destTotalSec = destHour*3600 + destMinute*60;
  207.                 CurTime = CurTime % 86400;
  208.                 //printf("nKB_SysPowerTask::destHour1(%d), destMinute1(%d)",
  209.                 //        destHour, destMinute);
  210.                 //printf("nKB_SysPowerTask::destTotalSec1(%ld), CurTime1(%ld)n",
  211.                 //        destTotalSec, CurTime);
  212.                 
  213.                 //允许向后2秒的误差
  214.                 if (CurTime == destTotalSec
  215.                     || CurTime == destTotalSec + 1
  216.                     || CurTime == destTotalSec + 2)
  217.                 {
  218.                     KB_SystemSetUpNow();
  219.                 }
  220.             }
  221.             #if 0
  222.             task_status((task_t *)SysPower_taskid, 
  223.                         &status, 
  224.                         task_status_flags_stack_used);
  225.             printf("nKB_SysPowerTask::task_stack_base(0x%x, 0x%x), task_stack_size(0x%x), task_stack_used(0x%x), task_time(0x%x)",
  226.                     status.task_stack_base, 
  227.                     SysPower_taskid, 
  228.                     status.task_stack_size,
  229.                     status.task_stack_used,
  230.                     status.task_time);
  231.             #endif
  232.         }
  233.         else
  234.         {
  235.             if (TRUE == KB_DMDQuerySignalStatus())
  236.             {         
  237.                 if (3000 == count)
  238.                 {
  239.                     printf("nKB_SysPowerTask::KB_SIGetTime");
  240.                     KB_SIGetTime(&g_SysPowerTime);
  241.                 }
  242.                 
  243.                 --count; 
  244.             
  245.                 if (0 == count)
  246.                 {
  247.                     count = 3000;
  248.                 }
  249.             }
  250.             #if 0
  251.             task_status((task_t *)SysPower_taskid, 
  252.                         &status, 
  253.                         task_status_flags_stack_used);
  254.             printf("nKB_SysPowerTask::task_stack_base(0x%x, 0x%x), task_stack_size(0x%x), task_stack_used(0x%x), task_time(0x%x)",
  255.                     status.task_stack_base, 
  256.                     SysPower_taskid, 
  257.                     status.task_stack_size,
  258.                     status.task_stack_used,
  259.                     status.task_time);
  260.             #endif
  261.         }
  262.         
  263.         KB_OSPTaskDelay(1000);
  264.     }
  265. }
  266. void KB_SysPowerInit(void)
  267. {
  268. #if 0
  269.     printf("nKB_SysPowerInit::----------ShutDownInfo-----");
  270.     printf("nKB_SysPowerInit::hour(%d)", (gE2pData.gSysPara.ShutDownInfo & 0x7c0)>>6);
  271.     printf("nKB_SysPowerInit::minute(%d)", gE2pData.gSysPara.ShutDownInfo & 0x3f);
  272.     printf("nKB_SysPowerInit::type(%d)", (gE2pData.gSysPara.ShutDownInfo & 0x1800)>>11);
  273.     printf("nKB_SysPowerInit::----------SetUpInfo-----");
  274.     printf("nKB_SysPowerInit::hour(%d)", (gE2pData.gSysPara.SetUpInfo & 0x7c0)>>6);
  275.     printf("nKB_SysPowerInit::minute(%d)", gE2pData.gSysPara.SetUpInfo & 0x3f);
  276.     printf("nKB_SysPowerInit::type(%d)", (gE2pData.gSysPara.SetUpInfo & 0x1800)>>11);
  277.     KB_DBPwdInfo tmp;
  278.     KB_DBGetPwdInfo(&tmp);
  279.     printf("nKB_SysPowerInit::PwdSwitch(%d)", tmp.PwdSwitch);
  280.     printf("nKB_SysPowerInit::PSW: %d %d %d %d %d %d", 
  281.             tmp.Password[0],
  282.             tmp.Password[1],
  283.             tmp.Password[2],
  284.             tmp.Password[3],
  285.             tmp.Password[4],
  286.             tmp.Password[5]);
  287. #endif
  288. KB_OSPTaskInit("SysP", 0x500, (void(*)(void *))KB_SysPowerTask, 
  289.                      SYSPOWER_PRIORITY, NULL, &SysPower_taskid);
  290.     return;
  291. }
  292. ST_ErrorCode_t KD_Restart(void)
  293. {
  294. U32 CodeReceived;
  295. STTBX_Print(("ENTERING SingapplRestart ......  n"));
  296. STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x300, 0x00F0);
  297. STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x300, 0x000F);
  298. CodeReceived = STSYS_ReadRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x300);
  299. STTBX_Print(("***LOCK STATUS = %08Xn", CodeReceived));
  300. STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x110, 0x02);
  301. CodeReceived = STSYS_ReadRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x140) | 0x0180;
  302. STTBX_Print(("***RESET STATUS = %08X ---changed to = ", CodeReceived));
  303. STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x140, 0x0180);
  304. CodeReceived = STSYS_ReadRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x140);
  305. STTBX_Print(("%08Xn", CodeReceived));
  306. STTBX_Print(("Enabling WATCHDOG...n"));
  307. STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x130, 0x01);
  308. STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x134, 0x10);
  309. return ST_NO_ERROR;
  310. }
  311. BOOL KB_SysPowerIsDown(void)
  312. {
  313.     return SysPowerShutedDownFlag;
  314. }