bool Is5vPresent( void )
{
    return ( IsVbusValid() || IsVdd5vGtVddio() );
}
////////////////////////////////////////////////////////////////////////////////
//! \brief
//!
//! \return
////////////////////////////////////////////////////////////////////////////////
int PowerPrep_ConfigurePowerSource( void )
{
	int iReturnValue = SUCCESS;

	/* initialize DCDC operating parameters */
	hw_power_Init();

#ifdef  NO_DCDC_BATT_SOURCE

	/* device configured for no source to DCDC_BATT input (5V only power
	 * source).  This boot option doesn't waste time looking for a good
	 *  battery.  Battery powered operation and automatic voltage
	 *  measurements are disabled.
	*/
    // set bit 11 of PERSISTENT1
    HW_RTC_PERSISTENT1_SET(0x800);

    // clear bit 12 PERSISTENT1
    HW_RTC_PERSISTENT1_CLR(0x1000);

	bBatteryReady = false;
	bBatteryGood = false;

	printf("\r\nConfigured for 5v only power source.\
		Battery powered operation disabled.\r\n");


	/* Disable automatic battery voltage measurements which seem unnecessary
	 * for this configuration.
	 */
    BF_SET(POWER_BATTMONITOR,EN_BATADJ);
	BF_CLR(LRADC_CONVERSION, AUTOMATIC);
	BF_WR(POWER_BATTMONITOR, BATT_VAL,525);  //4200/8

	HW_POWER_BATTMONITOR.B.BRWNOUT_LVL = BATTERY_BRWNOUT_BITFIELD_VALUE;

	iReturnValue = PowerPrep_5vBoot();

#ifndef MXS_VBUS_CURRENT_DRAW
	PowerPrep_CPUClock2PLL();
#endif


#elif defined(NO_VDD5V_SOURCE)
	printf("\r\nConfigured for DCDC_BATT only power source.\r\n");

#ifdef mx28
	/* We only care about the DCDC_BATT source in this configuration */
	BF_SET(POWER_BATTMONITOR,PWDN_BATTBRNOUT_5VDETECT_ENABLE);
#endif

    // clear bit 11 PERSISTENT1
    HW_RTC_PERSISTENT1_CLR(0x800);

    // set bit 12 PERSISTENT1
    HW_RTC_PERSISTENT1_SET(0x1000);
	/* since the DCDC_BATT input is our only source, we'll assume
	 * it is good and attempt to boot.  If your device has uses
	 * this configuration but has a external DCDC_BATT source
	 * that takes time to ramp, you could add a voltage check
	 * and wait here until voltage reaches near the final level to
	 * avoid trigger a battery brownout when the voltage is too
	 * low.
	 */
	bBatteryReady = true;

	/* bBatteryGood is not used for this configuration */
	/* bBatteryGood = don't care */

	/*Boot from DCDC_BATT source*/
	iReturnValue = PowerPrep_BattBoot();
	PowerPrep_CPUClock2PLL();

	/* raise battery brownout level to programmed value. */
	PowerPrep_InitBattBo();

	/* Configured to not use a VDD5V source */
	HW_POWER_5VCTRL_SET(BM_POWER_5VCTRL_ILIMIT_EQ_ZERO);




#else

    //clear bit 11 and 12 of PERSISTENT1
    HW_RTC_PERSISTENT1_CLR(0x1800);

	/* check if Battery Voltage is high enough for full
	* power operation.
	*/
	bBatteryReady = PowerPrep_IsBatteryReady();

	if(!IsVdd5vGtVddio())
	{
		/* this option allows for fast booting without
		* the unecessary delay required for proper
		* battery detection when booting from 5v.
		*/

		/* battery voltage is present and 5v is not connected,
		* assume valid battery voltage source is present.  Battery
		* brownout protection will take care of supply protection
		* if battery becomes invalid in the future
		*/
 		bBatteryGood = true;
		printf("\r\nboot from battery. 5v input not detected\r\n");
		/*Boot from battery*/
		iReturnValue = PowerPrep_BattBoot();
		PowerPrep_CPUClock2PLL();
	}
	else
	{
		/* 5v input detected, boot from 5V.
		*/
		bBatteryGood = PowerPrep_IsBatteryGood();
		if(!bBatteryGood) {
				BF_CLR(LRADC_CONVERSION, AUTOMATIC);
				BF_WR(POWER_BATTMONITOR, BATT_VAL,0);
				printf("\r\nNo battery or bad battery\
					detected!!!.Disabling battery\
					voltage measurements./r/n");
		}
		iReturnValue = PowerPrep_5vBoot();


#ifndef MXS_VBUS_CURRENT_DRAW
		PowerPrep_CPUClock2PLL();
#endif /* MXS_VBUS_CURRENT_DRAW */
	}
Exemple #3
0
////////////////////////////////////////////////////////////////////////////////
//! \brief
//!
//! \return
////////////////////////////////////////////////////////////////////////////////
int PowerPrep_ConfigurePowerSource( void )
{
	int iReturnValue = SUCCESS;

	/* initialize DCDC operating parameters */
	hw_power_Init();

#ifdef  NO_BATTERY_VOLTAGE_SOURCE

	/* device configured for "no battery" operation (5V only power source).  This boot
	* option doesn't waste time looking for a good battery.  Battery powered
	* operation and automatic voltage measurements are disabled.
	*/

	bBatteryReady = false;
	bBatteryGood = false;

	printf("\r\nConfigured for 5v only power source.\
		Battery powered operation disabled.\r\n");

	/* disable automatic battery voltage measurements */
	BF_CLR(LRADC_CONVERSION, AUTOMATIC);
	BF_WR(POWER_BATTMONITOR, BATT_VAL,0);

	iReturnValue = PowerPrep_5vBoot();

#ifndef MXS_VBUS_CURRENT_DRAW
	PowerPrep_CPUClock2PLL();
#endif
#else
	/* check if Battery Voltage is high enough for full
	* power operation.
	*/
	bBatteryReady = PowerPrep_IsBatteryReady();

	if(!IsVdd5vGtVddio())
	{
		/* this option allows for fast booting without
		* the unecessary delay required for proper
		* battery detection when booting from 5v.
		*/

		/* battery voltage is present and 5v is not connected,
		* assume valid battery voltage source is present.  Battery
		* brownout protection will take care of supply protection
		* if battery becomes invalid in the future
		*/
 		bBatteryGood = true;
		printf("\r\nboot from battery. 5v input not detected\r\n");
		/*Boot from battery*/
		iReturnValue = PowerPrep_BattBoot();
		PowerPrep_CPUClock2PLL();
	}
	else
	{
		/* 5v input detected.  Now we need to determine if a
		* valid battery source is present to decide which
		* power source to use during bootup.
		*/
		bBatteryGood = PowerPrep_IsBatteryGood();
		if(!bBatteryReady)
		{
			if(bBatteryGood)
				/* control arrives here if the battery voltage source
				* appears to be chargeable but the voltage is current
				* too low to use as a reliable battery voltage source.
				*/
				printf("\r\nChargeable battery detected but\
					the voltage is too low for battery\
					powered operation.Booting from 5V\
					power source.\r\n");
			else {
				BF_CLR(LRADC_CONVERSION, AUTOMATIC);
				BF_WR(POWER_BATTMONITOR, BATT_VAL,0);
				printf("\r\nNo battery or bad battery\
					detected!!!.Disabling battery\
					voltage measurements./r/n");
			}
			iReturnValue = PowerPrep_5vBoot();
#ifndef MXS_VBUS_CURRENT_DRAW
			PowerPrep_CPUClock2PLL();
#endif /* MXS_VBUS_CURRENT_DRAW */
		}
		else
		{
			printf("\r\n5v source detected.Valid battery\
				voltage detected.Booting from battery\
				voltage source.\r\n");
			/*Boot from battery*/
			iReturnValue = PowerPrep_BattBoot();
			PowerPrep_CPUClock2PLL();

		}
	}