Statistics
| Branch: | Tag: | Revision:

amiro-os / core / src / aos_system.c @ 697dba3c

History | View | Annotate | Download (36.139 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
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
59

    
60
/**
61
 * @brief   Number of entries in the system shell input buffer.
62
 */
63
#define SYSTEM_SHELL_BUFFERENTRIES    (1 + AMIROOS_CFG_SHELL_HISTLENGTH)
64

    
65
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
66

    
67
/******************************************************************************/
68
/* EXPORTED VARIABLES                                                         */
69
/******************************************************************************/
70

    
71
/**
72
 * @brief   Global system object.
73
 */
74
aos_system_t aos;
75

    
76
/******************************************************************************/
77
/* LOCAL TYPES                                                                */
78
/******************************************************************************/
79

    
80
/******************************************************************************/
81
/* LOCAL VARIABLES                                                            */
82
/******************************************************************************/
83

    
84
/*
85
 * forward declarations
86
 */
87
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
88
static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[]);
89
static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[]);
90
static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[]);
91
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
92
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]);
93
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
94
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
95

    
96
/**
97
 * @brief   Timer to accumulate system uptime.
98
 */
99
static virtual_timer_t _systimer;
100

    
101
/**
102
 * @brief   Accumulated system uptime.
103
 */
104
static aos_timestamp_t _uptime;
105

    
106
/**
107
 * @brief   Timer register value of last accumulation.
108
 */
109
static systime_t _synctime;
110

    
111
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
112

    
113
/**
114
 * @brief   Shell thread working area.
115
 */
116
static THD_WORKING_AREA(_shell_wa, AMIROOS_CFG_SHELL_STACKSIZE);
117

    
118
/**
119
 * @brief   Shell input buffer.
120
 */
121
static char _shell_buffer[SYSTEM_SHELL_BUFFERENTRIES * AMIROOS_CFG_SHELL_LINEWIDTH];
122

    
123
/**
124
 * @brief   Shell command to retrieve system information.
125
 */
126
static AOS_SHELL_COMMAND(_shellcmd_info, "module:info", _shellcmd_infocb);
127

    
128
/**
129
 * @brief   Shell command to set or retrieve system configuration.
130
 */
131
static AOS_SHELL_COMMAND(_shellcmd_config, "module:config", _shellcmd_configcb);
132

    
133
/**
134
 * @brief   Shell command to shutdown the system.
135
 */
136
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
137
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "system:shutdown", _shellcmd_shutdowncb);
138
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
139
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "module:shutdown", _shellcmd_shutdowncb);
140
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
141

    
142
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
143

    
144
/**
145
 * @brief   Shell kommand to run a test of the ChibiOS/RT kernel.
146
 */
147
static AOS_SHELL_COMMAND(_shellcmd_kerneltest, "kernel:test", _shellcmd_kerneltestcb);
148

    
149
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
150
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
151

    
152
/******************************************************************************/
153
/* LOCAL FUNCTIONS                                                            */
154
/******************************************************************************/
155

    
156
/**
157
 * @brief   Print a separator line.
158
 *
159
 * @param[in] stream    Stream to print to or NULL to print to all system streams.
160
 * @param[in] c         Character to use.
161
 * @param[in] n         Length of the separator line.
162
 *
163
 * @return  Number of characters printed.
164
 */
165
static unsigned int _printSystemInfoSeparator(BaseSequentialStream* stream, const char c, const unsigned int n)
166
{
167
  aosDbgCheck(stream != NULL);
168

    
169
  // print the specified character n times
170
  for (unsigned int i = 0; i < n; ++i) {
171
    streamPut(stream, (uint8_t)c);
172
  }
173
  streamPut(stream, '\n');
174

    
175
  return n+1;
176
}
177

    
178
/**
179
 * @brief   Print a system information line.
180
 * @details Prints a system information line with the following format:
181
 *            "<name>[spaces]fmt"
182
 *          The combined width of "<name>[spaces]" can be specified in order to align <fmt> on multiple lines.
183
 *          Note that there is not trailing newline added implicitely.
184
 *
185
 * @param[in] stream      Stream to print to or NULL to print to all system streams.
186
 * @param[in] name        Name of the entry/line.
187
 * @param[in] namewidth   Minimum width of the name column.
188
 * @param[in] fmt         Formatted string of information content.
189
 *
190
 * @return  Number of characters printed.
191
 */
192
static unsigned int _printSystemInfoLine(BaseSequentialStream* stream, const char* name, const unsigned int namewidth, const char* fmt, ...)
193
{
194
  aosDbgCheck(stream != NULL);
195
  aosDbgCheck(name != NULL);
196

    
197
  unsigned int n = 0;
198
  va_list ap;
199

    
200
  va_start(ap, fmt);
201
  n += (unsigned int)chprintf(stream, name);
202
  // print at least a single space character
203
  do {
204
    streamPut(stream, ' ');
205
    ++n;
206
  } while (n < namewidth);
207
  n += (unsigned int)chvprintf(stream, fmt, ap);
208
  va_end(ap);
209

    
210
  streamPut(stream, '\n');
211
  ++n;
212

    
213
  return n;
214
}
215

    
216
/**
217
 * @brief   Prints information about the system.
218
 *
219
 * @param[in] stream    Stream to print to.
220
 */
221
static void _printSystemInfo(BaseSequentialStream* stream)
222
{
223
  aosDbgCheck(stream != NULL);
224

    
225
  // local variables
226
#if (HAL_USE_RTC == TRUE)
227
  struct tm dt;
228
  aosSysGetDateTime(&dt);
229
#endif /* (HAL_USE_RTC == TRUE) */
230

    
231
  // print static information about module and operating system
232
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
233
  _printSystemInfoLine(stream, "Module", SYSTEM_INFO_NAMEWIDTH, "%s", BOARD_NAME);
234
#if defined(PLATFORM_NAME)
235
  _printSystemInfoLine(stream, "Platform", SYSTEM_INFO_NAMEWIDTH, "%s", PLATFORM_NAME);
236
#endif /* defined(PLATFORM_NAME) */
237
#if defined(PORT_CORE_VARIANT_NAME)
238
  _printSystemInfoLine(stream, "Core Variant", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_CORE_VARIANT_NAME);
239
#endif /* defined(PORT_CORE_VARIANT_NAME) */
240
  _printSystemInfoLine(stream, "Architecture", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_ARCHITECTURE_NAME);
241
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
242
#if (AMIROOS_CFG_SSSP_ENABLE == true)
243
  _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);
244
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
245
  _printSystemInfoLine(stream, "AMiRo-OS" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE);
246
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
247
  _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);
248
  _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");
249
  _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");
250
  _printSystemInfoLine(stream, "build type", SYSTEM_INFO_NAMEWIDTH,"%s", (AMIROOS_CFG_DBG == true) ? "debug" : "release");
251
  _printSystemInfoLine(stream, "Compiler" , SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u", "GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); // TODO: support other compilers than GCC
252
  _printSystemInfoLine(stream, "Compiled" , SYSTEM_INFO_NAMEWIDTH, "%s - %s", __DATE__, __TIME__);
253

    
254
  // print static information about the bootloader
255
#if (AMIROOS_CFG_BOOTLOADER != AOS_BOOTLOADER_NONE)
256
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
257
#endif /* (AMIROOS_CFG_BOOTLOADER != AOS_BOOTLOADER_NONE) */
258
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
259
  if (BL_CALLBACK_TABLE_ADDRESS->magicNumber == BL_MAGIC_NUMBER) {
260
    _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,
261
                         (BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Release) ? "stable" :
262
                         (BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_ReleaseCandidate) ? "release candidate" :
263
                         (BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Beta) ? "beta" :
264
                         (BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Alpha) ? "alpha" :
265
                         (BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_PreAlpha) ? "pre-alpha" :
266
                         "<release type unknown>",
267
                         BL_CALLBACK_TABLE_ADDRESS->vSSSP.major, BL_CALLBACK_TABLE_ADDRESS->vSSSP.minor);
268
#if (AMIROOS_CFG_SSSP_ENABLE == true)
269
    if (BL_CALLBACK_TABLE_ADDRESS->vSSSP.major != AOS_SSSP_VERSION_MAJOR) {
270
      const char* msg = "WARNING: AMiRo-BLT and AMiRo-OS implement incompatible SSSP versions!\n";
271
      stream ? chprintf(stream, msg) : aosprintf(msg);
272
    }
273
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
274
    _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
275
  } else {
276
    const char* msg = "WARNING: AMiRo-BLT incompatible or not available.\n";
277
    stream ? chprintf(stream, "%s", msg) : aosprintf("%s", msg);
278
  }
279
#endif /* (AMIROOS_CFG_BOOTLOADER == X) */
280

    
281
#if defined(AMIROOS_CFG_SYSINFO_HOOK)
282
  // print module specific information
283
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
284
  AMIROOS_CFG_SYSINFO_HOOK();
285
#endif /* defined(AMIROOS_CFG_SYSINFO_HOOK) */
286

    
287
  // print dynamic information about the module
288
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
289
#if (AMIROOS_CFG_SSSP_ENABLE == true)
290
  if (aos.sssp.moduleId != 0) {
291
    _printSystemInfoLine(stream, "Module ID", SYSTEM_INFO_NAMEWIDTH, "%u", aos.sssp.moduleId);
292
  } else {
293
    _printSystemInfoLine(stream, "Module ID", SYSTEM_INFO_NAMEWIDTH, "not available");
294
  }
