amiro-os / core / inc / aos_time.h @ 10b520a8
History | View | Annotate | Download (16.358 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 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_time.h
|
21 |
* @brief Time related constants and data types.
|
22 |
*
|
23 |
* @addtogroup aos_time
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#ifndef AMIROOS_TIME_H
|
28 |
#define AMIROOS_TIME_H
|
29 |
|
30 |
#include <amiroos.h> |
31 |
|
32 |
/******************************************************************************/
|
33 |
/* CONSTANTS */
|
34 |
/******************************************************************************/
|
35 |
|
36 |
#define MICROSECONDS_PER_MICROSECOND ((uint8_t) (1)) |
37 |
#define MILLISECONDS_PER_MILLISECOND ((uint8_t) (1)) |
38 |
#define SECONDS_PER_SECOND ((uint8_t) (1)) |
39 |
#define MINUTES_PER_MINUTE ((uint8_t) (1)) |
40 |
#define HOURS_PER_HOUR ((uint8_t) (1)) |
41 |
#define DAYS_PER_DAY ((uint8_t) (1)) |
42 |
#define WEEKS_PER_WEEK ((uint8_t) (1)) |
43 |
#define MONTHS_PER_MONTH ((uint8_t) (1)) |
44 |
#define YEARS_PER_YEAR ((uint8_t) (1)) |
45 |
#define DECADES_PER_DECADE ((uint8_t) (1)) |
46 |
#define CENTURIES_PER_CENTURY ((uint8_t) (1)) |
47 |
#define MILLENIUMS_PER_MILLENIUM ((uint8_t) (1)) |
48 |
|
49 |
#define MICROSECONDS_PER_MILLISECOND ((uint16_t) (1000)) |
50 |
#define MILLISECONDS_PER_SECOND ((uint16_t) (1000)) |
51 |
#define SECONDS_PER_MINUTE ((uint8_t) (60)) |
52 |
#define MINUTES_PER_HOUR ((uint8_t) (60)) |
53 |
#define HOURS_PER_DAY ((uint8_t) (24)) |
54 |
#define DAYS_PER_WEEK ((uint8_t) (7)) |
55 |
#define DAYS_PER_YEAR ((float) (365.25f)) |
56 |
#define MONTHS_PER_YEAR ((uint8_t) (12)) |
57 |
#define YEARS_PER_DECADE ((uint8_t) (10)) |
58 |
#define DECADES_PER_CENTURY ((uint8_t) (10)) |
59 |
#define CENTURIES_PER_MILLENIUM ((uint8_t) (10)) |
60 |
|
61 |
#define MICROSECONDS_PER_SECOND ((uint32_t) ((uint32_t)MICROSECONDS_PER_MILLISECOND * (uint32_t)MILLISECONDS_PER_SECOND))
|
62 |
#define MILLISECONDS_PER_MINUTE ((uint16_t) ((uint16_t)MILLISECONDS_PER_SECOND * (uint16_t)SECONDS_PER_MINUTE))
|
63 |
#define SECONDS_PER_HOUR ((uint16_t) ((uint16_t)SECONDS_PER_MINUTE * (uint16_t)MINUTES_PER_HOUR))
|
64 |
#define MINUTES_PER_DAY ((uint16_t) ((uint16_t)MINUTES_PER_HOUR * (uint16_t)HOURS_PER_DAY))
|
65 |
#define HOURS_PER_WEEK ((uint8_t) (HOURS_PER_DAY * DAYS_PER_WEEK))
|
66 |
#define HOURS_PER_YEAR ((uint16_t) ((float)HOURS_PER_DAY * DAYS_PER_YEAR)) |
67 |
#define DAYS_PER_MONTH ((float) (DAYS_PER_YEAR / (float)MONTHS_PER_YEAR)) |
68 |
#define DAYS_PER_DECADE ((float) (DAYS_PER_YEAR * (float)YEARS_PER_DECADE)) |
69 |
#define WEEKS_PER_YEAR ((float) (DAYS_PER_YEAR / (float)DAYS_PER_WEEK)) |
70 |
#define MONTHS_PER_DECADE ((uint8_t) (MONTHS_PER_YEAR * YEARS_PER_DECADE))
|
71 |
#define YEARS_PER_CENTURY ((uint8_t) (YEARS_PER_DECADE * DECADES_PER_CENTURY))
|
72 |
#define DECADES_PER_MILLENIUM ((uint8_t) (DECADES_PER_CENTURY * CENTURIES_PER_MILLENIUM))
|
73 |
|
74 |
#define MICROSECONDS_PER_MINUTE ((uint32_t) ((uint32_t)MICROSECONDS_PER_MILLISECOND * (uint32_t)MILLISECONDS_PER_MINUTE))
|
75 |
#define MILLISECONDS_PER_HOUR ((uint32_t) ((uint32_t)MILLISECONDS_PER_SECOND * (uint32_t)SECONDS_PER_HOUR))
|
76 |
#define SECONDS_PER_DAY ((uint32_t) ((uint32_t)SECONDS_PER_MINUTE * (uint32_t)MINUTES_PER_DAY))
|
77 |
#define MINUTES_PER_WEEK ((uint16_t) ((uint16_t)MINUTES_PER_HOUR * (uint16_t)HOURS_PER_WEEK))
|
78 |
#define HOURS_PER_MONTH ((float) ((float)HOURS_PER_DAY * DAYS_PER_MONTH)) |
79 |
#define HOURS_PER_DECADE ((uint32_t) ((float)HOURS_PER_DAY * DAYS_PER_DECADE)) |
80 |
#define MINUTES_PER_YEAR ((uint32_t) ((uint32_t)MINUTES_PER_HOUR * (uint32_t)HOURS_PER_YEAR))
|
81 |
#define DAYS_PER_CENTURY ((uint16_t) (DAYS_PER_YEAR * (float)YEARS_PER_CENTURY)) |
82 |
#define WEEKS_PER_MONTH ((float) (DAYS_PER_MONTH / (float)DAYS_PER_WEEK)) |
83 |
#define WEEKS_PER_DECADE ((float) (DAYS_PER_DECADE / (float)DAYS_PER_WEEK)) |
84 |
#define MONTHS_PER_CENTURY ((uint16_t) ((uint16_t)MONTHS_PER_YEAR * (uint16_t)YEARS_PER_CENTURY))
|
85 |
#define YEARS_PER_MILLENIUM ((uint16_t) ((uint16_t)YEARS_PER_DECADE * (uint16_t)DECADES_PER_MILLENIUM))
|
86 |
|
87 |
#define MICROSECONDS_PER_HOUR ((uint32_t) ((uint32_t)MICROSECONDS_PER_MILLISECOND * MILLISECONDS_PER_HOUR))
|
88 |
#define MILLISECONDS_PER_DAY ((uint32_t) ((uint32_t)MILLISECONDS_PER_SECOND * SECONDS_PER_DAY))
|
89 |
#define SECONDS_PER_WEEK ((uint32_t) (SECONDS_PER_MINUTE * (uint32_t)MINUTES_PER_WEEK))
|
90 |
#define SECONDS_PER_YEAR ((uint32_t) (SECONDS_PER_MINUTE * MINUTES_PER_YEAR))
|
91 |
#define MINUTES_PER_MONTH ((uint16_t) ((float)MINUTES_PER_HOUR * HOURS_PER_MONTH)) |
92 |
#define MINUTES_PER_DECADE ((uint32_t) ((uint32_t)MINUTES_PER_HOUR * HOURS_PER_DECADE))
|
93 |
#define HOURS_PER_CENTURY ((uint32_t) ((uint32_t)HOURS_PER_DAY * (uint32_t)DAYS_PER_CENTURY))
|
94 |
#define DAYS_PER_MILLENIUM ((uint32_t) (DAYS_PER_YEAR * (float)YEARS_PER_MILLENIUM)) |
95 |
#define WEEKS_PER_CENTURY ((float) ((float)DAYS_PER_CENTURY / (float)DAYS_PER_WEEK)) |
96 |
#define MONTHS_PER_MILLENIUM ((uint16_t) ((uint16_t)MONTHS_PER_YEAR * YEARS_PER_MILLENIUM))
|
97 |
|
98 |
#define MICROSECONDS_PER_DAY ((uint64_t) ((uint64_t)MICROSECONDS_PER_MILLISECOND * (uint64_t)MILLISECONDS_PER_DAY))
|
99 |
#define MILLISECONDS_PER_WEEK ((uint32_t) ((uint32_t)MILLISECONDS_PER_SECOND * SECONDS_PER_WEEK))
|
100 |
#define MILLISECONDS_PER_YEAR ((uint64_t) ((uint64_t)MILLISECONDS_PER_SECOND * (uint64_t)SECONDS_PER_YEAR))
|
101 |
#define SECONDS_PER_MONTH ((uint32_t) ((uint32_t)SECONDS_PER_MINUTE * (uint32_t)MINUTES_PER_MONTH))
|
102 |
#define SECONDS_PER_DECADE ((uint32_t) ((uint32_t)SECONDS_PER_MINUTE * MINUTES_PER_DECADE))
|
103 |
#define MINUTES_PER_CENTURY ((uint32_t) ((uint32_t)MINUTES_PER_HOUR * HOURS_PER_CENTURY))
|
104 |
#define HOURS_PER_MILLENIUM ((uint32_t) ((uint32_t)HOURS_PER_DAY * DAYS_PER_MILLENIUM))
|
105 |
#define WEEKS_PER_MILLENIUM ((float) ((float)DAYS_PER_MILLENIUM / (float)DAYS_PER_WEEK)) |
106 |
|
107 |
#define MICROSECONDS_PER_WEEK ((uint64_t) ((uint64_t)MICROSECONDS_PER_MILLISECOND * (uint64_t)MILLISECONDS_PER_WEEK))
|
108 |
#define MICROSECONDS_PER_YEAR ((uint64_t) ((uint64_t)MICROSECONDS_PER_MILLISECOND * MILLISECONDS_PER_YEAR))
|
109 |
#define MILLISECONDS_PER_MONTH ((uint32_t) ((uint32_t)MILLISECONDS_PER_SECOND * SECONDS_PER_MONTH))
|
110 |
#define MILLISECONDS_PER_DECADE ((uint64_t) ((uint64_t)MILLISECONDS_PER_SECOND * (uint64_t)SECONDS_PER_DECADE))
|
111 |
#define SECONDS_PER_CENTURY ((uint32_t) (SECONDS_PER_MINUTE * MINUTES_PER_CENTURY))
|
112 |
#define MINUTES_PER_MILLENIUM ((uint32_t) ((uint32_t)MINUTES_PER_HOUR * HOURS_PER_MILLENIUM))
|
113 |
|
114 |
#define MICROSECONDS_PER_MONTH ((uint64_t) ((uint64_t)MICROSECONDS_PER_MILLISECOND * (uint64_t)MILLISECONDS_PER_MONTH))
|
115 |
#define MICROSECONDS_PER_DECADE ((uint64_t) ((uint64_t)MICROSECONDS_PER_MILLISECOND * MILLISECONDS_PER_DECADE))
|
116 |
#define MILLISECONDS_PER_CENTURY ((uint64_t) ((uint64_t)MILLISECONDS_PER_SECOND * (uint64_t)SECONDS_PER_CENTURY))
|
117 |
#define SECONDS_PER_MILLENIUM ((uint64_t) ((uint64_t)SECONDS_PER_MINUTE * (uint64_t)MINUTES_PER_MILLENIUM))
|
118 |
|
119 |
#define MICROSECONDS_PER_CENTURY ((uint64_t) ((uint64_t)MICROSECONDS_PER_MILLISECOND * MILLISECONDS_PER_CENTURY))
|
120 |
#define MILLISECONDS_PER_MILLENIUM ((uint64_t) ((uint64_t)MILLISECONDS_PER_SECOND * SECONDS_PER_MILLENIUM))
|
121 |
|
122 |
#define MICROSECONDS_PER_MILLENIUM ((uint64_t) ((uint64_t)MICROSECONDS_PER_MILLISECOND * MILLISECONDS_PER_MILLENIUM))
|
123 |
|
124 |
#define MILLISECONDS_PER_MICROSECOND ((float)MILLISECONDS_PER_MILLISECOND / (float)MICROSECONDS_PER_MILLISECOND) |
125 |
|
126 |
#define SECONDS_PER_MICROSECOND ((float)SECONDS_PER_SECOND / (float)MICROSECONDS_PER_SECOND) |
127 |
#define SECONDS_PER_MILLISECOND ((float)SECONDS_PER_SECOND / (float)MILLISECONDS_PER_SECOND) |
128 |
|
129 |
#define MINUTES_PER_MICROSECOND ((float)MINUTES_PER_MINUTE / (float)MICROSECONDS_PER_MINUTE) |
130 |
#define MINUTES_PER_MILLISECOND ((float)MINUTES_PER_MINUTE / (float)MILLISECONDS_PER_MINUTE) |
131 |
#define MINUTES_PER_SECOND ((float)MINUTES_PER_MINUTE / (float)SECONDS_PER_MINUTE) |
132 |
|
133 |
#define HOURS_PER_MICROSECOND ((float)HOURS_PER_HOUR / (float)MICROSECONDS_PER_HOUR) |
134 |
#define HOURS_PER_MILLISECOND ((float)HOURS_PER_HOUR / (float)MILLISECONDS_PER_HOUR) |
135 |
#define HOURS_PER_SECOND ((float)HOURS_PER_HOUR / (float)SECONDS_PER_HOUR) |
136 |
#define HOURS_PER_MINUTE ((float)HOURS_PER_HOUR / (float)MINUTES_PER_HOUR) |
137 |
|
138 |
#define DAYS_PER_MICROSECOND ((float)DAYS_PER_DAY / (float)MICROSECONDS_PER_DAY) |
139 |
#define DAYS_PER_MILLISECOND ((float)DAYS_PER_DAY / (float)MILLISECONDS_PER_DAY) |
140 |
#define DAYS_PER_SECOND ((float)DAYS_PER_DAY / (float)SECONDS_PER_DAY) |
141 |
#define DAYS_PER_MINUTE ((float)DAYS_PER_DAY / (float)MINUTES_PER_DAY) |
142 |
#define DAYS_PER_HOUR ((float)DAYS_PER_DAY / (float)HOURS_PER_DAY) |
143 |
|
144 |
#define WEEKS_PER_MICROSECOND ((float)WEEKS_PER_WEEK / (float)MICROSECONDS_PER_WEEK) |
145 |
#define WEEKS_PER_MILLISECOND ((float)WEEKS_PER_WEEK / (float)MILLISECONDS_PER_WEEK) |
146 |
#define WEEKS_PER_SECOND ((float)WEEKS_PER_WEEK / (float)SECONDS_PER_WEEK) |
147 |
#define WEEKS_PER_MINUTE ((float)WEEKS_PER_WEEK / (float)MINUTES_PER_WEEK) |
148 |
#define WEEKS_PER_HOUR ((float)WEEKS_PER_WEEK / (float)HOURS_PER_WEEK) |
149 |
#define WEEKS_PER_DAY ((float)WEEKS_PER_WEEK / (float)DAYS_PER_WEEK) |
150 |
|
151 |
#define MONTHS_PER_MICROSECOND ((float)MONTHS_PER_MONTH / (float)MICROSECONDS_PER_MONTH) |
152 |
#define MONTHS_PER_MILLISECOND ((float)MONTHS_PER_MONTH / (float)MILLISECONDS_PER_MONTH) |
153 |
#define MONTHS_PER_SECOND ((float)MONTHS_PER_MONTH / (float)SECONDS_PER_MONTH) |
154 |
#define MONTHS_PER_MINUTE ((float)MONTHS_PER_MONTH / (float)MINUTES_PER_MONTH) |
155 |
#define MONTHS_PER_HOUR ((float)MONTHS_PER_MONTH / (float)HOURS_PER_MONTH) |
156 |
#define MONTHS_PER_DAY ((float)MONTHS_PER_MONTH / (float)DAYS_PER_MONTH) |
157 |
#define MONTHS_PER_WEEK ((float)MONTHS_PER_MONTH / (float)WEEKS_PER_MONTH) |
158 |
|
159 |
#define YEARS_PER_MICROSECOND ((float)YEARS_PER_YEAR / (float)MICROSECONDS_PER_YEAR) |
160 |
#define YEARS_PER_MILLISECOND ((float)YEARS_PER_YEAR / (float)MILLISECONDS_PER_YEAR) |
161 |
#define YEARS_PER_SECOND ((float)YEARS_PER_YEAR / (float)SECONDS_PER_YEAR) |
162 |
#define YEARS_PER_MINUTE ((float)YEARS_PER_YEAR / (float)MINUTES_PER_YEAR) |
163 |
#define YEARS_PER_HOUR ((float)YEARS_PER_YEAR / (float)HOURS_PER_YEAR) |
164 |
#define YEARS_PER_DAY ((float)YEARS_PER_YEAR / (float)DAYS_PER_YEAR) |
165 |
#define YEARS_PER_WEEK ((float)YEARS_PER_YEAR / (float)WEEKS_PER_YEAR) |
166 |
#define YEARS_PER_MONTH ((float)YEARS_PER_YEAR / (float)MONTHS_PER_YEAR) |
167 |
|
168 |
#define DECADES_PER_MICROSECOND ((float)DECADES_PER_DECADE / (float)MICROSECONDS_PER_DECADE) |
169 |
#define DECADES_PER_MILLISECOND ((float)DECADES_PER_DECADE / (float)MILLISECONDS_PER_DECADE) |
170 |
#define DECADES_PER_SECOND ((float)DECADES_PER_DECADE / (float)SECONDS_PER_DECADE) |
171 |
#define DECADES_PER_MINUTE ((float)DECADES_PER_DECADE / (float)MINUTES_PER_DECADE) |
172 |
#define DECADES_PER_HOUR ((float)DECADES_PER_DECADE / (float)HOURS_PER_DECADE) |
173 |
#define DECADES_PER_DAY ((float)DECADES_PER_DECADE / (float)DAYS_PER_DECADE) |
174 |
#define DECADES_PER_WEEK ((float)DECADES_PER_DECADE / (float)WEEKS_PER_DECADE) |
175 |
#define DECADES_PER_MONTH ((float)DECADES_PER_DECADE / (float)MONTHS_PER_DECADE) |
176 |
#define DECADES_PER_YEAR ((float)DECADES_PER_DECADE / (float)YEARS_PER_DECADE) |
177 |
|
178 |
#define CENTURIES_PER_MICROSECOND ((float)CENTURIES_PER_CENTURY / (float)MICROSECONDS_PER_CENTURY) |
179 |
#define CENTURIES_PER_MILLISECOND ((float)CENTURIES_PER_CENTURY / (float)MILLISECONDS_PER_CENTURY) |
180 |
#define CENTURIES_PER_SECOND ((float)CENTURIES_PER_CENTURY / (float)SECONDS_PER_CENTURY) |
181 |
#define CENTURIES_PER_MINUTE ((float)CENTURIES_PER_CENTURY / (float)MINUTES_PER_CENTURY) |
182 |
#define CENTURIES_PER_HOUR ((float)CENTURIES_PER_CENTURY / (float)HOURS_PER_CENTURY) |
183 |
#define CENTURIES_PER_DAY ((float)CENTURIES_PER_CENTURY / (float)DAYS_PER_CENTURY) |
184 |
#define CENTURIES_PER_WEEK ((float)CENTURIES_PER_CENTURY / (float)WEEKS_PER_CENTURY) |
185 |
#define CENTURIES_PER_MONTH ((float)CENTURIES_PER_CENTURY / (float)MONTHS_PER_CENTURY) |
186 |
#define CENTURIES_PER_YEAR ((float)CENTURIES_PER_CENTURY / (float)YEARS_PER_CENTURY) |
187 |
#define CENTURIES_PER_DECADE ((float)CENTURIES_PER_CENTURY / (float)DECADES_PER_CENTURY) |
188 |
|
189 |
#define MILLENIUMS_PER_MICROSECOND ((float)MILLENIUMS_PER_MILLENIUM / (float)MICROSECONDS_PER_MILLENIUM) |
190 |
#define MILLENIUMS_PER_MILLISECOND ((float)MILLENIUMS_PER_MILLENIUM / (float)MILLISECONDS_PER_MILLENIUM) |
191 |
#define MILLENIUMS_PER_SECOND ((float)MILLENIUMS_PER_MILLENIUM / (float)SECONDS_PER_MILLENIUM) |
192 |
#define MILLENIUMS_PER_MINUTE ((float)MILLENIUMS_PER_MILLENIUM / (float)MINUTES_PER_MILLENIUM) |
193 |
#define MILLENIUMS_PER_HOUR ((float)MILLENIUMS_PER_MILLENIUM / (float)HOURS_PER_MILLENIUM) |
194 |
#define MILLENIUMS_PER_DAY ((float)MILLENIUMS_PER_MILLENIUM / (float)DAYS_PER_MILLENIUM) |
195 |
#define MILLENIUMS_PER_WEEK ((float)MILLENIUMS_PER_MILLENIUM / (float)WEEKS_PER_MILLENIUM) |
196 |
#define MILLENIUMS_PER_MONTH ((float)MILLENIUMS_PER_MILLENIUM / (float)MONTHS_PER_MILLENIUM) |
197 |
#define MILLENIUMS_PER_YEAR ((float)MILLENIUMS_PER_MILLENIUM / (float)YEARS_PER_MILLENIUM) |
198 |
#define MILLENIUMS_PER_DECADE ((float)MILLENIUMS_PER_MILLENIUM / (float)DECADES_PER_MILLENIUM) |
199 |
#define MILLENIUMS_PER_CENTURY ((float)MILLENIUMS_PER_MILLENIUM / (float)CENTURIES_PER_MILLENIUM) |
200 |
|
201 |
/******************************************************************************/
|
202 |
/* SETTINGS */
|
203 |
/******************************************************************************/
|
204 |
|
205 |
/******************************************************************************/
|
206 |
/* CHECKS */
|
207 |
/******************************************************************************/
|
208 |
|
209 |
/******************************************************************************/
|
210 |
/* DATA STRUCTURES AND TYPES */
|
211 |
/******************************************************************************/
|
212 |
|
213 |
/**
|
214 |
* @brief Generic time to represent long time frames at high precision.
|
215 |
* @note By definition the temporal resolution is 1us.
|
216 |
*/
|
217 |
typedef uint64_t aos_timestamp_t;
|
218 |
|
219 |
/**
|
220 |
* @brief generic time to represent medium length time frames at high precision.
|
221 |
* @note By definition the temporal resolution is 1us.
|
222 |
*/
|
223 |
typedef uint32_t aos_interval_t;
|
224 |
|
225 |
/**
|
226 |
* @brief Generic time to represent long time frames at high precision.
|
227 |
* @note By definition the temporal resolution is 1us.
|
228 |
*/
|
229 |
typedef aos_timestamp_t aos_longinterval_t;
|
230 |
|
231 |
/******************************************************************************/
|
232 |
/* MACROS */
|
233 |
/******************************************************************************/
|
234 |
|
235 |
/******************************************************************************/
|
236 |
/* EXTERN DECLARATIONS */
|
237 |
/******************************************************************************/
|
238 |
|
239 |
#ifdef __cplusplus
|
240 |
extern "C" { |
241 |
#endif
|
242 |
uint8_t aosTimeDayOfWeekFromDate(const uint16_t day, const uint8_t month, const uint16_t year); |
243 |
#ifdef __cplusplus
|
244 |
} |
245 |
#endif
|
246 |
|
247 |
/******************************************************************************/
|
248 |
/* INLINE FUNCTIONS */
|
249 |
/******************************************************************************/
|
250 |
|
251 |
#endif /* AMIROOS_TIME_H */ |
252 |
|
253 |
/** @} */
|