foxBMS - Unit Tests
1.2.1
The foxBMS Unit Tests API Documentation
|
This is a collection of helper functions for the MAX1785x ICs. More...
Go to the source code of this file.
Macros | |
#define | MXM_TOOLS_LENGTH_BYTE (8u) |
Functions | |
static uint8_t | MXM_FirstSetBit (uint16_t bitmask) |
Find Position of first set bit in bitmask. More... | |
STD_RETURN_TYPE_e must_check_return | MXM_FirstSetBitTest (void) |
Test MXM_FirstSetBit(). More... | |
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 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 must_check_return | MXM_ExtractValueFromRegisterTest (void) |
Test MXM_ExtractValueFromRegister(). 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.c.
#define MXM_TOOLS_LENGTH_BYTE (8u) |
length of a byte
Definition at line 64 of file mxm_1785x_tools.c.
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 111 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 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 249 of file mxm_1785x_tools.c.
STD_RETURN_TYPE_e 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 144 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 175 of file mxm_1785x_tools.c.
STD_RETURN_TYPE_e must_check_return MXM_ExtractValueFromRegisterTest | ( | void | ) |
Test MXM_ExtractValueFromRegister().
Self-check that tests whether MXM_ExtractValueFromRegister() works as expected.
Definition at line 200 of file mxm_1785x_tools.c.
|
static |
Find Position of first set bit in bitmask.
Searches a bitmask starting from the lowest bit and returns the position of the first set bit.
[in] | bitmask | bitmask that should be searched |
Definition at line 81 of file mxm_1785x_tools.c.
STD_RETURN_TYPE_e must_check_return MXM_FirstSetBitTest | ( | void | ) |
Test MXM_FirstSetBit().
Tests the function MXM_FirstSetBit() if it works as expected.
Definition at line 94 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 228 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 241 of file mxm_1785x_tools.c.