|
foxBMS
1.0.0
The foxBMS Battery Management System API Documentation
|
Go to the documentation of this file.
74 #define BMS_SAVELASTSTATES() \
75 bms_state.laststate = bms_state.state; \
76 bms_state.lastsubstate = bms_state.substate
91 .ErrRequestCounter = 0u,
94 .OscillationTimeout = 0u,
95 .PrechargeTryCounter = 0u,
97 .closedStrings = {0u},
98 .closedPrechargeContactors = {0u},
99 .numberOfClosedStrings = 0u,
100 .deactivatedStrings = {0},
101 .firstClosedString = 0u,
102 .stringOpenTimeout = 0u,
103 .nextstringclosedtimer = 0u,
104 .stringCloseTimeout = 0u,
312 #if BS_SEPARATE_POWERLINES == 1
322 uint8_t openWireDetected = 0;
338 if (openWireDetected == 0u) {
422 int32_t max_stringVoltage_mV = INT32_MIN;
430 highest_string_index = s;
434 highest_string_index = s;
441 return highest_string_index;
447 int32_t closedStringVoltage_mV = 0;
448 bool searchString =
false;
460 searchString =
false;
463 if (
true == searchString) {
467 if ((
false == isStringClosed) && (0u == isStringVoltageValid)) {
469 int32_t minimumVoltageDifference_mV = INT32_MAX;
470 int32_t voltageDifference_mV = labs(closedStringVoltage_mV - pPackValues->
stringVoltage_mV[s]);
471 if (voltageDifference_mV <= minimumVoltageDifference_mV) {
475 minimumVoltageDifference_mV = voltageDifference_mV;
476 closestStringIndex = s;
479 minimumVoltageDifference_mV = voltageDifference_mV;
480 closestStringIndex = s;
487 return closestStringIndex;
493 int32_t min_stringVoltage_mV = INT32_MAX;
501 lowest_string_index = s;
505 lowest_string_index = s;
511 return lowest_string_index;
517 int32_t voltageDifference_mV = INT32_MAX;
525 voltageDifference_mV =
529 voltageDifference_mV = INT32_MAX;
531 return voltageDifference_mV;
538 average_current = INT32_MAX;
540 return average_current;
618 static uint32_t nextOpenWireCheck = 0;
620 static uint8_t stringNumber = 0u;
621 static uint8_t nextStringNumber = 0u;
769 if (stringNumber > 0u) {
810 #if LTC_STANDBY_PERIODIC_OPEN_WIRE_CHECK == TRUE
864 #if LTC_STANDBY_PERIODIC_OPEN_WIRE_CHECK == TRUE
865 if (nextOpenWireCheck <= timestamp) {
914 if (contRetVal ==
STD_OK) {
959 if (contRetVal ==
STD_OK) {
1034 if (contRetVal ==
STD_OK) {
1054 #if LTC_NORMAL_PERIODIC_OPEN_WIRE_CHECK == TRUE
1087 #if LTC_NORMAL_PERIODIC_OPEN_WIRE_CHECK == TRUE
1088 if (nextOpenWireCheck <= timestamp) {
1179 if (nextOpenWireCheck <= timestamp) {
1259 bool retval =
false;
1268 bool retval =
false;
1276 #ifdef UNITY_UNIT_TEST
1283 extern uint8_t TEST_BMS_CheckReEntrance(
void) {
1286 extern uint8_t TEST_BMS_CheckCanRequests(
void) {
1292 extern void TEST_BMS_GetMeasurementValues(
void) {
1296 extern void TEST_BMS_CheckOpenSenseWire(
void) {
Implementation of the tasks used by the system, headers.
int32_t highVoltageBusVoltage_mV
uint8_t crcError[BS_NR_OF_STRINGS]
static DATA_BLOCK_OPEN_WIRE_s bms_tableOpenWire
@ DATA_BLOCK_ID_PACK_VALUES
#define BMS_TIME_WAIT_AFTER_OPENING_PRECHARGE
uint8_t packDischargeOvercurrent
uint8_t stringDischargeOvercurrent[BS_NR_OF_STRINGS]
enum BMS_CURRENT_FLOW_STATE BMS_CURRENT_FLOW_STATE_e
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.
#define BMS_TIME_WAIT_AFTER_OPENING_STRING
@ BMS_CLOSE_FIRST_STRING_PRECHARGE_STATE
@ BMS_CHECK_ERROR_FLAGS_PRECHARGE_FIRST_STRING
@ BMS_CHECK_ERROR_FLAGS_PRECHARGE_CLOSINGSTRINGS
#define BMS_PRECHARGE_TRIES
#define BS_NR_OF_MODULES
number of modules in battery pack
#define BMS_STATEMACH_MEDIUMTIME
BMS statemachine medium time definition in BMS_Trigger() calls until next state/substate is processed...
@ BMS_STATEMACH_UNINITIALIZED
DATA_BLOCK_HEADER_s header
DATA_BLOCK_HEADER_s header
@ DATA_BLOCK_ID_OPEN_WIRE_BASE
@ BMS_PRECHARGE_CHECK_VOLTAGES
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
#define BMS_STATEMACH_VERYLONGTIME
BMS statemachine very long time definition in BMS_Trigger() calls until next state/substate is proces...
uint8_t invalidStringCurrent[BS_NR_OF_STRINGS]
uint8_t invalidStringVoltage[BS_NR_OF_STRINGS]
void SOA_CheckTemperatures(DATA_BLOCK_MIN_MAX_s *pMinimumMaximumCellTemperatures, DATA_BLOCK_PACK_VALUES_s *pCurrent)
checks the abidance by the safe operating area
uint8_t currentSensor[BS_NR_OF_STRINGS]
uint8_t stateRequestViaCan
static void BMS_CheckOpenSenseWire(void)
Check for any open voltage sense wire.
void SOA_CheckCurrent(DATA_BLOCK_PACK_VALUES_s *pTablePackValues)
checks the abidance by the safe operating area
#define DATA_WRITE_DATA(...)
#define BMS_REQ_ID_NORMAL
uint8_t fuseStateCharge[BS_NR_OF_STRINGS]
uint8_t invalidPackCurrent
uint8_t PrechargeTryCounter
uint32_t nextstringclosedtimer
Header for the driver for balancing.
uint8_t prechargeContactor[BS_NR_OF_STRINGS]
#define BS_RELAXATION_PERIOD_10ms
Wait time in 10ms before battery system is at rest. Balancing for example only starts if battery syst...
@ BMS_STATEMACH_INITIALIZED
@ BS_STRING_WITH_PRECHARGE
enum BMS_STATE_REQUEST BMS_STATE_REQUEST_e
BMS_CURRENT_FLOW_STATE_e BMS_GetCurrentFlowDirection(int32_t current_mA)
Get current flow direction, current value as function parameter.
uint8_t stringChargeOvercurrent[BS_NR_OF_STRINGS]
uint8_t currentOnOpenString[BS_NR_OF_STRINGS]
#define BS_NR_OF_CELLS_PER_MODULE
number of battery cells per battery module (parallel cells are counted as one)
uint8_t deactivatedStrings[BS_NR_OF_STRINGS]
enum BMS_RETURN_TYPE BMS_RETURN_TYPE_e
#define BMS_NO_STRING_AVAILABLE
Functions searching for next string return this value if no further string is available.
uint16_t OscillationTimeout
#define BMS_OPEN_CONTACTORS_ON_INSULATION_ERROR
Defines behaviour if an insulation error is detected.
int32_t MATH_AbsInt32(int32_t value)
Returns the absolute value of passed int32_t value.
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.
uint8_t undertemperatureCharge[BS_NR_OF_STRINGS]
@ BAL_STATE_NO_BALANCING_REQUEST
#define BMS_STRING_CLOSE_TIMEOUT
Timeout in BMS_Trigger() calls when closing a string after which the state machines goes to error if ...
uint8_t fuseStateNormal[BS_NR_OF_STRINGS]
#define BMS_TIME_WAIT_AFTER_STRING_CLOSED
enum BMS_STATEMACH BMS_STATEMACH_e
@ BMS_OPEN_ALL_PRECHARGES
#define BMS_STATEMACH_SHORTTIME
BMS statemachine short time definition in BMS_Trigger() calls until next state/substate is processed.
#define LTC_STANDBY_OPEN_WIRE_PERIOD_ms
static BMS_STATE_REQUEST_e BMS_TransferStateRequest(void)
transfers the current state request to the state machine.
uint8_t canTimingCc[BS_NR_OF_STRINGS]
uint8_t overtemperatureDischarge[BS_NR_OF_STRINGS]
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
@ BMS_CHECK_ERROR_FLAGS_INTERLOCK
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
static BMS_STATE_s bms_state
@ BMS_DO_NOT_TAKE_PRECHARGE_INTO_ACCCOUNT
@ BMS_PRECHARGE_CLOSE_PRECHARGE
uint8_t overtemperatureCharge[BS_NR_OF_STRINGS]
#define BMS_PRECHARGE_CURRENT_THRESHOLD_mA
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
BMS_POWERLINE_TYPE_e powerline
uint32_t ErrRequestCounter
uint8_t closedStrings[BS_NR_OF_STRINGS]
void SOA_CheckSlaveTemperatures(void)
FOR FUTURE COMPATIBILITY; DUMMY FUNCTION; DO NOT USE.
static STD_RETURN_TYPE_e BMS_CheckAnyErrorFlagSet(void)
Checks the error flags.
BMS_STATE_REQUEST_e stateRequest
Measurement IC driver header.
math library for often used math functions
static void BMS_GetMeasurementValues(void)
BMS_STATEMACH_SUB_e substate
uint8_t packChargeOvercurrent
uint8_t micConfigurationError[BS_NR_OF_STRINGS]
static int32_t BMS_GetAverageStringCurrent(DATA_BLOCK_PACK_VALUES_s *pPackValues)
Returns the average current flowing through all strings.
uint8_t numberOfClosedStrings
@ BMS_STATEMACH_DISCHARGE
static void BMS_UpdateBatsysState(DATA_BLOCK_PACK_VALUES_s *pPackValues)
Updates battery system state variable depending on measured/recent current values.
DATA_BLOCK_HEADER_s header
DATA_BLOCK_HEADER_s header
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
enum BMS_CONSIDER_PRECHARGE BMS_CONSIDER_PRECHARGE_e
bool BMS_IsStringClosed(uint8_t stringNumber)
Returns string state (closed or open)
uint8_t stringContactor[BS_NR_OF_STRINGS]
BMS_CURRENT_FLOW_STATE_e BMS_GetBatterySystemState(void)
Returns current battery system state (charging/discharging, resting or in relaxation phase)
Configuration of the battery cell (e.g., minimum and maximum cell voltage)
void BMS_Trigger(void)
trigger function for the SYS driver state machine.
static DATA_BLOCK_MIN_MAX_s bms_tableMinMax
#define BMS_AVERAGE_STRING_CURRENT_LIMIT_MA
@ BMS_CHECK_STRING_CLOSED
STD_RETURN_TYPE_e BMS_GetInitializationState(void)
Gets the initialization state.
static STD_RETURN_TYPE_e BMS_CheckPrecharge(uint8_t stringNumber, const DATA_BLOCK_PACK_VALUES_s *pPackValues)
Checks if the current limitations are violated.
@ BMS_ALREADY_INITIALIZED
uint16_t stringOpenTimeout
BMS_CURRENT_FLOW_STATE_e currentFlowState
ILCK_RETURN_TYPE_e ILCK_SetStateRequest(ILCK_STATE_REQUEST_e statereq)
sets the current state request of the state variable ilck_state.
STD_RETURN_TYPE_e initFinished
int32_t stringCurrent_mA[BS_NR_OF_STRINGS]
uint8_t muxError[BS_NR_OF_STRINGS]
@ BMS_CHECK_CLOSE_FIRST_STRING_PRECHARGE_STATE
#define LTC_NORMAL_OPEN_WIRE_PERIOD_ms
@ DATA_BLOCK_ID_STATEREQUEST
#define BMS_OSCILLATION_TIMEOUT
Timeout in 1*10ms to wait before re-entering to precharge.
uint8_t overVoltage[BS_NR_OF_STRINGS]
static uint8_t BMS_GetHighestString(BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues)
Returns ID of string with highest total voltage.
DATA_BLOCK_HEADER_s header
#define DATA_READ_DATA(...)
void SOA_CheckVoltages(DATA_BLOCK_MIN_MAX_s *pMinimumMaximumCellVoltages)
checks the abidance by the safe operating area
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 openwire[BS_NR_OF_STRINGS][BS_NR_OF_MODULES *(BS_NR_OF_CELLS_PER_MODULE+1)]
BMS_STATEMACH_e BMS_GetState(void)
Returns the current state.
uint8_t undertemperatureDischarge[BS_NR_OF_STRINGS]
@ DATA_BLOCK_ID_ERRORSTATE
Headers for the driver for the measurements needed by the BMS (e.g., I,V,T).
bool BMS_IsStringPrecharging(uint8_t stringNumber)
Returns if string is currently precharging or not.
@ BMS_CHECK_STATE_REQUESTS
static BMS_RETURN_TYPE_e BMS_CheckStateRequest(BMS_STATE_REQUEST_e statereq)
checks the state requests that are made.
uint8_t open_wire[BS_NR_OF_STRINGS]
@ BMS_STATEMACH_INITIALIZATION
uint8_t deepDischargeDetected[BS_NR_OF_STRINGS]
uint8_t spiError[BS_NR_OF_STRINGS]
uint8_t invalidHvBusVoltage
@ BMS_CHECK_INTERLOCK_CLOSE_AFTER_ERROR
#define NULL_PTR
Null pointer.
uint8_t underVoltage[BS_NR_OF_STRINGS]
static uint8_t BMS_GetLowestString(BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues)
Returns ID of string with lowest total voltage.
#define BMS_STRING_OPEN_TIMEOUT
Header for SOA module, responsible for checking battery parameters against safety limits.
uint8_t firstClosedString
#define BS_REST_CURRENT_mA
current threshold for determing rest state of battery. If absolute current is below this limit value ...
#define MIC_ERROR_OPEN_WIRE_PERIOD_ms
@ BMS_STATE_ERROR_REQUEST
#define BMS_STATEMACH_LONGTIME
BMS statemachine long time definition in BMS_Trigger() calls until next state/substate is processed.
@ BMS_NORMAL_CLOSE_NEXT_STRING
@ ILCK_STATE_CLOSE_REQUEST
BAL_RETURN_TYPE_e BAL_SetStateRequest(BAL_STATE_REQUEST_e stateRequest)
sets the current state request of the state variable bal_state.
DATA_BLOCK_HEADER_s header
#define BMS_SAVELASTSTATES()
@ DATA_BLOCK_ID_SYSTEMSTATE
uint16_t stringCloseTimeout
uint8_t canTimingEc[BS_NR_OF_STRINGS]
ILCK_ELECTRICAL_STATE_TYPE_e ILCK_GetInterlockFeedback(void)
Reads the feedback pin of the interlock and returns its current value (ILCK_SWITCH_OFF/ILCK_SWITCH_ON...
@ BMS_CHECK_ERROR_FLAGS_CLOSINGPRECHARGE
#define BMS_PRECHARGE_VOLTAGE_THRESHOLD_mV
int32_t stringVoltage_mV[BS_NR_OF_STRINGS]
@ ILCK_STATE_OPEN_REQUEST
uint8_t cellChargeOvercurrent[BS_NR_OF_STRINGS]
@ BMS_STATEMACH_PRECHARGE
BMS_STATEMACH_e nextstate
#define BMS_TIME_WAIT_AFTERPRECHARGEFAIL
Time to wait in BMS_Trigger() calls after precharge opened because precharge failed.
static DATA_BLOCK_PACK_VALUES_s bms_tablePackValues
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
DATA_BLOCK_HEADER_s header
#define BMS_REQ_ID_STANDBY
#define BMS_NEXT_STRING_VOLTAGE_LIMIT_MV
Max voltage difference in mV between two strings to allow closing the next string.
uint8_t closedPrechargeContactors[BS_NR_OF_STRINGS]
Headers for the driver for the interlock.
@ BMS_TAKE_PRECHARGE_INTO_ACCCOUNT
@ BMS_STATEMACH_OPENCONTACTORS
#define BMS_TIME_WAIT_AFTER_CLOSING_PRECHARGE
uint8_t cellDischargeOvercurrent[BS_NR_OF_STRINGS]
STD_RETURN_TYPE_e MEAS_RequestOpenWireCheck(uint8_t string)
Makes the request to the MIC state machine to perform open-wire check.
#define POSITIVE_DISCHARGE_CURRENT
BMS_RETURN_TYPE_e BMS_SetStateRequest(BMS_STATE_REQUEST_e statereq)
sets the current state request of the state variable bms_state.
static uint8_t BMS_CheckCanRequests(void)
Checks the state requests made to the BMS state machine.
#define BMS_REQ_ID_CHARGE
BS_STRING_PRECHARGE_PRESENT_e bs_stringsWithPrecharge[BS_NR_OF_STRINGS]
int64_t MATH_AbsInt64(int64_t value)
Returns the absolute value of passed int64_t value.
@ BMS_PRECHARGE_OPEN_PRECHARGE
static uint8_t BMS_CheckReEntrance(void)
re-entrance check of SYS state machine trigger function
@ BAL_STATE_ALLOWBALANCING_REQUEST