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