Statistics
| Branch: | Tag: | Revision:

amiro-os / test / periphery-lld / button_v1 / aos_test_button.c @ 42247107

History | View | Annotate | Download (4.381 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_button.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 4c72a54c Thomas Schöpping
#define INTERRUPT_EVENT_ID            1
29
30 f3ac1c96 Thomas Schöpping
/******************************************************************************/
31
/* EXPORTED VARIABLES                                                         */
32
/******************************************************************************/
33
34
/******************************************************************************/
35
/* LOCAL TYPES                                                                */
36
/******************************************************************************/
37
38
/******************************************************************************/
39
/* LOCAL VARIABLES                                                            */
40
/******************************************************************************/
41
42
/******************************************************************************/
43
/* LOCAL FUNCTIONS                                                            */
44
/******************************************************************************/
45
46
/******************************************************************************/
47
/* EXPORTED FUNCTIONS                                                         */
48
/******************************************************************************/
49 e545e620 Thomas Schöpping
50
/**
51 4c72a54c Thomas Schöpping
 * @brief   Button test function.
52 e545e620 Thomas Schöpping
 *
53
 * @param[in] stream  Stream for input/output.
54 4c72a54c Thomas Schöpping
 * @param[in] test    Test object.
55 e545e620 Thomas Schöpping
 *
56 4c72a54c Thomas Schöpping
 * @return            Test result value.
57 e545e620 Thomas Schöpping
 */
58 4c72a54c Thomas Schöpping
aos_testresult_t aosTestButtonFunc(BaseSequentialStream* stream, const aos_test_t* test)
59 e545e620 Thomas Schöpping
{
60 4c72a54c Thomas Schöpping
  aosDbgCheck(test->data != NULL &&
61
      ((aos_test_buttondata_t*)test->data)->button != NULL &&
62
      ((aos_test_buttondata_t*)test->data)->evtsource != NULL);
63 e545e620 Thomas Schöpping
64
  // local variables
65 ce12e797 Thomas Schöpping
  aos_testresult_t result;
66 b23ca7cc Thomas Schöpping
  int32_t status;
67 4c72a54c Thomas Schöpping
  unsigned int count = 0;
68
  button_lld_state_t bstate;
69
  event_listener_t evtlistener;
70
  aos_timestamp_t tcurrent, tend;
71
72 ce12e797 Thomas Schöpping
  aosTestResultInit(&result);
73
74 4c72a54c Thomas Schöpping
  chprintf(stream, "test interrupts for ten seconds...\n");
75
  chEvtRegister(((aos_test_buttondata_t*)test->data)->evtsource, &evtlistener, INTERRUPT_EVENT_ID);
76 b23ca7cc Thomas Schöpping
  status = APAL_STATUS_OK;
77 4c72a54c Thomas Schöpping
  aosSysGetUptime(&tend);
78
  tend += 10 * MICROSECONDS_PER_SECOND;
79
  do {
80
    const eventmask_t emask = chEvtWaitOneTimeout(EVENT_MASK(INTERRUPT_EVENT_ID), chTimeUS2I(MICROSECONDS_PER_SECOND));
81
    const eventflags_t eflags = chEvtGetAndClearFlags(&evtlistener);
82
    status |= button_lld_get(((aos_test_buttondata_t*)test->data)->button, &bstate);
83
    if (emask == EVENT_MASK(INTERRUPT_EVENT_ID) &&
84
        eflags == ((aos_test_buttondata_t*)test->data)->evtflags) {
85
      // a correct event was detected
86
      chprintf(stream, "\t\tinterrupt detected: %s\n", (bstate == BUTTON_LLD_STATE_PRESSED) ? "pressed" : "released");
87
      ++count;
88
    } else {
89
      // no button event was detected (usually timeout)
90
      chprintf(stream, "\t\twaiting for event...\n");
91
    }
92
    aosSysGetUptime(&tcurrent);
93
  } while (tcurrent < tend);
94
  chEvtUnregister(((aos_test_buttondata_t*)test->data)->evtsource, &evtlistener);
95
  if (status == APAL_STATUS_OK && count > 0) {
96
    aosTestPassedMsg(stream, &result, "%u events detected\n", count);
97 e545e620 Thomas Schöpping
  } else {
98 4c72a54c Thomas Schöpping
    aosTestFailedMsg(stream, &result, "0x%08X; %u\n", status, count);
99 e545e620 Thomas Schöpping
  }
100
101 4c72a54c Thomas Schöpping
  aosTestInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(ButtonDriver));
102 e545e620 Thomas Schöpping
103
  return result;
104
}
105
106 4c72a54c Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */