amiro-os / core / inc / aos_system.h @ 6a5c36eb
History | View | Annotate | Download (8.882 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.h
|
||
21 | * @brief System macros and structures.
|
||
22 | *
|
||
23 | * @addtogroup aos_system
|
||
24 | * @{
|
||
25 | */
|
||
26 | |||
27 | 6ff06bbf | Thomas Schöpping | #ifndef AMIROOS_SYSTEM_H
|
28 | #define AMIROOS_SYSTEM_H
|
||
29 | e545e620 | Thomas Schöpping | |
30 | 3940ba8a | Thomas Schöpping | #include <amiroos.h> |
31 | e545e620 | Thomas Schöpping | #include <chprintf.h> |
32 | |||
33 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
34 | /* CONSTANTS */
|
||
35 | /******************************************************************************/
|
||
36 | |||
37 | e545e620 | Thomas Schöpping | /**
|
38 | ba516b61 | Thomas Schöpping | * @brief Resolution of the system time measurement.
|
39 | e545e620 | Thomas Schöpping | */
|
40 | ba516b61 | Thomas Schöpping | #define AOS_SYSTEM_TIME_RESOLUTION ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY) |
41 | e545e620 | Thomas Schöpping | |
42 | /**
|
||
43 | e4379628 | Thomas Schöpping | * @brief System event flag mask for shutdown related events.
|
44 | e545e620 | Thomas Schöpping | */
|
45 | e4379628 | Thomas Schöpping | #define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_MASK ((eventflags_t)0x1F) |
46 | |||
47 | /**
|
||
48 | * @brief System event flag which is emitted when a passive shutdown was initiated.
|
||
49 | */
|
||
50 | #define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_PASSIVE ((eventflags_t)(1 << 0)) |
||
51 | e545e620 | Thomas Schöpping | |
52 | /**
|
||
53 | * @brief System event flag which is emitted when a shutdown to transportation mode was initiated.
|
||
54 | */
|
||
55 | e4379628 | Thomas Schöpping | #define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_TRANSPORTATION ((eventflags_t)(1 << 1)) |
56 | e545e620 | Thomas Schöpping | |
57 | /**
|
||
58 | * @brief System event flag which is emitted when a shutdown to deepsleep mode was initiated.
|
||
59 | */
|
||
60 | e4379628 | Thomas Schöpping | #define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_DEEPSLEEP ((eventflags_t)(1 << 2)) |
61 | e545e620 | Thomas Schöpping | |
62 | /**
|
||
63 | * @brief System event flag which is emitted when a shutdown to hibernate mode was initiated.
|
||
64 | */
|
||
65 | e4379628 | Thomas Schöpping | #define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_HIBERNATE ((eventflags_t)(1 << 3)) |
66 | e545e620 | Thomas Schöpping | |
67 | /**
|
||
68 | * @brief System event flag which is emitted when a system restart was initiated.
|
||
69 | */
|
||
70 | e4379628 | Thomas Schöpping | #define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_RESTART ((eventflags_t)(1 << 4)) |
71 | e545e620 | Thomas Schöpping | |
72 | 9ebb11a9 | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
73 | |||
74 | /**
|
||
75 | e545e620 | Thomas Schöpping | * @brief Major version of the implemented SSSP.
|
76 | */
|
||
77 | 933df08e | Thomas Schöpping | #define AOS_SYSTEM_SSSP_VERSION_MAJOR 1 |
78 | e545e620 | Thomas Schöpping | |
79 | /**
|
||
80 | * @brief Minor version of the implemented SSSP.
|
||
81 | */
|
||
82 | 933df08e | Thomas Schöpping | #define AOS_SYSTEM_SSSP_VERSION_MINOR 4 |
83 | |||
84 | /**
|
||
85 | * @brief Timeout delay according to SSSP.
|
||
86 | * @details SSSP defines timeouts to be ten times longer than the signal delay time.
|
||
87 | */
|
||
88 | #define AOS_SYSTEM_SSSP_TIMEOUT (10 * AMIROOS_CFG_SSSP_SIGNALDELAY) |
||
89 | e545e620 | Thomas Schöpping | |
90 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
91 | f3ac1c96 | Thomas Schöpping | |
92 | /******************************************************************************/
|
||
93 | /* SETTINGS */
|
||
94 | /******************************************************************************/
|
||
95 | |||
96 | /******************************************************************************/
|
||
97 | /* CHECKS */
|
||
98 | /******************************************************************************/
|
||
99 | |||
100 | /******************************************************************************/
|
||
101 | /* DATA STRUCTURES AND TYPES */
|
||
102 | /******************************************************************************/
|
||
103 | |||
104 | /**
|
||
105 | * @brief Enumerator to identify shutdown types.
|
||
106 | */
|
||
107 | typedef enum aos_shutdown { |
||
108 | AOS_SHUTDOWN_NONE, /**< Default value if no shutdown action was initiated */
|
||
109 | AOS_SHUTDOWN_PASSIVE, /**< Passive shutdown (initiated by another module). */
|
||
110 | AOS_SHUTDOWN_HIBERNATE, /**< Active shutdown to hibernate mode. */
|
||
111 | AOS_SHUTDOWN_DEEPSLEEP, /**< Active shutdown to deepsleep mode. */
|
||
112 | AOS_SHUTDOWN_TRANSPORTATION, /**< Active shutdown to transportation mode. */
|
||
113 | AOS_SHUTDOWN_RESTART, /**< Active saystem restart request. */
|
||
114 | } aos_shutdown_t; |
||
115 | |||
116 | #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
||
117 | |||
118 | e545e620 | Thomas Schöpping | /**
|
119 | 933df08e | Thomas Schöpping | * @brief Enumerator of the several stages of SSSP.
|
120 | e545e620 | Thomas Schöpping | */
|
121 | typedef enum aos_ssspstage { |
||
122 | 933df08e | Thomas Schöpping | AOS_SSSP_STARTUP_1_1 = 0x10, /**< Identifier of SSSP startup phase stage 1-1. */ |
123 | AOS_SSSP_STARTUP_1_2 = 0x11, /**< Identifier of SSSP startup phase stage 1-2. */ |
||
124 | AOS_SSSP_STARTUP_1_3 = 0x12, /**< Identifier of SSSP startup phase stage 1-3. */ |
||
125 | AOS_SSSP_STARTUP_2_1 = 0x14, /**< Identifier of SSSP startup phase stage 2-1. */ |
||
126 | AOS_SSSP_STARTUP_2_2 = 0x15, /**< Identifier of SSSP startup phase stage 2-2. */ |
||
127 | AOS_SSSP_STARTUP_3_1 = 0x18, /**< Identifier of SSSP startup phase stage 3-1. */ |
||
128 | AOS_SSSP_STARTUP_3_2 = 0x19, /**< Identifier of SSSP startup phase stage 3-2. */ |
||
129 | AOS_SSSP_STARTUP_3_3 = 0x1A, /**< Identifier of SSSP startup phase stage 3-3. */ |
||
130 | AOS_SSSP_STARTUP_3_4 = 0x1B, /**< Identifier of SSSP startup phase stage 3-4. */ |
||
131 | AOS_SSSP_OPERATION = 0x20, /**< Identifier of SSSP operation pahse. */ |
||
132 | AOS_SSSP_SHUTDOWN_1_1 = 0x30, /**< Identifier of SSSP shutdown phase stage 1-1. */ |
||
133 | AOS_SSSP_SHUTDOWN_1_2 = 0x31, /**< Identifier of SSSP shutdown phase stage 1-2. */ |
||
134 | AOS_SSSP_SHUTDOWN_1_3 = 0x32, /**< Identifier of SSSP shutdown phase stage 1-3. */ |
||
135 | AOS_SSSP_SHUTDOWN_2_1 = 0x34, /**< Identifier of SSSP shutdown phase stage 2-1. */ |
||
136 | AOS_SSSP_SHUTDOWN_2_2 = 0x35, /**< Identifier of SSSP shutdown phase stage 2-2. */ |
||
137 | AOS_SSSP_SHUTDOWN_3 = 0x38, /**< Identifier of SSSP shutdown phase stage 3. */ |
||
138 | e545e620 | Thomas Schöpping | } aos_ssspstage_t; |
139 | |||
140 | /**
|
||
141 | 933df08e | Thomas Schöpping | * @brief Type to represent module IDs.
|
142 | */
|
||
143 | typedef uint16_t aos_ssspmoduleid_t;
|
||
144 | |||
145 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
146 | 9ebb11a9 | Thomas Schöpping | |
147 | 933df08e | Thomas Schöpping | /**
|
148 | e545e620 | Thomas Schöpping | * @brief AMiRo-OS base system structure.
|
149 | */
|
||
150 | typedef struct aos_system { |
||
151 | 9ebb11a9 | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__) |
152 | e545e620 | Thomas Schöpping | /**
|
153 | 6b53f6bf | Thomas Schöpping | * @brief SSSP relevant data.
|
154 | e545e620 | Thomas Schöpping | */
|
155 | 6b53f6bf | Thomas Schöpping | struct {
|
156 | /**
|
||
157 | * @brief Current SSSP stage of the system.
|
||
158 | */
|
||
159 | aos_ssspstage_t stage; |
||
160 | 933df08e | Thomas Schöpping | |
161 | /**
|
||
162 | * @brief Module identifier.
|
||
163 | * @details A value of 0 indicates an uninitialized ID.
|
||
164 | * The vlaues 0 and ~0 are reserved und must not be set.
|
||
165 | */
|
||
166 | aos_ssspmoduleid_t moduleId; |
||
167 | 6b53f6bf | Thomas Schöpping | } sssp; |
168 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
169 | e545e620 | Thomas Schöpping | |
170 | /**
|
||
171 | ba516b61 | Thomas Schöpping | * @brief System I/O stream.
|
172 | */
|
||
173 | AosIOStream iostream; |
||
174 | |||
175 | /**
|
||
176 | e545e620 | Thomas Schöpping | * @brief Event structure.
|
177 | */
|
||
178 | struct {
|
||
179 | |||
180 | /**
|
||
181 | 1a8fb642 | Thomas Schöpping | * @brief GPIO event source.
|
182 | e545e620 | Thomas Schöpping | */
|
183 | 1a8fb642 | Thomas Schöpping | event_source_t gpio; |
184 | e545e620 | Thomas Schöpping | |
185 | /**
|
||
186 | 6b53f6bf | Thomas Schöpping | * @brief OS event source.
|
187 | e545e620 | Thomas Schöpping | */
|
188 | 6b53f6bf | Thomas Schöpping | event_source_t os; |
189 | e545e620 | Thomas Schöpping | } events; |
190 | |||
191 | 47e89ebf | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
192 | 7de0cc90 | Thomas Schöpping | |
193 | e545e620 | Thomas Schöpping | /**
|
194 | * @brief Pointer to the shell object.
|
||
195 | */
|
||
196 | 6b53f6bf | Thomas Schöpping | aos_shell_t shell; |
197 | 7de0cc90 | Thomas Schöpping | |
198 | 47e89ebf | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */ |
199 | e545e620 | Thomas Schöpping | |
200 | } aos_system_t; |
||
201 | |||
202 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
203 | /* MACROS */
|
||
204 | /******************************************************************************/
|
||
205 | e545e620 | Thomas Schöpping | |
206 | ba516b61 | Thomas Schöpping | /**
|
207 | * @brief Printf function that uses the default system I/O stream.
|
||
208 | 933df08e | Thomas Schöpping | *
|
209 | * @param[in] fmt Formatted string to print.
|
||
210 | ba516b61 | Thomas Schöpping | */
|
211 | #define aosprintf(fmt, ...) chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__) |
||
212 | |||
213 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
214 | /* EXTERN DECLARATIONS */
|
||
215 | /******************************************************************************/
|
||
216 | |||
217 | /**
|
||
218 | * @brief Global system object.
|
||
219 | */
|
||
220 | extern aos_system_t aos;
|
||
221 | |||
222 | 7de0cc90 | Thomas Schöpping | #if defined(__cplusplus)
|
223 | e545e620 | Thomas Schöpping | extern "C" { |
224 | 7de0cc90 | Thomas Schöpping | #endif /* defined(__cplusplus) */ |
225 | 6b53f6bf | Thomas Schöpping | void aosSysInit(const char* shellPrompt); |
226 | e545e620 | Thomas Schöpping | void aosSysStart(void); |
227 | 9ebb11a9 | Thomas Schöpping | #if (AMIROOS_CFG_SSSP_ENABLE == true) || defined (__DOXYGEN__) |
228 | e545e620 | Thomas Schöpping | eventmask_t aosSysSsspStartupOsInitSyncCheck(event_listener_t* syncEvtListener); |
229 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */ |
230 | e545e620 | Thomas Schöpping | void aosSysGetUptimeX(aos_timestamp_t* ut);
|
231 | 23437e98 | Thomas Schöpping | #if (HAL_USE_RTC == TRUE)
|
232 | 8399aeae | Thomas Schöpping | void aosSysGetDateTime(struct tm* dt); |
233 | void aosSysSetDateTime(struct tm* dt); |
||
234 | 7de0cc90 | Thomas Schöpping | #endif /* (HAL_USE_RTC == TRUE) */ |
235 | e545e620 | Thomas Schöpping | void aosSysShutdownInit(aos_shutdown_t shutdown);
|
236 | void aosSysStop(void); |
||
237 | void aosSysDeinit(void); |
||
238 | 1e5f7648 | Thomas Schöpping | void aosSysShutdownFinal(aos_shutdown_t shutdown);
|
239 | 1a8fb642 | Thomas Schöpping | palcallback_t aosSysGetStdGpioCallback(void);
|
240 | 7de0cc90 | Thomas Schöpping | #if defined(__cplusplus)
|
241 | e545e620 | Thomas Schöpping | } |
242 | 7de0cc90 | Thomas Schöpping | #endif /* defined(__cplusplus) */ |
243 | e545e620 | Thomas Schöpping | |
244 | f3ac1c96 | Thomas Schöpping | /******************************************************************************/
|
245 | /* INLINE FUNCTIONS */
|
||
246 | /******************************************************************************/
|
||
247 | |||
248 | e545e620 | Thomas Schöpping | /**
|
249 | * @brief Retrieves the system uptime.
|
||
250 | *
|
||
251 | acc97cbf | Thomas Schöpping | * @param[out] ut Pointer to the system uptime.
|
252 | e545e620 | Thomas Schöpping | */
|
253 | 9ff01927 | Thomas Schöpping | static inline void aosSysGetUptime(aos_timestamp_t* ut) |
254 | { |
||
255 | chSysLock(); |
||
256 | aosSysGetUptimeX(ut); |
||
257 | chSysUnlock(); |
||
258 | e545e620 | Thomas Schöpping | } |
259 | |||
260 | 6ff06bbf | Thomas Schöpping | #endif /* AMIROOS_SYSTEM_H */ |
261 | 53710ca3 | Marc Rothmann | |
262 | /** @} */ |