Statistics
| Branch: | Tag: | Revision:

amiro-os / unittests / periphery-lld / src / ut_alld_bq24103a.c @ f3ac1c96

History | View | Annotate | Download (4.236 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_bq24103a.h>
20

    
21
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && 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
#include <alld_bq24103a.h>
51

    
52
aos_utresult_t utAlldBq24103aFunc(BaseSequentialStream* stream, aos_unittest_t* ut)
53
{
54
  aosDbgCheck(ut->data != NULL);
55

    
56
  // local variables
57
  aos_utresult_t result = {0, 0};
58
  uint32_t status;
59
  bq24103a_lld_enable_t en[3];
60
  bq24103a_lld_charge_state_t charge;
61

    
62
  chprintf(stream, "read enable pin...\n");
63
  status = bq24103a_lld_get_enabled((BQ24103ADriver*)ut->data, &en[0]);
64
  chprintf(stream, "\t\tcurrently %s\n", (en[0] == BQ24103A_LLD_ENABLED) ? "enabled" : "disabled");
65
  if(status == APAL_STATUS_SUCCESS){
66
    aosUtPassed(stream, &result);
67
  } else {
68
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
69
  }
70

    
71
  chprintf(stream, "write enable pin...\n");
72
  status = bq24103a_lld_set_enabled((BQ24103ADriver*)ut->data, (en[0] == BQ24103A_LLD_ENABLED) ? BQ24103A_LLD_DISABLED : BQ24103A_LLD_ENABLED);
73
  aosThdMSleep(1);
74
  status |= bq24103a_lld_get_enabled((BQ24103ADriver*)ut->data, &en[1]);
75
  status |= bq24103a_lld_set_enabled((BQ24103ADriver*)ut->data, en[0]);
76
  aosThdMSleep(1);
77
  status |= bq24103a_lld_get_enabled((BQ24103ADriver*)ut->data, &en[2]);
78
  if(status == APAL_STATUS_SUCCESS && en[0] != en[1] && en[0] == en[2] && en[1] != en[2]){
79
    aosUtPassed(stream, &result);
80
  } else {
81
    aosUtFailedMsg(stream, &result, "0x%08X, %u-%u\n", status, en[1], en[2]);
82
  }
83

    
84
  chprintf(stream, "read status pin...\n");
85
  aosThdMSleep(500);
86
  status = bq24103a_lld_get_charge_status((BQ24103ADriver*)ut->data, &charge);
87
  chprintf(stream, "\t\tcharge status: %scharging\n", (charge == BQ24103A_LLD_CHARGING) ? "" : "not ");
88
  if (status == APAL_STATUS_SUCCESS) {
89
    aosUtPassed(stream, &result);
90
  } else {
91
    aosUtFailedMsg(stream, &result, "0x%08X\n", status);
92
  }
93

    
94
  aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(BQ24103ADriver));
95

    
96
  return result;
97
}
98

    
99
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_BQ24103A) */