Пример #1
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);
    }
}
Пример #2
0
int check_power_status(void)
{
    int var4;
    int var5;
    struct ShowBatteryChangeHandle *var6;
    int var7;
    int var8;
    int var9;
    int vasl;
    int sp0;
    int sp4;
    int sp8;
    int sp12;

    sp12 = svc_3e();
    if(sp12 == 1) {
        wlibc_uprintf(
                "battery low power with no dc or ac, should set power off\n");
        ShowPictureEx("c:\\os_show\\low_pwr.bmp", 0);
        svc_delay(3000);
        return -1;
    }
    if(sp12 == 3) {
        wlibc_uprintf(
                "battery low power with dc or ac, should charge longer\n");
        ShowPictureEx("c:\\os_show\\bempty.bmp", 0);
        svc_delay(3000);
        return -1;

    }
    sp12 = -1;
    svc_b0("target", "power_start", &sp12, 1);
    if(sp12 == 1) {
        return 0;
    }
    sp12 = svc_3b();
    wlibc_uprintf("startup status = %d\n", sp12);
    if( sp12 != 0)
        return 0;
    var6 = 0;
    sp0 = 0;
    power_int_reg();
    usb_detect_enter();
    var6 = ShowBatteryCharge_init();

    svc_delay(1500);
    sp8 = 0;
    sp4 = 0;
    svc_38(&sp8, &sp4);
    if(sp4 == 0) {
        wlibc_uprintf("no battery exist\n");
        ShowBatteryCharge_exit(var6);
        power_int_rel();
        usb_detect_exit();
        return 0;

    }
    wlibc_int_disable();
    var5 = svc_batt_chargerate();
    wlibc_int_enable();
    wlibc_uprintf("base bat_cal = %d\n", var5);
    if(var5 > 95)
        var5 = 100;
    if(var5 == 100) {
        ShowBatteryCharge_exit(var6);
        var6 = 0;
        fnL428008D0(&sp0);
        var7 = 0;
        while(var7 < 12) {
            if( *L4280A3A8 & 2 ) {
                *L4280A3A8 &= ~2;
                var8 = 0;
                wlibc_uprintf("short key\n");
            } else if( *L4280A3A8 & 1 ) {
                wlibc_int_disable();
                power_int_rel();
                usb_detect_exit();
                *L4280A3A8 &= ~1;
                wlibc_int_enable();
                power_int_reg();
                wlibc_uprintf("long key\n");
                return 0;
            }
            svc_delay(250);
            var7 = var7 + 1;
        }
    } else { 
        vasl = 10 - var5 / 10;
        var9 = 1000 / vasl;
        var8 = 0;
        while(var8 < 3) {
            var7 = var5;
            while(var7 < 110) {
                ShowBatteryCharge_rate(var6, var7);
                svc_delay(var9);
                if( *L4280A3A8 & 2 ) {
                    *L4280A3A8 &= ~2;
                    var8 = 0;
                    wlibc_uprintf("short key\n");
                } else if( *L4280A3A8 & 1 ) {
                    ShowBatteryCharge_exit(var6);
                    wlibc_int_disable();
                    power_int_rel();
                    usb_detect_exit();
                    *L4280A3A8 &= ~1;
                    wlibc_int_enable();
                    power_int_reg();
                    wlibc_uprintf("long key\n");
                    return 0;
                }
                var7 = var7 + 10;
            }
            var8 = var8 + 1;
        }
        ShowBatteryCharge_rate(var6, var5);
        svc_delay(1000);
    }
    svc_3a();
    wlibc_uprintf("extenal power low go high startup\n");
    while(1) {
        wlibc_uprintf("enter standby\n");
        if( *L4280A3A8 & 4 ) {
            sp12 = 8;
            *L4280A3A8 &= ~4;
        } else { 
            wlibc_int_disable();
            power_int_rel();
            usb_detect_exit();
            wlibc_int_enable();
            //De_CloseLayer(gDeParam0);
            sp12 = svc_05();
            wlibc_uprintf("exit standby by %d\n", sp12);
            wlibc_int_disable();
            var4 = svc_batt_chargerate();
            wlibc_int_enable();
            wlibc_uprintf("current bat_cal = %d\n", var4);
            if(var4 > var5) {
                var5 = var4;
                var4 = var5;
                if(var5 > 95) {
                    var5 = 100;
                }
            }
        }
        switch( sp12 - 2 ) {
        case 0:
            power_int_reg();
            //De_OpenLayer(gDeParam0);

            if(var5 == 100) {
                if(var6 != 0) {
                    ShowBatteryCharge_exit(var6);
                    var6 = 0;
                }
                fnL428008D0(&sp0);
                var7 = 0;
                while(var7 < 12) {
                    if( *L4280A3A8 & 2 ) {
                        *L4280A3A8 &= ~2;
                        var7 = 0;
                        wlibc_uprintf("MSG:L%d(%s):", 321,
                                "Board/fel_detect/fel_detect.c");
                        wlibc_ntprintf("short key\n");
                    } else { 
                        if( *L4280A3A8 & 1 ) {
                            ShowBatteryCharge_exit(var6);
                            wlibc_int_disable();
                            power_int_rel();
                            usb_detect_exit();
                            *L4280A3A8 &= ~1;
                            wlibc_int_enable();
                            power_int_reg();
                            wlibc_uprintf("long key\n");
                            return 0;
                        }
                    }
                    svc_delay(250);
                    var7 = var7 + 1;
                }
            } else { 
                vasl = 10 - var5 / 10;
                var9 = 1000 / vasl;
                var8 = 0;
                while(var8 < 3) {
                    var7 = var5;
                    while(var7 < 110) {
                        ShowBatteryCharge_rate(var6, var7);
                        svc_delay(var9);
                        if( *L4280A3A8 & 2 ) {
                            *L4280A3A8 &= ~2;
                            var8 = 0;
                            wlibc_uprintf("MSG:L%d(%s):", 354,
                                    "Board/fel_detect/fel_detect.c");
                            wlibc_ntprintf("short key\n");
                        } else if( *L4280A3A8 & 1 ) {
                            ShowBatteryCharge_exit(var6);
                            wlibc_int_disable();
                            power_int_rel();
                            usb_detect_exit();
                            *L4280A3A8 &= ~1;
                            wlibc_int_enable();
                            power_int_reg();
                            wlibc_uprintf("long key\n");
                            return 0;
                        }
                        var7 = var7 + 10;
                    }
                    var8 = var8 + 1;
                }
                ShowBatteryCharge_rate(var6, var5);
                svc_delay(1000);
            }
            break;
        case 1:
            ShowBatteryCharge_exit(var6);
            power_int_reg();
            return 0;
        case 2:
        case 3:
            //De_OpenLayer(gDeParam0);
            ShowBatteryCharge_rate(var6, var5);
        case 4:
        case 5:
            power_int_reg();
            if(sp12 != 4) {
                if(sp12 != 5) {
                    //De_OpenLayer(gDeParam0);
                    ShowBatteryCharge_rate(var6, var5);
                }
            }
            svc_delay(500);
            if(var6 != 0) {
                ShowBatteryCharge_degrade(var6);
                ShowBatteryCharge_exit(var6);
            } else { 
                fnL42800848();
            }
            return -1;
        case 6:
            usb_detect_enter();
            svc_delay(600);
            usb_detect_exit();
            break;
        case 7:
            power_set_usbpc();
            break;
        default:
            break;
        }
    }
}