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

📄 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 页
字号:

//------------------------------------------------------------------------------
//
// Function: PmicBatteryGetOvervoltageThreshold
//
// This function returns the overvoltage threshold value
//
// Parameters:
//      ovthresholdlevel [OUT] pointer to overvoltage threshold level
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryGetOvervoltageThreshold (UINT8* ovthresholdlevel)
{
    UINT32 param, temp;
    
    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
    if (ovthresholdlevel == NULL)
    {
        DEBUGMSG(ZONE_ERROR, (_T("PmicBatteryGetOvervoltageThreshold:Invalid Parameter\r\n")));
        return PMIC_PARAMETER_ERROR;
    }
    param = MC13783_CHG0_ADDR;

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

    *ovthresholdlevel  = CSP_BITFEXT(temp, MC13783_CHG0_OVCTRL);

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryUnregulatedChargeDisable
//
// This function disables the unregulated charge path. The voltage and current 
// limits will be controlled by the charge path regulator.
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryUnregulatedChargeDisable()
{
    PMIC_PARAM_LLA_WRITE_REG param;

    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_CHG0_ADDR;
    param.data = CSP_BITFVAL(MC13783_CHG0_UCHEN, MC13783_CHG0_UCHEN_DISABLE);
    param.mask = CSP_BITFMASK(MC13783_CHG0_UCHEN);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryUnregulatedChargeEnable
//
// This function enables the unregulated charge path. The settings of the charge
// path regulator (voltage and current limits) will be overruled.
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryUnregulatedChargeEnable()
{
    PMIC_PARAM_LLA_WRITE_REG param;

    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_CHG0_ADDR;
    param.data = CSP_BITFVAL(MC13783_CHG0_UCHEN, MC13783_CHG0_UCHEN_ENABLE);
    param.mask = CSP_BITFMASK(MC13783_CHG0_UCHEN);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryChargeLedDisable
//
// This function disables the charging LED
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryChargeLedDisable()
{
    PMIC_PARAM_LLA_WRITE_REG param;

    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_CHG0_ADDR;
    param.data = CSP_BITFVAL(MC13783_CHG0_CHRGLEDEN, MC13783_CHG0_CHRGLEDEN_DISABLE);
    param.mask = CSP_BITFMASK(MC13783_CHG0_CHRGLEDEN);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryChargeLedEnable
//
// This function enables the charging LED
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryChargeLedEnable()
{
    PMIC_PARAM_LLA_WRITE_REG param;

    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_CHG0_ADDR;
    param.data = CSP_BITFVAL(MC13783_CHG0_CHRGLEDEN, MC13783_CHG0_CHRGLEDEN_ENABLE);
    param.mask = CSP_BITFMASK(MC13783_CHG0_CHRGLEDEN);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryEnablePulldown
//
// This function enables the 5k pulldown resistor used in the dual path charging
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryEnablePulldown()
{
    PMIC_PARAM_LLA_WRITE_REG param;

    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_CHG0_ADDR;
    param.data = CSP_BITFVAL(MC13783_CHG0_CHRGRAWPDEN, MC13783_CHG0_CHRGRAWPDEN_ENABLE);
    param.mask = CSP_BITFMASK(MC13783_CHG0_CHRGRAWPDEN);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryDisablePulldown
//
// This function disables the 5k pulldown resistor used in dual path charging
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryDisablePulldown()
{
    PMIC_PARAM_LLA_WRITE_REG param;

    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_CHG0_ADDR;
    param.data = CSP_BITFVAL(MC13783_CHG0_CHRGRAWPDEN, MC13783_CHG0_CHRGRAWPDEN_DISABLE);
    param.mask = CSP_BITFMASK(MC13783_CHG0_CHRGRAWPDEN);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryEnableCoincellCharger
//
// This function enables the coincell charger
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryEnableCoincellCharger()
{
    PMIC_PARAM_LLA_WRITE_REG param;
    
    
    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_PWR_CTL0_ADDR;
    param.data = CSP_BITFVAL(MC13783_PWR_CTL0_COINCHEN, MC13783_PWR_CTL0_COINCHEN_ENABLE);
    param.mask = CSP_BITFMASK(MC13783_PWR_CTL0_COINCHEN);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//-----------------------------------------------------------------------------
//
// Function: PmicBatteryDisableCoincellCharger
//
// This function disables the coincell charger
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryDisableCoincellCharger()
{
    PMIC_PARAM_LLA_WRITE_REG param;

    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_PWR_CTL0_ADDR;
    param.data = CSP_BITFVAL(MC13783_PWR_CTL0_COINCHEN, MC13783_PWR_CTL0_COINCHEN_DISABLE);
    param.mask = CSP_BITFMASK(MC13783_PWR_CTL0_COINCHEN);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));
        
        
    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatterySetCoincellVoltage
//
// This function programs the output voltage level of coincell charger
//
// Parameters:
//      votlagelevel [IN] voltage level
//      level 0 = 2.7V
//            1 = 2.8V
//            2 = 2.9V
//            ... (in 100mV increment)
//            6 = 3.3V   
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatterySetCoincellVoltage (UINT8 coincellvoltagelevel)
{
    PMIC_PARAM_LLA_WRITE_REG param;
    
    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    // check coincell voltage level parameter
    if (coincellvoltagelevel > MC13783_BATTERY_MAX_COINCELL_VOLTAGE_LEVEL)
    {
        ERRORMSG(1, (_T("PmicBatterySetCoincellVoltage Invalid Parameter\r\n")));
        return PMIC_PARAMETER_ERROR;
    }

    param.addr = MC13783_PWR_CTL0_ADDR;
    param.data = CSP_BITFVAL(MC13783_PWR_CTL0_VCOIN, coincellvoltagelevel);
    param.mask = CSP_BITFMASK(MC13783_PWR_CTL0_VCOIN);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryGetCoincellVoltage
//
// This function returns the output voltage level of coincell charger
//
// Parameters:
//      voltagelevel [OUT] pointer to voltage level
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryGetCoincellVoltage (UINT8* coincellvoltagelevel)
{
    UINT32 param, temp;
    
    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));
    if (coincellvoltagelevel == NULL)
    {
        DEBUGMSG(ZONE_ERROR, (_T("PmicBatteryGetCoincellVoltage:Invalid Parameter\r\n")));
        return PMIC_PARAMETER_ERROR;
    }
    param = MC13783_PWR_CTL0_ADDR;

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

    *coincellvoltagelevel  = CSP_BITFEXT(temp, MC13783_PWR_CTL0_VCOIN);

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryEnableEolComparator
//
// This function enables the end-of-life function instead of the LOBAT
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryEnableEolComparator()
{
    PMIC_PARAM_LLA_WRITE_REG param;

    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_PWR_CTL0_ADDR;
    param.data = CSP_BITFVAL(MC13783_PWR_CTL0_EOLSEL, MC13783_PWR_CTL0_EOLSEL_ENABLE);
    param.mask = CSP_BITFMASK(MC13783_PWR_CTL0_EOLSEL);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
//
// Function: PmicBatteryDisableEolComparator
//
// This function disables the end-of-life comparator function
//
// Parameters:
//      None.
//      
//
// Returns:
//      PMIC_STATUS.
//
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryDisableEolComparator()
{
    PMIC_PARAM_LLA_WRITE_REG param;

    DEBUGMSG(ZONE_FUNC, (TEXT("+%s()\r\n"), __WFUNCTION__));

    param.addr = MC13783_PWR_CTL0_ADDR;
    param.data = CSP_BITFVAL(MC13783_PWR_CTL0_EOLSEL, MC13783_PWR_CTL0_EOLSEL_DISABLE);
    param.mask = CSP_BITFMASK(MC13783_PWR_CTL0_EOLSEL);

    if(! DeviceIoControl(hPMI, PMIC_IOCTL_LLA_WRITE_REG, &param,
              sizeof(param), NULL, 0, NULL, NULL))
        return PMIC_ERROR;

    DEBUGMSG(ZONE_FUNC, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return PMIC_SUCCESS;
}

//------------------------------------------------------------------------------
// Function: PmicBatteryGetChargerMode
//
//      This function returns the charger mode (ie. Dual Path, Single Path, 
//  Serial Path, Dual Input Single Path and Dual Input Serial Path).
// 
//      The way the bits are mapped to the actual pin definitions is:
//              LLOW --> GND 
//              OPEN --> HI Z
//              HHIGH--> VPMIC
//
// Parameters:
//       mode [OUT] pointer to charger mode.
//      
// Returns:
//      PMIC_STATUS.
//
// Remarks: 
//      
//------------------------------------------------------------------------------
PMIC_STATUS PmicBatteryGetChargerMode(CHARGER_MODE *mode)
{    

⌨️ 快捷键说明

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