Statistics
| Branch: | Tag: | Revision:

amiro-os / core / src / aos_system.c @ 96621a83

History | View | Annotate | Download (36.139 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 53710ca3 Marc Rothmann
/**
20
 * @file    aos_system.c
21
 * @brief   System code.
22
 * @details Contains system initialization and shutdown routines
23
 *          and system shell commands.
24
 *
25
 * @addtogroup aos_system
26
 * @{
27
 */
28
29 3940ba8a Thomas Schöpping
#include <amiroos.h>
30
#include <stdarg.h>
31 e545e620 Thomas Schöpping
#include <string.h>
32 8399aeae Thomas Schöpping
#include <stdlib.h>
33 3940ba8a Thomas Schöpping
34 e545e620 Thomas Schöpping
#if (AMIROOS_CFG_TESTS_ENABLE == true)
35
#include <ch_test.h>
36 0128be0f Marc Rothmann
#include <rt_test_root.h>
37 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
38 e545e620 Thomas Schöpping
39 f3ac1c96 Thomas Schöpping
/******************************************************************************/
40
/* LOCAL DEFINITIONS                                                          */
41
/******************************************************************************/
42
43 e545e620 Thomas Schöpping
/**
44
 * @brief   Period of the system timer.
45
 */
46 1e5f7648 Thomas Schöpping
#define SYSTIMER_PERIOD               (TIME_MAX_SYSTIME - CH_CFG_ST_TIMEDELTA)
47 e545e620 Thomas Schöpping
48
/**
49
 * @brief   Width of the printable system info text.
50
 */
51 08d86900 Thomas Schöpping
#define SYSTEM_INFO_WIDTH             80
52 e545e620 Thomas Schöpping
53 ba516b61 Thomas Schöpping
/**
54
 * @brief   Width of the name column of the system info table.
55
 */
56 08d86900 Thomas Schöpping
#define SYSTEM_INFO_NAMEWIDTH         20
57 ba516b61 Thomas Schöpping
58 697dba3c Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
59
60
/**
61
 * @brief   Number of entries in the system shell input buffer.
62
 */
63
#define SYSTEM_SHELL_BUFFERENTRIES    (1 + AMIROOS_CFG_SHELL_HISTLENGTH)
64
65
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
66
67 f3ac1c96 Thomas Schöpping
/******************************************************************************/
68
/* EXPORTED VARIABLES                                                         */
69
/******************************************************************************/
70
71
/**
72
 * @brief   Global system object.
73
 */
74
aos_system_t aos;
75
76
/******************************************************************************/
77
/* LOCAL TYPES                                                                */
78
/******************************************************************************/
79
80
/******************************************************************************/
81
/* LOCAL VARIABLES                                                            */
82
/******************************************************************************/
83
84
/*
85
 * forward declarations
86
 */
87 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
88 e545e620 Thomas Schöpping
static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[]);
89
static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[]);
90
static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[]);
91 f3ac1c96 Thomas Schöpping
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
92 e545e620 Thomas Schöpping
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]);
93 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
94 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
95 e545e620 Thomas Schöpping
96
/**
97
 * @brief   Timer to accumulate system uptime.
98
 */
99
static virtual_timer_t _systimer;
100
101
/**
102
 * @brief   Accumulated system uptime.
103
 */
104
static aos_timestamp_t _uptime;
105
106
/**
107
 * @brief   Timer register value of last accumulation.
108
 */
109
static systime_t _synctime;
110
111 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
112 3e1a9c79 Thomas Schöpping
113 e545e620 Thomas Schöpping
/**
114
 * @brief   Shell thread working area.
115
 */
116 10fd7ac9 Thomas Schöpping
static THD_WORKING_AREA(_shell_wa, AMIROOS_CFG_SHELL_STACKSIZE);
117 e545e620 Thomas Schöpping
118
/**
119
 * @brief   Shell input buffer.
120
 */
