71 #define MXM_VOLTAGE_READ_ARRAY_LENGTH (MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE + 3u)
173 #define MXM_DELAY_BALANCING 10000u
176 #define MXM_REF_VAA_mV (3300u)
182 #define MXM_I2C_MUX0_ADDRESS (0x4Cu)
184 #define MXM_I2C_MUX1_ADDRESS (0x4Du)
220 const uint8_t *
const kpkVoltRxBuffer,
221 uint16_t voltRxBufferLength,
222 uint8_t measurementOffset,
224 uint16_t *pVoltagesTarget,
226 uint32_t full_scale_reference_mV);
249 const uint8_t *
const kpkVoltageRxBuffer,
250 uint16_t voltageRxBufferLength,
471 for (uint8_t i_po = 2u; i_po < (msg_len - 2u); i_po = i_po + 2u) {
473 uint8_t calculatedModuleNumberInDaisyChain = numberOfSatellites - ((uint16_t)(i_po / 2u) - 1u) - 1u;
474 uint8_t stringNumber = 0u;
475 uint16_t moduleNumber = 0u;
483 uint8_t mask = 1u << c;
484 if ((uint8_t)(mask & kpkInstance->
rxBuffer[i_po]) > 0u) {
485 pDataOpenWire->
openwire[stringNumber][calculated_module_position + c] = 1;
487 pDataOpenWire->
openwire[stringNumber][calculated_module_position + c] = 0;
491 uint8_t mask = 1u << (c - 8u);
492 if ((uint8_t)(mask & kpkInstance->
rxBuffer[i_po + 1u]) > 0u) {
493 pDataOpenWire->
openwire[stringNumber][calculated_module_position + c] = 1;
495 pDataOpenWire->
openwire[stringNumber][calculated_module_position + c] = 0;
523 uint8_t stringNumber = 0u;
524 uint16_t moduleNumber = 0u;
561 const uint8_t *
const kpkVoltRxBuffer,
562 uint16_t voltRxBufferLength,
563 uint8_t measurementOffset,
565 uint16_t *pVoltagesTarget,
567 uint32_t full_scale_reference_mV) {
568 uint8_t number_of_connected_devices =
569 (voltRxBufferLength - 2u - 2u) /
573 for (uint8_t i = 2u; i < (voltRxBufferLength - 2u); i = i + 2u) {
574 uint8_t calculated_module_number = number_of_connected_devices - ((uint16_t)(i / 2u) - 1u) - 1u;
575 uint16_t calculated_module_position = 0u;
584 calculated_module_position = calculated_module_number;
590 uint16_t calculated_array_position = calculated_module_position + measurementOffset;
611 kpkVoltRxBuffer[i + 1u],
612 &pVoltagesTarget[calculated_array_position],
614 full_scale_reference_mV);
619 const uint8_t *
const kpkVoltageRxBuffer,
620 uint16_t voltageRxBufferLength,
627 uint8_t cell_offset = 0;
631 }
else if ((voltageRxBufferLength % 2u) != 0u) {
646 voltageRxBufferLength,
657 voltageRxBufferLength,
668 voltageRxBufferLength,
679 voltageRxBufferLength,
690 voltageRxBufferLength,
701 voltageRxBufferLength,
712 voltageRxBufferLength,
723 voltageRxBufferLength,
734 voltageRxBufferLength,
745 voltageRxBufferLength,
756 voltageRxBufferLength,
767 voltageRxBufferLength,
778 voltageRxBufferLength,
789 voltageRxBufferLength,
800 voltageRxBufferLength,
811 voltageRxBufferLength,
822 voltageRxBufferLength,
833 voltageRxBufferLength,
854 uint8_t test_buffer[100] = {0};
855 uint16_t testBufferLength = 100;
883 testBufferLength = 5;
892 test_buffer[2] = 0xFCu;
893 test_buffer[3] = 0xFFu;
894 test_buffer[4] = 0x00u;
895 test_buffer[5] = 0x00u;
896 test_buffer[6] = 0xFCu;
897 test_buffer[7] = 0xFFu;
898 test_buffer[8] = 0x42u;
899 test_buffer[9] = 0x44u;
900 testBufferLength = 10u;
920 test_buffer[2] = 0xFCu;
921 test_buffer[3] = 0xFFu;
922 test_buffer[4] = 0x00u;
923 test_buffer[5] = 0x00u;
924 test_buffer[6] = 0xFCu;
925 test_buffer[7] = 0xFFu;
926 test_buffer[8] = 0x42u;
927 test_buffer[9] = 0x44u;
928 testBufferLength = 10;
948 test_buffer[2] = 0xFCu;
949 test_buffer[3] = 0xFFu;
950 test_buffer[4] = 0x42u;
951 test_buffer[5] = 0x44u;
952 testBufferLength = 6;
970 test_buffer[2] = 0xFCu;
971 test_buffer[3] = 0xFFu;
972 test_buffer[4] = 0x42u;
973 test_buffer[5] = 0x44u;
974 testBufferLength = 6;
992 test_buffer[2] = 0xFCu;
993 test_buffer[3] = 0xFFu;
994 test_buffer[4] = 0x42u;
995 test_buffer[5] = 0x44u;
996 testBufferLength = 6;
1014 test_buffer[2] = 0xFCu;
1015 test_buffer[3] = 0xFFu;
1016 test_buffer[4] = 0x42u;
1017 test_buffer[5] = 0x44u;
1018 testBufferLength = 6;
1036 test_buffer[2] = 0xFCu;
1037 test_buffer[3] = 0xFFu;
1038 test_buffer[4] = 0x42u;
1039 test_buffer[5] = 0x44u;
1040 testBufferLength = 6;
1058 test_buffer[2] = 0xFCu;
1059 test_buffer[3] = 0xFFu;
1060 test_buffer[4] = 0x42u;
1061 test_buffer[5] = 0x44u;
1062 testBufferLength = 6;
1080 test_buffer[2] = 0xFCu;
1081 test_buffer[3] = 0xFFu;
1082 test_buffer[4] = 0x42u;
1083 test_buffer[5] = 0x44u;
1084 testBufferLength = 6;
1102 test_buffer[2] = 0xFCu;
1103 test_buffer[3] = 0xFFu;
1104 test_buffer[4] = 0x42u;
1105 test_buffer[5] = 0x44u;
1106 testBufferLength = 6;
1124 test_buffer[2] = 0xFCu;
1125 test_buffer[3] = 0xFFu;
1126 test_buffer[4] = 0x42u;
1127 test_buffer[5] = 0x44u;
1128 testBufferLength = 6;
1146 test_buffer[2] = 0xFCu;
1147 test_buffer[3] = 0xFFu;
1148 test_buffer[4] = 0x42u;
1149 test_buffer[5] = 0x44u;
1150 testBufferLength = 6;
1168 test_buffer[2] = 0xFCu;
1169 test_buffer[3] = 0xFFu;
1170 test_buffer[4] = 0x42u;
1171 test_buffer[5] = 0x44u;
1172 testBufferLength = 6;
1190 test_buffer[2] = 0xFCu;
1191 test_buffer[3] = 0xFFu;
1192 test_buffer[4] = 0x42u;
1193 test_buffer[5] = 0x44u;
1194 testBufferLength = 6;
1250 uint8_t stringNumber = 0u;
1251 uint16_t moduleNumber = 0u;
1256 if (moduleNumber == 0u) {
1276 uint8_t stringNumber = 0u;
1277 uint16_t moduleNumber = 0u;
1492 if (
STD_OK == database_retval) {
1527 if (mxm_moduleBalancingIndex < pState->highest5xDevice) {
1943 switch (pInstance->
state) {
2028 #ifdef UNITY_UNIT_TEST
2040 extern void TEST_MXM_HandleStateWriteall(
2045 extern bool TEST_MXM_HandleStateReadall(
2052 uint8_t *volt_rx_buffer,
2053 uint16_t volt_rx_buffer_len,
#define BS_NR_OF_CELLS_PER_MODULE
number of battery cells per battery module (parallel cells are counted as one)
#define BS_NR_OF_MODULES
number of modules in battery pack
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
#define DATA_READ_DATA(...)
#define DATA_WRITE_DATA(...)
@ DATA_BLOCK_ID_BALANCING_CONTROL
@ DATA_BLOCK_ID_CELL_TEMPERATURE_BASE
@ DATA_BLOCK_ID_OPEN_WIRE_BASE
@ DATA_BLOCK_ID_CELL_VOLTAGE_BASE
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
#define NULL_PTR
Null pointer.
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
#define must_check_return
Allows functions to generate warnings in GCC for unused returns.
#define MXM_I2C_MUX0_ADDRESS
address of MUX0
#define MXM_I2C_MUX1_ADDRESS
address of MUX1
static STD_RETURN_TYPE_e MXM_ParseVoltagesIntoDB(const MXM_MONITORING_INSTANCE_s *const kpkInstance)
Copies measured voltage data into the database.
static uint8_t mxm_evenCellsNeedBalancing
Even cells group needs to be balanced.
static STD_RETURN_TYPE_e MXM_ParseVoltageReadall(const uint8_t *const kpkVoltageRxBuffer, uint16_t voltageRxBufferLength, MXM_DATA_STORAGE_s *datastorage, MXM_CONVERSION_TYPE_e conversionType)
Parse a RX buffer containing voltage values.
static uint8_t mxm_oddCellsNeedBalancing
Odd cells group needs to be balanced.
static DATA_BLOCK_CELL_TEMPERATURE_s mxm_cellTemperatures
Local cell temperature data block.
static DATA_BLOCK_BALANCING_CONTROL_s mxm_balancingControl
Balancing control.
#define MXM_DELAY_BALANCING
Delay in milliseconds before the balancing status is updated.
static bool must_check_return MXM_HandleStateReadall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_REG_NAME_e registerName, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Handle the statemachine-transactions for a READALL.
static uint8_t mxm_oddCellsBalancingProcessed
Odd cells group balancing done.
static uint8_t mxm_evenCellsBalancingProcessed
Even cells group balancing done.
static uint8_t mxm_moduleBalancingIndex
Module index in the daisy chain.
static void MXM_StateMachineOperation(MXM_MONITORING_INSTANCE_s *pState)
State-Machine implementation for operation state.
static uint32_t mxm_currentTime
Timers used to guarantee that balancing is performed periodically.
static DATA_BLOCK_OPEN_WIRE_s mxm_openwire
Local data structure for openwire results.
static void MXM_HandleStateWriteall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Handle the statemachine-transactions for a WRITEALL.
static void MXM_GetDataFrom5XStateMachine(MXM_MONITORING_INSTANCE_s *pInstance)
Retrieves data from lower statemachine and writes it to the rx buffer.
static STD_RETURN_TYPE_e MXM_ConstructBalancingBuffer(void)
Fill the balancing datastructure.
uint16_t mxm_cellsToBalance
Mask to control balacing.
static const MXM_REG_NAME_e mxm_voltageCellAddresses[MXM_VOLTAGE_READ_ARRAY_LENGTH]
Mapping of voltage registers.
static uint32_t mxm_previousTime
Timers used to guarantee that balancing is performed periodically.
void MXM_StateMachine(MXM_MONITORING_INSTANCE_s *pInstance)
Battery monitoring driver for MAX1785x battery monitoring ICs.
#define MXM_REF_VAA_mV
VAA reference voltage (3.3V)
#define MXM_VOLTAGE_READ_ARRAY_LENGTH
static STD_RETURN_TYPE_e must_check_return MXM_ParseVoltageReadallTest(MXM_MONITORING_INSTANCE_s *pInstance)
Test the MXM_ParseVoltageReadall()-function.
static void MXM_ProcessOpenWire(const MXM_MONITORING_INSTANCE_s *const kpkInstance, DATA_BLOCK_OPEN_WIRE_s *pDataOpenWire)
Processes the retrieved information on openwire.
static MXM_MONINTORING_STATE_e must_check_return MXM_MonGetVoltages(MXM_MONITORING_INSTANCE_s *pState, MXM_REG_NAME_e regAddress)
Encapsulation for reading voltages from a register.
static DATA_BLOCK_CELL_VOLTAGE_s mxm_cellVoltages
Local cell voltage data block.
static STD_RETURN_TYPE_e must_check_return MXM_PreInitSelfCheck(MXM_MONITORING_INSTANCE_s *pState)
Execute all preinit selfchecks.
static void MXM_ParseVoltageLineReadall(const uint8_t *const kpkVoltRxBuffer, uint16_t voltRxBufferLength, uint8_t measurementOffset, MXM_CONVERSION_TYPE_e conversionType, uint16_t *pVoltagesTarget, MXM_MEASURE_TYPE_e meas_type, uint32_t full_scale_reference_mV)
Parse voltage values from a READALL receive buffer into an array.
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.
#define MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE
Maximum number of cells per module.
#define MXM_MAXIMUM_NR_OF_AUX_PER_MODULE
Maximum number of AUX ports per module.
@ MXM_CONVERSION_UNIPOLAR
@ MXM_CONVERSION_BLOCK_VOLTAGE
enum MXM_MEASURE_TYPE MXM_MEASURE_TYPE_e
enum MXM_CONVERSION_TYPE MXM_CONVERSION_TYPE_e
#define MXM_MAXIMUM_NR_OF_MODULES
Maximum number of modules.
@ MXM_MEASURE_CELL_VOLTAGE
@ MXM_MEASURE_BLOCK_VOLTAGE
STD_RETURN_TYPE_e must_check_return MXM_5XUserAccessibleAddressSpaceCheckerSelfCheck(void)
runs a selfcheck for the address space check
STD_RETURN_TYPE_e MXM_5XGetRXBuffer(const MXM_5X_INSTANCE_s *const kpkInstance, uint8_t *rxBuffer, uint16_t rxBufferLength)
Copy RX buffer into variable.
STD_RETURN_TYPE_e MXM_5XSetStateRequest(MXM_5X_INSTANCE_s *pInstance5x, MXM_STATEMACHINE_5X_e state, MXM_5X_COMMAND_PAYLOAD_s commandPayload, MXM_5X_STATE_REQUEST_STATUS_e *processed)
Set state request for the Battery Management Statemachine.
STD_RETURN_TYPE_e MXM_5XGetNumberOfSatellitesGood(const MXM_5X_INSTANCE_s *const kpkInstance)
Get the value of MXM_5X_INSTANCE::numberOfSatellitesIsGood.
MXM_DC_BYTE_e MXM_5XGetLastDCByte(const MXM_5X_INSTANCE_s *const kpkInstance)
Returns the last received DC byte.
uint8_t MXM_5XGetNumberOfSatellites(const MXM_5X_INSTANCE_s *const kpkInstance)
Get number of satellites.
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.
@ MXM_STATEMACH_5X_READALL
@ MXM_STATEMACH_5X_WRITEALL
@ MXM_STATEMACH_5X_WRITE_DEVICE
@ MXM_STATEMACH_5X_41B_FMEA_CHECK
@ MXM_5X_STATE_UNPROCESSED
#define BATTERY_MANAGEMENT_HELLOALL
HELLOALL message.
#define BATTERY_MANAGEMENT_READALL
READALL message (read single register of all daisy-chain devices)
#define BATTERY_MANAGEMENT_TX_LENGTH_READALL
Battery Management Protocol lengths of TX buffer.
STD_RETURN_TYPE_e must_check_return MXM_CRC8SelfTest(void)
Test the CRC8-algorithm with a known pattern.
enum MXM_REG_NAME MXM_REG_NAME_e
MAX1785x register names.
void MXM_MonRegistryParseIdIntoDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t rxBufferLength, MXM_REG_NAME_e type)
Parse ID (1 or 2) into the registry.
void MXM_MonRegistryInit(MXM_MONITORING_INSTANCE_s *pState)
Initialize monitoring registry.
STD_RETURN_TYPE_e MXM_MonRegistryConnectDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t numberOfDevices)
Mark devices as connected in the registry and set the address.
void MXM_MonRegistryParseVersionIntoDevices(MXM_MONITORING_INSTANCE_s *pState, uint8_t rxBufferLength)
Parse Version into the registry.
Functions in order to have a registry of monitoring ICs.
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Implementation of the tasks used by the system, headers.
uint8_t balancingState[BS_NR_OF_STRINGS][BS_NR_OF_BAT_CELLS]
DATA_BLOCK_HEADER_s header
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
DATA_BLOCK_HEADER_s header
uint32_t moduleVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_MODULES]
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_BAT_CELLS]
DATA_BLOCK_HEADER_s header
int32_t packVoltage_mV[BS_NR_OF_STRINGS]
DATA_BLOCK_HEADER_s header
uint8_t openwire[BS_NR_OF_STRINGS][BS_NR_OF_MODULES *(BS_NR_OF_CELLS_PER_MODULE+1)]
MXM_REG_NAME_e regAddress
uint16_t blockVoltages[MXM_MAXIMUM_NR_OF_MODULES]
uint16_t cellVoltages_mV[MXM_MAXIMUM_NR_OF_MODULES *MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE]
uint16_t auxVoltages_mV[MXM_MAXIMUM_NR_OF_MODULES *MXM_MAXIMUM_NR_OF_AUX_PER_MODULE]
uint8_t rxBuffer[MXM_RX_BUFFER_LENGTH]
STD_RETURN_TYPE_e resultSelfCheck
uint8_t mxmVoltageCellCounter
MXM_STATEMACHINE_OPERATION_STATES_e operationSubstate
MXM_SELFCHECK_s selfCheck
MXM_DATA_STORAGE_s localVoltages
Local storage for cell-voltages.
MXM_5X_COMMAND_PAYLOAD_s batteryCmdBuffer
MXM_5X_INSTANCE_s * pInstance5X
MXM_STATEMACHINE_STATES_e state
bool firstMeasurementDone
MXM_5X_STATE_REQUEST_STATUS_e requestStatus5x
STD_RETURN_TYPE_e parseVoltageReadall
STD_RETURN_TYPE_e extractValueFromRegister
STD_RETURN_TYPE_e fmeaStatusASCI
STD_RETURN_TYPE_e firstSetBit
STD_RETURN_TYPE_e addressSpaceChecker
Temperature Sensor Interface on Slave Unit driver header.
int16_t TSI_GetTemperature(uint16_t adcVoltage_mV)
translate a voltage to a temperature