Statistics
| Branch: | Tag: | Revision:

amiro-os / test / periphery-lld / MIC9404x_v1 / aos_test_MIC9404x.c @ 0b989911

History | View | Annotate | Download (4.849 KB)

1 ee884101 Thomas Schöpping
/*
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 4c72a54c Thomas Schöpping
#include <aos_test_MIC9404x.h>
21 ee884101 Thomas Schöpping
22 4c72a54c Thomas Schöpping
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
23 ee884101 Thomas Schöpping
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 4c72a54c Thomas Schöpping
 * @brief   MIC9404x test function.
50 ee884101 Thomas Schöpping
 *
51
 * @param[in] stream  Stream for input/output.
52 4c72a54c Thomas Schöpping
 * @param[in] test    Test object.
53 ee884101 Thomas Schöpping
 *
54 4c72a54c Thomas Schöpping
 * @return            Test result value.
55 ee884101 Thomas Schöpping
 */
56 4c72a54c Thomas Schöpping
aos_testresult_t aosTestMic9404xFunc(BaseSequentialStream* stream, const aos_test_t* test)
57 ee884101 Thomas Schöpping
{
58 4c72a54c Thomas Schöpping
  aosDbgCheck(test->data != NULL && ((aos_test_mic9404data_t*)test->data)->driver != NULL);
59 ee884101 Thomas Schöpping
60
  // local variables
61
  mic9404x_lld_state_t state_orig;
62
  mic9404x_lld_state_t state;
63 4c72a54c Thomas Schöpping
  aos_testresult_t result = {0, 0};
64 b23ca7cc Thomas Schöpping
  int32_t status;
65 ee884101 Thomas Schöpping
66
  chprintf(stream, "reading current status...\n");
67 4c72a54c Thomas Schöpping
  status = mic9404x_lld_get(((aos_test_mic9404data_t*)test->data)->driver, &state_orig);
68 ee884101 Thomas Schöpping
  if (status == APAL_STATUS_OK) {
69 4c72a54c Thomas Schöpping
    aosTestPassedMsg(stream, &result, "power %s\n", (state_orig == MIC9404x_LLD_STATE_ON) ? "enabled" : "disabled");
70 ee884101 Thomas Schöpping
  } else {
71 4c72a54c Thomas Schöpping
    aosTestFailed(stream, &result);
72 ee884101 Thomas Schöpping
  }
73
74
  state = state_orig;
75
  for (uint8_t i = 0; i < 2; ++i) {
76
    if (state == MIC9404x_LLD_STATE_ON) {
77
      chprintf(stream, "disabling for five seconds...\n");
78 4c72a54c Thomas Schöpping
      status = mic9404x_lld_set(((aos_test_mic9404data_t*)test->data)->driver, MIC9404x_LLD_STATE_OFF);
79
      status |= mic9404x_lld_get(((aos_test_mic9404data_t*)test->data)->driver, &state);
80 ee884101 Thomas Schöpping
      if (state == MIC9404x_LLD_STATE_OFF) {
81
        aosThdSSleep(5);
82 4c72a54c Thomas Schöpping
        status |= mic9404x_lld_get(((aos_test_mic9404data_t*)test->data)->driver, &state);
83 ee884101 Thomas Schöpping
      }
84
      if ((status == APAL_STATUS_OK) && (state == MIC9404x_LLD_STATE_OFF)) {
85 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
86 ee884101 Thomas Schöpping
      } else {
87 4c72a54c Thomas Schöpping
        aosTestFailed(stream, &result);
88 ee884101 Thomas Schöpping
        break;
89
      }
90
    } else {
91
      chprintf(stream, "enabling for five seconds...\n");
92 4c72a54c Thomas Schöpping
      status = mic9404x_lld_set(((aos_test_mic9404data_t*)test->data)->driver, MIC9404x_LLD_STATE_ON);
93
      status |= mic9404x_lld_get(((aos_test_mic9404data_t*)test->data)->driver, &state);
94 ee884101 Thomas Schöpping
      if (state == MIC9404x_LLD_STATE_ON) {
95
        aosThdSSleep(5);
96 4c72a54c Thomas Schöpping
        status |= mic9404x_lld_get(((aos_test_mic9404data_t*)test->data)->driver, &state);
97 ee884101 Thomas Schöpping
      }
98
      if ((status == APAL_STATUS_OK) && (state == MIC9404x_LLD_STATE_ON)) {
99 4c72a54c Thomas Schöpping
        aosTestPassed(stream, &result);
100 ee884101 Thomas Schöpping
      } else {
101 4c72a54c Thomas Schöpping
        aosTestFailed(stream, &result);
102 ee884101 Thomas Schöpping
        break;
103
      }
104
    }
105
  }
106
  // restore original state
107
  if (state != state_orig) {
108 4c72a54c Thomas Schöpping
    status = mic9404x_lld_set(((aos_test_mic9404data_t*)test->data)->driver, state);
109 ee884101 Thomas Schöpping
    if (status != APAL_STATUS_OK) {
110
      chprintf(stream, "\t\tWARNING: failed to restore original status!\n");
111
    }
112
  }
113
114 4c72a54c Thomas Schöpping
  aosTestInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(MIC9404xDriver));
115 ee884101 Thomas Schöpping
116
  return result;
117
}
118
119 4c72a54c Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */