foxBMS  1.1.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 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
 

Typedefs

typedef enum BMS_CURRENT_FLOW_STATE BMS_CURRENT_FLOW_STATE_e
 
typedef enum BMS_CHECK BMS_CHECK_e
 
typedef enum BMS_CONSIDER_PRECHARGE BMS_CONSIDER_PRECHARGE_e
 
typedef enum BMS_STATEMACH BMS_STATEMACH_e
 
typedef enum BMS_CANSTATE BMS_CANSTATE_e
 
typedef enum BMS_STATEMACH_SUB BMS_STATEMACH_SUB_e
 
typedef enum BMS_STATE_REQUEST BMS_STATE_REQUEST_e
 
typedef enum BMS_RETURN_TYPE BMS_RETURN_TYPE_e
 
typedef enum BMS_POWERLINE_TYPE BMS_POWERLINE_TYPE_e
 
typedef struct BMS_STATE BMS_STATE_s
 

Enumerations

enum  BMS_CURRENT_FLOW_STATE { BMS_CHARGING , BMS_DISCHARGING , BMS_RELAXATION , BMS_AT_REST }
 
enum  BMS_CHECK { BMS_CHECK_OK , BMS_CHECK_BUSY , BMS_CHECK_NOT_OK }
 
enum  BMS_CONSIDER_PRECHARGE { BMS_DO_NOT_TAKE_PRECHARGE_INTO_ACCCOUNT , BMS_TAKE_PRECHARGE_INTO_ACCCOUNT }
 
enum  BMS_STATEMACH {
  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 {
  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 {
  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_OPEN_INTERLOCK , BMS_CHECK_INTERLOCK_CLOSE_AFTER_ERROR , 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 { BMS_STATE_INIT_REQUEST , BMS_STATE_ERROR_REQUEST , BMS_STATE_NO_REQUEST }
 
enum  BMS_RETURN_TYPE {
  BMS_OK , BMS_BUSY_OK , BMS_REQUEST_PENDING , BMS_ILLEGAL_REQUEST ,
  BMS_ALREADY_INITIALIZED , BMS_ILLEGAL_TASK_TYPE
}
 
enum  BMS_POWERLINE_TYPE { BMS_PL_OPEN , BMS_PL_0 , BMS_PL_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...
 

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
2021-07-29 (date of last update)
Prefix
BMS

Definition in file bms.h.

Typedef Documentation

◆ BMS_CANSTATE_e

CAN states of the BMS state machine

◆ BMS_CHECK_e

typedef enum BMS_CHECK BMS_CHECK_e

Symbolic names for busyness of the syscontrol

◆ BMS_CONSIDER_PRECHARGE_e

Symbolic names to take precharge into account or not

◆ BMS_CURRENT_FLOW_STATE_e

Symbolic names for battery system state

◆ BMS_POWERLINE_TYPE_e

Powerline type (discharge or charge)

◆ BMS_RETURN_TYPE_e

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

◆ BMS_STATE_REQUEST_e

State requests for the BMS statemachine

◆ BMS_STATE_s

typedef struct BMS_STATE BMS_STATE_s

This structure contains all the variables relevant for the CONT state machine. The user can get the current state of the CONT state machine with this variable

◆ BMS_STATEMACH_e

States of the SYS state machine

◆ BMS_STATEMACH_SUB_e

Substates of the SYS state machine

Enumeration Type Documentation

◆ BMS_CANSTATE

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 104 of file bms.h.

◆ BMS_CHECK

enum BMS_CHECK

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 73 of file bms.h.

◆ BMS_CONSIDER_PRECHARGE

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 80 of file bms.h.

◆ BMS_CURRENT_FLOW_STATE

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 65 of file bms.h.

◆ BMS_POWERLINE_TYPE

Powerline type (discharge or charge)

Enumerator
BMS_PL_OPEN 
BMS_PL_0 
BMS_PL_1 

Definition at line 174 of file bms.h.

◆ BMS_RETURN_TYPE

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

Enumerator
BMS_OK 

CONT --> ok

BMS_BUSY_OK 

CONT under load --> ok

BMS_REQUEST_PENDING 

requested to be executed

BMS_ILLEGAL_REQUEST 

Request can not be executed

BMS_ALREADY_INITIALIZED 

Initialization of LTC already finished

BMS_ILLEGAL_TASK_TYPE 

Illegal

Definition at line 164 of file bms.h.

◆ BMS_STATE_REQUEST

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 155 of file bms.h.

◆ BMS_STATEMACH

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 86 of file bms.h.

◆ BMS_STATEMACH_SUB

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_OPEN_INTERLOCK 

Substate in error to open interlock after contactors have been opened

BMS_CHECK_INTERLOCK_CLOSE_AFTER_ERROR 

Substate in error to close interlock after all error flags were reset

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 119 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 1272 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 1276 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 1317 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 1299 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 1308 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 1321 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.

Remove statements below once interlock module is working

Remove statements above once interlock module is working

Definition at line 647 of file bms.c.

Here is the call graph for this function: