amiro-os / modules / PowerManagement_1-1 / test / PCA9544A / module_test_PCA9544A.c @ 1a8fb642
History | View | Annotate | Download (4.029 KB)
1 |
/*
|
---|---|
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 |
#include <amiroos.h> |
20 |
|
21 |
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR)) || defined(__DOXYGEN__) |
22 |
|
23 |
#include <module_test_PCA9544A.h> |
24 |
#include <aos_test_PCA9544A.h> |
25 |
#include <string.h> |
26 |
|
27 |
/******************************************************************************/
|
28 |
/* LOCAL DEFINITIONS */
|
29 |
/******************************************************************************/
|
30 |
|
31 |
/******************************************************************************/
|
32 |
/* EXPORTED VARIABLES */
|
33 |
/******************************************************************************/
|
34 |
|
35 |
/******************************************************************************/
|
36 |
/* LOCAL TYPES */
|
37 |
/******************************************************************************/
|
38 |
|
39 |
/******************************************************************************/
|
40 |
/* LOCAL VARIABLES */
|
41 |
/******************************************************************************/
|
42 |
|
43 |
static aos_test_pca9544adata_t _data = {
|
44 |
/* driver */ NULL, |
45 |
/* timeout */ MICROSECONDS_PER_SECOND,
|
46 |
}; |
47 |
|
48 |
static AOS_TEST(_test, "PCA9544A", "I2C multiplexer", moduleTestPca9544aShellCb, aosTestPca9544aFunc, &_data); |
49 |
|
50 |
/******************************************************************************/
|
51 |
/* LOCAL FUNCTIONS */
|
52 |
/******************************************************************************/
|
53 |
|
54 |
/******************************************************************************/
|
55 |
/* EXPORTED FUNCTIONS */
|
56 |
/******************************************************************************/
|
57 |
|
58 |
int moduleTestPca9544aShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result) |
59 |
{ |
60 |
enum {
|
61 |
UNKNOWN, |
62 |
MUX1, MUX2, |
63 |
} mux = UNKNOWN; |
64 |
|
65 |
// evaluate arguments
|
66 |
if (argc == 2) { |
67 |
if (strcmp(argv[1], "#1") == 0) { |
68 |
mux = MUX1; |
69 |
} else if (strcmp(argv[1], "#2") == 0) { |
70 |
mux = MUX2; |
71 |
} |
72 |
} |
73 |
|
74 |
// handle valid mux
|
75 |
if (mux != UNKNOWN) {
|
76 |
aos_testresult_t res = {0 ,0}; |
77 |
|
78 |
switch (mux) {
|
79 |
case MUX1:
|
80 |
_data.driver = &moduleLldI2cMultiplexer1; |
81 |
res = aosTestRun(stream, &_test, "I2C bus #1");
|
82 |
_data.driver = NULL;
|
83 |
break;
|
84 |
case MUX2:
|
85 |
_data.driver = &moduleLldI2cMultiplexer2; |
86 |
res = aosTestRun(stream, &_test, "I2C bus #2");
|
87 |
_data.driver = NULL;
|
88 |
break;
|
89 |
default:
|
90 |
break;
|
91 |
} |
92 |
if (result != NULL) { |
93 |
*result = res; |
94 |
} |
95 |
return AOS_OK;
|
96 |
} |
97 |
// handle invalid arguments
|
98 |
else {
|
99 |
// print help
|
100 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
101 |
chprintf(stream, "Options:\n");
|
102 |
chprintf(stream, " #1\n");
|
103 |
chprintf(stream, " Test the multiplexer on the I2C bus #1.\n");
|
104 |
chprintf(stream, " #2\n");
|
105 |
chprintf(stream, " Test the multiplexer on the I2C bus #2.\n");
|
106 |
if (result != NULL) { |
107 |
result->passed = 0;
|
108 |
result->failed = 0;
|
109 |
} |
110 |
return AOS_INVALIDARGUMENTS;
|
111 |
} |
112 |
} |
113 |
|
114 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && (BOARD_SENSORRING == BOARD_PROXIMITYSENSOR) */ |