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