foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
bms.h File Reference

bms driver header More...

#include "battery_system_cfg.h"
#include "bms_cfg.h"
#include "contactor.h"
#include "fstd_types.h"
#include <stdbool.h>
#include <stdint.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_OPEN_CONTACTORS , 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_PRECHARGE_CHECK_OPEN_PRECHARGE , BMS_OPEN_FIRST_CONTACTOR , BMS_OPEN_SECOND_CONTACTOR_MINUS , BMS_OPEN_SECOND_CONTACTOR_PLUS ,
  BMS_CHECK_CLOSE_SECOND_STRING_CONTACTOR_PRECHARGE_STATE , BMS_CHECK_ERROR_FLAGS_PRECHARGE , BMS_CHECK_ERROR_FLAGS_PRECHARGE_FIRST_STRING , BMS_PRECHARGE_CLOSE_NEXT_STRING ,
  BMS_CLOSE_SECOND_CONTACTOR_PLUS , BMS_CHECK_STRING_CLOSED , BMS_CHECK_ERROR_FLAGS_PRECHARGE_CLOSINGSTRINGS , BMS_CHECK_ERROR_FLAGS_CLOSINGPRECHARGE ,
  BMS_NORMAL_CLOSE_NEXT_STRING , BMS_NORMAL_CLOSE_SECOND_STRING_CONTACTOR , BMS_OPEN_ALL_PRECHARGES , BMS_CHECK_ALL_PRECHARGES_OPEN ,
  BMS_OPEN_STRINGS_ENTRY , BMS_OPEN_FIRST_STRING_CONTACTOR , BMS_OPEN_SECOND_STRING_CONTACTOR , BMS_CHECK_SECOND_STRING_CONTACTOR ,
  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 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...
 

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
2023-10-12 (date of last update)
Version
v1.6.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 111 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 80 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 87 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 72 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 178 of file bms.h.

◆ BMS_RETURN_TYPE_e

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

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 state machine already initialized

Definition at line 170 of file bms.h.

◆ BMS_STATE_REQUEST_e

State requests for the BMS state machine

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 163 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_OPEN_CONTACTORS 
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 93 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_PRECHARGE_CHECK_OPEN_PRECHARGE 
BMS_OPEN_FIRST_CONTACTOR 
BMS_OPEN_SECOND_CONTACTOR_MINUS 
BMS_OPEN_SECOND_CONTACTOR_PLUS 
BMS_CHECK_CLOSE_SECOND_STRING_CONTACTOR_PRECHARGE_STATE 
BMS_CHECK_ERROR_FLAGS_PRECHARGE 
BMS_CHECK_ERROR_FLAGS_PRECHARGE_FIRST_STRING 
BMS_PRECHARGE_CLOSE_NEXT_STRING 
BMS_CLOSE_SECOND_CONTACTOR_PLUS 
BMS_CHECK_STRING_CLOSED 
BMS_CHECK_ERROR_FLAGS_PRECHARGE_CLOSINGSTRINGS 
BMS_CHECK_ERROR_FLAGS_CLOSINGPRECHARGE 
BMS_NORMAL_CLOSE_NEXT_STRING 
BMS_NORMAL_CLOSE_SECOND_STRING_CONTACTOR 
BMS_OPEN_ALL_PRECHARGES 
BMS_CHECK_ALL_PRECHARGES_OPEN 
BMS_OPEN_STRINGS_ENTRY 
BMS_OPEN_FIRST_STRING_CONTACTOR 
BMS_OPEN_SECOND_STRING_CONTACTOR 
BMS_CHECK_SECOND_STRING_CONTACTOR 
BMS_OPEN_STRINGS_EXIT 

Definition at line 126 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 1586 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 1590 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 803 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 1632 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 807 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 1614 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 1623 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 1636 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 811 of file bms.c.

Here is the call graph for this function:

◆ BMS_Trigger()

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.

Here is the call graph for this function: