/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ static void usb_detect_irq_handler(void *p_arg) { pusb_struct pusb = &awxx_usb[0]; __u32 temp; temp = usb_get_bus_interrupt_status(pusb); usb_clear_bus_interrupt_status(pusb, temp); __debug("%s,temp=%x\n",__FUNCTION__,temp); if(temp & 0x04) //reset babble detected,set to usb pc { usb_clock_exit(); wBoot_DisableInt(awxx_usb[0].irq_no); power_ops_int_status |= 0x08; wBoot_timer_stop(tmr_hd); wBoot_timer_release(tmr_hd); tmr_hd = NULL; __inf("usb set pc\n"); //power_set_usbpc(); usb_working = 0; } return; }
/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ static void usb_detect_irq_handler(void *p_arg) { pusb_struct pusb = &awxx_usb[0]; __u32 temp; temp = usb_get_bus_interrupt_status(pusb); usb_clear_bus_interrupt_status(pusb, temp); __inf("usb irq %x\n", temp); if(temp & 0x04) { usb_clock_exit(); wBoot_DisableInt(awxx_usb[0].irq_no); wBoot_timer_stop(tmr_hd); wBoot_timer_release(tmr_hd); tmr_hd = NULL; usb_working = 0; //打开usb限流 __inf("usb irq ,set pc\n"); wBoot_power_limit_topc(); } return; }
/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ static void timer_test_usbdc(void *p_arg) { usb_clock_exit(); wBoot_DisableInt(awxx_usb[0].irq_no); usb_working = 0; //打开火牛限流 __inf("timer irq ,set dc\n"); wBoot_power_limit_todc(); return ; }
/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : * * 说明 : * * ************************************************************************************************************ */ __u32 usb_detect_exit(void) { __inf("usb exit detect\n"); usb_working = 0; usb_clock_exit(); wBoot_DisableInt(awxx_usb[0].irq_no); if(tmr_hd) { wBoot_timer_stop(tmr_hd); wBoot_timer_release(tmr_hd); tmr_hd = NULL; } return 0; }
/* ************************************************************************************************************ * * function * * 函数名称: * * 参数列表: * * 返回值 : 0:正常启动 * -1:关机 * * 说明 :如果是量产完成,直接关机 * * ************************************************************************************************************ */ __s32 check_power_status(void) { __s32 status; __s32 power_start; #ifdef CONFIG_AW_HOMELET_PRODUCT return 0; #endif status = wBoot_power_get_level(); if(status == BATTERY_RATIO_TOO_LOW_WITHOUT_DCIN) //低电状态下,无外部电源,直接关机 { __inf("battery low power with no dc or ac, should set power off\n"); ShowPictureEx("c:\\os_show\\low_pwr.bmp", 0); wBoot_timer_delay(3000); return -1; } power_start = 0; // 0: 不允许插火牛直接开机,必须通过判断:满足以下条件可以直接开机:长按power按键,前次是系统状态,如果电池电量过低,则不允许开机 // 1: 任意状态下,允许插火牛直接开机,同时要求电池电量足够高 // 2: 不允许插火牛直接开机,必须通过判断:满足以下条件可以直接开机:长按power按键,前次是系统状态,不要求电池电量 // 3: 任意状态下,允许插火牛直接开机,不要求电池电量 if(wBoot_script_parser_fetch("target", "power_start", &power_start, 1)) { power_start=0; } __debug("status=%d\n",status); switch(status) { case BATTERY_RATIO_ENOUGH: __inf("battery enough\n"); break; case BATTERY_RATIO_TOO_LOW_WITH_DCIN: __inf("battery too low with dc\n"); break; case BATTERY_RATIO_TOO_LOW_WITHOUT_DCIN: __inf("battery too low without dc\n"); break; default: break; } __inf("power_start=%x\n", power_start); if(status == BATTERY_RATIO_TOO_LOW_WITH_DCIN) //低电,同时带外部电源状态下 { if(!(power_start & 0x02)) //需要判断当前电池电量,要求power_start的第1bit的值为0 { //此种情况下,直接关机 __inf("battery low power with dc or ac, should charge longer\n"); ShowPictureEx("c:\\os_show\\bempty.bmp", 0); wBoot_timer_delay(3000); return -1; } else { if(power_start == 3) //不需要判断当前电池电量,如果为3,则进入系统,如果为0,则进行后续判断 { return 0; } } } else //电池电量足够情况下 { if(power_start & 0x01) //如果第0bit的值为1,则进入系统 { return 0; } } //其它情况下,进入后续判断 status = -1; status = wBoot_power_check_startup(); #ifdef FORCE_BOOT_STANDBY status = 0; #endif if(status) { return 0; } { __u32 dcin, bat_exist; __s32 bat_cal, this_bat_cal; __u32 bat_show_hd = NULL; int i, j; int bat_full_status = 0; //当前可以确定是火牛开机,但是是否开机还不确定,需要确认电池是否存在 WaitForDeInitFinish();//等 LCD init结束,release hard timer. power_int_reg(); usb_detect_enter(); bat_show_hd = ShowBatteryCharge_init(0); //wBoot_timer_delay(1500); dcin = 0; bat_exist = 0; wBoot_power_get_dcin_battery_exist(&dcin, &bat_exist); if(!bat_exist) { __inf("no battery exist\n"); ShowBatteryCharge_exit(bat_show_hd); power_int_rel(); usb_detect_exit(); return 0; } wlibc_int_disable(); this_bat_cal = wBoot_power_get_cal(); wlibc_int_enable(); __inf("base bat_cal = %d\n", this_bat_cal); if(this_bat_cal > 95) { this_bat_cal = 100; } if(this_bat_cal == 100) { ShowBatteryCharge_exit(bat_show_hd); bat_show_hd = NULL; show_battery_full(&bat_full_status); for(i =0; i<12; i++) { if(power_ops_int_status & 0x02) //短按 { power_ops_int_status &= ~0x02; j = 0; __inf("short key\n"); } else if(power_ops_int_status & 0x01) //长按 { wlibc_int_disable(); power_int_rel(); usb_detect_exit(); power_ops_int_status &= ~0x01; wlibc_int_enable(); power_int_reg(); __inf("long key\n"); return 0; } wBoot_timer_delay(250); } } else { int one_delay; one_delay = 1000/(10 - (this_bat_cal/10)); for(j=0; j<3; j++) { for(i=this_bat_cal; i<110; i+=10) { ShowBatteryCharge_rate(bat_show_hd, i); wBoot_timer_delay(one_delay); if(power_ops_int_status & 0x02) //短按 { power_ops_int_status &= ~0x02; j = 0; __inf("short key\n"); } else if(power_ops_int_status & 0x01) //长按 { ShowBatteryCharge_exit(bat_show_hd); wlibc_int_disable(); power_int_rel(); usb_detect_exit(); power_ops_int_status &= ~0x01; wlibc_int_enable(); power_int_reg(); __inf("long key\n"); return 0; } } } ShowBatteryCharge_rate(bat_show_hd, this_bat_cal); wBoot_timer_delay(1000); } wBoot_power_get_key(); __inf("extenal power low go high startup\n"); /****************************************************************** * * standby 返回值说明 * * -1: 进入standby失败 * 1: 普通按键唤醒 * 2: 电源按键短按唤醒 * 3: 电源按键长按唤醒 * 4: 外部电源移除唤醒 * 5: 电池充电完成 * 6: 在唤醒状态下外部电源被移除 * 7: 在唤醒状态下充电完成 * ******************************************************************/ do { if(power_ops_int_status & 0x04) { status = 8; power_ops_int_status &= ~0x04; } else { wlibc_int_disable(); power_int_rel(); usb_detect_exit(); wlibc_int_enable(); De_CloseLayer(board_res.layer_hd); wBoot_EnableInt(GIC_SRC_NMI); __inf("enter standby\n"); status = wBoot_standby(); __inf("exit standby by %d\n", status); wBoot_DisableInt(GIC_SRC_NMI); wlibc_int_disable(); bat_cal = wBoot_power_get_cal(); wlibc_int_enable(); __inf("current bat_cal = %d\n", bat_cal); if(bat_cal > this_bat_cal) { this_bat_cal = bat_cal; if(this_bat_cal > 95) { this_bat_cal = 100; } } } switch(status) { case 2: //短按power按键导致唤醒 { power_int_reg(); De_OpenLayer(board_res.layer_hd); if(this_bat_cal == 100) { if(bat_show_hd) { ShowBatteryCharge_exit(bat_show_hd); bat_show_hd = NULL; } show_battery_full(&bat_full_status); for(i =0; i<12; i++) { if(power_ops_int_status & 0x02) //短按 { power_ops_int_status &= ~0x02; i = 0; __msg("short key\n"); } else if(power_ops_int_status & 0x01) //长按 { ShowBatteryCharge_exit(bat_show_hd); wlibc_int_disable(); power_int_rel(); usb_detect_exit(); power_ops_int_status &= ~0x01; wlibc_int_enable(); power_int_reg(); __inf("long key\n"); return 0; } wBoot_timer_delay(250); } } else { int one_delay; one_delay = 1000/(10 - (this_bat_cal/10)); for(j=0; j<3; j++) { for(i=this_bat_cal; i<110; i+=10) { ShowBatteryCharge_rate(bat_show_hd, i); wBoot_timer_delay(one_delay); if(power_ops_int_status & 0x02) //短按 { power_ops_int_status &= ~0x02; j = 0; __msg("short key\n"); } else if(power_ops_int_status & 0x01) //长按 { ShowBatteryCharge_exit(bat_show_hd); wlibc_int_disable(); power_int_rel(); usb_detect_exit(); power_ops_int_status &= ~0x01; wlibc_int_enable(); power_int_reg(); __inf("long key\n"); return 0; } } } ShowBatteryCharge_rate(bat_show_hd, this_bat_cal); wBoot_timer_delay(1000); } } break; case 3: //长按电源按键之后,关闭电池图标,进入系统 { ShowBatteryCharge_exit(bat_show_hd); power_int_reg(); return 0; } case 4: //当移除外部电源时候,重新显示当前电池图标后,3秒后关机 case 5: //当电池充电完成的时候,需要关机 De_OpenLayer(board_res.layer_hd); ShowBatteryCharge_rate(bat_show_hd, this_bat_cal); case 6: case 7: { power_int_reg(); if((status != 4) && (status != 5)) { De_OpenLayer(board_res.layer_hd); ShowBatteryCharge_rate(bat_show_hd, this_bat_cal); } wBoot_timer_delay(500); if(bat_show_hd) { ShowBatteryCharge_degrade(bat_show_hd, 10); ShowBatteryCharge_exit(bat_show_hd); } else { shut_battery_full(); } return -1; } case 8: //standby过程中检测到vbus接入 { usb_detect_enter(); wBoot_timer_delay(600); usb_detect_exit(); } break; case 9: //standby过程中检测到vbus移除,同时存在普通dc { power_set_usbpc(); } break; default: break; } } while(1); } }