Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (6.44 KB)

1
/*
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_iostream.h>
23
#include <amiro-lld.h>
24
#include <aos_shell.h>
25
#include <aos_time.h>
26
#include <chprintf.h>
27

    
28
/**
29
 * @brief   Resolution of the system time measurement.
30
 */
31
#define AOS_SYSTEM_TIME_RESOLUTION              ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY)
32

    
33
/**
34
 * @brief   System event flag which is emitted when a shutdown was initiated.
35
 */
36
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN          (eventflags_t)(1 << 0)
37

    
38
/**
39
 * @brief   System event flag which is emitted when a shutdown to transportation mode was initiated.
40
 */
41
#define AOS_SYSTEM_EVENTFLAGS_TRANSPORTATION    (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 1))
42

    
43
/**
44
 * @brief   System event flag which is emitted when a shutdown to deepsleep mode was initiated.
45
 */
46
#define AOS_SYSTEM_EVENTFLAGS_DEEPSLEEP         (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 2))
47

    
48
/**
49
 * @brief   System event flag which is emitted when a shutdown to hibernate mode was initiated.
50
 */
51
#define AOS_SYSTEM_EVENTFLAGS_HIBERNATE         (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 3))
52

    
53
/**
54
 * @brief   System event flag which is emitted when a system restart was initiated.
55
 */
56
#define AOS_SYSTEM_EVENTFLAGS_RESTART           (AOS_SYSTEM_EVENTFLAGS_SHUTDOWN | (eventflags_t)(1 << 4))
57

    
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
  /**
107
   * @brief   Current SSSP stage of the system.
108
   */
109
  aos_ssspstage_t ssspStage;
110

    
111
  /**
112
   * @brief   System I/O stream.
113
   */
114
  AosIOStream iostream;
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
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
153
  /**
154
   * @brief   Pointer to the shell object.
155
   */
156
  aos_shell_t* shell;
157
#endif
158

    
159
} aos_system_t;
160

    
161
/**
162
 * @brief   Global system object.
163
 */
164
extern aos_system_t aos;
165

    
166
/**
167
 * @brief   Printf function that uses the default system I/O stream.
168
 */
169
#define aosprintf(fmt, ...)                     chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__)
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_ */