amiro-os / core / inc / aos_system.h @ 83e94d4b
History | View | Annotate | Download (7.064 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 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 |
/**
|
20 |
* @file aos_system.h
|
21 |
* @brief System macros and structures.
|
22 |
*
|
23 |
* @addtogroup aos_system
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#ifndef _AMIROOS_SYSTEM_H_
|
28 |
#define _AMIROOS_SYSTEM_H_
|
29 |
|
30 |
#include <time.h> |
31 |
#include <aos_iostream.h> |
32 |
#include <amiro-lld.h> |
33 |
#include <aos_shell.h> |
34 |
#include <aos_time.h> |
35 |
#include <chprintf.h> |
36 |
|
37 |
/**
|
38 |
* @brief Resolution of the system time measurement.
|
39 |
*/
|
40 |
#define AOS_SYSTEM_TIME_RESOLUTION ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY) |
41 |
|
42 |
/**
|
43 |
* @brief System event flag which is emitted when a shutdown was initiated.
|
44 |
*/
|
45 |
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN (eventflags_t)(1 << 0) |
46 |
|
47 |
/**
|
48 |
* @brief System event flag which is emitted when a shutdown to transportation mode was initiated.
|
49 |
*/
|
50 |
#define AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 1)) |
51 |
|
52 |
/**
|
53 |
* @brief System event flag which is emitted when a shutdown to deepsleep mode was initiated.
|
54 |
*/
|
55 |
#define AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 2)) |
56 |
|
57 |
/**
|
58 |
* @brief System event flag which is emitted when a shutdown to hibernate mode was initiated.
|
59 |
*/
|
60 |
#define AOS_SYSTEM_EVENTFLAGS_HIBERNATE (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 3)) |
61 |
|
62 |
/**
|
63 |
* @brief System event flag which is emitted when a system restart was initiated.
|
64 |
*/
|
65 |
#define AOS_SYSTEM_EVENTFLAGS_RESTART (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 4)) |
66 |
|
67 |
/**
|
68 |
* @brief Enumerator to identify shutdown types.
|
69 |
*/
|
70 |
typedef enum aos_shutdown { |
71 |
AOS_SHUTDOWN_NONE, /**< Default value if no shutdown action was initiated */
|
72 |
AOS_SHUTDOWN_PASSIVE, /**< Passive shutdown (initiated by another module). */
|
73 |
AOS_SHUTDOWN_HIBERNATE, /**< Active shutdown to hibernate mode. */
|
74 |
AOS_SHUTDOWN_DEEPSLEEP, /**< Active shutdown to deepsleep mode. */
|
75 |
AOS_SHUTDOWN_TRANSPORTATION, /**< Active shutdown to transportation mode. */
|
76 |
AOS_SHUTDOWN_RESTART, /**< Active saystem restart request. */
|
77 |
} aos_shutdown_t; |
78 |
|
79 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
80 |
|
81 |
/**
|
82 |
* @brief Major version of the implemented SSSP.
|
83 |
*/
|
84 |
#define AOS_SYSTEM_SSSP_VERSION_MAJOR 1 |
85 |
|
86 |
/**
|
87 |
* @brief Minor version of the implemented SSSP.
|
88 |
*/
|
89 |
#define AOS_SYSTEM_SSSP_VERSION_MINOR 4 |
90 |
|
91 |
/**
|
92 |
* @brief Timeout delay according to SSSP.
|
93 |
* @details SSSP defines timeouts to be ten times longer than the signal delay time.
|
94 |
*/
|
95 |
#define AOS_SYSTEM_SSSP_TIMEOUT (10 * AMIROOS_CFG_SSSP_SIGNALDELAY) |
96 |
|
97 |
/**
|
98 |
* @brief Enumerator of the several stages of SSSP.
|
99 |
*/
|
100 |
typedef enum aos_ssspstage { |
101 |
AOS_SSSP_STARTUP_1_1 = 0x10, /**< Identifier of SSSP startup phase stage 1-1. */ |
102 |
AOS_SSSP_STARTUP_1_2 = 0x11, /**< Identifier of SSSP startup phase stage 1-2. */ |
103 |
AOS_SSSP_STARTUP_1_3 = 0x12, /**< Identifier of SSSP startup phase stage 1-3. */ |
104 |
AOS_SSSP_STARTUP_2_1 = 0x14, /**< Identifier of SSSP startup phase stage 2-1. */ |
105 |
AOS_SSSP_STARTUP_2_2 = 0x15, /**< Identifier of SSSP startup phase stage 2-2. */ |
106 |
AOS_SSSP_STARTUP_3_1 = 0x18, /**< Identifier of SSSP startup phase stage 3-1. */ |
107 |
AOS_SSSP_STARTUP_3_2 = 0x19, /**< Identifier of SSSP startup phase stage 3-2. */ |
108 |
AOS_SSSP_STARTUP_3_3 = 0x1A, /**< Identifier of SSSP startup phase stage 3-3. */ |
109 |
AOS_SSSP_STARTUP_3_4 = 0x1B, /**< Identifier of SSSP startup phase stage 3-4. */ |
110 |
AOS_SSSP_OPERATION = 0x20, /**< Identifier of SSSP operation pahse. */ |
111 |
AOS_SSSP_SHUTDOWN_1_1 = 0x30, /**< Identifier of SSSP shutdown phase stage 1-1. */ |
112 |
AOS_SSSP_SHUTDOWN_1_2 = 0x31, /**< Identifier of SSSP shutdown phase stage 1-2. */ |
113 |
AOS_SSSP_SHUTDOWN_1_3 = 0x32, /**< Identifier of SSSP shutdown phase stage 1-3. */ |
114 |
AOS_SSSP_SHUTDOWN_2_1 = 0x34, /**< Identifier of SSSP shutdown phase stage 2-1. */ |
115 |
AOS_SSSP_SHUTDOWN_2_2 = 0x35, /**< Identifier of SSSP shutdown phase stage 2-2. */ |
116 |
AOS_SSSP_SHUTDOWN_3 = 0x38, /**< Identifier of SSSP shutdown phase stage 3. */ |
117 |
} aos_ssspstage_t; |
118 |
|
119 |
/**
|
120 |
* @brief Type to represent module IDs.
|
121 |
*/
|
122 |
typedef uint16_t aos_ssspmoduleid_t;
|
123 |
|
124 |
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */ |
125 |
|
126 |
/**
|
127 |
* @brief AMiRo-OS base system structure.
|
128 |
*/
|
129 |
typedef struct aos_system { |
130 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
131 |
/**
|
132 |
* @brief SSSP relevant data.
|
133 |
*/
|
134 |
struct {
|
135 |
/**
|
136 |
* @brief Current SSSP stage of the system.
|
137 |
*/
|
138 |
aos_ssspstage_t stage; |
139 |
|
140 |
/**
|
141 |
* @brief Module identifier.
|
142 |
* @details A value of 0 indicates an uninitialized ID.
|
143 |
* The vlaues 0 and ~0 are reserved und must not be set.
|
144 |
*/
|
145 |
aos_ssspmoduleid_t moduleId; |
146 |
} sssp; |
147 |
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */ |
148 |
|
149 |
/**
|
150 |
* @brief System I/O stream.
|
151 |
*/
|
152 |
AosIOStream iostream; |
153 |
|
154 |
/**
|
155 |
* @brief Event structure.
|
156 |
*/
|
157 |
struct {
|
158 |
|
159 |
/**
|
160 |
* @brief I/O event source.
|
161 |
*/
|
162 |
event_source_t io; |
163 |
|
164 |
/**
|
165 |
* @brief OS event source.
|
166 |
*/
|
167 |
event_source_t os; |
168 |
} events; |
169 |
|
170 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
171 |
/**
|
172 |
* @brief Pointer to the shell object.
|
173 |
*/
|
174 |
aos_shell_t shell; |
175 |
#endif
|
176 |
|
177 |
} aos_system_t; |
178 |
|
179 |
/**
|
180 |
* @brief Global system object.
|
181 |
*/
|
182 |
extern aos_system_t aos;
|
183 |
|
184 |
/**
|
185 |
* @brief Printf function that uses the default system I/O stream.
|
186 |
*
|
187 |
* @param[in] fmt Formatted string to print.
|
188 |
*/
|
189 |
#define aosprintf(fmt, ...) chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__) |
190 |
|
191 |
#ifdef __cplusplus
|
192 |
extern "C" { |
193 |
#endif
|
194 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) |
195 |
void aosSysInit(const char* shellPrompt); |
196 |
#else
|
197 |
void aosSysInit(void); |
198 |
#endif
|
199 |
void aosSysStart(void); |
200 |
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined (__DOXYGEN__) |
201 |
eventmask_t aosSysSsspStartupOsInitSyncCheck(event_listener_t* syncEvtListener); |
202 |
#endif
|
203 |
void aosSysGetUptimeX(aos_timestamp_t* ut);
|
204 |
void aosSysGetDateTime(struct tm* dt); |
205 |
void aosSysSetDateTime(struct tm* dt); |
206 |
void aosSysShutdownInit(aos_shutdown_t shutdown);
|
207 |
void aosSysStop(void); |
208 |
void aosSysDeinit(void); |
209 |
void aosSysShutdownFinal(aos_shutdown_t shutdown);
|
210 |
#ifdef __cplusplus
|
211 |
} |
212 |
#endif
|
213 |
|
214 |
/**
|
215 |
* @brief Retrieves the system uptime.
|
216 |
*
|
217 |
* @param[out] ut Pointer to the system uptime.
|
218 |
*/
|
219 |
static inline void aosSysGetUptime(aos_timestamp_t* ut) |
220 |
{ |
221 |
chSysLock(); |
222 |
aosSysGetUptimeX(ut); |
223 |
chSysUnlock(); |
224 |
} |
225 |
|
226 |
#endif /* _AMIROOS_SYSTEM_H_ */ |
227 |
|
228 |
/** @} */
|