75 #define BMS_NO_ACTIVE_DELAY_TIME_ms (UINT32_MAX)
80 #define BMS_SAVELASTSTATES() \
81 bms_state.laststate = bms_state.state; \
82 bms_state.lastsubstate = bms_state.substate
97 .ErrRequestCounter = 0u,
100 .OscillationTimeout = 0u,
101 .PrechargeTryCounter = 0u,
103 .closedStrings = {0u},
104 .closedPrechargeContactors = {0u},
105 .numberOfClosedStrings = 0u,
106 .deactivatedStrings = {0},
107 .firstClosedString = 0u,
108 .stringOpenTimeout = 0u,
109 .nextstringclosedtimer = 0u,
110 .stringCloseTimeout = 0u,
116 .transitionToErrorState =
false,
117 .timeAboveContactorBreakCurrent_ms = 0u,
118 .stringToBeOpened = 0u,
382 uint8_t openWireDetected = 0;
398 if (openWireDetected == 0u) {
447 bool fatalErrorActive =
false;
459 fatalErrorActive =
true;
462 return fatalErrorActive;
467 static uint32_t previousTimestamp = 0u;
476 const uint32_t timeSinceLastCall_ms = timestamp - previousTimestamp;
490 if (isErrorActive ==
true) {
497 previousTimestamp = timestamp;
511 bool feedbackValid =
false;
516 switch (contactorType) {
519 feedbackValid =
true;
524 feedbackValid =
true;
529 feedbackValid =
true;
536 return feedbackValid;
542 int32_t max_stringVoltage_mV = INT32_MIN;
550 highest_string_index = s;
554 highest_string_index = s;
561 return highest_string_index;
567 int32_t closedStringVoltage_mV = 0;
568 bool searchString =
false;
580 searchString =
false;
583 if (searchString ==
true) {
587 if ((isStringClosed ==
false) && (isStringVoltageValid == 0u)) {
589 int32_t minimumVoltageDifference_mV = INT32_MAX;
590 int32_t voltageDifference_mV = labs(closedStringVoltage_mV - pPackValues->
stringVoltage_mV[s]);
591 if (voltageDifference_mV <= minimumVoltageDifference_mV) {
595 minimumVoltageDifference_mV = voltageDifference_mV;
596 closestStringIndex = s;
599 minimumVoltageDifference_mV = voltageDifference_mV;
600 closestStringIndex = s;
607 return closestStringIndex;
613 int32_t min_stringVoltage_mV = INT32_MAX;
621 lowest_string_index = s;
625 lowest_string_index = s;
631 return lowest_string_index;
637 int32_t voltageDifference_mV = INT32_MAX;
645 voltageDifference_mV =
649 voltageDifference_mV = INT32_MAX;
651 return voltageDifference_mV;
658 average_current = INT32_MAX;
660 return average_current;
722 uint8_t contactor = 0u;
729 bool inPreferredDirection = (bool)(breakingDirection ==
cont_contactorStates[contactor].breakingDirection);
732 if (correctString && noPrechargeContactor && (inPreferredDirection || hasNoPreferredDirection)) {
770 return contactorToBeOpened;
778 if (firstOpenedContactorType ==
CONT_PLUS) {
784 uint8_t contactor = 0u;
798 return contactorToBeOpened;
829 static uint32_t nextOpenWireCheck = 0;
831 static uint8_t stringNumber = 0u;
832 static uint8_t nextStringNumber = 0u;
834 bool contactorFeedbackValid =
false;
1009 contactorFeedbackValid =
1016 if ((contactorState ==
CONT_SWITCH_OFF) || (contactorFeedbackValid ==
false)) {
1034 contactorFeedbackValid =
1041 if ((contactorState ==
CONT_SWITCH_OFF) || (contactorFeedbackValid ==
false)) {
1050 if (stringNumber > 0u) {
1096 #if BS_STANDBY_PERIODIC_OPEN_WIRE_CHECK == TRUE
1150 #if BS_STANDBY_PERIODIC_OPEN_WIRE_CHECK == TRUE
1151 if (nextOpenWireCheck <= timestamp) {
1215 if (contRetVal ==
STD_OK) {
1277 if (contRetVal ==
STD_OK) {
1346 if (contRetVal ==
STD_OK) {
1388 #if BS_NORMAL_PERIODIC_OPEN_WIRE_CHECK == TRUE
1422 #if BS_NORMAL_PERIODIC_OPEN_WIRE_CHECK == TRUE
1423 if (nextOpenWireCheck <= timestamp) {
1537 if (nextOpenWireCheck <= timestamp) {
1616 bool retval =
false;
1625 bool retval =
false;
1641 #ifdef UNITY_UNIT_TEST
#define AFE_ERROR_OPEN_WIRE_PERIOD_ms
Header for the driver for balancing.
@ BAL_STATE_ALLOWBALANCING_REQUEST
@ BAL_STATE_NO_BALANCING_REQUEST
BAL_RETURN_TYPE_e BAL_SetStateRequest(BAL_STATE_REQUEST_e stateRequest)
sets the current state request of the state variable bal_state.
Configuration of the battery cell (e.g., minimum and maximum cell voltage)
BS_STRING_PRECHARGE_PRESENT_e bs_stringsWithPrecharge[BS_NR_OF_STRINGS]
#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_REST_CURRENT_mA
current threshold for determining rest state of battery. If absolute current is below this limit valu...
#define BS_MAIN_CONTACTORS_MAXIMUM_BREAK_CURRENT_mA
Maximum break current of main contactors.
#define BS_POSITIVE_DISCHARGE_CURRENT
#define BS_NR_OF_MODULES_PER_STRING
number of modules in a string
#define BS_RELAXATION_PERIOD_10ms
Wait time in 10ms before battery system is at rest. Balancing for example only starts if battery syst...
@ BS_STRING_WITH_PRECHARGE
#define BS_NR_OF_CONTACTORS
#define BS_MAIN_FUSE_MAXIMUM_TRIGGER_DURATION_ms
Maximum fuse trigger duration.
static STD_RETURN_TYPE_e BMS_CheckPrecharge(uint8_t stringNumber, const DATA_BLOCK_PACK_VALUES_s *pPackValues)
Checks if the current limitations are violated.
uint8_t TEST_BMS_GetLowestString(BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues)
void TEST_BMS_CheckOpenSenseWire(void)
#define BMS_SAVELASTSTATES()
static DATA_BLOCK_MIN_MAX_s bms_tableMinMax
uint8_t TEST_BMS_GetClosestString(BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues)
BMS_RETURN_TYPE_e TEST_BMS_CheckStateRequest(BMS_STATE_REQUEST_e statereq)
bool BMS_IsStringPrecharging(uint8_t stringNumber)
Returns if string is currently precharging or not.
bool BMS_IsTransitionToErrorStateActive(void)
Check if transition in to error state is active.
BMS_RETURN_TYPE_e BMS_SetStateRequest(BMS_STATE_REQUEST_e statereq)
sets the current state request of the state variable bms_state.
static bool BMS_IsAnyFatalErrorFlagSet(void)
Checks all the error flags from diagnosis module with a severity of DIAG_FATAL_ERROR.
BMS_STATE_REQUEST_e TEST_BMS_TransferStateRequest(void)
static bool BMS_IsContactorFeedbackValid(uint8_t stringNumber, CONT_TYPE_e contactorType)
Checks if the contactor feedback for a specific contactor is valid need to be opened.
STD_RETURN_TYPE_e TEST_BMS_CheckPrecharge(uint8_t stringNumber, DATA_BLOCK_PACK_VALUES_s *pPackValues)
static BMS_RETURN_TYPE_e BMS_CheckStateRequest(BMS_STATE_REQUEST_e statereq)
checks the state requests that are made.
int32_t TEST_BMS_GetStringVoltageDifference(uint8_t string, DATA_BLOCK_PACK_VALUES_s *pPackValues)
uint8_t TEST_BMS_CheckCanRequests(void)
static void BMS_GetMeasurementValues(void)
static DATA_BLOCK_PACK_VALUES_s bms_tablePackValues
static void BMS_UpdateBatsysState(DATA_BLOCK_PACK_VALUES_s *pPackValues)
Updates battery system state variable depending on measured/recent current values.
static CONT_TYPE_e BMS_GetFirstContactorToBeOpened(uint8_t stringNumber, BMS_CURRENT_FLOW_STATE_e flowDirection)
Get first string contactor that should be opened depending on the actual current flow direction.
#define BMS_NO_ACTIVE_DELAY_TIME_ms
static int32_t BMS_GetAverageStringCurrent(DATA_BLOCK_PACK_VALUES_s *pPackValues)
Returns the average current flowing through all strings.
uint8_t TEST_BMS_CheckReEntrance(void)
void TEST_BMS_GetMeasurementValues(void)
void BMS_Trigger(void)
trigger function for the BMS driver state machine.
uint8_t BMS_GetNumberOfConnectedStrings(void)
Returns number of connected strings.
bool BMS_IsStringClosed(uint8_t stringNumber)
Returns string state (closed or open)
static void BMS_CheckOpenSenseWire(void)
Check for any open voltage sense wire.
BMS_CURRENT_FLOW_STATE_e BMS_GetCurrentFlowDirection(int32_t current_mA)
Get current flow direction, current value as function parameter.
static int32_t BMS_GetStringVoltageDifference(uint8_t string, const DATA_BLOCK_PACK_VALUES_s *pPackValues)
Returns voltage difference between first closed string and string ID.
STD_RETURN_TYPE_e TEST_BMS_IsBatterySystemStateOkay(void)
static uint8_t BMS_GetLowestString(BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues)
Returns ID of string with lowest total voltage.
BMS_CURRENT_FLOW_STATE_e BMS_GetBatterySystemState(void)
Returns current battery system state (charging/discharging, resting or in relaxation phase)
int32_t TEST_BMS_GetAverageStringCurrent(DATA_BLOCK_PACK_VALUES_s *pPackValues)
bool TEST_BMS_IsAnyFatalErrorFlagSet(void)
static uint8_t BMS_GetHighestString(BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues)
Returns ID of string with highest total voltage.
static uint8_t BMS_CheckReEntrance(void)
re-entrance check of SYS state machine trigger function
static DATA_BLOCK_OPEN_WIRE_s bms_tableOpenWire
static BMS_STATE_REQUEST_e BMS_TransferStateRequest(void)
transfers the current state request to the state machine.
void TEST_BMS_UpdateBatsysState(DATA_BLOCK_PACK_VALUES_s *pPackValues)
static BMS_STATE_s bms_state
static STD_RETURN_TYPE_e BMS_IsBatterySystemStateOkay(void)
Checks if any error flag is set and handles delay until contactors need to be opened.
static CONT_TYPE_e BMS_GetSecondContactorToBeOpened(uint8_t stringNumber, CONT_TYPE_e firstOpenedContactorType)
Get second string contactor that should be opened.
STD_RETURN_TYPE_e BMS_GetInitializationState(void)
Gets the initialization state.
static uint8_t BMS_CheckCanRequests(void)
Checks the state requests made to the BMS state machine.
BMS_STATEMACH_e BMS_GetState(void)
Returns the current state.
static uint8_t BMS_GetClosestString(BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues)
Returns ID of string with voltage closest to first closed string voltage.
uint8_t TEST_BMS_GetHighestString(BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues)
@ BMS_DO_NOT_TAKE_PRECHARGE_INTO_ACCCOUNT
@ BMS_TAKE_PRECHARGE_INTO_ACCCOUNT
@ BMS_STATE_ERROR_REQUEST
@ BMS_NORMAL_CLOSE_SECOND_STRING_CONTACTOR
@ BMS_PRECHARGE_OPEN_PRECHARGE
@ BMS_OPEN_SECOND_STRING_CONTACTOR
@ BMS_PRECHARGE_CLOSE_PRECHARGE
@ BMS_NORMAL_CLOSE_NEXT_STRING
@ BMS_CHECK_CLOSE_SECOND_STRING_CONTACTOR_PRECHARGE_STATE
@ BMS_CHECK_ERROR_FLAGS_PRECHARGE_CLOSINGSTRINGS
@ BMS_CHECK_ERROR_FLAGS_PRECHARGE_FIRST_STRING
@ BMS_CHECK_ERROR_FLAGS_CLOSINGPRECHARGE
@ BMS_PRECHARGE_CHECK_VOLTAGES
@ BMS_CHECK_STRING_CLOSED
@ BMS_PRECHARGE_CHECK_OPEN_PRECHARGE
@ BMS_OPEN_ALL_PRECHARGES
@ BMS_CHECK_ERROR_FLAGS_INTERLOCK
@ BMS_CHECK_STATE_REQUESTS
@ BMS_OPEN_FIRST_STRING_CONTACTOR
@ BMS_CHECK_SECOND_STRING_CONTACTOR
@ BMS_STATEMACH_PRECHARGE
@ BMS_STATEMACH_UNINITIALIZED
@ BMS_STATEMACH_INITIALIZATION
@ BMS_STATEMACH_DISCHARGE
@ BMS_STATEMACH_OPEN_CONTACTORS
@ BMS_STATEMACH_INITIALIZED
@ BMS_ALREADY_INITIALIZED
#define BMS_REQ_ID_STANDBY
#define BMS_AVERAGE_STRING_CURRENT_LIMIT_MA
#define BMS_TIME_WAIT_AFTER_OPENING_PRECHARGE
#define BMS_STATEMACH_LONGTIME
BMS state machine long time definition in BMS_Trigger() calls until next state/substate is processed.
#define BMS_STATEMACHINE_TASK_CYCLE_CONTEXT_MS
TODO.
#define BMS_STRING_OPEN_TIMEOUT
Timeout in BMS_Trigger() calls when opening a string after which the state machines goes to error if ...
#define BMS_WAIT_TIME_AFTER_OPENING_STRING_CONTACTOR
#define BMS_STRING_CLOSE_TIMEOUT
Timeout in BMS_Trigger() calls when closing a string after which the state machines goes to error if ...
#define BMS_WAIT_TIME_AFTER_CLOSING_STRING_CONTACTOR
#define BMS_WAIT_TIME_BETWEEN_CLOSING_STRINGS
#define BMS_NEXT_STRING_VOLTAGE_LIMIT_MV
Max voltage difference in mV between two strings to allow closing the next string.
#define BMS_PRECHARGE_TRIES
#define BMS_STATEMACH_MEDIUMTIME
BMS state machine medium time definition in BMS_Trigger() calls until next state/substate is processe...
#define BMS_STATEMACH_SHORTTIME
BMS state machine short time definition in BMS_Trigger() calls until next state/substate is processed...
#define BMS_REQ_ID_CHARGE
#define BMS_REQ_ID_NORMAL
#define BMS_NO_STRING_AVAILABLE
Functions searching for next string return this value if no further string is available.
#define BMS_OSCILLATION_TIMEOUT
Timeout in 1*10ms to wait before re-entering to precharge.
#define BMS_TIME_WAIT_AFTERPRECHARGEFAIL
Time to wait in BMS_Trigger() calls after precharge opened because precharge failed.
#define BMS_PRECHARGE_VOLTAGE_THRESHOLD_mV
#define BMS_PRECHARGE_CURRENT_THRESHOLD_mA
#define BMS_TIME_WAIT_AFTER_CLOSING_PRECHARGE
#define DATA_READ_DATA(...)
#define DATA_WRITE_DATA(...)
@ DATA_BLOCK_ID_ERROR_STATE
@ DATA_BLOCK_ID_SYSTEM_STATE
@ DATA_BLOCK_ID_STATE_REQUEST
@ DATA_BLOCK_ID_OPEN_WIRE_BASE
@ DATA_BLOCK_ID_PACK_VALUES
uint32_t DIAG_GetDelay(DIAG_ID_e diagnosisEntry)
Get configured delay of passed diagnosis entry.
STD_RETURN_TYPE_e DIAG_GetDiagnosisEntryState(DIAG_ID_e diagnosisEntry)
Checks if passed diagnosis entry has been triggered or not.
bool DIAG_IsAnyFatalErrorSet(void)
Check if any fatal error is set.
DIAG_RETURNTYPE_e DIAG_Handler(DIAG_ID_e diagId, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
@ DIAG_ID_PRECHARGE_ABORT_REASON_CURRENT
@ DIAG_ID_PRECHARGE_ABORT_REASON_VOLTAGE
#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.
int32_t MATH_AbsInt32_t(const int32_t value)
Returns the absolute value of passed int32_t value.
int64_t MATH_AbsInt64_t(const int64_t value)
Returns the absolute value of passed int64_t value.
math library for often used math functions
#define NULL_PTR
Null pointer.
#define BS_NORMAL_OPEN_WIRE_PERIOD_ms
#define BS_STANDBY_OPEN_WIRE_PERIOD_ms
IMD_RETURN_TYPE_e IMD_RequestInsulationMeasurement(void)
Request to activate the actual IMD measurement.
API header for the insulation monitoring device.
void LED_SetToggleTime(uint32_t onOffTime_ms)
Set debug LED with defined frequency.
Header file of the debug LED driver.
#define LED_NORMAL_OPERATION_ON_OFF_TIME_ms
#define LED_ERROR_OPERATION_ON_OFF_TIME_ms
STD_RETURN_TYPE_e MEAS_RequestOpenWireCheck(uint8_t string)
Makes the request to the AFE state machine to perform open-wire check.
Headers for the driver for the measurements needed by the BMS (e.g., I,V,T).
Declaration of the OS wrapper interface.
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
void SOA_CheckTemperatures(DATA_BLOCK_MIN_MAX_s *pMinimumMaximumCellTemperatures, DATA_BLOCK_PACK_VALUES_s *pCurrent)
checks the abidance by the safe operating area
void SOA_CheckVoltages(DATA_BLOCK_MIN_MAX_s *pMinimumMaximumCellVoltages)
checks the abidance by the safe operating area
void SOA_CheckSlaveTemperatures(void)
FOR FUTURE COMPATIBILITY; DUMMY FUNCTION; DO NOT USE.
void SOA_CheckCurrent(DATA_BLOCK_PACK_VALUES_s *pTablePackValues)
checks the abidance by the safe operating area
Header for SOA module, responsible for checking battery parameters against safety limits.
uint8_t PrechargeTryCounter
bool transitionToErrorState
BMS_CURRENT_FLOW_STATE_e currentFlowState
STD_RETURN_TYPE_e initFinished
uint8_t closedPrechargeContactors[BS_NR_OF_STRINGS]
BMS_STATEMACH_e nextstate
uint8_t closedStrings[BS_NR_OF_STRINGS]
uint8_t firstClosedString
CONT_TYPE_e contactorToBeOpened
uint8_t deactivatedStrings[BS_NR_OF_STRINGS]
uint32_t nextstringclosedtimer
BMS_STATE_REQUEST_e stateRequest
uint32_t ErrRequestCounter
uint32_t minimumActiveDelay_ms
uint8_t numberOfClosedStrings
uint16_t stringCloseTimeout
BMS_STATEMACH_SUB_e substate
uint16_t stringOpenTimeout
uint32_t timeAboveContactorBreakCurrent_ms
BMS_POWER_PATH_TYPE_e powerPath
uint32_t remainingDelay_ms
uint16_t OscillationTimeout
bool contactorInNegativePathOfStringFeedbackError[BS_NR_OF_STRINGS]
bool contactorInPositivePathOfStringFeedbackError[BS_NR_OF_STRINGS]
bool prechargeContactorFeedbackError[BS_NR_OF_STRINGS]
DATA_BLOCK_HEADER_s header
DATA_BLOCK_HEADER_s header
DATA_BLOCK_HEADER_s header
uint8_t openWire[BS_NR_OF_STRINGS][BS_NR_OF_MODULES_PER_STRING *BS_NR_OF_CELL_BLOCKS_PER_MODULE]
int32_t stringVoltage_mV[BS_NR_OF_STRINGS]
int32_t highVoltageBusVoltage_mV
uint8_t invalidPackCurrent
DATA_BLOCK_HEADER_s header
int32_t stringCurrent_mA[BS_NR_OF_STRINGS]
uint8_t invalidHvBusVoltage
uint8_t invalidStringCurrent[BS_NR_OF_STRINGS]
uint8_t invalidStringVoltage[BS_NR_OF_STRINGS]
DATA_BLOCK_HEADER_s header
uint8_t stateRequestViaCan
DATA_BLOCK_HEADER_s header
DIAG_ID_CFG_s * pFatalErrorLinkTable[DIAG_ID_MAX]
uint16_t numberOfFatalErrors