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