foxBMS - Unit Tests  1.2.1
The foxBMS Unit Tests API Documentation
test_mxm_bitextract.c
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 test_mxm_bitextract.c
44  * @author foxBMS Team
45  * @date 2020-04-07 (date of creation)
46  * @updated 2020-05-14 (date of last update)
47  * @ingroup UNIT_TEST_IMPLEMENTATION
48  * @prefix TEST
49  *
50  * @brief Test for test_mxm_bitextract.c
51  *
52  * @details def
53  *
54  */
55 
56 /*========== Includes =======================================================*/
57 #include "unity.h"
58 
59 #include "mxm_bitextract.h"
60 
61 /*========== Definitions and Implementations for Unit Test ==================*/
62 
63 /*========== Setup and Teardown =============================================*/
64 void setUp(void) {
65 }
66 
67 void tearDown(void) {
68 }
69 
70 /*========== Test Cases =====================================================*/
71 /*
72  * tests for write function
73  */
75  uint8_t reg = 0u;
76  TEST_ASSERT_EQUAL(1u, mxm_41bWriteValue(1u, 1, 0, reg));
77 }
78 
80  uint8_t reg = 0u;
81  TEST_ASSERT_EQUAL(2u, mxm_41bWriteValue(1u, 1, 1, reg));
82 }
83 
85  uint8_t reg = 1u;
86  TEST_ASSERT_EQUAL(3u, mxm_41bWriteValue(1u, 1, 1, reg));
87 }
88 
90  uint8_t reg = 0u;
91  TEST_ASSERT_EQUAL((1u << 5u), mxm_41bWriteValue(1u, 1, MXM_41B_TX_PREAMBLES, reg));
92 }
93 
95  uint8_t reg = 0u;
96  TEST_ASSERT_EQUAL(0xFu, mxm_41bWriteValue(0xFu, 4, MXM_41B_KEEP_ALIVE, reg));
97 }
98 
100  uint8_t reg = 0u;
101  TEST_ASSERT_EQUAL(128u, mxm_41bWriteValue(1u, 1, MXM_41B_RX_ERROR, reg));
102 }
103 
105  uint8_t reg = 0u;
106  TEST_ASSERT_EQUAL(8u, mxm_41bWriteValue(1u, 1, MXM_41B_RX_OVERFLOW_INT_ENABLE, reg));
107 }
108 
109 /*
110  * tests for read function
111  */
113  uint8_t reg = 1u;
114  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, 0));
115 }
116 
118  uint8_t reg = 0xFu;
119  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, 0));
120 }
121 
123  uint8_t reg = 2u;
124  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, 1));
125 }
126 
128  uint8_t reg = 7u;
129  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, 1));
130 }
131 
133  uint8_t reg = 0b100000;
134  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_TX_PREAMBLES));
135 }
136 
138  uint8_t reg = 0b1111;
139  TEST_ASSERT_EQUAL(0xFu, mxm_41bReadValue(reg, 4, MXM_41B_KEEP_ALIVE));
140 }
141 
143  uint8_t reg = 0b1;
144  TEST_ASSERT_EQUAL(0x1u, mxm_41bReadValue(reg, 4, MXM_41B_KEEP_ALIVE));
145 }
146 
148  uint8_t reg = 0b11111;
149  TEST_ASSERT_EQUAL(0xFu, mxm_41bReadValue(reg, 4, MXM_41B_KEEP_ALIVE));
150 }
151 
153  uint8_t reg = 0b10000000;
154  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_RX_ERROR));
155 }
156 
158  uint8_t reg = 0b1000;
159  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_RX_OVERFLOW_INT_ENABLE));
160 }
161 
163  uint8_t reg = 0b100000;
164  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_RX_BUSY_STATUS));
165 }
166 
168  uint8_t reg = 0b1;
169  TEST_ASSERT_EQUAL(1u, mxm_41bReadValue(reg, 1, MXM_41B_RX_EMPTY_STATUS));
170 }
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)