⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pmic_battery.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    UINT32 param, temp, chrgmod0, chrgmod1;
    
    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
    
    if (mode == NULL)
    {
        DEBUGMSG(ZONE_ERROR, (_T("PmicBatteryGetChargerMode:Invalid Parameter\r\n")));
        return PMIC_PARAMETER_ERROR;
    } 
    
    param = MC13783_PWR_MOD_ADDR;

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_READ_REG, &param, sizeof(param),
              &temp, sizeof(temp), NULL, NULL))
        return PMIC_ERROR;

    chrgmod0  = CSP_BITFEXT(temp, MC13783_PWR_MOD_CHRGMOD0);

    chrgmod1  = CSP_BITFEXT(temp, MC13783_PWR_MOD_CHRGMOD1);
    
    //To determine and return the Charger Mode
    if (chrgmod0 == LLOW && chrgmod1 == OPEN)
        *mode = DUAL_PATH;
        
    else if (chrgmod0 == OPEN && chrgmod1 == OPEN)
        *mode = SINGLE_PATH;
               
    else if (chrgmod0 == HHIGH && chrgmod1 == OPEN)
        *mode = SERIAL_PATH;

    else if (chrgmod0 == OPEN && chrgmod1 == HHIGH)
        *mode = DUAL_INPUT_SINGLE_PATH;

    else if (chrgmod0 == HHIGH && chrgmod1 == HHIGH)
        *mode = DUAL_INPUT_SERIAL_PATH;        
    
    else
        *mode = INVALID_CHARGER_MODE;
    
    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;

}

//------------------------------------------------------------------------------
// Function: PmicBatteryEnableAdChannel5
//
// This function enables use of AD channel 5 to read charge current
//
// Parameters:
//      None.
//      
// Returns:
//      PMIC_STATUS.
//
// Remarks: 
//      This function is only applicable to Roadrunner, it is a stub function
//      in MC13783
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryEnableAdChannel5()
{    
    return PMIC_SUCCESS;
}

//-----------------------------------------------------------------------------
//
// Function: PmicBatteryDisableAdChannel5
//
// This function disables use of AD channel 5 to read charge current
//
// Parameters:
//      None.      
//
// Returns:
//      PMIC_STATUS.
//
// Remarks: 
//      This function is only applicable to Roadrunner, it is a stub function
//      in MC13783
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryDisableAdChannel5()
{    
    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterySetCoincellCurrentlimit
//
// This function limits the output current level of coincell charger
//
// Parameters:
//      coincellcurrentlevel [IN] coincell current level      
//
// Returns:
//      PMIC_STATUS.
//
// Remarks: 
//      This function is only applicable to Roadrunner, it is a stub function
//      in MC13783
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterySetCoincellCurrentlimit (UINT8 coincellcurrentlevel)
{
    
    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryGetCoincellCurrentlimit
//
// This function returns the output current limit of coincell charger
//
// Parameters:
//      coincellcurrentlevel [OUT] pointer to coincell current level
//      
//
// Returns:
//      PMIC_STATUS.
//
// Remarks: 
//      This function is only applicable to Roadrunner, it is a stub function
//      in MC13783
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryGetCoincellCurrentlimit (UINT8* coincellcurrentlevel)
{
    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterySetEolTrip
//
// This function sets the end-of-life threshold
//
// Parameters:
//      eoltriplevel [IN] eol trip level      
//
// Returns:
//      PMIC_STATUS.
//
// Remarks: 
//      This function is only applicable to Roadrunner, it is a stub function
//      in MC13783
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterySetEolTrip (UINT8 eoltriplevel)
{
        return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryGetEolTrip
//
// This function returns the end-of-life threshold
//
// Parameters:
//      eoltriplevel [OUT] pointer to eol trip level      
//
// Returns:
//      PMIC_STATUS.
//
// Remarks: 
//      This function is only applicable to Roadrunner, it is a stub function
//      in MC13783
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryGetEolTrip (UINT8* eoltriplevel)
{
        return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterEnableCharger
//
// This function is used to start charging a battery. For different charger,
// different voltage and current range are supported.
//
// Parameters:
//      chgr
//          [in]  Charger as defined in BATT_CHARGER.
//      c_voltage
//          [in]  Charging voltage.
//      c_current
//          [in]  Charging current.
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterEnableCharger(BATT_CHARGER chgr, UINT8 c_voltage,
                                        UINT8 c_current)
{
     switch (chgr) 
    {
    case BATT_MAIN_CHGR:
        PmicBatterySetChargeVoltage(c_voltage);
        PmicBatterySetChargeCurrent (c_current);
        break;
                
    case BATT_CELL_CHGR:
        PmicBatteryEnableCoincellCharger ();
        PmicBatterySetCoincellVoltage (c_voltage);
        break;
                
    case BATT_TRCKLE_CHGR:
        PmicBatterySetTrickleCurrent(c_current);
        break;

    default:
        return PMIC_PARAMETER_ERROR;
        break;
    }

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterDisableCharger
//
// This function turns off the selected charger.
//
// Parameters:
//      chgr
//          [in]  Charger as defined in BATT_CHARGER.
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterDisableCharger(BATT_CHARGER chgr)
{
    switch (chgr) 
    {
    case BATT_MAIN_CHGR:
        PmicBatterySetChargeCurrent(0);
        break;
                
    case BATT_CELL_CHGR:
        PmicBatteryDisableCoincellCharger();
        break;
                
    case BATT_TRCKLE_CHGR:
        PmicBatterySetTrickleCurrent(0);
        break;

    default:
        return PMIC_PARAMETER_ERROR;
        break;
    }

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterSetCharger
//
// This function is used to change the charger setting.
//
// Parameters:
//      chgr
//          [in]  Charger as defined in BATT_CHARGER.
//      c_voltage
//          [in]  Charging voltage.
//      c_current
//          [in]  Charging current.
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterSetCharger(BATT_CHARGER chgr, UINT8 c_voltage,
                                        UINT8 c_current)
{
    switch (chgr) 
    {
    case BATT_MAIN_CHGR:
        PmicBatterySetChargeVoltage(c_voltage);
        PmicBatterySetChargeCurrent (c_current);
        break;
                
    case BATT_CELL_CHGR:
        PmicBatterySetCoincellVoltage (c_voltage);
        PmicBatteryEnableCoincellCharger();
        break;
                
    case BATT_TRCKLE_CHGR:
        PmicBatterySetTrickleCurrent(c_current);
        break;

    default:
        return PMIC_PARAMETER_ERROR;
        break;
    }

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterGetChargerSetting
//
// This function is used to retrive the charger setting.
//
// Parameters:
//      chgr
//          [in]  Charger as defined in BATT_CHARGER.
//      c_voltage
//          [out] a pointer to what the charging voltage is set to.
//      c_current
//          [out] a pointer to what the charging current is set to.
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterGetChargerSetting(BATT_CHARGER chgr, UINT8* c_voltage, 
                                        UINT8* c_current)
{
    switch (chgr) 
    {
    case BATT_MAIN_CHGR:
        PmicBatteryGetChargeVoltage(c_voltage);
        PmicBatteryGetChargeCurrent (c_current);
        break;
                
    case BATT_CELL_CHGR:
        PmicBatteryGetCoincellVoltage (c_voltage);
        break;
                
    case BATT_TRCKLE_CHGR:
        PmicBatteryGetTrickleCurrent(c_current);
        break;

    default:
        return PMIC_PARAMETER_ERROR;
        break;
    }

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterGetChargeCurrent
//
// This function retrives the main charger current.
//
// Parameters:
//      c_current
//          [out] a pointer to what the charging current measures
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterGetChargeCurrent(UINT16* c_current)
{
    // 
    return PmicADCGetSingleChannelEightSamples(CHRGISNS_CHNL,
                                                c_current);
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterEnableEol
//
// This function enables End-of-Life comparator.
//
// Parameters:  -- none
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterEnableEol(void)
{
    return PmicBatteryEnableEolComparator();
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterDisableEol
//
// This function disables End-of-Life comparator.
//
// Parameters:  -- none
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterDisableEol(void)
{
    return PmicBatteryDisableEolComparator();
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterLedControl
//
// This function controls charge LED.
//
// Parameters:
//      on
//          [in]  If on is ture, LED will be turned on, or otherwise the
//                LED will be turned off.
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterLedControl(BOOL on)
{
    if (on)
        return PmicBatteryChargeLedEnable();
    else
        return PmicBatteryChargeLedDisable();
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterSetReverseSupply
//
// This function sets reverse supply mode. 
//
// Parameters:
//      enable 
//          [i]]  If enable is ture, reverse supply mode is enable or otherwise 
//                the reverse supply mode is disabled.
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterSetReverseSupply(BOOL enable)
{
    if(enable)
        return PmicBatteryReverseEnable();
    else
        return PmicBatteryReverseDisable();
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterSetUnregulated
//
// This function sets unregulatored charging mode on main battery.
//
// Parameters:
//      enable
//          [in]  If enable is ture, unregulated charging mode is enabled 
//                otherwise it is disabled.
//
// Returns:
//      This function returns PMIC_SUCCESS if successful.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterSetUnregulated(BOOL enable)
{
    if(enable)
        return PmicBatteryUnregulatedChargeEnable();
    else
        return PmicBatteryUnregulatedChargeDisable();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -