Statistics
| Branch: | Tag: | Revision:

amiro-os / core / src / aos_system.c @ 10fd7ac9

History | View | Annotate | Download (35.692 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
static 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 command to retrieve system information.
116
 */
117
static AOS_SHELL_COMMAND(_shellcmd_info, "module:info", _shellcmd_infocb);
118

    
119
/**
120
 * @brief   Shell command to set or retrieve system configuration.
121
 */
122
static AOS_SHELL_COMMAND(_shellcmd_config, "module:config", _shellcmd_configcb);
123

    
124
/**
125
 * @brief   Shell command to shutdown the system.
126
 */
127
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
128
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "system:shutdown", _shellcmd_shutdowncb);
129
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
130
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "module:shutdown", _shellcmd_shutdowncb);
131
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
132

    
133
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
134

    
135
/**
136
 * @brief   Shell kommand to run a test of the ChibiOS/RT kernel.
137
 */
138
static AOS_SHELL_COMMAND(_shellcmd_kerneltest, "kernel:test", _shellcmd_kerneltestcb);
139

    
140
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
141
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
142

    
143
/******************************************************************************/
144
/* LOCAL FUNCTIONS                                                            */
145
/******************************************************************************/
146

    
147
/**
148
 * @brief   Print a separator line.
149
 *
150
 * @param[in] stream    Stream to print to or NULL to print to all system streams.
151
 * @param[in] c         Character to use.
152
 * @param[in] n         Length of the separator line.
153
 *
154
 * @return  Number of characters printed.
155
 */
156
static unsigned int _printSystemInfoSeparator(BaseSequentialStream* stream, const char c, const unsigned int n)
157
{
158
  aosDbgCheck(stream != NULL);
159

    
160
  // print the specified character n times
161
  for (unsigned int i = 0; i < n; ++i) {
162
    streamPut(stream, (uint8_t)c);
163
  }
164
  streamPut(stream, '\n');
165

    
166
  return n+1;
167
}
168

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

    
188
  unsigned int n = 0;
189
  va_list ap;
190

    
191
  va_start(ap, fmt);
192
  n += (unsigned int)chprintf(stream, name);
193
  // print at least a single space character
194
  do {
195
    streamPut(stream, ' ');
196
    ++n;
197
  } while (n < namewidth);
198
  n += (unsigned int)chvprintf(stream, fmt, ap);
199
  va_end(ap);
200

    
201
  streamPut(stream, '\n');
202
  ++n;
203

    
204
  return n;
205
}
206

    
207
/**
208
 * @brief   Prints information about the system.
209
 *
210
 * @param[in] stream    Stream to print to.
211
 */
212
static void _printSystemInfo(BaseSequentialStream* stream)
213
{
214
  aosDbgCheck(stream != NULL);
215

    
216
  // local variables
217
#if (HAL_USE_RTC == TRUE)
218
  struct tm dt;
219
  aosSysGetDateTime(&dt);
220
#endif /* (HAL_USE_RTC == TRUE) */
221

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

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

    
272
#if defined(AMIROOS_CFG_SYSINFO_HOOK)
273
  // print module specific information
274
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
275
  AMIROOS_CFG_SYSINFO_HOOK();
276
#endif /* defined(AMIROOS_CFG_SYSINFO_HOOK) */
277

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

    
296
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
297

    
298
  return;
299
}
300

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

    
317
  // local variables
318
  int retval = AOS_INVALIDARGUMENTS;
319

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

    
429
      // read and print new date and time
430
      aosSysGetDateTime(&dt);
431
      chprintf(stream, "date/time set to %04u-%02u-%02u %02u:%02u:%02u\n",
432
               dt.tm_year+1900, dt.tm_mon+1, dt.tm_mday,
433
               dt.tm_hour, dt.tm_min, dt.tm_sec);
434

    
435
      retval = AOS_OK;
436
    }
437
#endif /* (HAL_USE_RTC == TRUE) */
438
  }
439

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

    
466
  return (argc > 1 && strcmp(argv[1], "--help") == 0) ? AOS_OK : retval;
467
}
468

    
469
/**
470
 * @brief   Callback function for the system:info shell command.
471
 *
472
 * @param[in] stream    The I/O stream to use.
473
 * @param[in] argc      Number of arguments.
474
 * @param[in] argv      List of pointers to the arguments.
475
 *
476
 * @return            An exit status.
477
 * @retval  AOS_OK    The command was executed successfully.
478
 */
