foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
imd.c File Reference

Main driver state machine for insulation monitoring driver. More...

#include "imd.h"
#include "diag.h"
#include "os.h"
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for imd.c:

Go to the source code of this file.

Data Structures

struct  IMD_INFORMATION_s
 
struct  IMD_STATE_s
 

Macros

#define IMD_FSM_SHORT_TIME   (1u)
 

Enumerations

enum  IMD_FSM_SUBSTATES_e {
  IMD_FSM_SUBSTATE_DUMMY , IMD_FSM_SUBSTATE_ENTRY , IMD_FSM_SUBSTATE_INITIALIZATION_0 , IMD_FSM_SUBSTATE_INITIALIZATION_1 ,
  IMD_FSM_SUBSTATE_INITIALIZATION_EXIT , IMD_FSM_SUBSTATE_RUNNING_0 , IMD_FSM_SUBSTATE_RUNNING_1 , IMD_FSM_SUBSTATE_RUNNING_2
}
 
enum  IMD_CHECK_MULTIPLE_CALLS_e { IMD_MULTIPLE_CALLS_NO , IMD_MULTIPLE_CALLS_YES }
 

Functions

static IMD_RETURN_TYPE_e IMD_SetStateRequest (IMD_STATE_s *pImdState, IMD_STATE_REQUEST_e stateRequest)
 sets the current state request of the state variable imd_state. More...
 
static IMD_RETURN_TYPE_e IMD_CheckStateRequest (IMD_STATE_s *pImdState, IMD_STATE_REQUEST_e stateRequest)
 checks the state requests that are made. More...
 
static IMD_STATE_REQUEST_e IMD_TransferStateRequest (IMD_STATE_s *pImdState)
 transfers the current state request to the state machine. More...
 
static IMD_CHECK_MULTIPLE_CALLS_e IMD_CheckMultipleCalls (IMD_STATE_s *pImdState)
 check for multiple calls of state machine trigger function More...
 
