Statistics
| Branch: | Tag: | Revision:

amiro-os / os / core / inc / aos_system.h @ 6b53f6bf

History | View | Annotate | Download (6.089 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
#include <chprintf.h>
27
28
/**
29 ba516b61 Thomas Schöpping
 * @brief   Resolution of the system time measurement.
30 e545e620 Thomas Schöpping
 */
31 ba516b61 Thomas Schöpping
#define AOS_SYSTEM_TIME_RESOLUTION              ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY)
32 e545e620 Thomas Schöpping
33
/**
34 ba516b61 Thomas Schöpping
 * @brief   System event flag which is emitted when a shutdown was initiated.
35 e545e620 Thomas Schöpping
 */
36 ba516b61 Thomas Schöpping
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN          (eventflags_t)(1 << 0)
37 e545e620 Thomas Schöpping
38
/**
39
 * @brief   System event flag which is emitted when a shutdown to transportation mode was initiated.
40
 */
41 ba516b61 Thomas Schöpping
#define AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION    (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 1))
42 e545e620 Thomas Schöpping
43
/**
44
 * @brief   System event flag which is emitted when a shutdown to deepsleep mode was initiated.
45
 */
46 ba516b61 Thomas Schöpping
#define AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP         (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 2))
47 e545e620 Thomas Schöpping
48
/**
49
 * @brief   System event flag which is emitted when a shutdown to hibernate mode was initiated.
50
 */
51 ba516b61 Thomas Schöpping
#define AOS_SYSTEM_EVENTFLAGS_HIBERNATE         (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 3))
52 e545e620 Thomas Schöpping
53
/**
54
 * @brief   System event flag which is emitted when a system restart was initiated.
55
 */
56 ba516b61 Thomas Schöpping
#define AOS_SYSTEM_EVENTFLAGS_RESTART           (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 4))
57 e545e620 Thomas Schöpping
58
/**
59
 * @brief   Major version of the implemented SSSP.
60
 */
61
#define AOS_SYSTEM_SSSP_MAJOR                   1
62
63
/**
64
 * @brief   Minor version of the implemented SSSP.
65
 */
66
#define AOS_SYSTEM_SSSP_MINOR                   3
67
68
/**
69
 * @brief   Enumerator to identify shutdown types.
70
 */
71
typedef enum aos_shutdown {
72
  AOS_SHUTDOWN_NONE,            /**< Default value if no shutdown action was initiated */
73
  AOS_SHUTDOWN_PASSIVE,         /**< Passive shutdown (initiated by another module). */
74
  AOS_SHUTDOWN_HIBERNATE,       /**< Active shutdown to hibernate mode. */
75
  AOS_SHUTDOWN_DEEPSLEEP,       /**< Active shutdown to deepsleep mode. */
76
  AOS_SHUTDOWN_TRANSPORTATION,  /**< Active shutdown to transportation mode. */
77
  AOS_SHUTDOWN_RESTART,         /**< Active saystem restart request. */
78
} aos_shutdown_t;
79
80
/**
81
 * @brief   Enumerator of the several stages of SSSP
82
 */
83
typedef enum aos_ssspstage {
84
  AOS_SSSP_STARTUP_1_1  = 0x0000, /**< Identifier of SSSP startup phase stage 1-1. */
85
  AOS_SSSP_STARTUP_1_2  = 0x0001, /**< Identifier of SSSP startup phase stage 1-2. */
86
  AOS_SSSP_STARTUP_1_3  = 0x0002, /**< Identifier of SSSP startup phase stage 1-3. */
87
  AOS_SSSP_STARTUP_2_1  = 0x0004, /**< Identifier of SSSP startup phase stage 2-1. */
88
  AOS_SSSP_STARTUP_2_2  = 0x0005, /**< Identifier of SSSP startup phase stage 2-2. */
89
  AOS_SSSP_STARTUP_3_1  = 0x0008, /**< Identifier of SSSP startup phase stage 3-1. */
90
  AOS_SSSP_STARTUP_3_2  = 0x0009, /**< Identifier of SSSP startup phase stage 3-2. */
91
  AOS_SSSP_STARTUP_3_3  = 0x000A, /**< Identifier of SSSP startup phase stage 3-3. */
92
  AOS_SSSP_STARTUP_3_4  = 0x000B, /**< Identifier of SSSP startup phase stage 3-4. */
93
  AOS_SSSP_OPERATION    = 0x0100, /**< Identifier of SSSP operation pahse. */
94
  AOS_SSSP_SHUTDOWN_1_1 = 0x0200, /**< Identifier of SSSP shutdown phase stage 1-1. */
95
  AOS_SSSP_SHUTDOWN_1_2 = 0x0201, /**< Identifier of SSSP shutdown phase stage 1-2. */
96
  AOS_SSSP_SHUTDOWN_1_3 = 0x0202, /**< Identifier of SSSP shutdown phase stage 1-3. */
97
  AOS_SSSP_SHUTDOWN_2_1 = 0x0204, /**< Identifier of SSSP shutdown phase stage 2-1. */
98
  AOS_SSSP_SHUTDOWN_2_2 = 0x0205, /**< Identifier of SSSP shutdown phase stage 2-2. */
99
  AOS_SSSP_SHUTDOWN_3   = 0x0208, /**< Identifier of SSSP shutdown phase stage 3. */
100
} aos_ssspstage_t;
101
102
/**
103
 * @brief   AMiRo-OS base system structure.
104
 */
105
typedef struct aos_system {
106 6b53f6bf Thomas Schöpping
107 e545e620 Thomas Schöpping
  /**
108 6b53f6bf Thomas Schöpping
   * @brief   SSSP relevant data.
109 e545e620 Thomas Schöpping
   */
110 6b53f6bf Thomas Schöpping
  struct {
111
    /**
112
     * @brief   Current SSSP stage of the system.
113
     */
114
    aos_ssspstage_t stage;
115
  } sssp;
116 e545e620 Thomas Schöpping
117
  /**
118 ba516b61 Thomas Schöpping
   * @brief   System I/O stream.
119
   */
120
  AosIOStream iostream;
121
122
  /**
123 e545e620 Thomas Schöpping
   * @brief   Event structure.
124
   */
125
  struct {
126
127
    /**
128 6b53f6bf Thomas Schöpping
     * @brief   I/O event source.
129 e545e620 Thomas Schöpping
     */
130 6b53f6bf Thomas Schöpping
    event_source_t io;
131 e545e620 Thomas Schöpping
132
    /**
133 6b53f6bf Thomas Schöpping
     * @brief   OS event source.
134 e545e620 Thomas Schöpping
     */
135 6b53f6bf Thomas Schöpping
    event_source_t os;
136 e545e620 Thomas Schöpping
  } events;
137
138
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
139
  /**
140
   * @brief   Pointer to the shell object.
141
   */
142 6b53f6bf Thomas Schöpping
  aos_shell_t shell;
143 e545e620 Thomas Schöpping
#endif
144
145
} aos_system_t;
146
147
/**
148
 * @brief   Global system object.
149
 */
150
extern aos_system_t aos;
151
152 ba516b61 Thomas Schöpping
/**
153
 * @brief   Printf function that uses the default system I/O stream.
154
 */
155
#define aosprintf(fmt, ...)                     chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__)
156
157 e545e620 Thomas Schöpping
#ifdef __cplusplus
158
extern "C" {
159
#endif
160 6b53f6bf Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true)
161
  void aosSysInit(const char* shellPrompt);
162
#else
163
  void aosSysInit(void);
164
#endif
165 e545e620 Thomas Schöpping
  void aosSysStart(void);
166
  eventmask_t aosSysSsspStartupOsInitSyncCheck(event_listener_t* syncEvtListener);
167
  void aosSysGetUptimeX(aos_timestamp_t* ut);
168 8399aeae Thomas Schöpping
  void aosSysGetDateTime(struct tm* dt);
169
  void aosSysSetDateTime(struct tm* dt);
170 e545e620 Thomas Schöpping
  void aosSysShutdownInit(aos_shutdown_t shutdown);
171
  void aosSysStop(void);
172
  void aosSysDeinit(void);
173
  void aosSysShutdownFinal(EXTDriver* extDrv, aos_shutdown_t shutdown);
174
#ifdef __cplusplus
175
}
176
#endif
177
178
/**
179
 * @brief   Retrieves the system uptime.
180
 *
181
 * @param[out] ut   The system uptime.
182
 */
183
static inline void aosSysGetUptime(aos_timestamp_t* ut)
184
{
185
  aosDbgCheck(ut != NULL);
186
187
  chSysLock();
188
  aosSysGetUptimeX(ut);
189
  chSysUnlock();
190
191
  return;
192
}
193
194
#endif /* _AMIROOS_SYSTEM_H_ */