479
static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[])
480
{
481
  aosDbgCheck(stream != NULL);
482

    
483
  (void)argc;
484
  (void)argv;
485

    
486
  // print system information
487
  _printSystemInfo(stream);
488

    
489
  // print time measurement precision
490
  chprintf(stream, "module time resolution: %uus\n", AOS_SYSTEM_TIME_RESOLUTION);
491

    
492
  // print system uptime
493
  aos_timestamp_t uptime;
494
  aosSysGetUptime(&uptime);
495
  chprintf(stream, "The system is running for\n");
496
  chprintf(stream, "%10u days\n", (uint32_t)(uptime / MICROSECONDS_PER_DAY));
497
  chprintf(stream, "%10u hours\n", (uint8_t)(uptime % MICROSECONDS_PER_DAY / MICROSECONDS_PER_HOUR));
498
  chprintf(stream, "%10u minutes\n", (uint8_t)(uptime % MICROSECONDS_PER_HOUR / MICROSECONDS_PER_MINUTE));
499
  chprintf(stream, "%10u seconds\n", (uint8_t)(uptime % MICROSECONDS_PER_MINUTE / MICROSECONDS_PER_SECOND));
500
  chprintf(stream, "%10u milliseconds\n", (uint16_t)(uptime % MICROSECONDS_PER_SECOND / MICROSECONDS_PER_MILLISECOND));
501
  chprintf(stream, "%10u microseconds\n", (uint16_t)(uptime % MICROSECONDS_PER_MILLISECOND / MICROSECONDS_PER_MICROSECOND));
502
#if (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)
503
  chprintf(stream, "SSSP synchronization offset: %.3fus per %uus\n", (double)aosSsspGetSyncSkew(), AMIROOS_CFG_SSSP_SYSSYNCPERIOD);
504
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) */
505
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
506

    
507
  // print shell info
508
  chprintf(stream, "System shell information:\n");
509
  chprintf(stream, "\tcommands available:     %u\n", aosShellCountCommands(&aos.shell));
510
  chprintf(stream, "\tline width:             %u characters\n", aos.shell.input.length);
511
  chprintf(stream, "\tmaximum arguments:      %u\n", aos.shell.input.nargs);
512
#if (AMIROOS_CFG_DBG == true)
513
  chprintf(stream, "\tthread stack size:      %u bytes\n", aosThdGetStacksize(aos.shell.thread));
514
#if (CH_DBG_FILL_THREADS == TRUE)
515
  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));
516
#endif /* (CH_DBG_FILL_THREADS == TRUE) */
517
#endif /* (AMIROOS_CFG_DBG == true) */
518
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
519

    
520
  return AOS_OK;
521
}
522

    
523
/**
524
 * @brief   Callback function for the sytem:shutdown or module:shutdown shell command.
525
 *
526
 * @param[in] stream    The I/O stream to use.
527
 * @param[in] argc      Number of arguments.
528
 * @param[in] argv      List of pointers to the arguments.
529
 *
530
 * @return              An exit status.
531
 * @retval  AOS_OK                  The command was executed successfully.
532
 * @retval  AOS_INVALIDARGUMENTS   There was an issue with the arguments.
533
 */
534
static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[])
535
{
536
  aosDbgCheck(stream != NULL);
537

    
538
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE)
539

    
540
  (void)argv;
541

    
542
  if (argc != 1) {
543
    // error
544
    chprintf(stream, "ERROR: no arguments allowed.\n");
545
    return AOS_INVALIDARGUMENTS;
546
  } else {
547
    // broadcast shutdown event
548
    chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_MASK);
549
    // set terminate flag so no further prompt will be printed
550
    chThdTerminate(chThdGetSelfX());
551
    return AOS_OK;
552
  }
553

    
554
#elif (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
555

    
556
  // print help text
