Revision 7de0cc90 core/src/aos_system.c

View differences:

core/src/aos_system.c
34 34
#if (AMIROOS_CFG_TESTS_ENABLE == true)
35 35
#include <ch_test.h>
36 36
#include <rt_test_root.h>
37
#endif
37
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
38 38

  
39 39
/******************************************************************************/
40 40
/* LOCAL DEFINITIONS                                                          */
......
90 90
static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[]);
91 91
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
92 92
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]);
93
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
93
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
94 94
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
95 95

  
96 96
/**
......
168 168
static aos_shellcommand_t _shellcmd_shutdown = {
169 169
#if (AMIROOS_CFG_SSSP_ENABLE == true)
170 170
  /* name     */ "system:shutdown",
171
#else
171
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
172 172
  /* name     */ "module:shutdown",
173
#endif
173
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
174 174
  /* callback */ _shellcmd_shutdowncb,
175 175
  /* next     */ NULL,
176 176
};
......
184 184
  /* callback */ _shellcmd_kerneltestcb,
185 185
  /* next     */ NULL,
186 186
};
187
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
187
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
188 188
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
189 189

  
190 190
/******************************************************************************/
......
263 263
#if (HAL_USE_RTC == TRUE)
264 264
  struct tm dt;
265 265
  aosSysGetDateTime(&dt);
266
#endif /* HAL_USE_RTC == TRUE */
266
#endif /* (HAL_USE_RTC == TRUE) */
267 267

  
268 268
  // print static information about module and operating system
269 269
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
270 270
  _printSystemInfoLine(stream, "Module", SYSTEM_INFO_NAMEWIDTH, "%s", BOARD_NAME);
271
#ifdef PLATFORM_NAME
271
#if defined(PLATFORM_NAME)
272 272
  _printSystemInfoLine(stream, "Platform", SYSTEM_INFO_NAMEWIDTH, "%s", PLATFORM_NAME);
273
#endif
274
#ifdef PORT_CORE_VARIANT_NAME
273
#endif /* defined(PLATFORM_NAME) */
274
#if defined(PORT_CORE_VARIANT_NAME)
275 275
  _printSystemInfoLine(stream, "Core Variant", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_CORE_VARIANT_NAME);
276
#endif
276
#endif /* defined(PORT_CORE_VARIANT_NAME) */
277 277
  _printSystemInfoLine(stream, "Architecture", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_ARCHITECTURE_NAME);
278 278
  _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH);
279 279
#if (AMIROOS_CFG_SSSP_ENABLE == true)
280 280
  _printSystemInfoLine(stream, "AMiRo-OS" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (SSSP %u.%u)", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE, AOS_SYSTEM_SSSP_VERSION_MAJOR, AOS_SYSTEM_SSSP_VERSION_MINOR);
281
#else
281
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
282 282
  _printSystemInfoLine(stream, "AMiRo-OS" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE);
283
#endif
283
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
284 284
  _printSystemInfoLine(stream, "AMiRo-LLD" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (periphAL %u.%u)", AMIRO_LLD_VERSION_MAJOR, AMIRO_LLD_VERSION_MINOR, AMIRO_LLD_VERSION_PATCH, AMIRO_LLD_RELEASE_TYPE, PERIPHAL_VERSION_MAJOR, PERIPHAL_VERSION_MINOR);
285 285
  _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");
286 286
  _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");
......
307 307
        aosprintf("WARNING: Bootloader and AMiRo-OS implement incompatible SSSP versions!\n");
308 308
      }
309 309
    }
310
#endif
310
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
311 311
    _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
312 312
  } else {
313 313
    if (stream) {
......
325 325
  } else {
326 326
    _printSystemInfoLine(stream, "Module ID", SYSTEM_INFO_NAMEWIDTH, "not available");
327 327
  }
328
#endif
328
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
329 329
#if (HAL_USE_RTC == TRUE)
330 330
  _printSystemInfoLine(stream, "Date", SYSTEM_INFO_NAMEWIDTH, "%s %02u-%02u-%04u", (dt.tm_wday == 0) ? "Sunday" : (dt.tm_wday == 1) ? "Monday" : (dt.tm_wday == 2) ? "Tuesday" : (dt.tm_wday == 3) ? "Wednesday" : (dt.tm_wday == 4) ? "Thursday" : (dt.tm_wday == 5) ? "Friday" : "Saturday",
331 331
                       dt.tm_mday,
332 332
                       dt.tm_mon + 1,
333 333
                       dt.tm_year + 1900);
334 334
  _printSystemInfoLine(stream, "Time", SYSTEM_INFO_NAMEWIDTH, "%02u:%02u:%02u", dt.tm_hour, dt.tm_min, dt.tm_sec);
335
#endif /* HAL_USE_RTC == TRUE */
335
#endif /* (HAL_USE_RTC == TRUE) */
336 336

  
337 337
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
338 338

  
......
475 475

  
476 476
      retval = AOS_OK;
477 477
    }
478
#endif /* HAL_USE_RTC == TRUE */
478
#endif /* (HAL_USE_RTC == TRUE) */
479 479
  }
480 480

  
481 481
  // print help, if required
......
501 501
    chprintf(stream, "      hour\n");
502 502
    chprintf(stream, "      minute\n");
503 503
    chprintf(stream, "      second\n");
504
#endif /* HAL_USE_RTC == TRUE */
504
#endif /* (HAL_USE_RTC == TRUE) */
505 505
  }
506 506

  
507 507
  return (argc > 1 && strcmp(argv[1], "--help") == 0) ? AOS_OK : retval;
......
542 542
  chprintf(stream, "%10u microseconds\n", (uint16_t)(uptime % MICROSECONDS_PER_MILLISECOND / MICROSECONDS_PER_MICROSECOND));
543 543
#if (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)
544 544
  chprintf(stream, "SSSP synchronization offset: %.3fus per %uus\n", _syssyncskew, AMIROOS_CFG_SSSP_SYSSYNCPERIOD);
545
#endif /* AMIROOS_CFG_SSSP_MASTER != true && AMIROOS_CFG_PROFILE == true */
545
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) */
546 546
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
547 547

  
548 548
  // print shell info
......
554 554
  chprintf(stream, "\tthread stack size:      %u bytes\n", aosThdGetStacksize(aos.shell.thread));
555 555
#if (CH_DBG_FILL_THREADS == TRUE)
556 556
  chprintf(stream, "\tstack peak utilization: %u bytes (%.2f%%)\n", aosThdGetStackPeakUtilization(aos.shell.thread), (float)aosThdGetStackPeakUtilization(aos.shell.thread) / (float)aosThdGetStacksize(aos.shell.thread) * 100.0f);
557
#endif /* CH_DBG_FILL_THREADS == TRUE */
558
#endif /* AMIROOS_CFG_DBG == true */
557
#endif /* (CH_DBG_FILL_THREADS == TRUE) */
558
#endif /* (AMIROOS_CFG_DBG == true) */
559 559
  _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH);
560 560

  
561 561
  return AOS_OK;
......
624 624
      return AOS_INVALID_ARGUMENTS;
625 625
    }
626 626
  }
627
#else /* AMIROOS_CFG_SSSP_ENABLE == false */
627
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
628 628
  (void)argv;
629 629
  (void)argc;
630 630

  
631 631
  chEvtBroadcastFlags(&aos.events.os, AOS_SYSTEM_EVENTFLAGS_SHUTDOWN);
632 632
  chThdTerminate(chThdGetSelfX());
633 633
  return AOS_OK;
634
#endif /* AMIROOS_CFG_SSSP_ENABLE */
634
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
635 635
}
636 636

  
637 637
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
......
655 655

  
656 656
  return retval;
657 657
}
658
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
658
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
659 659
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
660 660

  
661 661
// suppress warning in case no interrupt GPIOs are defined
......
705 705
        _uptime -= uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD;
706 706
#if (AMIROOS_CFG_PROFILE == true)
707 707
        _syssyncskew = ((1.0f - SYSTEM_SYSSYNCSKEW_LPFACTOR) * _syssyncskew) + (SYSTEM_SYSSYNCSKEW_LPFACTOR * (uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD));
708
#endif
708
#endif /* (AMIROOS_CFG_PROFILE == true) */
709 709
      } else {
710 710
        _uptime += AMIROOS_CFG_SSSP_SYSSYNCPERIOD - (uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD);
711 711
#if (AMIROOS_CFG_PROFILE == true)
712 712
        _syssyncskew = ((1.0f - SYSTEM_SYSSYNCSKEW_LPFACTOR) * _syssyncskew) - (SYSTEM_SYSSYNCSKEW_LPFACTOR * (AMIROOS_CFG_SSSP_SYSSYNCPERIOD - (uptime % AMIROOS_CFG_SSSP_SYSSYNCPERIOD)));
713
#endif
713
#endif /* (AMIROOS_CFG_PROFILE == true) */
714 714
      }
