Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.696 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
#include <aos_test_bq27500_bq241xx.h>
21

    
22
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
23

    
24
/******************************************************************************/
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

    
49
aos_testresult_t aosTestBq27500Bq241xxFunc(BaseSequentialStream *stream, const aos_test_t *test)
50
{
51
  aosDbgCheck(test->data != NULL && ((aos_test_bq27500bq241xxdata_t*)test->data)->bq27500 != NULL && ((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx != NULL);
52

    
53
  // local variables
54
  aos_testresult_t result;
55
  int32_t status;
56
  uint16_t dst;
57
  bq27500_lld_flags_t flags;
58
  bq27500_lld_batgood_t bg;
59
  bq241xx_lld_enable_t charger_enabled;
60
  uint32_t sleeptime_s;
61
  bq241xx_lld_charge_state_t charge;
62

    
63
  aosTestResultInit(&result);
64

    
65
  chprintf(stream, "check for battery...\n");
66
  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
  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(((aos_test_bq27500bq241xxdata_t*)test->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
      aosTestPassedMsg(stream, &result, "no battery detected, aborting\n");
75
      return result;
76
    } else if (!bg) {
77
      aosTestPassedMsg(stream, &result, "battery damaged, aborting\n");
78
      return result;
79
    } else {
80
      aosTestPassed(stream, &result);
81
    }
82
  } else {
83
    aosTestFailedMsg(stream, &result, "0x%08X; aborting\n", status);
84
    return result;
85
  }
86

    
87
  chprintf(stream, "get current charger setting...\n");
88
  status = bq241xx_lld_get_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charger_enabled);
89
  if (status == APAL_STATUS_SUCCESS) {
90
    aosTestPassedMsg(stream, &result, "currently %s\n", (charger_enabled == BQ241xx_LLD_ENABLED) ? "enabled" : "disabled");
91
  } else {
92
    aosTestFailedMsg(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 == BQ241xx_LLD_ENABLED) {
98
      sleeptime_s = 120;
99
      chprintf(stream, "disable charger...\n");
100
      status = bq241xx_lld_set_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, BQ241xx_LLD_DISABLED);
101
      aosThdSSleep(1);
102
      status |= bq241xx_lld_get_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charger_enabled);
103
      status |= (charger_enabled == BQ241xx_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 |= bq241xx_lld_get_charge_status(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charge);
112
      chprintf(stream, "\t\tcharge status: %scharging\n", (charge == BQ241xx_LLD_CHARGING) ? "" : "not ");
113
      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
      if (status == APAL_STATUS_SUCCESS) {
115
        if (dst == 0xFFFF || dst == 0) {
116
          aosTestPassedMsg(stream, &result, "battery %sfull\n", flags.content.fc ? "" : "not ");
117
        } else {
118
          aosTestFailedMsg(stream, &result, "battery %sfull but charging (TTF = %umin)\n", flags.content.fc ? "" : "not ", dst);
119
        }
120
      } else {
121
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
122
      }
123
    }
124
    else { /* charger_enabled != BQ241xx_LLD_ENABLED */
125
      sleeptime_s = 90;
126
      chprintf(stream, "enable charger...\n");
127
      status = bq241xx_lld_set_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, BQ241xx_LLD_ENABLED);
128
      aosThdSSleep(1);
129
      status |= bq241xx_lld_get_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charger_enabled);
130
      status |= (charger_enabled == BQ241xx_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 |= bq241xx_lld_get_charge_status(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charge);
139
      chprintf(stream, "\t\tcharge status: %scharging\n", (charge == BQ241xx_LLD_CHARGING) ? "" : "not ");
140
      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
      if (status == APAL_STATUS_SUCCESS) {
142
        if (((dst == 0xFFFF || dst == 0) && flags.content.fc) || (!(dst == 0xFFFF || dst == 0) && !flags.content.fc)) {
143
          aosTestPassedMsg(stream, &result, "battery %sfull and %scharging (TTF = %umin)\n", flags.content.fc ? "" : "not ", (dst != 0xFFFF || dst != 0) ? "" : "not ", dst);
144
        } else {
145
          aosTestFailedMsg(stream, &result, "battery %sfull and %scharging (TTF = %umin)\n", flags.content.fc ? "" : "not ", (dst != 0xFFFF || dst != 0) ? "" : "not ", dst);
146
        }
147
      } else {
148
        aosTestFailedMsg(stream, &result, "0x%08X\n", status);
149
      }
150
    }
151

    
152
    bq241xx_lld_get_enabled(((aos_test_bq27500bq241xxdata_t*)test->data)->bq241xx, &charger_enabled);
153
  }
154

    
155
  return result;
156
}
157

    
158
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */