Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_system.h @ b49ed442

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