コード例 #1
0
ファイル: load_check.c プロジェクト: Aorjoa/bootloader
static int 	board_probe_battery_exist(void)		//获取电池状态
{
	int counter;
	int dc_exist, bat_exist;

	counter = 4;
	do
	{
		dc_exist = 0;
		bat_exist = 0;
		axp_power_get_dcin_battery_exist(&dc_exist, &bat_exist);
		printf("bat_exist=%d\n", bat_exist);
		if(bat_exist == -1)
		{
			printf("bat is unknown\n");
			__msdelay(500);
		}
		else
		{
			break;
		}
	}
	while(counter --);

	return bat_exist;
}
コード例 #2
0
ファイル: power_probe.c プロジェクト: Aorjoa/bootloader
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
static void power_int_irq(void *p_arg)
{
#ifdef DEBUG
	int i;
#endif
	unsigned char power_int_status[8];
	int  dc_exist, bat_exist;

	axp_int_query(power_int_status);
#ifdef DEBUG
	for(i=0;i<5;i++)
	{
		tick_printf("int status %d %x\n", i, power_int_status[i]);
	}
#endif
	if(power_int_status[0] & 0x48)   //外部电源插入
	{
		axp_power_get_dcin_battery_exist(&dc_exist, &bat_exist);
		if(dc_exist)
		{
			tick_printf("power insert\n");
			boot_standby_action &= ~0x10;
			boot_standby_action |= 0x04;
		}
	}
	if(power_int_status[0] & 0x8)   //usb 插入中断,启动usb检测
	{
		tick_printf("usb in\n");
		boot_standby_action |= 8;
		usb_detect_enter();
	}
	if(power_int_status[0] & 0x4)
	{
		tick_printf("usb out\n");
		boot_standby_action &= ~0x04;
		boot_standby_action |= 0x10;
		usb_detect_exit();
	}
	if(power_int_status[2] & 0x2)	//短按键
	{
		tick_printf("short key\n");
		boot_standby_action |= 2;

	}
	if(power_int_status[2] & 0x1)	//长按键
	{
		tick_printf("long key\n");
		boot_standby_action |= 1;
	}

	return;
}
コード例 #3
0
static int board_probe_bat_status(int standby_mode)
{
	int   dc_exist, bat_exist, counter;
	int   bat_init = 0;
	int   bat_cal = 1;
	int   ret, chargemode = 0;
	//当前可以确定是火牛开机,但是是否开机还不确定,需要确认电池是否存在
	//当电池不存在即开机,电池存在则关机
	//新添加,根据环境变量,是启动当前的待机,或者android待机功能
	ret = script_parser_fetch("charging_type", "charging_type", &chargemode, 1);
	if((!ret) && chargemode)
	{
		chargemode = 1;
	}

	counter = 4;
	do
	{
		dc_exist = 0;
		bat_exist = 0;
		axp_power_get_dcin_battery_exist(&dc_exist, &bat_exist);
		printf("bat_exist=%d\n", bat_exist);
		if(bat_exist == -1)
		{
			printf("bat is unknown\n");
			if(!chargemode)
			{
				if(!bat_init)
				{
					if(battery_charge_cartoon_init(0) < 0)
					{
						tick_printf("init charge cartoon fail\n");

						return -1;
					}
					bat_init = 1;
				}
			}
			__msdelay(500);
		}
		else
		{
			break;
		}
	}
	while(counter --);
#ifdef FORCE_BOOT_STANDBY
	bat_exist = 1;
#else
	if(standby_mode)
	{
		bat_exist = 1;
	}
#endif
	if(bat_exist <= 0)
	{
		tick_printf("no battery exist\n");
		if(chargemode)
		{
			return 0;
		}
		if(bat_init)
		{
			battery_charge_cartoon_exit();
		}
		return 0;
	}
	if(chargemode)
	{
		printf("use android charge mode");
		gd->chargemode = 1;

		return 0;
	}
	if(!bat_init)
	{
		bat_cal = axp_probe_rest_battery_capacity();
		printf("bat not inited\n");
		if(battery_charge_cartoon_init(bat_cal/(100/(SUNXI_BAT_BMP_MAX-1))) < 0)
		{
			tick_printf("init charge cartoon fail\n");

			return -1;
		}
	}
	if((!bat_cal) && (standby_mode))
	{
		bat_cal = 100;
	}

	return bat_cal;
}
コード例 #4
0
void power_limit_init(void)
{
	int battery_exist = 0;
	int dcin_exist = 0;
	int vbus_type = 0;
	int i = 0;

	do
	{
		#ifdef CONFIG_ARCH_HOMELET
			break;
		#endif
		axp_power_get_dcin_battery_exist(&dcin_exist, &battery_exist);//判断电池是否存在
		if(battery_exist >= 0)
		{
			break;
		}
		i ++;
		__msdelay(500);
	}
	while(i < 4);

	vbus_type = usb_probe_vbus_type();
	if(vbus_type == 1)								//属于dc类型电源
	{
		printf("vbus not exist\n");
		gd->vbus_status = SUNXI_VBUS_NOT_EXIST;
	}
	else
	{
		printf("vbus exist\n");
		gd->vbus_status = SUNXI_VBUS_EXIST;			//属于vbus类型
	}

	if(battery_exist != BATTERY_EXIST)			//电池不存在,则直接限流到DC模式
	{
		axp_set_vbus_limit_dc();
		puts("no battery, limit to dc\n");

		return ;
	}

	if(dcin_exist == AXP_DCIN_EXIST)		//如果普通外部电源存在,不是VBUS类型
	{
		axp_set_vbus_limit_dc();
		puts("normal dc exist, limit to dc\n");

		return ;
	}

	if(dcin_exist == AXP_VBUS_EXIST)		//如果VBUS电源存在
	{
		vbus_type = usb_probe_vbus_type();

		if(vbus_type == 1)					//属于dc类型电源
		{
			axp_set_vbus_limit_dc();    //dp_dm 拉高
			puts("vbus dc exist, limit to dc\n");
		}
		else
		{
			axp_set_vbus_limit_pc();    //dp_dm 拉低
			axp_set_charge_current(600);
			puts("vbus pc exist, limit to pc\n");
		}

		return ;
	}

	axp_set_vbus_limit_dc();				//只有电池存在
	puts("only battery exist, limit to dc\n");

	return ;
}