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

Source file for handling redundancy between redundant cell voltage and cell temperature measurements. More...

#include "redundancy.h"
#include "bms.h"
#include "database.h"
#include "diag.h"
#include "foxmath.h"
#include "os.h"
#include "plausibility.h"
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for redundancy.c:

Go to the source code of this file.

Functions

static bool MRC_MeasurementUpdatedAtLeastOnce (uint32_t timestamp, uint32_t previousTimestamp)
 Check timestamp if measurement has been updated at least once. More...
 
static STD_RETURN_TYPE_e MRC_MeasurementUpdatedRecently (uint32_t timestamp, uint32_t previousTimestamp, uint32_t timeInterval)
 Check timestamp if measurement has been updated recently. More...
 
static bool MRC_ValidateCellVoltageMeasurement (DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase, DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0)
 Function to validate results of cell voltage measurement. More...
 
static bool MRC_ValidateCellTemperatureMeasurement (DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureBase, DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperatureRedundancy0)
 Function to validate results of cell temperature measurement. More...
 
static void MRC_ValidateCurrentMeasurement (DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
 Function to validate results of current measurement. More...
 
static void MRC_ValidateStringVoltageMeasurement (DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor, DATA_BLOCK_CELL_VOLTAGE_s *pTableCellVoltage)
 Function to validate results of string voltage measurement. More...
 
static void MRC_ValidateBatteryVoltageMeasurement (void)
 Function to validate HV battery voltage measurement. More...
 
static void MRC_ValidateHighVoltageBusMeasurement (DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
 Function to validate results of high voltage measurement and calculate battery voltage and high voltage bus voltage. More...
 
static void MRC_ValidatePowerMeasurement (DATA_BLOCK_CURRENT_SENSOR_s *pTableCurrentSensor)
 Function to validate results of power measurement. More...
 
static STD_RETURN_TYPE_e MRC_CalculateCellVoltageMinMaxAverage (const DATA_BLOCK_CELL_VOLTAGE_s *const pValidatedVoltages, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
 Function calculates minimum, maximum and average cell voltages. More...
 
static STD_RETURN_TYPE_e MRC_CalculateCellTemperatureMinMaxAverage (DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures, DATA_BLOCK_MIN_MAX_s *pMinMaxAverageValues)
 Function calculates minimum, maximum and average cell temperatures. More...
 
static STD_RETURN_TYPE_e MRC_ValidateCellVoltage (DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageBase, DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltageRedundancy0, DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages)
 Function compares cell voltage measurements from base measurement with one redundant measurement and writes result in pValidatedVoltages. More...
 
static STD_RETURN_TYPE_e MRC_UpdateCellVoltageValidation (DATA_BLOCK_CELL_VOLTAGE_s *pCellVoltage, DATA_BLOCK_CELL_VOLTAGE_s *pValidatedVoltages)
 Function updates validated cell voltage measurement with data from a single measurement source. This can be the case if no redundancy is used at all or if one or more of the redundant measurements are not working properly. More...
 
static STD_RETURN_TYPE_e MRC_ValidateCellTemperature (DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureBase, DATA_BLOCK_CELL_TEMPERATURE_s *pCelltemperatureRedundancy0, DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperatures)
 Function compares cell temperature measurements from base measurement with one redundant measurement and writes result in pValidatedTemperatures. More...
 
static STD_RETURN_TYPE_e MRC_UpdateCellTemperatureValidation (DATA_BLOCK_CELL_TEMPERATURE_s *pCellTemperature, DATA_BLOCK_CELL_TEMPERATURE_s *pValidatedTemperature)
 Function updates validated cell temperature measurement with data from a single measurement source. This can be the case if no redundancy is used at all or if one or more of the redundant measurements are not working properly. More...
 
STD_RETURN_TYPE_e MRC_Initialize (void)
 Function to initalize redundancy module. More...
 
STD_RETURN_TYPE_e MRC_ValidateAfeMeasurement (void)
 Function to validate the measurement between redundant measurement values for cell voltage and cell temperature. More...
 
STD_RETURN_TYPE_e MRC_ValidatePackMeasurement (void)
 Function to validate the measurements of pack values (string values, pack values) More...
 

Variables

static MRC_STATE_s mrc_state
 
static DATA_BLOCK_MIN_MAX_s mrc_tableMinimumMaximumValues = {.header.uniqueId = DATA_BLOCK_ID_MIN_MAX}
 
static DATA_BLOCK_CELL_VOLTAGE_s mrc_tableCellVoltages = {.header.uniqueId = DATA_BLOCK_ID_CELL_VOLTAGE}
 
static DATA_BLOCK_CELL_TEMPERATURE_s mrc_tableCellTemperatures = {.header.uniqueId = DATA_BLOCK_ID_CELL_TEMPERATURE}
 
static DATA_BLOCK_PACK_VALUES_s mrc_tablePackValues = {.header.uniqueId = DATA_BLOCK_ID_PACK_VALUES}
 

Detailed Description

Source file for handling redundancy between redundant cell voltage and cell temperature measurements.

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-07-31 (date of creation)
Updated
2023-10-12 (date of last update)
Version
v1.6.0
Prefix
MRC

Definition in file redundancy.c.

Function Documentation

◆ MRC_CalculateCellTemperatureMinMaxAverage()

static STD_RETURN_TYPE_e MRC_CalculateCellTemperatureMinMaxAverage ( DATA_BLOCK_CELL_TEMPERATURE_s pValidatedTemperatures,
DATA_BLOCK_MIN_MAX_s pMinMaxAverageValues 
)
static

Function calculates minimum, maximum and average cell temperatures.

Parameters
[in]pValidatedTemperaturesvalidated temperatures from base and/or redundant measurements
[out]pMinMaxAverageValuescalculated cell temperature min/max/average values
Returns
STD_NOT_OK if all cell temperatures are invalid and no minimum, maximum and average cell temperature values could be calculated, otherwise STD_OK

Definition at line 835 of file redundancy.c.

◆ MRC_CalculateCellVoltageMinMaxAverage()

static STD_RETURN_TYPE_e MRC_CalculateCellVoltageMinMaxAverage ( const DATA_BLOCK_CELL_VOLTAGE_s *const  pValidatedVoltages,
DATA_BLOCK_MIN_MAX_s pMinMaxAverageValues 
)
static

Function calculates minimum, maximum and average cell voltages.

Parameters
[in]pValidatedVoltagesvalidated voltages from base and/or redundant measurements
[out]pMinMaxAverageValuescalculated cell voltage min/max/average values
Returns
STD_NOT_OK if all cell voltage are invalid and no minimum, maximum and average cell voltage values could be calculated, otherwise STD_OK

Definition at line 777 of file redundancy.c.

◆ MRC_Initialize()

STD_RETURN_TYPE_e MRC_Initialize ( void  )

Function to initalize redundancy module.

Returns
STD_OK if module has been initialized successfully, otherwise STD_NOT_OK

< bitmask if current is valid. 0->valid, 1->invalid

< bitmask if voltage is valid. 0->valid, 1->invalid

< bitmask if voltage is valid. 0->valid, 1->invalid

< bitmask if power is valid. 0->valid, 1->invalid

Definition at line 1078 of file redundancy.c.

◆ MRC_MeasurementUpdatedAtLeastOnce()

static bool MRC_MeasurementUpdatedAtLeastOnce ( uint32_t  timestamp,
uint32_t  previousTimestamp 
)
static

Check timestamp if measurement has been updated at least once.

Parameters
[in]timestamptimestamp of last measurement update
[in]previousTimestamptimestamp of previously updated measurement
Returns
true if measurement has been updated at least once, otherwise false

Definition at line 247 of file redundancy.c.

◆ MRC_MeasurementUpdatedRecently()

static STD_RETURN_TYPE_e MRC_MeasurementUpdatedRecently ( uint32_t  timestamp,
uint32_t  previousTimestamp,
uint32_t  timeInterval 
)
static

Check timestamp if measurement has been updated recently.

Parameters
[in]timestamptimestamp of last measurement update
[in]previousTimestamptimestamp of previously updated measurement
[in]timeIntervalin systicks (type: uint32_t)
Returns
true if measurement has recently been updated, otherwise false

Definition at line 258 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_UpdateCellTemperatureValidation()

static STD_RETURN_TYPE_e MRC_UpdateCellTemperatureValidation ( DATA_BLOCK_CELL_TEMPERATURE_s pCellTemperature,
DATA_BLOCK_CELL_TEMPERATURE_s pValidatedTemperature 
)
static

Function updates validated cell temperature measurement with data from a single measurement source. This can be the case if no redundancy is used at all or if one or more of the redundant measurements are not working properly.

Parameters
[in]pCellTemperaturecell temperature measurement
[out]pValidatedTemperaturevalidated temperature values
Returns
STD_NOT_OK if not all cell voltages could be validated, otherwise STD_OK

Definition at line 1061 of file redundancy.c.

◆ MRC_UpdateCellVoltageValidation()

static STD_RETURN_TYPE_e MRC_UpdateCellVoltageValidation ( DATA_BLOCK_CELL_VOLTAGE_s pCellVoltage,
DATA_BLOCK_CELL_VOLTAGE_s pValidatedVoltages 
)
static

Function updates validated cell voltage measurement with data from a single measurement source. This can be the case if no redundancy is used at all or if one or more of the redundant measurements are not working properly.

Parameters
[in]pCellVoltagecell voltage measurement
[out]pValidatedVoltagesvalidated voltage values
Returns
STD_NOT_OK if not all cell voltages could be validated, otherwise STD_OK

Definition at line 969 of file redundancy.c.

◆ MRC_ValidateAfeMeasurement()

STD_RETURN_TYPE_e MRC_ValidateAfeMeasurement ( void  )

Function to validate the measurement between redundant measurement values for cell voltage and cell temperature.

Returns
STD_OK if measurement has been validated successfully, otherwise i.e. if no new values have been measured since the last call STD_NOT_OK

Definition at line 1103 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidateBatteryVoltageMeasurement()

static void MRC_ValidateBatteryVoltageMeasurement ( void  )
static

Function to validate HV battery voltage measurement.

Definition at line 643 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidateCellTemperature()

static STD_RETURN_TYPE_e MRC_ValidateCellTemperature ( DATA_BLOCK_CELL_TEMPERATURE_s pCelltemperatureBase,
DATA_BLOCK_CELL_TEMPERATURE_s pCelltemperatureRedundancy0,
DATA_BLOCK_CELL_TEMPERATURE_s pValidatedTemperatures 
)
static

Function compares cell temperature measurements from base measurement with one redundant measurement and writes result in pValidatedTemperatures.

Parameters
[in]pCelltemperatureBasebase cell temperature measurement
[in]pCelltemperatureRedundancy0redundant cell temperature measurement
[out]pValidatedTemperaturesvalidated temperatures from redundant measurement values
Returns
STD_NOT_OK if not all cell voltages could be validated, otherwise STD_OK

Definition at line 986 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidateCellTemperatureMeasurement()

static bool MRC_ValidateCellTemperatureMeasurement ( DATA_BLOCK_CELL_TEMPERATURE_s pCellTemperatureBase,
DATA_BLOCK_CELL_TEMPERATURE_s pCellTemperatureRedundancy0 
)
static

Function to validate results of cell temperature measurement.

Parameters
[in]pCellTemperatureBasebase cell temperature measurement
[in]pCellTemperatureRedundancy0redundant cell temperature measurement
Returns
bool true, if measurement has been validated successfully and database entry needs to be updated, otherwise false.

Definition at line 403 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidateCellVoltage()

static STD_RETURN_TYPE_e MRC_ValidateCellVoltage ( DATA_BLOCK_CELL_VOLTAGE_s pCellVoltageBase,
DATA_BLOCK_CELL_VOLTAGE_s pCellVoltageRedundancy0,
DATA_BLOCK_CELL_VOLTAGE_s pValidatedVoltages 
)
static

Function compares cell voltage measurements from base measurement with one redundant measurement and writes result in pValidatedVoltages.

Parameters
[in]pCellVoltageBasebase cell voltage measurement
[in]pCellVoltageRedundancy0redundant cell voltage measurement
[out]pValidatedVoltagesvalidated voltages from redundant measurement values
Returns
STD_NOT_OK if not all cell voltages could be validated, otherwise STD_OK

Definition at line 893 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidateCellVoltageMeasurement()

static bool MRC_ValidateCellVoltageMeasurement ( DATA_BLOCK_CELL_VOLTAGE_s pCellVoltageBase,
DATA_BLOCK_CELL_VOLTAGE_s pCellVoltageRedundancy0 
)
static

Function to validate results of cell voltage measurement.

Parameters
[in]pCellVoltageBasebase cell voltage measurement
[in]pCellVoltageRedundancy0redundant cell voltage measurement
Returns
bool true, if measurement has been validated successfully and database entry needs to be updated, otherwise false.

Definition at line 276 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidateCurrentMeasurement()

static void MRC_ValidateCurrentMeasurement ( DATA_BLOCK_CURRENT_SENSOR_s pTableCurrentSensor)
static

Function to validate results of current measurement.

Parameters
[in]pTableCurrentSensorpointer to current measurements

Definition at line 529 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidateHighVoltageBusMeasurement()

static void MRC_ValidateHighVoltageBusMeasurement ( DATA_BLOCK_CURRENT_SENSOR_s pTableCurrentSensor)
static

Function to validate results of high voltage measurement and calculate battery voltage and high voltage bus voltage.

Parameters
[in]pTableCurrentSensorpointer current sensor high voltage measurements

Definition at line 683 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidatePackMeasurement()

STD_RETURN_TYPE_e MRC_ValidatePackMeasurement ( void  )

Function to validate the measurements of pack values (string values, pack values)

Returns
STD_OK if measurement has been validated successfully, otherwise i.e. if no new values have been measured since the last call STD_NOT_OK

Definition at line 1144 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidatePowerMeasurement()

static void MRC_ValidatePowerMeasurement ( DATA_BLOCK_CURRENT_SENSOR_s pTableCurrentSensor)
static

Function to validate results of power measurement.

Parameters
[in]pTableCurrentSensorpointer to power/current measurements

Definition at line 717 of file redundancy.c.

Here is the call graph for this function:

◆ MRC_ValidateStringVoltageMeasurement()

static void MRC_ValidateStringVoltageMeasurement ( DATA_BLOCK_CURRENT_SENSOR_s pTableCurrentSensor,
DATA_BLOCK_CELL_VOLTAGE_s pTableCellVoltage 
)
static

Function to validate results of string voltage measurement.

Parameters
[in]pTableCurrentSensorpointer current sensor high voltage measurements
[in]pTableCellVoltagepointer to cell voltage measurements

Definition at line 578 of file redundancy.c.

Here is the call graph for this function:

Variable Documentation

◆ mrc_state

MRC_STATE_s mrc_state
static
Initial value:
= {
.lastBaseCellVoltageTimestamp = 0u,
.lastRedundancy0CellVoltageTimestamp = 0u,
.lastBaseCelltemperatureTimestamp = 0u,
.lastRedundancy0CelltemperatureTimestamp = 0u,
.lastStringCurrentTimestamp = {0u},
}

state of the redundancy module

Definition at line 82 of file redundancy.c.

◆ mrc_tableCellTemperatures

DATA_BLOCK_CELL_TEMPERATURE_s mrc_tableCellTemperatures = {.header.uniqueId = DATA_BLOCK_ID_CELL_TEMPERATURE}
static

local copies of database tables

Definition at line 77 of file redundancy.c.

◆ mrc_tableCellVoltages

DATA_BLOCK_CELL_VOLTAGE_s mrc_tableCellVoltages = {.header.uniqueId = DATA_BLOCK_ID_CELL_VOLTAGE}
static

local copies of database tables

Definition at line 76 of file redundancy.c.

◆ mrc_tableMinimumMaximumValues

DATA_BLOCK_MIN_MAX_s mrc_tableMinimumMaximumValues = {.header.uniqueId = DATA_BLOCK_ID_MIN_MAX}
static

local copies of database tables

Definition at line 75 of file redundancy.c.

◆ mrc_tablePackValues

DATA_BLOCK_PACK_VALUES_s mrc_tablePackValues = {.header.uniqueId = DATA_BLOCK_ID_PACK_VALUES}
static

local copies of database tables

Definition at line 78 of file redundancy.c.