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