Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.143 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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 <amiroos.h>
31
#include <chprintf.h>
32

    
33
/******************************************************************************/
34
/* CONSTANTS                                                                  */
35
/******************************************************************************/
36

    
37
/**
38
 * @brief   Resolution of the system time measurement.
39
 */
40
#define AOS_SYSTEM_TIME_RESOLUTION              ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY)
41

    
42
/**
43
 * @brief   System event flag mask for shutdown related events.
44
 */
45
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_MASK     ((eventflags_t)0x1F)
46

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

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

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

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

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

    
72
/******************************************************************************/
73
/* SETTINGS                                                                   */
74
/******************************************************************************/
75

    
76
/******************************************************************************/
77
/* CHECKS                                                                     */
78
/******************************************************************************/
79

    
80
/******************************************************************************/
81
/* DATA STRUCTURES AND TYPES                                                  */
82
/******************************************************************************/
83

    
84
/**
85
 * @brief   Enumerator to identify shutdown types.
86
 */
87
typedef enum aos_shutdown {
88
  AOS_SHUTDOWN_NONE,            /**< Default value if no shutdown action was initiated */
89
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
90
  AOS_SHUTDOWN_PASSIVE,         /**< Passive shutdown (initiated by another module). */
91
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
92
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) || defined (__DOXYGEN__)
93
  AOS_SHUTDOWN_ACTIVE,          /**< Active shutdown. */
94
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_NONE) */
95
#if (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) || defined (__DOXYGEN__)
96
  AOS_SHUTDOWN_HIBERNATE,       /**< Active shutdown to hibernate mode. */
97
  AOS_SHUTDOWN_DEEPSLEEP,       /**< Active shutdown to deepsleep mode. */
98
  AOS_SHUTDOWN_TRANSPORTATION,  /**< Active shutdown to transportation mode. */
99
  AOS_SHUTDOWN_RESTART,         /**< Active saystem restart request. */
100
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) */
101
} aos_shutdown_t;
102

    
103
/**
104
 * @brief   AMiRo-OS base system structure.
105
 */
106
typedef struct aos_system {
107

    
108
  /**
109
   * @brief   System I/O stream.
110
   */
111
  AosIOStream iostream;
112

    
113
  /**
114
   * @brief   Event structure.
115
   */
116
  struct {
117

    
118
    /**
119
     * @brief   GPIO event source.
120
     */
121
    event_source_t gpio;
122

    
123
    /**
124
     * @brief   OS event source.
125
     */
126
    event_source_t os;
127
  } events;
128

    
129
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
130

    
131
  /**
132
   * @brief   Pointer to the shell object.
133
   */
134
  aos_shell_t shell;
135

    
136
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
137

    
138
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
139

    
140
  /**
141
   * @brief   SSSP relevant data.
142
   */
143
  aos_ssspdata_t sssp;
144

    
145
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
146

    
147
} aos_system_t;
148

    
149
/******************************************************************************/
150
/* MACROS                                                                     */
151
/******************************************************************************/
152

    
153
/**
154
 * @brief   Printf function that uses the default system I/O stream.
155
 *
156
 * @param[in] fmt   Formatted string to print.
157
 */
158
#define aosprintf(fmt, ...)                     chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__)
159

    
160
/******************************************************************************/
161
/* EXTERN DECLARATIONS                                                        */
162
/******************************************************************************/
163

    
164
/**
165
 * @brief   Global system object.
166
 */
167
extern aos_system_t aos;
168

    
169
#if defined(__cplusplus)
170
extern "C" {
171
#endif /* defined(__cplusplus) */
172
  void aosSysInit(const char* shellPrompt);
173
  void aosSysStart(void);
174
  void aosSysStartUptimeS(void);
175
  void aosSysGetUptimeX(aos_timestamp_t* ut);
176
#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
177
  void aosSysGetDateTime(struct tm* dt);
178
  void aosSysSetDateTime(struct tm* dt);
179
#endif /* (HAL_USE_RTC == TRUE) */
180
  void aosSysShutdownInit(aos_shutdown_t shutdown);
181
  void aosSysStop(void);
182
  void aosSysDeinit(void);
183
#if ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) ||               \
184
    ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) || \
185
    defined(__DOXYGEN__)
186
  void aosSysShutdownToBootloader(aos_shutdown_t shutdown);
187
#endif /* ((AMIROOS_CFG_SSSP_ENABLE == true) && (AMIROOS_CFG_SSSP_SHUTDOWN != true)) || ((AMIROOS_CFG_SSSP_ENABLE != true) && (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT)) */
188
  palcallback_t aosSysGetStdGpioCallback(void);
189
#if defined(__cplusplus)
190
}
191
#endif /* defined(__cplusplus) */
192

    
193
/******************************************************************************/
194
/* INLINE FUNCTIONS                                                           */
195
/******************************************************************************/
196

    
197
/**
198
 * @brief   Retrieves the system uptime.
199
 *
200
 * @param[out] ut   Pointer to the system uptime.
201
 */
202
static inline void aosSysGetUptime(aos_timestamp_t* ut)
203
{
204
  chSysLock();
205
  aosSysGetUptimeX(ut);
206
  chSysUnlock();
207
}
208

    
209
#endif /* AMIROOS_SYSTEM_H */
210

    
211
/** @} */