73 #define BMS_NO_ACTIVE_DELAY_TIME_ms (UINT32_MAX)
78 #define BMS_SAVELASTSTATES() \
79 bms_state.laststate = bms_state.state; \
80 bms_state.lastsubstate = bms_state.substate
95 .ErrRequestCounter = 0u,
98 .OscillationTimeout = 0u,
99 .PrechargeTryCounter = 0u,
101 .closedStrings = {0u},
102 .closedPrechargeContactors = {0u},
103 .numberOfClosedStrings = 0u,
104 .deactivatedStrings = {0},
105 .firstClosedString = 0u,
106 .stringOpenTimeout = 0u,
107 .nextstringclosedtimer = 0u,
108 .stringCloseTimeout = 0u,
114 .transitionToErrorState =
false,
340 uint8_t openWireDetected = 0;
356 if (openWireDetected == 0u) {
391 bool fatalErrorActive =
false;
403 fatalErrorActive =
true;
406 return fatalErrorActive;
411 static uint32_t previousTimestamp = 0u;
420 const uint32_t timeSinceLastCall_ms = timestamp - previousTimestamp;
434 if (isErrorActive ==
true) {
441 previousTimestamp = timestamp;
455 int32_t max_stringVoltage_mV = INT32_MIN;
463 highest_string_index = s;
467 highest_string_index = s;
474 return highest_string_index;
480 int32_t closedStringVoltage_mV = 0;
481 bool searchString =
false;
493 searchString =
false;
496 if (searchString ==
true) {
500 if ((isStringClosed ==
false) && (isStringVoltageValid == 0u)) {
502 int32_t minimumVoltageDifference_mV = INT32_MAX;
503 int32_t voltageDifference_mV = labs(closedStringVoltage_mV - pPackValues->
stringVoltage_mV[s]);
504 if (voltageDifference_mV <= minimumVoltageDifference_mV) {
508 minimumVoltageDifference_mV = voltageDifference_mV;
509 closestStringIndex = s;
512 minimumVoltageDifference_mV = voltageDifference_mV;
513 closestStringIndex = s;
520 return closestStringIndex;
526 int32_t min_stringVoltage_mV = INT32_MAX;
534 lowest_string_index = s;
538 lowest_string_index = s;
544 return lowest_string_index;
550 int32_t voltageDifference_mV = INT32_MAX;
558 voltageDifference_mV =
562 voltageDifference_mV = INT32_MAX;
564 return voltageDifference_mV;
571 average_current = INT32_MAX;
573 return average_current;
651 static uint32_t nextOpenWireCheck = 0;
653 static uint8_t stringNumber = 0u;
654 static uint8_t nextStringNumber = 0u;
807 if (stringNumber > 0u) {
849 #if BS_STANDBY_PERIODIC_OPEN_WIRE_CHECK == TRUE
903 #if BS_STANDBY_PERIODIC_OPEN_WIRE_CHECK == TRUE
904 if (nextOpenWireCheck <= timestamp) {
955 if (contRetVal ==
STD_OK) {
1000 if (contRetVal ==
STD_OK) {
1075 if (contRetVal ==
STD_OK) {
1097 #if BS_NORMAL_PERIODIC_OPEN_WIRE_CHECK == TRUE
1130 #if BS_NORMAL_PERIODIC_OPEN_WIRE_CHECK == TRUE
1131 if (nextOpenWireCheck <= timestamp) {
1225 if (nextOpenWireCheck <= timestamp) {
1304 bool retval =
false;
1313 bool retval =
false;
1329 #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 determing rest state of battery. If absolute current is below this limit value ...
#define 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
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)
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.
#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 SYS 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.
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_PRECHARGE_OPEN_PRECHARGE
@ BMS_PRECHARGE_CLOSE_PRECHARGE
@ BMS_NORMAL_CLOSE_NEXT_STRING
@ 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_OPEN_ALL_PRECHARGES
@ BMS_CHECK_ERROR_FLAGS_INTERLOCK
@ BMS_CHECK_STATE_REQUESTS
@ BMS_CLOSE_FIRST_STRING_PRECHARGE_STATE
@ BMS_CHECK_CLOSE_FIRST_STRING_PRECHARGE_STATE
@ BMS_STATEMACH_PRECHARGE
@ BMS_STATEMACH_OPENCONTACTORS
@ BMS_STATEMACH_UNINITIALIZED
@ BMS_STATEMACH_INITIALIZATION
@ BMS_STATEMACH_DISCHARGE
@ BMS_STATEMACH_INITIALIZED
@ BMS_ALREADY_INITIALIZED
#define BMS_TIME_WAIT_AFTER_OPENING_STRING
#define BMS_REQ_ID_STANDBY
#define BMS_AVERAGE_STRING_CURRENT_LIMIT_MA
#define BMS_TIME_WAIT_AFTER_OPENING_PRECHARGE
#define BMS_STATEMACH_LONGTIME
BMS statemachine long time definition in BMS_Trigger() calls until next state/substate is processed.
#define BMS_STRING_OPEN_TIMEOUT
#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_TIME_WAIT_AFTER_STRING_CLOSED
#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 statemachine medium time definition in BMS_Trigger() calls until next state/substate is processed...
#define BMS_STATEMACH_SHORTTIME
BMS statemachine 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_SYSTEMSTATE
@ DATA_BLOCK_ID_OPEN_WIRE_BASE
@ DATA_BLOCK_ID_PACK_VALUES
@ DATA_BLOCK_ID_STATEREQUEST
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 diag_id, DIAG_EVENT_e event, DIAG_IMPACT_LEVEL_e impact, uint32_t data)
DIAG_Handler provides generic error handling, based on diagnosis group.
#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
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
BMS_POWER_PATH_TYPE_e powerPath
uint32_t remainingDelay_ms
uint16_t OscillationTimeout
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+1u)]
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]
uint8_t stateRequestViaCan
DATA_BLOCK_HEADER_s header
DATA_BLOCK_HEADER_s header
DIAG_ID_CFG_s * pFatalErrorLinkTable[DIAG_ID_MAX]
uint16_t numberOfFatalErrors