amiro-os / unittests / periphery-lld / src / ut_alld_bq27500_bq24103a.c @ f3ac1c96
History | View | Annotate | Download (7.75 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 <ut_alld_bq27500_bq24103a.h> |
20 |
|
21 |
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_BQ27500) && defined(AMIROLLD_CFG_USE_BQ24103A)) || defined(__DOXYGEN__) |
22 |
|
23 |
/******************************************************************************/
|
24 |
/* LOCAL DEFINITIONS */
|
25 |
/******************************************************************************/
|
26 |
|
27 |
/******************************************************************************/
|
28 |
/* EXPORTED VARIABLES */
|
29 |
/******************************************************************************/
|
30 |
|
31 |
/******************************************************************************/
|
32 |
/* LOCAL TYPES */
|
33 |
/******************************************************************************/
|
34 |
|
35 |
/******************************************************************************/
|
36 |
/* LOCAL VARIABLES */
|
37 |
/******************************************************************************/
|
38 |
|
39 |
/******************************************************************************/
|
40 |
/* LOCAL FUNCTIONS */
|
41 |
/******************************************************************************/
|
42 |
|
43 |
/******************************************************************************/
|
44 |
/* EXPORTED FUNCTIONS */
|
45 |
/******************************************************************************/
|
46 |
|
47 |
#include <aos_debug.h> |
48 |
#include <chprintf.h> |
49 |
#include <aos_thread.h> |
50 |
|
51 |
aos_utresult_t utAlldBq27500Bq24103aFunc(BaseSequentialStream *stream, aos_unittest_t *ut) |
52 |
{ |
53 |
aosDbgCheck(ut->data != NULL && ((ut_bq27500bq24103adata_t*)ut->data)->bq27500 != NULL && ((ut_bq27500bq24103adata_t*)ut->data)->bq24103a != NULL); |
54 |
|
55 |
// local variables
|
56 |
aos_utresult_t result = {0, 0}; |
57 |
uint32_t status; |
58 |
uint16_t dst; |
59 |
bq27500_lld_flags_t flags; |
60 |
bq27500_lld_batgood_t bg; |
61 |
bq24103a_lld_enable_t charger_enabled; |
62 |
uint32_t sleeptime_s; |
63 |
bq24103a_lld_charge_state_t charge; |
64 |
|
65 |
chprintf(stream, "check for battery...\n");
|
66 |
status = bq27500_lld_std_command(((ut_bq27500bq24103adata_t*)ut->data)->bq27500, BQ27500_LLD_STD_CMD_Flags, &dst, ((ut_bq27500bq24103adata_t*)ut->data)->timeout); |
67 |
flags.value = dst; |
68 |
chprintf(stream, "\t\tbattery detected: %s\n", flags.content.bat_det ? "yes" : "no"); |
69 |
chprintf(stream, "\t\tbattery fully charged: %s\n", flags.content.fc ? "yes" : "no"); |
70 |
status |= bq27500_lld_read_batgood(((ut_bq27500bq24103adata_t*)ut->data)->bq27500, &bg); |
71 |
chprintf(stream, "\t\tbattery good: %s\n", (bg == BQ27500_LLD_BATTERY_GOOD) ? "yes" : "no"); |
72 |
if (status == APAL_STATUS_SUCCESS) {
|
73 |
if (!flags.content.bat_det) {
|
74 |
aosUtPassedMsg(stream, &result, "no battery detected, aborting\n");
|
75 |
return result;
|
76 |
} else if (!bg) { |
77 |
aosUtPassedMsg(stream, &result, "battery damaged, aborting\n");
|
78 |
return result;
|
79 |
} else {
|
80 |
aosUtPassed(stream, &result); |
81 |
} |
82 |
} else {
|
83 |
aosUtFailedMsg(stream, &result, "0x%08X; aborting\n", status);
|
84 |
return result;
|
85 |
} |
86 |
|
87 |
chprintf(stream, "get current charger setting...\n");
|
88 |
status = bq24103a_lld_get_enabled(((ut_bq27500bq24103adata_t*)ut->data)->bq24103a, &charger_enabled); |
89 |
if (status == APAL_STATUS_SUCCESS) {
|
90 |
aosUtPassedMsg(stream, &result, "currently %s\n", (charger_enabled == BQ24103A_LLD_ENABLED) ? "enabled" : "disabled"); |
91 |
} else {
|
92 |
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
93 |
} |
94 |
|
95 |
// disable/enable charger
|
96 |
for (uint8_t iteration = 0; iteration < 2; ++iteration) { |
97 |
if (charger_enabled == BQ24103A_LLD_ENABLED) {
|
98 |
sleeptime_s = 120;
|
99 |
chprintf(stream, "disable charger...\n");
|
100 |
status = bq24103a_lld_set_enabled(((ut_bq27500bq24103adata_t*)ut->data)->bq24103a, BQ24103A_LLD_DISABLED); |
101 |
aosThdSSleep(1);
|
102 |
status |= bq24103a_lld_get_enabled(((ut_bq27500bq24103adata_t*)ut->data)->bq24103a, &charger_enabled); |
103 |
status |= (charger_enabled == BQ24103A_LLD_DISABLED) ? 0x0000 : 0x0100; |
104 |
for (uint32_t s = 0; s < sleeptime_s; ++s) { |
105 |
int nchars = chprintf(stream, "%us / %us", s, sleeptime_s); |
106 |
aosThdSSleep(1);
|
107 |
for (int c = 0; c < nchars; ++c) { |
108 |
chprintf(stream, "\b \b");
|
109 |
} |
110 |
} |
111 |
status |= bq24103a_lld_get_charge_status(((ut_bq27500bq24103adata_t*)ut->data)->bq24103a, &charge); |
112 |
chprintf(stream, "\t\tcharge status: %scharging\n", (charge == BQ24103A_LLD_CHARGING) ? "" : "not "); |
113 |
status |= bq27500_lld_std_command(((ut_bq27500bq24103adata_t*)ut->data)->bq27500, BQ27500_LLD_STD_CMD_TimeToFull, &dst, ((ut_bq27500bq24103adata_t*)ut->data)->timeout); |
114 |
if (status == APAL_STATUS_SUCCESS) {
|
115 |
if (dst == 0xFFFF || dst == 0) { |
116 |
aosUtPassedMsg(stream, &result, "battery %sfull\n", flags.content.fc ? "" : "not "); |
117 |
} else {
|
118 |
aosUtFailedMsg(stream, &result, "battery %sfull but charging (TTF = %umin)\n", flags.content.fc ? "" : "not ", dst); |
119 |
} |
120 |
} else {
|
121 |
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
122 |
} |
123 |
} |
124 |
else { /* charger_enabled != BQ24103A_LLD_ENABLED */ |
125 |
sleeptime_s = 90;
|
126 |
chprintf(stream, "enable charger...\n");
|
127 |
status = bq24103a_lld_set_enabled(((ut_bq27500bq24103adata_t*)ut->data)->bq24103a, BQ24103A_LLD_ENABLED); |
128 |
aosThdSSleep(1);
|
129 |
status |= bq24103a_lld_get_enabled(((ut_bq27500bq24103adata_t*)ut->data)->bq24103a, &charger_enabled); |
130 |
status |= (charger_enabled == BQ24103A_LLD_ENABLED) ? 0x0000 : 0x0100; |
131 |
for (uint32_t s = 0; s < sleeptime_s; ++s) { |
132 |
int nchars = chprintf(stream, "%us / %us", s, sleeptime_s); |
133 |
aosThdSSleep(1);
|
134 |
for (int c = 0; c < nchars; ++c) { |
135 |
chprintf(stream, "\b \b");
|
136 |
} |
137 |
} |
138 |
status |= bq24103a_lld_get_charge_status(((ut_bq27500bq24103adata_t*)ut->data)->bq24103a, &charge); |
139 |
chprintf(stream, "\t\tcharge status: %scharging\n", (charge == BQ24103A_LLD_CHARGING) ? "" : "not "); |
140 |
status |= bq27500_lld_std_command(((ut_bq27500bq24103adata_t*)ut->data)->bq27500, BQ27500_LLD_STD_CMD_TimeToFull, &dst, ((ut_bq27500bq24103adata_t*)ut->data)->timeout); |
141 |
if (status == APAL_STATUS_SUCCESS) {
|
142 |
if (((dst == 0xFFFF || dst == 0) && flags.content.fc) || (!(dst == 0xFFFF || dst == 0) && !flags.content.fc)) { |
143 |
aosUtPassedMsg(stream, &result, "battery %sfull and %scharging (TTF = %umin)\n", flags.content.fc ? "" : "not ", (dst != 0xFFFF || dst != 0) ? "" : "not ", dst); |
144 |
} else {
|
145 |
aosUtFailedMsg(stream, &result, "battery %sfull and %scharging (TTF = %umin)\n", flags.content.fc ? "" : "not ", (dst != 0xFFFF || dst != 0) ? "" : "not ", dst); |
146 |
} |
147 |
} else {
|
148 |
aosUtFailedMsg(stream, &result, "0x%08X\n", status);
|
149 |
} |
150 |
} |
151 |
|
152 |
bq24103a_lld_get_enabled(((ut_bq27500bq24103adata_t*)ut->data)->bq24103a, &charger_enabled); |
153 |
} |
154 |
|
155 |
return result;
|
156 |
} |
157 |
|
158 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_BQ27500) && defined(AMIROLLD_CFG_USE_BQ24103A) */ |