Statistics
| Branch: | Tag: | Revision:

amiro-os / core / src / aos_system.c @ e977b199

History | View | Annotate | Download (39.126 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 96621a83 Thomas Schöpping
Copyright (C) 2016..2020  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 08d86900 Thomas Schöpping
#define SYSTEM_INFO_WIDTH             80
52 e545e620 Thomas Schöpping
53 ba516b61 Thomas Schöpping
/**
54
 * @brief   Width of the name column of the system info table.
55
 */
56 08d86900 Thomas Schöpping
#define SYSTEM_INFO_NAMEWIDTH         20
57 ba516b61 Thomas Schöpping
58 697dba3c Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
59
60
/**
61
 * @brief   Number of entries in the system shell input buffer.
62
 */
63
#define SYSTEM_SHELL_BUFFERENTRIES    (1 + AMIROOS_CFG_SHELL_HISTLENGTH)
64
65
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
66
67 f3ac1c96 Thomas Schöpping
/******************************************************************************/
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 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_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 3da12676 Thomas Schöpping
#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
92
static int _shellcmd_cpuloadcb(BaseSequentialStream* stream, int argc, char* argv[]);
93
#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
94 f3ac1c96 Thomas Schöpping
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
95 e545e620 Thomas Schöpping
static int _shellcmd_kerneltestcb(BaseSequentialStream* stream, int argc, char* argv[]);
96 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
97 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
98 e545e620 Thomas Schöpping
99
/**
100
 * @brief   Timer to accumulate system uptime.
101
 */
102
static virtual_timer_t _systimer;
103
104
/**
105
 * @brief   Accumulated system uptime.
106
 */
107
static aos_timestamp_t _uptime;
108
109
/**
110
 * @brief   Timer register value of last accumulation.
111
 */
112
static systime_t _synctime;
113
114 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
115 3e1a9c79 Thomas Schöpping
116 e545e620 Thomas Schöpping
/**
117 3da12676 Thomas Schöpping
 * @brief   System shell name.
118
 */
119
static const char _shell_name[] = "system shell";
120
121
/**
122 e545e620 Thomas Schöpping
 * @brief   Shell thread working area.
123
 */
124 10fd7ac9 Thomas Schöpping
static THD_WORKING_AREA(_shell_wa, AMIROOS_CFG_SHELL_STACKSIZE);
125 e545e620 Thomas Schöpping
126
/**
127
 * @brief   Shell input buffer.
128
 */
129 697dba3c Thomas Schöpping
static char _shell_buffer[SYSTEM_SHELL_BUFFERENTRIES * AMIROOS_CFG_SHELL_LINEWIDTH];
130 e545e620 Thomas Schöpping
131
/**
132
 * @brief   Shell command to retrieve system information.
133
 */
134 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_info, "module:info", _shellcmd_infocb);
135 e545e620 Thomas Schöpping
136
/**
137
 * @brief   Shell command to set or retrieve system configuration.
138
 */
139 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_config, "module:config", _shellcmd_configcb);
140 e545e620 Thomas Schöpping
141
/**
142
 * @brief   Shell command to shutdown the system.
143
 */
144 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
145 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "system:shutdown", _shellcmd_shutdowncb);
146 7de0cc90 Thomas Schöpping
#else /* (AMIROOS_CFG_SSSP_ENABLE == true) */
147 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_shutdown, "module:shutdown", _shellcmd_shutdowncb);
148 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
149 e545e620 Thomas Schöpping
150 3da12676 Thomas Schöpping
#if ((CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE)) || defined(__DOXYGEN__)
151
152
/**
153
 * @brief   Shell command to read out CPU load.
154
 */
155
static AOS_SHELL_COMMAND(_shellcmd_cpuload, "module:cpuload", _shellcmd_cpuloadcb);
156
157
#endif /* (CH_CFG_USE_REGISTRY == TRUE) && (CH_DBG_STATISTICS == TRUE) */
158
159 e545e620 Thomas Schöpping
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
160 cda14729 Thomas Schöpping
161 e545e620 Thomas Schöpping
/**
162 3da12676 Thomas Schöpping
 * @brief   Shell command to run a test of the ChibiOS/RT kernel.
163 e545e620 Thomas Schöpping
 */
164 4c72a54c Thomas Schöpping
static AOS_SHELL_COMMAND(_shellcmd_kerneltest, "kernel:test", _shellcmd_kerneltestcb);
165 cda14729 Thomas Schöpping
166 7de0cc90 Thomas Schöpping
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
167 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
168 e545e620 Thomas Schöpping
169 f3ac1c96 Thomas Schöpping
/******************************************************************************/
170
/* LOCAL FUNCTIONS                                                            */
171
/******************************************************************************/
172 e545e620 Thomas Schöpping
173
/**
174
 * @brief   Print a separator line.
175
 *
176 ba516b61 Thomas Schöpping
 * @param[in] stream    Stream to print to or NULL to print to all system streams.
177 e545e620 Thomas Schöpping
 * @param[in] c         Character to use.
178
 * @param[in] n         Length of the separator line.
179
 *
180
 * @return  Number of characters printed.
181
 */
182
static unsigned int _printSystemInfoSeparator(BaseSequentialStream* stream, const char c, const unsigned int n)
183
{
184
  aosDbgCheck(stream != NULL);
185
186
  // print the specified character n times
187
  for (unsigned int i = 0; i < n; ++i) {
188 83e58975 Thomas Schöpping
    streamPut(stream, (uint8_t)c);
189 e545e620 Thomas Schöpping
  }
190
  streamPut(stream, '\n');
191
192
  return n+1;
193
}
194
195
/**
196
 * @brief   Print a system information line.
197
 * @details Prints a system information line with the following format:
198
 *            "<name>[spaces]fmt"
199
 *          The combined width of "<name>[spaces]" can be specified in order to align <fmt> on multiple lines.
200
 *          Note that there is not trailing newline added implicitely.
201
 *
202 ba516b61 Thomas Schöpping
 * @param[in] stream      Stream to print to or NULL to print to all system streams.
203 e545e620 Thomas Schöpping
 * @param[in] name        Name of the entry/line.
204 08d86900 Thomas Schöpp