amiro-os / core / src / aos_system.c @ 3106e8cc
History | View | Annotate | Download (43.562 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 |
/**
|
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 |
#include <amiroos.h> |
30 |
#include <stdarg.h> |
31 |
#include <string.h> |
32 |
#include <stdlib.h> |
33 |
|
34 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) |
35 |
#include <ch_test.h> |
36 |
#include <rt_test_root.h> |
37 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
38 |
|
39 |
/******************************************************************************/
|
40 |
/* LOCAL DEFINITIONS */
|
41 |
/******************************************************************************/
|
42 |
|
43 |
/**
|
44 |
* @brief Period of the system timer.
|
45 |
*/
|
46 |
#define SYSTIMER_PERIOD (TIME_MAX_SYSTIME - CH_CFG_ST_TIMEDELTA)
|
47 |
|
48 |
/**
|
49 |
* @brief Width of the printable system info text.
|
50 |
*/
|
51 |
#define SYSTEM_INFO_WIDTH 70 |
52 |
|
53 |
/**
|
54 |
* @brief Width of the name column of the system info table.
|
55 |
*/
|
56 |
#define SYSTEM_INFO_NAMEWIDTH 14 |
57 |
|
58 |
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)) || defined(__DOXYGEN__) |
59 |
|
60 |
/**
|
61 |
* @brief Weighting factor for the low-pass filter used for calculating the @p _syssyncskew value.
|
62 |
*/
|
63 |
#define SYSTEM_SYSSYNCSKEW_LPFACTOR (0.1f / AOS_SYSTEM_TIME_RESOLUTION) |
64 |
|
65 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) */ |
66 |
|
67 |
/******************************************************************************/
|
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 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
88 |
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 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
92 |
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]); |
93 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
94 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
95 |
|
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 |
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER == true)) || defined(__DOXYGEN__) |
112 |
/**
|
113 |
* @brief Timer to drive the SYS_SYNC signal for system wide time synchronization according to SSSP.
|
114 |
*/
|
115 |
static virtual_timer_t _syssynctimer;
|
116 |
|
117 |
/**
|
118 |
* @brief Last uptime of system wide time synchronization.
|
119 |
*/
|
120 |
static aos_timestamp_t _syssynctime;
|
121 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER == true) */ |
122 |
|
123 |
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)) || defined(__DOXYGEN__) |
124 |
/**
|
125 |
* @brief Offset between local clock and system wide synchronization signal.
|
126 |
*/
|
127 |
static float _syssyncskew; |
128 |
|
129 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) */ |
130 |
|
131 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
132 |
/**
|
133 |
* @brief Shell thread working area.
|
134 |
*/
|
135 |
THD_WORKING_AREA(_shell_wa, AMIROOS_CFG_SHELL_STACKSIZE); |
136 |
|
137 |
/**
|
138 |
* @brief Shell input buffer.
|
139 |
*/
|
140 |
static char _shell_line[AMIROOS_CFG_SHELL_LINEWIDTH]; |
141 |
|
142 |
/**
|
143 |
* @brief Shell argument buffer.
|
144 |
*/
|
145 |
static char* _shell_arglist[AMIROOS_CFG_SHELL_MAXARGS]; |
146 |
|
147 |
/**
|
148 |
* @brief Shell command to retrieve system information.
|
149 |
*/
|
150 |
static aos_shellcommand_t _shellcmd_info = {
|
151 |
/* name */ "module:info", |
152 |
/* callback */ _shellcmd_infocb,
|
153 |
/* next */ NULL, |
154 |
}; |
155 |
|
156 |
/**
|
157 |
* @brief Shell command to set or retrieve system configuration.
|
158 |
*/
|
159 |
static aos_shellcommand_t _shellcmd_config = {
|
160 |
/* name */ "module:config", |
161 |
/* callback */ _shellcmd_configcb,
|
162 |
/* next */ NULL, |
163 |
}; |
164 |
|
165 |
/**
|
166 |
* @brief Shell command to shutdown the system.
|
167 |
*/
|
168 |
static aos_shellcommand_t _shellcmd_shutdown = {
|
169 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
170 |
/* name */ "system:shutdown", |
171 |
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
172 |
/* name */ "module:shutdown", |
173 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
174 |
/* callback */ _shellcmd_shutdowncb,
|
175 |
/* next */ NULL, |
176 |
}; |
177 |
|
178 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
179 |
/**
|
180 |
* @brief Shell kommand to run a test of the ChibiOS/RT kernel.
|
181 |
*/
|
182 |
static aos_shellcommand_t _shellcmd_kerneltest = {
|
183 |
/* name */ "kernel:test", |
184 |
/* callback */ _shellcmd_kerneltestcb,
|
185 |
/* next */ NULL, |
186 |
}; |
187 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
188 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
189 |
|
190 |
/******************************************************************************/
|
191 |
/* LOCAL FUNCTIONS */
|
192 |
/******************************************************************************/
|
193 |
|
194 |
/**
|
195 |
* @brief Print a separator line.
|
196 |
*
|
197 |
* @param[in] stream Stream to print to or NULL to print to all system streams.
|
198 |
* @param[in] c Character to use.
|
199 |
* @param[in] n Length of the separator line.
|
200 |
*
|
201 |
* @return Number of characters printed.
|
202 |
*/
|
203 |
static unsigned int _printSystemInfoSeparator(BaseSequentialStream* stream, const char c, const unsigned int n) |
204 |
{ |
205 |
aosDbgCheck(stream != NULL);
|
206 |
|
207 |
// print the specified character n times
|
208 |
for (unsigned int i = 0; i < n; ++i) { |
209 |
streamPut(stream, c); |
210 |
} |
211 |
streamPut(stream, '\n');
|
212 |
|
213 |
return n+1; |
214 |
} |
215 |
|
216 |
/**
|
217 |
* @brief Print a system information line.
|
218 |
* @details Prints a system information line with the following format:
|
219 |
* "<name>[spaces]fmt"
|
220 |
* The combined width of "<name>[spaces]" can be specified in order to align <fmt> on multiple lines.
|
221 |
* Note that there is not trailing newline added implicitely.
|
222 |
*
|
223 |
* @param[in] stream Stream to print to or NULL to print to all system streams.
|
224 |
* @param[in] name Name of the entry/line.
|
225 |
* @param[in] namewidth Width of the name column.
|
226 |
* @param[in] fmt Formatted string of information content.
|
227 |
*
|
228 |
* @return Number of characters printed.
|
229 |
*/
|
230 |
static unsigned int _printSystemInfoLine(BaseSequentialStream* stream, const char* name, const unsigned int namewidth, const char* fmt, ...) |
231 |
{ |
232 |
aosDbgCheck(stream != NULL);
|
233 |
aosDbgCheck(name != NULL);
|
234 |
|
235 |
unsigned int n = 0; |
236 |
va_list ap; |
237 |
|
238 |
va_start(ap, fmt); |
239 |
n += chprintf(stream, name); |
240 |
while (n < namewidth) {
|
241 |
streamPut(stream, ' ');
|
242 |
++n; |
243 |
} |
244 |
n += chvprintf(stream, fmt, ap); |
245 |
va_end(ap); |
246 |
|
247 |
streamPut(stream, '\n');
|
248 |
++n; |
249 |
|
250 |
return n;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* @brief Prints information about the system.
|
255 |
*
|
256 |
* @param[in] stream Stream to print to.
|
257 |
*/
|
258 |
static void _printSystemInfo(BaseSequentialStream* stream) |
259 |
{ |
260 |
aosDbgCheck(stream != NULL);
|
261 |
|
262 |
// local variables
|
263 |
#if (HAL_USE_RTC == TRUE)
|
264 |
struct tm dt;
|
265 |
aosSysGetDateTime(&dt); |
266 |
#endif /* (HAL_USE_RTC == TRUE) */ |
267 |
|
268 |
// print static information about module and operating system
|
269 |
_printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
|
270 |
_printSystemInfoLine(stream, "Module", SYSTEM_INFO_NAMEWIDTH, "%s", BOARD_NAME); |
271 |
#if defined(PLATFORM_NAME)
|
272 |
_printSystemInfoLine(stream, "Platform", SYSTEM_INFO_NAMEWIDTH, "%s", PLATFORM_NAME); |
273 |
#endif /* defined(PLATFORM_NAME) */ |
274 |
#if defined(PORT_CORE_VARIANT_NAME)
|
275 |
_printSystemInfoLine(stream, "Core Variant", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_CORE_VARIANT_NAME); |
276 |
#endif /* defined(PORT_CORE_VARIANT_NAME) */ |
277 |
_printSystemInfoLine(stream, "Architecture", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_ARCHITECTURE_NAME); |
278 |
_printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
|
279 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
280 |
_printSystemInfoLine(stream, "AMiRo-OS" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (SSSP %u.%u)", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE, AOS_SYSTEM_SSSP_VERSION_MAJOR, AOS_SYSTEM_SSSP_VERSION_MINOR); |
281 |
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
282 |
_printSystemInfoLine(stream, "AMiRo-OS" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE); |
283 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
284 |
_printSystemInfoLine(stream, "AMiRo-LLD" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (periphAL %u.%u)", AMIRO_LLD_VERSION_MAJOR, AMIRO_LLD_VERSION_MINOR, AMIRO_LLD_VERSION_PATCH, AMIRO_LLD_RELEASE_TYPE, PERIPHAL_VERSION_MAJOR, PERIPHAL_VERSION_MINOR); |
285 |
_printSystemInfoLine(stream, "ChibiOS/RT" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s", CH_KERNEL_MAJOR, CH_KERNEL_MINOR, CH_KERNEL_PATCH, (CH_KERNEL_STABLE == 1) ? "stable" : "non-stable"); |
286 |
_printSystemInfoLine(stream, "ChibiOS/HAL", SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s", CH_HAL_MAJOR, CH_HAL_MINOR, CH_HAL_PATCH, (CH_HAL_STABLE == 1) ? "stable" : "non-stable"); |
287 |
_printSystemInfoLine(stream, "build type", SYSTEM_INFO_NAMEWIDTH,"%s", (AMIROOS_CFG_DBG == true) ? "debug" : "release"); |
288 |
_printSystemInfoLine(stream, "Compiler" , SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u", "GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); // TODO: support other compilers than GCC |
289 |
_printSystemInfoLine(stream, "Compiled" , SYSTEM_INFO_NAMEWIDTH, "%s - %s", __DATE__, __TIME__); |
290 |
|
291 |
// print static information about the bootloader
|
292 |
_printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
|
293 |
if (BL_CALLBACK_TABLE_ADDRESS->magicNumber == BL_MAGIC_NUMBER) {
|
294 |
_printSystemInfoLine(stream, "AMiRo-BLT", SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (SSSP %u.%u)", BL_CALLBACK_TABLE_ADDRESS->vBootloader.major, BL_CALLBACK_TABLE_ADDRESS->vBootloader.minor, BL_CALLBACK_TABLE_ADDRESS->vBootloader.patch, |
295 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Release) ? "stable" :
|
296 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_ReleaseCandidate) ? "release candidate" :
|
297 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Beta) ? "beta" :
|
298 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Alpha) ? "alpha" :
|
299 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_PreAlpha) ? "pre-alpha" :
|
300 |
"<release type unknown>",
|
301 |
BL_CALLBACK_TABLE_ADDRESS->vSSSP.major, BL_CALLBACK_TABLE_ADDRESS->vSSSP.minor); |
302 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
303 |
if (BL_CALLBACK_TABLE_ADDRESS->vSSSP.major != AOS_SYSTEM_SSSP_VERSION_MAJOR) {
|
304 |
if (stream) {
|
305 |
chprintf(stream, "WARNING: Bootloader and AMiRo-OS implement incompatible SSSP versions!\n");
|
306 |
} else {
|
307 |
aosprintf("WARNING: Bootloader and AMiRo-OS implement incompatible SSSP versions!\n");
|
308 |
} |
309 |
} |
310 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
311 |
_printSystemInfoLine(stream, "Compiler", SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u", (BL_CALLBACK_TABLE_ADDRESS->vCompiler.identifier == BL_VERSION_ID_GCC) ? "GCC" : "<compiler unknown>", BL_CALLBACK_TABLE_ADDRESS->vCompiler.major, BL_CALLBACK_TABLE_ADDRESS->vCompiler.minor, BL_CALLBACK_TABLE_ADDRESS->vCompiler.patch); // TODO: support other compilers than GCC |
312 |
} else {
|
313 |
if (stream) {
|
314 |
chprintf(stream, "Bootload |