amiro-os / unittests / periphery-lld / src / ut_alld_at24c01bn-sh-b.c @ 8be006e0
History | View | Annotate | Download (9.555 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 | #include <aos_debug.h> |
||
24 | #include <chprintf.h> |
||
25 | |||
26 | /**
|
||
27 | * @brief EEPROM address for page write/read access.
|
||
28 | */
|
||
29 | #define _pageAddress (AT24C01BN_LLD_SIZE_BYTES - 2*AT24C01BN_LLD_PAGE_SIZE_BYTES) |
||
30 | |||
31 | /**
|
||
32 | * @brief EEPROM address for byte write/read access.
|
||
33 | */
|
||
34 | #define _byteAddress (_pageAddress + AT24C01BN_LLD_PAGE_SIZE_BYTES - 1) |
||
35 | |||
36 | /**
|
||
37 | * @brief Offset for overflow tests.
|
||
38 | */
|
||
39 | #define _overflowOffset 3 |
||
40 | |||
41 | /**
|
||
42 | * @brief EEPROM address for page write/read access with overflow.
|
||
43 | */
|
||
44 | #define _overflowAddress (_pageAddress + _overflowOffset)
|
||
45 | |||
46 | /**
|
||
47 | * @brief Test data byte.
|
||
48 | */
|
||
49 | #define _bytedata 0xA5 |
||
50 | |||
51 | /**
|
||
52 | * @brief AT24C01BN-SH-B unit test function.
|
||
53 | *
|
||
54 | * @param[in] stream Stream for inout/outout.
|
||
55 | * @param[in] ut Unit test object.
|
||
56 | *
|
||
57 | * @return Unit test result value.
|
||
58 | */
|
||
59 | aos_utresult_t utAlldAt24c01bnFunc(BaseSequentialStream* stream, aos_unittest_t* ut) |
||
60 | { |
||
61 | aosDbgCheck(ut->data != NULL && ((ut_at24c01bndata_t*)(ut->data))->driver != NULL); |
||
62 | |||
63 | // local variables
|
||
64 | aos_utresult_t result = {0, 0}; |
||
65 | uint32_t status = 0;
|
||
66 | uint8_t page_data[AT24C01BN_LLD_PAGE_SIZE_BYTES]; |
||
67 | uint8_t original_data[AT24C01BN_LLD_PAGE_SIZE_BYTES]; |
||
68 | uint8_t read_data[AT24C01BN_LLD_PAGE_SIZE_BYTES]; |
||
69 | size_t errors = 0;
|
||
70 | for (size_t dataIdx = 0; dataIdx < AT24C01BN_LLD_PAGE_SIZE_BYTES; ++dataIdx) { |
||
71 | page_data[dataIdx] = dataIdx; |
||
72 | } |
||
73 | |||
74 | chprintf(stream, "reading byte...\n");
|
||
75 | status = at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, original_data, 1, ((ut_at24c01bndata_t*)(ut->data))->timeout);
|
||
76 | if (status == APAL_STATUS_SUCCESS || status == APAL_STATUS_WARNING) {
|
||
77 | aosUtPassed(stream, &result); |
||
78 | } else {
|
||
79 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
80 | } |
||
81 | |||
82 | chprintf(stream, "writing byte...\n");
|
||
83 | status = at24c01bn_lld_write_byte(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, _bytedata, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
84 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
85 | continue;
|
||
86 | } |
||
87 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, &read_data[0], 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
88 | status |= (read_data[0] == _bytedata) ? 0x00 : 0x20; |
||
89 | status = at24c01bn_lld_write_byte(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, (uint8_t)~_bytedata, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
90 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
91 | continue;
|
||
92 | } |
||
93 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, &read_data[1], 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
94 | status |= (read_data[1] == (uint8_t)~_bytedata) ? 0x00 : 0x40; |
||
95 | status |= at24c01bn_lld_write_byte(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, original_data[0], ((ut_at24c01bndata_t*)(ut->data))->timeout);
|
||
96 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
97 | continue;
|
||
98 | } |
||
99 | status |= at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _byteAddress, &read_data[2], 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
100 | status |= (read_data[2] == original_data[0]) ? 0x00 : 0x80; |
||
101 | if (status == APAL_STATUS_SUCCESS || status == APAL_STATUS_WARNING) {
|
||
102 | aosUtPassed(stream, &result); |
||
103 | } else {
|
||
104 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
105 | } |
||
106 | |||
107 | chprintf(stream, "reading page...\n");
|
||
108 | status = at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _pageAddress, original_data, AT24C01BN_LLD_PAGE_SIZE_BYTES, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
109 | if (status == APAL_STATUS_SUCCESS) {
|
||
110 | aosUtPassed(stream, &result); |
||
111 | } else {
|
||
112 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
113 | } |
||
114 | |||
115 | chprintf(stream, "writing page...\n");
|
||
116 | 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); |
||
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, _pageAddress, read_data, AT24C01BN_LLD_PAGE_SIZE_BYTES, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
121 | errors = 0;
|
||
122 | for (size_t dataIdx = 0; dataIdx < AT24C01BN_LLD_PAGE_SIZE_BYTES; dataIdx++) { |
||
123 | if (read_data[dataIdx] != page_data[dataIdx]) {
|
||
124 | ++errors; |
||
125 | } |
||
126 | } |
||
127 | if (status == APAL_STATUS_OK && errors == 0) { |
||
128 | aosUtPassed(stream, &result); |
||
129 | } else {
|
||
130 | aosUtFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
||
131 | } |
||
132 | |||
133 | chprintf(stream, "reading page at current address...\n");
|
||
134 | // set address counter to UT_ALLD_AT24C01BN_PAGE_ADDRESS
|
||
135 | status = at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _pageAddress-1, read_data, 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
136 | if (status == APAL_STATUS_WARNING) {
|
||
137 | // on STM32F1 platform the address gets incremented by 2 after reading
|
||
138 | status = at24c01bn_lld_read(((ut_at24c01bndata_t*)(ut->data))->driver, _pageAddress-2, read_data, 1, ((ut_at24c01bndata_t*)(ut->data))->timeout); |
||
139 | } |
||
140 | // read page from the current address
|
||
141 | 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); |
||
142 | errors = 0;
|
||
143 | for (uint8_t dataIdx = 0; dataIdx < 8; 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, "writing page with overflow (7 bytes)...\n");
|
||
155 | 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);
|
||
156 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
157 | continue;
|
||
158 | } |
||
159 | 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); |
||
160 | 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);
|
||
161 | errors = 0;
|
||
162 | for (uint8_t dataIdx = 0; dataIdx < AT24C01BN_LLD_PAGE_SIZE_BYTES-1; dataIdx++) { |
||
163 | if (read_data[dataIdx] != page_data[dataIdx]) {
|
||
164 | ++errors; |
||
165 | } |
||
166 | } |
||
167 | if (status == APAL_STATUS_OK && errors == 0) { |
||
168 | aosUtPassed(stream, &result); |
||
169 | } else {
|
||
170 | aosUtFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
||
171 | } |
||
172 | |||
173 | chprintf(stream, "writing page with overflow (8 bytes)...\n");
|
||
174 | 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); |
||
175 | while (at24c01bn_lld_poll_ack(((ut_at24c01bndata_t*)(ut->data))->driver, ((ut_at24c01bndata_t*)(ut->data))->timeout) == APAL_STATUS_FAILURE) {
|
||
176 | continue;
|
||
177 | } |
||
178 | 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); |
||
179 | 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); |
||
180 | errors = 0;
|
||
181 | for (uint8_t dataIdx = 0; dataIdx < AT24C01BN_LLD_PAGE_SIZE_BYTES; dataIdx++) { |
||
182 | if (read_data[dataIdx] != page_data[dataIdx]) {
|
||
183 | ++errors; |
||
184 | } |
||
185 | } |
||
186 | if (status == APAL_STATUS_OK && errors == 0) { |
||
187 | aosUtPassed(stream, &result); |
||
188 | } else {
|
||
189 | aosUtFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
||
190 | } |
||
191 | |||
192 | chprintf(stream, "write back original data...\n");
|
||
193 | 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); |
||
194 | if (status == APAL_STATUS_SUCCESS) {
|
||
195 | aosUtPassed(stream, &result); |
||
196 | } else {
|
||
197 | aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
||
198 | } |
||
199 | |||
200 | aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(AT24C01BNDriver)); |
||
201 | |||
202 | return result;
|
||
203 | } |
||
204 | |||
205 | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_AT24C01BN) */ |