foxBMS - Unit Tests  1.4.0
The foxBMS Unit Tests API Documentation
test_mxm_bitextract.c
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 test_mxm_bitextract.c
44  * @author foxBMS Team
45  * @date 2020-04-07 (date of creation)
46  * @updated 2022-07-28 (date of last update)
47  * @version v1.4.0
48  * @ingroup UNIT_TEST_IMPLEMENTATION
49  * @prefix TEST
50  *
51  * @brief Test for test_mxm_bitextract.c
52  *
53  * @details def
54  *
55  */
56 
57 /*========== Includes =======================================================*/
58 #include "unity.h"
59 
60 #include "mxm_bitextract.h"
61 
62 /*========== Definitions and Implementations for Unit Test ==================*/
63 
64 /*========== Setup and Teardown =============================================*/
65 void setUp(void) {
66 }
67 
68 void tearDown(void) {
69 }
70 
71 /*========== Test Cases =====================================================*/
72 /*
73  * tests for write function
74  */
76  uint8_t reg = 0u;
77  TEST_ASSERT_EQUAL(1u, mxm_41bWriteValue(1u, 1, 0, reg));
78 }
79 
81  uint8_t reg = 0u;
82  TEST_ASSERT_EQUAL(2u, mxm_41bWriteValue(1u, 1, 1, reg));
83 }
84 
86  uint8_t reg = 1u;
87  TEST_ASSERT_EQUAL(3u, mxm_41bWriteValue(1u, 1, 1, reg));
88 }
89 
91  uint8_t reg = 0u;
92  TEST_ASSERT_EQUAL((1u << 5u), mxm_41bWriteValue(1u, 1, MXM_41B_TX_PREAMBLES, reg));
93 }
94 
96  uint8_t reg = 0u;
97  TEST_ASSERT_EQUAL(0xFu, mxm_41bWriteValue(0xFu, 4, MXM_41B_KEEP_ALIVE, reg));
98 }
99 
101  uint8_t reg = 0u;
102  TEST_ASSERT_EQUAL(128u, mxm_41bWriteValue(1u, 1, MXM_41B_RX_ERROR, reg));
103 }
104 
106  uint8_t reg = 0u;
107  TEST_ASSERT_EQUAL(8u, mxm_41bWriteValue(1u, 1, MXM_41B_RX_OVERFLOW_INT_ENABLE, reg));
108 }
109 
110 /*
111  * tests for read function
112  */
114  uint8_t reg = 1u;
115  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, 0));
116 }
117 
119  uint8_t reg = 0xFu;
120  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, 0));
121 }
122 
124  uint8_t reg = 2u;
125  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, 1));
126 }
127 
129  uint8_t reg = 7u;
130  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, 1));
131 }
132 
134  uint8_t reg = 0b100000;
135  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_TX_PREAMBLES));
136 }
137 
139  uint8_t reg = 0b1111;
140  TEST_ASSERT_EQUAL(0xFu, mxm_41bReadValue(reg, 4, MXM_41B_KEEP_ALIVE));
141 }
142 
144  uint8_t reg = 0b1;
145  TEST_ASSERT_EQUAL(0x1u, mxm_41bReadValue(reg, 4, MXM_41B_KEEP_ALIVE));
146 }
147 
149  uint8_t reg = 0b11111;
150  TEST_ASSERT_EQUAL(0xFu, mxm_41bReadValue(reg, 4, MXM_41B_KEEP_ALIVE));
151 }
152 
154  uint8_t reg = 0b10000000;
155  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_RX_ERROR));
156 }
157 
159  uint8_t reg = 0b1000;
160  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_RX_OVERFLOW_INT_ENABLE));
161 }
162 
164  uint8_t reg = 0b100000;
165  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_RX_BUSY_STATUS));
166 }
167 
169  uint8_t reg = 0b1;
170  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_RX_EMPTY_STATUS));
171 }
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
Bit extraction function for MXM_17841b.
#define MXM_41B_KEEP_ALIVE
#define MXM_41B_RX_BUSY_STATUS
#define MXM_41B_RX_EMPTY_STATUS
#define MXM_41B_RX_OVERFLOW_INT_ENABLE
#define MXM_41B_RX_ERROR
#define MXM_41B_TX_PREAMBLES
void testReadValueRXOverflowStatus(void)
void testReadValuePositionOneWithMoreBits(void)
void testWriteValueKeepAlive(void)
void testReadValueKeepAliveFiveBits(void)
void testReadValuePositionZero(void)
void testWriteValuePositionOne(void)
void setUp(void)
void tearDown(void)
void testWriteValueRXErrorInt(void)
void testReadValueKeepAliveOne(void)
void testWriteValuePositionOneWithBitZeroInRegister(void)
void testWriteValueOverflowInt(void)
void testReadValueRXEmptyStatus(void)
void testWriteValueTXPreambles(void)
void testReadValueTXPreambles(void)
void testWriteValuePositionZero(void)
void testReadValuePositionZeroWithMoreBits(void)
void testReadValueRXError(void)
void testReadValueKeepAlive(void)
void testReadValuePositionOne(void)
void testReadValueRXBusy(void)