foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
mxm_bitextract.h
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, 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 mxm_bitextract.h
44  * @author foxBMS Team
45  * @date 2019-01-15 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup DRIVERS
49  * @prefix MXM
50  *
51  * @brief Bit extraction function for MXM_17841b
52  *
53  * @details This module supplies a specific bit extraction functionality to
54  * read & write into status registers. The different statuses that are read
55  * from or write into are indicated in the enum.
56  * Battery monitoring driver for MAX1785x battery monitoring ICs.
57  *
58  */
59 
60 #ifndef FOXBMS__MXM_BITEXTRACT_H_
61 #define FOXBMS__MXM_BITEXTRACT_H_
62 
63 /*========== Includes =======================================================*/
64 
65 #include <stdint.h>
66 
67 /*========== Macros and Definitions =========================================*/
68 /**
69  * @brief Bit-values for registers
70  */
71 /* AXIVION Disable Style MisraC2012-2.5: Defines are based on data sheet and exist all for completeness. */
72 typedef uint8_t MXM_41B_REG_BIT_VALUE;
73 /** one bit, 0u */
74 #define MXM_41B_REG_FALSE ((MXM_41B_REG_BIT_VALUE)0x00u)
75 /** one bit, 1u */
76 #define MXM_41B_REG_TRUE ((MXM_41B_REG_BIT_VALUE)0x01u)
77 /** bit sequence for baud rate 500KBps */
78 #define MXM_41B_REG_BAUD_RATE_500KBPS ((MXM_41B_REG_BIT_VALUE)0x00u)
79 /** alternative bit sequence for baud rate 500KBps */
80 #define MXM_41B_REG_BAUD_RATE_500KBPS_ALT ((MXM_41B_REG_BIT_VALUE)0x01u)
81 /** bit sequence for baud rate 1MBps */
82 #define MXM_41B_REG_BAUD_RATE_1MBPS ((MXM_41B_REG_BIT_VALUE)0x02u)
83 /** bit sequence for baud rate 2MBps */
84 #define MXM_41B_REG_BAUD_RATE_2MBPS ((MXM_41B_REG_BIT_VALUE)0x03u)
85 /** bit sequence for a keep alive period of 0&micro;s */
86 #define MXM_41B_REG_KEEP_ALIVE_0US ((MXM_41B_REG_BIT_VALUE)0x00u)
87 /** bit sequence for a keep alive period of 10&micro;s */
88 #define MXM_41B_REG_KEEP_ALIVE_10US ((MXM_41B_REG_BIT_VALUE)0x01u)
89 /** bit sequence for a keep alive period of 20&micro;s */
90 #define MXM_41B_REG_KEEP_ALIVE_20US ((MXM_41B_REG_BIT_VALUE)0x02u)
91 /** bit sequence for a keep alive period of 40&micro;s */
92 #define MXM_41B_REG_KEEP_ALIVE_40US ((MXM_41B_REG_BIT_VALUE)0x03u)
93 /** bit sequence for a keep alive period of 80&micro;s */
94 #define MXM_41B_REG_KEEP_ALIVE_80US ((MXM_41B_REG_BIT_VALUE)0x04u)
95 /** bit sequence for a keep alive period of 160&micro;s */
96 #define MXM_41B_REG_KEEP_ALIVE_160US ((MXM_41B_REG_BIT_VALUE)0x05u)
97 /** bit sequence for a keep alive period of 320&micro;s */
98 #define MXM_41B_REG_KEEP_ALIVE_320US ((MXM_41B_REG_BIT_VALUE)0x06u)
99 /** bit sequence for a keep alive period of 640&micro;s */
100 #define MXM_41B_REG_KEEP_ALIVE_640US ((MXM_41B_REG_BIT_VALUE)0x07u)
101 /** bit sequence for a keep alive period of 1280&micro;s */
102 #define MXM_41B_REG_KEEP_ALIVE_1280US ((MXM_41B_REG_BIT_VALUE)0x08u)
103 /** bit sequence for a keep alive period of 2560&micro;s */
104 #define MXM_41B_REG_KEEP_ALIVE_2560US ((MXM_41B_REG_BIT_VALUE)0x09u)
105 /** bit sequence for a keep alive period of 5120&micro;s */
106 #define MXM_41B_REG_KEEP_ALIVE_5120US ((MXM_41B_REG_BIT_VALUE)0x0Au)
107 /** bit sequence for a keep alive period of 10240&micro;s */
108 #define MXM_41B_REG_KEEP_ALIVE_10240US ((MXM_41B_REG_BIT_VALUE)0x0Bu)
109 /** bit sequence for a infinite keep alive period (disabled) */
110 #define MXM_41B_REG_KEEP_ALIVE_INF_DLY ((MXM_41B_REG_BIT_VALUE)0x0Fu)
111 /* AXIVION Enable Style MisraC2012-2.5: */
112 
113 /**
114  * @brief define for creating a bitmask
115  */
116 #define MXM_REG_MASK(start, end) (((1u << ((end) - (start) + 1u)) - 1u) << (start))
117 
118 /** types for bits in the register of MAX17841B */
119 typedef uint8_t MXM_41B_REG_BITS;
120 /** bit for the feature TX Preambles */
121 #define MXM_41B_TX_PREAMBLES ((MXM_41B_REG_BITS)5u)
122 /** bit for the feature Keep Alive */
123 #define MXM_41B_KEEP_ALIVE ((MXM_41B_REG_BITS)0u)
124 /** bit for the RX Error */
125 #define MXM_41B_RX_ERROR ((MXM_41B_REG_BITS)7u)
126 /** bit for the RX Busy Status */
127 #define MXM_41B_RX_BUSY_STATUS ((MXM_41B_REG_BITS)5u)
128 /** bit for the feature RX Overflow Interrupt */
129 #define MXM_41B_RX_OVERFLOW_INT_ENABLE ((MXM_41B_REG_BITS)3u)
130 /** bit for the RX Overflow Status */
131 #define MXM_41B_RX_OVERFLOW_STATUS ((MXM_41B_REG_BITS)3u)
132 /** bit for the RX Stop Status */
133 #define MXM_41B_RX_STOP_STATUS ((MXM_41B_REG_BITS)1u)
134 /** bit for the RX Empty Status */
135 #define MXM_41B_RX_EMPTY_STATUS ((MXM_41B_REG_BITS)0u)
136 
137 /*========== Extern Constant and Variable Declarations ======================*/
138 
139 /*========== Extern Function Prototypes =====================================*/
140 /**
141  * @brief write a value to a register supplied as variable
142  * @details This function takes a register (reg), writes the data
143  * described by numberOFBits, shift and value to the register
144  * value and returns the updated register.
145  * @param[in] value register value that should be written to the
146  * register
147  * @param[in] numberOfBits length of the entry that should be written in
148  * bits
149  * @param[in] shift start position in the register in bits
150  * @param[in] reg complete value of the register
151  * @return updated value of the register
152  */
154  MXM_41B_REG_BIT_VALUE value,
155  uint8_t numberOfBits,
156  MXM_41B_REG_BITS shift,
157  uint8_t reg);
158 
159 /**
160  * @brief read a value from a register supplied as variable
161  * @details This function takes a register (reg), and extracts the data
162  * described by its length in bits (numberOfBits) and position
163  * (pos). This value is then returned.
164  * @param[in] reg value of the register to be read
165  * @param[in] numberOfBits length og the bit sequence in bits
166  * @param[in] position start position of the bit sequence
167  * @returns the isolated and shifted bit value
168  */
169 extern MXM_41B_REG_BIT_VALUE mxm_41bReadValue(uint8_t reg, uint8_t numberOfBits, MXM_41B_REG_BITS position);
170 
171 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
172 #ifdef UNITY_UNIT_TEST
173 #endif
174 
175 #endif /* FOXBMS__MXM_BITEXTRACT_H_ */
uint8_t MXM_41B_REG_BITS
uint8_t MXM_41B_REG_BIT_VALUE
Bit-values for registers.
MXM_41B_REG_BIT_VALUE mxm_41bWriteValue(MXM_41B_REG_BIT_VALUE value, uint8_t numberOfBits, MXM_41B_REG_BITS shift, uint8_t reg)
write a value to a register supplied as variable
MXM_41B_REG_BIT_VALUE mxm_41bReadValue(uint8_t reg, uint8_t numberOfBits, MXM_41B_REG_BITS position)
read a value from a register supplied as variable