foxBMS-UnitTests  1.0.0
The foxBMS Unit Tests API Documentation
foxmath.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
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