UiInitial.c
上传用户:hjhsjcl
上传日期:2020-09-25
资源大小:11378k
文件大小:22k
源码类别:

压缩解压

开发平台:

C++ Builder

  1. /*==========================================================================
  2. Copyright (c) 2004 ALi Corporation. All Rights Reserved
  3. File: Initial.c
  4. content: Default Program Module load by Boot Rom.
  5.  Process initialization of the device.
  6. History: Created by David Chiu 2004/3/19
  7. ==========================================================================*/
  8. #define _UI_INITIAL_
  9. #include <DP8051XP.H>
  10. #include "TypeDef.h"
  11. #include "Const.h"
  12. #include "Reg5661.h"
  13. #include "Common.h"
  14. #include "Initial.h"
  15. #include "Key.h"
  16. #include "OledString.h"
  17. #include "FileSystem.h"
  18. #include "NandFlash.h"
  19. #include "Sd.h"
  20. #include "DDM.h"
  21. #include "SaveSetting.h"
  22. #include "UiInitial.h"
  23. #include "ExtCodec.h"
  24. #include "IntCodec.h"
  25. #if(ENABLE_HOST_FUNCTION) //allen050720
  26. #include "UsbHostCommon.h"
  27. #include "UsbHost.h"
  28. #endif
  29. #if(_PEDOMETER_Mode_)
  30. #include "UiPedoMeter.h"
  31. #endif
  32. #include "OLED.h"
  33. #include "IconDefine.h"
  34. #if(USE_STEP_UP_CONVERTER) //Jeff070315#1
  35. #include "StepUp.h"
  36. #endif
  37. #if(USE_FW_CHARGER)
  38. #include "Charger.h"     //Jason 20070119#1 // Jeff070303#1
  39. #endif
  40. #include "Usb.h" //Walace060719#1
  41. #if(FM_MODULE==2)
  42. #include "I2C.h"
  43. #endif
  44. void InitVariable(void);
  45. void InitDispCtrl(BOOL fRunUsb) large; //Walace060501#3
  46. #if(INIT_KEY_HOLD_AUTO_POWER_OFF)  //Walace060216#1
  47. void UiInitShowKeyHold(void);
  48. #endif
  49. #if(USE_STEP_UP_CONVERTER)
  50. #include "StepUp.h"
  51. #endif
  52. main(void)
  53. {
  54. BYTE bKey;
  55. BOOL fBootHotKey,fRunUsb;
  56. BOOL      fKeyHoldPowerOff;
  57. BOOL fExtPowerOn; //tne 2006/01/17 #2
  58. BOOL fGoAmuse; //Vicky060301
  59. #if(_PEDOMETER_Mode_)
  60. XBYTE gxbPedoMeterWriteData;
  61. #endif
  62. //David051123#6 start
  63. #if(IC_5661_TYPE==IC_M5638C_B1B)
  64. WD_DIS();
  65. #endif
  66. //End
  67. Init8051();
  68. //vicky050602#1
  69. #if(SETTING_FOR_ICE_START|ICE_REAL_MODE)
  70.     obDCVARRD=0x04; //DCV clock
  71.     obDCVWRDATA=0xe2; //147 MHz
  72.     obCLKMCUDIVF=0x0A;
  73.     obCLKMCUCTRL=0xC8; //MCU clock use system clock //147/12
  74. #endif
  75. InitDisableClk();
  76. InitPowerCtrl();
  77. Init5661Ctrl();
  78. InitVariable();
  79. InitSpecialGpio();
  80. BootGpioControl();
  81. #if(CDC_FOR_S5638)
  82. IntCdcRStringPowerOn(); //Ren050312#2
  83. #endif
  84. /////tne 2006/01/17 #2/////
  85. #if(SETTING_FOR_ICE_START|ICE_REAL_MODE)
  86. ClkDspEn(); //060519
  87. obSYSSOFTRSTCTRL&=0xF7; //reset dsp
  88. obSYSSOFTRSTCTRL|=0x08; //dsp enable
  89. ClkDspDis(); 
  90. obPMSIZE|=0x04;//MCU USE ALL
  91. #if(NEW_FLASH)
  92. NandInit(NDINIT_IDENT_DONE);
  93. #else
  94. NandInit();
  95. #endif
  96. gxbSysState=S_INIT_RTC;
  97. #if(ICE_FOR_USB)
  98. fRunUsb = TRUE;
  99. #else
  100. fRunUsb = FALSE;
  101. #endif
  102. fExtPowerOn = FALSE;
  103. fKeyHoldPowerOff=FALSE;
  104. gfKeyLockedSts=KEY_UNLOCK;
  105. gxbLcdContrast=LCD_DEFAULT_CONTRAST;
  106. #else
  107. //Walace060920#1 start
  108. bKey=KEY_INVALID;
  109. fBootHotKey=FALSE;
  110. fRunUsb=FALSE;
  111. fKeyHoldPowerOff=FALSE;
  112. fExtPowerOn=FALSE;
  113. fGoAmuse=FALSE;
  114. //Walace060920#1 end
  115. gfKeyLockedSts=KEY_UNLOCK; //Nick061120
  116. if(CheckProgRestart()) //Firmware restart
  117. { //gxbSysState=S_INIT_FS_REC;  //Walace060626#4
  118. gxbSysState=S_INIT_DISP_ANIMATE; 
  119. }
  120. else //First boot
  121. {
  122. #if(PLAY_IN_ADAPTOR)
  123. gxbAdaptorPlugIn=ADAPTER_DEFAULT_STATE;   // Jason 20070119#1 //WHH070307#5
  124. #endif
  125. gxbSysState=S_INIT_RTC;
  126. }
  127. //Try to load lcd constract value for power on animation
  128. if(SramCheck())
  129. {
  130. SramRead(SRAM_CONTRAST,&gxbLcdContrast);
  131. SramRead(SRAM_BACK_LIGHT, &gxbBackLightTime);//Walace060320#2
  132. }
  133. else
  134. {
  135. gxbLcdContrast=LCD_DEFAULT_CONTRAST;
  136. gxbBackLightTime = LCD_BACKLIGHT_DEFAULT_NUM; //Walace060320#2
  137. }
  138. //======================add by Rojam for PedoMeter=============================
  139. #if(_PEDOMETER_Mode_)
  140. obSYSSOFTRSTCTRL2 |= 0x04; // Disable I2C soft reset //add by Rojam for soft power On  PedoMeter
  141. obCLKI2CMCTRL = 0xD0; // Enable I2C Clock 12MHz
  142. obMODSEL2 |= 0x08; // I2C Mode Select
  143. obREADYENH |= 0x08; // I2C I/O Ready
  144. obI2CCLKDIV = 7; // Set I2C Serial Port Clock for PedoMeter
  145. bKey=0xff;
  146. while(obI2CSERSTS&0x80)
  147. {
  148. bKey--;
  149. }
  150. gxbPedoMeterWriteData=0x01; //0x00 Open PedoMeter ; 0x01 Close PedoMeter
  151. obCLKI2CMCTRL |= 0x80; //clock Enable //Renshuo050322#A
  152. obMODSEL2 |= 0x08; //I2CM Enable
  153. obI2CMAADDR = PedoMeter_ADDR;
  154. obI2CFIFO = gxbPedoMeterWriteData;
  155. obI2CMACMD = (I2C_CMD_SINGLE | I2C_CMD_CURRENT | I2C_CMD_WRITE_MODE | I2C_CMD_DATA_LEN(1));
  156. //PedoMeterWrite();
  157. //Renshuo050322#A      
  158. bKey=0xff;
  159. while(obI2CSERSTS&0x80)
  160. {
  161. bKey--;
  162. }//wait for idle 
  163. obMODSEL2 &= 0xF7; //I2CM Disable
  164. obCLKI2CMCTRL &= 0x7F; //clock Disable
  165. #endif
  166. //===================================================
  167. #if(DEBUG_M5638C) //Walace060202
  168. obDCVARRD = 0x07;
  169. obDCVWRDATA = obDCVRDDATA & (~0x80); //do not use pswitch delay
  170. #endif
  171. if(VbusCheck(CHECK_VBUS_ON)) //Walace060901#2
  172. {
  173. fRunUsb=TRUE;
  174. fExtPowerOn=FALSE;
  175. #if(USE_FW_CHARGER)  //WHH070304
  176. ChargerInit(); // ChargerInit for USB Mode
  177. #endif
  178. }
  179. //Jason 20070119#1 start   
  180. #if(PLAY_IN_ADAPTOR)
  181. if(gxbAdaptorPlugIn==ADAPTER_PLUG_IN)  //WHH070307#5
  182. {
  183. fRunUsb=FALSE;
  184. fExtPowerOn=FALSE;
  185. // Jason 20070119#1 start // Jeff070303#1 add WHH please Check
  186. #if(USE_FW_CHARGER)
  187. ChargerInit(); //WHH070304 // ChargerInit for Device Mode
  188. //gxbChargerFlag=1;//WHH070309#1
  189. obUSBOTGCTRL |= 0x02;
  190. obSYSSOFTRSTCTRL &= 0x7F; 
  191. obUSBOTGSPEED &= USB_OFFJ;
  192. obGPIOCDIR|=0x04; //enable external LDO to turn on 3V3/1V8 for adapter plug out  system is on
  193. obGPIOCDAT|=0x04;   //enable external LDO to turn on 3V3/1V8 for adapter plug out syetem is on
  194. #endif
  195. // Jason 20070119#1 end
  196. }
  197. #endif
  198. //Jason 20070119#1 end
  199. #endif  // #if(SETTING_FOR_ICE_START)
  200. InitSetPmi();
  201. ///////////////////////////
  202. //fBootHotKey=FALSE; //Walace060920#1
  203. //fGoAmuse=FALSE; //Vicky060301
  204. //SM Clock
  205. obCLKSMDIVF=0x08; //0x08
  206. obCLKSMCTRL=0xC8; // 147/10=14.6(13.4)
  207. KeyInit();
  208. EnableTimer0();
  209. gxbBtyLowNum=0;
  210. //UsbEnableInt(VBUS_INT); //Walace060719#1
  211. //SysEnableInt0(USB_INT); //Walace060719#1
  212. //Sample code for Ext.. power on
  213. #if(!SETTING_FOR_ICE_START) //David041117#4 start
  214. /*
  215. #if(!DEBUG_M5638C) //Renshuo050528#D
  216. gxbLcdCounter=0;
  217. while(gxbLcdCounter<PW_ON_EXT_DELAY)
  218. {
  219. //Detect Power Key
  220. obDCVARRD=0x03;
  221. if(!(obDCVRDDATA&0x80))
  222. SetPowerOff();
  223. }
  224. #endif
  225. */
  226. #endif
  227. //Nick060808 start
  228.   #if(ENABLE_SD_FUNCTION&SD_DET_USE_INT1)
  229. obGPIO_INT_SOURCE = 0x01;//use gpiod interrupt
  230. obGPIO_INT_MASK &= 0xDF;//disable gpiod5
  231. obGPIO_INT_MASK |= 0x20;//enable gpiod5
  232. obSYSINT1MASK |= 0x04;//enable gpio_int
  233. #endif
  234. //Nick060808 end
  235. while(1)
  236. {
  237. KeyGet(bKey);
  238. if((bKey&0x0F)==KEY_VOL_UP)
  239. { fBootHotKey=TRUE; }
  240. //Vicky060301
  241. #if(ENABLE_AMUSE_FUNC)
  242. if((bKey&0x0F)==0x04)
  243. { fGoAmuse=TRUE; }
  244. #endif
  245. //End
  246. switch(gxbSysState)
  247. {
  248. //tne 2006/01/17 #2
  249. case S_INIT_RTC:
  250. bKey = obDCV_INT_FLAG; //Walace060803#3 read clear for intial value.
  251. InitRtc();
  252.  //Walace060710#1 start
  253. #if(DEBUG_M5638C)//Nick060510#1 move to LOAD_PM state
  254. if(!fRunUsb)              
  255. BrownOutInit(); //Ren060125 
  256. #endif
  257.   //Walace060710#1 end
  258. EX0=1;  //Walace060710#1
  259. EA=1;
  260.                                 #if(SD_DET_USE_INT1) //Nick060808
  261.                                 EX1 = 1;                             
  262.                                 #endif
  263. #if(1) //Walace060813#1 //Patrick061016
  264. if(!fRunUsb) //Walace061201#1
  265. LowBatteryDetection(5); //tne 2006/11/29 #1
  266. #endif
  267. gxbSysState++;
  268. break;
  269. case S_INIT_FONT_TABLE:
  270. if(!FontTableInit())
  271. gxbLastErrCode=ERR_INIT_FONT_ERR;
  272. gxbSysState++;
  273. break;
  274. case S_INIT_DISP_ANIMATE:
  275. SetSysSpeed(SYS_SPEED_NORMAL); //Walace070106#5
  276.  //Walace060501#3 start
  277. OledInit();
  278. //OLED_CLEAR_ALL();
  279. OledShowIconNew(2,IM_BG_CLEAR_TO_BLACK,0,0); // WHH 070129
  280. gxbLcdCounter=0; // WHH 070129
  281. while(gxbLcdCounter<4){;} // WHH 070129
  282. //if(gxbBackLightTime!=LCD_BACKLIGHT_MIN_NUM)  //Walace060828#1 
  283. if((gxbBackLightTime!=LCD_BACKLIGHT_MIN_NUM)||fRunUsb) //Walace060828#1 
  284. {
  285. gxbBackLightCounter=BACKLIGHT_STS_ON;
  286. BACKLIGHT_ON();
  287. }
  288. else
  289. {
  290. gxbBackLightCounter=BACKLIGHT_STS_OFF;  
  291. BACKLIGHT_OFF();
  292. //tne 2006/11/29 #1 //Maybe low battery, try more stern test...
  293. if(gxbBtyLowNum>=LOW_BTY_RETRY_NUM)
  294. LowBatteryDetection(10);
  295. }
  296. if((!fRunUsb)&&(gfKeyLockedSts==KEY_LOCK))
  297. {
  298. #if(USE_STEP_UP_CONVERTER) //Larry061025#1
  299. InitStepUpConverter();
  300. #endif
  301. fKeyHoldPowerOff=TRUE;
  302. #if(COST_DOWN_CIRCUIT) // WHH 070125 #1
  303. obGPIOCDIR|=0x04;
  304. obGPIOCDAT|=0x04;
  305. #endif
  306. UiInitShowKeyHold();
  307. }
  308. else
  309. {
  310. fKeyHoldPowerOff=FALSE;
  311. InitDispCtrl(fRunUsb);
  312. }
  313.  //Walace060501#3 end
  314.  
  315. gxbSysState++;
  316. break;
  317. case S_INIT_NAND_FLASH:
  318. //modify by Nick 2006/02/14 add it. must use this clk source to avoid SD fail
  319. //obCLKMCUCTRL=0xb8; //Nick 2006/02/14 //Use DCV Audio clock //Nick060327#1
  320. SetSysSpeed(SYS_SPEED_UP_NAND_INIT); //tne 2005/11/28 #2
  321. //Ted 0203 start
  322. /*
  323. if(!NandInit())
  324. gxbLastErrCode=ERR_INIT_FLASH_ERR;
  325. */
  326. #if(NEW_FLASH)
  327. if(NandInit(NDINIT_DONE))//060508
  328. #else
  329. if(NandInit())
  330. #endif
  331. {
  332. if(gxwAddrPMI!=0)
  333. RestoreBlock0(); //if Block0 fail, start to recover Block0
  334. #if(NANDRESTORE_EN) 
  335. RecoverNandReStore(); //Scott061204 //Recover lost nandrestore block
  336. #endif
  337. }
  338. else
  339. {
  340. gxbLastErrCode=ERR_INIT_FLASH_ERR;
  341. }
  342. //Ted 0203 end
  343. gxbSysState++;
  344. break;
  345. case S_INIT_LOAD_SETTING:
  346. //LoadExtMemory //Walace061212#3
  347. #if(!ICE_REAL_MODE)
  348. gxwProgramIndex=PM_INIT;
  349. ClkDspEn();
  350. obSYSSOFTRSTCTRL&=0xF7; //reset dsp
  351. obSYSSOFTRSTCTRL|=0x08; //dsp enable
  352. ClkDspDis();
  353. obPMSIZE|=0x04; //MCU USE ALL
  354. //Load Ext. Program
  355. LoadProgram(gxwProgramIndex,EXT_CODE_ONLY);
  356. EA=1;
  357. #endif
  358. //
  359. #if(ICE_REAL_MODE)
  360. InitChkSetting(TRUE);
  361. #else
  362. if(!fRunUsb)
  363. InitChkSetting(fBootHotKey);
  364. else
  365. InitChkSetting(FALSE);
  366. #endif
  367. #if(REC_TEST)
  368. gxwRecCnt=0;
  369. #endif
  370. gxbSysState++;
  371. break;
  372. case S_INIT_CALIBRATION:
  373. #if(ONE_BATT_MODE&DEBUG_M5638C)  // Jeff_060620
  374. #if(!(SETTING_FOR_ICE_START|ICE_REAL_MODE))
  375. if(!fRunUsb) //Jeff_060314
  376. { // Jeff_061109 start
  377. RefleshBattCheck(0x1000); // Jeff_061102
  378. if(BattCheck()<125) // don't do calibration when batt is too high     // Jeff_061102
  379. {BandGapCalibrationCheck();}
  380. } // Jeff_061109 end
  381. #if(USE_VDDIO_CALIBRATION) //hsiang VddioCali start
  382. InitialVddioCalibration(); 
  383. #endif //hsiang VddioCali end
  384. #endif
  385. #endif
  386. //Walace060614#2  BandGap mark start
  387. //BANDGAP_3V3_POWER_OFF();  //Walace060108 
  388. //BANDGAP_1V8_SWITCH();   //Walace060108 
  389. //#else //Walace060108
  390. //BANDGAP_3V3_SWITCH();
  391. //Walace060614#2  BandGap mark end
  392. gxbSysState++;
  393. break;
  394. case S_INIT_FONT_INDEX:
  395. //tne 2005/11/28 #2
  396. CKCON &= 0xF8;
  397. CKCON |= 0x02;
  398. SetSysSpeed(SYS_SPEED_UP_UI); //Walace060720#3
  399. if(!fRunUsb)
  400. {
  401. LoadStringTableIndex();
  402. LoadTransTableIndex();
  403. }
  404. gxbSysState++;
  405. break;
  406. case S_INIT_FS:
  407. ReCheckStorage(gxbStorage);
  408. if(!FsInit())
  409. {
  410. gxbLastErrCode=ERR_INIT_FS_ERR;
  411. gxbSysState++; //skip rec init
  412. }
  413. gxbSysState++;
  414. break;
  415. case S_INIT_FS_REC:
  416. /*
  417. if(fRunUsb) //If pure USB mode, not need rec init
  418. {
  419. if( ((gxbDrmOptionMode&DRM_OPTION_MTP_MODE)==DRM_OPTION_MTP_OFF) || (fBootHotKey) )
  420. goto NO_REC_INIT;
  421. }
  422. */
  423. //if(!fRunUsb)
  424. SetSysSpeed(SYS_SPEED_UP_INIT); //Walace060720#3
  425. if(!fRunUsb&&!gbFsUnableUse)  //Walace060629#2
  426. InitRecInit();
  427. gxbSysState++;
  428. break;
  429. case S_INIT_LOAD_PM:
  430. //Use DCV Sys clock
  431. //#if(USE_STEP_UP_CONVERTER)
  432. McuClockCtrlAdjust(0xC8);// WHH #1 061017
  433. //#else
  434. //obCLKMCUCTRL=0xC8; //73(67)/5=14.6(13.4) //modify by Nick 2006/02/14 add it
  435. //#endif
  436. SetSysSpeed(SYS_SPEED_NORMAL);
  437. CKCON &= 0xF8;
  438. //tne 2005/11/23 #2
  439. //OLED_CLEAR_ALL(); //Walace060501#3
  440. if(gxbBackLightTime!=LCD_BACKLIGHT_MIN_NUM) //Walace060511#2
  441. { //OledSetContrast(gxbLcdContrast<<2); //Walace060204#Bright
  442. // OledSetBrightness(gxbLcdContrast);  //Walace060204#Bright 
  443. }
  444. #if(ICE_REAL_MODE)
  445. IE=0;
  446. gxbDeviceMode=DEV_MUSIC;
  447. gxwProgramIndex=PM_PLAY_FAT_LARGE;
  448. ClkDspEn();
  449. obSYSSOFTRSTCTRL&=0xF7; //reset dsp
  450. obSYSSOFTRSTCTRL|=DSP_RST_DIS; //dsp enable
  451. ClkDspDis();
  452. obPMSIZE|=0x04;//MCU USE ALL
  453. gxbModuleState=MODULE_INITIAL; //NandRestore
  454. LoadProgram(PM_VIDEO_FLIST,NORMAL_CODE); 
  455. //LoadProgram(PM_PLAY_FAT_LARGE,NORMAL_CODE); //vicky061001#2 Debug Play
  456. //Load program here~
  457. #endif
  458.                              //Jason060925#1
  459. #if ((FM_MODULE==0)&&FM_INIT_STANDBY) // modify by Rojam 2007-04-18 14:3
  460. InitFmMuteAndStandBy();
  461. #endif
  462. if(fRunUsb)
  463. {
  464. //BACKLIGHT_OFF(); //Walace060501#3
  465. InitRunToUsb(fBootHotKey);
  466. }
  467. //BrownOutInit();//Nick060510#1 //Walace060710#1
  468. //If alarm switch on, enable dvc alarm interrupt
  469. EA=0;
  470. obDCVARRD=0x03;
  471. obDCV_INT_MASK = obDCV_INT_MASK | ((obDCVRDDATA&RTC_GET_ALARM_STS)|0x04);
  472. //OLED_CLEAR_ALL();
  473. #if(INIT_KEY_HOLD_AUTO_POWER_OFF)  //Walace060216#1
  474. if(fKeyHoldPowerOff)
  475. {
  476. gxbSettingBuffer[SETTING_CURRENT_MODE]=SAVE_FROM_INIT_KEY_HOLD;
  477. gxbSettingBuffer[SETTING_NEXT_MODE]=SAVE_AND_POWER_OFF;
  478. LoadProgram(PM_SAVE_SETTING,NORMAL_CODE);
  479. }
  480. #endif
  481. //Vicky060301
  482. #if(ENABLE_AMUSE_FUNC)
  483. if(fGoAmuse &(!fRunUsb))
  484. gxbDeviceMode=DEV_AMUSE;
  485. #endif
  486. //End
  487. switch(gxbDeviceMode)
  488. {
  489. // WHH #1 301_061220(start)
  490. case DEV_SAVE:
  491. gxbFsDelId=FSDEL_GO_SAVE;
  492. gxbSettingBuffer[SETTING_CURRENT_MODE]=SAVE_FROM_INIT;
  493. gxbSettingBuffer[SETTING_NEXT_MODE]=SAVE_AND_SEL_MODE;
  494. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  495.  break;
  496. // WHH #1 301_061220(end)  
  497. case DEV_FM:
  498. gxbFmPreset=0x00; //vicky050131
  499. //LoadProgram(PM_FM,NORMAL_CODE);
  500. gxbFsDelId = FSDEL_GO_FM;  //File manipulation then go to specified PM
  501. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  502. break;
  503. case DEV_FILE_CTRL: //tne 2007/01/12 #1
  504. gxbFsDelId = FSDEL_GO_FCTRL;  //File manipulation then go to specified PM
  505. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  506. break;
  507. case DEV_SYS:
  508. //LoadProgram(PM_SYSTEM,NORMAL_CODE);
  509. gxbFsDelId = FSDEL_GO_SYS;  //File manipulation then go to specified PM
  510. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  511. break;
  512. default:
  513. gxbDeviceMode=DEV_MUSIC;
  514. case DEV_MUSIC:
  515. //if(gfLargeBlock)
  516. {
  517. //LoadProgram(PM_PLAY_FAT_LARGE,NORMAL_CODE);
  518. gxbFsDelId = FSDEL_GO_PLAY; //File manipulation then go to specified PM
  519. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  520. }
  521. break;
  522. case DEV_DVR:
  523. //if(gfLargeBlock)
  524. {
  525. //LoadProgram(PM_PLAY_DVR,NORMAL_CODE);
  526. gxbFsDelId = FSDEL_GO_DVR; //File manipulation then go to specified PM
  527. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  528. }
  529. break;
  530. case DEV_HST:
  531. //LoadProgram(PM_HOST,NORMAL_CODE);
  532. gxbFsDelId = FSDEL_GO_HST;  //File manipulation then go to specified PM
  533. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  534. break;
  535. case DEV_PHO: // Walace050916
  536. gxbFsDelId = FSDEL_GO_PHO;  //File manipulation then go to specified PM
  537. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  538. break;
  539. case DEV_VIDEO: //Walace for _PM_VIDEO_
  540. gxbFsDelId = FSDEL_GO_VIDEO;  //File manipulation then go to specified PM
  541. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  542. break;
  543. //vicky060301
  544. #if(ENABLE_AMUSE_FUNC)
  545. case DEV_AMUSE:
  546. gxbFsDelId = FSDEL_GO_AMUSE;  //File manipulation then go to specified PM
  547. LoadProgram(PM_INIT_CHK,NORMAL_CODE);
  548. break;
  549. #endif
  550. //End
  551. }
  552. break;
  553. }
  554. }
  555. }
  556. void InitVariable(void)
  557. {
  558. gfAlarmTimeUp=FALSE;
  559. gxbStorType=STOR_NAND;
  560. #if(NEW_FLASH)
  561. gxbNandInitStage=NDINIT_INIT;//060508 new_nf
  562. #else
  563. gfNandInit=FALSE;
  564. #endif
  565. gxbBtyLowNum=0;
  566. //gxwBattAverage = (127<<4); //initial batt average value to "full battery"  //Renshuo050126#B
  567. gxwBattAverage = (BATTERY_LV_MAX<<4); //Walace060108#1
  568. gxbModuleState = MODULE_INITIAL; //Walace060607#1 PlayProcess
  569. gxbDeviceMode=DEV_INIT;
  570. gxbAbRepeatSts=AB_REPT_RESET; // no AB repeat
  571. gxwCurrentPlayTime=0;
  572. //gxdwCurrentLrcTime=0; //tne 2006/02/10 #1 ////Walace060226#remove
  573. gxbErrCode=ERR_NO_ERROR;
  574. gbFsUnableUse=FALSE; //add by tne 2005/01/07 #1
  575. #if(ENABLE_SD_FUNCTION)
  576. SdDefaultSetting();
  577. #endif
  578. #if(ENABLE_HOST_FUNCTION)
  579. UsbHostPowerOff();
  580. #endif
  581. gxbLastBattSts=UI_ICON_BTY_LV1;
  582. gxbLastErrCode=ERR_NO_ERROR;
  583. gdwSampleNum=0;
  584. gxbLastVolume=FADEOUT_VOL; //Renshuo041203#A
  585. gxbTargetVolume = FADEOUT_VOL; //Renshuo041203#A
  586. gxbPlaybackRate = 0; //050202Renshuo#A
  587.        gxbLcdLimitCol=MAX_COLNUM;
  588. #if(DRM_MODE_EN) //Nick060606#1
  589. gfHostSupportMTP = TRUE;
  590. gxbHostTimeOutRetry = 0;
  591. #endif
  592. gxbSWCBW=0; //allen051101#3
  593. #if(NEW_FLASH)
  594. gfCommonModified=FALSE; //Walace060904#2 
  595. #endif
  596. #if(USE_STEP_UP_CONVERTER)
  597. gxwAuxAverage=0;
  598. #endif
  599. #if(FM_MODULE==2)
  600. gxbFmChip=0x20;    //Rojam 070117
  601. #endif
  602. //Nick061120 start //NandRestore start
  603. gxbRestoreBlkNum = 0;
  604. gxbCurrentRestoreStep = 0;
  605. gxbRestoreCopy = 0;
  606. gxbRestoreSetPage = 0;
  607. gxbNandRestoreFlag = 0;
  608. gxwTimeToScanPM = 0; //Nick061204
  609. //Nick061120 end //NandRestore end
  610. }
  611. void InitDispCtrl(BOOL fRunUsb) large //Walace060501#3
  612. {
  613. #if(INIT_USE_BTY_LOW_FLAG)
  614.      BYTE bI;
  615. #endif
  616. BYTE bCycle;  // WHH #5 301_061225
  617. //check battery low flag
  618. #if(INIT_USE_BTY_LOW_FLAG)
  619. if(SramCheck())  //vicky050517
  620. {
  621. SramRead(SRAM_BYT_LOW_FLAG,&bI);
  622. if(bI)
  623. {
  624. StrShowInitLowPower();
  625. gxbLcdCounter=0;
  626. while(gxbLcdCounter<PW_ON_DISP_INTERVAL) { };
  627. OledDisplayOn(OFF);
  628. SetPowerOff();
  629. }
  630. }
  631. #endif
  632. #if(USE_STEP_UP_CONVERTER)
  633. InitStepUpConverter();
  634. #endif
  635. //Walace060501#3 start
  636. if(fRunUsb)
  637. {
  638. // WHH #6 301_061225(start)
  639. OledShowIconNew(2,IM_WAITING,0,0); //tne 2007/01/09 #3
  640. /*OledShowIcon(ICON_PC,14,16);
  641. OledShowIcon(ICON_USB_STATE_IDLE,52,LINE2);
  642. #if(DRM_MODE_EN) //Walace060902#1 start
  643. OledShowIcon(ICON_USB_SEARCH,SEG8,LINE2-6);
  644. #else
  645. OledShowIcon(ICON_USB_MASS,SEG8,LINE2);
  646. #endif //Walace060902#1 end*/
  647. // WHH #6 301_061225(end)
  648.  
  649. }
  650. else
  651. {
  652. #if(0)//COST_DOWN_CIRCUIT) // modify by Rojam 2007-03-27 17:13
  653. obGPIOCDIR|=0x04;
  654. obGPIOCDAT|=0x04;
  655. #endif
  656. #if(_PEDOMETER_Mode_)
  657. gxdCurrentStepNum=0;
  658. gxbPedometerPowerOn=0;
  659. gxwCurrentMotionTime=0;
  660. gxdCurrentMotionDistance=0;
  661. gxwLastAccelerationX=0;
  662. gxwLastAccelerationY=0;
  663. gxbCalibration=TRUE;
  664. gxbUp=0;
  665. gxbDown=0;
  666. gxwAcc0Lpf0=1;
  667. gxwAcc0Lpf1=1;
  668. gxwAcc1Lpf0=1;
  669. gxwAcc1Lpf1=1;
  670. gxwAcc0Hpf0=1;
  671. gxwAcc0Hpf1=1;
  672. gxwAcc1Hpf0=1;
  673. gxwAcc1Hpf1=1;
  674. gxwAccFilter0=1;
  675. gxwAccFilter1=1;
  676. gxwAccMax=1;
  677. gxwAccMin=1;
  678. gxwAccPeak=1;
  679. gxbSensStep=32; //16:WALK; 32:JOG; 100:RUN
  680. #endif
  681. #if(!ONE_BATT_MODE)
  682. #if(COLOR_MODE==0)
  683. obGPIOCDIR|=0x04;
  684. obGPIOCDAT|=0x04;
  685. #else 
  686. obGPIOADIR|=0x01;
  687. obGPIOADAT|=0x01;
  688. #endif
  689. #endif
  690. //Walace060806#3 start
  691. // WHH #5 301_061225(start)
  692. for(bCycle=0;bCycle<5;bCycle++)
  693. {
  694. ShowAnimation(IM_OPEN_ANIMATION_START ,
  695.      IM_OPEN_ANIMATION_OFFSET ,
  696.                           IM_OPEN_ANIMATION_NUM,
  697.                                 0,
  698.                                 0,
  699.                                 IM_OPEN_ANIMATION_DELAY );
  700. }
  701. /*ShowAnimation(ANI_POWER_ON_START,
  702.      ANI_POWER_ON_OFFSET,
  703.                           ANI_POWER_ON_NUM,
  704.                                 0,
  705.                                 0,
  706.                                 ANI_POWER_ON_DEALY);*/
  707. // WHH #5 301_061225(end)                                 
  708. //Walace060806#3 end
  709. }
  710. //Walace060501#3 end
  711.                           
  712. }
  713. //Walace060216#1
  714. #if(INIT_KEY_HOLD_AUTO_POWER_OFF) 
  715. void UiInitShowKeyHold(void)
  716. {
  717. SetSysSpeed(SYS_SPEED_NORMAL);
  718. if(gxbBackLightTime!=LCD_BACKLIGHT_MIN_NUM)
  719. {
  720. gxbBackLightCounter=BACKLIGHT_STS_ON; //Set state on and clen counter
  721. BACKLIGHT_ON();
  722. }
  723. else
  724. {
  725. gxbBackLightCounter=BACKLIGHT_STS_OFF;   //Dennis_Shih051122#1
  726. BACKLIGHT_OFF(); //Dennis_Shih051122#1
  727. }
  728. //tne 2007/01/17 #2
  729. OledShowIconNew(2,IM_BG_CLEAR_TO_BLACK,0,0);
  730. OledShowIconNew(1,ICON_KEY_HOLD,(OLED_MAX_COL-48)/2,(OLED_MAX_ROW-48)/2);
  731. #if(IC_5661_TYPE==IC_M5638C_B1B) //Walace060524#1
  732. #if(COST_DOWN_CIRCUIT)
  733. obGPIOCDIR&=~0x02;
  734. #else
  735. obDCVARRD=0x02;
  736. #endif
  737. #else
  738. obDCVARRD=0x03;
  739. #endif
  740. while(gxbLcdCounter<10)
  741. {
  742. //Detect Power Key
  743. #if(COST_DOWN_CIRCUIT)
  744. if((obGPIOCDAT&0x02))
  745. gxbLcdCounter = 0;
  746. #else
  747. if((obDCVRDDATA&0x80))
  748. gxbLcdCounter = 0;
  749. #endif
  750. }
  751. }
  752. #endif