295
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
296
#if (HAL_USE_RTC == TRUE)
297
  _printSystemInfoLine(stream, "Date", SYSTEM_INFO_NAMEWIDTH, "%04u-%02u-%02u (%s)",
298
                       dt.tm_year + 1900,
299
                       dt.tm_mon + 1,
300
                       dt.tm_mday,
301
                       (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");
302
  _printSystemInfoLine(stream, "Time", SYSTEM_INFO_NAMEWIDTH, "%02u:%02u:%02u", dt.tm_hour, dt.tm_min, dt.tm_sec);
303
#endif /* (HAL_USE_RTC == TRUE) */
304

    
305
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
306

    
307
  return;
308
}
309

    
310
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
311
/**
312
 * @brief   Callback function for the system:config shell command.
313
 *
314
 * @param[in] stream    The I/O stream to use.
315
 * @param[in] argc      Number of arguments.
316
 * @param[in] argv      List of pointers to the arguments.
317
 *
318
 * @return              An exit status.
319
 * @retval  AOS_OK                  The command was executed successfuly.
320
 * @retval  AOS_INVALIDARGUMENTS    There was an issue with the arguemnts.
321
 */
322
static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[])
323
{
324
  aosDbgCheck(stream != NULL);
325

    
326
  // local variables
327
  int retval = AOS_INVALIDARGUMENTS;
328

    
329
  // if there are additional arguments
330
  if (argc > 1) {
331
    // if the user wants to set or retrieve the shell configuration
332
    if (strcmp(argv[1], "--shell") == 0) {
333
      // if the user wants to modify the shell configuration
334
      if (argc > 2) {
335
        // if the user wants to modify the prompt
336
        if (strcmp(argv[2], "prompt") == 0) {
337
          // there must be a further argument
338
          if (argc > 3) {
339
            // handle the option
340
            if (strcmp(argv[3], "text") == 0) {
341
              aos.shell.config &= ~AOS_SHELL_CONFIG_PROMPT_MINIMAL;
342
              retval = AOS_OK;
343
            }
344
            else if (strcmp(argv[3], "minimal") == 0) {
345
              aos.shell.config |= AOS_SHELL_CONFIG_PROMPT_MINIMAL;
346
              retval = AOS_OK;
347
            }
348
            else if (strcmp(argv[3], "notime") == 0) {
349
              aos.shell.config &= ~(AOS_SHELL_CONFIG_PROMPT_UPTIME | AOS_SHELL_CONFIG_PROMPT_DATETIME);
350
              retval = AOS_OK;
351
            }
352
            else if (strcmp(argv[3], "uptime") == 0) {
353
              aos.shell.config &= ~AOS_SHELL_CONFIG_PROMPT_DATETIME;
354
              aos.shell.config |= AOS_SHELL_CONFIG_PROMPT_UPTIME;
355
              retval = AOS_OK;
356
            }
357
            else if (strcmp(argv[3], "date&time") == 0) {
358
              aos.shell.config &= ~AOS_SHELL_CONFIG_PROMPT_UPTIME;
359
              aos.shell.config |= AOS_SHELL_CONFIG_PROMPT_DATETIME;
360
              retval = AOS_OK;
361
            }
362
            else {
363
              chprintf(stream, "unknown option '%s'\n", argv[3]);
364
              return AOS_INVALIDARGUMENTS;
365
            }
366
          }
367
        }
368
        // if the user wants to modify the string matching
369
        else if (strcmp(argv[2], "match") == 0) {
370
          // there must be a further argument
371
          if (argc > 3) {
372
            if (strcmp(argv[3], "casesensitive") == 0) {
373
              aos.shell.config |= AOS_SHELL_CONFIG_MATCH_CASE;
374
              retval = AOS_OK;
375
            }
376
            else if (strcmp(argv[3], "caseinsensitive") == 0) {
377
              aos.shell.config &= ~AOS_SHELL_CONFIG_MATCH_CASE;
378
              retval = AOS_OK;
379
            }
380
          }
381
        }
382
      }
383
      // if the user wants to retrieve the shell configuration
384
      else {
385
        chprintf(stream, "current shell configuration:\n");
386
        chprintf(stream, "  prompt text:   %s\n",
387
                 (aos.shell.prompt != NULL) ? aos.shell.prompt : "n/a");
388
        char time[10];
389
        switch (aos.shell.config & (AOS_SHELL_CONFIG_PROMPT_UPTIME | AOS_SHELL_CONFIG_PROMPT_DATETIME)) {
390
          case AOS_SHELL_CONFIG_PROMPT_UPTIME:
391
            strcpy(time, "uptime"); break;
392
          case AOS_SHELL_CONFIG_PROMPT_DATETIME:
393
            strcpy(time, "date&time"); break;
394
          default:
395
            strcpy(time, "no time"); break;
396
        }
397
        chprintf(stream, "  prompt style:  %s, %s\n",
398
                 (aos.shell.config & AOS_SHELL_CONFIG_PROMPT_MINIMAL) ? "minimal" : "text",
399
                 time);
400
        chprintf(stream, "  input method:  %s\n",
401
                 (aos.shell.config & AOS_SHELL_CONFIG_INPUT_OVERWRITE) ? "replace" : "insert");
402
        chprintf(stream, "  text matching: %s\n",
403
                 (aos.shell.config & AOS_SHELL_CONFIG_MATCH_CASE) ? "case sensitive" : "case insensitive");
404
        retval = AOS_OK;
405
      }
406
    }
407
# if (HAL_USE_RTC == TRUE)
408
    // if the user wants to configure the date or time
409
    else if (strcmp(argv[1], "--date&time") == 0 && argc == 4) {
410
      struct tm dt;
411
      aosSysGetDateTime(&dt);
412
      int val = atoi(argv[3]);
413
      if (strcmp(argv[2], "year") == 0 && val >= 1900) {
414
        dt.tm_year = val - 1900;
415
      }
416
      else if (strcmp(argv[2], "month") == 0 && val > 0 && val <= 12) {
417
        dt.tm_mon = val - 1;
418
      }
419
      else if (strcmp(argv[2], "day") == 0 && val > 0 && val <= 31) {
420
        dt.tm_mday = val;
421
      }
422
      else if (strcmp(argv[2], "hour") == 0 && val >= 0 && val < 24) {
423
        dt.tm_hour = val;
424
      }
425
      else if (strcmp(argv[2], "minute") == 0 && val >= 0 && val < 60) {
426
        dt.tm_min = val;
427
      }
428
      else if (strcmp(argv[2], "second") == 0 && val >= 0 && val < 60) {
429
        dt.tm_sec = val;
430
      }
431
      else {
432
        chprintf(stream, "unknown option '%s' or invalid value '%s'\n", argv[2], argv[3]);
433
        return AOS_INVALIDARGUMENTS;
434
      }
435
      dt.tm_wday = aosTimeDayOfWeekFromDate((uint16_t)dt.tm_mday, (uint8_t)dt.tm_mon+1, (uint16_t)dt.tm_year+1900) % DAYS_PER_WEEK;
436
      aosSysSetDateTime(&dt);
437

    
438
      // read and print new date and time
439
      aosSysGetDateTime(&dt);
440
      chprintf(stream, "date/time set to %04u-%02u-%02u %02u:%02u:%02u\n",
441
               dt.tm_year+1900, dt.tm_mon+1, dt.tm_mday,
442
               dt.tm_hour, dt.tm_min, dt.tm_sec);
443

    
444
      retval = AOS_OK;
445
    }
446
#endif /* (HAL_USE_RTC == TRUE) */
447
  }
448

    
449
  // print help, if required
450
  if (retval == AOS_INVALIDARGUMENTS) {
451
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
452
    chprintf(stream, "Options:\n");
453
    chprintf(stream, "  --help\n");
454
    chprintf(stream, "    Print this help text.\n");
455
    chprintf(stream, "  --shell [OPT [VAL]]\n");
456
    chprintf(stream, "    Set or retrieve shell configuration.\n");
457
    chprintf(stream, "    Possible OPTs and VALs are:\n");
458
    chprintf(stream, "      prompt text|minimal|uptime|date&time|notime\n");
459
    chprintf(stream, "        Configures the prompt.\n");
460
    chprintf(stream, "      match casesensitive|caseinsenitive\n");
461
    chprintf(stream, "        Configures string matching.\n");
462
#if (HAL_USE_RTC == TRUE)
463
    chprintf(stream, "  --date&time OPT VAL\n");
464
    chprintf(stream, "    Set the date/time value of OPT to VAL.\n");
465
    chprintf(stream, "    Possible OPTs are:\n");
466
    chprintf(stream, "      year\n");
467
    chprintf(stream, "      month\n");
468
    chprintf(stream, "      day\n");
469
    chprintf(stream, "      hour\n");
470
    chprintf(stream, "      minute\n");
471
    chprintf(stream, "      second\n");
472
#endif /* (HAL_USE_RTC == TRUE) */
473
  }
474

    
475
  return (argc > 1 && strcmp(argv[1], "--help") == 0) ? AOS_OK : retval;
476
}
477

    
478
/**
479
 * @brief   Callback function for the system:info shell command.
480
 *
481
 * @param[in] stream    The I/O stream to use.
482
 * @param[in] argc      Number of arguments.
483
 * @param[in] argv      List of pointers to the arguments.
484
 *
485
 * @return            An exit status.
486
 * @retval  AOS_OK    The command was executed successfully.
487
 */