static void IMD_SetState (IMD_STATE_s *pImdState, IMD_FSM_STATES_e nextState, IMD_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 IMD_SetSubstate (IMD_STATE_s *pImdState, IMD_FSM_SUBSTATES_e nextSubstate, uint16_t idleTime)
 Sets the next substate and the timer value of the state variable. More...
 
static STD_RETURN_TYPE_e IMD_RunStateMachine (IMD_STATE_s *pImdState)
 Defines the state transitions. More...
 
static STD_RETURN_TYPE_e IMD_EvaluateInsulationMeasurement (DATA_BLOCK_INSULATION_MONITORING_s *pTableInsulationMonitoring)
 Evaluates measurement perform by IMD driver. More...
 
IMD_RETURN_TYPE_e IMD_RequestInitialization (void)
 Request initialization of IMD state machine. More...
 
IMD_RETURN_TYPE_e IMD_RequestInsulationMeasurement (void)
 Request to activate the actual IMD measurement. More...
 
IMD_RETURN_TYPE_e IMD_RequestMeasurementStop (void)
 Request to deactivate the actual IMD measurement. More...
 
bool IMD_GetInitializationState (void)
 Gets the initialization state. More...
 
STD_RETURN_TYPE_e IMD_Trigger (void)
 trigger function for the IMD driver state machine. More...
 

Variables

static DATA_BLOCK_INSULATION_MONITORING_s imd_tableInsulationMonitoring
 
static IMD_STATE_s imd_state
 

Detailed Description

Main driver state machine for insulation monitoring driver.

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
2021-11-04 (date of creation)
Updated
2023-10-12 (date of last update)
Version
v1.6.0
Prefix
IMD

This superimposed state machine initializes, enables and disables the selected Insulation Monitoring Device. Furthermore, the measurement results are evaluated and saved in the database. Requests are used to control the IMD state machine and with that the behavior of the IMDs.

Definition in file imd.c.

Macro Definition Documentation

◆ IMD_FSM_SHORT_TIME

#define IMD_FSM_SHORT_TIME   (1u)

state machine short time definition in IMD_Trigger calls until next state is processed

Definition at line 75 of file imd.c.

Enumeration Type Documentation

◆ IMD_CHECK_MULTIPLE_CALLS_e

Symbolic names to check for multiple calls of IMD_Trigger

Enumerator
IMD_MULTIPLE_CALLS_NO 

no multiple calls, OK

IMD_MULTIPLE_CALLS_YES 

multiple calls, not OK

Definition at line 90 of file imd.c.

◆ IMD_FSM_SUBSTATES_e

Substates of the state machine

Enumerator
IMD_FSM_SUBSTATE_DUMMY 

dummy state - always the first substate

IMD_FSM_SUBSTATE_ENTRY 

entry state - always the second substate

IMD_FSM_SUBSTATE_INITIALIZATION_0 

fist initialization substate

IMD_FSM_SUBSTATE_INITIALIZATION_1 

second initialization substate

IMD_FSM_SUBSTATE_INITIALIZATION_EXIT 

last initialization substate

IMD_FSM_SUBSTATE_RUNNING_0 

fist running substate

IMD_FSM_SUBSTATE_RUNNING_1 

second running substate

IMD_FSM_SUBSTATE_RUNNING_2 

third running substate

Definition at line 78 of file imd.c.

Function Documentation

◆ IMD_CheckMultipleCalls()

static IMD_CHECK_MULTIPLE_CALLS_e IMD_CheckMultipleCalls ( IMD_STATE_s pImdState)
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
[in,out]pImdStatepointer to state variable of IMD state machine
Returns
IMD_MULTIPLE_CALLS_YES if there were multiple calls, IMD_MULTIPLE_CALLS_NO otherwise

Definition at line 290 of file imd.c.

Here is the call graph for this function:

◆ IMD_CheckStateRequest()

static IMD_RETURN_TYPE_e IMD_CheckStateRequest ( IMD_STATE_s pImdState,
IMD_STATE_REQUEST_e  stateRequest 
)
static

checks the state requests that are made.

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

Parameters
[in]stateRequeststate request to be checked
[in,out]pImdStatepointer to state variable of IMD state machine
Returns
result of the state request that was made

Definition at line 252 of file imd.c.

◆ IMD_EvaluateInsulationMeasurement()

static STD_RETURN_TYPE_e IMD_EvaluateInsulationMeasurement ( DATA_BLOCK_INSULATION_MONITORING_s pTableInsulationMonitoring)
static

Evaluates measurement perform by IMD driver.

This function evaluates the insulation measurement performed by the selected IMD driver and updates the database entry.

Parameters
[in,out]pTableInsulationMonitoringpointer to insulation monitoring database entry
Returns
Always IMD_REQUEST_OK

Definition at line 461 of file imd.c.

Here is the call graph for this function:

◆ IMD_GetInitializationState()

bool IMD_GetInitializationState ( void  )

Gets the initialization state.

This function is used for getting the IMD initialization state.

Returns
true if state machine initialized, otherwise false

Definition at line 524 of file imd.c.

◆ IMD_RequestInitialization()

IMD_RETURN_TYPE_e IMD_RequestInitialization ( void  )

Request initialization of IMD state machine.

Returns
Always IMD_REQUEST_OK

Definition at line 512 of file imd.c.

Here is the call graph for this function:

◆ IMD_RequestInsulationMeasurement()

IMD_RETURN_TYPE_e IMD_RequestInsulationMeasurement ( void  )

Request to activate the actual IMD measurement.

Returns
Always IMD_REQUEST_OK

Definition at line 516 of file imd.c.

Here is the call graph for this function:

◆ IMD_RequestMeasurementStop()

IMD_RETURN_TYPE_e IMD_RequestMeasurementStop ( void  )

Request to deactivate the actual IMD measurement.

Returns
Always IMD_REQUEST_OK

Definition at line 520 of file imd.c.

Here is the call graph for this function:

◆ IMD_RunStateMachine()

static STD_RETURN_TYPE_e IMD_RunStateMachine ( IMD_STATE_s pImdState)
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
[in,out]pImdStatestate of the example state machine
Returns
Always STD_OK

Definition at line 351 of file imd.c.

Here is the call graph for this function:

◆ IMD_SetState()

static void IMD_SetState ( IMD_STATE_s pImdState,
IMD_FSM_STATES_e  nextState,
IMD_FSM_SUBSTATES_e  nextSubstate,
uint16_t  idleTime 
)
static

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

Parameters
[in,out]pImdStatestate of the example state machine
[in]nextStatestate to be transferred into
[in]nextSubstatesubstate to be transferred into
[in]idleTimewait time for the state machine

Definition at line 303 of file imd.c.

Here is the call graph for this function:

◆ IMD_SetStateRequest()

static IMD_RETURN_TYPE_e IMD_SetStateRequest ( IMD_STATE_s pImdState,
IMD_STATE_REQUEST_e  stateRequest 
)
static

sets the current state request of the state variable imd_state.

This function is used to make a state request to the state machine, e.g, initialize state machine or shut-down state machine. It calls IMD_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
[in]stateRequeststate request to set
[in,out]pImdStatepointer to state variable of IMD state machine
Returns
OK if request has been accepted, otherwise error reason

Definition at line 236 of file imd.c.

Here is the call graph for this function:

◆ IMD_SetSubstate()

static void IMD_SetSubstate ( IMD_STATE_s pImdState,
IMD_FSM_SUBSTATES_e  nextSubstate,
uint16_t  idleTime 
)
static

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

Parameters
[in,out]pImdStatestate of the example state machine
[in]nextSubstatesubstate to be transferred into
[in]idleTimewait time for the state machine

Definition at line 341 of file imd.c.

◆ IMD_TransferStateRequest()

static IMD_STATE_REQUEST_e IMD_TransferStateRequest ( IMD_STATE_s pImdState)
static

transfers the current state request to the state machine.

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

Parameters
[in,out]pImdStatepointer to state variable of IMD state machine
Returns
current state request

Definition at line 281 of file imd.c.

Here is the call graph for this function:

◆ IMD_Trigger()

STD_RETURN_TYPE_e IMD_Trigger ( void  )

trigger function for the IMD driver state machine.

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

Returns
returns STD_OK if trigger called successfully

Definition at line 528 of file imd.c.

Here is the call graph for this function:

Variable Documentation

◆ imd_state

IMD_STATE_s imd_state
static
Initial value:
= {
.timer = 0u,
.triggerEntry = 0u,
.nextState = IMD_FSM_STATE_DUMMY,
.stateRequest = IMD_STATE_NO_REQUEST,
.currentState = IMD_FSM_STATE_HAS_NEVER_RUN,
.previousState = IMD_FSM_STATE_DUMMY,
.nextSubstate = IMD_FSM_SUBSTATE_DUMMY,
.currentSubstate = IMD_FSM_SUBSTATE_DUMMY,
.previousSubstate = IMD_FSM_SUBSTATE_DUMMY,
.information.isStatemachineInitialized = false,
.information.switchImdDeviceOn = false,
}
@ IMD_FSM_SUBSTATE_DUMMY
Definition: imd.c:79
static DATA_BLOCK_INSULATION_MONITORING_s imd_tableInsulationMonitoring
Definition: imd.c:118
@ IMD_FSM_STATE_HAS_NEVER_RUN
Definition: imd.h:95
@ IMD_FSM_STATE_DUMMY
Definition: imd.h:94
@ IMD_STATE_NO_REQUEST
Definition: imd.h:89

global IMD state

Definition at line 122 of file imd.c.

◆ imd_tableInsulationMonitoring

DATA_BLOCK_INSULATION_MONITORING_s imd_tableInsulationMonitoring
static
Initial value:
= {
@ DATA_BLOCK_ID_INSULATION_MONITORING
Definition: database_cfg.h:97

Definition at line 118 of file imd.c.