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