Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.143 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3 84f0ce9e Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 e545e620 Thomas Schöpping

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 53710ca3 Marc Rothmann
/**
20
 * @file    aos_system.h
21
 * @brief   System macros and structures.
22
 *
23
 * @addtogroup aos_system
24
 * @{
25
 */
26
27 6ff06bbf Thomas Schöpping
#ifndef AMIROOS_SYSTEM_H
28
#define AMIROOS_SYSTEM_H
29 e545e620 Thomas Schöpping
30 3940ba8a Thomas Schöpping
#include <amiroos.h>
31 e545e620 Thomas Schöpping
#include <chprintf.h>
32
33 f3ac1c96 Thomas Schöpping
/******************************************************************************/
34
/* CONSTANTS                                                                  */
35
/******************************************************************************/
36
37 e545e620 Thomas Schöpping
/**
38 ba516b61 Thomas Schöpping
 * @brief   Resolution of the system time measurement.
39 e545e620 Thomas Schöpping
 */
40 ba516b61 Thomas Schöpping
#define AOS_SYSTEM_TIME_RESOLUTION              ((MICROSECONDS_PER_SECOND + CH_CFG_ST_FREQUENCY - 1) / CH_CFG_ST_FREQUENCY)
41 e545e620 Thomas Schöpping
42
/**
43 cda14729 Thomas Schöpping
 * @brief   System event flag mask for shutdown related events.
44 e545e620 Thomas Schöpping
 */
45 cda14729 Thomas Schöpping
#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 e545e620 Thomas Schöpping
52
/**
53
 * @brief   System event flag which is emitted when a shutdown to transportation mode was initiated.
54
 */
55 cda14729 Thomas Schöpping
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_TRANSPORTATION ((eventflags_t)(1 << 1))
56 e545e620 Thomas Schöpping
57
/**
58
 * @brief   System event flag which is emitted when a shutdown to deepsleep mode was initiated.
59
 */
60 cda14729 Thomas Schöpping
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_DEEPSLEEP ((eventflags_t)(1 << 2))
61 e545e620 Thomas Schöpping
62
/**
63
 * @brief   System event flag which is emitted when a shutdown to hibernate mode was initiated.
64
 */
65 cda14729 Thomas Schöpping
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_HIBERNATE ((eventflags_t)(1 << 3))
66 e545e620 Thomas Schöpping
67
/**
68
 * @brief   System event flag which is emitted when a system restart was initiated.
69
 */
70 cda14729 Thomas Schöpping
#define AOS_SYSTEM_EVENTFLAGS_SHUTDOWN_RESTART ((eventflags_t)(1 << 4))
71 f3ac1c96 Thomas Schöpping
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 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
90 f3ac1c96 Thomas Schöpping
  AOS_SHUTDOWN_PASSIVE,         /**< Passive shutdown (initiated by another module). */
91 cda14729 Thomas Schöpping
#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 f3ac1c96 Thomas Schöpping
  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 cda14729 Thomas Schöpping
#endif /* (AMIROOS_CFG_BOOTLOADER == AOS_BOOTLOADER_AMiRoBLT) */
101 f3ac1c96 Thomas Schöpping
} aos_shutdown_t;
102
103 933df08e Thomas Schöpping
/**
104 e545e620 Thomas Schöpping
 * @brief   AMiRo-OS base system structure.
105
 */