488
static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[])
489
{
490
  aosDbgCheck(stream != NULL);
491

    
492
  (void)argc;
493
  (void)argv;
494

    
495
  // print system information
496
  _printSystemInfo(stream);
497

    
498
  // print time measurement precision
499
  chprintf(stream, "module time resolution: %uus\n", AOS_SYSTEM_TIME_RESOLUTION);
500

    
501
  // print system uptime
502
  aos_timestamp_t uptime;
503
  aosSysGetUptime(&uptime);
504
  chprintf(stream, "The system is running for\n");
505
  chprintf(stream, "%10u days\n", (uint32_t)(uptime / MICROSECONDS_PER_DAY));
506
  chprintf(stream, "%10u hours\n", (uint8_t)(uptime % MICROSECONDS_PER_DAY / MICROSECONDS_PER_HOUR));
507
  chprintf(stream, "%10u minutes\n", (uint8_t)(uptime % MICROSECONDS_PER_HOUR / MICROSECONDS_PER_MINUTE));
508
  chprintf(stream, "%10u seconds\n", (uint8_t)(uptime % MICROSECONDS_PER_MINUTE / MICROSECONDS_PER_SECOND));
509
  chprintf(stream, "%10u milliseconds\n", (uint16_t)(uptime % MICROSECONDS_PER_SECOND / MICROSECONDS_PER_MILLISECOND));
510
  chprintf(stream, "%10u microseconds\n", (uint16_t)(uptime % MICROSECONDS_PER_MILLISECOND / MICROSECONDS_PER_MICROSECOND));
511
#if (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)
512
  chprintf(stream, "SSSP synchronization offset: %.3fus per %uus\n", (double)aosSsspGetSyncSkew(), AMIROOS_CFG_SSSP_SYSSYNCPERIOD);
513
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) */
514
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
515

    
516
  // print shell info