557
  if (argc != 2 || strcmp(argv[1], "--help") == 0) {
558
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
559
    chprintf(stream, "Options:\n");
560
    chprintf(stream, "  --help\n");
561
    chprintf(stream, "    Print this help text.\n");
562
    chprintf(stream, "  --hibernate, -h\n");
563
    chprintf(stream, "    Shutdown to hibernate mode.\n");
564
    chprintf(stream, "    Least energy saving, but allows charging via pins.\n");
565
    chprintf(stream, "  --deepsleep, -d\n");
566
    chprintf(stream, "    Shutdown to deepsleep mode.\n");
567
    chprintf(stream, "    Minimum energy consumption while allowing charging via plug.\n");
568
    chprintf(stream, "  --transportation, -t\n");
569
    chprintf(stream, "    Shutdown to transportation mode.\n");
570
    chprintf(stream, "    Minimum energy consumption with all interrupts disabled (no charging).\n");
571
    chprintf(stream, "  --restart, -r\n");
572
    chprintf(stream, "    Shutdown and restart system.\n");
573

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

    
612
#endif /* (AMIROOS_CFG_BOOTLOADER == X) */
613
}
614

    
615
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
616

    
617
/**
618
 * @brief   Callback function for the kernel:test shell command.
619
 *
620
 * @param[in] stream    The I/O stream to use.
621
 * @param[in] argc      Number of arguments.
622
 * @param[in] argv      List of pointers to the arguments.
623
 *
624
 * @return      An exit status.
625
 */
626
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[])
627
{
628
  aosDbgCheck(stream != NULL);
629

    
630
  (void)argc;
631
  (void)argv;
632

    
633
  msg_t retval = test_execute(stream, &rt_test_suite);
634

    
635
  return retval;
636
}
637

    
638
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
639
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
640

    
641
// suppress warning in case no interrupt GPIOs are defined
642
#pragma GCC diagnostic push
643
#pragma GCC diagnostic ignored "-Wunused-function"
644
/**
645
 * @brief   Generic callback function for GPIO interrupts.
646
 *
647
 * @param[in] args   Pointer to the GPIO line identifier.
648
 */
649
static void _gpioCallback(void* args)
650
{
651
  aosDbgCheck((args != NULL) && (*((ioline_t*)args) != PAL_NOLINE) && (PAL_PAD(*((ioline_t*)args)) < sizeof(eventflags_t) * 8));
652

    
653
  chSysLockFromISR();
654
  chEvtBroadcastFlagsI(&aos.events.gpio, AOS_GPIOEVENT_FLAG(PAL_PAD(*((ioline_t*)args))));
655
  chSysUnlockFromISR();
656

    
657
  return;
658
}
659
#pragma GCC diagnostic pop
660

    
661
/**
662
 * @brief   Callback function for the uptime accumulation timer.
663
 *
664
 * @param[in] par   Generic parameter.
665
 */
666
static void _uptimeCallback(void* par)
667
{
668
  (void)par;
669

    
670
  chSysLockFromISR();
671
  // read current time in system ticks
672
  register const systime_t st = chVTGetSystemTimeX();
673
  // update the uptime variables
674
  _uptime += chTimeI2US(chTimeDiffX(_synctime, st));
675
  _synctime = st;
676
  // enable the timer again
677
  chVTSetI(&_systimer, SYSTIMER_PERIOD, &_uptimeCallback, NULL);
678
  chSysUnlockFromISR();
679

    
680
  return;
681
}
682

    
683
/**
684
 * @brief   Retreive the number of active threads.
685
 *
686
 * @return  Number of active threads.
687
 */
688
size_t _numActiveThreads(void)
689
{
690
  size_t threads = 0;
691
  thread_t* tp = chRegFirstThread();
692
  while (tp) {
693
    threads += (tp->state == CH_STATE_FINAL) ? 1 : 0;
694
    tp = chRegNextThread(tp);
695
  }
696

    
697
  return threads;
698
}
699

    
700
/******************************************************************************/
701
/* EXPORTED FUNCTIONS                                                         */
702
/******************************************************************************/
703

    
704
/**
705
 * @brief   AMiRo-OS system initialization.
706
 * @note    Must be called from the system control thread (usually main thread).
707
 *
708
 * @param[in] shellPrompt   String to be printed as prompt of the system shell.
709
 */
