70 #define MXM_OFFSET_CELL_1 (0u)
71 #define MXM_OFFSET_CELL_2 (1u)
72 #define MXM_OFFSET_CELL_3 (2u)
73 #define MXM_OFFSET_CELL_4 (3u)
74 #define MXM_OFFSET_CELL_5 (4u)
75 #define MXM_OFFSET_CELL_6 (5u)
76 #define MXM_OFFSET_CELL_7 (6u)
77 #define MXM_OFFSET_CELL_8 (7u)
78 #define MXM_OFFSET_CELL_9 (8u)
79 #define MXM_OFFSET_CELL_10 (9u)
80 #define MXM_OFFSET_CELL_11 (10u)
81 #define MXM_OFFSET_CELL_12 (11u)
82 #define MXM_OFFSET_CELL_13 (12u)
83 #define MXM_OFFSET_CELL_14 (13u)
84 #define MXM_OFFSET_AUX0 (0u)
85 #define MXM_OFFSET_AUX2 (2u)
86 #define MXM_OFFSET_AUX3 (3u)
87 #define MXM_OFFSET_BLOCK (0u)
90 #define MXM_MAXIMUM_ERROR_COUNT (10u)
93 #define MXM_TIMEOUT_RESET_ERROR_COUNTER_ms (500)
96 #define MXM_TEST_BUFFER_MAXIMUM_LENGTH (120u)
101 .minimumPlausibleVoltage_mV = -2500,
106 #define MXM_REF_VAA_mV (3300u)
141 const uint8_t *
const kpkVoltRxBuffer,
142 uint16_t voltRxBufferLength,
143 uint8_t measurementOffset,
145 uint16_t *pVoltagesTarget,
147 uint32_t fullScaleReference_mV);
170 const uint8_t *
const kpkVoltageRxBuffer,
171 uint16_t voltageRxBufferLength,
221 const uint8_t *
const kpkVoltRxBuffer,
222 uint16_t voltRxBufferLength,
223 uint8_t measurementOffset,
225 uint16_t *pVoltagesTarget,
227 uint32_t fullScaleReference_mV) {
234 FAS_ASSERT(((voltRxBufferLength - 2u - 2u) / 2u) <= (uint16_t)UINT8_MAX);
236 const uint8_t numberOfConnectedDevices = (uint8_t)(((voltRxBufferLength - 2u - 2u) / 2u) & (uint8_t)UINT8_MAX);
239 for (uint8_t i = 2u; i < (voltRxBufferLength - 2u); i = i + 2u) {
240 const uint8_t calculatedModuleNumber = numberOfConnectedDevices - ((i / 2u) - 1u) - 1u;
241 uint16_t calculatedModulePosition = 0u;
242 switch (measurementType) {
250 calculatedModulePosition = calculatedModuleNumber;
256 FAS_ASSERT((calculatedModulePosition + measurementOffset) <= (uint16_t)UINT16_MAX);
257 uint16_t calculatedArrayPosition = calculatedModulePosition + measurementOffset;
260 switch (measurementType) {
276 FAS_ASSERT((i + (uint16_t)1u) <= voltRxBufferLength);
279 kpkVoltRxBuffer[i + 1u],
280 &pVoltagesTarget[calculatedArrayPosition],
282 fullScaleReference_mV);
287 const uint8_t *
const kpkVoltageRxBuffer,
288 uint16_t voltageRxBufferLength,
298 }
else if ((voltageRxBufferLength % 2u) != 0u) {
308 switch (kpkVoltageRxBuffer[1]) {
312 voltageRxBufferLength,
322 voltageRxBufferLength,
332 voltageRxBufferLength,
342 voltageRxBufferLength,
352 voltageRxBufferLength,
362 voltageRxBufferLength,
372 voltageRxBufferLength,
382 voltageRxBufferLength,
392 voltageRxBufferLength,
402 voltageRxBufferLength,
412 voltageRxBufferLength,
422 voltageRxBufferLength,
432 voltageRxBufferLength,
442 voltageRxBufferLength,
452 voltageRxBufferLength,
462 voltageRxBufferLength,
472 voltageRxBufferLength,
482 voltageRxBufferLength,
542 testBufferLength = 5;
552 testBuffer[2] = 0xFCu;
553 testBuffer[3] = 0xFFu;
554 testBuffer[4] = 0x00u;
555 testBuffer[5] = 0x00u;
556 testBuffer[6] = 0xFCu;
557 testBuffer[7] = 0xFFu;
558 testBuffer[8] = 0x42u;
559 testBuffer[9] = 0x44u;
560 testBufferLength = 10u;
582 testBuffer[2] = 0xFCu;
583 testBuffer[3] = 0xFFu;
584 testBuffer[4] = 0x00u;
585 testBuffer[5] = 0x00u;
586 testBuffer[6] = 0xFCu;
587 testBuffer[7] = 0xFFu;
588 testBuffer[8] = 0x42u;
589 testBuffer[9] = 0x44u;
590 testBufferLength = 10;
612 testBuffer[2] = 0xFCu;
613 testBuffer[3] = 0xFFu;
614 testBuffer[4] = 0x42u;
615 testBuffer[5] = 0x44u;
616 testBufferLength = 6;
636 testBuffer[2] = 0xFCu;
637 testBuffer[3] = 0xFFu;
638 testBuffer[4] = 0x42u;
639 testBuffer[5] = 0x44u;
640 testBufferLength = 6;
660 testBuffer[2] = 0xFCu;
661 testBuffer[3] = 0xFFu;
662 testBuffer[4] = 0x42u;
663 testBuffer[5] = 0x44u;
664 testBufferLength = 6;
684 testBuffer[2] = 0xFCu;
685 testBuffer[3] = 0xFFu;
686 testBuffer[4] = 0x42u;
687 testBuffer[5] = 0x44u;
688 testBufferLength = 6;
708 testBuffer[2] = 0xFCu;
709 testBuffer[3] = 0xFFu;
710 testBuffer[4] = 0x42u;
711 testBuffer[5] = 0x44u;
712 testBufferLength = 6;
732 testBuffer[2] = 0xFCu;
733 testBuffer[3] = 0xFFu;
734 testBuffer[4] = 0x42u;
735 testBuffer[5] = 0x44u;
736 testBufferLength = 6;
756 testBuffer[2] = 0xFCu;
757 testBuffer[3] = 0xFFu;
758 testBuffer[4] = 0x42u;
759 testBuffer[5] = 0x44u;
760 testBufferLength = 6;
780 testBuffer[2] = 0xFCu;
781 testBuffer[3] = 0xFFu;
782 testBuffer[4] = 0x42u;
783 testBuffer[5] = 0x44u;
784 testBufferLength = 6;
804 testBuffer[2] = 0xFCu;
805 testBuffer[3] = 0xFFu;
806 testBuffer[4] = 0x42u;
807 testBuffer[5] = 0x44u;
808 testBufferLength = 6;
828 testBuffer[2] = 0xFCu;
829 testBuffer[3] = 0xFFu;
830 testBuffer[4] = 0x42u;
831 testBuffer[5] = 0x44u;
832 testBufferLength = 6;
852 testBuffer[2] = 0xFCu;
853 testBuffer[3] = 0xFFu;
854 testBuffer[4] = 0x42u;
855 testBuffer[5] = 0x44u;
856 testBufferLength = 6;
876 testBuffer[2] = 0xFCu;
877 testBuffer[3] = 0xFFu;
878 testBuffer[4] = 0x42u;
879 testBuffer[5] = 0x44u;
880 testBufferLength = 6;
927 const bool counterCanBeReset =
929 if (counterCanBeReset ==
true) {
1013 "please check assumptions: code cannot handle number of modules");
1016 for (uint8_t i = 2u; i < (messageLength - 2u); i = i + 2u) {
1018 const uint8_t calculatedModuleNumberInDaisyChain = numberOfSatellites - ((i / 2u) - 1u) - 1u;
1019 uint8_t stringNumber = 0u;
1020 uint16_t moduleNumber = 0u;
1028 const uint8_t mask = 1u << c;
1029 if ((uint8_t)(mask & kpkInstance->
rxBuffer[i]) > 0u) {
1037 if ((uint8_t)(mask & kpkInstance->
rxBuffer[i + 1u]) > 0u) {
1071 uint8_t stringNumber = 0u;
1072 uint16_t moduleNumber = 0u;
1119 uint8_t stringNumber = 0u;
1120 uint16_t moduleNumber = 0u;
1127 if (moduleNumber == 0u) {
1137 if ((int32_t)cellVoltageLocal_mV > INT16_MAX) {
1141 (int16_t)cellVoltageLocal_mV;
1146 if ((valueIsPlausible ==
STD_OK) && moduleIsConnected) {
1147 numberValidVoltageMeasurements[stringNumber]++;
1151 ((uint64_t)1u << i_bat);
1160 uint8_t stringNumber = 0u;
1161 uint16_t moduleNumber = 0u;
1177 if ((valueIsPlausible ==
STD_OK) && moduleIsConnected) {
1178 numberValidTemperatureMeasurements[stringNumber]++;
1270 pMonitoringInstance->
rxBuffer[i] = 0u;
1323 switch (pInstance->
state) {
1385 (resultNumberOfSatellitesGood ==
STD_OK)) {
1420 #ifdef UNITY_UNIT_TEST
1428 uint8_t *voltRxBuffer,
1429 uint16_t voltRxBufferLength,
STD_RETURN_TYPE_e AFE_PlausibilityCheckTempMinMax(const int16_t celltemperature_ddegC)
Cell temperature plausibility check.
STD_RETURN_TYPE_e AFE_PlausibilityCheckVoltageMeasurementRange(const int16_t cellvoltage_mV, const AFE_PLAUSIBILITY_VALUES_s plausibleValues)
Cell voltage measurement range plausibility check.
plausibility checks for cell voltage and cell temperatures
#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_WRITE_DATA(...)
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
#define static_assert(cond, msg)
static assertion macro
#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.
void MXM_CheckIfErrorCounterCanBeReset(MXM_MONITORING_INSTANCE_s *pInstance)
Function that checks if the error counter can be reset.
#define MXM_TEST_BUFFER_MAXIMUM_LENGTH
#define MXM_OFFSET_CELL_13
void MXM_ErrorHandlerReset(MXM_MONITORING_INSTANCE_s *pInstance, bool immediateReset)
This error handler is used as a last resort and tries a reset of the complete driver.
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 const AFE_PLAUSIBILITY_VALUES_s mxm_plausibleCellVoltages
#define MXM_OFFSET_CELL_11
#define MXM_OFFSET_CELL_6
STD_RETURN_TYPE_e MXM_ProcessOpenWire(const MXM_MONITORING_INSTANCE_s *const kpkInstance)
Processes the retrieved information on openwire.
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.
#define MXM_OFFSET_CELL_1
#define MXM_OFFSET_CELL_7
#define MXM_OFFSET_CELL_10
STD_RETURN_TYPE_e TEST_MXM_ParseVoltagesIntoDB(MXM_MONITORING_INSTANCE_s *pInstance)
STD_RETURN_TYPE_e MXM_ParseVoltagesIntoDB(const MXM_MONITORING_INSTANCE_s *const kpkInstance)
Copies measured voltage data into the database.
#define MXM_OFFSET_CELL_14
#define MXM_OFFSET_CELL_8
#define MXM_OFFSET_CELL_5
#define MXM_OFFSET_CELL_4
static void MXM_GetDataFrom5XStateMachine(MXM_MONITORING_INSTANCE_s *pInstance)
Retrieves data from lower statemachine and writes it to the rx buffer.
STD_RETURN_TYPE_e MXM_ConstructBalancingBuffer(MXM_BALANCING_STATE_s *pBalancingInstance)
Fill the balancing datastructure.
MXM_MONITORING_STATE_e must_check_return MXM_MonGetVoltages(MXM_MONITORING_INSTANCE_s *pState, MXM_REG_NAME_e regAddress)
Encapsulation for reading voltages from a register.
#define MXM_OFFSET_CELL_9
#define MXM_OFFSET_CELL_2
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 measurementType, uint32_t fullScaleReference_mV)
Parse voltage values from a READALL receive buffer into an array.
void MXM_StateMachine(MXM_MONITORING_INSTANCE_s *pInstance)
Main state-machine implementation.
#define MXM_MAXIMUM_ERROR_COUNT
#define MXM_REF_VAA_mV
VAA reference voltage (3.3V)
void MXM_InitializeStateStruct(MXM_BALANCING_STATE_s *pBalancingInstance, MXM_MONITORING_INSTANCE_s *pMonitoringInstance)
Initializes the state structs with default values.
#define MXM_TIMEOUT_RESET_ERROR_COUNTER_ms
static STD_RETURN_TYPE_e must_check_return MXM_ParseVoltageReadallTest(MXM_MONITORING_INSTANCE_s *pInstance)
Test the MXM_ParseVoltageReadall()-function.
STD_RETURN_TYPE_e TEST_MXM_ParseVoltageReadallTest(MXM_MONITORING_INSTANCE_s *pInstance)
void MXM_HandleStateWriteall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Handle the statemachine-transactions for a WRITEALL.
static STD_RETURN_TYPE_e must_check_return MXM_PreInitSelfCheck(MXM_MONITORING_INSTANCE_s *pState)
Execute all preinit selfchecks.
#define MXM_OFFSET_CELL_3
STD_RETURN_TYPE_e TEST_MXM_ParseVoltageReadall(uint8_t *voltRxBuffer, uint16_t voltRxBufferLength, MXM_DATA_STORAGE_s *datastorage, MXM_CONVERSION_TYPE_e conversionType)
#define MXM_OFFSET_CELL_12
Headers for the driver for the MAX17841B ASCI and MAX1785x monitoring chip.
#define MXM_REF_UNIPOLAR_CELL_mV
MXM_MODEL_ID_e MXM_GetModelIdOfDaisyChain(void)
returns the model ID of the daisy chain
void MXM_StateMachineOperation(MXM_MONITORING_INSTANCE_s *pState)
State-Machine implementation for operation state.
#define MXM_THRESHOLD_DIAGNOSTIC_AFTER_CYCLES
Battery monitoring driver for MAX1785x battery monitoring ICs.
#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_MEASURE_CELL_VOLTAGE
@ MXM_MEASURE_BLOCK_VOLTAGE
@ MXM_CONVERSION_UNIPOLAR
@ MXM_CONVERSION_BLOCK_VOLTAGE
@ MXM_siliconVersion_invalid
#define MXM_MAXIMUM_NR_OF_MODULES
Maximum number of modules.
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_s::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_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.
const bool mxm_allowSkippingPostInitSelfCheck
STD_RETURN_TYPE_e must_check_return MXM_CRC8SelfTest(void)
Test the CRC8-algorithm with a known pattern.
MXM_REG_NAME_e
MAX1785x register names.
bool MXM_CheckIfADeviceIsConnected(const MXM_MONITORING_INSTANCE_s *const kpkState, uint8_t device)
check if a device is connected
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.
Functions in order to have a registry of monitoring ICs.
bool OS_CheckTimeHasPassed(uint32_t oldTimeStamp_ms, uint32_t timeToPass_ms)
This function checks if timeToPass has passed since the last timestamp to now.
Declaration of the OS wrapper interface.
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
struct definition for plausibility values of an AFE
const int16_t maximumPlausibleVoltage_mV
uint8_t balancingState[BS_NR_OF_STRINGS][BS_NR_OF_BAT_CELLS]
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
uint16_t invalidCellTemperature[BS_NR_OF_STRINGS][BS_NR_OF_MODULES]
uint16_t nrValidTemperatures[BS_NR_OF_STRINGS]
uint16_t nrValidCellVoltages[BS_NR_OF_STRINGS]
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]
uint64_t invalidCellVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES]
int32_t packVoltage_mV[BS_NR_OF_STRINGS]
uint8_t openwire[BS_NR_OF_STRINGS][BS_NR_OF_MODULES *(BS_NR_OF_CELLS_PER_MODULE+1u)]
MXM_REG_NAME_e regAddress
DATA_BLOCK_BALANCING_CONTROL_s *const pBalancingControl_table
bool oddCellsNeedBalancing
bool evenCellsBalancingProcessed
bool oddCellsBalancingProcessed
bool evenCellsNeedBalancing
uint8_t moduleBalancingIndex
uint32_t previousTimeStamp
uint32_t currentTimeStamp
uint16_t blockVoltages[MXM_MAXIMUM_NR_OF_MODULES]
uint16_t auxVoltages_mV[MXM_MAXIMUM_NR_OF_MODULES *MXM_MAXIMUM_NR_OF_AUX_PER_MODULE]
uint16_t cellVoltages_mV[MXM_MAXIMUM_NR_OF_MODULES *MXM_MAXIMUM_NR_OF_CELLS_PER_MODULE]
MXM_5X_COMMAND_PAYLOAD_s batteryCmdBuffer
STD_RETURN_TYPE_e resultSelfCheck
uint32_t timestampLastError
MXM_STATEMACHINE_OPERATION_STATES_e operationSubstate
MXM_SELFCHECK_s selfCheck
uint8_t diagnosticCounter
uint8_t rxBuffer[MXM_RX_BUFFER_LENGTH]
MXM_REGISTRY_ENTRY_s registry[MXM_MAXIMUM_NR_OF_MODULES]
uint8_t mxmVoltageCellCounter
MXM_STATEMACHINE_STATES_e state
bool firstMeasurementDone
MXM_5X_INSTANCE_s *const pInstance5X
MXM_5X_STATE_REQUEST_STATUS_e requestStatus5x
MXM_DATA_STORAGE_s localVoltages
Local storage for cell-voltages.
DATA_BLOCK_OPEN_WIRE_s *const pOpenwire_table
DATA_BLOCK_CELL_VOLTAGE_s *const pCellVoltages_table
DATA_BLOCK_CELL_TEMPERATURE_s *const pCellTemperatures_table
MXM_siliconVersion_e siliconVersion
STD_RETURN_TYPE_e firstSetBit
STD_RETURN_TYPE_e parseVoltageReadall
STD_RETURN_TYPE_e fmeaStatusASCI
STD_RETURN_TYPE_e extractValueFromRegister
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