517
  chprintf(stream, "System shell information:\n");
518
  chprintf(stream, "\tcommands available:     %u\n", aosShellCountCommands(&aos.shell));
519
  chprintf(stream, "\tinput width:            %u characters\n", aos.shell.input.linewidth);
520
  chprintf(stream, "\tmaximum arguments:      %u\n", aos.shell.input.nargs);
521
  chprintf(stream, "\thistory size:           %u\n", aos.shell.input.nentries - 1);
522
#if (AMIROOS_CFG_DBG == true)
523
  chprintf(stream, "\tthread stack size:      %u bytes\n", aosThdGetStacksize(aos.shell.thread));
524
#if (CH_DBG_FILL_THREADS == TRUE)
525
  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));
526
#endif /* (CH_DBG_FILL_THREADS == TRUE) */
527
#endif /* (AMIROOS_CFG_DBG == true) */
528
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
529

    
530
  return AOS_OK;
531
}
532

    
533
/**
534
 * @brief   Callback function for the sytem:shutdown or module:shutdown shell command.
535
 *
536
 * @param[in] stream    The I/O stream to use.
537
 * @param[in] argc      Number of arguments.
538
 * @param[in] argv      List of pointers to the arguments.
539
 *
540
 * @return              An exit status.
541
 * @retval  AOS_OK                  The command was executed successfully.
542
 * @retval  AOS_INVALIDARGUMENTS   There was an issue with the arguments.
543
 */
544
static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[])
545
{
546
  aosDbgCheck(stream != NULL);
547

    
548
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE)
549

    
550
  (void)argv;
551

    
552
  if (argc != 1) {
553
    // error
554
    chprintf(stream, "ERROR: no arguments allowed.\n");
555
    return AOS_INVALIDARGUMENTS;
556
  } else {
557
    // broadcast shutdown event
558
    chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_MASK);
559
    // set terminate flag so no further prompt will be printed
560
    chThdTerminate(chThdGetSelfX());
561
    return AOS_OK;
562
  }
563

    
564
#elif (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
565

    
566
  // print help text
567
  if (argc != 2 || strcmp(argv[1], "--help") == 0) {
568
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
569
    chprintf(stream, "Options:\n");
570
    chprintf(stream, "  --help\n");
571
    chprintf(stream, "    Print this help text.\n");
572
    chprintf(stream, "  --hibernate, -h\n");
573
    chprintf(stream, "    Shutdown to hibernate mode.\n");
574
    chprintf(stream, "    Least energy saving, but allows charging via pins.\n");
575
    chprintf(stream, "  --deepsleep, -d\n");
576
    chprintf(stream, "    Shutdown to deepsleep mode.\n");
577
    chprintf(stream, "    Minimum energy consumption while allowing charging via plug.\n");
578
    chprintf(stream, "  --transportation, -t\n");
579
    chprintf(stream, "    Shutdown to transportation mode.\n");
580
    chprintf(stream, "    Minimum energy consumption with all interrupts disabled (no charging).\n");
581
    chprintf(stream, "  --restart, -r\n");
582
    chprintf(stream, "    Shutdown and restart system.\n");
583

    
584
    return (argc != 2) ? AOS_INVALIDARGUMENTS : AOS_OK;
585
  }
586
  // handle argument
587
  else {
588
    if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--hibernate") == 0) {
589
      // broadcast shutdown event
590
      chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_HIBERNATE);
591
      // set terminate flag so no further prompt will be printed
592
      chThdTerminate(chThdGetSelfX());
593
      return AOS_OK;
594
    }
595
    else if (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--deepsleep") == 0) {
596
      // broadcast shutdown event
597
      chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_DEEPSLEEP);
598
      // set terminate flag so no further prompt will be printed
599
      chThdTerminate(chThdGetSelfX());
600
      return AOS_OK;
601
    }
602
    else if (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--transportation") == 0) {
603
      // broadcast shutdown event
604
      chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_TRANSPORTATION);
