amiro-os / core / src / aos_system.c @ f3ac1c96
History | View | Annotate | Download (41.451 KB)
| 1 | e545e620 | Thomas Schöpping | /*
|
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | 84f0ce9e | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
| 4 | e545e620 | Thomas Schöpping | |
| 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 <amiroblt.h> |
||
| 32 | 8399aeae | Thomas Schöpping | #include <module.h> |
| 33 | e545e620 | Thomas Schöpping | #include <string.h> |
| 34 | 8399aeae | Thomas Schöpping | #include <stdlib.h> |
| 35 | e545e620 | Thomas Schöpping | #if (AMIROOS_CFG_TESTS_ENABLE == true) |
| 36 | #include <ch_test.h> |
||
| 37 | 0128be0f | Marc Rothmann | #include <rt_test_root.h> |
| 38 | e545e620 | Thomas Schöpping | #endif
|
| 39 | |||
| 40 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 41 | /* LOCAL DEFINITIONS */
|
||
| 42 | /******************************************************************************/
|
||
| 43 | |||
| 44 | e545e620 | Thomas Schöpping | /**
|
| 45 | * @brief Period of the system timer.
|
||
| 46 | */
|
||
| 47 | 1e5f7648 | Thomas Schöpping | #define SYSTIMER_PERIOD (TIME_MAX_SYSTIME - CH_CFG_ST_TIMEDELTA)
|
| 48 | e545e620 | Thomas Schöpping | |
| 49 | /**
|
||
| 50 | * @brief Width of the printable system info text.
|
||
| 51 | */
|
||
| 52 | #define SYSTEM_INFO_WIDTH 70 |
||
| 53 | |||
| 54 | ba516b61 | Thomas Schöpping | /**
|
| 55 | * @brief Width of the name column of the system info table.
|
||
| 56 | */
|
||
| 57 | #define SYSTEM_INFO_NAMEWIDTH 14 |
||
| 58 | |||
| 59 | f3ac1c96 | Thomas Schöpping | #if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)) || defined(__DOXYGEN__) |
| 60 | |||
| 61 | /**
|
||
| 62 | * @brief Weighting factor for the low-pass filter used for calculating the @p _syssyncskew value.
|
||
| 63 | */
|
||
| 64 | #define SYSTEM_SYSSYNCSKEW_LPFACTOR (0.1f / AOS_SYSTEM_TIME_RESOLUTION) |
||
| 65 | |||
| 66 | #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) */ |
||
| 67 | |||
| 68 | /******************************************************************************/
|
||
| 69 | /* EXPORTED VARIABLES */
|
||
| 70 | /******************************************************************************/
|
||
| 71 | |||
| 72 | /**
|
||
| 73 | * @brief Global system object.
|
||
| 74 | */
|
||
| 75 | aos_system_t aos; |
||
| 76 | |||
| 77 | /******************************************************************************/
|
||
| 78 | /* LOCAL TYPES */
|
||
| 79 | /******************************************************************************/
|
||
| 80 | |||
| 81 | /******************************************************************************/
|
||
| 82 | /* LOCAL VARIABLES */
|
||
| 83 | /******************************************************************************/
|
||
| 84 | |||
| 85 | /*
|
||
| 86 | * forward declarations
|
||
| 87 | */
|
||
| 88 | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
| 89 | e545e620 | Thomas Schöpping | static int _shellcmd_configcb(BaseSequentialStream* stream, int argc, char* argv[]); |
| 90 | static int _shellcmd_infocb(BaseSequentialStream* stream, int argc, char* argv[]); |
||
| 91 | static int _shellcmd_shutdowncb(BaseSequentialStream* stream, int argc, char* argv[]); |
||
| 92 | f3ac1c96 | Thomas Schöpping | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
| 93 | e545e620 | Thomas Schöpping | static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]); |
| 94 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
| 95 | 2dd2e257 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
| 96 | e545e620 | Thomas Schöpping | |
| 97 | /**
|
||
| 98 | * @brief Timer to accumulate system uptime.
|
||
| 99 | */
|
||
| 100 | static virtual_timer_t _systimer;
|
||
| 101 | |||
| 102 | /**
|
||
| 103 | * @brief Accumulated system uptime.
|
||
| 104 | */
|
||
| 105 | static aos_timestamp_t _uptime;
|
||
| 106 | |||
| 107 | /**
|
||
| 108 | * @brief Timer register value of last accumulation.
|
||
| 109 | */
|
||
| 110 | static systime_t _synctime;
|
||
| 111 | |||
| 112 | 9ebb11a9 | Thomas Schöpping | #if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER == true)) || defined(__DOXYGEN__) |
| 113 | e545e620 | Thomas Schöpping | /**
|
| 114 | * @brief Timer to drive the SYS_SYNC signal for system wide time synchronization according to SSSP.
|
||
| 115 | */
|
||
| 116 | static virtual_timer_t _syssynctimer;
|
||
| 117 | |||
| 118 | /**
|
||
| 119 | * @brief Last uptime of system wide time synchronization.
|
||
| 120 | */
|
||
| 121 | static aos_timestamp_t _syssynctime;
|
||
| 122 | f3ac1c96 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER == true) */ |
| 123 | e545e620 | Thomas Schöpping | |
| 124 | 9ebb11a9 | Thomas Schöpping | #if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true)) || defined(__DOXYGEN__) |
| 125 | 2674917e | Thomas Schöpping | /**
|
| 126 | * @brief Offset between local clock and system wide synchronization signal.
|
||
| 127 | */
|
||
| 128 | 3e1a9c79 | Thomas Schöpping | static float _syssyncskew; |
| 129 | 2674917e | Thomas Schöpping | |
| 130 | 9ebb11a9 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_MASTER != true) && (AMIROOS_CFG_PROFILE == true) */ |
| 131 | 3e1a9c79 | Thomas Schöpping | |
| 132 | 2dd2e257 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
| 133 | e545e620 | Thomas Schöpping | /**
|
| 134 | * @brief Shell thread working area.
|
||
| 135 | */
|
||
| 136 | THD_WORKING_AREA(_shell_wa, AMIROOS_CFG_SHELL_STACKSIZE); |
||
| 137 | |||
| 138 | /**
|
||
| 139 | * @brief Shell input buffer.
|
||
| 140 | */
|
||
| 141 | static char _shell_line[AMIROOS_CFG_SHELL_LINEWIDTH]; |
||
| 142 | |||
| 143 | /**
|
||
| 144 | * @brief Shell argument buffer.
|
||
| 145 | */
|
||
| 146 | static char* _shell_arglist[AMIROOS_CFG_SHELL_MAXARGS]; |
||
| 147 | |||
| 148 | /**
|
||
| 149 | * @brief Shell command to retrieve system information.
|
||
| 150 | */
|
||
| 151 | static aos_shellcommand_t _shellcmd_info = {
|
||
| 152 | /* name */ "module:info", |
||
| 153 | /* callback */ _shellcmd_infocb,
|
||
| 154 | /* next */ NULL, |
||
| 155 | }; |
||
| 156 | |||
| 157 | /**
|
||
| 158 | * @brief Shell command to set or retrieve system configuration.
|
||
| 159 | */
|
||
| 160 | static aos_shellcommand_t _shellcmd_config = {
|
||
| 161 | /* name */ "module:config", |
||
| 162 | /* callback */ _shellcmd_configcb,
|
||
| 163 | /* next */ NULL, |
||
| 164 | }; |
||
| 165 | |||
| 166 | /**
|
||
| 167 | * @brief Shell command to shutdown the system.
|
||
| 168 | */
|
||
| 169 | static aos_shellcommand_t _shellcmd_shutdown = {
|
||
| 170 | 1d3e002f | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_ENABLE == true) |
| 171 | e545e620 | Thomas Schöpping | /* name */ "system:shutdown", |
| 172 | 1d3e002f | Thomas Schöpping | #else
|
| 173 | /* name */ "module:shutdown", |
||
| 174 | #endif
|
||
| 175 | e545e620 | Thomas Schöpping | /* callback */ _shellcmd_shutdowncb,
|
| 176 | /* next */ NULL, |
||
| 177 | }; |
||
| 178 | |||
| 179 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
| 180 | /**
|
||
| 181 | * @brief Shell kommand to run a test of the ChibiOS/RT kernel.
|
||
| 182 | */
|
||
| 183 | static aos_shellcommand_t _shellcmd_kerneltest = {
|
||
| 184 | /* name */ "kernel:test", |
||
| 185 | /* callback */ _shellcmd_kerneltestcb,
|
||
| 186 | /* next */ NULL, |
||
| 187 | }; |
||
| 188 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
| 189 | 2dd2e257 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
| 190 | e545e620 | Thomas Schöpping | |
| 191 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
| 192 | /* LOCAL FUNCTIONS */
|
||
| 193 | /******************************************************************************/
|
||
| 194 | e545e620 | Thomas Schöpping | |
| 195 | /**
|
||
| 196 | * @brief Print a separator line.
|
||
| 197 | *
|
||
| 198 | ba516b61 | Thomas Schöpping | * @param[in] stream Stream to print to or NULL to print to all system streams.
|
| 199 | e545e620 | Thomas Schöpping | * @param[in] c Character to use.
|
| 200 | * @param[in] n Length of the separator line.
|
||
| 201 | *
|
||
| 202 | * @return Number of characters printed.
|
||
| 203 | */
|
||
| 204 | static unsigned int _printSystemInfoSeparator(BaseSequentialStream* stream, const char c, const unsigned int n) |
||
| 205 | {
|
||
| 206 | aosDbgCheck(stream != NULL);
|
||
| 207 | |||
| 208 | // print the specified character n times
|
||
| 209 | for (unsigned int i = 0; i < n; ++i) { |
||
| 210 | streamPut(stream, c); |
||
| 211 | } |
||
| 212 | streamPut(stream, '\n');
|
||
| 213 | |||
| 214 | return n+1; |
||
| 215 | } |
||
| 216 | |||
| 217 | /**
|
||
| 218 | * @brief Print a system information line.
|
||
| 219 |