foxBMS  1.1.1
The foxBMS Battery Management System API Documentation
state-machine.c File Reference

Implementation of some driver that needs a state machine. More...

#include "state-machine.h"
Include dependency graph for state-machine.c:

Go to the source code of this file.

Macros

#define EG_FSM_SHORT_TIME   (1u)
 
#define EG_FSM_MEDIUM_TIME   (5u)
 
#define EG_FSM_LONG_TIME   (10u)
 

Typedefs

typedef enum EG_CHECK_MULTIPLE_CALLS EG_CHECK_MULTIPLE_CALLS_e
 

Enumerations

enum  EG_CHECK_MULTIPLE_CALLS { EG_MULTIPLE_CALLS_NO , EG_MULTIPLE_CALLS_YES }
 

Functions

static EG_CHECK_MULTIPLE_CALLS_e EG_CheckMultipleCalls (EG_STATE_s *pEgState)
 check for multiple calls of state machine trigger function More...
 
static void EG_SetState (EG_STATE_s *pEgState, EG_FSM_STATES_e nextState, EG_FSM_SUBSTATES_e nextSubstate, uint16_t idleTime)
 Sets the next state, the next substate and the timer value of the state variable. More...
 
static void EG_SetSubstate (EG_STATE_s *pEgState, EG_FSM_SUBSTATES_e nextSubstate, uint16_t idleTime)
 Sets the next substate and the timer value of the state variable. More...
 
static bool EG_SomeInitializationFunction0 (void)
 dummy function for initialization substate EG_FSM_SUBSTATE_INITIALIZATION_0 More...
 
static bool EG_SomeInitializationFunction1 (void)
 dummy function for initialization substate EG_FSM_SUBSTATE_INITIALIZATION_1 More...
 
static bool EG_SomeInitializationFunctionExit (void)
 dummy function to check if the initialization step of the state machine was successful (EG_FSM_SUBSTATE_INITIALIZATION_1) More...
 
static bool EG_SomeRunningFunction0 (void)
 dummy function making a test to determine the outcome of substate EG_FSM_SUBSTATE_RUNNING_0 More...
 
static bool EG_SomeRunningFunction1 (void)
 dummy function making a test to determine the outcome of substate EG_FSM_SUBSTATE_RUNNING_1 More...
 
static bool EG_SomeRunningFunction2 (void)
 dummy function making a test to determine the outcome of substate EG_FSM_SUBSTATE_RUNNING_2 More...
 
static EG_FSM_STATES_e EG_ProcessInitializationState (EG_STATE_s *pEgState)
 Processes the initialization state. More...
 
static EG_FSM_STATES_e EG_ProcessRunningState (EG_STATE_s *pEgState)
 Processes the running state. More...
 
static STD_RETURN_TYPE_e EG_RunStateMachine (EG_STATE_s *pEgState)
 Defines the state transitions. More...
 
STD_RETURN_TYPE_e EG_Trigger (EG_STATE_s *pEgState)
 tick function, call this to advance the state machine More...
 

Variables

EG_STATE_s eg_state
 

Detailed Description

Implementation of some driver that needs a state machine.

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-10-29 (date of creation)
Updated
2020-11-09 (date of last update)
Prefix
EG

Definition in file state-machine.c.

Macro Definition Documentation

◆ EG_FSM_LONG_TIME

#define EG_FSM_LONG_TIME   (10u)

statemachine long time definition in EG_Trigger calls until next state/substate is processed

Definition at line 74 of file state-machine.c.

◆ EG_FSM_MEDIUM_TIME

#define EG_FSM_MEDIUM_TIME   (5u)

statemachine medium time definition in EG_Trigger calls until next state/substate is processed

Definition at line 68 of file state-machine.c.

◆ EG_FSM_SHORT_TIME

#define EG_FSM_SHORT_TIME   (1u)

statemachine short time definition in EG_Trigger calls until next state is processed

Definition at line 62 of file state-machine.c.

Typedef Documentation

◆ EG_CHECK_MULTIPLE_CALLS_e

Symbolic names to check for multiple calls of EG_Trigger

Enumeration Type Documentation

◆ EG_CHECK_MULTIPLE_CALLS

Symbolic names to check for multiple calls of EG_Trigger

Enumerator
EG_MULTIPLE_CALLS_NO 

no multiple calls, OK

EG_MULTIPLE_CALLS_YES 

multiple calls, not OK

Definition at line 77 of file state-machine.c.

Function Documentation

◆ EG_CheckMultipleCalls()

static EG_CHECK_MULTIPLE_CALLS_e EG_CheckMultipleCalls ( EG_STATE_s pEgState)
static

check for multiple calls of state machine trigger function

The trigger function is not reentrant, which means it cannot be called multiple times. This functions increments the triggerEntry counter once and must be called each time the trigger function is called. If triggerEntry is greater than one, there were multiple calls. For this function to work, triggerEntry must be decremented each time the trigger function is called, even if no processing do because the timer is non-zero.

Parameters
pEgStatestate of the fake state machine
Returns
EG_MULTIPLE_CALLS_YES if there were multiple calls, EG_MULTIPLE_CALLS_NO otherwise

