amiro-os / core / src / aos_system.c.autosave @ 27d0378b
History | View | Annotate | Download (36.68 KB)
| 1 | 27d0378b | Simon Welzel | /* |
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
||
| 3 | Copyright (C) 2016..2018 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 <aos_system.h> |
||
| 30 | |||
| 31 | #include <amiroos.h> |
||
| 32 | #include <amiroblt.h> |
||
| 33 | #include <module.h> |
||
| 34 | #include <string.h> |
||
| 35 | #include <stdlib.h> |
||
| 36 | #if (AMIROOS_CFG_TESTS_ENABLE == true) |
||
| 37 | #include <ch_test.h> |
||
| 38 | #include <rt_test_root.h> |
||
| 39 | #endif |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @brief Period of the system timer. |
||
| 43 | */ |
||
| 44 | #define SYSTIMER_PERIOD (TIME_MAX_SYSTIME - CH_CFG_ST_TIMEDELTA) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @brief Width of the printable system info text. |
||
| 48 | */ |
||
| 49 | #define SYSTEM_INFO_WIDTH 70 |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @brief Width of the name column of the system info table. |
||
| 53 | */ |
||
| 54 | #define SYSTEM_INFO_NAMEWIDTH 14 |
||
| 55 | |||
| 56 | /* forward declarations */ |
||
| 57 | static void _printSystemInfo(BaseSequentialStream* stream); |
||
| 58 | #if (AMIROOS_CFG_SHELL_ENABLE == true) |
||
| 59 | static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[]); |
||
| 60 | static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[]); |
||
| 61 | static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[]); |
||
| 62 | #if (AMIROOS_CFG_TESTS_ENABLE == true) |
||
| 63 | static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]); |
||
| 64 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
| 65 | #endif /* AMIROOS_CFG_SHELL_ENABLE == true */ |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @brief Timer to accumulate system uptime. |
||
| 69 | */ |
||
| 70 | static virtual_timer_t _systimer; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @brief Accumulated system uptime. |
||
| 74 | */ |
||
| 75 | static aos_timestamp_t _uptime; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @brief Timer register value of last accumulation. |
||
| 79 | */ |
||
| 80 | static systime_t _synctime; |
||
| 81 | |||
| 82 | #if (AMIROOS_CFG_SSSP_MASTER == true) || defined(__DOXYGEN__) |
||
| 83 | /** |
||
| 84 | * @brief Timer to drive the SYS_SYNC signal for system wide time synchronization according to SSSP. |
||
| 85 | */ |
||
| 86 | static virtual_timer_t _syssynctimer; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @brief Last uptime of system wide time synchronization. |
||
| 90 | */ |
||
| 91 | static aos_timestamp_t _syssynctime; |
||
| 92 | #endif |
||
| 93 | |||
| 94 | #if ((AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)) || defined(__DOXYGEN__) |
||
| 95 | /** |
||
| 96 | * @brief Offset between local clock and system wide synchronization signal. |
||
| 97 | */ |
||
| 98 | static float _syssyncskew; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @brief Weighting factor for the low-pass filter used for calculating the @p _syssyncskew value. |
||
| 102 | */ |
||
| 103 | #define SYSTEM_SYSSYNCSKEW_LPFACTOR (0.1f / AOS_SYSTEM_TIME_RESOLUTION) |
||
| 104 | #endif |
||
| 105 | |||
| 106 | #if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
||
| 107 | /** |
||
| 108 | * @brief Shell thread working area. |
||
| 109 | */ |
||
| 110 | THD_WORKING_AREA(_shell_wa, AMIROOS_CFG_SHELL_STACKSIZE); |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @brief Shell input buffer. |
||
| 114 | */ |
||
| 115 | static char _shell_line[AMIROOS_CFG_SHELL_LINEWIDTH]; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @brief Shell argument buffer. |
||
| 119 | */ |
||
| 120 | static char* _shell_arglist[AMIROOS_CFG_SHELL_MAXARGS]; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @brief Shell command to retrieve system information. |
||
| 124 | */ |
||
| 125 | static aos_shellcommand_t _shellcmd_info = {
|
||
| 126 | /* name */ "module:info", |
||
| 127 | /* callback */ _shellcmd_infocb, |
||
| 128 | /* next */ NULL, |
||
| 129 | }; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @brief Shell command to set or retrieve system configuration. |
||
| 133 | */ |
||
| 134 | static aos_shellcommand_t _shellcmd_config = {
|
||
| 135 | /* name */ "module:config", |
||
| 136 | /* callback */ _shellcmd_configcb, |
||
| 137 | /* next */ NULL, |
||
| 138 | }; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @brief Shell command to shutdown the system. |
||
| 142 | */ |
||
| 143 | static aos_shellcommand_t _shellcmd_shutdown = {
|
||
| 144 | /* name */ "system:shutdown", |
||
| 145 | /* callback */ _shellcmd_shutdowncb, |
||
| 146 | /* next */ NULL, |
||
| 147 | }; |
||
| 148 | #endif /* AMIROOS_CFG_SHELL_ENABLE == true */ |
||
| 149 | |||
| 150 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
| 151 | /** |
||
| 152 | * @brief Shell kommand to run a test of the ChibiOS/RT kernel. |
||
| 153 | */ |
||
| 154 | static aos_shellcommand_t _shellcmd_kerneltest = {
|
||
| 155 | /* name */ "kernel:test", |
||
| 156 | /* callback */ _shellcmd_kerneltestcb, |
||
| 157 | /* next */ NULL, |
||
| 158 | }; |
||
| 159 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @brief Global system object. |
||
| 163 | */ |
||
| 164 | aos_system_t aos; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @brief Print a separator line. |
||
| 168 | * |
||
| 169 | * @param[in] stream Stream to print to or NULL to print to all system streams. |
||
| 170 | * @param[in] c Character to use. |
||
| 171 | * @param[in] n Length of the separator line. |
||
| 172 | * |
||
| 173 | * @return Number of characters printed. |
||
| 174 | */ |
||
| 175 | static unsigned int _printSystemInfoSeparator(BaseSequentialStream* stream, const char c, const unsigned int n) |
||
| 176 | {
|
||
| 177 | aosDbgCheck(stream != NULL); |
||
| 178 | |||
| 179 | // print the specified character n times |
||
| 180 | for (unsigned int i = 0; i < n; ++i) {
|
||
| 181 | streamPut(stream, c); |
||
| 182 | } |
||
| 183 | streamPut(stream, '\n'); |
||
| 184 | |||
| 185 | return n+1; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @brief Print a system information line. |
||
| 190 | * @details Prints a system information line with the following format: |
||
| 191 | * "<name>[spaces]fmt" |
||
| 192 | * The combined width of "<name>[spaces]" can be specified in order to align <fmt> on multiple lines. |
||
| 193 | * Note that there is not trailing newline added implicitely. |
||
| 194 | * |
||
| 195 | * @param[in] stream Stream to print to or NULL to print to all system streams. |
||
| 196 | * @param[in] name Name of the entry/line. |
||
| 197 | * @param[in] namewidth Width of the name column. |
||
| 198 | * @param[in] fmt Formatted string of information content. |
||
| 199 | * |
||
| 200 | * @return Number of characters printed. |
||
| 201 | */ |
||
| 202 | static unsigned int _printSystemInfoLine(BaseSequentialStream* stream, const char* name, const unsigned int namewidth, const char* fmt, ...) |
||
| 203 | {
|
||
| 204 | aosDbgCheck(stream != NULL); |
||
| 205 | aosDbgCheck(name != NULL); |
||
| 206 | |||
| 207 | unsigned int n = 0; |
||
| 208 | va_list ap; |
||
| 209 | |||
| 210 | va_start(ap, fmt); |
||
| 211 | n += chprintf(stream, name); |
||
| 212 | while (n < namewidth) {
|
||
| 213 | streamPut(stream, ' '); |
||
| 214 | ++n; |
||
| 215 | } |
||
| 216 | n += chvprintf(stream, fmt, ap); |
||
| 217 | va_end(ap); |
||
| 218 | |||
| 219 | streamPut(stream, '\n'); |
||
| 220 | ++n; |
||
| 221 | |||
| 222 | return n; |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @brief Prints information about the system. |
||
| 227 | * |
||
| 228 | * @param[in] stream Stream to print to. |
||
| 229 | */ |
||
| 230 | static void _printSystemInfo(BaseSequentialStream* stream) |
||
| 231 | {
|
||
| 232 | aosDbgCheck(stream != NULL); |
||
| 233 | |||
| 234 | // local variables |
||
| 235 | struct tm dt; |
||
| 236 | aosSysGetDateTime(&dt); |
||
| 237 | |||
| 238 | // print static information about module and operating system |
||
| 239 | _printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH); |
||
| 240 | _printSystemInfoLine(stream, "Module", SYSTEM_INFO_NAMEWIDTH, "%s (v%s)", BOARD_NAME, BOARD_VERSION); |
||
| 241 | #ifdef PLATFORM_NAME |
||
| 242 | _printSystemInfoLine(stream, "Platform", SYSTEM_INFO_NAMEWIDTH, "%s", PLATFORM_NAME); |
||
| 243 | #endif |
||
| 244 | #ifdef PORT_CORE_VARIANT_NAME |
||
| 245 | _printSystemInfoLine(stream, "Core Variant", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_CORE_VARIANT_NAME); |
||
| 246 | #endif |
||
| 247 | _printSystemInfoLine(stream, "Architecture", SYSTEM_INFO_NAMEWIDTH, "%s", PORT_ARCHITECTURE_NAME); |
||
| 248 | _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH); |
||
| 249 | _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); |
||
| 250 | _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); |
||
| 251 | _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"); |
||
| 252 | _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"); |
||
| 253 | _printSystemInfoLine(stream, "build type", SYSTEM_INFO_NAMEWIDTH,"%s", (AMIROOS_CFG_DBG == true) ? "debug" : "release"); |
||
| 254 | _printSystemInfoLine(stream, "Compiler" , SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u", "GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); // TODO: support other compilers than GCC |
||
| 255 | _printSystemInfoLine(stream, "Compiled" , SYSTEM_INFO_NAMEWIDTH, "%s - %s", __DATE__, __TIME__); |
||
| 256 | |||
| 257 | // print static information about the bootloader |
||
| 258 | _printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH); |
||
| 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 (BL_CALLBACK_TABLE_ADDRESS->vSSSP.major != AOS_SYSTEM_SSSP_VERSION_MAJOR) {
|
||
| 269 | if (stream) {
|
||
| 270 | chprintf(stream, "WARNING: Bootloader and AMiRo-OS implement incompatible SSSP versions!\n"); |