Index: firmware/App/Drivers/BatteryDriver.c =================================================================== diff -u -r76687feec84ff53de5eed426b26290bd08de963c -r0b606b5cbf2df52ea9845544155eae947ca4b8ee --- firmware/App/Drivers/BatteryDriver.c (.../BatteryDriver.c) (revision 76687feec84ff53de5eed426b26290bd08de963c) +++ firmware/App/Drivers/BatteryDriver.c (.../BatteryDriver.c) (revision 0b606b5cbf2df52ea9845544155eae947ca4b8ee) @@ -14,24 +14,28 @@ * @date (original) 11-May-2026 * ***************************************************************************/ -#include -#include // For memcpy +#include // For memcpy +#include "BatteryDriver.h" #include "i2c.h" +#include "Messaging.h" #include "Timers.h" /** - * @addtogroup Battery + * @addtogroup BatteryDriver * @{ */ // ********** private definitions ********** #define BATTERY_COMM_TIME_OUT_MS 2 ///< Battery communication time out in ms. +#define BATTERY_CHARGER_SLAVE_ADDRESS 0x6B ///< Battery charger controller device address. +#define BATTERY_PACK_SLAVE_ADDRESS 0x0B ///< Battery pack device address. // ********** private data ********** -static OVERRIDE_U32_T batteryI2CStatusRegister = { 0, 0, 0, 0 }; ///< Battery I2C Interrupt Status register +static OVERRIDE_U32_T batteryI2CStatusRegister; ///< Battery I2C Interrupt Status register + // ********** private function prototypes ********** static void setupI2CDriver( void ); @@ -45,22 +49,28 @@ /*********************************************************************//** * @brief - * The initsetupI2CDriver function initializes the I2C driver. - * @details Inputs: none - * @details Outputs: I2C driver initialized. + * The initsetupI2CDriver function initializes the I2C driver for battery + * communication. + * @details \b Inputs: none + * @details \b Outputs: I2C driver initialized. * @return none *************************************************************************/ void initsetupI2CDriver(void) { +// batteryI2CStatusRegister.data = 0; +// batteryI2CStatusRegister.ovData = 0; +// batteryI2CStatusRegister.ovInitData = 0; +// batteryI2CStatusRegister.override = 0; + memset(&batteryI2CStatusRegister, 0, sizeof(OVERRIDE_U32_T)); setupI2CDriver(); } /*********************************************************************//** * @brief - * The setupI2CDriver function setups i2c driver in repeat mode to be + * The setupI2CDriver function sets up the I2C driver in repeat mode to be * compatible with SMBus protocol. - * @details Inputs: none - * @details Outputs: setup i2c driver in repeat mode + * @details \b Inputs: none + * @details \b Outputs: I2C driver configured in repeat mode. * @return none *************************************************************************/ static void setupI2CDriver( void ) @@ -72,11 +82,11 @@ /*********************************************************************//** * @brief - * The waitForTxReady function checks for transmit ready status from i2c - * driver with a timeout. - * @details Inputs: none - * @details Outputs: checked i2c transmit ready status - * @return TRUE if i2c driver ready to transmit data, otherwise FALSE + * The waitForTxReady function checks for transmit ready status from the + * I2C driver with a timeout. + * @details \b Inputs: none + * @details \b Outputs: none + * @return TRUE if I2C driver is ready to transmit, otherwise FALSE *************************************************************************/ static BOOL waitForTxReady( void ) { @@ -93,11 +103,11 @@ /*********************************************************************//** * @brief - * The waitForRxReady function checks for receive ready status from i2c - * driver with a timeout. - * @details Inputs: none - * @details Outputs: checked i2c receive ready status - * @return TRUE if i2c driver ready to receive data, otherwise FALSE + * The waitForRxReady function checks for receive ready status from the + * I2C driver with a timeout. + * @details \b Inputs: none + * @details \b Outputs: none + * @return TRUE if I2C driver is ready to receive, otherwise FALSE *************************************************************************/ static BOOL waitForRxReady( void ) { @@ -114,10 +124,11 @@ /*********************************************************************//** * @brief - * The waitForAccessReady function checks if i2c registers are ready to be accessed. - * @details Inputs: none - * @details Outputs: checked i2c registers access ready status - * @return TRUE if i2c driver registers are ready to be accessed, otherwise FALSE + * The waitForAccessReady function checks if I2C registers are ready + * to be accessed. + * @details \b Inputs: none + * @details \b Outputs: none + * @return TRUE if I2C driver registers are ready to be accessed, otherwise FALSE *************************************************************************/ static BOOL waitForAccessReady( void ) { @@ -134,10 +145,10 @@ /*********************************************************************//** * @brief - * The generateStopCondition function generates a i2c stop condition and + * The generateStopCondition function generates an I2C stop condition and * waits until the stop condition is detected or timed out. - * @details Inputs: none - * @details Outputs: generated i2c stop condition + * @details \b Inputs: none + * @details \b Outputs: I2C stop condition generated. * @return none *************************************************************************/ static void generateStopCondition( void ) @@ -166,7 +177,14 @@ BOOL getBatteryData( U32 slaveAddr, U08 command, U32 * dataPtr ) { BOOL result = FALSE; - + if (slaveAddr) + { + slaveAddr = BATTERY_PACK_SLAVE_ADDRESS; + } + else + { + slaveAddr = BATTERY_CHARGER_SLAVE_ADDRESS; + } if ( TRUE == startCommTx( slaveAddr ) ) { U16 data = (U16)( (*dataPtr) & MASK_OFF_MSW ); @@ -183,11 +201,14 @@ /*********************************************************************//** * @brief - * The startCommTx function starts i2c communication and verifies slave devices ack. - * @details Inputs: i2cREG1 - * @details Outputs: starts i2c comm in master transmit mode - * @param slaveAddr slave device address - * @return TRUE if start communication successful, otherwise FALSE + * The startCommTx function starts I2C communication and verifies the + * slave device acknowledges. + * @details \b Alarm: ALARM_ID_TD_BATTERY_COMM_FAULT if too many + * communication faults detected. + * @details \b Inputs: i2cREG1 + * @details \b Outputs: I2C communication started in master transmit mode. + * @param slaveAddr slave device address to communicate with. + * @return TRUE if communication started successfully, otherwise FALSE *************************************************************************/ static BOOL startCommTx( U32 slaveAddr ) { @@ -226,12 +247,15 @@ /*********************************************************************//** * @brief - * The getData function send command to battery interface to get data. - * @details Inputs: none - * @details Outputs: get the battery data based on given command - * @param command command to send to the slave device - * @param dataPtr data pointer to store command response data - * @return TRUE if received battery data, otherwise FALSE + * The getData function sends a command to the battery device and retrieves + * the response data. + * @details \b Alarm: ALARM_ID_TD_BATTERY_COMM_FAULT if too many + * communication faults detected. + * @details \b Inputs: none + * @details \b Outputs: battery data retrieved from device. + * @param command command to send to the device. + * @param dataPtr pointer to store the command response data. + * @return TRUE if data received successfully, otherwise FALSE *************************************************************************/ static BOOL getData( U08 command, U16 * dataPtr ) { @@ -273,11 +297,12 @@ /*********************************************************************//** * @brief - * The getI2CStatusRegister function returns the I2C status register - * @details Inputs: batteryI2CStatusRegister, i2cREG1->STR - * @details Outputs: none - * @param reset override on get - * @return I2C Interrupt Status. + * The getI2CStatusRegister function returns the current I2C status + * register value. + * @details \b Inputs: batteryI2CStatusRegister, i2cREG1->STR + * @details \b Outputs: none + * @param resetOverride flag to reset the override after reading. + * @return current I2C interrupt status register value. *************************************************************************/ U32 getI2CStatusRegister( BOOL resetOverride ) { @@ -297,11 +322,12 @@ /*********************************************************************//** * @brief - * The checkTooManyI2CCommFaults function checks for too many comm faults - * within a set period of time. Assumed function is being called when a new - * comm fault is detected so a new comm fault will be added to the list. - * @details Inputs: none - * @details Outputs: alarm 98 on trigger. + * The checkTooManyI2CCommFaults function checks for too many I2C + * communication faults within a set period of time. + * @details \b Alarm: ALARM_ID_TD_BATTERY_COMM_FAULT if too many + * communication faults are detected within the time window. + * @details \b Inputs: none + * @details \b Outputs: none * @return none *************************************************************************/ static void checkTooManyI2CCommFaults( void ) @@ -312,5 +338,20 @@ } } -/**@}*/ +/*********************************************************************//** + * @brief + * The testBatteryI2CStatusOverride function overrides the battery I2C + * status register value. + * @details \b Inputs: none + * @details \b Outputs: batteryI2CStatusRegister + * @param message override message from Diamond which includes the + * I2C status register value to override to. + * @return TRUE if override request is successful, FALSE if not + *************************************************************************/ +BOOL testBatteryI2CStatusOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, (OVERRIDE_F32_T*)&batteryI2CStatusRegister ); + return result; +} +/**@}*/