foxBMS  1.0.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
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 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.h
TODO.
mxm_41bWriteValue
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
Definition: mxm_bitextract.c:105
mxm_41bReadValue
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
Definition: mxm_bitextract.c:101
MXM_41B_REG_BITS
uint8_t MXM_41B_REG_BITS
Definition: mxm_bitextract.h:115
MXM_41B_REG_BIT_VALUE
uint8_t MXM_41B_REG_BIT_VALUE
Bit-values for registers.
Definition: mxm_bitextract.h:69