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

Sys driver implementation. More...

#include "general.h"
#include "sys.h"
#include "algorithm.h"
#include "bal.h"
#include "bms.h"
#include "can.h"
#include "contactor.h"
#include "diag.h"
#include "fram.h"
#include "fstd_types.h"
#include "imd.h"
#include "interlock.h"
#include "meas.h"
#include "os.h"
#include "sbc.h"
#include "sof_trapezoid.h"
#include "state_estimation.h"
#include <stdint.h>
Include dependency graph for sys.c:

Go to the source code of this file.

Macros

#define SYS_SAVELASTSTATES(x)
 
#define SYS_BIST_GENERAL_MAGIC_NUMBER   (42u)
 

Enumerations

enum  SYS_CHECK_MULTIPLE_CALLS_e { SYS_MULTIPLE_CALLS_NO , SYS_MULTIPLE_CALLS_YES }
 

Functions

static SYS_CHECK_MULTIPLE_CALLS_e SYS_CheckMultipleCalls (SYS_STATE_s *pSystemState)
 check for multiple calls of state machine trigger function More...
 
static STD_RETURN_TYPE_e SYS_RunStateMachine (SYS_STATE_s *pSystemState)
 Defines the state transitions. More...
 
static SYS_RETURN_TYPE_e SYS_CheckStateRequest (SYS_STATE_REQUEST_e stateRequest)
 checks the state requests that are made. More...
 
static SYS_STATE_REQUEST_e SYS_TransferStateRequest (void)
 transfers the current state request to the state machine. More...
 
SYS_RETURN_TYPE_e SYS_SetStateRequest (SYS_STATE_REQUEST_e stateRequest)
 sets the current state request of the state variable sys_state. More...
 
void SYS_GeneralMacroBist (void)
 
STD_RETURN_TYPE_e SYS_Trigger (SYS_STATE_s *pSystemState)
 tick function, call this to advance the state machine More...
 

Variables

SYS_STATE_s sys_state
 

Detailed Description

Sys driver implementation.

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
SYS

Definition in file sys.c.

Macro Definition Documentation

◆ SYS_BIST_GENERAL_MAGIC_NUMBER

#define SYS_BIST_GENERAL_MAGIC_NUMBER   (42u)

Magic number that is searched by the SYS_GeneralMacroBist().

Definition at line 85 of file sys.c.

◆ SYS_SAVELASTSTATES

#define SYS_SAVELASTSTATES (   x)
Value:
(x)->lastState = (x)->state; \
(x)->lastSubstate = (x)->substate

Saves the last state and the last substate

Definition at line 80 of file sys.c.

Enumeration Type Documentation

◆ SYS_CHECK_MULTIPLE_CALLS_e

Symbolic names to check for multiple calls of SYS_Trigger()

Enumerator
SYS_MULTIPLE_CALLS_NO 

no multiple calls, OK

SYS_MULTIPLE_CALLS_YES 

multiple calls, not OK

Definition at line 92 of file sys.c.

Function Documentation

◆ SYS_CheckMultipleCalls()

static SYS_CHECK_MULTIPLE_CALLS_e SYS_CheckMultipleCalls ( SYS_STATE_s pSystemState)
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
pSystemStatestate of the fake state machine
Returns
SYS_MULTIPLE_CALLS_YES if there were multiple calls, SYS_MULTIPLE_CALLS_NO otherwise

Definition at line 142 of file sys.c.

Here is the call graph for this function:

◆ SYS_CheckStateRequest()

static SYS_RETURN_TYPE_e SYS_CheckStateRequest ( SYS_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 is returned immediately.

Parameters
stateRequeststate request to be checked
Returns
result of the state request that was made, taken from SYS_RETURN_TYPE_e

Definition at line 593 of file sys.c.

◆ SYS_GeneralMacroBist()

void SYS_GeneralMacroBist ( void  )

built-in self-test for the macros in general.h

Definition at line 618 of file sys.c.

◆ SYS_RunStateMachine()

static STD_RETURN_TYPE_e SYS_RunStateMachine ( SYS_STATE_s pSystemState)
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
pSystemStatestate of the example state machine
Returns
TODO

Definition at line 155 of file sys.c.

Here is the call graph for this function:

◆ SYS_SetStateRequest()

SYS_RETURN_TYPE_e SYS_SetStateRequest ( SYS_STATE_REQUEST_e  stateRequest)

sets the current state request of the state variable sys_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 SYS_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 requested to set
Returns
If the request was successfully set, it returns the SYS_OK, else the current state of requests (type SYS_STATE_REQUEST_e)

Definition at line 569 of file sys.c.

Here is the call graph for this function:

◆ SYS_TransferStateRequest()

static SYS_STATE_REQUEST_e SYS_TransferStateRequest ( void  )
static

transfers the current state request to the state machine.

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

Returns
retVal current state request, taken from SYS_STATE_REQUEST_e

Definition at line 558 of file sys.c.

Here is the call graph for this function:

◆ SYS_Trigger()

STD_RETURN_TYPE_e SYS_Trigger ( SYS_STATE_s pSystemState)

tick function, call this to advance the state machine

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

Definition at line 626 of file sys.c.

Here is the call graph for this function:

Variable Documentation

◆ sys_state

SYS_STATE_s sys_state
Initial value:
= {
.timer = 0,
.triggerEntry = 0,
.stateRequest = SYS_STATE_NO_REQUEST,
.substate = SYS_ENTRY,
.lastSubstate = SYS_ENTRY,
.illegalRequestsCounter = 0,
.initializationTimeout = 0,
}
@ SYS_ENTRY
Definition: sys.h:127
@ SYS_STATE_NO_REQUEST
Definition: sys.h:153
@ SYS_STATEMACH_UNINITIALIZED
Definition: sys.h:107

contains the state of the contactor state machine

Definition at line 98 of file sys.c.