605
      // set terminate flag so no further prompt will be printed
606
      chThdTerminate(chThdGetSelfX());
607
      return AOS_OK;
608
    }
609
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--restart") == 0) {
610
      // broadcast shutdown event
611
      chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_RESTART);
612
      // set terminate flag so no further prompt will be printed
613
      chThdTerminate(chThdGetSelfX());
614
      return AOS_OK;
615
    }
616
    else {
617
      chprintf(stream, "unknown argument %s\n", argv[1]);
618
      return AOS_INVALIDARGUMENTS;
619
    }
620
  }
621

    
622
#endif /* (AMIROOS_CFG_BOOTLOADER == X) */
623
}
624

    
625
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
626

    
627
/**
628
 * @brief   Callback function for the kernel:test shell command.
629
 *
630
 * @param[in] stream    The I/O stream to use.
631
 * @param[in] argc      Number of arguments.
632
 * @param[in] argv      List of pointers to the arguments.
633
 *
634
 * @return      An exit status.
635
 */
636
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[])
637
{
638
  aosDbgCheck(stream != NULL);
639

    
640
  (void)argc;
641
  (void)argv;
642

    
643
  msg_t retval = test_execute(stream, &rt_test_suite);
644

    
645
  return retval;
646
}
647

    
648
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
649
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
650

    
651
// suppress warning in case no interrupt GPIOs are defined
652
#pragma GCC diagnostic push
653
#pragma GCC diagnostic ignored "-Wunused-function"
654
/**
655
 * @brief   Generic callback function for GPIO interrupts.
656
 *
657
 * @param[in] args   Pointer to the GPIO line identifier.
658
 */
659
static void _gpioCallback(void* args)
660
{
661
  aosDbgCheck((args != NULL) && (*((ioline_t*)args) != PAL_NOLINE) && (PAL_PAD(*((ioline_t*)args)) < sizeof(eventflags_t) * 8));
662

    
663
  chSysLockFromISR();
664
  chEvtBroadcastFlagsI(&aos.events.gpio, AOS_GPIOEVENT_FLAG(PAL_PAD(*((ioline_t*)args))));
665
  chSysUnlockFromISR();
666

    
667
  return;
668
}
669
#pragma GCC diagnostic pop
670

    
671
/**
672
 * @brief   Callback function for the uptime accumulation timer.
673
 *
674
 * @param[in] par   Generic parameter.
675
 */
676
static void _uptimeCallback(void* par)
677
{
678
  (void)par;
679

    
680
  chSysLockFromISR();
681
  // read current time in system ticks
682
  register const systime_t st = chVTGetSystemTimeX();
683
  // update the uptime variables
684
  _uptime += chTimeI2US(chTimeDiffX(_synctime, st));
685
  _synctime = st;
686
  // enable the timer again
687
  chVTSetI(&_systimer, SYSTIMER_PERIOD, &_uptimeCallback, NULL);
688
  chSysUnlockFromISR();
689

    
690
  return;
691
}
692

    
693
/**
694
 * @brief   Retreive the number of active threads.
695
 *
696
 * @return  Number of active threads.
697
 */
698
size_t _numActiveThreads(void)
699
{
700
  size_t threads = 0;
701
  thread_t* tp = chRegFirstThread();
702
  while (tp) {
703
    threads += (tp->state == CH_STATE_FINAL) ? 1 : 0;
704
    tp = chRegNextThread(tp);
705
  }
706

    
707
  return threads;
708
}
709

    
710
/******************************************************************************/
711
/* EXPORTED FUNCTIONS                                                         */
712
/******************************************************************************/
713

    
714
/**
715
 * @brief   AMiRo-OS system initialization.
716
 * @note    Must be called from the system control thread (usually main thread).
717
 *
718
 * @param[in] shellPrompt   String to be printed as prompt of the system shell.
719
 */
720
void aosSysInit(const char* shellPrompt)
721
{
722
  aosDbgCheck(shellPrompt != NULL || !AMIROOS_CFG_SHELL_ENABLE);
723

    
724
  /* set control thread to maximum priority */
725
  chThdSetPriority(AOS_THD_CTRLPRIO);
726

    
727
#if (AMIROOS_CFG_SSSP_ENABLE == true)
728
  aosSsspInit(&_uptime);
729
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
730

    
731
  /* set local variables */
732
  chVTObjectInit(&_systimer);
733
#if (AMIROOS_CFG_SSSP_ENABLE == true)
734
  // uptime counter is started when SSSP proceeds to operation phase
735
  _synctime = 0;
736
  _uptime = 0;
737
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
738
  // start the uptime counter
739
  chSysLock();
740
  aosSysStartUptimeS();
741
  chSysUnlock();
742
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
743

    
744
  /* initialize aos configuration */
745
  aosIOStreamInit(&aos.iostream);
746
  chEvtObjectInit(&aos.events.gpio);
747
  chEvtObjectInit(&aos.events.os);
748

    
749
#if (AMIROOS_CFG_SHELL_ENABLE == true)
750

    
751
  /* init shell */
752
  aosShellInit(&aos.shell,
753
               shellPrompt,
754
               _shell_buffer,
755
               SYSTEM_SHELL_BUFFERENTRIES,
756
               AMIROOS_CFG_SHELL_LINEWIDTH,
757
               AMIROOS_CFG_SHELL_MAXARGS);
758
  // add system commands
759
  aosShellAddCommand(&aos.shell, &_shellcmd_config);
760
  aosShellAddCommand(&aos.shell, &_shellcmd_info);
761
  aosShellAddCommand(&aos.shell, &_shellcmd_shutdown);
762
#if (AMIROOS_CFG_TESTS_ENABLE == true)
763
  aosShellAddCommand(&aos.shell, &_shellcmd_kerneltest);
764
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
765

    
766
#else /* (AMIROOS_CFG_SHELL_ENABLE == true) */
767

    
768
  // suppress unused variable warnings
769
  (void)shellPrompt;
770

    
771
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
772

    
773
  return;
774
}
775

    
776
/**
777
 * @brief   Starts the system and all system threads.
778
 */
