amiro-os / modules / PowerManagement_1-1 / test / INA219 / module_test_INA219.c @ 1a8fb642
History | View | Annotate | Download (5.33 KB)
1 | 4c72a54c | 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 | #include <amiroos.h> |
||
20 | |||
21 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
22 | |||
23 | #include <module_test_INA219.h> |
||
24 | #include <aos_test_INA219.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_ina219data_t _data = {
|
||
44 | /* driver */ NULL, |
||
45 | /* expected voltage */ 0.0f, |
||
46 | /* tolerance */ 0.05f, |
||
47 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
48 | }; |
||
49 | |||
50 | static AOS_TEST(_test, "INA219", "power monitor", moduleTestIna219ShellCb, aosTestIna219Func, &_data); |
||
51 | |||
52 | /******************************************************************************/
|
||
53 | /* LOCAL FUNCTIONS */
|
||
54 | /******************************************************************************/
|
||
55 | |||
56 | /******************************************************************************/
|
||
57 | /* EXPORTED FUNCTIONS */
|
||
58 | /******************************************************************************/
|
||
59 | |||
60 | int moduleTestIna219ShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result) |
||
61 | { |
||
62 | enum {
|
||
63 | UNKNOWN, |
||
64 | VDD, VIO18, VIO33, VSYS42, VIO50, |
||
65 | } monitor = UNKNOWN; |
||
66 | |||
67 | // evaluate argument
|
||
68 | if (argc == 2) { |
||
69 | if (strcmp(argv[1], "VDD") == 0) { |
||
70 | monitor = VDD; |
||
71 | } else if (strcmp(argv[1], "VIO1.8") == 0) { |
||
72 | monitor = VIO18; |
||
73 | } else if (strcmp(argv[1], "VIO3.3") == 0) { |
||
74 | monitor = VIO33; |
||
75 | } else if (strcmp(argv[1], "VSYS4.2") == 0) { |
||
76 | monitor = VSYS42; |
||
77 | } else if (strcmp(argv[1], "VIO5.0") == 0) { |
||
78 | monitor = VIO50; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | // handle valid monitor
|
||
83 | if (monitor != UNKNOWN) {
|
||
84 | aos_testresult_t res = {0, 0}; |
||
85 | |||
86 | switch (monitor) {
|
||
87 | case VDD:
|
||
88 | _data.inad = &moduleLldPowerMonitorVdd; |
||
89 | _data.v_expected = 3.3f; |
||
90 | res = aosTestRun(stream, &_test, "VDD (3.3V)");
|
||
91 | _data.inad = NULL;
|
||
92 | _data.v_expected = 0.0f; |
||
93 | break;
|
||
94 | case VIO18:
|
||
95 | _data.inad = &moduleLldPowerMonitorVio18; |
||
96 | _data.v_expected = 1.8f; |
||
97 | res = aosTestRun(stream, &_test, "VIO (1.8V)");
|
||
98 | _data.inad = NULL;
|
||
99 | _data.v_expected = 0.0f; |
||
100 | break;
|
||
101 | case VIO33:
|
||
102 | _data.inad = &moduleLldPowerMonitorVio33; |
||
103 | _data.v_expected = 3.3f; |
||
104 | res = aosTestRun(stream, &_test, "VIO (3.3V)");
|
||
105 | _data.inad = NULL;
|
||
106 | _data.v_expected = 0.0f; |
||
107 | break;
|
||
108 | case VSYS42:
|
||
109 | _data.inad = &moduleLldPowerMonitorVsys42; |
||
110 | _data.v_expected = 4.2f; |
||
111 | res = aosTestRun(stream, &_test, "VSYS (4.2V)");
|
||
112 | _data.inad = NULL;
|
||
113 | _data.v_expected = 0.0f; |
||
114 | break;
|
||
115 | case VIO50:
|
||
116 | _data.inad = &moduleLldPowerMonitorVio50; |
||
117 | _data.v_expected = 5.0f; |
||
118 | res = aosTestRun(stream, &_test, "VIO (5.0V)");
|
||
119 | _data.inad = NULL;
|
||
120 | _data.v_expected = 0.0f; |
||
121 | break;
|
||
122 | default:
|
||
123 | break;
|
||
124 | } |
||
125 | if (result != NULL) { |
||
126 | *result = res; |
||
127 | } |
||
128 | return AOS_OK;
|
||
129 | } |
||
130 | // handle invalid arguments
|
||
131 | else {
|
||
132 | // print help
|
||
133 | chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
||
134 | chprintf(stream, "Options:\n");
|
||
135 | chprintf(stream, " VDD\n");
|
||
136 | chprintf(stream, " Test VDD (3.3V) power monitor.\n");
|
||
137 | chprintf(stream, " VIO1.8\n");
|
||
138 | chprintf(stream, " Test VIO 1.8V power monitor.\n");
|
||
139 | chprintf(stream, " VIO3.3\n");
|
||
140 | chprintf(stream, " Test VIO 3.3V power monitor.\n");
|
||
141 | chprintf(stream, " VSYS4.2\n");
|
||
142 | chprintf(stream, " Test VSYS 4.2V power monitor.\n");
|
||
143 | chprintf(stream, " VIO5.0\n");
|
||
144 | chprintf(stream, " Test VIO 5.0V power monitor.\n");
|
||
145 | if (result != NULL) { |
||
146 | result->passed = 0;
|
||
147 | result->failed = 0;
|
||
148 | } |
||
149 | return AOS_INVALIDARGUMENTS;
|
||
150 | } |
||
151 | } |
||
152 | |||
153 | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |