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