amiro-os / test / periphery-lld / PCAL6524_v1 / aos_test_PCAL6524.c @ d796dcdf
History | View | Annotate | Download (9.633 KB)
1 | bffb3465 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2019 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 | ddf34c3d | Thomas Schöpping | #include <amiroos.h> |
20 | 4c72a54c | Thomas Schöpping | #include <aos_test_PCAL6524.h> |
21 | bffb3465 | Thomas Schöpping | |
22 | 4c72a54c | Thomas Schöpping | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
23 | bffb3465 | Thomas Schöpping | |
24 | #include <string.h> |
||
25 | |||
26 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
27 | /* LOCAL DEFINITIONS */
|
||
28 | /******************************************************************************/
|
||
29 | |||
30 | /******************************************************************************/
|
||
31 | /* EXPORTED VARIABLES */
|
||
32 | /******************************************************************************/
|
||
33 | |||
34 | /******************************************************************************/
|
||
35 | /* LOCAL TYPES */
|
||
36 | /******************************************************************************/
|
||
37 | |||
38 | /******************************************************************************/
|
||
39 | /* LOCAL VARIABLES */
|
||
40 | /******************************************************************************/
|
||
41 | |||
42 | /******************************************************************************/
|
||
43 | /* LOCAL FUNCTIONS */
|
||
44 | /******************************************************************************/
|
||
45 | |||
46 | /******************************************************************************/
|
||
47 | /* EXPORTED FUNCTIONS */
|
||
48 | /******************************************************************************/
|
||
49 | |||
50 | 4c72a54c | Thomas Schöpping | aos_testresult_t aosTestPcal6524Func(BaseSequentialStream* stream, const aos_test_t* test)
|
51 | bffb3465 | Thomas Schöpping | { |
52 | 4c72a54c | Thomas Schöpping | aosDbgCheck((test->data != NULL) && (((aos_test_pcal6524data_t*)test->data)->pcal6524d != NULL)); |
53 | bffb3465 | Thomas Schöpping | |
54 | // local variables
|
||
55 | ce12e797 | Thomas Schöpping | aos_testresult_t result; |
56 | b23ca7cc | Thomas Schöpping | int32_t status; |
57 | bffb3465 | Thomas Schöpping | uint8_t buffer[24];
|
58 | memset(buffer, 0xAA, sizeof(buffer)); |
||
59 | |||
60 | ce12e797 | Thomas Schöpping | aosTestResultInit(&result); |
61 | |||
62 | bffb3465 | Thomas Schöpping | // This test is currently not supported. See PCAL6524 driver implementation for further information.
|
63 | // chprintf(stream, "reading device ID...\n");
|
||
64 | 4c72a54c | Thomas Schöpping | // status = pcal6524_lld_read_id(((aos_test_pcal6524data_t*)test->data)->pcal6524d, buffer, ((aos_test_pcal6524data_t*)test->data)->timeout);
|
65 | bffb3465 | Thomas Schöpping | // chprintf(stream, "\t\traw: 0x%02X 0x%02X 0x%02X\n", buffer[0], buffer[1], buffer[2]);
|
66 | // chprintf(stream, "\t\tname: 0x%03X\n", ((pcal6524_lld_deviceid_t*)buffer)->name);
|
||
67 | // chprintf(stream, "\t\tpart: 0x%03X\n", ((pcal6524_lld_deviceid_t*)buffer)->part);
|
||
68 | // chprintf(stream, "\t\trevision: 0x%01X\n", ((pcal6524_lld_deviceid_t*)buffer)->revision);
|
||
69 | // if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
|
||
70 | 4c72a54c | Thomas Schöpping | // aosTestPassed(stream, &result);
|
71 | bffb3465 | Thomas Schöpping | // } else {
|
72 | 4c72a54c | Thomas Schöpping | // aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
73 | bffb3465 | Thomas Schöpping | // }
|
74 | |||
75 | chprintf(stream, "reading register...\n");
|
||
76 | 4c72a54c | Thomas Schöpping | status = pcal6524_lld_read_reg(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer, ((aos_test_pcal6524data_t*)test->data)->timeout); |
77 | bffb3465 | Thomas Schöpping | chprintf(stream, "\t\tdebounce count: %u\n", buffer[0]); |
78 | if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
|
||
79 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
80 | bffb3465 | Thomas Schöpping | } else {
|
81 | 4c72a54c | Thomas Schöpping | aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
82 | bffb3465 | Thomas Schöpping | } |
83 | |||
84 | chprintf(stream, "writing register...\n");
|
||
85 | buffer[3] = 0xFF; |
||
86 | 4c72a54c | Thomas Schöpping | status = pcal6524_lld_write_reg(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer[3], ((aos_test_pcal6524data_t*)test->data)->timeout);
|
87 | status |= pcal6524_lld_read_reg(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, &buffer[4], ((aos_test_pcal6524data_t*)test->data)->timeout);
|
||
88 | status |= pcal6524_lld_write_reg(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, buffer[0], ((aos_test_pcal6524data_t*)test->data)->timeout);
|
||
89 | status |= pcal6524_lld_read_reg(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_SWITCHDEBOUNCECOUNT, &buffer[1], ((aos_test_pcal6524data_t*)test->data)->timeout);
|
||
90 | bffb3465 | Thomas Schöpping | if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
|
91 | ((buffer[1] == buffer[0]) && (buffer[4] == buffer[3]))) { |
||
92 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
93 | bffb3465 | Thomas Schöpping | } else {
|
94 | 4c72a54c | Thomas Schöpping | aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
95 | bffb3465 | Thomas Schöpping | } |
96 | |||
97 | chprintf(stream, "reading group...\n");
|
||
98 | 4c72a54c | Thomas Schöpping | status = pcal6524_lld_read_group(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, buffer, ((aos_test_pcal6524data_t*)test->data)->timeout); |
99 | bffb3465 | Thomas Schöpping | chprintf(stream, "\t\toutput drive strength: 0x%04X 0x%04X 0x%04X\n",
|
100 | (((uint16_t)buffer[0]) << 8) | buffer[1], |
||
101 | (((uint16_t)buffer[2]) << 8) | buffer[3], |
||
102 | (((uint16_t)buffer[4]) << 8) | buffer[5]); |
||
103 | if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
|
||
104 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
105 | bffb3465 | Thomas Schöpping | } else {
|
106 | 4c72a54c | Thomas Schöpping | aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
107 | bffb3465 | Thomas Schöpping | } |
108 | |||
109 | chprintf(stream, "writing group...\n");
|
||
110 | memset(&buffer[6], PCAL6524_LL_OUTPUTDRIVESTRENGTH_0_25, 6); |
||
111 | 4c72a54c | Thomas Schöpping | status = pcal6524_lld_write_group(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[6], ((aos_test_pcal6524data_t*)test->data)->timeout);
|
112 | status |= pcal6524_lld_read_group(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[12], ((aos_test_pcal6524data_t*)test->data)->timeout);
|
||
113 | status |= pcal6524_lld_write_group(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[0], ((aos_test_pcal6524data_t*)test->data)->timeout);
|
||
114 | status |= pcal6524_lld_read_group(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUTDRIVESTRENGTH_P0A, &buffer[18], ((aos_test_pcal6524data_t*)test->data)->timeout);
|
||
115 | bffb3465 | Thomas Schöpping | if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
|
116 | ((memcmp(&buffer[12], &buffer[6], 6) == 0) && (memcmp(&buffer[18], &buffer[0], 6) == 0))) { |
||
117 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
118 | bffb3465 | Thomas Schöpping | } else {
|
119 | 4c72a54c | Thomas Schöpping | aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
120 | bffb3465 | Thomas Schöpping | } |
121 | |||
122 | chprintf(stream, "reading continuously...\n");
|
||
123 | // read the following registers continously (24 bytes):
|
||
124 | // output 0-3 + polarity inversions 0-3 + configuration 0-3 + output drive strength 0A-2B + input latch 0-3 + pupd enable 0-3 + pupd selection 0-3
|
||
125 | 4c72a54c | Thomas Schöpping | status = pcal6524_lld_read_continuous(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, buffer, 24, ((aos_test_pcal6524data_t*)test->data)->timeout);
|
126 | bffb3465 | Thomas Schöpping | chprintf(stream, "\t\toutput: 0x%02X 0x%02X 0x%02X\n", buffer[0], buffer[1], buffer[2]); |
127 | chprintf(stream, "\t\tpolarity inversion: 0x%02X 0x%02X 0x%02X\n", buffer[3], buffer[4], buffer[5]); |
||
128 | chprintf(stream, "\t\tconfiguration: 0x%02X 0x%02X 0x%02X\n", buffer[6], buffer[7], buffer[8]); |
||
129 | chprintf(stream, "\t\toutput drive strength: 0x%04X 0x%04X 0x%04X\n",
|
||
130 | (((uint16_t)buffer[9]) << 8) | buffer[10], |
||
131 | (((uint16_t)buffer[11]) << 8) | buffer[12], |
||
132 | (((uint16_t)buffer[13]) << 8) | buffer[14]); |
||
133 | chprintf(stream, "\t\tinput latch: 0x%02X 0x%02X 0x%02X\n", buffer[15], buffer[16], buffer[17]); |
||
134 | chprintf(stream, "\t\tpupd enable: 0x%02X 0x%02X 0x%02X\n", buffer[18], buffer[19], buffer[20]); |
||
135 | chprintf(stream, "\t\tpupd selection: 0x%02X 0x%02X 0x%02X\n", buffer[21], buffer[22], buffer[23]); |
||
136 | if ((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) {
|
||
137 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
138 | bffb3465 | Thomas Schöpping | } else {
|
139 | 4c72a54c | Thomas Schöpping | aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
140 | bffb3465 | Thomas Schöpping | } |
141 | |||
142 | chprintf(stream, "writing continuously...\n");
|
||
143 | { |
||
144 | uint8_t writebuffer[24];
|
||
145 | uint8_t readbuffer[2][24]; |
||
146 | // copy the read configuration but set the output drive strength to factor 0.25
|
||
147 | memcpy(writebuffer, buffer, sizeof(buffer));
|
||
148 | memset(&writebuffer[9], PCAL6524_LL_OUTPUTDRIVESTRENGTH_0_25, 6); |
||
149 | 4c72a54c | Thomas Schöpping | status = pcal6524_lld_write_continuous(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, writebuffer, 24, ((aos_test_pcal6524data_t*)test->data)->timeout);
|
150 | status |= pcal6524_lld_read_continuous(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, readbuffer[0], 24, ((aos_test_pcal6524data_t*)test->data)->timeout); |
||
151 | status |= pcal6524_lld_write_continuous(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, buffer, 24, ((aos_test_pcal6524data_t*)test->data)->timeout);
|
||
152 | status |= pcal6524_lld_read_continuous(((aos_test_pcal6524data_t*)test->data)->pcal6524d, PCAL6524_LLD_CMD_OUTPUT_P0, readbuffer[1], 24, ((aos_test_pcal6524data_t*)test->data)->timeout); |
||
153 | bffb3465 | Thomas Schöpping | if (((status == APAL_STATUS_OK) || (status == APAL_STATUS_WARNING)) &&
|
154 | ((memcmp(writebuffer, readbuffer[0], 24) == 0) && (memcmp(buffer, readbuffer[1], 24) == 0))) { |
||
155 | 4c72a54c | Thomas Schöpping | aosTestPassed(stream, &result); |
156 | bffb3465 | Thomas Schöpping | } else {
|
157 | 4c72a54c | Thomas Schöpping | aosTestFailedMsg(stream, &result, "0x%08X\n", status);
|
158 | bffb3465 | Thomas Schöpping | } |
159 | } |
||
160 | |||
161 | 4c72a54c | Thomas Schöpping | aosTestInfoMsg(stream, "driver object memory footprint: %u bytes\n", sizeof(PCAL6524Driver)); |
162 | bffb3465 | Thomas Schöpping | |
163 | return result;
|
||
164 | } |
||
165 | |||
166 | 4c72a54c | Thomas Schöpping | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |