foxBMS - Unit Tests
1.5.0
The foxBMS Unit Tests API Documentation
|
bms driver implementation More...
#include "bms.h"
#include "battery_cell_cfg.h"
#include "afe.h"
#include "bal.h"
#include "database.h"
#include "diag.h"
#include "foxmath.h"
#include "imd.h"
#include "led.h"
#include "meas.h"
#include "os.h"
#include "soa.h"
#include <stdbool.h>
#include <stdint.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 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. 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... | |
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. More... | |
static CONT_TYPE_e | BMS_GetSecondContactorToBeOpened (uint8_t stringNumber, CONT_TYPE_e firstOpenedContactorType) |
Get second string contactor that should be opened. 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 BMS 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... | |
BMS_RETURN_TYPE_e | TEST_BMS_CheckStateRequest (BMS_STATE_REQUEST_e statereq) |
BMS_STATE_REQUEST_e | TEST_BMS_TransferStateRequest (void) |
uint8_t | TEST_BMS_CheckReEntrance (void) |
uint8_t | TEST_BMS_CheckCanRequests (void) |
bool | TEST_BMS_IsAnyFatalErrorFlagSet (void) |
STD_RETURN_TYPE_e | TEST_BMS_IsBatterySystemStateOkay (void) |
void | TEST_BMS_GetMeasurementValues (void) |
void | TEST_BMS_CheckOpenSenseWire (void) |
STD_RETURN_TYPE_e | TEST_BMS_CheckPrecharge (uint8_t stringNumber, DATA_BLOCK_PACK_VALUES_s *pPackValues) |
uint8_t | TEST_BMS_GetHighestString (BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues) |
uint8_t | TEST_BMS_GetClosestString (BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues) |
uint8_t | TEST_BMS_GetLowestString (BMS_CONSIDER_PRECHARGE_e precharge, DATA_BLOCK_PACK_VALUES_s *pPackValues) |
int32_t | TEST_BMS_GetStringVoltageDifference (uint8_t string, DATA_BLOCK_PACK_VALUES_s *pPackValues) |
int32_t | TEST_BMS_GetAverageStringCurrent (DATA_BLOCK_PACK_VALUES_s *pPackValues) |
void | TEST_BMS_UpdateBatsysState (DATA_BLOCK_PACK_VALUES_s *pPackValues) |
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 406 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 334 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 564 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 |
Get first string contactor that should be opened depending on the actual current flow direction.
Check the mounting direction of the contactors and open the contactor that is mounted in the preferred current flow direction. Open the plus contactor first if, there is no contactor in preferred direction to the curren flow to open available. This may be either because both contactors are installed in the same direction or because the contactors are bidirectional.
stringNumber | string that will be opened |
flowDirection | current flow direction (charging or discharging) |
|
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 | ) |
|
static |
Get second string contactor that should be opened.
Mounting direction of the contactor does not need to be checked for the second contactor as the current has already been interrupted opening the first contactor.
stringNumber | string that will be opened |
firstOpenedContactorType | type of first contactor that has been opened |
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 634 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 446 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 465 of file bms.c.
|
static |
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 811 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 346 of file bms.c.
void BMS_Trigger | ( | void | ) |
trigger function for the BMS driver state machine.
This function contains the sequence of events in the BMS state machine. It must be called time-triggered, every 10 milliseconds. This function needs to be adapted to be adapted to the behavior the batter system shall provide to the target application.
Definition at line 825 of file bms.c.
|
static |
uint8_t TEST_BMS_CheckCanRequests | ( | void | ) |
void TEST_BMS_CheckOpenSenseWire | ( | void | ) |
STD_RETURN_TYPE_e TEST_BMS_CheckPrecharge | ( | uint8_t | stringNumber, |
DATA_BLOCK_PACK_VALUES_s * | pPackValues | ||
) |
uint8_t TEST_BMS_CheckReEntrance | ( | void | ) |
BMS_RETURN_TYPE_e TEST_BMS_CheckStateRequest | ( | BMS_STATE_REQUEST_e | statereq | ) |
int32_t TEST_BMS_GetAverageStringCurrent | ( | DATA_BLOCK_PACK_VALUES_s * | pPackValues | ) |
uint8_t TEST_BMS_GetClosestString | ( | BMS_CONSIDER_PRECHARGE_e | precharge, |
DATA_BLOCK_PACK_VALUES_s * | pPackValues | ||
) |
uint8_t TEST_BMS_GetHighestString | ( | BMS_CONSIDER_PRECHARGE_e | precharge, |
DATA_BLOCK_PACK_VALUES_s * | pPackValues | ||
) |
uint8_t TEST_BMS_GetLowestString | ( | BMS_CONSIDER_PRECHARGE_e | precharge, |
DATA_BLOCK_PACK_VALUES_s * | pPackValues | ||
) |
void TEST_BMS_GetMeasurementValues | ( | void | ) |
int32_t TEST_BMS_GetStringVoltageDifference | ( | uint8_t | string, |
DATA_BLOCK_PACK_VALUES_s * | pPackValues | ||
) |
bool TEST_BMS_IsAnyFatalErrorFlagSet | ( | void | ) |
STD_RETURN_TYPE_e TEST_BMS_IsBatterySystemStateOkay | ( | void | ) |
BMS_STATE_REQUEST_e TEST_BMS_TransferStateRequest | ( | void | ) |
void TEST_BMS_UpdateBatsysState | ( | DATA_BLOCK_PACK_VALUES_s * | pPackValues | ) |
|
static |
|
static |
|
static |
|
static |