Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (8.83 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
/* CONSTANTS                                                                  */
39
/******************************************************************************/
40

    
41
/**
42
 * @brief   Resolution of the system time measurement.
43
 */
44
#define AOS_SYSTEM_TIME_RESOLUTION              ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY)
45

    
46
/**
47
 * @brief   System event flag which is emitted when a shutdown was initiated.
48
 */
49
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN          (eventflags_t)(1 << 0)
50

    
51
/**
52
 * @brief   System event flag which is emitted when a shutdown to transportation mode was initiated.
53
 */
54
#define AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION    (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 1))
55

    
56
/**
57
 * @brief   System event flag which is emitted when a shutdown to deepsleep mode was initiated.
58
 */
59
#define AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP         (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 2))
60

    
61
/**
62
 * @brief   System event flag which is emitted when a shutdown to hibernate mode was initiated.
63
 */
64
#define AOS_SYSTEM_EVENTFLAGS_HIBERNATE         (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 3))
65

    
66
/**
67
 * @brief   System event flag which is emitted when a system restart was initiated.
68
 */
69
#define AOS_SYSTEM_EVENTFLAGS_RESTART           (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 4))
70

    
71
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
72

    
73
/**
74
 * @brief   Major version of the implemented SSSP.
75
 */
76
#define AOS_SYSTEM_SSSP_VERSION_MAJOR           1
77

    
78
/**
79
 * @brief   Minor version of the implemented SSSP.
80
 */
81
#define AOS_SYSTEM_SSSP_VERSION_MINOR           4
82

    
83
/**
84
 * @brief   Timeout delay according to SSSP.
85
 * @details SSSP defines timeouts to be ten times longer than the signal delay time.
86
 */
87
#define AOS_SYSTEM_SSSP_TIMEOUT                 (10 * AMIROOS_CFG_SSSP_SIGNALDELAY)
88

    
89
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
90

    
91
/******************************************************************************/
92
/* SETTINGS                                                                   */
93
/******************************************************************************/
94

    
95
/******************************************************************************/
96
/* CHECKS                                                                     */
97
/******************************************************************************/
98

    
99
/******************************************************************************/
100
/* DATA STRUCTURES AND TYPES                                                  */
101
/******************************************************************************/
102

    
103
/**
104
 * @brief   Enumerator to identify shutdown types.
105
 */
106
typedef enum aos_shutdown {
107
  AOS_SHUTDOWN_NONE,            /**< Default value if no shutdown action was initiated */
108
  AOS_SHUTDOWN_PASSIVE,         /**< Passive shutdown (initiated by another module). */
109
  AOS_SHUTDOWN_HIBERNATE,       /**< Active shutdown to hibernate mode. */
110
  AOS_SHUTDOWN_DEEPSLEEP,       /**< Active shutdown to deepsleep mode. */
111
  AOS_SHUTDOWN_TRANSPORTATION,  /**< Active shutdown to transportation mode. */
112
  AOS_SHUTDOWN_RESTART,         /**< Active saystem restart request. */
113
} aos_shutdown_t;
114

    
115
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
116

    
117
/**
118
 * @brief   Enumerator of the several stages of SSSP.
119
 */
120
typedef enum aos_ssspstage {
121
  AOS_SSSP_STARTUP_1_1  = 0x10, /**< Identifier of SSSP startup phase stage 1-1. */
122
  AOS_SSSP_STARTUP_1_2  = 0x11, /**< Identifier of SSSP startup phase stage 1-2. */
123
  AOS_SSSP_STARTUP_1_3  = 0x12, /**< Identifier of SSSP startup phase stage 1-3. */
124
  AOS_SSSP_STARTUP_2_1  = 0x14, /**< Identifier of SSSP startup phase stage 2-1. */
125
  AOS_SSSP_STARTUP_2_2  = 0x15, /**< Identifier of SSSP startup phase stage 2-2. */
126
  AOS_SSSP_STARTUP_3_1  = 0x18, /**< Identifier of SSSP startup phase stage 3-1. */
127
  AOS_SSSP_STARTUP_3_2  = 0x19, /**< Identifier of SSSP startup phase stage 3-2. */
128
  AOS_SSSP_STARTUP_3_3  = 0x1A, /**< Identifier of SSSP startup phase stage 3-3. */
129
  AOS_SSSP_STARTUP_3_4  = 0x1B, /**< Identifier of SSSP startup phase stage 3-4. */
130
  AOS_SSSP_OPERATION    = 0x20, /**< Identifier of SSSP operation pahse. */
131
  AOS_SSSP_SHUTDOWN_1_1 = 0x30, /**< Identifier of SSSP shutdown phase stage 1-1. */
132
  AOS_SSSP_SHUTDOWN_1_2 = 0x31, /**< Identifier of SSSP shutdown phase stage 1-2. */
133
  AOS_SSSP_SHUTDOWN_1_3 = 0x32, /**< Identifier of SSSP shutdown phase stage 1-3. */
134
  AOS_SSSP_SHUTDOWN_2_1 = 0x34, /**< Identifier of SSSP shutdown phase stage 2-1. */
135
  AOS_SSSP_SHUTDOWN_2_2 = 0x35, /**< Identifier of SSSP shutdown phase stage 2-2. */
136
  AOS_SSSP_SHUTDOWN_3   = 0x38, /**< Identifier of SSSP shutdown phase stage 3. */
137
} aos_ssspstage_t;
138

    
139
/**
140
 * @brief   Type to represent module IDs.
141
 */
142
typedef uint16_t aos_ssspmoduleid_t;
143

    
144
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
145

    
146
/**
147
 * @brief   AMiRo-OS base system structure.
148
 */
149
typedef struct aos_system {
150
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
151
  /**
152
   * @brief   SSSP relevant data.
153
   */
154
  struct {
155
    /**
156
     * @brief   Current SSSP stage of the system.
157
     */
158
    aos_ssspstage_t stage;
159

    
160
    /**
161
     * @brief   Module identifier.
162
     * @details A value of 0 indicates an uninitialized ID.
163
     *          The vlaues 0 and ~0 are reserved und must not be set.
164
     */
165
    aos_ssspmoduleid_t moduleId;
166
  } sssp;
167
#endif /* AMIROOS_CFG_SSSP_ENABLE == true */
168

    
169
  /**
170
   * @brief   System I/O stream.
171
   */
172
  AosIOStream iostream;
173

    
174
  /**
175
   * @brief   Event structure.
176
   */
177
  struct {
178

    
179
    /**
180
     * @brief   I/O event source.
181
     */
182
    event_source_t io;
183

    
184
    /**
185
     * @brief   OS event source.
186
     */
187
    event_source_t os;
188
  } events;
189

    
190
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
191
  /**
192
   * @brief   Pointer to the shell object.
193
   */
194
  aos_shell_t shell;
195
#endif
196

    
197
} aos_system_t;
198

    
199
/******************************************************************************/
200
/* MACROS                                                                     */
201
/******************************************************************************/
202

    
203
/**
204
 * @brief   Printf function that uses the default system I/O stream.
205
 *
206
 * @param[in] fmt   Formatted string to print.
207
 */
208
#define aosprintf(fmt, ...)                     chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__)
209

    
210
/******************************************************************************/
211
/* EXTERN DECLARATIONS                                                        */
212
/******************************************************************************/
213

    
214
/**
215
 * @brief   Global system object.
216
 */
217
extern aos_system_t aos;
218

    
219
#ifdef __cplusplus
220
extern "C" {
221
#endif
222
#if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true)
223
  void aosSysInit(const char* shellPrompt);
224
#else
225
  void aosSysInit(void);
226
#endif
227
  void aosSysStart(void);
228
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined (__DOXYGEN__)
229
  eventmask_t aosSysSsspStartupOsInitSyncCheck(event_listener_t* syncEvtListener);
230
#endif
231
  void aosSysGetUptimeX(aos_timestamp_t* ut);
232
  void aosSysGetDateTime(struct tm* dt);
233
  void aosSysSetDateTime(struct tm* dt);
234
  void aosSysShutdownInit(aos_shutdown_t shutdown);
235
  void aosSysStop(void);
236
  void aosSysDeinit(void);
237
  void aosSysShutdownFinal(aos_shutdown_t shutdown);
238
#ifdef __cplusplus
239
}
240
#endif
241

    
242
/******************************************************************************/
243
/* INLINE FUNCTIONS                                                           */
244
/******************************************************************************/
245

    
246
/**
247
 * @brief   Retrieves the system uptime.
248
 *
249
 * @param[out] ut   Pointer to the system uptime.
250
 */
251
static inline void aosSysGetUptime(aos_timestamp_t* ut)
252
{
253
  chSysLock();
254
  aosSysGetUptimeX(ut);
255
  chSysUnlock();
256
}
257

    
258
#endif /* AMIROOS_SYSTEM_H */
259

    
260
/** @} */