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