µ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_systick Class Reference

SysTick derived clock. More...

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

+ Inheritance diagram for os::rtos::clock_systick:

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_systick ()
 Construct a SysTick clock object instance.
 
virtual ~clock_systick () override
 Destruct the SysTick clock object instance.
 
Public Member Functions
virtual timestamp_t now (void)
 Tell the current time, possibly adjusted for epoch.
 
timestamp_t steady_now (void)
 Tell the current time since startup.
 
result_t sleep_for (duration_t duration)
 Sleep for a relative duration.
 
virtual result_t sleep_until (timestamp_t timestamp)
 Sleep until an absolute timestamp.
 
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 = OS_INTEGER_SYSTICK_FREQUENCY_HZ
 SysTick frequency in Hz.
 

Public Member Functions

virtual void start (void) override
 
template<typename Rep_T >
static constexpr clock::duration_t ticks_cast (Rep_T microsec)
 Convert microseconds to ticks.
 

Detailed Description

SysTick derived clock.

This clock counts SysTick interrupts since startup.

The SysTick clock should be a steady clock, i.e. the total count of ticks should be monotone ascending (in other words no adjustments to the past should be performed).

For Cortex-M implementations using the standard SysTick, this clock is able to provide accuracy at CPU cycle level, by sampling the SysTick internal counter. For a CPU clock of 100 MHz, this gives a 10 ns resolution, quite high for accurate timing.

Example
void
func(void)
{
// Do something
// Get the current ticks counter.
// Put the current thread to sleep for a given number of ticks.
// Put the current thread to sleep for a given number of microseconds.
// For a 1000 Hz clock, the actual value is 4 ticks.
// Do something else.
}
static constexpr clock::duration_t ticks_cast(Rep_T microsec)
Convert microseconds to ticks.
virtual timestamp_t now(void)
Tell the current time, possibly adjusted for epoch.
result_t sleep_for(duration_t duration)
Sleep for a relative duration.
port::clock::timestamp_t timestamp_t
Type of variables holding clock time stamps.
Definition os-clocks.h:92
clock_systick sysclock
The system clock object instance.

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

Constructor & Destructor Documentation

◆ clock_systick()

os::rtos::clock_systick::clock_systick ( )

Construct a SysTick clock object instance.

Warning
Cannot be invoked from Interrupt Service Routines.

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

◆ ~clock_systick()

os::rtos::clock_systick::~clock_systick ( )
overridevirtual

Destruct the SysTick clock object instance.

Warning
Cannot be invoked from Interrupt Service Routines.

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

Member Function Documentation

◆ 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 774 of file os-decls.h.

◆ now()

clock::timestamp_t os::rtos::clock::now ( void  )
virtualinherited

Tell the current time, possibly 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 in os::rtos::adjustable_clock, and os::rtos::clock_highres.

Definition at line 173 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 201 of file os-clocks.cpp.

◆ sleep_until()

result_t os::rtos::clock::sleep_until ( timestamp_t  timestamp)
virtualinherited

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 in os::rtos::adjustable_clock.

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

◆ start()

void os::rtos::clock_systick::start ( void  )
overridevirtual
Warning
Cannot be invoked from Interrupt Service Routines.

Implements os::rtos::clock.

Definition at line 569 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 187 of file os-clocks.cpp.

◆ ticks_cast()

template<typename Rep_T >
static constexpr clock::duration_t os::rtos::clock_systick::ticks_cast ( Rep_T  microsec)
staticconstexpr

Convert microseconds to ticks.

Template Parameters
Rep_TType of input, auto deduced (usually uint32_t or uin64_t)
Parameters
[in]microsecThe number of microseconds.
Returns
The number of ticks.

◆ 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 324 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 282 of file os-clocks.cpp.

Member Data Documentation

◆ frequency_hz

constexpr uint32_t os::rtos::clock_systick::frequency_hz = OS_INTEGER_SYSTICK_FREQUENCY_HZ
staticconstexpr

SysTick frequency in Hz.

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


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