foxBMS  1.1.0
The foxBMS Battery Management System API Documentation
mxm_1785x_tools.c File Reference

This is a collection of helper functions for the MAX1785x ICs. More...

#include "mxm_1785x_tools.h"
#include "mxm_register_map.h"
Include dependency graph for mxm_1785x_tools.c:

Go to the source code of this file.

Functions

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...
 

Detailed Description

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:

  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-15 (date of creation)
Updated
2021-06-16 (date of last update)
Prefix
MXM

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.

Function Documentation

◆ MXM_Convert()

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 datasheet. 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.

Parameters
[in]lsbLSB of the value
[in]msbMSB of the value
[out]pTargetpointer in which the converted value shall be written
[in]convTypetype of conversion (bipolar or unipolar)
[in]fullScaleReference_mVreference voltage of full scale (for voltage measurements 5000)

Definition at line 98 of file mxm_1785x_tools.c.

Here is the call graph for this function:

◆ MXM_ConvertModuleToString()

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.

Parameters
[in]moduleNumbernumber of the module in the daisy-chain (starts with 0)
[out]pStringNumberpointer where the string number will be written
[out]pModuleNumberInStringmodule number in the string

Definition at line 222 of file mxm_1785x_tools.c.

◆ MXM_ConvertTest()

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.

Returns
STD_OK on successful execution, otherwise STD_NOT_OK

Definition at line 125 of file mxm_1785x_tools.c.

Here is the call graph for this function:

◆ MXM_ExtractValueFromRegister()

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.

Parameters
[in]lsbleast significant byte of the register
[in]msbmost significant byte of the register
[in]bitmaskbitmask for the value
[out]pValuepointer to a variable in which the value should be written

Definition at line 155 of file mxm_1785x_tools.c.

Here is the call graph for this function:

◆ MXM_ExtractValueFromRegisterTest()

STD_RETURN_TYPE_e must_check_return MXM_ExtractValueFromRegisterTest ( void  )

Test MXM_ExtractValueFromRegister().

Self-check that tests whether MXM_ExtractValueFromRegister() works as expected.

Returns
STD_OK if the self-check has passed successfully

Definition at line 174 of file mxm_1785x_tools.c.

Here is the call graph for this function:

◆ MXM_FirstSetBit()

uint8_t MXM_FirstSetBit ( uint16_t  bitmask)

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.

Parameters
[in]bitmaskbitmask that should be searched
Returns
position of first set bit

Definition at line 73 of file mxm_1785x_tools.c.

◆ MXM_FirstSetBitTest()

STD_RETURN_TYPE_e must_check_return MXM_FirstSetBitTest ( void  )

Test MXM_FirstSetBit().

Tests the function MXM_FirstSetBit() if it works as expected.

Returns
STD_OK if the self-check has passed successfully

Definition at line 85 of file mxm_1785x_tools.c.

Here is the call graph for this function:

◆ MXM_Unipolar14BitInto16Bit()

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).

Parameters
[in]inputValueunipolar 14bit-value
[out]lsbLSB in 16bit-format
[out]msbMSB in 16bit-format

Definition at line 203 of file mxm_1785x_tools.c.

◆ MXM_VoltageIntoUnipolar14Bit()

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.

Parameters
[in]voltage_mVvoltage in mV
[in]fullscaleReference_mVvalue of the fullscale in mV; typically 5000
Returns
unipolar 14bit value for usage with MXM_Unipolar14BitInto16Bit()

Definition at line 214 of file mxm_1785x_tools.c.