µOS++ IIIe Reference 6.3.17
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
33namespace os
34{
35 namespace estd
36 {
37 namespace chrono
38 {
39
40 // ----------------------------------------------------------------------
41
42 using namespace os;
43
44 // Number of seconds from epoch (1 January 1970 00:00:00 UTC)
45 // when the system was started.
46 // Must be set during startup by reading the RTC.
47 // uint64_t startup_absolute_seconds;
48
49#pragma GCC diagnostic push
50#pragma GCC diagnostic ignored "-Waggregate-return"
51
52 // ======================================================================
53
56 {
57 const auto ticks = rtos::sysclock.now ();
58 return time_point
59 { duration
60 { ticks } };
61 }
62
63 // ======================================================================
64
67 {
68 const auto secs = rtos::rtclock.now ();
69 return time_point
70 { duration
71 { secs } };
72 }
73
75
76 // ======================================================================
77
80 {
81 const auto ticks = rtos::sysclock.now ();
82 return time_point
83 { duration
84 { systicks
85 { ticks } + realtime_clock::startup_time_point.time_since_epoch () //
86 } //
87 };
88 }
89
90 time_t
92 {
93 return time_t (
94 std::chrono::duration_cast<std::chrono::seconds> (
95 t.time_since_epoch ()).count ());
96 }
97
99 system_clock::from_time_t (time_t t) noexcept
100 {
101 return system_clock::time_point (std::chrono::seconds (t));
102 }
103
104 // ======================================================================
105
108 {
109 auto cycles = rtos::hrclock.now ();
110
111 // The duration is the number of sum of SysTick ticks plus the current
112 // count of CPU cycles (computed from the SysTick counter).
113 // Notice: a more exact solution would be to compute
114 // ticks * divisor + cycles, but this severely reduces the
115 // range of ticks.
116 return time_point
117 { duration
118 { duration
119 { cycles * 1000000000ULL
121 + realtime_clock::startup_time_point.time_since_epoch () } //
122 };
123 }
124
125#pragma GCC diagnostic pop
126
127 // ------------------------------------------------------------------------
128
129 } /* namespace chrono */
130 } /* namespace estd */
131} /* namespace os */
132
133// ----------------------------------------------------------------------------
std::chrono::time_point< high_resolution_clock > time_point
Definition chrono:212
static time_point now() noexcept
Definition chrono.cpp:107
std::chrono::nanoseconds duration
Definition chrono:209
std::chrono::duration< rep, period > duration
basic duration type of clock
Definition chrono:138
std::chrono::time_point< realtime_clock > time_point
Definition chrono:141
static time_point startup_time_point
Definition chrono:161
static time_point now() noexcept
Definition chrono.cpp:66
static time_point from_time_t(time_t t) noexcept
Definition chrono.cpp:99
std::chrono::time_point< system_clock > time_point
Definition chrono:177
std::chrono::microseconds duration
Definition chrono:174
static time_t to_time_t(const time_point &tp) noexcept
Definition chrono.cpp:91
static time_point now() noexcept
Definition chrono.cpp:79
std::chrono::time_point< systick_clock > time_point
basic time_point type of clock
Definition chrono:87
static time_point now() noexcept
Definition chrono.cpp:55
std::chrono::duration< rep, period > duration
basic duration type of clock
Definition chrono:84
virtual timestamp_t now(void) override
Tell the current time adjusted for epoch.
uint32_t input_clock_frequency_hz(void)
Definition os-clocks.h:905
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:108
System namespace.
Single file µOS++ RTOS definitions.