Embedded Artistry Framework
Embedded Systems C++ Framework
Time Utilities

Functions that work with C and C++ time types. More...

Collaboration diagram for Time Utilities:

Time Conversion Functions

Convert between C and C++ time representations.

constexpr std::chrono::nanoseconds embutil::timespecToDuration (const timespec ts) noexcept
 Convert from struct timespec to std::chrono::duration. More...
 
constexpr std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > embutil::timespecToTimePoint (const timespec ts) noexcept
 Convert from struct timespec to std::chrono::time_point. More...
 
constexpr timespec embutil::durationToTimespec (std::chrono::nanoseconds dur) noexcept
 Convert from std::chrono::duration to struct timespec. More...
 
constexpr timespec embutil::timepointToTimespec (std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds > tp) noexcept
 Convert from std::chrono::time_point to struct timespec. More...
 

Detailed Description

Functions that work with C and C++ time types.

You can define UTIL_TIME_INCLUDE_TIMEVAL to include timeval conversion functions. Since these are defined in sys/time.h on POSIX systems, embedded devices may not have them, so we do not use them by default.

Time conversionf unctions were inspired by this post on StackOverflow: https://stackoverflow.com/questions/31409036/converting-from-struct-timespec-to-stdchrono

Function Documentation

◆ durationToTimespec()

constexpr timespec embutil::durationToTimespec ( std::chrono::nanoseconds  dur)
noexcept

Convert from std::chrono::duration to struct timespec.

Parameters
[in]durstd::chrono::duration value, which can be relative or absolute.
Returns
the equivalent struct timespec value.

◆ timepointToTimespec()

constexpr timespec embutil::timepointToTimespec ( std::chrono::time_point< std::chrono::system_clock, std::chrono::nanoseconds >  tp)
noexcept

Convert from std::chrono::time_point to struct timespec.

Parameters
[in]tpstd::chrono::time_point value using the system_clock.
Returns
the equivalent struct timespec value.

Referenced by os::posix::ConditionVariable::wait().

◆ timespecToDuration()

constexpr std::chrono::nanoseconds embutil::timespecToDuration ( const timespec  ts)
noexcept

Convert from struct timespec to std::chrono::duration.

Parameters
[in]tsTimespec value, which can be relative or absolute.
Returns
the equivalent std::chrono::duration value in nanoseconds.

Referenced by embutil::timespecToTimePoint(), and os::freertos::ConditionVariable::wait().

◆ timespecToTimePoint()

constexpr std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> embutil::timespecToTimePoint ( const timespec  ts)
noexcept

Convert from struct timespec to std::chrono::time_point.

Parameters
[in]tsTimespec value, which can be relative or absolute.
Returns
the equivalent std::chrono::time_point value using the system_clock.

References embutil::timespecToDuration().