foxBMS  1.0.2
The foxBMS Battery Management System API Documentation
foxmath.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file foxmath.h
44  * @author foxBMS Team
45  * @date 2018-01-18 (date of creation)
46  * @updated 2018-01-18 (date of last update)
47  * @ingroup DRIVERS
48  * @prefix MATH
49  *
50  * @brief math library for often used math functions
51  *
52  * @details This header file contains the different math function declarations.
53  * Currently the following functions are supported:
54  * - Slope
55  * - Linear interpolation
56  *
57  */
58 
59 #ifndef FOXBMS__FOXMATH_H_
60 #define FOXBMS__FOXMATH_H_
61 
62 /*========== Includes =======================================================*/
63 #include "general.h"
64 
65 #include <float.h>
66 #include <math.h>
67 #include <stdlib.h>
68 
69 /*========== Macros and Definitions =========================================*/
70 
71 /** Add defines for unit conversions */
72 #define UNIT_CONVERSION_FACTOR_1000_INTEGER (1000)
73 
74 /*========== Extern Constant and Variable Declarations ======================*/
75 
76 /*========== Extern Function Prototypes =====================================*/
77 
78 /**
79  * @brief Linear inter-/extrapolates a third point according to two given points
80  *
81  * @param x1: x-value of point 1
82  * @param y1: y-value of point 1
83  * @param x2: x-value of point 2
84  * @param y2: y-value of point 2
85  * @param x_interpolate: x value of interpolation point
86  *
87  * @return interpolated value (float)
88  */
89 extern float MATH_linearInterpolation(float x1, float y1, float x2, float y2, float x_interpolate);
90 
91 /**
92  * @brief Swap bytes of uint16_t value
93  * @param val: value to swap bytes: 0x1234 -> 0x3412
94  */
95 extern uint16_t MATH_swapBytes_uint16_t(uint16_t val);
96 
97 /**
98  * @brief Swap bytes of uint32_t value
99  * @param val: value to swap bytes: 0x12345678 -> 0x78563412
100  */
101 extern uint32_t MATH_swapBytes_uint32_t(uint32_t val);
102 
103 /**
104  * @brief Swap bytes of uint64_t value
105  * @param val: value to swap bytes: 0x1122334455667788 -> 0x8877665544332211
106  */
107 extern uint64_t MATH_swapBytes_uint64_t(uint64_t val);
108 
109 /**
110  * @brief Returns the minimum of the passed float values
111  * @param[in] value1 value 1
112  * @param[in] value2 value 2
113  * @return minimum value
114  */
115 extern float MATH_minimumOfTwoFloats(float value1, float value2);
116 
117 /**
118  * @brief Returns the absolute value of passed int32_t value
119  * @param[in] value integer value
120  * @return absolute value or INT32_MAX if INT32_MIN is passed
121  */
122 extern int32_t MATH_AbsInt32(int32_t value);
123 
124 /**
125  * @brief Returns the absolute value of passed int64_t value
126  * @param[in] value integer value
127  * @return absolute value or INT64_MAX if INT64_MIN is passed
128  */
129 extern int64_t MATH_AbsInt64(int64_t value);
130 
131 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
132 
133 #endif /* FOXBMS__FOXMATH_H_ */
MATH_swapBytes_uint32_t
uint32_t MATH_swapBytes_uint32_t(uint32_t val)
Swap bytes of uint32_t value.
Definition: foxmath.c:90
general.h
TODO.
MATH_linearInterpolation
float MATH_linearInterpolation(float x1, float y1, float x2, float y2, float x_interpolate)
Linear inter-/extrapolates a third point according to two given points.
Definition: foxmath.c:69
MATH_swapBytes_uint16_t
uint16_t MATH_swapBytes_uint16_t(uint16_t val)
Swap bytes of uint16_t value.
Definition: foxmath.c:86
MATH_AbsInt64
int64_t MATH_AbsInt64(int64_t value)
Returns the absolute value of passed int64_t value.
Definition: foxmath.c:113
MATH_AbsInt32
int32_t MATH_AbsInt32(int32_t value)
Returns the absolute value of passed int32_t value.
Definition: foxmath.c:105
MATH_minimumOfTwoFloats
float MATH_minimumOfTwoFloats(float value1, float value2)
Returns the minimum of the passed float values.
Definition: foxmath.c:101
MATH_swapBytes_uint64_t
uint64_t MATH_swapBytes_uint64_t(uint64_t val)
Swap bytes of uint64_t value.
Definition: foxmath.c:95