Statistics
| Branch: | Tag: | Revision:

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

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

    
21
#if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_LED)) || 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
#include <aos_debug.h>
47
#include <chprintf.h>
48
#include <alld_led.h>
49
#include <aos_thread.h>
50

    
51
/**
52
 * @brief   LED unit test function.
53
 *
54
 * @param[in] stream  Stream for input/output.
55
 * @param[in] ut      Unit test object.
56
 *
57
 * @return            Unit test result value.
58
 */
59
aos_utresult_t utAlldLedFunc(BaseSequentialStream* stream, aos_unittest_t* ut)
60
{
61
  aosDbgCheck(ut->data != NULL);
62

    
63
  // local variables
64
  aos_utresult_t result = {0, 0};
65
  uint32_t status = AOS_OK;
66

    
67
  chprintf(stream, "lighting up for two seconds...\n");
68
  led_lld_state_t state = LED_LLD_STATE_ON;
69
  status = led_lld_set((LEDDriver*)ut->data, state);
70
  aosThdSSleep(2);
71
  status |= led_lld_get((LEDDriver*)ut->data, &state);
72
  if (status == APAL_STATUS_OK && state == LED_LLD_STATE_ON) {
73
    aosUtPassed(stream, &result);
74
  } else {
75
    aosUtFailed(stream, &result);
76
  }
77

    
78
  chprintf(stream, "turning off for two seconds...\n");
79
  state = LED_LLD_STATE_OFF;
80
  status = led_lld_set((LEDDriver*)ut->data, state);
81
  aosThdSSleep(2);
82
  status |= led_lld_get((LEDDriver*)ut->data, &state);
83
  if (status == APAL_STATUS_OK && state == LED_LLD_STATE_OFF) {
84
    aosUtPassed(stream, &result);
85
  } else {
86
    aosUtFailed(stream, &result);
87
  }
88

    
89
  chprintf(stream, "toggling for two seconds...\n");
90
  status = led_lld_set((LEDDriver*)ut->data, LED_LLD_STATE_ON);
91
  for (uint32_t i = 0; i < 2000/100; ++i) {
92
    status |= led_lld_toggle((LEDDriver*)ut->data);
93
    status |= led_lld_get((LEDDriver*)ut->data, &state);
94
    status |= ((uint8_t)state != (i & 0x01u)) ? APAL_STATUS_ERROR : APAL_STATUS_OK;
95
    aosThdMSleep(100);
96
  }
97
  status = led_lld_set((LEDDriver*)ut->data, LED_LLD_STATE_OFF);
98
  if (status == APAL_STATUS_OK) {
99
    aosUtPassed(stream, &result);
100
  } else {
101
    aosUtFailed(stream, &result);
102
  }
103

    
104
  aosUtInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(LEDDriver));
105

    
106
  return result;
107
}
108

    
109
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_LED) */