amiro-os / unittests / periphery-lld / src / ut_alld_at24c01bn-sh-b.c @ 7da800ab
History | View | Annotate | Download (10.939 KB)
1 | e545e620 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | 84f0ce9e | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 | e545e620 | Thomas Schöpping | |
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | #include <ut_alld_at24c01bn-sh-b.h> |
||
20 | |||
21 | #if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_AT24C01BN)) || defined(__DOXYGEN__) |
||
22 | |||
23 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
24 | /* LOCAL DEFINITIONS */
|
||
25 | /******************************************************************************/
|
||
26 | e545e620 | Thomas Schöpping | |
27 | /**
|
||
28 | * @brief EEPROM address for page write/read access.
|
||
29 | */
|
||
30 | #define _pageAddress (AT24C01BN_LLD_SIZE_BYTES - 2*AT24C01BN_LLD_PAGE_SIZE_BYTES) |
||
31 | |||
32 | /**
|
||
33 | * @brief EEPROM address for byte write/read access.
|
||
34 | */
|
||
35 | #define _byteAddress (_pageAddress + AT24C01BN_LLD_PAGE_SIZE_BYTES - 1) |
||
36 | |||
37 | /**
|
||
38 | * @brief Offset for overflow tests.
|
||
39 | */
|
||
40 | #define _overflowOffset 3 |
||
41 | |||
42 | /**
|
||
43 | * @brief EEPROM address for page write/read access with overflow.
|
||
44 | */
|
||
45 | #define _overflowAddress (_pageAddress + _overflowOffset)
|
||
46 | |||
47 | /**
|
||
48 | * @brief Test data byte.
|
||
49 | */
|
||
50 | #define _bytedata 0xA5 |
||
51 | |||
52 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
53 | /* EXPORTED VARIABLES */
|
||
54 | /******************************************************************************/
|
||
55 | |||
56 | /******************************************************************************/
|
||
57 | /* LOCAL TYPES */
|
||
58 | /******************************************************************************/
|
||
59 | |||
60 | /******************************************************************************/
|
||
61 | /* LOCAL VARIABLES */
|
||
62 | /******************************************************************************/
|
||
63 | |||
64 | /******************************************************************************/
|
||
65 | /* LOCAL FUNCTIONS */
|
||
66 | /******************************************************************************/
|
||
67 | |||
68 | /******************************************************************************/
|
||
69 | /* EXPORTED FUNCTIONS */
|
||
70 | /******************************************************************************/
|
||
71 | |||
72 | e545e620 | Thomas Schöpping | /**
|
73 | * @brief AT24C01BN-SH-B unit test function.
|
||
74 | *
|
||
75 | * @param[in] stream Stream for inout/outout.
|
||
76 | * @param[in] ut Unit test object.
|
||
77 | *
|
||
78 | * @return Unit test result value.
|
||
79 | */
|
||
80 | aos_utresult_t utAlldAt24c01bnFunc(BaseSequentialStream* stream, aos_unittest_t* ut) |
||
81 | { |
||
82 | aosDbgCheck(ut->data != NULL && ((ut_at24c01bndata_t*)(ut->data))->driver != NULL); |
||
83 | |||
84 | // local variables
|
||
85 | aos_utresult_t result = {0, 0}; |
||
86 | uint32_t status = 0;
|
||
87 | uint8_t page_data[AT24C01BN_LLD_PAGE_SIZE_BYTES]; |
||
88 | uint8_t original_data[AT24C01BN_LLD_PAGE_SIZE_BYTES]; |
||
89 | uint8_t read_data[AT24C01BN_LLD_PAGE_SIZE_BYTES]; |
||
90 | size_t errors = 0;
|
||
91 | for (size_t dataIdx = 0; dataIdx < AT24C01BN_LLD_PAGE_SIZE_BYTES; ++dataIdx) { |
||
92 | page_data[dataIdx] = dataIdx; |
||
93 | } |
||
94 | |||
95 | chprintf(stream, "reading byte...\n");
|
||
96 | status = at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, original_data, 1, ((ut_at24c01bndata_t*)(ut->data))->timeout);
|
||
97 | if (status == APAL_STATUS_SUCCESS || status == APAL_STATUS_WARNING) {
|
||
98 | aosUtPassed(stream, &result); |
||
99 | } else {
|
||
100 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
101 | } |
||
102 | |||
103 | chprintf(stream, "writing byte...\n");
|
||
104 | status = at24c01bn_lld_write_byte(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, _bytedata, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
105 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
106 | continue;
|
||
107 | } |
||
108 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, &read_data[0], 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
109 | status |= (read_data[0] == _bytedata) ? 0x00 : 0x20; |
||
110 | status = at24c01bn_lld_write_byte(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, (uint8_t)~_bytedata, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
111 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
112 | continue;
|
||
113 | } |
||
114 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, &read_data[1], 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
115 | status |= (read_data[1] == (uint8_t)~_bytedata) ? 0x00 : 0x40; |
||
116 | status |= at24c01bn_lld_write_byte(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, original_data[0], ((ut_at24c01bndata_t*)(ut->data))->timeout);
|
||
117 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
118 | continue;
|
||
119 | } |
||
120 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, &read_data[2], 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
121 | status |= (read_data[2] == original_data[0]) ? 0x00 : 0x80; |
||
122 | if (status == APAL_STATUS_SUCCESS || status == APAL_STATUS_WARNING) {
|
||
123 | aosUtPassed(stream, &result); |
||
124 | } else {
|
||
125 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
126 | } |
||
127 | |||
128 | chprintf(stream, "reading page...\n");
|
||
129 | status = at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _pageAddress, original_data, AT24C01BN_LLD_PAGE_SIZE_BYTES, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
130 | if (status == APAL_STATUS_SUCCESS) {
|
||
131 | aosUtPassed(stream, &result); |
||
132 | } else {
|
||
133 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
134 | } |
||
135 | |||
136 | chprintf(stream, "writing page...\n");
|
||
137 | status = at24c01bn_lld_write_page(((ut_at24c01bndata_t*)(ut->data))->driver, _pageAddress, page_data, AT24C01BN_LLD_PAGE_SIZE_BYTES, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
138 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
139 | continue;
|
||
140 | } |
||
141 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _pageAddress, read_data, AT24C01BN_LLD_PAGE_SIZE_BYTES, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
142 | errors = 0;
|
||
143 | for (size_t dataIdx = 0; dataIdx < AT24C01BN_LLD_PAGE_SIZE_BYTES; dataIdx++) { |
||
144 | if (read_data[dataIdx] != page_data[dataIdx]) {
|
||
145 | ++errors; |
||
146 | } |
||
147 | } |
||
148 | if (status == APAL_STATUS_OK && errors == 0) { |
||
149 | aosUtPassed(stream, &result); |
||
150 | } else {
|
||
151 | aosUtFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
||
152 | } |
||
153 | |||
154 | chprintf(stream, "reading page at current address...\n");
|
||
155 | // set address counter to UT_ALLD_AT24C01BN_PAGE_ADDRESS
|
||
156 | status = at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _pageAddress-1, read_data, 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
157 | if (status == APAL_STATUS_WARNING) {
|
||
158 | // on STM32F1 platform the address gets incremented by 2 after reading
|
||
159 | status = at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _pageAddress-2, read_data, 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
160 | } |
||
161 | // read page from the current address
|
||
162 | status = at24c01bn_lld_read_current_address(((ut_at24c01bndata_t*)(ut->data))->driver, read_data, AT24C01BN_LLD_PAGE_SIZE_BYTES, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
163 | errors = 0;
|
||
164 | for (uint8_t dataIdx = 0; dataIdx < 8; dataIdx++) { |
||
165 | if (read_data[dataIdx] != page_data[dataIdx]) {
|
||
166 | ++errors; |
||
167 | } |
||
168 | } |
||
169 | if (status == APAL_STATUS_OK && errors == 0) { |
||
170 | aosUtPassed(stream, &result); |
||
171 | } else {
|
||
172 | aosUtFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
||
173 | } |
||
174 | |||
175 | chprintf(stream, "writing page with overflow (7 bytes)...\n");
|
||
176 | status = at24c01bn_lld_write_page(((ut_at24c01bndata_t*)(ut->data))->driver, _overflowAddress, page_data, AT24C01BN_LLD_PAGE_SIZE_BYTES-1, ((ut_at24c01bndata_t*)(ut->data))->timeout);
|
||
177 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
178 | continue;
|
||
179 | } |
||
180 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _overflowAddress, read_data, AT24C01BN_LLD_PAGE_SIZE_BYTES-_overflowOffset, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
181 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _overflowAddress-_overflowOffset, read_data+(AT24C01BN_LLD_PAGE_SIZE_BYTES-_overflowOffset), _overflowOffset-1, ((ut_at24c01bndata_t*)(ut->data))->timeout);
|
||
182 | errors = 0;
|
||
183 | for (uint8_t dataIdx = 0; dataIdx < AT24C01BN_LLD_PAGE_SIZE_BYTES-1; dataIdx++) { |
||
184 | if (read_data[dataIdx] != page_data[dataIdx]) {
|
||
185 | ++errors; |
||
186 | } |
||
187 | } |
||
188 | if (status == APAL_STATUS_OK && errors == 0) { |
||
189 | aosUtPassed(stream, &result); |
||
190 | } else {
|
||
191 | aosUtFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
||
192 | } |
||
193 | |||
194 | chprintf(stream, "writing page with overflow (8 bytes)...\n");
|
||
195 | status = at24c01bn_lld_write_page(((ut_at24c01bndata_t*)(ut->data))->driver, _overflowAddress, page_data, AT24C01BN_LLD_PAGE_SIZE_BYTES, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
196 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
197 | continue;
|
||
198 | } |
||
199 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _overflowAddress, read_data, AT24C01BN_LLD_PAGE_SIZE_BYTES-_overflowOffset, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
200 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _overflowAddress-_overflowOffset, read_data+(AT24C01BN_LLD_PAGE_SIZE_BYTES-_overflowOffset), _overflowOffset, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
201 | errors = 0;
|
||
202 | for (uint8_t dataIdx = 0; dataIdx < AT24C01BN_LLD_PAGE_SIZE_BYTES; dataIdx++) { |
||
203 | if (read_data[dataIdx] != page_data[dataIdx]) {
|
||
204 | ++errors; |
||
205 | } |
||
206 | } |
||
207 | if (status == APAL_STATUS_OK && errors == 0) { |
||
208 | aosUtPassed(stream, &result); |
||
209 | } else {
|
||
210 | aosUtFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
||
211 | } |
||
212 | |||
213 | chprintf(stream, "write back original data...\n");
|
||
214 | status = at24c01bn_lld_write_page(((ut_at24c01bndata_t*)(ut->data))->driver, _pageAddress, original_data, AT24C01BN_LLD_PAGE_SIZE_BYTES, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
215 | if (status == APAL_STATUS_SUCCESS) {
|
||
216 | aosUtPassed(stream, &result); |
||
217 | } else {
|
||
218 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
219 | } |
||
220 | |||
221 | aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(AT24C01BNDriver)); |
||
222 | |||
223 | return result;
|
||
224 | } |
||
225 | |||
226 | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_AT24C01BN) */ |