106
typedef struct aos_system {
107
108
  /**
109 ba516b61 Thomas Schöpping
   * @brief   System I/O stream.
110
   */
111
  AosIOStream iostream;
112
113
  /**
114 e545e620 Thomas Schöpping
   * @brief   Event structure.
115
   */
116
  struct {
117
118
    /**
119 cda14729 Thomas Schöpping
     * @brief   GPIO event source.
120 e545e620 Thomas Schöpping
     */
121 cda14729 Thomas Schöpping
    event_source_t gpio;
122 e545e620 Thomas Schöpping
123
    /**
124 6b53f6bf Thomas Schöpping
     * @brief   OS event source.
125 e545e620 Thomas Schöpping
     */
126 6b53f6bf Thomas Schöpping
    event_source_t os;
127 e545e620 Thomas Schöpping
  } events;
128
129 cda14729 Thomas Schöpping
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
130 7de0cc90 Thomas Schöpping
131 e545e620 Thomas Schöpping
  /**
132
   * @brief   Pointer to the shell object.
133
   */
134 6b53f6bf Thomas Schöpping
  aos_shell_t shell;
135 7de0cc90 Thomas Schöpping
136 cda14729 Thomas Schöpping
#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 e545e620 Thomas Schöpping
147
} aos_system_t;
148
149 f3ac1c96 Thomas Schöpping
/******************************************************************************/
150
/* MACROS                                                                     */
151
/******************************************************************************/
152 e545e620 Thomas Schöpping
153 ba516b61 Thomas Schöpping
/**
154
 * @brief   Printf function that uses the default system I/O stream.
155 933df08e Thomas Schöpping
 *
156
 * @param[in] fmt   Formatted string to print.
157 ba516b61 Thomas Schöpping
 */
158
#define aosprintf(fmt, ...)                     chprintf((BaseSequentialStream*)&aos.iostream, fmt, ##__VA_ARGS__)
159
160 f3ac1c96 Thomas Schöpping
/******************************************************************************/
161
/* EXTERN DECLARATIONS                                                        */
162
/******************************************************************************/
163
164
/**
165
 * @brief   Global system object.
166
 */
167
extern aos_system_t aos;
168
169 7de0cc90 Thomas Schöpping
#if defined(__cplusplus)
170 e545e620 Thomas Schöpping
extern "C" {
171 7de0cc90 Thomas Schöpping
#endif /* defined(__cplusplus) */
172 6b53f6bf Thomas Schöpping
  void aosSysInit(const char* shellPrompt);
173 e545e620 Thomas Schöpping
  void aosSysStart(void);
174 c218345a Thomas Schöpping
  void aosSysStartUptimeS(void);
175 e545e620 Thomas Schöpping
  void aosSysGetUptimeX(aos_timestamp_t* ut);
176 cda14729 Thomas Schöpping
#if (HAL_USE_RTC == TRUE) || defined(__DOXYGEN__)
177 8399aeae Thomas Schöpping
  void aosSysGetDateTime(struct tm* dt);
178
  void aosSysSetDateTime(struct tm* dt);
179 7de0cc90 Thomas Schöpping
#endif /* (HAL_USE_RTC == TRUE) */
180 e545e620 Thomas Schöpping
  void aosSysShutdownInit(aos_shutdown_t shutdown);
181
  void aosSysStop(void);
182
  void aosSysDeinit(void);
183 cda14729 Thomas Schöpping
#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 7de0cc90 Thomas Schöpping
#if defined(__cplusplus)
190 e545e620 Thomas Schöpping
}
191 7de0cc90 Thomas Schöpping
#endif /* defined(__cplusplus) */
192 e545e620 Thomas Schöpping
193 f3ac1c96 Thomas Schöpping
/******************************************************************************/
194
/* INLINE FUNCTIONS                                                           */
195
/******************************************************************************/
196
197 e545e620 Thomas Schöpping
/**
198
 * @brief   Retrieves the system uptime.
199
 *
200 acc97cbf Thomas Schöpping
 * @param[out] ut   Pointer to the system uptime.
201 e545e620 Thomas Schöpping
 */
202 9ff01927 Thomas Schöpping
static inline void aosSysGetUptime(aos_timestamp_t* ut)
203
{
204
  chSysLock();
205
  aosSysGetUptimeX(ut);
206
  chSysUnlock();
207 e545e620 Thomas Schöpping
}
208
209 6ff06bbf Thomas Schöpping
#endif /* AMIROOS_SYSTEM_H */
210 53710ca3 Marc Rothmann
211
/** @} */