Index: firmware/App/Drivers/Battery.c =================================================================== diff -u -r72350346b44261f2a9bbd23220ea11978f635039 -r7690b677a3870da643e67bd622d3b342dfac0040 --- firmware/App/Drivers/Battery.c (.../Battery.c) (revision 72350346b44261f2a9bbd23220ea11978f635039) +++ firmware/App/Drivers/Battery.c (.../Battery.c) (revision 7690b677a3870da643e67bd622d3b342dfac0040) @@ -36,6 +36,8 @@ #define BATTERY_PACK_REL_STATE_OF_CHARGE_CMD 0x0D ///< Command to get battery pack relative state of charge. #define BATTERY_PACK_STATUS_CMD 0x16 ///< Command to get battery pack status. +#define BATTERY_PACK_MIN_CHARGE_PCT 50 ///< Minimum battery pack state of charge in percentage. + #define BATTERY_COMM_TIME_OUT_MS 1 ///< Battery communication time out in ms. #define BATTERY_MONITOR_INTERVAL_MS 750 ///< Battery monitor interval in ms. #define AC_POWER_LOST_PERSISTENT_COUNT 3 ///< AC power lost persistent count before alarming. @@ -50,6 +52,8 @@ static U32 lostACPowerPersistentCount = 0; ///< Persistent count for AC power lost alarm. static BOOL hasBatteryChargerStatus = FALSE; ///< Flag indicates if battery charger status has been obtained. static U32 commFaultPersistentCount = 0; ///< Persistence count for battery comm fault. + +static SELF_TEST_STATUS_T batteryTestStatus; ///< Current battery SOC test status. // ********** private function prototypes ********** @@ -78,6 +82,7 @@ lostACPowerPersistentCount = 0; hasBatteryChargerStatus = FALSE; commFaultPersistentCount = 0; + batteryTestStatus = SELF_TEST_STATUS_IN_PROGRESS; setupI2CDriver(); } @@ -120,8 +125,6 @@ { hasBatteryChargerStatus = FALSE; - getBatteryData( BATTERY_PACK_SLAVE_ADDRESS, BATTERY_PACK_REL_STATE_OF_CHARGE_CMD, &batteryRelStateOfCharge_pct ); - if ( TRUE == getBatteryData( BATTERY_PACK_SLAVE_ADDRESS, BATTERY_PACK_STATUS_CMD, &batteryPackStatus ) ) { if ( 0 != batteryPackStatus ) @@ -135,6 +138,31 @@ /*********************************************************************//** * @brief + * The execBatteryTest function executes the battery SOC check. + * @details Inputs: battery state of charge + * @details Outputs: alerts when battery pack charge is low + * @return battery SOC test status + *************************************************************************/ +SELF_TEST_STATUS_T execBatteryTest( void ) +{ + if ( TRUE == getBatteryData( BATTERY_PACK_SLAVE_ADDRESS, BATTERY_PACK_REL_STATE_OF_CHARGE_CMD, &batteryRelStateOfCharge_pct ) ) + { + if ( batteryRelStateOfCharge_pct < BATTERY_PACK_MIN_CHARGE_PCT ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_BATTERY_PACK_CHARGE_TOO_LOW, batteryRelStateOfCharge_pct ); + } + else + { + clearAlarmCondition( ALARM_ID_HD_BATTERY_PACK_CHARGE_TOO_LOW ); + batteryTestStatus = SELF_TEST_STATUS_PASSED; + } + } + + return batteryTestStatus; +} + +/*********************************************************************//** + * @brief * The getBatteryRemainingPercent function returns the latest battery relative * state of charge percentage. * @details Inputs: none