foxBMS
1.1.0
The foxBMS Battery Management System API Documentation
|
bms driver implementation More...
#include "bms.h"
#include "battery_cell_cfg.h"
#include "bal.h"
#include "contactor.h"
#include "database.h"
#include "diag.h"
#include "foxmath.h"
#include "interlock.h"
#include "meas.h"
#include "mic.h"
#include "os.h"
#include "soa.h"
Go to the source code of this file.
Macros | |
#define | BMS_NO_ACTIVE_DELAY_TIME_ms (UINT32_MAX) |
#define | BMS_SAVELASTSTATES() |
Functions | |
static BMS_RETURN_TYPE_e | BMS_CheckStateRequest (BMS_STATE_REQUEST_e statereq) |
checks the state requests that are made. More... | |
static BMS_STATE_REQUEST_e | BMS_TransferStateRequest (void) |
transfers the current state request to the state machine. More... | |
static uint8_t | BMS_CheckReEntrance (void) |
re-entrance check of SYS state machine trigger function More... | |
static uint8_t | BMS_CheckCanRequests (void) |
Checks the state requests made to the BMS state machine. More... | |
static bool | BMS_IsAnyFatalErrorFlagSet (void) |
Checks all the error flags from diagnosis module with a severity of DIAG_FATAL_ERROR. More... | |
static STD_RETURN_TYPE_e | BMS_IsBatterySystemStateOkay (void) |
Checks if any error flag is set and handles delay until contactors need to be opened. More... | |
static void | BMS_GetMeasurementValues (void) |
static void | BMS_CheckOpenSenseWire (void) |
Check for any open voltage sense wire. More... | |
static STD_RETURN_TYPE_e | BMS_CheckPrecharge (uint8_t stringNumber, const DATA_BLOCK_PACK_VALUES_s *pPackValues) |
Checks if the current limitations are violated. More... | |
static uint8_t | BMS_GetHighestString (BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues) |
Returns ID of string with highest total voltage. More... | |
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. More... | |
static uint8_t | BMS_GetLowestString (BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues) |
Returns ID of string with lowest total voltage. More... | |
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. More... | |
static int32_t | BMS_GetAverageStringCurrent (DATA_BLOCK_PACK_VALUES_s *pPackValues) |
Returns the average current flowing through all strings. More... | |
static void | BMS_UpdateBatsysState (DATA_BLOCK_PACK_VALUES_s *pPackValues) |
Updates battery system state variable depending on measured/recent current values. More... | |
STD_RETURN_TYPE_e | BMS_GetInitializationState (void) |
Gets the initialization state. More... | |
BMS_STATEMACH_e | BMS_GetState (void) |
Returns the current state. More... | |
BMS_RETURN_TYPE_e | BMS_SetStateRequest (BMS_STATE_REQUEST_e statereq) |
sets the current state request of the state variable bms_state. More... | |
void | BMS_Trigger (void) |
trigger function for the SYS driver state machine. More... | |
BMS_CURRENT_FLOW_STATE_e | BMS_GetBatterySystemState (void) |
Returns current battery system state (charging/discharging, resting or in relaxation phase) More... | |
BMS_CURRENT_FLOW_STATE_e | BMS_GetCurrentFlowDirection (int32_t current_mA) |
Get current flow direction, current value as function parameter. More... | |
bool | BMS_IsStringClosed (uint8_t stringNumber) |
Returns string state (closed or open) More... | |
bool | BMS_IsStringPrecharging (uint8_t stringNumber) |
Returns if string is currently precharging or not. More... | |
uint8_t | BMS_GetNumberOfConnectedStrings (void) |
Returns number of connected strings. More... | |
bool | BMS_IsTransitionToErrorStateActive (void) |
Check if transition in to error state is active. More... | |
Variables | |
static BMS_STATE_s | bms_state |
static DATA_BLOCK_MIN_MAX_s | bms_tableMinMax = {.header.uniqueId = DATA_BLOCK_ID_MIN_MAX} |
static DATA_BLOCK_OPEN_WIRE_s | bms_tableOpenWire = {.header.uniqueId = DATA_BLOCK_ID_OPEN_WIRE_BASE} |
static DATA_BLOCK_PACK_VALUES_s | bms_tablePackValues = {.header.uniqueId = DATA_BLOCK_ID_PACK_VALUES} |
bms driver implementation
SPDX-License-Identifier: BSD-3-Clause
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:
Definition in file bms.c.
#define BMS_NO_ACTIVE_DELAY_TIME_ms (UINT32_MAX) |
#define BMS_SAVELASTSTATES | ( | ) |
Saves the last state and the last substate
|
static |
|
static |
|
static |
Checks if the current limitations are violated.
[in] | stringNumber | string addressed |
[in] | pPackValues | pointer to pack values database entry |
Definition at line 364 of file bms.c.
|
static |
re-entrance check of SYS state machine trigger function
This function is not re-entrant and should only be called time- or event-triggered. It increments the triggerentry counter from the state variable ltc_state. It should never be called by two different processes, so if it is the case, triggerentry should never be higher than 0 when this function is called.
Definition at line 292 of file bms.c.
|
static |
|
static |
Returns the average current flowing through all strings.
This function is used when closing strings.
[in] | pPackValues | pointer to pack values database entry |
BMS_CURRENT_FLOW_STATE_e BMS_GetBatterySystemState | ( | void | ) |
Returns current battery system state (charging/discharging, resting or in relaxation phase)
|
static |
Returns ID of string with voltage closest to first closed string voltage.
This is used to close further strings in drive.
[in] | precharge | If BMS_DO_NOT_TAKE_PRECHARGE_INTO_ACCCOUNT, precharge availability for string is ignored. if BMS_TAKE_PRECHARGE_INTO_ACCCOUNT, only select string that has precharge available. |
[in] | pPackValues | pointer to pack values database entry |
Definition at line 477 of file bms.c.
BMS_CURRENT_FLOW_STATE_e BMS_GetCurrentFlowDirection | ( | int32_t | current_mA | ) |
Get current flow direction, current value as function parameter.
[in] | current_mA | current that is flowing |
|
static |
Returns ID of string with highest total voltage.
This is used to close the first string when drive-off is requested.
[in] | precharge | If BMS_DO_NOT_TAKE_PRECHARGE_INTO_ACCCOUNT, precharge availability for string is ignored. if BMS_TAKE_PRECHARGE_INTO_ACCCOUNT, only select string that has precharge available. |
[in] | pPackValues | pointer to pack values database entry |
STD_RETURN_TYPE_e BMS_GetInitializationState | ( | void | ) |
Gets the initialization state.
This function is used for getting the BMS initialization state.
|
static |
Returns ID of string with lowest total voltage.
This is used to close the first string when charge-off is requested.
[in] | precharge | If 0, precharge availability for string is ignored. If 1, only selects a string that has precharge available. |
[in] | pPackValues | pointer to pack values database entry |
|
static |
uint8_t BMS_GetNumberOfConnectedStrings | ( | void | ) |
BMS_STATEMACH_e BMS_GetState | ( | void | ) |
|
static |
Returns voltage difference between first closed string and string ID.
This function is used to check voltage when trying to close further strings.
[in] | string | ID of string that must be compared with first closed string |
[in] | pPackValues | pointer to pack values database entry |
Definition at line 547 of file bms.c.
|
static |
Checks all the error flags from diagnosis module with a severity of DIAG_FATAL_ERROR.
Checks all the error flags from diagnosis module with a severity of DIAG_FATAL_ERROR. Furthermore, sets parameter minimumActiveDelay_ms of bms_state variable.
Definition at line 390 of file bms.c.
|
static |
Checks if any error flag is set and handles delay until contactors need to be opened.
Checks all the diagnosis entries with severity of DIAG_FATAL_ERROR and handles the configured delay until the contactors need to be opened. The shortest delay is used, if multiple errors are active at once.
Check if a fatal error has been detected previously. If yes, check delay
Set previous timestamp for next call
Definition at line 409 of file bms.c.
bool BMS_IsStringClosed | ( | uint8_t | stringNumber | ) |
bool BMS_IsStringPrecharging | ( | uint8_t | stringNumber | ) |
bool BMS_IsTransitionToErrorStateActive | ( | void | ) |
BMS_RETURN_TYPE_e BMS_SetStateRequest | ( | BMS_STATE_REQUEST_e | statereq | ) |
sets the current state request of the state variable bms_state.
This function is used to make a state request to the state machine, e.g, start voltage measurement, read result of voltage measurement, re-initialization. It calls BMS_CheckStateRequest() to check if the request is valid. The state request is rejected if is not valid. The result of the check is returned immediately, so that the requester can act in case it made a non-valid state request.
statereq | state request to set |
Definition at line 633 of file bms.c.
|
static |
transfers the current state request to the state machine.
This function takes the current state request from bms_state transfers it to the state machine. It resets the value from bms_state to BMS_STATE_NO_REQUEST
Definition at line 304 of file bms.c.
void BMS_Trigger | ( | void | ) |
trigger function for the SYS driver state machine.
This function contains the sequence of events in the SYS state machine. It must be called time-triggered, every 10 milliseconds.
Remove statements below once interlock module is working
Remove statements above once interlock module is working
Definition at line 647 of file bms.c.
|
static |
|
static |
contains the state of the bms state machine
|
static |
|
static |
|
static |