foxBMS - Unit Tests  1.3.0
The foxBMS Unit Tests API Documentation
bms.h File Reference

bms driver header More...

#include "battery_system_cfg.h"
#include "bms_cfg.h"
#include "database.h"
Include dependency graph for bms.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BMS_STATE_s
 

Enumerations

enum  BMS_CURRENT_FLOW_STATE_e { BMS_CHARGING , BMS_DISCHARGING , BMS_RELAXATION , BMS_AT_REST }
 
enum  BMS_CHECK_e { BMS_CHECK_OK , BMS_CHECK_BUSY , BMS_CHECK_NOT_OK }
 
enum  BMS_CONSIDER_PRECHARGE_e { BMS_DO_NOT_TAKE_PRECHARGE_INTO_ACCCOUNT , BMS_TAKE_PRECHARGE_INTO_ACCCOUNT }
 
enum  BMS_STATEMACH_e {
  BMS_STATEMACH_UNINITIALIZED , BMS_STATEMACH_INITIALIZATION , BMS_STATEMACH_INITIALIZED , BMS_STATEMACH_IDLE ,
  BMS_STATEMACH_OPENCONTACTORS , BMS_STATEMACH_STANDBY , BMS_STATEMACH_PRECHARGE , BMS_STATEMACH_NORMAL ,
  BMS_STATEMACH_DISCHARGE , BMS_STATEMACH_CHARGE , BMS_STATEMACH_ERROR , BMS_STATEMACH_UNDEFINED ,
  BMS_STATEMACH_RESERVED1
}
 
enum  BMS_CANSTATE_e {
  BMS_CANSTATE_UNINITIALIZED , BMS_CANSTATE_INITIALIZATION , BMS_CANSTATE_INITIALIZED , BMS_CANSTATE_IDLE ,
  BMS_CANSTATE_OPENCONTACTORS , BMS_CANSTATE_STANDBY , BMS_CANSTATE_PRECHARGE , BMS_CANSTATE_NORMAL ,
  BMS_CANSTATE_CHARGE , BMS_CANSTATE_ERROR
}
 
enum  BMS_STATEMACH_SUB_e {
  BMS_ENTRY , BMS_CHECK_ERROR_FLAGS_INTERLOCK , BMS_INTERLOCK_CHECKED , BMS_CHECK_STATE_REQUESTS ,
  BMS_CHECK_BALANCING_REQUESTS , BMS_CHECK_ERROR_FLAGS , BMS_CHECK_CONTACTOR_NORMAL_STATE , BMS_CHECK_CONTACTOR_CHARGE_STATE ,
  BMS_PRECHARGE_CLOSE_MINUS , BMS_PRECHARGE_CLOSE_PRECHARGE , BMS_PRECHARGE_CHECK_VOLTAGES , BMS_PRECHARGE_OPEN_PRECHARGE ,
  BMS_OPEN_FIRST_CONTACTOR , BMS_OPEN_SECOND_CONTACTOR_MINUS , BMS_OPEN_SECOND_CONTACTOR_PLUS , BMS_CLOSE_FIRST_STRING_PRECHARGE_STATE ,
  BMS_CHECK_CLOSE_FIRST_STRING_PRECHARGE_STATE , BMS_CHECK_ERROR_FLAGS_PRECHARGE , BMS_CHECK_ERROR_FLAGS_PRECHARGE_FIRST_STRING , BMS_PRECHARGE_CLOSE_NEXT_STRING ,
  BMS_CHECK_STRING_CLOSED , BMS_CHECK_ERROR_FLAGS_PRECHARGE_CLOSINGSTRINGS , BMS_CHECK_ERROR_FLAGS_CLOSINGPRECHARGE , BMS_NORMAL_CLOSE_NEXT_STRING ,
  BMS_OPEN_ALL_PRECHARGES , BMS_CHECK_ALL_PRECHARGES_OPEN , BMS_OPEN_STRINGS_ENTRY , BMS_OPEN_STRINGS ,
  BMS_CHECK_STRING_OPEN , BMS_OPEN_STRINGS_EXIT
}
 
enum  BMS_STATE_REQUEST_e { BMS_STATE_INIT_REQUEST , BMS_STATE_ERROR_REQUEST , BMS_STATE_NO_REQUEST }
 
