nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Data Structures | Public Types | Static Public Member Functions | Static Public Attributes
nrfcxx::clock::uptime Class Reference

Support for a persistent system clock with 32 KiHz resolution. More...

#include <nrfcxx/clock.hpp>

Data Structures

class  timestamp24
 Class supporting short-term duration measurements. More...
 

Public Types

using mutex_type = mutex_irq< static_cast< IRQn_Type >(nrf5::UPTIME_RTC.IRQn)>
 An RAII type for mutex access to state that might be changed during the uptime clock FLIH.
 
using duration_type = std::chrono::duration< int64_t, std::ratio< 1, Frequency_Hz > >
 Full precision duration type for uptime clock. More...
 
using text_type = char[13]
 A type containing a NUL-terminated text time representation: HH:MM:SS.mmm
 
using day_text_type = char[18]
 A type encoding a NUL-terminated text day+time representation: DDDD HH:MM:SS.mmm
 

Static Public Member Functions

static const char * as_text (text_type buf, uint64_t dur_utt)
 Convert an uptime duration to text format. More...
 
static const char * as_day_text (day_text_type buf, uint64_t dur_utt, bool with_msec=false)
 Convert an uptime duration to text format. More...
 
static unsigned int now24 ()
 Low 24 bits of the uptime counter. More...
 
constexpr static unsigned int delta24 (unsigned int a, unsigned int b)
 Calculate the tick-count between two 24-bit counter values. More...
 
static uint64_t now ()
 Full-range uptime counter. More...
 
template<typename DurT >
constexpr static DurT to_duration (int64_t utt)
 Generic conversion from uptime ticks to a std::chrono::duration type.
 
template<typename DurT >
constexpr static duration_type::rep from_duration (DurT dur)
 Generic conversion from a std::chrono::duration type to uptime ticks.
 
constexpr static int64_t to_us (int64_t utt)
 Convert uptime ticks to integral microseconds (rounding down).
 
constexpr static int64_t from_us (int64_t us)
 Convert integral microseconds to uptime ticks (rounding down).
 
constexpr static int64_t to_ms (int64_t utt)
 Convert uptime ticks to integral milliseconds (rounding down).
 
constexpr static int64_t from_ms (int64_t ms)
 Convert integral milliseconds to uptime ticks (rounding down).
 
static int sleep (int dur)
 Sleep for a given number of uptime ticks. More...
 
template<typename DurT , typename DurT::rep = 0>
static DurT sleep (DurT dur)
 Sleep for a specified duration. More...
 
static void wakeup ()
 Cancel any in-progress sleep(). More...
 

Static Public Attributes

constexpr static unsigned int Frequency_Hz = 32768
 Frequency of the uptime clock as a symbolic constant.
 

Detailed Description

Support for a persistent system clock with 32 KiHz resolution.

The functionality of this namespace is backed by infrastructure tied to one of the RTCs, almost certainly nrfcxx::periph::RTC::RTC1.

Member Typedef Documentation

◆ duration_type

using nrfcxx::clock::uptime::duration_type = std::chrono::duration<int64_t, std::ratio<1, Frequency_Hz> >

Full precision duration type for uptime clock.

Warning
As with other std::chono durations the representation type is signed, so be careful if a negative duration might end up in a context where it's converted to an unsigned counter value.

Member Function Documentation

◆ as_day_text()

static const char* nrfcxx::clock::uptime::as_day_text ( day_text_type  buf,
uint64_t  dur_utt,
bool  with_msec = false 
)
static

Convert an uptime duration to text format.

Normal result is DDD HH:MM:SS or DDD HH:MM:SS.mmm, where the number of days has leading zeros. If more than 999 days are required, a four-digit day field is generated.

Parameters
bufwhere the representation will be stored.
dur_uttthe duration to be represented.
with_msecwhether milliseconds are to be included in the output.
Returns
buf

◆ as_text()

static const char* nrfcxx::clock::uptime::as_text ( text_type  buf,
uint64_t  dur_utt 
)
static

Convert an uptime duration to text format.

Parameters
bufwhere the representation will be stored.
dur_uttthe duration to be represented. Values wrap at multiples of 100 hours.
Returns
buf

◆ delta24()

constexpr static unsigned int nrfcxx::clock::uptime::delta24 ( unsigned int  a,
unsigned int  b 
)
inlinestaticconstexpr

Calculate the tick-count between two 24-bit counter values.

Returns
The value that when added to counter value a would produce counter value b.
Note
a and b are assumed to be 24-bit counter values as returned by now24(). The duration value returned will be in the range [0 s, 512 s).

◆ now()

static uint64_t nrfcxx::clock::uptime::now ( )
static

Full-range uptime counter.

This interface supports durations exceeding 17 Ma (i.e. about one quarter of the time since Chicxulub).

Feel free to store the value in an unsigned int which will reduce the maximum duration to about 32 h 24 min 32 s.

◆ now24()

static unsigned int nrfcxx::clock::uptime::now24 ( )
inlinestatic

Low 24 bits of the uptime counter.

This interface has the least overhead to obtain a counter, but wraps every 512 s (8 min 32 s).

◆ sleep() [1/2]

template<typename DurT , typename DurT::rep = 0>
static DurT nrfcxx::clock::uptime::sleep ( DurT  dur)
inlinestatic

Sleep for a specified duration.

Parameters
durhow long to stay asleep, absent invocations of wakeup().
Returns
the remaining portion of dur at the time of return. The value will be rounded towards zero so if this is to be useful the precision of DurT should be at least as high as duration_type.
See also
sleep(int)

◆ sleep() [2/2]

static int nrfcxx::clock::uptime::sleep ( int  dur)
static

Sleep for a given number of uptime ticks.

Parameters
durthe number of ticks to stay asleep, absent invocations of wakeup().
Returns
the number of ticks remaining from the value of dur passed in. Normally this will be zero or negative, but it may be positive if wakeup() was invoked during a FLIH.
Note
If wakeup() has been invoked since the last time sleep() returned the function will return immediately. Reinvocations will not return early unless wakeup() is invoked again.

◆ wakeup()

static void nrfcxx::clock::uptime::wakeup ( )
static

Cancel any in-progress sleep().

This function should be invoked from interrupt handlers in the case where the application may be blocked in a call to sleep() that should be pre-empted by application processing of an event noted by the handler.


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