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