µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::rtos::clock_rtc Class Reference

Real time clock. More...

#include <cmsis-plus/rtos/os.h>

+ Inheritance diagram for os::rtos::clock_rtc:

Public Types

Types & Constants
using duration_t = port::clock::duration_t
 Type of variables holding clock durations.
 
using timestamp_t = port::clock::timestamp_t
 Type of variables holding clock time stamps.
 
using offset_t = port::clock::offset_t
 Type of variables holding clock offsets.
 

Public Member Functions

Constructors & Destructor
 clock_rtc ()
 Construct a real time clock object instance.
 
virtual ~clock_rtc () override
 Destruct the real time clock object instance.
 
Public Member Functions
virtual void start (void) override
 Initialise and make the RTC tick.
 
Public Member Functions
virtual timestamp_t now (void) override
 Tell the current time adjusted for epoch.
 
virtual result_t sleep_until (timestamp_t timestamp) override
 Sleep until an absolute timestamp.
 
virtual offset_t offset (void) override
 Get adjustment offset.
 
virtual offset_t offset (offset_t value) override
 Set adjustment offset.
 
void internal_check_timestamps (void)
 
Public Member Functions
timestamp_t steady_now (void)
 Tell the current time since startup.
 
result_t sleep_for (duration_t duration)
 Sleep for a relative duration.
 
result_t wait_for (duration_t timeout)
 Timed wait for an event.
 
timestamp_t update_for_slept_time (duration_t duration)
 Increase the internal count after a deep sleep.
 
Public Member Functions
const char * name (void) const
 Get object name.
 

Static Public Attributes

Types & Constants
static constexpr uint32_t frequency_hz = 1
 Real time clock frequency in Hz.
 

Detailed Description

Real time clock.

This clock counts seconds since epoch or startup.

The real time clock should be derived from a battery powered second counting RTC, initialised at startup with the number of seconds since the standard POSIX epoch (January 1st, 1970).

As any usual clock, it might occasionally be adjusted to match a reference clock, so it cannot be a steady clock.

For systems that do not have a hardware RTC, it can be derived from SysTick, but in this case it must be externally initialised with the epoch.

Example
void
func(void)
{
// Do something
// Get the current seconds counter.
// Put the current thread to sleep for a given number of seconds.
// Do something else.
}
virtual timestamp_t now(void) override
Tell the current time adjusted for epoch.
result_t sleep_for(duration_t duration)
Sleep for a relative duration.
clock_rtc rtclock
The real time clock object instance.
port::clock::timestamp_t timestamp_t
Type of variables holding clock time stamps.
Definition os-clocks.h:85

Definition at line 590 of file os-clocks.h.

Constructor & Destructor Documentation

◆ clock_rtc()

os::rtos::clock_rtc::clock_rtc ( )

Construct a real time clock object instance.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 674 of file os-clocks.cpp.

◆ ~clock_rtc()

os::rtos::clock_rtc::~clock_rtc ( )
overridevirtual

Destruct the real time clock object instance.

Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 683 of file os-clocks.cpp.

Member Function Documentation

◆ internal_check_timestamps()

void os::rtos::adjustable_clock::internal_check_timestamps ( void  )
inherited

◆ name()

const char * os::rtos::internal::object_named::name ( void  ) const
inlineinherited

Get object name.

Parameters
None.
Returns
A null terminated string.

All objects return a non-null string; anonymous objects return "-".

Note
Can be invoked from Interrupt Service Routines.

Definition at line 759 of file os-decls.h.

◆ now()

clock::timestamp_t os::rtos::adjustable_clock::now ( void  )
overridevirtualinherited

Tell the current time adjusted for epoch.

Parameters
None.
Returns
The clock current timestamp (time units from startup plus the epoch offset).
Note
Can be invoked from Interrupt Service Routines.

Reimplemented from os::rtos::clock.

Definition at line 434 of file os-clocks.cpp.

◆ offset() [1/2]

clock::offset_t os::rtos::adjustable_clock::offset ( offset_t  value)
overridevirtualinherited

Set adjustment offset.

Parameters
[in]valueInteger representing the offset to epoch (positive).
Returns
Integer value representing the previous offset to epoch.
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 504 of file os-clocks.cpp.

◆ offset() [2/2]

clock::offset_t os::rtos::adjustable_clock::offset ( void  )
overridevirtualinherited

Get adjustment offset.

Parameters
None.
Returns
Integer value representing the offset to epoch.
Note
Can be invoked from Interrupt Service Routines.

Definition at line 495 of file os-clocks.cpp.

◆ sleep_for()

result_t os::rtos::clock::sleep_for ( duration_t  duration)
inherited

Sleep for a relative duration.

Parameters
[in]durationThe number of clock units (ticks or seconds) to sleep.
Return values
ETIMEDOUTThe sleep lasted the entire duration.
EPERMCannot be invoked from an Interrupt Service Routines.
EINTRThe sleep was interrupted.
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 190 of file os-clocks.cpp.

◆ sleep_until()

result_t os::rtos::adjustable_clock::sleep_until ( timestamp_t  timestamp)
overridevirtualinherited

Sleep until an absolute timestamp.

Parameters
[in]timestampThe absolute moment in time, in clock units.
Return values
ETIMEDOUTThe sleep lasted the entire duration.
EPERMCannot be invoked from an Interrupt Service Routines.
EINTRThe sleep was interrupted.
Warning
Cannot be invoked from Interrupt Service Routines.

Reimplemented from os::rtos::clock.

Definition at line 456 of file os-clocks.cpp.

◆ start()

void os::rtos::clock_rtc::start ( void  )
overridevirtual

Initialise and make the RTC tick.

Parameters
None.
Returns
Nothing.

Must be called only once, during inits.

Warning
Cannot be invoked from Interrupt Service Routines.

Implements os::rtos::clock.

Definition at line 696 of file os-clocks.cpp.

◆ steady_now()

clock::timestamp_t os::rtos::clock::steady_now ( void  )
inherited

Tell the current time since startup.

Parameters
None.
Returns
The clock current steady timestamp (time units from startup).
Note
Can be invoked from Interrupt Service Routines.

Definition at line 176 of file os-clocks.cpp.

◆ update_for_slept_time()

clock::timestamp_t os::rtos::clock::update_for_slept_time ( duration_t  duration)
inherited

Increase the internal count after a deep sleep.

Parameters
durationNumber of ticks lost during sleep.
Returns
The clock current steady timestamp (time units from startup).

During deep sleep the interrupts used to count clock ticks are usually disabled and an external RTC is configured to wake-up the device, so a number of clock ticks are lost.

To keep the clocks accurate, it is recommended to sample the external RTC before entering deep sleep and again when the device is back to life, compute the time slept as difference, and use this function to update the internal clock counter.

Definition at line 329 of file os-clocks.cpp.

◆ wait_for()

result_t os::rtos::clock::wait_for ( duration_t  timeout)
inherited

Timed wait for an event.

Parameters
[in]timeoutThe timeout in clock units.
Return values
result::okAn event occurred before the timeout.
ETIMEDOUTThe wait lasted the entire duration.
EPERMCannot be invoked from an Interrupt Service Routines.
EINTRThe sleep was interrupted.
Warning
Cannot be invoked from Interrupt Service Routines.

Definition at line 279 of file os-clocks.cpp.

Member Data Documentation

◆ frequency_hz

constexpr uint32_t os::rtos::clock_rtc::frequency_hz = 1
staticconstexpr

Real time clock frequency in Hz.

Definition at line 602 of file os-clocks.h.


The documentation for this class was generated from the following files: