//------------------------------------------------------------------------------
//
//  Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2004-2007, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//
//  File:  battdrvrUtility.cpp
//
//  Provides the utility function for  battdrvr
//
//------------------------------------------------------------------------------
#pragma warning(push)
#pragma warning(disable: 4115 4201 4204 4214)
#include <windows.h>
#include <stdlib.h>
#pragma warning(pop)

#include "battdrvrUtility.h"


//-----------------------------------------------------------------------------
// External Functions

//-----------------------------------------------------------------------------
// External Variables


//-----------------------------------------------------------------------------
// Defines

#define C_S_TO_MS        1000       // convert factor from sec to milli sec
#define C_A_TO_MA        1000       // convert factor from A to mA
#define C_BASE          100         // base factor to convert peukert number and charge efficiency

//-----------------------------------------------------------------------------
// Types


//-----------------------------------------------------------------------------
// Global Variables


//-----------------------------------------------------------------------------
// Local Variables



//-----------------------------------------------------------------------------
// Local Functions



//------------------------------------------------------------------------------
//
// Function: CalChargingCapacityChange
//
// This function returns the change of the batt capacity during charging based on battery charging 
// equation: delta_capacity =  current * e * t;
//
// Parameters:
//      current
//          [in] current flow inside the battery
//      e
//          [in] charge efficiency for the battery
//      t
//          [in] duration of the charging
//
// Returns:
//      DWORD
//
//------------------------------------------------------------------------------
DWORD CalChargingCapacityChange(DWORD current, DWORD e, DWORD t)
{
    return (DWORD)(current *e/C_BASE* t/C_S_TO_MS);
}


//------------------------------------------------------------------------------
//
// Function: CalDischargingCapacityChange
//
// This function returns the change of the batt capacity during discharging based on peukert's 
// equation: delta_capacity =  (current ^p) * t
//
// Parameters:
//      current
//          [in] current flow inside the battery
//      p
//          [in] peukert number for the battery
//      t
//          [in] duration of the charging
//
// Returns:
//      DWORD
//
//------------------------------------------------------------------------------
DWORD CalDischargingCapacityChange(DWORD current, DWORD p, DWORD t)
{
    return (DWORD)(pow((double)current/C_A_TO_MA, (double)p/C_BASE)*C_A_TO_MA*t/C_S_TO_MS);
}