715 715
    }
716 716
  }
......
792 792
 */
793 793
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
794 794
void aosSysInit(const char* shellPrompt)
795
#else
795
#else /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
796 796
void aosSysInit(void)
797
#endif
797
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
798 798
{
799 799
  /* set control thread to maximum priority */
800 800
  chThdSetPriority(AOS_THD_CTRLPRIO);
......
807 807
#if (AMIROOS_CFG_SSSP_MASTER == true)
808 808
  chVTObjectInit(&_syssynctimer);
809 809
  _syssynctime = 0;
810
#endif
810
#endif /* (AMIROOS_CFG_SSSP_MASTER == true) */
811 811
#if (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)
812 812
  _syssyncskew = 0.0f;
813
#endif
814
#else /* AMIROOS_CFG_SSSP_ENABLE == false */
813
#endif /* (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) */
814
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
815 815
  // start the uptime counter
816 816
  chSysLock();
817 817
  _synctime = chVTGetSystemTimeX();
818 818
  _uptime = 0;
819 819
  chVTSetI(&_systimer, SYSTIMER_PERIOD, &_uptimeCallback, NULL);
820 820
  chSysUnlock();
821
#endif /* AMIROOS_CFG_SSSP_ENABLE */
821
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
822 822

  
823 823
  /* initialize aos configuration */
824 824
#if (AMIROOS_CFG_SSSP_ENABLE == true)
825 825
  aos.sssp.stage = AOS_SSSP_STARTUP_2_1;
826 826
  aos.sssp.moduleId = 0;
827
#endif
827
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
828 828
  aosIOStreamInit(&aos.iostream);
829 829
  chEvtObjectInit(&aos.events.io);
830 830
  chEvtObjectInit(&aos.events.os);
......
837 837
  // SYNC signal
838 838
#if (AMIROOS_CFG_SSSP_MASTER == true)
839 839
  palSetPadCallback(moduleSsspGpioSync.gpio->port, moduleSsspGpioSync.gpio->pad, _intCallback, &moduleSsspGpioSync.gpio->pad);
840
#else
840
#else /* (AMIROOS_CFG_SSSP_MASTER == true) */
841 841
  palSetPadCallback(moduleSsspGpioSync.gpio->port, moduleSsspGpioSync.gpio->pad, _signalSyncCallback, &moduleSsspGpioSync.gpio->pad);
842
#endif
842
#endif /* (AMIROOS_CFG_SSSP_MASTER == true) */
843 843
  palEnablePadEvent(moduleSsspGpioSync.gpio->port, moduleSsspGpioSync.gpio->pad, APAL2CH_EDGE(moduleSsspGpioSync.meta.edge));
844 844
#if (AMIROOS_CFG_SSSP_STACK_START != true)
845 845
  // DN signal
846 846
  palSetPadCallback(moduleSsspGpioDn.gpio->port, moduleSsspGpioDn.gpio->pad, _intCallback, &moduleSsspGpioDn.gpio->pad);
847 847
  palEnablePadEvent(moduleSsspGpioDn.gpio->port, moduleSsspGpioDn.gpio->pad, APAL2CH_EDGE(moduleSsspGpioDn.meta.edge));
848
#endif
848
#endif /* (AMIROOS_CFG_SSSP_STACK_START != true) */
849 849
#if (AMIROOS_CFG_SSSP_STACK_END != true)
850 850
  // UP signal
851 851
  palSetPadCallback(moduleSsspGpioUp.gpio->port, moduleSsspGpioUp.gpio->pad, _intCallback, &moduleSsspGpioUp.gpio->pad);
852 852
  palEnablePadEvent(moduleSsspGpioUp.gpio->port, moduleSsspGpioUp.gpio->pad, APAL2CH_EDGE(moduleSsspGpioUp.meta.edge));
853
#endif
854
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
855
#ifdef MODULE_INIT_INTERRUPTS
853
#endif /* (AMIROOS_CFG_SSSP_STACK_END != true) */
854
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
855
#if defined(MODULE_INIT_INTERRUPTS)
856 856
  // further interrupt signals
857 857
  MODULE_INIT_INTERRUPTS();
858
#endif
858
#endif /* defined(MODULE_INIT_INTERRUPTS) */
859 859

  
860 860
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true)
861 861
  /* init shell */