779
void aosSysStart(void)
780
{
781
  // print system information;
782
  _printSystemInfo((BaseSequentialStream*)&aos.iostream);
783
  aosprintf("\n");
784

    
785
#if (AMIROOS_CFG_SHELL_ENABLE == true)
786
  // start system shell thread
787
#if (CH_CFG_USE_THREADHIERARCHY == TRUE)
788
  aos.shell.thread = chThdCreateStatic(_shell_wa, sizeof(_shell_wa), AMIROOS_CFG_SHELL_THREADPRIO, aosShellThread, &aos.shell, &ch.mainthread);
789
#else /* (CH_CFG_USE_THREADHIERARCHY == TRUE) */
790
  aos.shell.thread = chThdCreateStatic(_shell_wa, sizeof(_shell_wa), AMIROOS_CFG_SHELL_THREADPRIO, aosShellThread, &aos.shell);
791
#endif /* (CH_CFG_USE_THREADHIERARCHY == TRUE) */
792
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
793

    
794
  return;
795
}
796

    
797
/**
798
 * @brief   Start the system uptime measurement.
799
 * @note    Must be called from a locked context.
800
 */
801
void aosSysStartUptimeS(void)
802
{
803
  chDbgCheckClassS();
804

    
805
  // start the uptime aggregation counter
806
  _synctime = chVTGetSystemTimeX();
807
  _uptime = 0;
808
  chVTSetI(&_systimer, SYSTIMER_PERIOD, &_uptimeCallback, NULL);
809

    
810
  return;
811
}
812

    
813
/**
814
 * @brief   Retrieves the system uptime.
815
 *
816
 * @param[out] ut   The system uptime.
817
 */
818
void aosSysGetUptimeX(aos_timestamp_t* ut)
819
{
820
  aosDbgCheck(ut != NULL);
821

    
822
  *ut = _uptime + chTimeI2US(chTimeDiffX(_synctime, chVTGetSystemTimeX()));
823

    
824
  return;
825
}
826

    
827
#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
828

    
829
/**
830
 * @brief   retrieves the date and time from the MCU clock.
831
 *
832
 * @param[out] td   The date and time.
833
 */
834
void aosSysGetDateTime(struct tm* dt)
835
{
836
  aosDbgCheck(dt != NULL);
837

    
838
  RTCDateTime rtc;
839
  rtcGetTime(&MODULE_HAL_RTC, &rtc);
840
  rtcConvertDateTimeToStructTm(&rtc, dt, NULL);
841

    
842
  return;
843
}
844

    
845
/**
846
 * @brief   set the date and time of the MCU clock.
847
 *
848
 * @param[in] dt    The date and time to set.
849
 */
850
void aosSysSetDateTime(struct tm* dt)
851
{
852
  aosDbgCheck(dt != NULL);
853

    
854
  RTCDateTime rtc;
855
  rtcConvertStructTmToDateTime(dt, 0, &rtc);
856
  rtcSetTime(&MODULE_HAL_RTC, &rtc);
857

    
858
  return;
859
}
860

    
861
#endif /* (HAL_USE_RTC == TRUE) */
862

    
863
/**
864
 * @brief   Initializes/Acknowledges a system shutdown/restart request.
865
 * @note    This functions should be called from the thread with highest priority.
866
 *
867
 * @param[in] shutdown    Type of shutdown.
868
 */
869
void aosSysShutdownInit(aos_shutdown_t shutdown)
870
{
871
  // check arguments
872
  aosDbgCheck(shutdown != AOS_SHUTDOWN_NONE);
873

    
874
#if (AMIROOS_CFG_SSSP_ENABLE == true)
875

    
876
  // activate the PD signal only if this module initiated the shutdown
877
  if (shutdown != AOS_SHUTDOWN_PASSIVE) {
878
    aosSsspShutdownInit(true);
879
  }
880

    
881
  switch (shutdown) {
882
    case AOS_SHUTDOWN_PASSIVE:
883
      chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_PASSIVE);
884
      aosprintf("shutdown request received...\n");
885
      break;
886
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE)
887
    case AOS_SHUTDOWN_ACTIVE:
