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