amiro-os / core / src / aos_system.c @ f606e2bf
History | View | Annotate | Download (35.813 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 80 |
52 |
|
53 |
/**
|
54 |
* @brief Width of the name column of the system info table.
|
55 |
*/
|
56 |
#define SYSTEM_INFO_NAMEWIDTH 20 |
57 |
|
58 |
/******************************************************************************/
|
59 |
/* EXPORTED VARIABLES */
|
60 |
/******************************************************************************/
|
61 |
|
62 |
/**
|
63 |
* @brief Global system object.
|
64 |
*/
|
65 |
aos_system_t aos; |
66 |
|
67 |
/******************************************************************************/
|
68 |
/* LOCAL TYPES */
|
69 |
/******************************************************************************/
|
70 |
|
71 |
/******************************************************************************/
|
72 |
/* LOCAL VARIABLES */
|
73 |
/******************************************************************************/
|
74 |
|
75 |
/*
|
76 |
* forward declarations
|
77 |
*/
|
78 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
79 |
static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[]); |
80 |
static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[]); |
81 |
static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[]); |
82 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
83 |
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]); |
84 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
85 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
86 |
|
87 |
/**
|
88 |
* @brief Timer to accumulate system uptime.
|
89 |
*/
|
90 |
static virtual_timer_t _systimer;
|
91 |
|
92 |
/**
|
93 |
* @brief Accumulated system uptime.
|
94 |
*/
|
95 |
static aos_timestamp_t _uptime;
|
96 |
|
97 |
/**
|
98 |
* @brief Timer register value of last accumulation.
|
99 |
*/
|
100 |
static systime_t _synctime;
|
101 |
|
102 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
103 |
|
104 |
/**
|
105 |
* @brief Shell thread working area.
|
106 |
*/
|
107 |
THD_WORKING_AREA(_shell_wa, AMIROOS_CFG_SHELL_STACKSIZE); |
108 |
|
109 |
/**
|
110 |
* @brief Shell input buffer.
|
111 |
*/
|
112 |
static char _shell_line[AMIROOS_CFG_SHELL_LINEWIDTH]; |
113 |
|
114 |
/**
|
115 |
* @brief Shell argument buffer.
|
116 |
*/
|
117 |
static char* _shell_arglist[AMIROOS_CFG_SHELL_MAXARGS]; |
118 |
|
119 |
/**
|
120 |
* @brief Shell command to retrieve system information.
|
121 |
*/
|
122 |
static AOS_SHELL_COMMAND(_shellcmd_info, "module:info", _shellcmd_infocb); |
123 |
|
124 |
/**
|
125 |
* @brief Shell command to set or retrieve system configuration.
|
126 |
*/
|
127 |
static AOS_SHELL_COMMAND(_shellcmd_config, "module:config", _shellcmd_configcb); |
128 |
|
129 |
/**
|
130 |
* @brief Shell command to shutdown the system.
|
131 |
*/
|
132 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
133 |
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "system:shutdown", _shellcmd_shutdowncb); |
134 |
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
135 |
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "module:shutdown", _shellcmd_shutdowncb); |
136 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
137 |
|
138 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
139 |
|
140 |
/**
|
141 |
* @brief Shell kommand to run a test of the ChibiOS/RT kernel.
|
142 |
*/
|
143 |
static AOS_SHELL_COMMAND(_shellcmd_kerneltest, "kernel:test", _shellcmd_kerneltestcb); |
144 |
|
145 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
146 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
147 |
|
148 |
/******************************************************************************/
|
149 |
/* LOCAL FUNCTIONS */
|
150 |
/******************************************************************************/
|
151 |
|
152 |
/**
|
153 |
* @brief Print a separator line.
|
154 |
*
|
155 |
* @param[in] stream Stream to print to or NULL to print to all system streams.
|
156 |
* @param[in] c Character to use.
|
157 |
* @param[in] n Length of the separator line.
|
158 |
*
|
159 |
* @return Number of characters printed.
|
160 |
*/
|
161 |
static unsigned int _printSystemInfoSeparator(BaseSequentialStream* stream, const char c, const unsigned int n) |
162 |
{ |
163 |
aosDbgCheck(stream != NULL);
|
164 |
|
165 |
// print the specified character n times
|
166 |
for (unsigned int i = 0; i < n; ++i) { |
167 |
streamPut(stream, (uint8_t)c); |
168 |
} |
169 |
streamPut(stream, '\n');
|
170 |
|
171 |
return n+1; |
172 |
} |
173 |
|
174 |
/**
|
175 |
* @brief Print a system information line.
|
176 |
* @details Prints a system information line with the following format:
|
177 |
* "<name>[spaces]fmt"
|
178 |
* The combined width of "<name>[spaces]" can be specified in order to align <fmt> on multiple lines.
|
179 |
* Note that there is not trailing newline added implicitely.
|
180 |
*
|
181 |
* @param[in] stream Stream to print to or NULL to print to all system streams.
|
182 |
* @param[in] name Name of the entry/line.
|
183 |
* @param[in] namewidth Minimum width of the name column.
|
184 |
* @param[in] fmt Formatted string of information content.
|
185 |
*
|
186 |
* @return Number of characters printed.
|
187 |
*/
|
188 |
static unsigned int _printSystemInfoLine(BaseSequentialStream* stream, const char* name, const unsigned int namewidth, const char* fmt, ...) |
189 |
{ |
190 |
aosDbgCheck(stream != NULL);
|
191 |
aosDbgCheck(name != NULL);
|
192 |
|
193 |
unsigned int n = 0; |
194 |
va_list ap; |
195 |
|
196 |
va_start(ap, fmt); |
197 |
n += (unsigned int)chprintf(stream, name); |
198 |
// print at least a single space character
|
199 |
do {
|
200 |
streamPut(stream, ' ');
|
201 |
++n; |
202 |
} while (n < namewidth);
|
203 |
n += (unsigned int)chvprintf(stream, fmt, ap); |
204 |
va_end(ap); |
205 |
|
206 |
streamPut(stream, '\n');
|
207 |
++n; |
208 |
|
209 |
return n;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* @brief Prints information about the system.
|
214 |
*
|
215 |
* @param[in] stream Stream to print to.
|
216 |
*/
|
217 |
static void _printSystemInfo(BaseSequentialStream* stream) |
218 |
{ |
219 |
aosDbgCheck(stream != NULL);
|
220 |
|
221 |
// local variables
|
222 |
#if (HAL_USE_RTC == TRUE)
|
223 |
struct tm dt;
|
224 |
aosSysGetDateTime(&dt); |
225 |
#endif /* (HAL_USE_RTC == TRUE) */ |
226 |
|
227 |
// print static information about module and operating system
|
228 |
_printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
|
229 |
_printSystemInfoLine(stream, "Module", SYSTEM_INFO_NAMEWIDTH, "%s", BOARD_NAME); |
230 |
#if defined(PLATFORM_NAME)
|
231 |
_printSystemInfoLine(stream, "Platform", SYSTEM_INFO_NAMEWIDTH, "%s", PLATFORM_NAME); |
232 |
#endif /* defined(PLATFORM_NAME) */ |
233 |
#if defined(PORT_CORE_VARIANT_NAME)
|
234 |
_printSystemInfoLine(stream, "Core Variant", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_CORE_VARIANT_NAME); |
235 |
#endif /* defined(PORT_CORE_VARIANT_NAME) */ |
236 |
_printSystemInfoLine(stream, "Architecture", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_ARCHITECTURE_NAME); |
237 |
_printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
|
238 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
239 |
_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_SSSP_VERSION_MAJOR, AOS_SSSP_VERSION_MINOR); |
240 |
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
241 |
_printSystemInfoLine(stream, "AMiRo-OS" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE); |
242 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
243 |
_printSystemInfoLine(stream, "AMiRo-LLD" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (periphAL %u.%u)", AMIROLLD_VERSION_MAJOR, AMIROLLD_VERSION_MINOR, AMIROLLD_VERSION_PATCH, AMIROLLD_RELEASE_TYPE, PERIPHAL_VERSION_MAJOR, PERIPHAL_VERSION_MINOR); |
244 |
_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"); |
245 |
_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"); |
246 |
_printSystemInfoLine(stream, "build type", SYSTEM_INFO_NAMEWIDTH,"%s", (AMIROOS_CFG_DBG == true) ? "debug" : "release"); |
247 |
_printSystemInfoLine(stream, "Compiler" , SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u", "GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); // TODO: support other compilers than GCC |
248 |
_printSystemInfoLine(stream, "Compiled" , SYSTEM_INFO_NAMEWIDTH, "%s - %s", __DATE__, __TIME__); |
249 |
|
250 |
// print static information about the bootloader
|
251 |
#if (AMIROOS_CFG_BOOTLOADER != AOS_BOOTLOADER_NONE)
|
252 |
_printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
|
253 |
#endif /* (AMIROOS_CFG_BOOTLOADER != AOS_BOOTLOADER_NONE) */ |
254 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
|
255 |
if (BL_CALLBACK_TABLE_ADDRESS->magicNumber == BL_MAGIC_NUMBER) {
|
256 |
_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, |
257 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Release) ? "stable" :
|
258 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_ReleaseCandidate) ? "release candidate" :
|
259 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Beta) ? "beta" :
|
260 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Alpha) ? "alpha" :
|
261 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_PreAlpha) ? "pre-alpha" :
|
262 |
"<release type unknown>",
|
263 |
BL_CALLBACK_TABLE_ADDRESS->vSSSP.major, BL_CALLBACK_TABLE_ADDRESS->vSSSP.minor); |
264 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
265 |
if (BL_CALLBACK_TABLE_ADDRESS->vSSSP.major != AOS_SSSP_VERSION_MAJOR) {
|
266 |
const char* msg = "WARNING: AMiRo-BLT and AMiRo-OS implement incompatible SSSP versions!\n"; |
267 |
stream ? chprintf(stream, msg) : aosprintf(msg); |
268 |
} |
269 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
270 |
_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 |
271 |
} else {
|
272 |
const char* msg = "WARNING: AMiRo-BLT incompatible or not available.\n"; |
273 |
stream ? chprintf(stream, "%s", msg) : aosprintf("%s", msg); |
274 |
} |
275 |
#endif /* (AMIROOS_CFG_BOOTLOADER == X) */ |
276 |
|
277 |
#if defined(AMIROOS_CFG_SYSINFO_HOOK)
|
278 |
// print module specific information
|
279 |
_printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
|
280 |
AMIROOS_CFG_SYSINFO_HOOK(); |
281 |
#endif /* defined(AMIROOS_CFG_SYSINFO_HOOK) */ |
282 |
|
283 |
// print dynamic information about the module
|
284 |
_printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
|
285 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
286 |
if (aos.sssp.moduleId != 0) { |
287 |
_printSystemInfoLine(stream, "Module ID", SYSTEM_INFO_NAMEWIDTH, "%u", aos.sssp.moduleId); |
288 |
} else {
|
289 |
_printSystemInfoLine(stream, "Module ID", SYSTEM_INFO_NAMEWIDTH, "not available"); |
290 |
} |
291 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
292 |
#if (HAL_USE_RTC == TRUE)
|
293 |
_printSystemInfoLine(stream, "Date", SYSTEM_INFO_NAMEWIDTH, "%04u-%02u-%02u (%s)", |
294 |
dt.tm_year + 1900,
|
295 |
dt.tm_mon + 1,
|
296 |
dt.tm_mday, |
297 |
(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"); |
298 |
_printSystemInfoLine(stream, "Time", SYSTEM_INFO_NAMEWIDTH, "%02u:%02u:%02u", dt.tm_hour, dt.tm_min, dt.tm_sec); |
299 |
#endif /* (HAL_USE_RTC == TRUE) */ |
300 |
|
301 |
_printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
|
302 |
|
303 |
return;
|
304 |
} |
305 |
|
306 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
307 |
/**
|
308 |
* @brief Callback function for the system:config shell command.
|
309 |
*
|
310 |
* @param[in] stream The I/O stream to use.
|
311 |
* @param[in] argc Number of arguments.
|
312 |
* @param[in] argv List of pointers to the arguments.
|
313 |
*
|
314 |
* @return An exit status.
|
315 |
* @retval AOS_OK The command was executed successfuly.
|
316 |
* @retval AOS_INVALIDARGUMENTS There was an issue with the arguemnts.
|
317 |
*/
|
318 |
static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[]) |
319 |
{ |
320 |
aosDbgCheck(stream != NULL);
|
321 |
|
322 |
// local variables
|
323 |
int retval = AOS_INVALIDARGUMENTS;
|
324 |
|
325 |
// if there are additional arguments
|
326 |
if (argc > 1) { |
327 |
// if the user wants to set or retrieve the shell configuration
|
328 |
if (strcmp(argv[1], "--shell") == 0) { |
329 |
// if the user wants to modify the shell configuration
|
330 |
if (argc > 2) { |
331 |
// if the user wants to modify the prompt
|
332 |
if (strcmp(argv[2], "prompt") == 0) { |
333 |
// there must be a further argument
|
334 |
if (argc > 3) { |
335 |
// handle the option
|
336 |
if (strcmp(argv[3], "text") == 0) { |
337 |
aos.shell.config &= ~AOS_SHELL_CONFIG_PROMPT_MINIMAL; |
338 |
retval = AOS_OK; |
339 |
} |
340 |
else if (strcmp(argv[3], "minimal") == 0) { |
341 |
aos.shell.config |= AOS_SHELL_CONFIG_PROMPT_MINIMAL; |
342 |
retval = AOS_OK; |
343 |
} |
344 |
else if (strcmp(argv[3], "notime") == 0) { |
345 |
aos.shell.config &= ~(AOS_SHELL_CONFIG_PROMPT_UPTIME | AOS_SHELL_CONFIG_PROMPT_DATETIME); |
346 |
retval = AOS_OK; |
347 |
} |
348 |
else if (strcmp(argv[3], "uptime") == 0) { |
349 |
aos.shell.config &= ~AOS_SHELL_CONFIG_PROMPT_DATETIME; |
350 |
aos.shell.config |= AOS_SHELL_CONFIG_PROMPT_UPTIME; |
351 |
retval = AOS_OK; |
352 |
} |
353 |
else if (strcmp(argv[3], "date&time") == 0) { |
354 |
aos.shell.config &= ~AOS_SHELL_CONFIG_PROMPT_UPTIME; |
355 |
aos.shell.config |= AOS_SHELL_CONFIG_PROMPT_DATETIME; |
356 |
retval = AOS_OK; |
357 |
} |
358 |
else {
|
359 |
chprintf(stream, "unknown option '%s'\n", argv[3]); |
360 |
return AOS_INVALIDARGUMENTS;
|
361 |
} |
362 |
} |
363 |
} |
364 |
// if the user wants to modify the string matching
|
365 |
else if (strcmp(argv[2], "match") == 0) { |
366 |
// there must be a further argument
|
367 |
if (argc > 3) { |
368 |
if (strcmp(argv[3], "casesensitive") == 0) { |
369 |
aos.shell.config |= AOS_SHELL_CONFIG_MATCH_CASE; |
370 |
retval = AOS_OK; |
371 |
} |
372 |
else if (strcmp(argv[3], "caseinsensitive") == 0) { |
373 |
aos.shell.config &= ~AOS_SHELL_CONFIG_MATCH_CASE; |
374 |
retval = AOS_OK; |
375 |
} |
376 |
} |
377 |
} |
378 |
} |
379 |
// if the user wants to retrieve the shell configuration
|
380 |
else {
|
381 |
chprintf(stream, "current shell configuration:\n");
|
382 |
chprintf(stream, " prompt text: %s\n",
|
383 |
(aos.shell.prompt != NULL) ? aos.shell.prompt : "n/a"); |
384 |
char time[10]; |
385 |
switch (aos.shell.config & (AOS_SHELL_CONFIG_PROMPT_UPTIME | AOS_SHELL_CONFIG_PROMPT_DATETIME)) {
|
386 |
case AOS_SHELL_CONFIG_PROMPT_UPTIME:
|
387 |
strcpy(time, "uptime"); break; |
388 |
case AOS_SHELL_CONFIG_PROMPT_DATETIME:
|
389 |
strcpy(time, "date&time"); break; |
390 |
default:
|
391 |
strcpy(time, "no time"); break; |
392 |
} |
393 |
chprintf(stream, " prompt style: %s, %s\n",
|
394 |
(aos.shell.config & AOS_SHELL_CONFIG_PROMPT_MINIMAL) ? "minimal" : "text", |
395 |
time); |
396 |
chprintf(stream, " input method: %s\n",
|
397 |
(aos.shell.config & AOS_SHELL_CONFIG_INPUT_OVERWRITE) ? "replace" : "insert"); |
398 |
chprintf(stream, " text matching: %s\n",
|
399 |
(aos.shell.config & AOS_SHELL_CONFIG_MATCH_CASE) ? "case sensitive" : "case insensitive"); |
400 |
retval = AOS_OK; |
401 |
} |
402 |
} |
403 |
# if (HAL_USE_RTC == TRUE)
|
404 |
// if the user wants to configure the date or time
|
405 |
else if (strcmp(argv[1], "--date&time") == 0 && argc == 4) { |
406 |
struct tm dt;
|
407 |
aosSysGetDateTime(&dt); |
408 |
int val = atoi(argv[3]); |
409 |
if (strcmp(argv[2], "year") == 0 && val >= 1900) { |
410 |
dt.tm_year = val - 1900;
|
411 |
} |
412 |
else if (strcmp(argv[2], "month") == 0 && val > 0 && val <= 12) { |
413 |
dt.tm_mon = val - 1;
|
414 |
} |
415 |
else if (strcmp(argv[2], "day") == 0 && val > 0 && val <= 31) { |
416 |
dt.tm_mday = val; |
417 |
} |
418 |
else if (strcmp(argv[2], "hour") == 0 && val >= 0 && val < 24) { |
419 |
dt.tm_hour = val; |
420 |
} |
421 |
else if (strcmp(argv[2], "minute") == 0 && val >= 0 && val < 60) { |
422 |
dt.tm_min = val; |
423 |
} |
424 |
else if (strcmp(argv[2], "second") == 0 && val >= 0 && val < 60) { |
425 |
dt.tm_sec = val; |
426 |
} |
427 |
else {
|
428 |
chprintf(stream, "unknown option '%s' or invalid value '%s'\n", argv[2], argv[3]); |
429 |
return AOS_INVALIDARGUMENTS;
|
430 |
} |
431 |
dt.tm_wday = aosTimeDayOfWeekFromDate((uint16_t)dt.tm_mday, (uint8_t)dt.tm_mon+1, (uint16_t)dt.tm_year+1900) % DAYS_PER_WEEK; |
432 |
aosSysSetDateTime(&dt); |
433 |
|
434 |
// read and print new date and time
|
435 |
aosSysGetDateTime(&dt); |
436 |
chprintf(stream, "date/time set to %04u-%02u-%02u %02u:%02u:%02u\n",
|
437 |
dt.tm_year+1900, dt.tm_mon+1, dt.tm_mday, |
438 |
dt.tm_hour, dt.tm_min, dt.tm_sec); |
439 |
|
440 |
retval = AOS_OK; |
441 |
} |
442 |
#endif /* (HAL_USE_RTC == TRUE) */ |
443 |
} |
444 |
|
445 |
// print help, if required
|
446 |
if (retval == AOS_INVALIDARGUMENTS) {
|
447 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
448 |
chprintf(stream, "Options:\n");
|
449 |
chprintf(stream, " --help\n");
|
450 |
chprintf(stream, " Print this help text.\n");
|
451 |
chprintf(stream, " --shell [OPT [VAL]]\n");
|
452 |
chprintf(stream, " Set or retrieve shell configuration.\n");
|
453 |
chprintf(stream, " Possible OPTs and VALs are:\n");
|
454 |
chprintf(stream, " prompt text|minimal|uptime|date&time|notime\n");
|
455 |
chprintf(stream, " Configures the prompt.\n");
|
456 |
chprintf(stream, " match casesensitive|caseinsenitive\n");
|
457 |
chprintf(stream, " Configures string matching.\n");
|
458 |
#if (HAL_USE_RTC == TRUE)
|
459 |
chprintf(stream, " --date&time OPT VAL\n");
|
460 |
chprintf(stream, " Set the date/time value of OPT to VAL.\n");
|
461 |
chprintf(stream, " Possible OPTs are:\n");
|
462 |
chprintf(stream, " year\n");
|
463 |
chprintf(stream, " month\n");
|
464 |
chprintf(stream, " day\n");
|
465 |
chprintf(stream, " hour\n");
|
466 |
chprintf(stream, " minute\n");
|
467 |
chprintf(stream, " second\n");
|
468 |
#endif /* (HAL_USE_RTC == TRUE) */ |
469 |
} |
470 |
|
471 |
return (argc > 1 && strcmp(argv[1], "--help") == 0) ? AOS_OK : retval; |
472 |
} |
473 |
|
474 |
/**
|
475 |
* @brief Callback function for the system:info shell command.
|
476 |
*
|
477 |
* @param[in] stream The I/O stream to use.
|
478 |
* @param[in] argc Number of arguments.
|
479 |
* @param[in] argv List of pointers to the arguments.
|
480 |
*
|
481 |
* @return An exit status.
|
482 |
* @retval AOS_OK The command was executed successfully.
|
483 |
*/
|
484 |
static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[]) |
485 |
{ |
486 |
aosDbgCheck(stream != NULL);
|
487 |
|
488 |
(void)argc;
|
489 |
(void)argv;
|
490 |
|
491 |
// print system information
|
492 |
_printSystemInfo(stream); |
493 |
|
494 |
// print time measurement precision
|
495 |
chprintf(stream, "module time resolution: %uus\n", AOS_SYSTEM_TIME_RESOLUTION);
|
496 |
|
497 |
// print system uptime
|
498 |
aos_timestamp_t uptime; |
499 |
aosSysGetUptime(&uptime); |
500 |
chprintf(stream, "The system is running for\n");
|
501 |
chprintf(stream, "%10u days\n", (uint32_t)(uptime / MICROSECONDS_PER_DAY));
|
502 |
chprintf(stream, "%10u hours\n", (uint8_t)(uptime % MICROSECONDS_PER_DAY / MICROSECONDS_PER_HOUR));
|
503 |
chprintf(stream, "%10u minutes\n", (uint8_t)(uptime % MICROSECONDS_PER_HOUR / MICROSECONDS_PER_MINUTE));
|
504 |
chprintf(stream, "%10u seconds\n", (uint8_t)(uptime % MICROSECONDS_PER_MINUTE / MICROSECONDS_PER_SECOND));
|
505 |
chprintf(stream, "%10u milliseconds\n", (uint16_t)(uptime % MICROSECONDS_PER_SECOND / MICROSECONDS_PER_MILLISECOND));
|
506 |
chprintf(stream, "%10u microseconds\n", (uint16_t)(uptime % MICROSECONDS_PER_MILLISECOND / MICROSECONDS_PER_MICROSECOND));
|
507 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) |
508 |
chprintf(stream, "SSSP synchronization offset: %.3fus per %uus\n", (double)aosSsspGetSyncSkew(), AMIROOS_CFG_SSSP_SYSSYNCPERIOD); |
509 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) */ |
510 |
_printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
|
511 |
|
512 |
// print shell info
|
513 |
chprintf(stream, "System shell information:\n");
|
514 |
chprintf(stream, "\tcommands available: %u\n", aosShellCountCommands(&aos.shell));
|
515 |
chprintf(stream, "\tline width: %u characters\n", aos.shell.input.width);
|
516 |
chprintf(stream, "\tmaximum arguments: %u\n", aos.shell.arglistsize);
|
517 |
#if (AMIROOS_CFG_DBG == true) |
518 |
chprintf(stream, "\tthread stack size: %u bytes\n", aosThdGetStacksize(aos.shell.thread));
|
519 |
#if (CH_DBG_FILL_THREADS == TRUE)
|
520 |
chprintf(stream, "\tstack peak utilization: %u bytes (%.2f%%)\n", aosThdGetStackPeakUtilization(aos.shell.thread), (double)((float)(aosThdGetStackPeakUtilization(aos.shell.thread)) / (float)(aosThdGetStacksize(aos.shell.thread)) * 100.0f)); |
521 |
#endif /* (CH_DBG_FILL_THREADS == TRUE) */ |
522 |
#endif /* (AMIROOS_CFG_DBG == true) */ |
523 |
_printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
|
524 |
|
525 |
return AOS_OK;
|
526 |
} |
527 |
|
528 |
/**
|
529 |
* @brief Callback function for the sytem:shutdown or module:shutdown shell command.
|
530 |
*
|
531 |
* @param[in] stream The I/O stream to use.
|
532 |
* @param[in] argc Number of arguments.
|
533 |
* @param[in] argv List of pointers to the arguments.
|
534 |
*
|
535 |
* @return An exit status.
|
536 |
* @retval AOS_OK The command was executed successfully.
|
537 |
* @retval AOS_INVALIDARGUMENTS There was an issue with the arguments.
|
538 |
*/
|
539 |
static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[]) |
540 |
{ |
541 |
aosDbgCheck(stream != NULL);
|
542 |
|
543 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE)
|
544 |
|
545 |
(void)argv;
|
546 |
|
547 |
if (argc != 1) { |
548 |
// error
|
549 |
chprintf(stream, "ERROR: no arguments allowed.\n");
|
550 |
return AOS_INVALIDARGUMENTS;
|
551 |
} else {
|
552 |
// broadcast shutdown event
|
553 |
chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_MASK); |
554 |
// set terminate flag so no further prompt will be printed
|
555 |
chThdTerminate(chThdGetSelfX()); |
556 |
return AOS_OK;
|
557 |
} |
558 |
|
559 |
#elif (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
|
560 |
|
561 |
// print help text
|
562 |
if (argc != 2 || strcmp(argv[1], "--help") == 0) { |
563 |
chprintf(stream, "Usage: %s OPTION\n", argv[0]); |
564 |
chprintf(stream, "Options:\n");
|
565 |
chprintf(stream, " --help\n");
|
566 |
chprintf(stream, " Print this help text.\n");
|
567 |
chprintf(stream, " --hibernate, -h\n");
|
568 |
chprintf(stream, " Shutdown to hibernate mode.\n");
|
569 |
chprintf(stream, " Least energy saving, but allows charging via pins.\n");
|
570 |
chprintf(stream, " --deepsleep, -d\n");
|
571 |
chprintf(stream, " Shutdown to deepsleep mode.\n");
|
572 |
chprintf(stream, " Minimum energy consumption while allowing charging via plug.\n");
|
573 |
chprintf(stream, " --transportation, -t\n");
|
574 |
chprintf(stream, " Shutdown to transportation mode.\n");
|
575 |
chprintf(stream, " Minimum energy consumption with all interrupts disabled (no charging).\n");
|
576 |
chprintf(stream, " --restart, -r\n");
|
577 |
chprintf(stream, " Shutdown and restart system.\n");
|
578 |
|
579 |
return (argc != 2) ? AOS_INVALIDARGUMENTS : AOS_OK; |
580 |
} |
581 |
// handle argument
|
582 |
else {
|
583 |
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--hibernate") == 0) { |
584 |
// broadcast shutdown event
|
585 |
chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_HIBERNATE); |
586 |
// set terminate flag so no further prompt will be printed
|
587 |
chThdTerminate(chThdGetSelfX()); |
588 |
return AOS_OK;
|
589 |
} |
590 |
else if (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--deepsleep") == 0) { |
591 |
// broadcast shutdown event
|
592 |
chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_DEEPSLEEP); |
593 |
// set terminate flag so no further prompt will be printed
|
594 |
chThdTerminate(chThdGetSelfX()); |
595 |
return AOS_OK;
|
596 |
} |
597 |
else if (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--transportation") == 0) { |
598 |
// broadcast shutdown event
|
599 |
chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_TRANSPORTATION); |
600 |
// set terminate flag so no further prompt will be printed
|
601 |
chThdTerminate(chThdGetSelfX()); |
602 |
return AOS_OK;
|
603 |
} |
604 |
else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--restart") == 0) { |
605 |
// broadcast shutdown event
|
606 |
chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_RESTART); |
607 |
// set terminate flag so no further prompt will be printed
|
608 |
chThdTerminate(chThdGetSelfX()); |
609 |
return AOS_OK;
|
610 |
} |
611 |
else {
|
612 |
chprintf(stream, "unknown argument %s\n", argv[1]); |
613 |
return AOS_INVALIDARGUMENTS;
|
614 |
} |
615 |
} |
616 |
|
617 |
#endif /* (AMIROOS_CFG_BOOTLOADER == X) */ |
618 |
} |
619 |
|
620 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
621 |
|
622 |
/**
|
623 |
* @brief Callback function for the kernel:test shell command.
|
624 |
*
|
625 |
* @param[in] stream The I/O stream to use.
|
626 |
* @param[in] argc Number of arguments.
|
627 |
* @param[in] argv List of pointers to the arguments.
|
628 |
*
|
629 |
* @return An exit status.
|
630 |
*/
|
631 |
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]) |
632 |
{ |
633 |
aosDbgCheck(stream != NULL);
|
634 |
|
635 |
(void)argc;
|
636 |
(void)argv;
|
637 |
|
638 |
msg_t retval = test_execute(stream, &rt_test_suite); |
639 |
|
640 |
return retval;
|
641 |
} |
642 |
|
643 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
644 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
645 |
|
646 |
// suppress warning in case no interrupt GPIOs are defined
|
647 |
#pragma GCC diagnostic push
|
648 |
#pragma GCC diagnostic ignored "-Wunused-function" |
649 |
/**
|
650 |
* @brief Generic callback function for GPIO interrupts.
|
651 |
*
|
652 |
* @param[in] args Pointer to the GPIO line identifier.
|
653 |
*/
|
654 |
static void _gpioCallback(void* args) |
655 |
{ |
656 |
aosDbgCheck((args != NULL) && (*((ioline_t*)args) != PAL_NOLINE) && (PAL_PAD(*((ioline_t*)args)) < sizeof(eventflags_t) * 8)); |
657 |
|
658 |
chSysLockFromISR(); |
659 |
chEvtBroadcastFlagsI(&aos.events.gpio, AOS_GPIOEVENT_FLAG(PAL_PAD(*((ioline_t*)args)))); |
660 |
chSysUnlockFromISR(); |
661 |
|
662 |
return;
|
663 |
} |
664 |
#pragma GCC diagnostic pop
|
665 |
|
666 |
/**
|
667 |
* @brief Callback function for the uptime accumulation timer.
|
668 |
*
|
669 |
* @param[in] par Generic parameter.
|
670 |
*/
|
671 |
static void _uptimeCallback(void* par) |
672 |
{ |
673 |
(void)par;
|
674 |
|
675 |
chSysLockFromISR(); |
676 |
// read current time in system ticks
|
677 |
register const systime_t st = chVTGetSystemTimeX(); |
678 |
// update the uptime variables
|
679 |
_uptime += chTimeI2US(chTimeDiffX(_synctime, st)); |
680 |
_synctime = st; |
681 |
// enable the timer again
|
682 |
chVTSetI(&_systimer, SYSTIMER_PERIOD, &_uptimeCallback, NULL);
|
683 |
chSysUnlockFromISR(); |
684 |
|
685 |
return;
|
686 |
} |
687 |
|
688 |
/**
|
689 |
* @brief Retreive the number of active threads.
|
690 |
*
|
691 |
* @return Number of active threads.
|
692 |
*/
|
693 |
size_t _numActiveThreads(void)
|
694 |
{ |
695 |
size_t threads = 0;
|
696 |
thread_t* tp = chRegFirstThread(); |
697 |
while (tp) {
|
698 |
threads += (tp->state == CH_STATE_FINAL) ? 1 : 0; |
699 |
tp = chRegNextThread(tp); |
700 |
} |
701 |
|
702 |
return threads;
|
703 |
} |
704 |
|
705 |
/******************************************************************************/
|
706 |
/* EXPORTED FUNCTIONS */
|
707 |
/******************************************************************************/
|
708 |
|
709 |
/**
|
710 |
* @brief AMiRo-OS system initialization.
|
711 |
* @note Must be called from the system control thread (usually main thread).
|
712 |
*
|
713 |
* @param[in] shellPrompt String to be printed as prompt of the system shell.
|
714 |
*/
|
715 |
void aosSysInit(const char* shellPrompt) |
716 |
{ |
717 |
/* set control thread to maximum priority */
|
718 |
chThdSetPriority(AOS_THD_CTRLPRIO); |
719 |
|
720 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
721 |
aosSsspInit(&_uptime); |
722 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
723 |
|
724 |
/* set local variables */
|
725 |
chVTObjectInit(&_systimer); |
726 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
727 |
// uptime counter is started when SSSP proceeds to operation phase
|
728 |
_synctime = 0;
|
729 |
_uptime = 0;
|
730 |
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
731 |
// start the uptime counter
|
732 |
chSysLock(); |
733 |
aosSysStartUptimeS(); |
734 |
chSysUnlock(); |
735 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
736 |
|
737 |
/* initialize aos configuration */
|
738 |
aosIOStreamInit(&aos.iostream); |
739 |
chEvtObjectInit(&aos.events.gpio); |
740 |
chEvtObjectInit(&aos.events.os); |
741 |
|
742 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) |
743 |
|
744 |
/* init shell */
|
745 |
aosShellInit(&aos.shell, |
746 |
&aos.events.os, |
747 |
shellPrompt, |
748 |
_shell_line, |
749 |
AMIROOS_CFG_SHELL_LINEWIDTH, |
750 |
_shell_arglist, |
751 |
AMIROOS_CFG_SHELL_MAXARGS); |
752 |
// add system commands
|
753 |
aosShellAddCommand(&aos.shell, &_shellcmd_config); |
754 |
aosShellAddCommand(&aos.shell, &_shellcmd_info); |
755 |
aosShellAddCommand(&aos.shell, &_shellcmd_shutdown); |
756 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) |
757 |
aosShellAddCommand(&aos.shell, &_shellcmd_kerneltest); |
758 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
759 |
|
760 |
#else /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
761 |
|
762 |
// suppress unused variable warnings
|
763 |
(void)shellPrompt;
|
764 |
|
765 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
766 |
|
767 |
return;
|
768 |
} |
769 |
|
770 |
/**
|
771 |
* @brief Starts the system and all system threads.
|
772 |
*/
|
773 |
void aosSysStart(void) |
774 |
{ |
775 |
// print system information;
|
776 |
_printSystemInfo((BaseSequentialStream*)&aos.iostream); |
777 |
aosprintf("\n");
|
778 |
|
779 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) |
780 |
// start system shell thread
|
781 |
#if (CH_CFG_USE_THREADHIERARCHY == TRUE)
|
782 |
aos.shell.thread = chThdCreateStatic(_shell_wa, sizeof(_shell_wa), AMIROOS_CFG_SHELL_THREADPRIO, aosShellThread, &aos.shell, &ch.mainthread);
|
783 |
#else /* (CH_CFG_USE_THREADHIERARCHY == TRUE) */ |
784 |
aos.shell.thread = chThdCreateStatic(_shell_wa, sizeof(_shell_wa), AMIROOS_CFG_SHELL_THREADPRIO, aosShellThread, &aos.shell);
|
785 |
#endif /* (CH_CFG_USE_THREADHIERARCHY == TRUE) */ |
786 |
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
787 |
|
788 |
return;
|
789 |
} |
790 |
|
791 |
/**
|
792 |
* @brief Start the system uptime measurement.
|
793 |
* @note Must be called from a locked context.
|
794 |
*/
|
795 |
void aosSysStartUptimeS(void) |
796 |
{ |
797 |
chDbgCheckClassS(); |
798 |
|
799 |
// start the uptime aggregation counter
|
800 |
_synctime = chVTGetSystemTimeX(); |
801 |
_uptime = 0;
|
802 |
chVTSetI(&_systimer, SYSTIMER_PERIOD, &_uptimeCallback, NULL);
|
803 |
|
804 |
return;
|
805 |
} |
806 |
|
807 |
/**
|
808 |
* @brief Retrieves the system uptime.
|
809 |
*
|
810 |
* @param[out] ut The system uptime.
|
811 |
*/
|
812 |
void aosSysGetUptimeX(aos_timestamp_t* ut)
|
813 |
{ |
814 |
aosDbgCheck(ut != NULL);
|
815 |
|
816 |
*ut = _uptime + chTimeI2US(chTimeDiffX(_synctime, chVTGetSystemTimeX())); |
817 |
|
818 |
return;
|
819 |
} |
820 |
|
821 |
#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
|
822 |
|
823 |
/**
|
824 |
* @brief retrieves the date and time from the MCU clock.
|
825 |
*
|
826 |
* @param[out] td The date and time.
|
827 |
*/
|
828 |
void aosSysGetDateTime(struct tm* dt) |
829 |
{ |
830 |
aosDbgCheck(dt != NULL);
|
831 |
|
832 |
RTCDateTime rtc; |
833 |
rtcGetTime(&MODULE_HAL_RTC, &rtc); |
834 |
rtcConvertDateTimeToStructTm(&rtc, dt, NULL);
|
835 |
|
836 |
return;
|
837 |
} |
838 |
|
839 |
/**
|
840 |
* @brief set the date and time of the MCU clock.
|
841 |
*
|
842 |
* @param[in] dt The date and time to set.
|
843 |
*/
|
844 |
void aosSysSetDateTime(struct tm* dt) |
845 |
{ |
846 |
aosDbgCheck(dt != NULL);
|
847 |
|
848 |
RTCDateTime rtc; |
849 |
rtcConvertStructTmToDateTime(dt, 0, &rtc);
|
850 |
rtcSetTime(&MODULE_HAL_RTC, &rtc); |
851 |
|
852 |
return;
|
853 |
} |
854 |
|
855 |
#endif /* (HAL_USE_RTC == TRUE) */ |
856 |
|
857 |
/**
|
858 |
* @brief Initializes/Acknowledges a system shutdown/restart request.
|
859 |
* @note This functions should be called from the thread with highest priority.
|
860 |
*
|
861 |
* @param[in] shutdown Type of shutdown.
|
862 |
*/
|
863 |
void aosSysShutdownInit(aos_shutdown_t shutdown)
|
864 |
{ |
865 |
// check arguments
|
866 |
aosDbgCheck(shutdown != AOS_SHUTDOWN_NONE); |
867 |
|
868 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
869 |
|
870 |
// activate the PD signal only if this module initiated the shutdown
|
871 |
if (shutdown != AOS_SHUTDOWN_PASSIVE) {
|
872 |
aosSsspShutdownInit(true);
|
873 |
} |
874 |
|
875 |
switch (shutdown) {
|
876 |
case AOS_SHUTDOWN_PASSIVE:
|
877 |
chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_PASSIVE); |
878 |
aosprintf("shutdown request received...\n");
|
879 |
break;
|
880 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE)
|
881 |
case AOS_SHUTDOWN_ACTIVE:
|
882 |
aosprintf("shutdown initiated...\n");
|
883 |
break;
|
884 |
#elif (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
|
885 |
case AOS_SHUTDOWN_HIBERNATE:
|
886 |
aosprintf("shutdown to hibernate mode...\n");
|
887 |
break;
|
888 |
case AOS_SHUTDOWN_DEEPSLEEP:
|
889 |
aosprintf("shutdown to deepsleep mode...\n");
|
890 |
break;
|
891 |
case AOS_SHUTDOWN_TRANSPORTATION:
|
892 |
aosprintf("shutdown to transportation mode...\n");
|
893 |
break;
|
894 |
case AOS_SHUTDOWN_RESTART:
|
895 |
aosprintf("restarting system...\n");
|
896 |
break;
|
897 |
#endif /* (AMIROOS_CFG_BOOTLOADER == X) */ |
898 |
case AOS_SHUTDOWN_NONE:
|
899 |
// must never occur
|
900 |
aosDbgAssert(false);
|
901 |
break;
|
902 |
} |
903 |
|
904 |
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
905 |
|
906 |
aosprintf("shutdown initiated...\n");
|
907 |
|
908 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
909 |
|
910 |
return;
|
911 |
} |
912 |
|
913 |
/**
|
914 |
* @brief Stops the system and all related threads (not the thread this function is called from).
|
915 |
*/
|
916 |
void aosSysStop(void) |
917 |
{ |
918 |
// wait until the calling thread is the only remaining active thread
|
919 |
#if (CH_CFG_NO_IDLE_THREAD == TRUE)
|
920 |
while (_numActiveThreads() > 1) { |
921 |
#else /* (CH_CFG_NO_IDLE_THREAD == TRUE) */ |
922 |
while (_numActiveThreads() > 2) { |
923 |
#endif /* (CH_CFG_NO_IDLE_THREAD == TRUE) */ |
924 |
aosDbgPrintf("waiting for all threads to terminate...\n");
|
925 |
chThdYield(); |
926 |
} |
927 |
|
928 |
return;
|
929 |
} |
930 |
|
931 |
/**
|
932 |
* @brief Deinitialize all system variables.
|
933 |
*/
|
934 |
void aosSysDeinit(void) |
935 |
{ |
936 |
return;
|
937 |
} |
938 |
|
939 |
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) || \ |
940 |
((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) || \
|
941 |
defined(__DOXYGEN__) |
942 |
|
943 |
/**
|
944 |
* @brief Finally shuts down the system and calls the bootloader callback function.
|
945 |
* @note This function should be called from the thtead with highest priority.
|
946 |
*
|
947 |
* @param[in] shutdown Type of shutdown.
|
948 |
*/
|
949 |
void aosSysShutdownToBootloader(aos_shutdown_t shutdown)
|
950 |
{ |
951 |
// check arguments
|
952 |
aosDbgCheck(shutdown != AOS_SHUTDOWN_NONE); |
953 |
|
954 |
// disable all interrupts
|
955 |
irqDeinit(); |
956 |
|
957 |
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
|
958 |
// validate AMiRo-BLT
|
959 |
if ((BL_CALLBACK_TABLE_ADDRESS->magicNumber == BL_MAGIC_NUMBER) &&
|
960 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.major == BL_VERSION_MAJOR) && |
961 |
(BL_CALLBACK_TABLE_ADDRESS->vBootloader.minor >= BL_VERSION_MINOR)) { |
962 |
// call bootloader callback depending on arguments
|
963 |
switch (shutdown) {
|
964 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) |
965 |
case AOS_SHUTDOWN_PASSIVE:
|
966 |
BL_CALLBACK_TABLE_ADDRESS->cbHandleShutdownRequest(); |
967 |
break;
|
968 |
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
969 |
case AOS_SHUTDOWN_HIBERNATE:
|
970 |
BL_CALLBACK_TABLE_ADDRESS->cbShutdownHibernate(); |
971 |
break;
|
972 |
case AOS_SHUTDOWN_DEEPSLEEP:
|
973 |
BL_CALLBACK_TABLE_ADDRESS->cbShutdownDeepsleep(); |
974 |
break;
|
975 |
case AOS_SHUTDOWN_TRANSPORTATION:
|
976 |
BL_CALLBACK_TABLE_ADDRESS->cbShutdownTransportation(); |
977 |
break;
|
978 |
case AOS_SHUTDOWN_RESTART:
|
979 |
BL_CALLBACK_TABLE_ADDRESS->cbShutdownRestart(); |
980 |
break;
|
981 |
// must never occur
|
982 |
case AOS_SHUTDOWN_NONE:
|
983 |
default:
|
984 |
break;
|
985 |
} |
986 |
} else {
|
987 |
// fallback if AMiRo-BLT was found to be invalid
|
988 |
aosprintf("ERROR: AMiRo-BLT incompatible or not available!\n");
|
989 |
aosThdMSleep(10);
|
990 |
chSysDisable(); |
991 |
} |
992 |
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) */ |
993 |
|
994 |
return;
|
995 |
} |
996 |
|
997 |
#endif /* ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) || ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) */ |
998 |
|
999 |
/**
|
1000 |
* @brief Generic callback function for GPIO interrupts.
|
1001 |
*
|
1002 |
* @return Pointer to the callback function.
|
1003 |
*/
|
1004 |
palcallback_t aosSysGetStdGpioCallback(void)
|
1005 |
{ |
1006 |
return _gpioCallback;
|
1007 |
} |
1008 |
|
1009 |
/** @} */
|