Statistics
| Branch: | Tag: | Revision:

amiro-os / test / periphery-lld / bq27500_v1_bq241xx_v1 / aos_test_bq27500_bq241xx.c @ 96621a83

History | View | Annotate | Download (7.696 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 96621a83 Thomas Schöpping
Copyright (C) 2016..2020  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 4c72a54c Thomas Schöpping
#include <aos_test_bq27500_bq241xx.h>
21 e545e620 Thomas Schöpping
22 4c72a54c Thomas Schöpping
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
23 ddf34c3d Thomas Schöpping
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 4c72a54c Thomas Schöpping
aos_testresult_t aosTestBq27500Bq241xxFunc(BaseSequentialStream *stream, const aos_test_t *test)
50 e545e620 Thomas Schöpping
{
51 4c72a54c Thomas Schöpping
  aosDbgCheck(test->data != NULL && ((aos_test_bq27500bq241xxdata_t*)test->data)->bq27500 != NULL && ((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx != NULL);
52 e545e620 Thomas Schöpping
53
  // local variables
54 ce12e797 Thomas Schöpping
  aos_testresult_t result;
55 b23ca7cc Thomas Schöpping
  int32_t status;
56 e545e620 Thomas Schöpping
  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 ce12e797 Thomas Schöpping
  aosTestResultInit(&result);
64
65 e545e620 Thomas Schöpping
  chprintf(stream, "check for battery...\n");
66 4c72a54c Thomas Schöpping
  status = bq27500_lld_std_command(((aos_test_bq27500bq241xxdata_t*)test->data)->bq27500, BQ27500_LLD_STD_CMD_Flags, &dst, ((aos_test_bq27500bq241xxdata_t*)test->data)->timeout);
67 e545e620 Thomas Schöpping
  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 4c72a54c Thomas Schöpping
  status |= bq27500_lld_read_batgood(((aos_test_bq27500bq241xxdata_t*)test->data)->bq27500, &bg);
71 e545e620 Thomas Schöpping
  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 4c72a54c Thomas Schöpping
      aosTestPassedMsg(stream, &result, "no battery detected, aborting\n");
75 e545e620 Thomas Schöpping
      return result;
76
    } else if (!bg) {
77 4c72a54c Thomas Schöpping
      aosTestPassedMsg(stream, &result, "battery damaged, aborting\n");
78 e545e620 Thomas Schöpping
      return result;
79
    } else {
80 4c72a54c Thomas Schöpping
      aosTestPassed(stream, &result);
81 e545e620 Thomas Schöpping
    }
82
  } else {
83 4c72a54c Thomas Schöpping
    aosTestFailedMsg(stream, &result, "0x%08X; aborting\n", status);
84 e545e620 Thomas Schöpping
    return result;
85
  }
86
87
  chprintf(stream, "get current charger setting...\n");
88 4c72a54c Thomas Schöpping
  status = bq241xx_lld_get_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charger_enabled);
89 e545e620 Thomas Schöpping
  if (status == APAL_STATUS_SUCCESS) {
90 4c72a54c Thomas Schöpping
    aosTestPassedMsg(stream, &result, "currently %s\n", (charger_enabled == BQ241xx_LLD_ENABLED) ? "enabled" : "disabled");
91 e545e620 Thomas Schöpping
  } else {
92 4c72a54c Thomas Schöpping
    aosTestFailedMsg(stream, &result, "0x%08X\n", status);
93 e545e620 Thomas Schöpping
  }
94
95
  // disable/enable charger
96
  for (uint8_t iteration = 0; iteration < 2; ++iteration) {
97 ddf34c3d Thomas Schöpping
    if (charger_enabled == BQ241xx_LLD_ENABLED) {
98 e545e620 Thomas Schöpping
      sleeptime_s = 120;
99
      chprintf(stream, "disable charger...\n");
100 4c72a54c Thomas Schöpping
      status = bq241xx_lld_set_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, BQ241xx_LLD_DISABLED);
101 e545e620 Thomas Schöpping
      aosThdSSleep(1);
102 4c72a54c Thomas Schöpping
      status |= bq241xx_lld_get_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charger_enabled);
103 ddf34c3d Thomas Schöpping
      status |= (charger_enabled == BQ241xx_LLD_DISABLED) ? 0x0000 : 0x0100;
104 e545e620 Thomas Schöpping
      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 4c72a54c Thomas Schöpping
      status |= bq241xx_lld_get_charge_status(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charge);
112 ddf34c3d Thomas Schöpping
      chprintf(stream, "\t\tcharge status: %scharging\n", (charge == BQ241xx_LLD_CHARGING) ? "" : "not ");
113 4c72a54c Thomas Schöpping
      status |= bq27500_lld_std_command(((aos_test_bq27500bq241xxdata_t*)test->data)->bq27500, BQ27500_LLD_STD_CMD_TimeToFull, &dst, ((aos_test_bq27500bq241xxdata_t*)test->data)->timeout);
114 e545e620 Thomas Schöpping
      if (status == APAL_STATUS_SUCCESS) {
115
        if (dst == 0xFFFF || dst == 0) {
116 4c72a54c Thomas Schöpping
          aosTestPassedMsg(stream, &result, "battery %sfull\n", flags.content.fc ? "" : "not ");
117 e545e620 Thomas Schöpping
        } else {
118 4c72a54c Thomas Schöpping
          aosTestFailedMsg(stream, &result, "battery %sfull but charging (TTF = %umin)\n", flags.content.fc ? "" : "not ", dst);
119 e545e620 Thomas Schöpping
        }
120
      } else {
121 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
122 e545e620 Thomas Schöpping
      }
123
    }