......
872 872
  aosShellAddCommand(&aos.shell, &_shellcmd_shutdown);
873 873
#if (AMIROOS_CFG_TESTS_ENABLE == true)
874 874
  aosShellAddCommand(&aos.shell, &_shellcmd_kerneltest);
875
#endif
875
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
876 876
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
877 877

  
878 878
  return;
......
898 898
    chVTSetI(&_syssynctimer, chTimeUS2I((t > (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) ? (t - (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2)) : (t + (AMIROOS_CFG_SSSP_SYSSYNCPERIOD / 2))), _sysSyncTimerCallback, NULL);
899 899
    chSysUnlock();
900 900
  }
901
#endif
902
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
901
#endif /* (AMIROOS_CFG_SSSP_MASTER == true) */
902
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
903 903

  
904 904
  // print system information;
905 905
  _printSystemInfo((BaseSequentialStream*)&aos.iostream);
......
909 909
  // start system shell thread
910 910
#if (CH_CFG_USE_THREADHIERARCHY == TRUE)
911 911
  aos.shell.thread = chThdCreateStatic(_shell_wa, sizeof(_shell_wa), AMIROOS_CFG_SHELL_THREADPRIO, aosShellThread, &aos.shell, &ch.mainthread);
912
#else
912
#else /* (CH_CFG_USE_THREADHIERARCHY == TRUE) */
913 913
  aos.shell.thread = chThdCreateStatic(_shell_wa, sizeof(_shell_wa), AMIROOS_CFG_SHELL_THREADPRIO, aosShellThread, &aos.shell);
914
#endif
915
#endif
914
#endif /* (CH_CFG_USE_THREADHIERARCHY == TRUE) */
915
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
916 916

  
917 917
  return;
918 918
}
......
968 968
    return m;
969 969
  }
970 970
}
971
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
971
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
972 972

  
973 973
/**
974 974
 * @brief   Retrieves the system uptime.
......
1018 1018
  return;
1019 1019
}
1020 1020

  
1021
#endif /* HAL_USE_RTC == TRUE */
1021
#endif /* (HAL_USE_RTC == TRUE) */
1022 1022

  
1023 1023
/**
1024 1024
 * @brief   Initializes/Acknowledges a system shutdown/restart request.
......
1035 1035
#if (AMIROOS_CFG_SSSP_MASTER == true)
1036 1036
  // deactivate the system synchronization timer
1037 1037
  chVTReset(&_syssynctimer);
1038
#endif
1038
#endif /* (AMIROOS_CFG_SSSP_MASTER == true) */
1039 1039

  
1040 1040
  // update the system SSSP stage
1041 1041
  aos.sssp.stage = AOS_SSSP_SHUTDOWN_1_1;
......
1048 1048
  // activate the SYS_SYNC signal
1049 1049
  apalControlGpioSet(&moduleSsspGpioSync, APAL_GPIO_ON);
1050 1050
  chSysUnlock();
1051
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
1051
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
1052 1052

  
1053 1053
  switch (shutdown) {
1054 1054
    case AOS_SHUTDOWN_PASSIVE:
......
1080 1080
#if (AMIROOS_CFG_SSSP_ENABLE == true)
1081 1081
  // update the system SSSP stage
1082 1082
  aos.sssp.stage = AOS_SSSP_SHUTDOWN_1_2;
1083
#endif
1083
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
1084 1084

  
1085 1085
  return;
1086 1086
}
......
1092 1092
{
1093 1093
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true)
1094 1094
  chThdWait(aos.shell.thread);
1095
#endif
1095
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */
1096 1096

  
1097 1097
  return;
1098 1098
}
......
1122 1122
#if (AMIROOS_CFG_SSSP_ENABLE == true)
1123 1123
  // update the system SSSP stage
1124 1124
  aos.sssp.stage = AOS_SSSP_SHUTDOWN_1_3;
1125
#endif
1125
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
1126 1126

  
1127 1127
  // validate bootloader
1128 1128
  if ((BL_CALLBACK_TABLE_ADDRESS->magicNumber == BL_MAGIC_NUMBER) &&

Also available in: Unified diff