Definition at line 211 of file state-machine.c.

Here is the call graph for this function:

◆ EG_ProcessInitializationState()

static EG_FSM_STATES_e EG_ProcessInitializationState ( EG_STATE_s pEgState)
static

Processes the initialization state.

Parameters
pEgStatestate of the example state machine
Returns
Always STD_OK

Definition at line 291 of file state-machine.c.

Here is the call graph for this function:

◆ EG_ProcessRunningState()

static EG_FSM_STATES_e EG_ProcessRunningState ( EG_STATE_s pEgState)
static

Processes the running state.

Parameters
pEgStatestate of the example state machine
Returns
Always STD_OK

Definition at line 334 of file state-machine.c.

Here is the call graph for this function:

◆ EG_RunStateMachine()

static STD_RETURN_TYPE_e EG_RunStateMachine ( EG_STATE_s pEgState)
static

Defines the state transitions.

This function contains the implementation of the state machine, i.e., the sequence of states and substates. It is called by the trigger function every time the state machine timer has a non-zero value.

Parameters
pEgStatestate of the example state machine
Returns
Always STD_OK

Definition at line 377 of file state-machine.c.

Here is the call graph for this function:

◆ EG_SetState()

static void EG_SetState ( EG_STATE_s pEgState,
EG_FSM_STATES_e  nextState,
EG_FSM_SUBSTATES_e  nextSubstate,
uint16_t  idleTime 
)
static

Sets the next state, the next substate and the timer value of the state variable.

Parameters
pEgStatestate of the example state machine
nextStatestate to be transferred into
nextSubstatesubstate to be transferred into
idleTimewait time for the state machine

Definition at line 224 of file state-machine.c.

Here is the call graph for this function:

◆ EG_SetSubstate()

static void EG_SetSubstate ( EG_STATE_s pEgState,
EG_FSM_SUBSTATES_e  nextSubstate,
uint16_t  idleTime 
)
static

Sets the next substate and the timer value of the state variable.

Parameters
pEgStatestate of the example state machine
nextSubstatesubstate to be transferred into
idleTimewait time for the state machine

Definition at line 259 of file state-machine.c.

◆ EG_SomeInitializationFunction0()

static bool EG_SomeInitializationFunction0 ( void  )
static

dummy function for initialization substate EG_FSM_SUBSTATE_INITIALIZATION_0

Returns
returns always true

Definition at line 267 of file state-machine.c.

◆ EG_SomeInitializationFunction1()

static bool EG_SomeInitializationFunction1 ( void  )
static

dummy function for initialization substate EG_FSM_SUBSTATE_INITIALIZATION_1

Returns
returns always true

Definition at line 271 of file state-machine.c.

◆ EG_SomeInitializationFunctionExit()

static bool EG_SomeInitializationFunctionExit ( void  )
static

dummy function to check if the initialization step of the state machine was successful (EG_FSM_SUBSTATE_INITIALIZATION_1)

Returns
returns always true

Definition at line 275 of file state-machine.c.

◆ EG_SomeRunningFunction0()

static bool EG_SomeRunningFunction0 ( void  )
static

dummy function making a test to determine the outcome of substate EG_FSM_SUBSTATE_RUNNING_0

Returns
returns always true

Definition at line 279 of file state-machine.c.

◆ EG_SomeRunningFunction1()

static bool EG_SomeRunningFunction1 ( void  )
static

dummy function making a test to determine the outcome of substate EG_FSM_SUBSTATE_RUNNING_1

Returns
returns always true

Definition at line 283 of file state-machine.c.

◆ EG_SomeRunningFunction2()

static bool EG_SomeRunningFunction2 ( void  )
static

dummy function making a test to determine the outcome of substate EG_FSM_SUBSTATE_RUNNING_2

Returns
returns always true

Definition at line 287 of file state-machine.c.

◆ EG_Trigger()

STD_RETURN_TYPE_e EG_Trigger ( EG_STATE_s pEgState)

tick function, call this to advance the state machine

Parameters
pEgStatecurrent state of the state machine
Returns
returns always STD_OK

Definition at line 435 of file state-machine.c.

Here is the call graph for this function:

Variable Documentation

◆ eg_state

EG_STATE_s eg_state
Initial value:
= {
.timer = 0,
.triggerEntry = 0,
.currentState = EG_FSM_STATE_HAS_NEVER_RUN,
.previousState = EG_FSM_STATE_HAS_NEVER_RUN,
.nextSubstate = EG_FSM_SUBSTATE_DUMMY,
.currentSubstate = EG_FSM_SUBSTATE_DUMMY,
.previousSubstate = EG_FSM_SUBSTATE_DUMMY,
.information.r0 = 0,
.information.r1 = 0,
.information.r2 = 0,
}
@ EG_FSM_STATE_HAS_NEVER_RUN
Definition: state-machine.h:64
@ EG_FSM_SUBSTATE_DUMMY
Definition: state-machine.h:73

local instance of the driver-state

Definition at line 87 of file state-machine.c.