enum  BMS_RETURN_TYPE_e { BMS_OK , BMS_REQUEST_PENDING , BMS_ILLEGAL_REQUEST , BMS_ALREADY_INITIALIZED }
 
enum  BMS_POWER_PATH_TYPE_e { BMS_POWER_PATH_OPEN , BMS_POWER_PATH_0 , BMS_POWER_PATH_1 }
 

Functions

BMS_RETURN_TYPE_e BMS_SetStateRequest (BMS_STATE_REQUEST_e statereq)
 sets the current state request of the state variable bms_state. More...
 
BMS_STATEMACH_e BMS_GetState (void)
 Returns the current state. More...
 
STD_RETURN_TYPE_e BMS_GetInitializationState (void)
 Gets the initialization 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...
 
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)
 
STD_RETURN_TYPE_e TEST_BMS_IsBatterySystemStateOkay (void)
 
bool TEST_BMS_IsAnyFatalErrorFlagSet (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)
 

Detailed Description

bms driver header

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:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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:

  • ″This product uses parts of foxBMS®″
  • ″This product includes parts of foxBMS®″
  • ″This product is derived from foxBMS®″
Author
foxBMS Team
Date
2020-02-24 (date of creation)
Updated
2022-05-30 (date of last update)
Version
v1.3.0
Prefix
BMS

Definition in file bms.h.

Enumeration Type Documentation

◆ BMS_CANSTATE_e

CAN states of the BMS state machine

Enumerator
BMS_CANSTATE_UNINITIALIZED 
BMS_CANSTATE_INITIALIZATION 
BMS_CANSTATE_INITIALIZED 
BMS_CANSTATE_IDLE 
BMS_CANSTATE_OPENCONTACTORS 
BMS_CANSTATE_STANDBY 
BMS_CANSTATE_PRECHARGE 
BMS_CANSTATE_NORMAL 
BMS_CANSTATE_CHARGE 
BMS_CANSTATE_ERROR 

Definition at line 105 of file bms.h.

◆ BMS_CHECK_e

Symbolic names for busyness of the syscontrol

Enumerator
BMS_CHECK_OK 

syscontrol ok

BMS_CHECK_BUSY 

syscontrol busy

BMS_CHECK_NOT_OK 

syscontrol not ok

Definition at line 74 of file bms.h.

◆ BMS_CONSIDER_PRECHARGE_e

Symbolic names to take precharge into account or not

Enumerator
BMS_DO_NOT_TAKE_PRECHARGE_INTO_ACCCOUNT 

do not take precharge into account

BMS_TAKE_PRECHARGE_INTO_ACCCOUNT 

do take precharge into account

Definition at line 81 of file bms.h.

◆ BMS_CURRENT_FLOW_STATE_e

Symbolic names for battery system state

Enumerator
BMS_CHARGING 

battery is charged

BMS_DISCHARGING 

battery is discharged

BMS_RELAXATION 

battery relaxation ongoing

BMS_AT_REST 

battery is resting

Definition at line 66 of file bms.h.

◆ BMS_POWER_PATH_TYPE_e

Power path type (discharge or charge)

Enumerator
BMS_POWER_PATH_OPEN 
BMS_POWER_PATH_0 
BMS_POWER_PATH_1 

Definition at line 171 of file bms.h.

◆ BMS_RETURN_TYPE_e

Possible return values when state requests are made to the BMS statemachine

Enumerator
BMS_OK 

request was successful

BMS_REQUEST_PENDING 

error: another request is currently processed

BMS_ILLEGAL_REQUEST 

error: request can not be executed

BMS_ALREADY_INITIALIZED 

error: BMS statemachine already initialized

Definition at line 163 of file bms.h.

◆ BMS_STATE_REQUEST_e

State requests for the BMS statemachine

Enumerator
BMS_STATE_INIT_REQUEST 

request for initialization

BMS_STATE_ERROR_REQUEST 

request for ERROR state

BMS_STATE_NO_REQUEST 

dummy request for no request

Definition at line 154 of file bms.h.

◆ BMS_STATEMACH_e

States of the SYS state machine

Enumerator
BMS_STATEMACH_UNINITIALIZED 
BMS_STATEMACH_INITIALIZATION 
BMS_STATEMACH_INITIALIZED 
BMS_STATEMACH_IDLE 
BMS_STATEMACH_OPENCONTACTORS 
BMS_STATEMACH_STANDBY 
BMS_STATEMACH_PRECHARGE 
BMS_STATEMACH_NORMAL 
BMS_STATEMACH_DISCHARGE 
BMS_STATEMACH_CHARGE 
BMS_STATEMACH_ERROR 
BMS_STATEMACH_UNDEFINED 
BMS_STATEMACH_RESERVED1 

Definition at line 87 of file bms.h.

◆ BMS_STATEMACH_SUB_e

Substates of the SYS state machine

Enumerator
BMS_ENTRY 

Substate entry state

BMS_CHECK_ERROR_FLAGS_INTERLOCK 

Substate check measurements after interlock closed

BMS_INTERLOCK_CHECKED 

Substate interlocked checked

BMS_CHECK_STATE_REQUESTS 

Substate check if there is a state request

BMS_CHECK_BALANCING_REQUESTS 

Substate check if there is a balancing request

BMS_CHECK_ERROR_FLAGS 

Substate check if any error flag set

BMS_CHECK_CONTACTOR_NORMAL_STATE 

Substate in precharge, check if there contactors reached normal

BMS_CHECK_CONTACTOR_CHARGE_STATE 

Substate in precharge, check if there contactors reached normal

BMS_PRECHARGE_CLOSE_MINUS 
BMS_PRECHARGE_CLOSE_PRECHARGE 
BMS_PRECHARGE_CHECK_VOLTAGES 
BMS_PRECHARGE_OPEN_PRECHARGE 
BMS_OPEN_FIRST_CONTACTOR 
BMS_OPEN_SECOND_CONTACTOR_MINUS 
BMS_OPEN_SECOND_CONTACTOR_PLUS 
BMS_CLOSE_FIRST_STRING_PRECHARGE_STATE 
BMS_CHECK_CLOSE_FIRST_STRING_PRECHARGE_STATE 
BMS_CHECK_ERROR_FLAGS_PRECHARGE 
BMS_CHECK_ERROR_FLAGS_PRECHARGE_FIRST_STRING 
BMS_PRECHARGE_CLOSE_NEXT_STRING 
BMS_CHECK_STRING_CLOSED 
BMS_CHECK_ERROR_FLAGS_PRECHARGE_CLOSINGSTRINGS 
BMS_CHECK_ERROR_FLAGS_CLOSINGPRECHARGE 
BMS_NORMAL_CLOSE_NEXT_STRING 
BMS_OPEN_ALL_PRECHARGES 
BMS_CHECK_ALL_PRECHARGES_OPEN 
BMS_OPEN_STRINGS_ENTRY 
BMS_OPEN_STRINGS 
BMS_CHECK_STRING_OPEN 
BMS_OPEN_STRINGS_EXIT 

Definition at line 120 of file bms.h.

Function Documentation

◆ BMS_GetBatterySystemState()

BMS_CURRENT_FLOW_STATE_e BMS_GetBatterySystemState ( void  )

Returns current battery system state (charging/discharging, resting or in relaxation phase)

Returns
BMS_CURRENT_FLOW_STATE_e

Definition at line 1274 of file bms.c.

◆ BMS_GetCurrentFlowDirection()

BMS_CURRENT_FLOW_STATE_e BMS_GetCurrentFlowDirection ( int32_t  current_mA)

Get current flow direction, current value as function parameter.

