foxBMS  1.3.0
The foxBMS Battery Management System API Documentation
bal.h File Reference

Header for the driver for balancing. More...

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

Go to the source code of this file.

Data Structures

struct  BAL_STATE_s
 

Enumerations

enum  BAL_STATEMACH_e {
  BAL_STATEMACH_UNINITIALIZED , BAL_STATEMACH_INITIALIZATION , BAL_STATEMACH_INITIALIZED , BAL_STATEMACH_CHECK_BALANCING ,
  BAL_STATEMACH_BALANCE , BAL_STATEMACH_NO_BALANCING , BAL_STATEMACH_ALLOWBALANCING , BAL_STATEMACH_GLOBALDISABLE ,
  BAL_STATEMACH_GLOBALENABLE , BAL_STATEMACH_UNDEFINED , BAL_STATEMACH_RESERVED1 , BAL_STATEMACH_ERROR
}
 
enum  BAL_STATEMACH_SUB_e {
  BAL_ENTRY , BAL_CHECK_IMBALANCES , BAL_COMPUTE_IMBALANCES , BAL_ACTIVATE_BALANCING ,
  BAL_CHECK_LOWEST_VOLTAGE , BAL_CHECK_CURRENT
}
 
enum  BAL_STATE_REQUEST_e {
  BAL_STATE_INIT_REQUEST , BAL_STATE_ERROR_REQUEST , BAL_STATE_NO_BALANCING_REQUEST , BAL_STATE_ALLOWBALANCING_REQUEST ,
  BAL_STATE_GLOBAL_DISABLE_REQUEST , BAL_STATE_GLOBAL_ENABLE_REQUEST , BAL_STATE_NO_REQUEST
}
 
enum  BAL_RETURN_TYPE_e {
  BAL_OK , BAL_BUSY_OK , BAL_REQUEST_PENDING , BAL_ILLEGAL_REQUEST ,
  BAL_INIT_ERROR , BAL_OK_FROM_ERROR , BAL_ERROR , BAL_ALREADY_INITIALIZED ,
  BAL_ILLEGAL_TASK_TYPE
}
 

Functions

void BAL_SaveLastStates (BAL_STATE_s *pBalancingState)
 Saves the last state and the last substate. More...
 
uint8_t BAL_CheckReEntrance (BAL_STATE_s *currentState)
 re-entrance check of BAL state machine trigger function More...
 
BAL_STATE_REQUEST_e BAL_TransferStateRequest (BAL_STATE_s *currentState)
 transfers the current state request to the state machine. More...
 
BAL_RETURN_TYPE_e BAL_CheckStateRequest (BAL_STATE_s *pCurrentState, BAL_STATE_REQUEST_e stateRequest)
 checks the state requests that are made. More...
 
void BAL_ProcessStateUninitalized (BAL_STATE_s *pCurrentState, BAL_STATE_REQUEST_e stateRequest)
 Substate handling function for BAL_Trigger() More...
 
void BAL_ProcessStateInitialization (BAL_STATE_s *currentState)
 State machine subfunction to initialize the balancing state machine. More...
 
void BAL_ProcessStateInitialized (BAL_STATE_s *currentState)
 State machine subfunction to transfer from an initalized state to "running" states of th state machine. More...
 
STD_RETURN_TYPE_e BAL_Init (DATA_BLOCK_BALANCING_CONTROL_s *pControl)
 Generic initialization function for the balancing module. More...
 
BAL_RETURN_TYPE_e BAL_SetStateRequest (BAL_STATE_REQUEST_e stateRequest)
 sets the current state request of the state variable bal_state. More...
 
STD_RETURN_TYPE_e BAL_GetInitializationState (void)
 gets the initialization state. More...
 
void BAL_Trigger (void)
 trigger function for the BAL driver state machine. More...
 

Detailed Description

Header for the driver for balancing.

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
BAL

Definition in file bal.h.

Enumeration Type Documentation

◆ BAL_RETURN_TYPE_e

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

Enumerator
BAL_OK 

BAL --> ok

BAL_BUSY_OK 

BAL busy

BAL_REQUEST_PENDING 

requested to be executed

BAL_ILLEGAL_REQUEST 

Request can not be executed

BAL_INIT_ERROR 

Error state: Source: Initialization

BAL_OK_FROM_ERROR 

Return from error --> ok

BAL_ERROR 

General error state

BAL_ALREADY_INITIALIZED 

Initialization of BAL already finished

BAL_ILLEGAL_TASK_TYPE 

Illegal

Definition at line 113 of file bal.h.

◆ BAL_STATE_REQUEST_e

State requests for the BAL statemachine

Enumerator
BAL_STATE_INIT_REQUEST 
BAL_STATE_ERROR_REQUEST 
BAL_STATE_NO_BALANCING_REQUEST 
BAL_STATE_ALLOWBALANCING_REQUEST 
BAL_STATE_GLOBAL_DISABLE_REQUEST 
BAL_STATE_GLOBAL_ENABLE_REQUEST 
BAL_STATE_NO_REQUEST 

