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