888
      aosprintf("shutdown initiated...\n");
889
      break;
890
#elif (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
891
    case AOS_SHUTDOWN_HIBERNATE:
892
      aosprintf("shutdown to hibernate mode...\n");
893
      break;
894
    case AOS_SHUTDOWN_DEEPSLEEP:
895
      aosprintf("shutdown to deepsleep mode...\n");
896
      break;
897
    case AOS_SHUTDOWN_TRANSPORTATION:
898
      aosprintf("shutdown to transportation mode...\n");
899
      break;
900
    case AOS_SHUTDOWN_RESTART:
901
      aosprintf("restarting system...\n");
902
      break;
903
#endif /* (AMIROOS_CFG_BOOTLOADER == X) */
904
    case AOS_SHUTDOWN_NONE:
905
      // must never occur
906
      aosDbgAssert(false);
907
      break;
908
  }
909

    
910
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
911

    
912
  aosprintf("shutdown initiated...\n");
913

    
914
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
915

    
916
  return;
917
}
918

    
919
/**
920
 * @brief   Stops the system and all related threads (not the thread this function is called from).
921
 */
922
void aosSysStop(void)
923
{
924
  // wait until the calling thread is the only remaining active thread
925
#if (CH_CFG_NO_IDLE_THREAD == TRUE)
926
  while (_numActiveThreads() > 1) {
927
#else /* (CH_CFG_NO_IDLE_THREAD == TRUE) */
928
  while (_numActiveThreads() > 2) {
929
#endif /* (CH_CFG_NO_IDLE_THREAD == TRUE) */
930
    aosDbgPrintf("waiting for all threads to terminate...\n");
931
    chThdYield();
932
  }
933

    
934
  return;
935
}
936

    
937
/**
938
 * @brief   Deinitialize all system variables.
939
 */
940
void aosSysDeinit(void)
941
{
942
  return;
943
}
944

    
945
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) ||                 \
946
    ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) || \
947
    defined(__DOXYGEN__)
948

    
949
/**
950
 * @brief   Finally shuts down the system and calls the bootloader callback function.
951
 * @note    This function should be called from the thtead with highest priority.
952
 *
953
 * @param[in] shutdown    Type of shutdown.
954
 */
955
void aosSysShutdownToBootloader(aos_shutdown_t shutdown)
956
{
957
  // check arguments
958
  aosDbgCheck(shutdown != AOS_SHUTDOWN_NONE);
959

    
960
  // disable all interrupts
961
  irqDeinit();
962

    
963
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
964
  // validate AMiRo-BLT
965
  if ((BL_CALLBACK_TABLE_ADDRESS->magicNumber == BL_MAGIC_NUMBER) &&
966
      (BL_CALLBACK_TABLE_ADDRESS->vBootloader.major == BL_VERSION_MAJOR) &&
967
      (BL_CALLBACK_TABLE_ADDRESS->vBootloader.minor >= BL_VERSION_MINOR)) {
968
    // call bootloader callback depending on arguments
969
    switch (shutdown) {
970
#if (AMIROOS_CFG_SSSP_ENABLE == true)
971
      case AOS_SHUTDOWN_PASSIVE:
972
        BL_CALLBACK_TABLE_ADDRESS->cbHandleShutdownRequest();
973
        break;
974
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
975
      case AOS_SHUTDOWN_HIBERNATE:
976
        BL_CALLBACK_TABLE_ADDRESS->cbShutdownHibernate();
977
        break;
978
      case AOS_SHUTDOWN_DEEPSLEEP:
979
        BL_CALLBACK_TABLE_ADDRESS->cbShutdownDeepsleep();
980
        break;
981
      case AOS_SHUTDOWN_TRANSPORTATION:
982
        BL_CALLBACK_TABLE_ADDRESS->cbShutdownTransportation();
983
        break;
984
      case AOS_SHUTDOWN_RESTART:
985
        BL_CALLBACK_TABLE_ADDRESS->cbShutdownRestart();
986
        break;
987
      // must never occur
988
      case AOS_SHUTDOWN_NONE:
989
      default:
990
        break;
991
    }
992
  } else {
993
    // fallback if AMiRo-BLT was found to be invalid
994
    aosprintf("ERROR: AMiRo-BLT incompatible or not available!\n");
995
    aosThdMSleep(10);
996
    chSysDisable();
997
  }
998
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) */
999

    
1000
  return;
1001
}
1002

    
1003
#endif /* ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) || ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) */
1004

    
1005
/**
1006
 * @brief   Generic callback function for GPIO interrupts.
1007
 *
1008
 * @return  Pointer to the callback function.
1009
 */
1010
palcallback_t aosSysGetStdGpioCallback(void)
1011
{
1012
  return _gpioCallback;
1013
}
1014

    
1015
/** @} */