Statistics
| Branch: | Tag: | Revision:

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

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