Mbed OS Reference
Loading...
Searching...
No Matches
RealTimeClock Class Reference

An implementation of a C++11 Clock representing the HAL real-time clock. More...

#include <RealTimeClock.h>

Static Public Member Functions

static void init ()
 Initialize the RTC peripheral. More...
 
static void free ()
 Deinitialize RTC. More...
 
static bool isenabled () noexcept
 Check if the RTC has the time set and is counting. More...
 
static time_point now () noexcept
 Get the current time from the RTC peripheral. More...
 
static void write (time_point t) noexcept
 Write the current time in seconds to the RTC peripheral. More...
 
static time_point from_time_t (time_t t) noexcept
 Convert a C time_t to C++ Chrono time_point. More...
 
static time_t to_time_t (const time_point &t) noexcept
 Convert a C++ Chrono time_point to a C time_t. More...
 
static void lock ()
 Lock the clock to ensure it stays running; dummy for API compatibility with HighResClock. More...
 
static void unlock ()
 Unlock the clock, allowing it to stop during power saving; dummy for API compatibility with HighResClock. More...
 

Detailed Description

An implementation of a C++11 Clock representing the HAL real-time clock.

This is intended to be usable as a substitute for std::chrono::system_clock, but is provided as a separate class, due to inconsistencies in retargetting support between toolchains.

This is only a thin wrapper around the HAL RTC API, and as such it requires the same use of initialization.

Definition at line 41 of file RealTimeClock.h.

Member Function Documentation

◆ init()

static void init ( )
static

Initialize the RTC peripheral.

Power up the RTC in preparation for access. This function must be called before any other RealTimeClock methods are called. This does not change the state of the RTC. It just enables access to it.

See also
rtc_init

Definition at line 57 of file RealTimeClock.h.

◆ free()

static void free ( )
static

Deinitialize RTC.

Powerdown the RTC in preparation for sleep, powerdown or reset. That should only affect the CPU domain and not the time keeping logic. After this function is called no other RealTimeClock methods should be called except for RealTimeClock::init.

See also
rtc_free

Definition at line 71 of file RealTimeClock.h.

◆ isenabled()

static bool isenabled ( )
staticnoexcept

Check if the RTC has the time set and is counting.

Return values
falseThe time reported by the RTC is not valid
trueThe time has been set and the RTC is counting
See also
rtc_isenabled

Definition at line 83 of file RealTimeClock.h.

◆ now()

static time_point now ( )
staticnoexcept

Get the current time from the RTC peripheral.

Returns
The current time in seconds
See also
rtc_read

Definition at line 94 of file RealTimeClock.h.

◆ write()

static void write ( time_point  t)
staticnoexcept

Write the current time in seconds to the RTC peripheral.

Parameters
tThe current time to be set in seconds.
See also
rtc_write

Definition at line 105 of file RealTimeClock.h.

◆ from_time_t()

static time_point from_time_t ( time_t  t)
staticnoexcept

Convert a C time_t to C++ Chrono time_point.

Parameters
ta time_t object
Returns
a RealTimeClock::time_point object that represents the same point in time as t.

Definition at line 115 of file RealTimeClock.h.

◆ to_time_t()

static time_t to_time_t ( const time_point &  t)
staticnoexcept

Convert a C++ Chrono time_point to a C time_t.

Parameters
ta RealTimeClock::time_point object
Returns
a time_t object that represents the same point in time as t.

Definition at line 125 of file RealTimeClock.h.

◆ lock()

static void lock ( )
static

Lock the clock to ensure it stays running; dummy for API compatibility with HighResClock.

Definition at line 131 of file RealTimeClock.h.

◆ unlock()

static void unlock ( )
static

Unlock the clock, allowing it to stop during power saving; dummy for API compatibility with HighResClock.

Definition at line 136 of file RealTimeClock.h.