foxBMS - Unit Tests
1.4.1
The foxBMS Unit Tests API Documentation
|
This is a collection of helper functions for the MAX1785x ICs. More...
#include "mxm_cfg.h"
#include "database.h"
#include "mxm_basic_defines.h"
#include "mxm_battery_management.h"
#include "mxm_register_map.h"
Go to the source code of this file.
Data Structures | |
struct | MXM_SELFCHECK_s |
struct | MXM_REGISTRY_ENTRY_s |
struct | MXM_BALANCING_STATE_s |
struct | MXM_MONITORING_INSTANCE_s |
Macros | |
#define | MXM_RX_BUFFER_LENGTH (100u) |
Length of RX buffer. More... | |
Functions | |
void | MXM_Convert (uint8_t lsb, uint8_t msb, uint16_t *pTarget, MXM_CONVERSION_TYPE_e convType, uint32_t fullScaleReference_mV) |
Convert a measurement value to a voltage value. More... | |
STD_RETURN_TYPE_e GEN_MUST_CHECK_RETURN | MXM_ConvertTest (void) |
Test the MXM_Convert()-function. More... | |
void | MXM_ExtractValueFromRegister (uint8_t lsb, uint8_t msb, MXM_REG_BM bitmask, uint16_t *pValue) |
Extract a value from a single register. More... | |
STD_RETURN_TYPE_e GEN_MUST_CHECK_RETURN | MXM_ExtractValueFromRegisterTest (void) |
Test MXM_ExtractValueFromRegister(). More... | |
STD_RETURN_TYPE_e GEN_MUST_CHECK_RETURN | MXM_FirstSetBitTest (void) |
Test MXM_FirstSetBit(). More... | |
void | MXM_Unipolar14BitInto16Bit (uint16_t inputValue, uint8_t *lsb, uint8_t *msb) |
convert a unipolar 14bit-value and shifts it into the 16bit-format More... | |
uint16_t | MXM_VoltageIntoUnipolar14Bit (uint16_t voltage_mV, uint16_t fullscaleReference_mV) |
convert a voltage value into a unipolar 14bit value More... | |
void | MXM_ConvertModuleToString (const uint16_t moduleNumber, uint8_t *pStringNumber, uint16_t *pModuleNumberInString) |
Get the string and module number from a global module number. More... | |
This is a collection of helper functions for the MAX1785x ICs.
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:
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 collection of helper functions for the MAX1785x ICs helps to calculate the lsb and msb for register values and similar tasks.
Definition in file mxm_1785x_tools.h.
#define MXM_RX_BUFFER_LENGTH (100u) |
Length of RX buffer.
This define describes the length of the array MXM_MONITORING_INSTANCE_s::rxBuffer. It is large enough to fit the largest message that can be written into a single buffer which consists of 6 command bytes and MXM_MAXIMUM_NR_OF_MODULES times 2 receive bytes for the maximum number of connected monitoring ICs.
Definition at line 215 of file mxm_1785x_tools.h.
intermediate state-definition for MXM_MonGetVoltages()
Enumerator | |
---|---|
MXM_MONITORING_STATE_PENDING | state completion is pending |
MXM_MONITORING_STATE_PASS | state passed successfully |
Definition at line 167 of file mxm_1785x_tools.h.
states of the MXM_StateMachineOperation() statemachine
Definition at line 87 of file mxm_1785x_tools.h.
States of the global Maxim state-machine.
State transitions are currently autonomous and will have to be integrated into the Battery System state-machine.
Definition at line 76 of file mxm_1785x_tools.h.
void MXM_Convert | ( | uint8_t | lsb, |
uint8_t | msb, | ||
uint16_t * | pTarget, | ||
MXM_CONVERSION_TYPE_e | convType, | ||
uint32_t | fullScaleReference_mV | ||
) |
Convert a measurement value to a voltage value.
This function converts measurement values from the monitoring IC into a voltage value. It assumes that measurement values are spread over the LSB and MSB according to the data sheet. This means that the two lowest bits are 0 and the 14-bit measurement is spread over the 14 highest bits.
The conversion type describes the kind of measurement that has been executed.
[in] | lsb | LSB of the value |
[in] | msb | MSB of the value |
[out] | pTarget | pointer in which the converted value shall be written |
[in] | convType | type of conversion (bipolar or unipolar) |
[in] | fullScaleReference_mV | reference voltage of full scale (for voltage measurements 5000) |
Definition at line 113 of file mxm_1785x_tools.c.
void MXM_ConvertModuleToString | ( | const uint16_t | moduleNumber, |
uint8_t * | pStringNumber, | ||
uint16_t * | pModuleNumberInString | ||
) |
Get the string and module number from a global module number.
Maxim driver knows only one string internally and maps on demand this one string onto several strings (for instances where several modules are in the same daisy-chain but belong to different strings).
This function assumes that a string contains BS_NR_OF_MODULES_PER_STRING modules in BS_NR_OF_STRINGS strings and that they are connected in a daisy-chain.
[in] | moduleNumber | number of the module in the daisy-chain (starts with 0) |
[out] | pStringNumber | pointer where the string number will be written |
[out] | pModuleNumberInString | module number in the string |
Definition at line 263 of file mxm_1785x_tools.c.
STD_RETURN_TYPE_e GEN_MUST_CHECK_RETURN MXM_ConvertTest | ( | void | ) |
Test the MXM_Convert()-function.
This test-function is intended as a self-check. It tests whether the MXM_Convert()-function computes the values as expected.
Definition at line 150 of file mxm_1785x_tools.c.
void MXM_ExtractValueFromRegister | ( | uint8_t | lsb, |
uint8_t | msb, | ||
MXM_REG_BM | bitmask, | ||
uint16_t * | pValue | ||
) |
Extract a value from a single register.
This function extracts a single value from a single register. The register has to be supplied as MSB and LSB. The bitmask has to be of type MXM_REG_BM. The extracted value will be written into value.
The function can only extract values from single registers (MSB and LSB)and does not handle values that span multiple registers.
[in] | lsb | least significant byte of the register |
[in] | msb | most significant byte of the register |
[in] | bitmask | bitmask for the value |
[out] | pValue | pointer to a variable in which the value should be written |
Definition at line 181 of file mxm_1785x_tools.c.
STD_RETURN_TYPE_e GEN_MUST_CHECK_RETURN MXM_ExtractValueFromRegisterTest | ( | void | ) |
Test MXM_ExtractValueFromRegister().
Self-check that tests whether MXM_ExtractValueFromRegister() works as expected.
Definition at line 209 of file mxm_1785x_tools.c.
STD_RETURN_TYPE_e GEN_MUST_CHECK_RETURN MXM_FirstSetBitTest | ( | void | ) |
Test MXM_FirstSetBit().
Tests the function MXM_FirstSetBit() if it works as expected.
Definition at line 96 of file mxm_1785x_tools.c.
void MXM_Unipolar14BitInto16Bit | ( | uint16_t | inputValue, |
uint8_t * | lsb, | ||
uint8_t * | msb | ||
) |
convert a unipolar 14bit-value and shifts it into the 16bit-format
Takes a value in the unipolar 14bit format and transforms it into a 16bit register entry for the monitoring IC (separated into LSB and MSB).
[in] | inputValue | unipolar 14bit-value |
[out] | lsb | LSB in 16bit-format |
[out] | msb | MSB in 16bit-format |
Definition at line 237 of file mxm_1785x_tools.c.
uint16_t MXM_VoltageIntoUnipolar14Bit | ( | uint16_t | voltage_mV, |
uint16_t | fullscaleReference_mV | ||
) |
convert a voltage value into a unipolar 14bit value
Takes a voltage value in mV together with a reference for fullscale values into a unipolar 14bit value.
[in] | voltage_mV | voltage in mV |
[in] | fullscaleReference_mV | value of the fullscale in mV; typically 5000 |
Definition at line 252 of file mxm_1785x_tools.c.