121 697dba3c Thomas Schöpping
static char _shell_buffer[SYSTEM_SHELL_BUFFERENTRIES * AMIROOS_CFG_SHELL_LINEWIDTH];
122 e545e620 Thomas Schöpping
123
/**
124
 * @brief   Shell command to retrieve system information.
125
 */
126 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_info, "module:info", _shellcmd_infocb);
127 e545e620 Thomas Schöpping
128
/**
129
 * @brief   Shell command to set or retrieve system configuration.
130
 */
131 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_config, "module:config", _shellcmd_configcb);
132 e545e620 Thomas Schöpping
133
/**
134
 * @brief   Shell command to shutdown the system.
135
 */
136 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
137 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "system:shutdown", _shellcmd_shutdowncb);
138 7de0cc90 Thomas Schöpping
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
139 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "module:shutdown", _shellcmd_shutdowncb);
140 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
141 e545e620 Thomas Schöpping
142
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
143 cda14729 Thomas Schöpping
144 e545e620 Thomas Schöpping
/**
145
 * @brief   Shell kommand to run a test of the ChibiOS/RT kernel.
146
 */
147 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_kerneltest, "kernel:test", _shellcmd_kerneltestcb);
148 cda14729 Thomas Schöpping
149 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
150 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
151 e545e620 Thomas Schöpping
152 f3ac1c96 Thomas Schöpping
/******************************************************************************/
153
/* LOCAL FUNCTIONS                                                            */
154
/******************************************************************************/
155 e545e620 Thomas Schöpping
156
/**
157
 * @brief   Print a separator line.
158
 *
159 ba516b61 Thomas Schöpping
 * @param[in] stream    Stream to print to or NULL to print to all system streams.
160 e545e620 Thomas Schöpping
 * @param[in] c         Character to use.
161
 * @param[in] n         Length of the separator line.
162
 *
163
 * @return  Number of characters printed.
164
 */
165
static unsigned int _printSystemInfoSeparator(BaseSequentialStream* stream, const char c, const unsigned int n)
166
{
167
  aosDbgCheck(stream != NULL);
168
169
  // print the specified character n times
170
  for (unsigned int i = 0; i < n; ++i) {
171 83e58975 Thomas Schöpping
    streamPut(stream, (uint8_t)c);
172 e545e620 Thomas Schöpping
  }
173
  streamPut(stream, '\n');
174
175
  return n+1;
176
}
177
178
/**
179
 * @brief   Print a system information line.
180
 * @details Prints a system information line with the following format:
181
 *            "<name>[spaces]fmt"
182
 *          The combined width of "<name>[spaces]" can be specified in order to align <fmt> on multiple lines.
183
 *          Note that there is not trailing newline added implicitely.
184
 *
185 ba516b61 Thomas Schöpping
 * @param[in] stream      Stream to print to or NULL to print to all system streams.
186 e545e620 Thomas Schöpping
 * @param[in] name        Name of the entry/line.
187 08d86900 Thomas Schöpping
 * @param[in] namewidth   Minimum width of the name column.
188 e545e620 Thomas Schöpping
 * @param[in] fmt         Formatted string of information content.
189
 *
190
 * @return  Number of characters printed.
191
 */
192
static unsigned int _printSystemInfoLine(BaseSequentialStream* stream, const char* name, const unsigned int namewidth, const char* fmt, ...)
193
{
194
  aosDbgCheck(stream != NULL);
195 ba516b61 Thomas Schöpping
  aosDbgCheck(name != NULL);
196 e545e620 Thomas Schöpping
197
  unsigned int n = 0;
198 ba516b61 Thomas Schöpping
  va_list ap;
199 e545e620 Thomas Schöpping
200 ba516b61 Thomas Schöpping
  va_start(ap, fmt);
201 83e58975 Thomas Schöpping
  n += (unsigned int)chprintf(stream, name);
202 08d86900 Thomas Schöpping
  // print at least a single space character
203