@@ -53,6 +53,9 @@ namespace Clock {
53
53
* `std::chrono::duration_cast<>()`.
54
54
*/
55
55
56
+ using Microseconds64 = std::chrono::duration<uint64_t , std::micro>;
57
+ using Microseconds32 = std::chrono::duration<uint32_t , std::micro>;
58
+
56
59
using Milliseconds64 = std::chrono::duration<uint64_t , std::milli>;
57
60
using Milliseconds32 = std::chrono::duration<uint32_t , std::milli>;
58
61
@@ -64,6 +67,19 @@ constexpr Seconds16 kZero{ 0 };
64
67
65
68
namespace Literals {
66
69
70
+ constexpr Microseconds64 operator " " _us(unsigned long long int us)
71
+ {
72
+ return Microseconds64 (us);
73
+ }
74
+ constexpr Microseconds64 operator " " _us64(unsigned long long int us)
75
+ {
76
+ return Microseconds64 (us);
77
+ }
78
+ constexpr Microseconds32 operator " " _us32(unsigned long long int us)
79
+ {
80
+ return Microseconds32 (us);
81
+ }
82
+
67
83
constexpr Milliseconds64 operator " " _ms(unsigned long long int ms)
68
84
{
69
85
return Milliseconds64 (ms);
@@ -127,6 +143,29 @@ class ClockBase
127
143
*/
128
144
Timestamp GetMonotonicTimestamp () { return GetMonotonicMilliseconds64 (); }
129
145
146
+ /* *
147
+ * Returns a monotonic system time in units of microseconds.
148
+ *
149
+ * This function returns an elapsed time in microseconds since an arbitrary, platform-defined epoch.
150
+ * The value returned is guaranteed to be ever-increasing (i.e. never wrapping or decreasing) between
151
+ * reboots of the system. Additionally, the underlying time source is guaranteed to tick
152
+ * continuously during any system sleep modes that do not entail a restart upon wake.
153
+ *
154
+ * Although some platforms may choose to return a value that measures the time since boot for the
155
+ * system, applications must *not* rely on this.
156
+ *
157
+ * Applications must not rely on the time returned by GetMonotonicMicroseconds64() actually having
158
+ * granularity finer than milliseconds.
159
+ *
160
+ * Platform implementations *must* use the same epoch for GetMonotonicMicroseconds64() and GetMonotonicMilliseconds64().
161
+ *
162
+ * Platforms *must* use an epoch such that the upper bit of a value returned by GetMonotonicMicroseconds64() is zero
163
+ * for the expected operational life of the system.
164
+ *
165
+ * @returns Elapsed time in microseconds since an arbitrary, platform-defined epoch.
166
+ */
167
+ virtual Microseconds64 GetMonotonicMicroseconds64 () = 0;
168
+
130
169
/* *
131
170
* Returns a monotonic system time in units of milliseconds.
132
171
*
@@ -138,8 +177,9 @@ class ClockBase
138
177
* Although some platforms may choose to return a value that measures the time since boot for the
139
178
* system, applications must *not* rely on this.
140
179
*
141
- * Platforms *must* use an epoch such that the upper bit of a value returned by GetMonotonicMilliseconds64() is zero
142
- * for the expected operational life of the system.
180
+ * Platform implementations *must* use the same epoch for GetMonotonicMicroseconds64() and GetMonotonicMilliseconds64().
181
+ * (As a consequence of this, and the requirement for GetMonotonicMicroseconds64() to return high bit zero, values
182
+ * returned by GetMonotonicMilliseconds64() will have the high ten bits zero.)
143
183
*
144
184
* @returns Elapsed time in milliseconds since an arbitrary, platform-defined epoch.
145
185
*/
@@ -151,6 +191,7 @@ class ClockImpl : public ClockBase
151
191
{
152
192
public:
153
193
~ClockImpl () = default ;
194
+ Microseconds64 GetMonotonicMicroseconds64 () override ;
154
195
Milliseconds64 GetMonotonicMilliseconds64 () override ;
155
196
};
156
197
@@ -167,8 +208,8 @@ inline void SetSystemClockForTesting(Clock::ClockBase * clock)
167
208
} // namespace Internal
168
209
169
210
#if CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_SOCKETS
170
- Milliseconds64 TimevalToMilliseconds (const timeval & in);
171
- void ToTimeval (Milliseconds64 in, timeval & out);
211
+ Microseconds64 TimevalToMicroseconds (const timeval & in);
212
+ void ToTimeval (Microseconds64 in, timeval & out);
172
213
#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_SOCKETS
173
214
174
215
} // namespace Clock
0 commit comments