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