Parameters
[in]current_mAcurrent that is flowing
Returns
BMS_DISCHARGING or BMS_CHARGING depending on current direction. Return BMS_AT_REST. ((type: BMS_CURRENT_FLOW_STATE_e)

Definition at line 1278 of file bms.c.

◆ BMS_GetInitializationState()

STD_RETURN_TYPE_e BMS_GetInitializationState ( void  )

Gets the initialization state.

This function is used for getting the BMS initialization state.

Returns
STD_OK if initialized, otherwise STD_NOT_OK

Definition at line 625 of file bms.c.

◆ BMS_GetNumberOfConnectedStrings()

uint8_t BMS_GetNumberOfConnectedStrings ( void  )

Returns number of connected strings.

Returns
Returns number of connected strings

Definition at line 1320 of file bms.c.

◆ BMS_GetState()

BMS_STATEMACH_e BMS_GetState ( void  )

Returns the current state.

This function is used in the functioning of the SYS state machine.

Returns
current state, taken from BMS_STATEMACH_e

Definition at line 629 of file bms.c.

◆ BMS_IsStringClosed()

bool BMS_IsStringClosed ( uint8_t  stringNumber)

Returns string state (closed or open)

Parameters
[in]stringNumberstring addressed
Returns
false if string is open, true if string is closed

Definition at line 1302 of file bms.c.

◆ BMS_IsStringPrecharging()

bool BMS_IsStringPrecharging ( uint8_t  stringNumber)

Returns if string is currently precharging or not.

Parameters
[in]stringNumberstring addressed
Returns
false if precharge contactor is open, true if closed and string is precharging

Definition at line 1311 of file bms.c.

◆ BMS_IsTransitionToErrorStateActive()

bool BMS_IsTransitionToErrorStateActive ( void  )

Check if transition in to error state is active.

Returns
True, if transition into error state is ongoing, otherwise false

Definition at line 1324 of file bms.c.

◆ BMS_SetStateRequest()

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.

Parameters
statereqstate request to set
Returns
current state request

Definition at line 633 of file bms.c.

Here is the call graph for this function:

◆ BMS_Trigger()

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.

Definition at line 647 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_CheckCanRequests()

uint8_t TEST_BMS_CheckCanRequests ( void  )

Definition at line 1339 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_CheckOpenSenseWire()

void TEST_BMS_CheckOpenSenseWire ( void  )

Definition at line 1351 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_CheckPrecharge()

STD_RETURN_TYPE_e TEST_BMS_CheckPrecharge ( uint8_t  stringNumber,
DATA_BLOCK_PACK_VALUES_s pPackValues 
)

Definition at line 1354 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_CheckReEntrance()

uint8_t TEST_BMS_CheckReEntrance ( void  )

Definition at line 1336 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_CheckStateRequest()

BMS_RETURN_TYPE_e TEST_BMS_CheckStateRequest ( BMS_STATE_REQUEST_e  statereq)

Definition at line 1330 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_GetAverageStringCurrent()

int32_t TEST_BMS_GetAverageStringCurrent ( DATA_BLOCK_PACK_VALUES_s pPackValues)

Definition at line 1370 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_GetClosestString()

uint8_t TEST_BMS_GetClosestString ( BMS_CONSIDER_PRECHARGE_e  precharge,
DATA_BLOCK_PACK_VALUES_s pPackValues 
)

Definition at line 1360 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_GetHighestString()

uint8_t TEST_BMS_GetHighestString ( BMS_CONSIDER_PRECHARGE_e  precharge,
DATA_BLOCK_PACK_VALUES_s pPackValues 
)

Definition at line 1357 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_GetLowestString()

uint8_t TEST_BMS_GetLowestString ( BMS_CONSIDER_PRECHARGE_e  precharge,
DATA_BLOCK_PACK_VALUES_s pPackValues 
)

Definition at line 1364 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_GetMeasurementValues()

void TEST_BMS_GetMeasurementValues ( void  )

Definition at line 1348 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_GetStringVoltageDifference()

int32_t TEST_BMS_GetStringVoltageDifference ( uint8_t  string,
DATA_BLOCK_PACK_VALUES_s pPackValues 
)

Definition at line 1367 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_IsAnyFatalErrorFlagSet()

bool TEST_BMS_IsAnyFatalErrorFlagSet ( void  )

Definition at line 1342 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_IsBatterySystemStateOkay()

STD_RETURN_TYPE_e TEST_BMS_IsBatterySystemStateOkay ( void  )

Definition at line 1345 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_TransferStateRequest()

BMS_STATE_REQUEST_e TEST_BMS_TransferStateRequest ( void  )

Definition at line 1333 of file bms.c.

Here is the call graph for this function:

◆ TEST_BMS_UpdateBatsysState()

void TEST_BMS_UpdateBatsysState ( DATA_BLOCK_PACK_VALUES_s pPackValues)

Definition at line 1373 of file bms.c.

Here is the call graph for this function: