amiro-os / test / periphery-lld / AT24C01B_v1 / aos_test_AT24C01B.c @ ab5cad1b
History | View | Annotate | Download (11.23 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2020 Thomas Schöpping et al.
|
4 |
|
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 <amiroos.h> |
20 |
#include <aos_test_AT24C01B.h> |
21 |
|
22 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
23 |
|
24 |
/******************************************************************************/
|
25 |
/* LOCAL DEFINITIONS */
|
26 |
/******************************************************************************/
|
27 |
|
28 |
/**
|
29 |
* @brief EEPROM address for page write/read access.
|
30 |
*/
|
31 |
#define _pageAddress (AT24C01B_LLD_SIZE_BYTES - 2*AT24C01B_LLD_PAGE_SIZE_BYTES) |
32 |
|
33 |
/**
|
34 |
* @brief EEPROM address for byte write/read access.
|
35 |
*/
|
36 |
#define _byteAddress (_pageAddress + AT24C01B_LLD_PAGE_SIZE_BYTES - 1) |
37 |
|
38 |
/**
|
39 |
* @brief Offset for overflow tests.
|
40 |
*/
|
41 |
#define _overflowOffset 3 |
42 |
|
43 |
/**
|
44 |
* @brief EEPROM address for page write/read access with overflow.
|
45 |
*/
|
46 |
#define _overflowAddress (_pageAddress + _overflowOffset)
|
47 |
|
48 |
/**
|
49 |
* @brief Test data byte.
|
50 |
*/
|
51 |
#define _bytedata 0xA5 |
52 |
|
53 |
/******************************************************************************/
|
54 |
/* EXPORTED VARIABLES */
|
55 |
/******************************************************************************/
|
56 |
|
57 |
/******************************************************************************/
|
58 |
/* LOCAL TYPES */
|
59 |
/******************************************************************************/
|
60 |
|
61 |
/******************************************************************************/
|
62 |
/* LOCAL VARIABLES */
|
63 |
/******************************************************************************/
|
64 |
|
65 |
/******************************************************************************/
|
66 |
/* LOCAL FUNCTIONS */
|
67 |
/******************************************************************************/
|
68 |
|
69 |
/******************************************************************************/
|
70 |
/* EXPORTED FUNCTIONS */
|
71 |
/******************************************************************************/
|
72 |
|
73 |
/**
|
74 |
* @brief AT24C01B test function.
|
75 |
*
|
76 |
* @param[in] stream Stream for input/output.
|
77 |
* @param[in] test Test object.
|
78 |
*
|
79 |
* @return Test result value.
|
80 |
*/
|
81 |
aos_testresult_t aosTestAt24c01bFunc(BaseSequentialStream* stream, const aos_test_t* test)
|
82 |
{ |
83 |
aosDbgCheck(test->data != NULL && ((aos_test_at24c01bdata_t*)(test->data))->driver != NULL); |
84 |
|
85 |
// local variables
|
86 |
aos_testresult_t result; |
87 |
int32_t status; |
88 |
uint8_t page_data[AT24C01B_LLD_PAGE_SIZE_BYTES]; |
89 |
uint8_t original_data[AT24C01B_LLD_PAGE_SIZE_BYTES]; |
90 |
uint8_t read_data[AT24C01B_LLD_PAGE_SIZE_BYTES]; |
91 |
size_t errors = 0;
|
92 |
|
93 |
aosTestResultInit(&result); |
94 |
for (size_t dataIdx = 0; dataIdx < AT24C01B_LLD_PAGE_SIZE_BYTES; ++dataIdx) { |
95 |
page_data[dataIdx] = dataIdx; |
96 |
} |
97 |
|
98 |
chprintf(stream, "reading byte...\n");
|
99 |
status = at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _byteAddress, original_data, 1, ((aos_test_at24c01bdata_t*)(test->data))->timeout);
|
100 |
if (status == APAL_STATUS_SUCCESS || status == APAL_STATUS_WARNING) {
|
101 |
aosTestPassed(stream, &result); |
102 |
} else {
|
103 |
aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
104 |
} |
105 |
|
106 |
chprintf(stream, "writing byte...\n");
|
107 |
status = at24c01b_lld_write_byte(((aos_test_at24c01bdata_t*)(test->data))->driver, _byteAddress, _bytedata, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
108 |
while (at24c01b_lld_poll_ack(((aos_test_at24c01bdata_t*)(test->data))->driver, ((aos_test_at24c01bdata_t*)(test->data))->timeout) == APAL_STATUS_FAILURE) {
|
109 |
continue;
|
110 |
} |
111 |
status |= at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _byteAddress, &read_data[0], 1, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
112 |
status |= (read_data[0] == _bytedata) ? 0x00 : 0x20; |
113 |
status = at24c01b_lld_write_byte(((aos_test_at24c01bdata_t*)(test->data))->driver, _byteAddress, (uint8_t)~_bytedata, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
114 |
while (at24c01b_lld_poll_ack(((aos_test_at24c01bdata_t*)(test->data))->driver, ((aos_test_at24c01bdata_t*)(test->data))->timeout) == APAL_STATUS_FAILURE) {
|
115 |
continue;
|
116 |
} |
117 |
status |= at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _byteAddress, &read_data[1], 1, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
118 |
status |= (read_data[1] == (uint8_t)~_bytedata) ? 0x00 : 0x40; |
119 |
status |= at24c01b_lld_write_byte(((aos_test_at24c01bdata_t*)(test->data))->driver, _byteAddress, original_data[0], ((aos_test_at24c01bdata_t*)(test->data))->timeout);
|
120 |
while (at24c01b_lld_poll_ack(((aos_test_at24c01bdata_t*)(test->data))->driver, ((aos_test_at24c01bdata_t*)(test->data))->timeout) == APAL_STATUS_FAILURE) {
|
121 |
continue;
|
122 |
} |
123 |
status |= at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _byteAddress, &read_data[2], 1, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
124 |
status |= (read_data[2] == original_data[0]) ? 0x00 : 0x80; |
125 |
if (status == APAL_STATUS_SUCCESS || status == APAL_STATUS_WARNING) {
|
126 |
aosTestPassed(stream, &result); |
127 |
} else {
|
128 |
aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
129 |
} |
130 |
|
131 |
chprintf(stream, "reading page...\n");
|
132 |
status = at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _pageAddress, original_data, AT24C01B_LLD_PAGE_SIZE_BYTES, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
133 |
if (status == APAL_STATUS_SUCCESS) {
|
134 |
aosTestPassed(stream, &result); |
135 |
} else {
|
136 |
aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
137 |
} |
138 |
|
139 |
chprintf(stream, "writing page...\n");
|
140 |
status = at24c01b_lld_write_page(((aos_test_at24c01bdata_t*)(test->data))->driver, _pageAddress, page_data, AT24C01B_LLD_PAGE_SIZE_BYTES, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
141 |
while (at24c01b_lld_poll_ack(((aos_test_at24c01bdata_t*)(test->data))->driver, ((aos_test_at24c01bdata_t*)(test->data))->timeout) == APAL_STATUS_FAILURE) {
|
142 |
continue;
|
143 |
} |
144 |
status |= at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _pageAddress, read_data, AT24C01B_LLD_PAGE_SIZE_BYTES, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
145 |
errors = 0;
|
146 |
for (size_t dataIdx = 0; dataIdx < AT24C01B_LLD_PAGE_SIZE_BYTES; dataIdx++) { |
147 |
if (read_data[dataIdx] != page_data[dataIdx]) {
|
148 |
++errors; |
149 |
} |
150 |
} |
151 |
if (status == APAL_STATUS_OK && errors == 0) { |
152 |
aosTestPassed(stream, &result); |
153 |
} else {
|
154 |
aosTestFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
155 |
} |
156 |
|
157 |
chprintf(stream, "reading page at current address...\n");
|
158 |
// set address counter to UT_ALLD_AT24C01B_PAGE_ADDRESS
|
159 |
status = at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _pageAddress-1, read_data, 1, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
160 |
if (status == APAL_STATUS_WARNING) {
|
161 |
// on STM32F1 platform the address gets incremented by 2 after reading
|
162 |
status = at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _pageAddress-2, read_data, 1, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
163 |
} |
164 |
// read page from the current address
|
165 |
status = at24c01b_lld_read_current_address(((aos_test_at24c01bdata_t*)(test->data))->driver, read_data, AT24C01B_LLD_PAGE_SIZE_BYTES, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
166 |
errors = 0;
|
167 |
for (uint8_t dataIdx = 0; dataIdx < 8; dataIdx++) { |
168 |
if (read_data[dataIdx] != page_data[dataIdx]) {
|
169 |
++errors; |
170 |
} |
171 |
} |
172 |
if (status == APAL_STATUS_OK && errors == 0) { |
173 |
aosTestPassed(stream, &result); |
174 |
} else {
|
175 |
aosTestFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
176 |
} |
177 |
|
178 |
chprintf(stream, "writing page with overflow (7 bytes)...\n");
|
179 |
status = at24c01b_lld_write_page(((aos_test_at24c01bdata_t*)(test->data))->driver, _overflowAddress, page_data, AT24C01B_LLD_PAGE_SIZE_BYTES-1, ((aos_test_at24c01bdata_t*)(test->data))->timeout);
|
180 |
while (at24c01b_lld_poll_ack(((aos_test_at24c01bdata_t*)(test->data))->driver, ((aos_test_at24c01bdata_t*)(test->data))->timeout) == APAL_STATUS_FAILURE) {
|
181 |
continue;
|
182 |
} |
183 |
status |= at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _overflowAddress, read_data, AT24C01B_LLD_PAGE_SIZE_BYTES-_overflowOffset, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
184 |
status |= at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _overflowAddress-_overflowOffset, read_data+(AT24C01B_LLD_PAGE_SIZE_BYTES-_overflowOffset), _overflowOffset-1, ((aos_test_at24c01bdata_t*)(test->data))->timeout);
|
185 |
errors = 0;
|
186 |
for (uint8_t dataIdx = 0; dataIdx < AT24C01B_LLD_PAGE_SIZE_BYTES-1; dataIdx++) { |
187 |
if (read_data[dataIdx] != page_data[dataIdx]) {
|
188 |
++errors; |
189 |
} |
190 |
} |
191 |
if (status == APAL_STATUS_OK && errors == 0) { |
192 |
aosTestPassed(stream, &result); |
193 |
} else {
|
194 |
aosTestFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
195 |
} |
196 |
|
197 |
chprintf(stream, "writing page with overflow (8 bytes)...\n");
|
198 |
status = at24c01b_lld_write_page(((aos_test_at24c01bdata_t*)(test->data))->driver, _overflowAddress, page_data, AT24C01B_LLD_PAGE_SIZE_BYTES, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
199 |
while (at24c01b_lld_poll_ack(((aos_test_at24c01bdata_t*)(test->data))->driver, ((aos_test_at24c01bdata_t*)(test->data))->timeout) == APAL_STATUS_FAILURE) {
|
200 |
continue;
|
201 |
} |
202 |
status |= at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _overflowAddress, read_data, AT24C01B_LLD_PAGE_SIZE_BYTES-_overflowOffset, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
203 |
status |= at24c01b_lld_read(((aos_test_at24c01bdata_t*)(test->data))->driver, _overflowAddress-_overflowOffset, read_data+(AT24C01B_LLD_PAGE_SIZE_BYTES-_overflowOffset), _overflowOffset, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
204 |
errors = 0;
|
205 |
for (uint8_t dataIdx = 0; dataIdx < AT24C01B_LLD_PAGE_SIZE_BYTES; dataIdx++) { |
206 |
if (read_data[dataIdx] != page_data[dataIdx]) {
|
207 |
++errors; |
208 |
} |
209 |
} |
210 |
if (status == APAL_STATUS_OK && errors == 0) { |
211 |
aosTestPassed(stream, &result); |
212 |
} else {
|
213 |
aosTestFailedMsg(stream, &result, "0x%08X; %u\n", status, errors);
|
214 |
} |
215 |
|
216 |
chprintf(stream, "write back original data...\n");
|
217 |
status = at24c01b_lld_write_page(((aos_test_at24c01bdata_t*)(test->data))->driver, _pageAddress, original_data, AT24C01B_LLD_PAGE_SIZE_BYTES, ((aos_test_at24c01bdata_t*)(test->data))->timeout); |
218 |
if (status == APAL_STATUS_SUCCESS) {
|
219 |
aosTestPassed(stream, &result); |
220 |
} else {
|
221 |
aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
222 |
} |
223 |
|
224 |
aosTestInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(AT24C01BDriver)); |
225 |
|
226 |
return result;
|
227 |
} |
228 |
|
229 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |