Statistics
| Branch: | Tag: | Revision:

amiro-os / os / core / src / aos_system.c @ 2674917e

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