124 ddf34c3d Thomas Schöpping
    else { /* charger_enabled != BQ241xx_LLD_ENABLED */
125 e545e620 Thomas Schöpping
      sleeptime_s = 90;
126
      chprintf(stream, "enable charger...\n");
127 4c72a54c Thomas Schöpping
      status = bq241xx_lld_set_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, BQ241xx_LLD_ENABLED);
128 e545e620 Thomas Schöpping
      aosThdSSleep(1);
129 4c72a54c Thomas Schöpping
      status |= bq241xx_lld_get_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charger_enabled);
130 ddf34c3d Thomas Schöpping
      status |= (charger_enabled == BQ241xx_LLD_ENABLED) ? 0x0000 : 0x0100;
131 e545e620 Thomas Schöpping
      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 4c72a54c Thomas Schöpping
      status |= bq241xx_lld_get_charge_status(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charge);
139 ddf34c3d Thomas Schöpping
      chprintf(stream, "\t\tcharge status: %scharging\n", (charge == BQ241xx_LLD_CHARGING) ? "" : "not ");
140 4c72a54c Thomas Schöpping
      status |= bq27500_lld_std_command(((aos_test_bq27500bq241xxdata_t*)test->data)->bq27500, BQ27500_LLD_STD_CMD_TimeToFull, &dst, ((aos_test_bq27500bq241xxdata_t*)test->data)->timeout);
141 e545e620 Thomas Schöpping
      if (status == APAL_STATUS_SUCCESS) {
142
        if (((dst == 0xFFFF || dst == 0) && flags.content.fc) || (!(dst == 0xFFFF || dst == 0) && !flags.content.fc)) {
143 4c72a54c Thomas Schöpping
          aosTestPassedMsg(stream, &result, "battery %sfull and %scharging (TTF = %umin)\n", flags.content.fc ? "" : "not ", (dst != 0xFFFF || dst != 0) ? "" : "not ", dst);
144 e545e620 Thomas Schöpping
        } else {
145 4c72a54c Thomas Schöpping
          aosTestFailedMsg(stream, &result, "battery %sfull and %scharging (TTF = %umin)\n", flags.content.fc ? "" : "not ", (dst != 0xFFFF || dst != 0) ? "" : "not ", dst);
146 e545e620 Thomas Schöpping
        }
147
      } else {
148 4c72a54c Thomas Schöpping
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
149 e545e620 Thomas Schöpping
      }
150
    }
151
152 4c72a54c Thomas Schöpping
    bq241xx_lld_get_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charger_enabled);
153 e545e620 Thomas Schöpping
  }
154
155
  return result;
156
}
157
158 4c72a54c Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */