µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
chrono.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#include <cmsis-plus/rtos/os.h>
30
31// ----------------------------------------------------------------------------
32
33#if defined(__clang__)
34#pragma clang diagnostic ignored "-Wc++98-compat"
35#endif
36
37// ----------------------------------------------------------------------------
38
39namespace os
40{
41 namespace estd
42 {
43 namespace chrono
44 {
45
46 // ----------------------------------------------------------------------
47
48 using namespace os;
49
50 // Number of seconds from epoch (1 January 1970 00:00:00 UTC)
51 // when the system was started.
52 // Must be set during startup by reading the RTC.
53 // uint64_t startup_absolute_seconds;
54
55#pragma GCC diagnostic push
56#pragma GCC diagnostic ignored "-Waggregate-return"
57
58 // ======================================================================
59
62 {
63 const auto ticks = rtos::sysclock.now ();
64 return time_point
65 { duration
66 { ticks } };
67 }
68
69 // ======================================================================
70
73 {
74 const auto secs = rtos::rtclock.now ();
75 return time_point
76 { duration
77 { secs } };
78 }
79
81
82 // ======================================================================
83
86 {
87 const auto ticks = rtos::sysclock.now ();
88 return time_point
89 { duration
90 { systicks
91 { ticks } + realtime_clock::startup_time_point.time_since_epoch () //
92 } //
93 };
94 }
95
96 time_t
98 {
99 return time_t (
100 std::chrono::duration_cast<std::chrono::seconds> (
101 t.time_since_epoch ()).count ());
102 }
103
105 system_clock::from_time_t (time_t t) noexcept
106 {
107 return system_clock::time_point (std::chrono::seconds (t));
108 }
109
110 // ======================================================================
111
114 {
115 auto cycles = rtos::hrclock.now ();
116
117#pragma GCC diagnostic push
118#if defined(__clang__)
119// error: 'long long' is incompatible with C++98 [-Werror,-Wc++98-compat-pedantic]
120#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
121#endif
122 // The duration is the number of sum of SysTick ticks plus the current
123 // count of CPU cycles (computed from the SysTick counter).
124 // Notice: a more exact solution would be to compute
125 // ticks * divisor + cycles, but this severely reduces the
126 // range of ticks.
127 return time_point
128 { duration
129 { duration
130 { cycles * 1000000000ULL
132 + realtime_clock::startup_time_point.time_since_epoch () } //
133 };
134#pragma GCC diagnostic pop
135 }
136
137#pragma GCC diagnostic pop
138
139 // ------------------------------------------------------------------------
140
141 } /* namespace chrono */
142 } /* namespace estd */
143} /* namespace os */
144
145// ----------------------------------------------------------------------------
std::chrono::time_point< high_resolution_clock > time_point
Definition chrono:226
static time_point now() noexcept
Definition chrono.cpp:113
std::chrono::nanoseconds duration
Definition chrono:223
std::chrono::duration< rep, period > duration
basic duration type of clock
Definition chrono:152
std::chrono::time_point< realtime_clock > time_point
Definition chrono:155
static time_point startup_time_point
Definition chrono:175
static time_point now() noexcept
Definition chrono.cpp:72
static time_point from_time_t(time_t t) noexcept
Definition chrono.cpp:105
std::chrono::time_point< system_clock > time_point
Definition chrono:191
std::chrono::microseconds duration
Definition chrono:188
static time_t to_time_t(const time_point &tp) noexcept
Definition chrono.cpp:97
static time_point now() noexcept
Definition chrono.cpp:85
std::chrono::time_point< systick_clock > time_point
basic time_point type of clock
Definition chrono:96
static time_point now() noexcept
Definition chrono.cpp:61
std::chrono::duration< rep, period > duration
basic duration type of clock
Definition chrono:93
virtual timestamp_t now(void) override
Tell the current time adjusted for epoch.
uint32_t input_clock_frequency_hz(void)
Definition os-clocks.h:934
virtual timestamp_t now(void) override
Tell the current time.
virtual timestamp_t now(void)
Tell the current time, possibly adjusted for epoch.
clock_highres hrclock
The high resolution clock object instance.
clock_rtc rtclock
The real time clock object instance.
clock_systick sysclock
The system clock object instance.
systick_clock::duration systicks
Definition chrono:117
System namespace.
Single file µOS++ RTOS definitions.