Revision ba516b61 os/core/src/aos_system.c

View differences:

os/core/src/aos_system.c
37 37
 */
38 38
#define SYSTEM_INFO_WIDTH             70
39 39

  
40
/**
41
 * @brief   Width of the name column of the system info table.
42
 */
43
#define SYSTEM_INFO_NAMEWIDTH         14
44

  
40 45
/* forward declarations */
41 46
static void _printSystemInfo(BaseSequentialStream* stream);
42 47
#if (AMIROOS_CFG_SHELL_ENABLE == true)
......
59 64
static apalControlGpio_t* _gpioSync;
60 65

  
61 66
/**
62
 * @brief   Sequelntiel Stream Multiplexer for the system I/O stream.
63
 */
64
static SequentialStreamMux _ssm;
65

  
66
/**
67 67
 * @brief   Timer to accumulate system uptime.
68 68
 */
69 69
static virtual_timer_t _systimer;
......
154 154
 * @brief   Global system object.
155 155
 */
156 156
aos_system_t aos = {
157
  /* SSSP stage */ AOS_SSSP_STARTUP_2_1,
158
  /* event      */ {
159
    /* I/O      */ {
157
  /* SSSP stage       */ AOS_SSSP_STARTUP_2_1,
158
  /* I/O stream       */ {
159
    /* channel          */ NULL,
160
  },
161
  /* event            */ {
162
    /* I/O              */ {
160 163
      /* source           */ {
161
        /* next listener  */ NULL,
164
        /* next listener    */ NULL,
162 165
      },
163 166
      /* flagsSignalPd    */ 0,
164 167
      /* flagsSignalSync  */ 0,
165 168
    },
166
    /* OS */ {
167
      /* source */ {
168
        /* next listener  */ NULL,
169
    /* OS               */ {
170
      /* source           */ {
171
        /* next listener    */ NULL,
169 172
      }
170 173
    },
171 174
  },
172
  /* ssm        */ &_ssm,
173 175
#if (AMIROOS_CFG_SHELL_ENABLE == true)
174
  /* shell      */ &_shell,
176
  /* shell            */ &_shell,
175 177
#endif
176 178
};
177 179

  
178 180
/**
179 181
 * @brief   Print a separator line.
180 182
 *
181
 * @param[in] stream    Stream to print to.
183
 * @param[in] stream    Stream to print to or NULL to print to all system streams.
182 184
 * @param[in] c         Character to use.
183 185
 * @param[in] n         Length of the separator line.
184 186
 *
......
204 206
 *          The combined width of "<name>[spaces]" can be specified in order to align <fmt> on multiple lines.
205 207
 *          Note that there is not trailing newline added implicitely.
206 208
 *
207
 * @param[in] stream      Stream to print to.
209
 * @param[in] stream      Stream to print to or NULL to print to all system streams.
208 210
 * @param[in] name        Name of the entry/line.
209 211
 * @param[in] namewidth   Width of the name column.
210 212
 * @param[in] fmt         Formatted string of information content.
......
214 216
static unsigned int _printSystemInfoLine(BaseSequentialStream* stream, const char* name, const unsigned int namewidth, const char* fmt, ...)
215 217
{
216 218
  aosDbgCheck(stream != NULL);
217
  aosDbgCheck(stream != NULL);
219
  aosDbgCheck(name != NULL);
218 220

  
219 221
  unsigned int n = 0;
222
  va_list ap;
220 223

  
221
  // print the name and trailing spaces
224
  va_start(ap, fmt);
222 225
  n += chprintf(stream, name);
223 226
  while (n < namewidth) {
224 227
    streamPut(stream, ' ');
225 228
    ++n;
226 229
  }
227

  
228
  // print the content
229
  va_list ap;
230
  va_start(ap, fmt);
231 230
  n += chvprintf(stream, fmt, ap);
232 231
  va_end(ap);
233 232

  
......
239 238
 *
240 239
 * @param[in] stream    Stream to print to.
241 240
 */
242
static void _printSystemInfo(BaseSequentialStream *stream)
241
static void _printSystemInfo(BaseSequentialStream* stream)
243 242
{
244 243
  aosDbgCheck(stream != NULL);
245 244

  
246 245
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
247
  _printSystemInfoLine(stream, "Module", 14, "%s (v%s)\n", BOARD_NAME, BOARD_VERSION);
246
  _printSystemInfoLine(stream, "Module", SYSTEM_INFO_NAMEWIDTH, "%s (v%s)\n", BOARD_NAME, BOARD_VERSION);
248 247
#ifdef PLATFORM_NAME
249
  _printSystemInfoLine(stream, "Platform", 14, "%s\n", PLATFORM_NAME);
248
  _printSystemInfoLine(stream, "Platform", SYSTEM_INFO_NAMEWIDTH, "%s\n", PLATFORM_NAME);
250 249
#endif
251 250
#ifdef PORT_CORE_VARIANT_NAME
252
  _printSystemInfoLine(stream, "Core Variant", 14, "%s\n", PORT_CORE_VARIANT_NAME);
251
  _printSystemInfoLine(stream, "Core Variant", SYSTEM_INFO_NAMEWIDTH, "%s\n", PORT_CORE_VARIANT_NAME);
253 252
#endif
254
  _printSystemInfoLine(stream, "Architecture", 14, "%s\n", PORT_ARCHITECTURE_NAME);
253
  _printSystemInfoLine(stream, "Architecture", SYSTEM_INFO_NAMEWIDTH, "%s\n", PORT_ARCHITECTURE_NAME);
255 254
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
256
  _printSystemInfoLine(stream, "AMiRo-OS" ,14, "%u.%u.%u %s (%s build)\n", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE, (AMIROOS_CFG_DBG == true) ? "debug" : "release");
257
  _printSystemInfoLine(stream, "AMiRo-LLD" ,14, "%u.%u.%u %s (periphAL %u.%u)\n", AMIRO_LLD_VERSION_MAJOR, AMIRO_LLD_VERSION_MINOR, AMIRO_LLD_VERSION_PATCH, AMIRO_LLD_RELEASE_TYPE, PERIPHAL_VERSION_MAJOR, PERIPHAL_VERSION_MINOR);
258
  _printSystemInfoLine(stream, "ChibiOS/RT" ,14, "%u.%u.%u %s\n", CH_KERNEL_MAJOR, CH_KERNEL_MINOR, CH_KERNEL_PATCH, (CH_KERNEL_STABLE == 1) ? "stable" : "non-stable");
259
  _printSystemInfoLine(stream, "ChibiOS/HAL",14, "%u.%u.%u %s\n", CH_HAL_MAJOR, CH_HAL_MINOR, CH_HAL_PATCH, (CH_HAL_STABLE == 1) ? "stable" : "non-stable");
260
  _printSystemInfoLine(stream, "Compiler" ,14, "%s %u.%u.%u\n", "GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); // TODO: support other compilers than GCC
261
  _printSystemInfoLine(stream, "Compiled" ,14, "%s - %s\n", __DATE__, __TIME__);
255
  _printSystemInfoLine(stream, "AMiRo-OS" ,SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (SSSP %u.%u)\n", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE, AOS_SYSTEM_SSSP_MAJOR, AOS_SYSTEM_SSSP_MINOR);
256
  _printSystemInfoLine(stream, "AMiRo-LLD" ,SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (periphAL %u.%u)\n", AMIRO_LLD_VERSION_MAJOR, AMIRO_LLD_VERSION_MINOR, AMIRO_LLD_VERSION_PATCH, AMIRO_LLD_RELEASE_TYPE, PERIPHAL_VERSION_MAJOR, PERIPHAL_VERSION_MINOR);
257
  _printSystemInfoLine(stream, "ChibiOS/RT" ,SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s\n", CH_KERNEL_MAJOR, CH_KERNEL_MINOR, CH_KERNEL_PATCH, (CH_KERNEL_STABLE == 1) ? "stable" : "non-stable");
258
  _printSystemInfoLine(stream, "ChibiOS/HAL",SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s\n", CH_HAL_MAJOR, CH_HAL_MINOR, CH_HAL_PATCH, (CH_HAL_STABLE == 1) ? "stable" : "non-stable");
259
  _printSystemInfoLine(stream, "build type",SYSTEM_INFO_NAMEWIDTH,"%s\n", (AMIROOS_CFG_DBG == true) ? "debug" : "release");
260
  _printSystemInfoLine(stream, "Compiler" ,SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u\n", "GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); // TODO: support other compilers than GCC
261
  _printSystemInfoLine(stream, "Compiled" ,SYSTEM_INFO_NAMEWIDTH, "%s - %s\n", __DATE__, __TIME__);
262 262
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
263 263
  if (BL_CALLBACK_TABLE_ADDRESS->magicNumber == BL_MAGIC_NUMBER) {
264
    _printSystemInfoLine(stream, "AMiRo-BLT", 14, "%u.%u.%u %s (SSSP %u.%u)\n", BL_CALLBACK_TABLE_ADDRESS->vBootloader.major, BL_CALLBACK_TABLE_ADDRESS->vBootloader.minor, BL_CALLBACK_TABLE_ADDRESS->vBootloader.patch,
264
    _printSystemInfoLine(stream, "AMiRo-BLT", SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (SSSP %u.%u)\n", BL_CALLBACK_TABLE_ADDRESS->vBootloader.major, BL_CALLBACK_TABLE_ADDRESS->vBootloader.minor, BL_CALLBACK_TABLE_ADDRESS->vBootloader.patch,
265 265
                         (BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Release) ? "stable" :
266 266
                         (BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_ReleaseCandidate) ? "release candidate" :
267 267
                         (BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_Beta) ? "beta" :
......
269 269
                         (BL_CALLBACK_TABLE_ADDRESS->vBootloader.identifier == BL_VERSION_ID_AMiRoBLT_PreAlpha) ? "pre-alpha" :
270 270
                         "<release type unknown>",
271 271
                         BL_CALLBACK_TABLE_ADDRESS->vSSSP.major, BL_CALLBACK_TABLE_ADDRESS->vSSSP.minor);
272
    _printSystemInfoLine(stream, "Compiler", 14, "%s %u.%u.%u\n", (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
272
    if (BL_CALLBACK_TABLE_ADDRESS->vSSSP.major != AOS_SYSTEM_SSSP_MAJOR) {
273
      if (stream) {
274
        chprintf(stream, "WARNING: Bootloader and AMiRo-OS implement incompatible SSSP versions!\n");
275
      } else {
276
        aosprintf("WARNING: Bootloader and AMiRo-OS implement incompatible SSSP versions!\n");
277
      }
278
    }
279
    _printSystemInfoLine(stream, "Compiler", SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u\n", (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
273 280
  } else {
274
    chprintf(stream, "Bootloader incompatible or not available.\n");
281
    if (stream) {
282
      chprintf(stream, "Bootloader incompatible or not available.\n");
283
    } else {
284
      aosprintf("Bootloader incompatible or not available.\n");
285
    }
275 286
  }
276 287
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
277 288

  
......
292 303
 */
293 304
static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[])
294 305
{
306
  aosDbgCheck(stream != NULL);
307

  
295 308
  // local variables
296 309
  int retval = AOS_INVALID_ARGUMENTS;
297 310

  
......
386 399
 */
387 400
static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[])
388 401
{
402
  aosDbgCheck(stream != NULL);
403

  
389 404
  (void)argc;
390 405
  (void)argv;
391 406

  
......
422 437
 */
423 438
static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[])
424 439
{
440
  aosDbgCheck(stream != NULL);
441

  
425 442
  // print help text
426 443
  if (argc != 2 || strcmp(argv[1], "--help") == 0) {
427 444
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
......
446 463
  else {
447 464
    if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--hibernate") == 0) {
448 465
      chEvtBroadcastFlags(&aos.events.os.source, AOS_SYSTEM_EVENTFLAGS_HIBERNATE);
449
      chThdExit(MSG_OK);
466
      chThdTerminate(currp);
450 467
      return AOS_OK;
451 468
    }
452 469
    else if (strcmp(argv[1], "-d") == 0 || strcmp(argv[1], "--deepsleep") == 0) {
453 470
      chEvtBroadcastFlags(&aos.events.os.source, AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP);
454
      chThdExit(MSG_OK);
471
      chThdTerminate(currp);
455 472
      return AOS_OK;
456 473
    }
457 474
    else if (strcmp(argv[1], "-t") == 0 || strcmp(argv[1], "--transportation") == 0) {
458 475
      chEvtBroadcastFlags(&aos.events.os.source, AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION);
459
      chThdExit(MSG_OK);
476
      chThdTerminate(currp);
460 477
      return AOS_OK;
461 478
    }
462 479
    else if (strcmp(argv[1], "-r") == 0 || strcmp(argv[1], "--restart") == 0) {
463 480
      chEvtBroadcastFlags(&aos.events.os.source, AOS_SYSTEM_EVENTFLAGS_RESTART);
464
      chThdExit(MSG_OK);
481
      chThdTerminate(currp);
465 482
      return AOS_OK;
466 483
    }
467 484
    else {
......
484 501
 */
485 502
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[])
486 503
{
504
  aosDbgCheck(stream != NULL);
505

  
487 506
  (void)argc;
488 507
  (void)argv;
489 508

  
......
626 645
 * @param[in] evtFlagsPd    Event flags to be set when a PD interrupt occurs.
627 646
 * @param[in] evtFlagsSync  Event flags to be set when a Sync interrupt occurs.
628 647
 * @param[in] shellPrompt   String to be printed as prompt of the system shell.
648
 * @param[in] stdio         Default (usually physically) interface for I/O like shell.
629 649
 */
630 650
void aosSysInit(EXTDriver* extDrv,
631 651
                EXTConfig* extCfg,
......
657 677

  
658 678
  // set aos configuration
659 679
  aos.ssspStage = AOS_SSSP_STARTUP_2_1;
680
  aosIOStreamInit(&aos.iostream);
660 681
  chEvtObjectInit(&aos.events.io.source);
661 682
  chEvtObjectInit(&aos.events.os.source);
662 683
  aos.events.io.flagsSignalPd = evtFlagsPd;
663 684
  aos.events.io.flagsSignalSync = evtFlagsSync;
664
  ssmObjectInit(aos.ssm);
665 685

  
666 686
  // setup external interrupt system
667 687
  extCfg->channels[gpioPd->gpio->pad].cb = _signalPdCallback;
......
671 691
#if (AMIROOS_CFG_SHELL_ENABLE == true)
672 692
  // init shell
673 693
  aosShellInit(aos.shell,
674
               (BaseSequentialStream*)aos.ssm,
694
               &aos.events.os.source,
675 695
               shellPrompt,
676 696
               _shell_line,
677 697
               AMIROOS_CFG_SHELL_LINEWIDTH,
......
699 719
  // update the system SSSP stage
700 720
  aos.ssspStage = AOS_SSSP_OPERATION;
701 721

  
702
  // prin system information
703
  _printSystemInfo(AOS_SYSTEM_STDIO);
722
  // print system information;
723
  _printSystemInfo((BaseSequentialStream*)&aos.iostream);
704 724
  aosprintf("\n");
705 725

  
706 726
#if (AMIROOS_CFG_SHELL_ENABLE == true)
......
810 830

  
811 831
  switch (shutdown) {
812 832
    case AOS_SHUTDOWN_PASSIVE:
833
      chEvtBroadcastFlags(&aos.events.os.source, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN);
813 834
      aosprintf("shutdown request received...\n");
814 835
      break;
815 836
    case AOS_SHUTDOWN_HIBERNATE:
837
      chEvtBroadcastFlags(&aos.events.os.source, AOS_SYSTEM_EVENTFLAGS_HIBERNATE);
816 838
      aosprintf("shutdown to hibernate mode...\n");
817 839
      break;
818 840
    case AOS_SHUTDOWN_DEEPSLEEP:
841
      chEvtBroadcastFlags(&aos.events.os.source, AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP);
819 842
      aosprintf("shutdown to deepsleep mode...\n");
820 843
      break;
821 844
    case AOS_SHUTDOWN_TRANSPORTATION:
845
      chEvtBroadcastFlags(&aos.events.os.source, AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION);
822 846
      aosprintf("shutdown to transportation mode...\n");
823 847
      break;
824 848
    case AOS_SHUTDOWN_RESTART:
849
      chEvtBroadcastFlags(&aos.events.os.source, AOS_SYSTEM_EVENTFLAGS_RESTART);
825 850
      aosprintf("restarting system...\n");
826 851
      break;
827 852
   // must never occur
......
842 867
void aosSysStop(void)
843 868
{
844 869
#if (AMIROOS_CFG_SHELL_ENABLE == true)
845
  chThdTerminate(aos.shell->thread);
870
  chThdWait(aos.shell->thread);
846 871
#endif
847 872

  
848 873
  return;
......
853 878
 */
854 879
void aosSysDeinit(void)
855 880
{
856
  aos.ssm->input = NULL;
857

  
858 881
  return;
859 882
}
860 883

  

Also available in: Unified diff