72 #define MXM_OFFSET_CELL_1 (0u)
73 #define MXM_OFFSET_CELL_2 (1u)
74 #define MXM_OFFSET_CELL_3 (2u)
75 #define MXM_OFFSET_CELL_4 (3u)
76 #define MXM_OFFSET_CELL_5 (4u)
77 #define MXM_OFFSET_CELL_6 (5u)
78 #define MXM_OFFSET_CELL_7 (6u)
79 #define MXM_OFFSET_CELL_8 (7u)
80 #define MXM_OFFSET_CELL_9 (8u)
81 #define MXM_OFFSET_CELL_10 (9u)
82 #define MXM_OFFSET_CELL_11 (10u)
83 #define MXM_OFFSET_CELL_12 (11u)
84 #define MXM_OFFSET_CELL_13 (12u)
85 #define MXM_OFFSET_CELL_14 (13u)
86 #define MXM_OFFSET_AUX0 (0u)
87 #define MXM_OFFSET_AUX2 (2u)
88 #define MXM_OFFSET_AUX3 (3u)
89 #define MXM_OFFSET_BLOCK (0u)
92 #define MXM_MAXIMUM_ERROR_COUNT (10u)
95 #define MXM_TIMEOUT_RESET_ERROR_COUNTER_ms (500)
98 #define MXM_TEST_BUFFER_MAXIMUM_LENGTH (120u)
103 .minimumPlausibleVoltage_mV = -2500,
108 #define MXM_REF_VAA_mV (3300u)
143 const uint8_t *
const kpkVoltRxBuffer,
144 uint16_t voltRxBufferLength,
145 uint8_t measurementOffset,
147 uint16_t *pVoltagesTarget,
149 uint32_t fullScaleReference_mV);
172 const uint8_t *
const kpkVoltageRxBuffer,
173 uint16_t voltageRxBufferLength,
200 const uint8_t *
const kpkVoltRxBuffer,
201 uint16_t voltRxBufferLength,
202 uint8_t measurementOffset,
204 uint16_t *pVoltagesTarget,
206 uint32_t fullScaleReference_mV) {
218 FAS_ASSERT(((voltRxBufferLength - 2u - 2u) / 2u) <= (uint16_t)UINT8_MAX);
220 const uint8_t numberOfConnectedDevices = (uint8_t)(((voltRxBufferLength - 2u - 2u) / 2u) & (uint8_t)UINT8_MAX);
223 for (uint8_t i = 2u; i < (voltRxBufferLength - 2u); i = i + 2u) {
224 const uint8_t calculatedModuleNumber = numberOfConnectedDevices - ((i / 2u) - 1u) - 1u;
225 uint16_t calculatedModulePosition = 0u;
226 switch (measurementType) {
234 calculatedModulePosition = calculatedModuleNumber;
240 FAS_ASSERT((calculatedModulePosition + measurementOffset) <= (uint16_t)UINT16_MAX);
241 uint16_t calculatedArrayPosition = calculatedModulePosition + measurementOffset;
244 switch (measurementType) {
260 FAS_ASSERT((i + (uint16_t)1u) <= voltRxBufferLength);
263 kpkVoltRxBuffer[i + 1u],
264 &pVoltagesTarget[calculatedArrayPosition],
266 fullScaleReference_mV);
271 const uint8_t *
const kpkVoltageRxBuffer,
272 uint16_t voltageRxBufferLength,
284 }
else if ((voltageRxBufferLength % 2u) != 0u) {
294 switch (kpkVoltageRxBuffer[1]) {
298 voltageRxBufferLength,
308 voltageRxBufferLength,
318 voltageRxBufferLength,
328 voltageRxBufferLength,
338 voltageRxBufferLength,
348 voltageRxBufferLength,
358 voltageRxBufferLength,
368 voltageRxBufferLength,
378 voltageRxBufferLength,
388 voltageRxBufferLength,
398 voltageRxBufferLength,
408 voltageRxBufferLength,
418 voltageRxBufferLength,
428 voltageRxBufferLength,
438 voltageRxBufferLength,
448 voltageRxBufferLength,
458 voltageRxBufferLength,
468 voltageRxBufferLength,
528 testBufferLength = 5;
538 testBuffer[2] = 0xFCu;
539 testBuffer[3] = 0xFFu;
540 testBuffer[4] = 0x00u;
541 testBuffer[5] = 0x00u;
542 testBuffer[6] = 0xFCu;
543 testBuffer[7] = 0xFFu;
544 testBuffer[8] = 0x42u;
545 testBuffer[9] = 0x44u;
546 testBufferLength = 10u;
568 testBuffer[2] = 0xFCu;
569 testBuffer[3] = 0xFFu;
570 testBuffer[4] = 0x00u;
571 testBuffer[5] = 0x00u;
572 testBuffer[6] = 0xFCu;
573 testBuffer[7] = 0xFFu;
574 testBuffer[8] = 0x42u;
575 testBuffer[9] = 0x44u;
576 testBufferLength = 10;
598 testBuffer[2] = 0xFCu;
599 testBuffer[3] = 0xFFu;
600 testBuffer[4] = 0x42u;
601 testBuffer[5] = 0x44u;
602 testBufferLength = 6;
622 testBuffer[2] = 0xFCu;
623 testBuffer[3] = 0xFFu;
624 testBuffer[4] = 0x42u;
625 testBuffer[5] = 0x44u;
626 testBufferLength = 6;
646 testBuffer[2] = 0xFCu;
647 testBuffer[3] = 0xFFu;
648 testBuffer[4] = 0x42u;
649 testBuffer[5] = 0x44u;
650 testBufferLength = 6;
670 testBuffer[2] = 0xFCu;
671 testBuffer[3] = 0xFFu;
672 testBuffer[4] = 0x42u;
673 testBuffer[5] = 0x44u;
674 testBufferLength = 6;
694 testBuffer[2] = 0xFCu;
695 testBuffer[3] = 0xFFu;
696 testBuffer[4] = 0x42u;
697 testBuffer[5] = 0x44u;
698 testBufferLength = 6;
718 testBuffer[2] = 0xFCu;
719 testBuffer[3] = 0xFFu;
720 testBuffer[4] = 0x42u;
721 testBuffer[5] = 0x44u;
722 testBufferLength = 6;
742 testBuffer[2] = 0xFCu;
743 testBuffer[3] = 0xFFu;
744 testBuffer[4] = 0x42u;
745 testBuffer[5] = 0x44u;
746 testBufferLength = 6;
766 testBuffer[2] = 0xFCu;
767 testBuffer[3] = 0xFFu;
768 testBuffer[4] = 0x42u;
769 testBuffer[5] = 0x44u;
770 testBufferLength = 6;
790 testBuffer[2] = 0xFCu;
791 testBuffer[3] = 0xFFu;
792 testBuffer[4] = 0x42u;
793 testBuffer[5] = 0x44u;
794 testBufferLength = 6;
814 testBuffer[2] = 0xFCu;
815 testBuffer[3] = 0xFFu;
816 testBuffer[4] = 0x42u;
817 testBuffer[5] = 0x44u;
818 testBufferLength = 6;
838 testBuffer[2] = 0xFCu;
839 testBuffer[3] = 0xFFu;
840 testBuffer[4] = 0x42u;
841 testBuffer[5] = 0x44u;
842 testBufferLength = 6;
862 testBuffer[2] = 0xFCu;
863 testBuffer[3] = 0xFFu;
864 testBuffer[4] = 0x42u;
865 testBuffer[5] = 0x44u;
866 testBufferLength = 6;
892 const bool counterCanBeReset =
894 if (counterCanBeReset ==
true) {
978 "please check assumptions: code cannot handle number of modules");
981 for (uint8_t i = 2u; i < (messageLength - 2u); i = i + 2u) {
983 const uint8_t calculatedModuleNumberInDaisyChain = numberOfSatellites - ((i / 2u) - 1u) - 1u;
984 uint8_t stringNumber = 0u;
985 uint16_t moduleNumber = 0u;
993 const uint8_t mask = 1u << c;
994 if ((uint8_t)(mask & kpkInstance->
rxBuffer[i]) > 0u) {
1002 if ((uint8_t)(mask & kpkInstance->
rxBuffer[i + 1u]) > 0u) {
1037 uint8_t stringNumber = 0u;
1038 uint16_t moduleNumber = 0u;
1085 uint8_t stringNumber = 0u;
1086 uint16_t moduleNumber = 0u;
1093 if (moduleNumber == 0u) {
1104 if ((int32_t)cellVoltageLocal_mV > INT16_MAX) {
1108 (int16_t)cellVoltageLocal_mV;
1113 if ((valueIsPlausible ==
STD_OK) && moduleIsConnected) {
1114 numberValidVoltageMeasurements[stringNumber]++;
1118 ((uint64_t)1u << i_bat);
1127 uint8_t stringNumber = 0u;
1128 uint16_t moduleNumber = 0u;
1144 if ((valueIsPlausible ==
STD_OK) && moduleIsConnected) {
1145 numberValidTemperatureMeasurements[stringNumber]++;
1233 pMonitoringInstance->
rxBuffer[i] = 0u;
1324 switch (pInstance->
state) {
1387 (resultNumberOfSatellitesGood ==
STD_OK)) {
1422 #ifdef UNITY_UNIT_TEST
1430 uint8_t *voltRxBuffer,
1431 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_CELL_BLOCKS_PER_MODULE
number of cells per module
#define BS_NR_OF_STRINGS
Number of parallel strings in the battery pack.
#define BS_NR_OF_TEMP_SENSORS_PER_MODULE
number of temperature sensors per battery module
#define BS_NR_OF_MODULES_PER_STRING
number of modules in a string
#define DATA_WRITE_DATA(...)
STD_RETURN_TYPE_e DIAG_CheckEvent(STD_RETURN_TYPE_e cond, DIAG_ID_e diagId, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_CheckEvent provides a simple interface to check an event for STD_OK.
#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 FAS_STATIC_ASSERT(cond, msg)
#define NULL_PTR
Null pointer.
#define GEN_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
STD_RETURN_TYPE_e MXM_PreInitSelfCheck(MXM_MONITORING_INSTANCE_s *pState)
Execute all preinit selfchecks.
#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.
bool GEN_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 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.
#define MXM_OFFSET_CELL_1
#define MXM_OFFSET_CELL_7
#define MXM_OFFSET_CELL_10
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.
#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
static STD_RETURN_TYPE_e GEN_MUST_CHECK_RETURN MXM_ParseVoltageReadallTest(MXM_MONITORING_INSTANCE_s *pInstance)
Test the MXM_ParseVoltageReadall()-function.
#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
MXM_MONITORING_STATE_e GEN_MUST_CHECK_RETURN MXM_MonGetVoltages(MXM_MONITORING_INSTANCE_s *pState, MXM_REG_NAME_e regAddress)
Encapsulation for reading voltages from a register.
void MXM_HandleStateWriteall(MXM_MONITORING_INSTANCE_s *pInstance, MXM_STATEMACHINE_OPERATION_STATES_e nextState)
Handle the statemachine-transactions for a WRITEALL.
#define MXM_OFFSET_CELL_3
#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.
@ MXM_SILICON_VERSION_INVALID
#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
#define MXM_MAXIMUM_NR_OF_MODULES
Maximum number of modules.
STD_RETURN_TYPE_e GEN_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 GEN_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_CELL_BLOCKS_PER_STRING]
int16_t cellTemperature_ddegC[BS_NR_OF_STRINGS][BS_NR_OF_TEMP_SENSORS_PER_STRING]
uint16_t nrValidTemperatures[BS_NR_OF_STRINGS]
uint16_t invalidCellTemperature[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
int32_t packVoltage_mV[BS_NR_OF_STRINGS]
uint64_t invalidCellVoltage[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
uint16_t nrValidCellVoltages[BS_NR_OF_STRINGS]
uint32_t moduleVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING]
int16_t cellVoltage_mV[BS_NR_OF_STRINGS][BS_NR_OF_CELL_BLOCKS_PER_STRING]
uint8_t openwire[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING *(BS_NR_OF_CELL_BLOCKS_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_SILICON_VERSION_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