amiro-os / core / src / aos_system.c @ 960338cc
History | View | Annotate | Download (37.403 KB)
| 1 | e545e620 | Thomas Schöpping | /*
|
|---|---|---|---|
| 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 | 53710ca3 | Marc Rothmann | /**
|
| 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 | e545e620 | Thomas Schöpping | #include <aos_system.h> |
| 30 | |||
| 31 | #include <amiroos.h> |
||
| 32 | #include <amiroblt.h> |
||
| 33 | 8399aeae | Thomas Schöpping | #include <module.h> |
| 34 | e545e620 | Thomas Schöpping | #include <string.h> |
| 35 | 8399aeae | Thomas Schöpping | #include <stdlib.h> |
| 36 | e545e620 | Thomas Schöpping | #if (AMIROOS_CFG_TESTS_ENABLE == true) |
| 37 | #include <ch_test.h> |
||
| 38 | 0128be0f | Marc Rothmann | #include <rt_test_root.h> |
| 39 | e545e620 | Thomas Schöpping | #endif
|
| 40 | |||
| 41 | /**
|
||
| 42 | * @brief Period of the system timer.
|
||
| 43 | */
|
||
| 44 | 1e5f7648 | Thomas Schöpping | #define SYSTIMER_PERIOD (TIME_MAX_SYSTIME - CH_CFG_ST_TIMEDELTA)
|
| 45 | e545e620 | Thomas Schöpping | |
| 46 | /**
|
||
| 47 | * @brief Width of the printable system info text.
|
||
| 48 | */
|
||
| 49 | #define SYSTEM_INFO_WIDTH 70 |
||
| 50 | |||
| 51 | ba516b61 | Thomas Schöpping | /**
|
| 52 | * @brief Width of the name column of the system info table.
|
||
| 53 | */
|
||
| 54 | #define SYSTEM_INFO_NAMEWIDTH 14 |
||
| 55 | |||
| 56 | e545e620 | Thomas Schöpping | /* 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 | aed3754b | Thomas Schöpping | #endif /* AMIROOS_CFG_SHELL_ENABLE == true */ |
| 66 | e545e620 | Thomas Schöpping | |
| 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 | 1ef74af5 | Simon Welzel | #if (AMIROOS_CFG_SSSP_ENABLE == true) |
| 83 | e545e620 | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_MASTER == true) || defined(__DOXYGEN__) |
| 84 | /**
|
||
| 85 | * @brief Timer to drive the SYS_SYNC signal for system wide time synchronization according to SSSP.
|
||
| 86 | */
|
||
| 87 | static virtual_timer_t _syssynctimer;
|
||
| 88 | |||
| 89 | 1ef74af5 | Simon Welzel | #endif
|
| 90 | |||
| 91 | e545e620 | Thomas Schöpping | /**
|
| 92 | * @brief Last uptime of system wide time synchronization.
|
||
| 93 | */
|
||
| 94 | static aos_timestamp_t _syssynctime;
|
||
| 95 | #endif
|
||
| 96 | |||
| 97 | 1ef74af5 | Simon Welzel | #if (AMIROOS_CFG_SSSP_ENABLE == true) |
| 98 | 3e1a9c79 | Thomas Schöpping | #if ((AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)) || defined(__DOXYGEN__) |
| 99 | 2674917e | Thomas Schöpping | /**
|
| 100 | * @brief Offset between local clock and system wide synchronization signal.
|
||
| 101 | */
|
||
| 102 | 3e1a9c79 | Thomas Schöpping | static float _syssyncskew; |
| 103 | 2674917e | Thomas Schöpping | |
| 104 | /**
|
||
| 105 | * @brief Weighting factor for the low-pass filter used for calculating the @p _syssyncskew value.
|
||
| 106 | */
|
||
| 107 | 3e1a9c79 | Thomas Schöpping | #define SYSTEM_SYSSYNCSKEW_LPFACTOR (0.1f / AOS_SYSTEM_TIME_RESOLUTION) |
| 108 | #endif
|
||
| 109 | 1ef74af5 | Simon Welzel | #endif
|
| 110 | 3e1a9c79 | Thomas Schöpping | |
| 111 | e545e620 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
| 112 | /**
|
||
| 113 | * @brief Shell thread working area.
|
||
| 114 | */
|
||
| 115 | THD_WORKING_AREA(_shell_wa, AMIROOS_CFG_SHELL_STACKSIZE); |
||
| 116 | |||
| 117 | /**
|
||
| 118 | * @brief Shell input buffer.
|
||
| 119 | */
|
||
| 120 | static char _shell_line[AMIROOS_CFG_SHELL_LINEWIDTH]; |
||
| 121 | |||
| 122 | /**
|
||
| 123 | * @brief Shell argument buffer.
|
||
| 124 | */
|
||
| 125 | static char* _shell_arglist[AMIROOS_CFG_SHELL_MAXARGS]; |
||
| 126 | |||
| 127 | /**
|
||
| 128 | * @brief Shell command to retrieve system information.
|
||
| 129 | */
|
||
| 130 | static aos_shellcommand_t _shellcmd_info = {
|
||
| 131 | /* name */ "module:info", |
||
| 132 | /* callback */ _shellcmd_infocb,
|
||
| 133 | /* next */ NULL, |
||
| 134 | }; |
||
| 135 | |||
| 136 | /**
|
||
| 137 | * @brief Shell command to set or retrieve system configuration.
|
||
| 138 | */
|
||
| 139 | static aos_shellcommand_t _shellcmd_config = {
|
||
| 140 | /* name */ "module:config", |
||
| 141 | /* callback */ _shellcmd_configcb,
|
||
| 142 | /* next */ NULL, |
||
| 143 | }; |
||
| 144 | |||
| 145 | /**
|
||
| 146 | * @brief Shell command to shutdown the system.
|
||
| 147 | */
|
||
| 148 | static aos_shellcommand_t _shellcmd_shutdown = {
|
||
| 149 | /* name */ "system:shutdown", |
||
| 150 | /* callback */ _shellcmd_shutdowncb,
|
||
| 151 | /* next */ NULL, |
||
| 152 | }; |
||
| 153 | #endif /* AMIROOS_CFG_SHELL_ENABLE == true */ |
||
| 154 | |||
| 155 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
| 156 | /**
|
||
| 157 | * @brief Shell kommand to run a test of the ChibiOS/RT kernel.
|
||
| 158 | */
|
||
| 159 | static aos_shellcommand_t _shellcmd_kerneltest = {
|
||
| 160 | /* name */ "kernel:test", |
||
| 161 | /* callback */ _shellcmd_kerneltestcb,
|
||
| 162 | /* next */ NULL, |
||
| 163 | }; |
||
| 164 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
| 165 | |||
| 166 | /**
|
||
| 167 | * @brief Global system object.
|
||
| 168 | */
|
||
| 169 | 6b53f6bf | Thomas Schöpping | aos_system_t aos; |
| 170 | e545e620 | Thomas Schöpping | |
| 171 | /**
|
||
| 172 | * @brief Print a separator line.
|
||
| 173 | *
|
||
| 174 | ba516b61 | Thomas Schöpping | * @param[in] stream Stream to print to or NULL to print to all system streams.
|
| 175 | e545e620 | Thomas Schöpping | * @param[in] c Character to use.
|
| 176 | * @param[in] n Length of the separator line.
|
||
| 177 | *
|
||
| 178 | * @return Number of characters printed.
|
||
| 179 | */
|
||
| 180 | static unsigned int _printSystemInfoSeparator(BaseSequentialStream* stream, const char c, const unsigned int n) |
||
| 181 | {
|
||
| 182 | aosDbgCheck(stream != NULL);
|
||
| 183 | |||
| 184 | // print the specified character n times
|
||
| 185 | for (unsigned int i = 0; i < n; ++i) { |
||
| 186 | streamPut(stream, c); |
||
| 187 | } |
||
| 188 | streamPut(stream, '\n');
|
||
| 189 | |||
| 190 | return n+1; |
||
| 191 | } |
||
| 192 | |||
| 193 | /**
|
||
| 194 | * @brief Print a system information line.
|
||
| 195 | * @details Prints a system information line with the following format:
|
||
| 196 | * "<name>[spaces]fmt"
|
||
| 197 | * The combined width of "<name>[spaces]" can be specified in order to align <fmt> on multiple lines.
|
||
| 198 | * Note that there is not trailing newline added implicitely.
|
||
| 199 | *
|
||
| 200 | ba516b61 | Thomas Schöpping | * @param[in] stream Stream to print to or NULL to print to all system streams.
|
| 201 | e545e620 | Thomas Schöpping | * @param[in] name Name of the entry/line.
|
| 202 | * @param[in] namewidth Width of the name column.
|
||
| 203 | * @param[in] fmt Formatted string of information content.
|
||
| 204 | *
|
||
| 205 | * @return Number of characters printed.
|
||
| 206 | */
|
||
| 207 | static unsigned int _printSystemInfoLine(BaseSequentialStream* stream, const char* name, const unsigned int namewidth, const char* fmt, ...) |
||
| 208 | {
|
||
| 209 | aosDbgCheck(stream != NULL);
|
||
| 210 | ba516b61 | Thomas Schöpping | aosDbgCheck(name != NULL);
|
| 211 | e545e620 | Thomas Schöpping | |
| 212 | unsigned int n = 0; |
||
| 213 | ba516b61 | Thomas Schöpping | va_list ap; |
| 214 | e545e620 | Thomas Schöpping | |
| 215 | ba516b61 | Thomas Schöpping | va_start(ap, fmt); |
| 216 | e545e620 | Thomas Schöpping | n += chprintf(stream, name); |
| 217 | while (n < namewidth) {
|
||
| 218 | streamPut(stream, ' ');
|
||
| 219 | ++n; |
||
| 220 | } |
||
| 221 | n += chvprintf(stream, fmt, ap); |
||
| 222 | va_end(ap); |
||
| 223 | |||
| 224 | 933df08e | Thomas Schöpping | streamPut(stream, '\n');
|