710
void aosSysInit(const char* shellPrompt)
711
{
712
  /* set control thread to maximum priority */
713
  chThdSetPriority(AOS_THD_CTRLPRIO);
714

    
715
#if (AMIROOS_CFG_SSSP_ENABLE == true)
716
  aosSsspInit(&_uptime);
717
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
718

    
719
  /* set local variables */
720
  chVTObjectInit(&_systimer);
721
#if (AMIROOS_CFG_SSSP_ENABLE == true)
722
  // uptime counter is started when SSSP proceeds to operation phase
723
  _synctime = 0;
724
  _uptime = 0;
725
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
726
  // start the uptime counter
727
  chSysLock();
728
  aosSysStartUptimeS();
729
  chSysUnlock();
730
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
731

    
732
  /* initialize aos configuration */
733
  aosIOStreamInit(&aos.iostream);
734
  chEvtObjectInit(&aos.events.gpio);
735
  chEvtObjectInit(&aos.events.os);
736

    
737
#if (AMIROOS_CFG_SHELL_ENABLE == true)
738

    
739
  /* init shell */
740
  aosShellInit(&aos.shell,
741
               &aos.events.os,
742
               shellPrompt,
743
               _shell_line,
744
               AMIROOS_CFG_SHELL_LINEWIDTH,
745
               AMIROOS_CFG_SHELL_MAXARGS);
746
  // add system commands
747
  aosShellAddCommand(&aos.shell, &_shellcmd_config);
748
  aosShellAddCommand(&aos.shell, &_shellcmd_info);
749
  aosShellAddCommand(&aos.shell, &_shellcmd_shutdown);
750
#if (AMIROOS_CFG_TESTS_ENABLE == true)
751
  aosShellAddCommand(&aos.shell, &_shellcmd_kerneltest);
752
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
753

    
754
#else /* (AMIROOS_CFG_SHELL_ENABLE == true) */
755

    
756
  // suppress unused variable warnings
757
  (void)shellPrompt;
758

    
759
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
760

    
761
  return;
762
}
763

    
764
/**
765
 * @brief   Starts the system and all system threads.
766
 */
767
void aosSysStart(void)
768
{
769
  // print system information;
770
  _printSystemInfo((BaseSequentialStream*)&aos.iostream);
771
  aosprintf("\n");
772

    
773
#if (AMIROOS_CFG_SHELL_ENABLE == true)
774
  // start system shell thread
775
#if (CH_CFG_USE_THREADHIERARCHY == TRUE)
776
  aos.shell.thread = chThdCreateStatic(_shell_wa, sizeof(_shell_wa), AMIROOS_CFG_SHELL_THREADPRIO, aosShellThread, &aos.shell, &ch.mainthread);
777
#else /* (CH_CFG_USE_THREADHIERARCHY == TRUE) */
778
  aos.shell.thread = chThdCreateStatic(_shell_wa, sizeof(_shell_wa), AMIROOS_CFG_SHELL_THREADPRIO, aosShellThread, &aos.shell);
779
#endif /* (CH_CFG_USE_THREADHIERARCHY == TRUE) */
780
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
781

    
782
  return;
783
}
784

    
785
/**
786
 * @brief   Start the system uptime measurement.
787
 * @note    Must be called from a locked context.
788
 */
789
void aosSysStartUptimeS(void)
790
{
791
  chDbgCheckClassS();
792

    
793
  // start the uptime aggregation counter
794
  _synctime = chVTGetSystemTimeX();
795
  _uptime = 0;
796
  chVTSetI(&_systimer, SYSTIMER_PERIOD, &_uptimeCallback, NULL);
797

    
798
  return;
799
}
800

    
801
/**
802
 * @brief   Retrieves the system uptime.
803
 *
804
 * @param[out] ut   The system uptime.
805
 */
806
void aosSysGetUptimeX(aos_timestamp_t* ut)
807
{
808
  aosDbgCheck(ut != NULL);
809

    
810
  *ut = _uptime + chTimeI2US(chTimeDiffX(_synctime, chVTGetSystemTimeX()));
811

    
812
  return;
813
}
814

    
815
#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
816

    
817
/**
818
 * @brief   retrieves the date and time from the MCU clock.
819
 *
820
 * @param[out] td   The date and time.
821
 */
822
void aosSysGetDateTime(struct tm* dt)
823
{
824
  aosDbgCheck(dt != NULL);
825

    
826
  RTCDateTime rtc;
827
  rtcGetTime(&MODULE_HAL_RTC, &rtc);
828
  rtcConvertDateTimeToStructTm(&rtc, dt, NULL);
829

    
830
  return;
831
}
832

    
833
/**
834
 * @brief   set the date and time of the MCU clock.
835
 *
836
 * @param[in] dt    The date and time to set.
837
 */