default state: no request to the statemachine

Definition at line 100 of file bal.h.

◆ BAL_STATEMACH_e

States of the BAL state machine

Enumerator
BAL_STATEMACH_UNINITIALIZED 
BAL_STATEMACH_INITIALIZATION 
BAL_STATEMACH_INITIALIZED 
BAL_STATEMACH_CHECK_BALANCING 
BAL_STATEMACH_BALANCE 
BAL_STATEMACH_NO_BALANCING 
BAL_STATEMACH_ALLOWBALANCING 
BAL_STATEMACH_GLOBALDISABLE 
BAL_STATEMACH_GLOBALENABLE 
BAL_STATEMACH_UNDEFINED 

undefined state

BAL_STATEMACH_RESERVED1 

reserved state

BAL_STATEMACH_ERROR 

Error-State:

Definition at line 69 of file bal.h.

◆ BAL_STATEMACH_SUB_e

Substates of the BAL state machine

Enumerator
BAL_ENTRY 

Substate entry state

BAL_CHECK_IMBALANCES 

Check if balancing has been initialized

BAL_COMPUTE_IMBALANCES 

Compute imbalances

BAL_ACTIVATE_BALANCING 

Activated balancing resistors

BAL_CHECK_LOWEST_VOLTAGE 

Check if lowest voltage is still above limit

BAL_CHECK_CURRENT 

Check if current is still under limit

Definition at line 88 of file bal.h.

Function Documentation

◆ BAL_CheckReEntrance()

uint8_t BAL_CheckReEntrance ( BAL_STATE_s currentState)

re-entrance check of BAL 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. 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.

Returns
0 if no further instance of the function is active, 0xff otherwise

Definition at line 84 of file bal.c.

Here is the call graph for this function:

◆ BAL_CheckStateRequest()

BAL_RETURN_TYPE_e BAL_CheckStateRequest ( BAL_STATE_s pCurrentState,
BAL_STATE_REQUEST_e  stateRequest 
)

checks the state requests that are made.

This function checks the validity of the state requests. The results of the checked is returned immediately.

Parameters
pCurrentStatepointer to the current state
stateRequeststate request to be checked
Returns
result of the state request that was made

Definition at line 113 of file bal.c.

◆ BAL_GetInitializationState()

STD_RETURN_TYPE_e BAL_GetInitializationState ( void  )

gets the initialization state.

This function is used for getting the balancing initialization state

Returns
STD_OK if initialized, otherwise STD_NOT_OK

Definition at line 308 of file bal_strategy_history.c.

◆ BAL_Init()

Generic initialization function for the balancing module.

Definition at line 148 of file bal.c.

◆ BAL_ProcessStateInitialization()

void BAL_ProcessStateInitialization ( BAL_STATE_s currentState)

State machine subfunction to initialize the balancing state machine.

TODO

Definition at line 171 of file bal.c.

◆ BAL_ProcessStateInitialized()

void BAL_ProcessStateInitialized ( BAL_STATE_s currentState)

State machine subfunction to transfer from an initalized state to "running" states of th state machine.

TODO

Definition at line 179 of file bal.c.

◆ BAL_ProcessStateUninitalized()

void BAL_ProcessStateUninitalized ( BAL_STATE_s pCurrentState,
BAL_STATE_REQUEST_e  stateRequest 
)

Substate handling function for BAL_Trigger()

Parameters
pCurrentStatepointer to the current state
stateRequeststate request to set

Definition at line 157 of file bal.c.

◆ BAL_SaveLastStates()

void BAL_SaveLastStates ( BAL_STATE_s pBalancingState)

Saves the last state and the last substate.

Definition at line 70 of file bal.c.

◆ BAL_SetStateRequest()

BAL_RETURN_TYPE_e BAL_SetStateRequest ( BAL_STATE_REQUEST_e  stateRequest)

sets the current state request of the state variable bal_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 BAL_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
stateRequeststate request to set
Returns
current state request

Definition at line 312 of file bal_strategy_history.c.

Here is the call graph for this function:

◆ BAL_TransferStateRequest()

BAL_STATE_REQUEST_e BAL_TransferStateRequest ( BAL_STATE_s currentState)

transfers the current state request to the state machine.

This function takes the current state request from current state and transfers it to the state machine. It resets the value from to BAL_STATE_NO_REQUEST

Returns
current state request

Definition at line 100 of file bal.c.

Here is the call graph for this function:

◆ BAL_Trigger()

void BAL_Trigger ( void  )

trigger function for the BAL driver state machine.

This function contains the sequence of events in the BAL state machine. It must be called time-triggered, every 100 milliseconds.

Definition at line 326 of file bal_strategy_history.c.

Here is the call graph for this function: