// ============================================================================= // calib_StubTaskInit // ----------------------------------------------------------------------------- /// Calib Stub OS task. // ============================================================================= PROTECTED VOID calib_StubTaskInit(VOID) { UINT32 evt[4]; Msg_t *msg; #ifdef CES_DISPLAY LCDD_SCREEN_INFO_T screenInfo; GFX_ROI_T fullScreenRoi; #endif CALIB_PROFILE_FUNCTION_ENTER(calib_StubTestTaskInit); /// Some initialization. /// Enable full-speed access to flash and ram. memd_FlashOpen(tgt_GetMemdFlashConfig()); memd_RamOpen(tgt_GetMemdRamConfig()); #if (CHIP_HAS_USB == 1) && (CALIB_WITHOUT_USB != 1) uctls_Open(g_calibStubMbx, 0, 0, 0, "USB Calib"); uctls_SetMode(UCTLS_ID_TRACE); // Force usb power cycle uctls_ChargerStatus(UCTLS_CHARGER_STATUS_DISCONNECTED); sxr_Sleep(8000); // Initiate charger status calib_ChargerHandler(pmd_GetChargerStatus()); // Configure PMD to warn the calib when a charger is plugged. pmd_SetChargerStatusHandler(calib_ChargerHandler); #endif // CHIP_HAS_USB && (CALIB_WITHOUT_USB != 1) #ifdef CES_DISPLAY /// Setup the display. lcdd_Open(); lcdd_SetStandbyMode(FALSE); lcdd_GetScreenInfo(&screenInfo); // Fill the whole screen with white. fullScreenRoi.start.x = 0; fullScreenRoi.start.y = 0; fullScreenRoi.width = screenInfo.width; fullScreenRoi.height = screenInfo.height; while (LCDD_ERR_NO != lcdd_FillRect16(&fullScreenRoi, 0xffff)); /// Draw a cool logo. while (lcdd_Blit16(&g_calibLogoFbw, 0, 0) != LCDD_ERR_NO); lcdd_SetBrightness(6); fmg_PrintfInit(0, 8, screenInfo.width, screenInfo.height); SXS_TRACE(TSTDOUT, "Running code: Calib Embedded Stub"); /// Switch ON/OFF PAL traces. sxs_SetTraceLevel(_PAL, 0x1); #endif // Start the calibration stub calib_StubOpen(); /// Update the display. calib_DispState(TRUE); /// Start the display refresh and battery monitoring timers. sxs_StartTimer(DISP_TIME, DISP_TIMER, NULL, FALSE, g_calibStubMbx); /// Main loop. while (1) { /// Wait for a timer event or a key message. msg = sxr_Wait(evt, g_calibStubMbx); if (msg == 0) { /// Refresh screen. if (evt[0] == DISP_TIMER) { CALIB_PROFILE_PULSE(calib_StubTimDisp); /// Update the display. calib_DispState(FALSE); /// Wakeup the task to update the display. sxs_StartTimer(DISP_TIME, DISP_TIMER, NULL, FALSE, g_calibStubMbx); } /// Skip the message handling. continue; } else { /// Free the message. sxr_Free(msg); /// Don't handle the key pressing. } } }
TASK_ENTRY BAL_MainTaskEntry(void *pData) { INT8 IsUDisk = 0; BOOL need_draw = TRUE; INT32 active = 0; //当前活动的项目 INT32 result = APP_DEFAULT_RESULT; INT32 ret = RESULT_NULL; INT32 bt_active_ret = RESULT_NULL; TM_SYSTEMTIME systime; extern BOOL g_usb_connected; // dump version and date //hal_HstSendEvent(SYS_EVENT,0x11223344); //hal_HstSendEvent(SYS_EVENT,GetPlatformVersion()); //hal_HstSendEvent(SYS_EVENT,GetPlatformRevision()); //hal_HstSendEvent(SYS_EVENT,GetPlatformBuildDate()); //hal_HstSendEvent(SYS_EVENT,AP_GetVersion()); //hal_HstSendEvent(SYS_EVENT,AP_GetBuildDate()); APP_ReadComPara(); //读取系统的全局变量。可以放在os初始化的过程中做 #if XDL_APP_SUPPORT_LOWBAT_DETECT==1//warkey 2.1 StartBatTimer(); #endif gui_load_resource(g_comval->langid); LED_SetPattern(GUI_LED_POWERON, 1); #if APP_SUPPORT_LCD==1 if(AP_Support_LCD()) { lcdd_Open(); GUI_Initialise(g_displayconfig.lcd_width, g_displayconfig.lcd_heigth); GUI_SetTextColor(g_displayconfig.font_color); GUI_SetBackColor(g_displayconfig.back_color); } #endif if(g_test_mode) { NVRAMWriteData(); APP_Test_Mode(); } APP_DisplaySysLogo(FALSE); AP_GetBuildDate();//force link date time functions. // check systemtime TM_GetSystemTime(&systime); if(systime.uHour >= 24 || systime.uDay == 0 || systime.uYear > 2050) // invalid date time { systime.uYear = 2012; systime.uMonth = 8; systime.uDay = 15; systime.uHour = 12; systime.uMinute = 30; TM_SetSystemTime(&systime); } #if APP_SUPPORT_LCD==1 TIMER_SetAlarm(1); #endif hal_HstSendEvent(SYS_EVENT, 0x09250001); APP_InitialFunPtr(); //初始化各个模块的回调函数,最后通过宏定义来实现开关 APP_Read_Sys_Config(); LED_SetPattern(GUI_LED_NONE, 1); hal_HstSendEvent(BOOT_EVENT, 0x09558000); #if APP_SUPPORT_LCD==0 //added for T_card update without LCD. Search TF card, if there is a file with the name "tflash_update.bin", then do the update. #ifdef MCD_TFCARD_SUPPORT { INT32 file = -1, card_ok = -1; UINT32 cur_data = AP_GetBuildDate(); UINT32 cur_time = AP_GetBuildTime(); boolean needupdate = FALSE; hal_HstSendEvent(BOOT_EVENT, 0x98880001); hal_HstSendEvent(BOOT_EVENT, cur_data); hal_HstSendEvent(BOOT_EVENT, cur_time); hal_HstSendEvent(BOOT_EVENT, 0x98880001); card_ok = FS_MountDevice(FS_DEV_TYPE_TFLASH); hal_HstSendEvent(BOOT_EVENT, card_ok); if(card_ok == ERR_SUCCESS) { FS_FILE_ATTR file_attr; TM_FILETIME sFileTime; TM_SYSTEMTIME sSysTm; UINT32 bin_createDate = 0; UINT32 bin_createTime = 0; UINT32 offset = 0; file = FS_Open(UPDATE_TFLASH_BIN_NAME, FS_O_RDWR, 0); hal_HstSendEvent(BOOT_EVENT, 0x09550000); hal_HstSendEvent(BOOT_EVENT, file); hal_HstSendEvent(BOOT_EVENT, 0x09550000); #if 1 FS_Seek(file, 0xc, FS_SEEK_SET); FS_Read(file, &offset, 4); FS_Seek(file, ((offset & 0x00ffffff)) - 0x10, FS_SEEK_SET); FS_Read(file, &bin_createDate, 4); FS_Read(file, &bin_createTime, 4); hal_HstSendEvent(BOOT_EVENT, 0x98880002); hal_HstSendEvent(BOOT_EVENT, bin_createDate); hal_HstSendEvent(BOOT_EVENT, bin_createTime); hal_HstSendEvent(BOOT_EVENT, 0x98880002); #else if(FS_GetFileAttrByHandle(file, &file_attr) == 0) { sFileTime.DateTime = file_attr.i_mtime; TM_FileTimeToSystemTime(sFileTime, &sSysTm); bin_createDate = ((sSysTm.uYear) * 10000 + ((sSysTm.uMonth) * 100) + sSysTm.uDay); bin_createTime = sSysTm.uHour * 10000 + sSysTm.uMinute * 100 + sSysTm.uSecond; hal_HstSendEvent(BOOT_EVENT, 0x98880002); hal_HstSendEvent(BOOT_EVENT, bin_createDate); hal_HstSendEvent(BOOT_EVENT, bin_createTime); hal_HstSendEvent(BOOT_EVENT, 0x98880002); } #endif //if((cur_data<bin_createDate) || //(cur_data==bin_createDate && cur_time<bin_createTime)) if((cur_data != bin_createDate) || (cur_time != bin_createTime)) //只要不是同一软件就允许升级 { needupdate = TRUE; } hal_HstSendEvent(BOOT_EVENT, needupdate); hal_HstSendEvent(BOOT_EVENT, 0x98880008); if(file >= 0 && needupdate) { Upgrade_Flash(file); RestartSystem(); } else { FS_Close(file); } } } #endif #endif g_last_reslt = result; if(GetUsbCableStatus()) { hal_HstSendEvent(APP_EVENT, 0x13113001); result = RESULT_UDISK; } if(gpio_detect_linein() == GPIO_DETECTED) { hal_HstSendEvent(APP_EVENT, 0x13113002); result = RESULT_LINE_IN; } // IsUDisk = g_comval->Onlinedev; #ifdef SUPPORT_POWERON_ENTER_CHARGE_AP//warkey 2.1 app_trace(APP_MAIN_TRC, "GetBattery:%d", GetBattery()); if(-1 == GetBattery() && g_usb_connected == 0) { // hal_HstSendEvent(SYS_EVENT, 0x13062707); hal_HstSendEvent(APP_EVENT, 0x13113003); result = Charging_Entry(); } #endif while(1) { if(result==RESULT_STANDBY) { LED_SetPattern(GUI_LED_NONE, 0xde); } else { LED_SetPattern(GUI_LED_NONE, 1); } hal_HstSendEvent(SYS_EVENT, 0x09250002); hal_HstSendEvent(SYS_EVENT, result); if(result == RESULT_NULL || result == RESULT_MAIN) { #if APP_SUPPORT_MENU==1 if(AP_Support_MENU()) { ui_auto_select = FALSE; result = GUI_Display_Menu(GUI_MENU_MAIN, main_menu_callback); g_last_reslt = RESULT_NULL; if(result == RESULT_TIMEOUT || result == RESULT_IGNORE || result == RESULT_NULL) { result = RESULT_IDLE; // RESULT_CALENDAR; } } else #endif { if(RESULT_STANDBY != result) { result = g_last_reslt; } switch(result) { case RESULT_STANDBY: break; case RESULT_BT: #if APP_SUPPORT_MUSIC==1 result = RESULT_MUSIC; break; case RESULT_MUSIC: #endif #if APP_SUPPORT_FM || APP_SUPPORT_LINEIN //没有Line in时才进入FM 2012-9-27 if(gpio_detect_linein() == GPIO_DETECTED) { #if APP_SUPPORT_LINEIN ==1 result = RESULT_LINE_IN; break; #else result = RESULT_RADIO; break; #endif } else { #if APP_SUPPORT_FM==1 result = RESULT_RADIO; break; #endif } case RESULT_LINE_IN: case RESULT_RADIO: #endif #if APP_SUPPORT_RECORD if(AP_Support_RECORD()) { result = RESULT_RECORD_NOSTART; break; } case RESULT_RECORD_NOSTART: #endif #if APP_SUPPORT_BLUETOOTH result = RESULT_BT; break; #endif default: result = APP_DEFAULT_RESULT; break; } } } else if(result == RESULT_POWERON) { if(AP_Support_LCD()) { GUI_ClearScreen(NULL); GUI_UpdateScreen(NULL); } LED_SetPattern(GUI_LED_POWERON, 1); APP_DisplaySysLogo(TRUE); LED_SetPattern(GUI_LED_NONE, 1); if (g_comval->LightTime == 0) //每次开机判断一次!解决Bug Report:27 { CloseBacklight(); } else { OpenBacklight(); } //APP_DUMP("g_last_reslt:", g_last_reslt); result = g_last_reslt; if(GetUsbCableStatus()) { hal_HstSendEvent(APP_EVENT, 0x07021549); result = RESULT_UDISK; } if(gpio_detect_linein() == GPIO_DETECTED) { hal_HstSendEvent(APP_EVENT, 0x07021550); result = RESULT_LINE_IN; } need_draw = TRUE; } else //boot with param or result != 0 { switch( result) { #if APP_SUPPORT_MUSIC==1 case RESULT_MUSIC: hal_HstSendEvent(SYS_EVENT, 0x20120000); ret = APP_ModCall(FUN_MUSIC, 0); g_last_reslt = result; result = ret; #if APP_SUPPORT_FADE_INOUT==1 if(g_fade_volume_backup != -1) { // hal_HstSendEvent(SYS_EVENT, 0x13101701); // hal_HstSendEvent(SYS_EVENT, g_fade_volume_backup); SetPAVolume(g_fade_volume_backup); g_fade_volume_backup = -1; } #endif if(g_usb_audio_tcard&&GetUsbCableStatus())//plug in tcard when usb audio is running { result = RESULT_UDISK; } hal_HstSendEvent(SYS_EVENT, 0x20124444); hal_HstSendEvent(SYS_EVENT, g_last_reslt); hal_HstSendEvent(SYS_EVENT, result); break; #endif case RESULT_RADIO: hal_HstSendEvent(SYS_EVENT, 0x20120033); ret = APP_ModCall(FUN_FM, 0); hal_HstSendEvent(SYS_EVENT, 0x20120044); g_last_reslt = result; result = ret; hal_HstSendEvent(SYS_EVENT, 0x20123001); break; case RESULT_RECORD_START: //进入录音 case RESULT_RECORD_NOSTART: case RESULT_FMREC_START: case RESULT_FMREC_NOSTART: ret = APP_ModCall(FUN_RECORD, result); //传入result,以判断是否直接开始FM录音? g_last_reslt = result; result = ret; break; case RESULT_RECORD_SWITCH: if(g_last_reslt == RESULT_RECORD_START || g_last_reslt == RESULT_RECORD_NOSTART) { result = RESULT_FMREC_NOSTART; } else if(g_last_reslt == RESULT_FMREC_START || g_last_reslt == RESULT_FMREC_NOSTART) { result = RESULT_RECORD_NOSTART; } ret = APP_ModCall(FUN_RECORD, result); //传入result,以判断是否直接开始FM录音? g_last_reslt = result; result = ret; break; case RESULT_CHARGING: result = APP_ModCall(FUN_CHARGING, 0); break; case RESULT_IDLE: //APP_DUMP("g_last_reslt:", g_last_reslt); result = APP_ModCall(FUN_IDLE, 0); break; case RESULT_LINE_IN: hal_HstSendEvent(SYS_EVENT, 0x20128888); if(event_detected_displaying_log == RESULT_LINE_IN) { event_detected_displaying_log = 0; } result = APP_ModCall(FUN_LINEIN, 0); hal_HstSendEvent(SYS_EVENT, 0x20129999); hal_HstSendEvent(SYS_EVENT, g_last_reslt); hal_HstSendEvent(SYS_EVENT, result); // if(result == RESULT_NULL || result == RESULT_MAIN) if(g_linein_out_event == 1)//line-in was removed { result = g_last_reslt; if(result == RESULT_LINE_IN) { result = APP_DEFAULT_RESULT; } g_linein_out_event = 0; if(g_usb_audio_linein&&GetUsbCableStatus())//plug in line-in when usb audio is running, so return usb audio again { result = RESULT_UDISK; hal_HstSendEvent(SYS_EVENT, 0x13071801); } } else { g_last_reslt = RESULT_LINE_IN; } break; case RESULT_STANDBY: { extern UINT8 g_light_time; #ifdef SUPPORT_POWERON_ENTER_CHARGE_AP//warkey 2.1 if(-1 == GetBattery()) { result = Charging_Entry(); } else #endif { g_light_time = 0; result = APP_StandBy(); if(g_comval->LightTime != 0) { g_light_time = g_comval->LightTime * 2; OpenBacklight(); } } } break; #if APP_SUPPORT_CALIB_KEY==1 case RESULT_KEYCALIB: result = APP_CalibKey(); break; #endif case RESULT_SYSTEM: ret = APP_ModCall(FUN_SYSTEM_SETTING, 0); g_last_reslt = result; result = ret; break; case RESULT_ALARM: ret = APP_ModCall(FUN_TIMER, 1); g_last_reslt = result; result = ret; break; case RESULT_TIMER: ret = APP_ModCall(FUN_TIMER, 0); g_last_reslt = result; result = ret; break; case RESULT_UDISK: //IsUDisk=1; //if(IsUDisk) { if(g_usb_active_after_bt != 0) { g_usb_active_after_bt = 0; } if(event_detected_displaying_log == RESULT_UDISK) { event_detected_displaying_log = 0; } hal_HstSendEvent(SYS_EVENT, 0x09250003); result = APP_ModCall(FUN_USB, 0); hal_HstSendEvent(SYS_EVENT, 0x09250004); } if(result == RESULT_NULL) { result = g_last_reslt; if(result == RESULT_UDISK) { result = APP_DEFAULT_RESULT; } } if(result == RESULT_BT_ACTIVE) { bt_active_ret = RESULT_UDISK; } //fix udisk return, drop key up //result = RESULT_MUSIC; hal_HstSendEvent(SYS_EVENT, result); break; #if APP_SUPPORT_BLUETOOTH==1 case RESULT_BT: hal_HstSendEvent(SYS_EVENT, 0x20120001); ret = APP_ModCall(FUN_BT, -1); g_last_reslt = result; result = ret; if(musicplay_timer) { COS_KillTimer(musicplay_timer); musicplay_timer = 0; } hal_HstSendEvent(SYS_EVENT, 0x20127777); hal_HstSendEvent(SYS_EVENT, g_last_reslt); hal_HstSendEvent(SYS_EVENT, result); break; case RESULT_BT_ACTIVE: hal_HstSendEvent(SYS_EVENT, 0x20120002); if(bt_active_ret != RESULT_NULL) { result = APP_ModCall(FUN_BT, bt_active_ret); } else { result = APP_ModCall(FUN_BT, g_last_reslt); } //add by wuxiang call_status = 0; g_bt_call_time = 0; bt_active_ret = RESULT_NULL; if(musicplay_timer) { COS_KillTimer(musicplay_timer); musicplay_timer = 0; } //add end hal_HstSendEvent(SYS_EVENT, 0x20126666); if(g_last_reslt == RESULT_ALARM) { result = RESULT_IDLE; } break; #endif case RESULT_CALENDAR: ret = APP_ModCall(FUN_CALENDAR, 0); g_last_reslt = result; result = ret; break; default: //APP_DUMP("never run here: ", result); hal_HstSendEvent(SYS_EVENT, 0x20125555); hal_HstSendEvent(SYS_EVENT, result); result = RESULT_MAIN; break; }//switch(reault) //APP_ReadComPara(); //IsUDisk = 1; //更新Onlinedev need_draw = TRUE; } }//while never exit }