Revision 8399aeae os/core/src/aos_system.c

View differences:

os/core/src/aos_system.c
20 20

  
21 21
#include <amiroos.h>
22 22
#include <amiroblt.h>
23
#include <module.h>
23 24
#include <string.h>
25
#include <stdlib.h>
24 26
#if (AMIROOS_CFG_TESTS_ENABLE == true)
25 27
#include <ch_test.h>
26 28
#endif
......
250 252
#endif
251 253
  _printSystemInfoLine(stream, "Architecture", SYSTEM_INFO_NAMEWIDTH, "%s\n", PORT_ARCHITECTURE_NAME);
252 254
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
253
  _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);
254
  _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);
255
  _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");
256
  _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");
257
  _printSystemInfoLine(stream, "build type",SYSTEM_INFO_NAMEWIDTH,"%s\n", (AMIROOS_CFG_DBG == true) ? "debug" : "release");
258
  _printSystemInfoLine(stream, "Compiler" ,SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u\n", "GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); // TODO: support other compilers than GCC
259
  _printSystemInfoLine(stream, "Compiled" ,SYSTEM_INFO_NAMEWIDTH, "%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__);
260 262
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
261 263
  if (BL_CALLBACK_TABLE_ADDRESS->magicNumber == BL_MAGIC_NUMBER) {
262 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,
......
282 284
      aosprintf("Bootloader incompatible or not available.\n");
283 285
    }
284 286
  }
287
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
288
  struct tm dt;
289
  aosSysGetDateTime(&dt);
290
  _printSystemInfoLine(stream, "Date", SYSTEM_INFO_NAMEWIDTH, "%s %02u-%02u-%04u\n", (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",
291
                       dt.tm_mday,
292
                       dt.tm_mon + 1,
293
                       dt.tm_year + 1900);
294
  _printSystemInfoLine(stream, "Time", SYSTEM_INFO_NAMEWIDTH, "%02u:%02u:%02u\n", dt.tm_hour, dt.tm_min, dt.tm_sec);
285 295
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
286 296

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

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

  
433
      retval = AOS_OK;
434
    }
368 435
  }
369 436

  
370 437
  // print help, if required
......
376 443
    chprintf(stream, "  --shell [OPT [VAL]]\n");
377 444
    chprintf(stream, "    Set or retrieve shell configuration.\n");
378 445
    chprintf(stream, "    Possible OPTs and VALs are:\n");
379
    chprintf(stream, "      prompt text|minimal|uptime|notime\n");
446
    chprintf(stream, "      prompt text|minimal|uptime|date&time|notime\n");
380 447
    chprintf(stream, "        Configures the prompt.\n");
381 448
    chprintf(stream, "      match casesensitive|caseinsenitive\n");
382 449
    chprintf(stream, "        Configures string matching.\n");
450
    chprintf(stream, "  --date&time OPT VAL\n");
451
    chprintf(stream, "    Set the date/time value of OPT to VAL.\n");
452
    chprintf(stream, "    Possible OPTs are:\n");
453
    chprintf(stream, "      year\n");
454
    chprintf(stream, "      month\n");
455
    chprintf(stream, "      day\n");
456
    chprintf(stream, "      hour\n");
457
    chprintf(stream, "      minute\n");
458
    chprintf(stream, "      second\n");
383 459
  }
384 460

  
385 461
  return (argc > 1 && strcmp(argv[1], "--help") == 0) ? AOS_OK : retval;
......
577 653
 *
578 654
 * @param[in] par   Generic parameter.
579 655
 */
580
#include <module.h>
581 656
static void _uptimeCallback(void* par)
582 657
{
583 658
  (void)par;
......
799 874
}
800 875

  
801 876
/**
877
 * @brief   retrieves the date and time from the MCU clock.
878
 *
879
 * @param[out] td   The date and time.
880
 */
881
void aosSysGetDateTime(struct tm* dt)
882
{
883
  aosDbgCheck(dt != NULL);
884

  
885
  RTCDateTime rtc;
886
  rtcGetTime(&MODULE_HAL_RTC, &rtc);
887
  rtcConvertDateTimeToStructTm(&rtc, dt, NULL);
888

  
889
  return;
890
}
891

  
892
/**
893
 * @brief   set the date and time of the MCU clock.
894
 *
895
 * @param[in] dt    The date and time to set.
896
 */
897
void aosSysSetDateTime(struct tm* dt)
898
{
899
  aosDbgCheck(dt != NULL);
900

  
901
  RTCDateTime rtc;
902
  rtcConvertStructTmToDateTime(dt, 0, &rtc);
903
  rtcSetTime(&MODULE_HAL_RTC, &rtc);
904

  
905
  return;
906
}
907

  
908
/**
802 909
 * @brief   Initializes/Acknowledges a system shutdown/restart request.
803 910
 * @note    This functions should be called from the thread with highest priority.
804 911
 *

Also available in: Unified diff