838
void aosSysSetDateTime(struct tm* dt)
839
{
840
  aosDbgCheck(dt != NULL);
841

    
842
  RTCDateTime rtc;
843
  rtcConvertStructTmToDateTime(dt, 0, &rtc);
844
  rtcSetTime(&MODULE_HAL_RTC, &rtc);
845

    
846
  return;
847
}
848

    
849
#endif /* (HAL_USE_RTC == TRUE) */
850

    
851
/**
852
 * @brief   Initializes/Acknowledges a system shutdown/restart request.
853
 * @note    This functions should be called from the thread with highest priority.
854
 *
855
 * @param[in] shutdown    Type of shutdown.
856
 */
857
void aosSysShutdownInit(aos_shutdown_t shutdown)
858
{
859
  // check arguments
860
  aosDbgCheck(shutdown != AOS_SHUTDOWN_NONE);
861

    
862
#if (AMIROOS_CFG_SSSP_ENABLE == true)
863

    
864
  // activate the PD signal only if this module initiated the shutdown
865
  if (shutdown != AOS_SHUTDOWN_PASSIVE) {
866
    aosSsspShutdownInit(true);
867
  }
868

    
869
  switch (shutdown) {
870
    case AOS_SHUTDOWN_PASSIVE:
871
      chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_PASSIVE);
872
      aosprintf("shutdown request received...\n");
873
      break;
874
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE)
875
    case AOS_SHUTDOWN_ACTIVE:
876
      aosprintf("shutdown initiated...\n");
877
      break;
878
#elif (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)
879
    case AOS_SHUTDOWN_HIBERNATE:
880
      aosprintf("shutdown to hibernate mode...\n");
881
      break;
882
    case AOS_SHUTDOWN_DEEPSLEEP:
883
      aosprintf("shutdown to deepsleep mode...\n");
884
      break;
885
    case AOS_SHUTDOWN_TRANSPORTATION:
886
      aosprintf("shutdown to transportation mode...\n");
887
      break;
888
    case AOS_SHUTDOWN_RESTART:
889
      aosprintf("restarting system...\n");
890
      break;
891
#endif /* (AMIROOS_CFG_BOOTLOADER == X) */
892
    case AOS_SHUTDOWN_NONE:
893
      // must never occur
894
      aosDbgAssert(false);
895
      break;
896
  }
897

    
898
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
899

    
900
  aosprintf("shutdown initiated...\n");
901

    
902
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
903

    
904
  return;
905
}
906

    
907
/**
908
 * @brief   Stops the system and all related threads (not the thread this function is called from).
909
 */
910
void aosSysStop(void)
911
{
912
  // wait until the calling thread is the only remaining active thread
913
#if (CH_CFG_NO_IDLE_THREAD == TRUE)
914
  while (_numActiveThreads() > 1) {
915
#else /* (CH_CFG_NO_IDLE_THREAD == TRUE) */
916
  while (_numActiveThreads() > 2) {
917
#endif /* (CH_CFG_NO_IDLE_THREAD == TRUE) */
918
    aosDbgPrintf("waiting for all threads to terminate...\n");
919
    chThdYield();
920
  }
921

    
922
  return;
923
}
924

    
925
/**
926
 * @brief   Deinitialize all system variables.
927
 */
928
void aosSysDeinit(void)
929
{
930
  return;
931
}
932

    
933
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) ||                 \
934
    ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) || \
935
    defined(__DOXYGEN__)
936

    
937
/**
938
 * @brief   Finally shuts down the system and calls the bootloader callback function.
939
 * @note    This function should be called from the thtead with highest priority.
940
 *
941
 * @param[in] shutdown    Type of shutdown.
942
 */
943
void aosSysShutdownToBootloader(aos_shutdown_t shutdown)
944
{
945
  // check arguments
946
  aosDbgCheck(shutdown != AOS_SHUTDOWN_NONE);
947

    
948
  // disable all interrupts
949
  irqDeinit();
950

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

    
988
  return;
989
}
990

    
991
#endif /* ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) || ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) */
992

    
993
/**
994
 * @brief   Generic callback function for GPIO interrupts.
995
 *
996
 * @return  Pointer to the callback function.
997
 */
998
palcallback_t aosSysGetStdGpioCallback(void)
999
{
1000
  return _gpioCallback;
1001
}
1002

    
1003
/** @} */