BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Data Structures | Macros | Typedefs | Functions
uptime.h File Reference

Support for maintaining a system uptime counter. More...

#include <bsp430/periph/timer.h>
#include <bsp430/clock.h>
#include <sys/time.h>

Go to the source code of this file.

Data Structures

struct  sBSP430uptimeActivityTotals
 
struct  sBSP430uptimeNTPShortFormat
 
struct  sBSP430uptimeNTPTimestamp
 
struct  sBSP430uptimeNTPPacketHeader
 

Macros

#define configBSP430_UPTIME   0
 
#define BSP430_UPTIME   include <bsp430/platform.h>
 
#define configBSP430_UPTIME_EPOCH   0
 
#define configBSP430_UPTIME_DELAY   0
 
#define BSP430_UPTIME_TIMER_PERIPH_CPPID   include "bsp430_config.h"
 
#define BSP430_UPTIME_TIMER_PERIPH_HANDLE   platform or application specific
 
#define configBSP430_UPTIME_TIMER_HAL_CC0_ISR   indirectly defaulted
 
#define BSP430_UPTIME_TASSEL   TASSEL_1 /* == TASSEL__ACLK */
 
#define BSP430_UPTIME_DIVIDING_SHIFT   0
 
#define BSP430_UPTIME_MS_TO_UTT(ms_)   BSP430_CORE_MS_TO_TICKS((ms_), ulBSP430uptimeConversionFrequency_Hz())
 
#define BSP430_UPTIME_UTT_TO_MS(utt_)   BSP430_CORE_TICKS_TO_MS((utt_), ulBSP430uptimeConversionFrequency_Hz())
 
#define BSP430_UPTIME_US_TO_UTT(us_)   BSP430_CORE_US_TO_TICKS((us_), ulBSP430uptimeConversionFrequency_Hz())
 
#define BSP430_UPTIME_UTT_TO_US(utt_)   BSP430_CORE_TICKS_TO_US((utt_), ulBSP430uptimeConversionFrequency_Hz())
 
#define BSP430_UPTIME_AS_TEXT_LENGTH   sizeof("HHH:MM:SS.mmm")
 
#define BSP430_UPTIME_DELAY_CCIDX   1
 
#define BSP430_UPTIME_DELAY_UTT_NI(delay_utt_, lpm_bits_, exit_expr_)
 
#define BSP430_UPTIME_DELAY_UTT(delay_utt_, lpm_bits_, exit_expr_)
 
#define BSP430_UPTIME_DELAY_MS_NI(delay_ms_, lpm_bits_, exit_expr_)
 
#define BSP430_UPTIME_DELAY_MS(delay_ms_, lpm_bits_, exit_expr_)
 
#define BSP430_UPTIME_POSIX_EPOCH_NTPIS   2208988800UL
 
#define BSP430_UPTIME_BYPASS_EPOCH_NTP   ((uint64_t)(BSP430_UPTIME_POSIX_EPOCH_NTPIS + 1388534400UL) << 32)
 
#define BSP430_UPTIME_EPOCH_UPDATE_INTERVAL_UTT   0x40000000L
 
#define BSP430_UPTIME_EPOCH_VALID_OFFSET_UTT   0x60000000L
 

Typedefs

typedef struct sBSP430uptimeActivityTotals sBSP430uptimeActivityTotals
 
typedef struct sBSP430uptimeNTPShortFormat sBSP430uptimeNTPShortFormat
 
typedef struct sBSP430uptimeNTPTimestamp sBSP430uptimeNTPTimestamp
 
typedef struct sBSP430uptimeNTPPacketHeader sBSP430uptimeNTPPacketHeader
 

Functions

static BSP430_CORE_INLINE hBSP430halTIMER hBSP430uptimeTimer (void)
 
unsigned long ulBSP430uptimeConversionFrequency_Hz (void)
 
unsigned long ulBSP430uptimeSetConversionFrequency_ni (unsigned long frequency_Hz)
 
static BSP430_CORE_INLINE unsigned long ulBSP430uptime_ni (void)
 
static BSP430_CORE_INLINE unsigned long ulBSP430uptime (void)
 
static BSP430_CORE_INLINE unsigned long long ullBSP430uptime (void)
 
static BSP430_CORE_INLINE unsigned long long ullBSP430uptimeCorrected (unsigned int ctr)
 
static BSP430_CORE_INLINE unsigned int uiBSP430uptimeCounter_ni (void)
 
static BSP430_CORE_INLINE bool bBSP430uptimeIsValid (unsigned long duration_utt)
 
static BSP430_CORE_INLINE unsigned long ulBSP430uptimeValidated (unsigned long duration_utt)
 
void vBSP430uptimeStart_ni (void)
 
void vBSP430uptimeSuspend_ni (void)
 
void vBSP430uptimeResume_ni (void)
 
const char * xBSP430uptimeAsText (unsigned long duration_utt, char *buffer)
 
const char * xBSP430uptimeAsText_ni (unsigned long duration_utt)
 
unsigned int uiBSP430uptimeScaleForDisplay (unsigned long long duration_utt, const char **unitp)
 
void vBSP430uptimeActivityReset (sBSP430uptimeActivityTotals *sp, bool from_now)
 
static BSP430_CORE_INLINE void vBSP430uptimeActivityStartSleep_ni (sBSP430uptimeActivityTotals *sp)
 
static BSP430_CORE_INLINE void vBSP430uptimeActivityStartActive_ni (sBSP430uptimeActivityTotals *sp)
 
static BSP430_CORE_INLINE unsigned int uiBSP430uptimeActivity_ppt (sBSP430uptimeActivityTotals *sp)
 
long lBSP430uptimeSleepUntil (unsigned long setting_utt, unsigned int lpm_bits)
 
int iBSP430uptimeDelaySetEnabled_ni (int enablep)
 
int iBSP430uptimeCheckEpochValidity ()
 
unsigned long ulBSP430uptimeLastEpochUpdate ()
 
long lBSP430uptimeEpochAge ()
 
int iBSP430uptimeEpochEra (unsigned long time_utt)
 
int iBSP430uptimeInitializeNTPRequest (sBSP430uptimeNTPPacketHeader *ntpp)
 
int iBSP430uptimeSetNTPXmtField (sBSP430uptimeNTPPacketHeader *ntpp, unsigned long *putt)
 
int iBSP430uptimeSetEpochFromNTP (uint64_t epoch_ntp)
 
int iBSP430uptimeAdjustEpochFromNTP (int64_t adjustment_ntp)
 
int iBSP430uptimeSetEpochFromTimeval (const struct timeval *tv, unsigned long when_utt)
 
int iBSP430uptimeAsNTP (unsigned long utt, uint64_t *ntpp, int bypass_validation)
 
int iBSP430uptimeAsTimeval (unsigned long utt, struct timeval *tv)
 
time_t xBSP430uptimeAsPOSIXTime (unsigned long utt)
 
int iBSP430uptimeProcessNTPResponse (const sBSP430uptimeNTPPacketHeader *req, const sBSP430uptimeNTPPacketHeader *resp, uint64_t rec_ntp, int64_t *adjustment_ntp, long *adjustment_ms, unsigned long *rtt_us)
 

Detailed Description

Support for maintaining a system uptime counter.

This module provides routines to initialize and query a long-term clock, using a platform-selected timer sourced by an undivided ACLK.

vBSP430uptimeStart_ni() must be invoked on hardware initialization after configuring the system clocks. This is done for you in vBSP430platformInitialize_ni() if configBSP430_UPTIME is true.

Normally BSP430_PERIPH_TA0 is used for this function, but see BSP430_UPTIME_TIMER_PERIPH_CPPID if you want to select a different timer.

Warning
The capture/compare register for BSP430_TIMER_VALID_COUNTER_READ_CCIDX is reserved for use in overflow management. Do not use or reconfigure this register.
See also
Epoch Support for the Uptime Timer
Homepage
http://github.com/pabigot/bsp430

Macro Definition Documentation

#define BSP430_UPTIME   include <bsp430/platform.h>

Defined to a true value if BSP430_UPTIME_TIMER_PERIPH_CPPID has been provided, making the uptime infrastructure available.

Dependency:
configBSP430_UPTIME
Platform-Based Value:
Undefined here; include <bsp430/platform.h> to obtain the correct value of this macro.
#define BSP430_UPTIME_AS_TEXT_LENGTH   sizeof("HHH:MM:SS.mmm")

Expected length for a buffer used by xBSP430uptimeAsText().

This macro may be used to allocate such a buffer.

At 32 kiHz resolution a 32-bit integer holding ticks can only represent 36 hours before wrapping, but at 10 kHz resolution the same counter might express up to 119 hours, so this allows durations up to up to 999:59:59.999 to be expressed.

Examples:
rf/cc3000/cli/main.c, sensors/hh10d/main.c, sensors/venus6pps/main.c, and utility/m25p/main.c.
#define BSP430_UPTIME_DELAY_CCIDX   1

The capture/compare index to be used for delays.

If configBSP430_UPTIME_DELAY is enabled this capture/compare register index will be used on the uptime timer to support delays using the Alarm-related Timer Functionality infrastructure.

Note
Most applications should avoid using CC 0 because it is normally reserved for RTOS context switch support, and CC 2 because it is normally used in uiBSP430timerSafeCounterRead_ni() from ulBSP430timerCounter_ni() when configBSP430_TIMER_VALID_COUNTER_READ is enabled. The uptime timer is generally asynchronous to MCLK so valid counter reads are critical.
Warning
If you assign the same value to BSP430_UPTIME_DELAY_CCIDX and BSP430_TIMER_VALID_COUNTER_READ_CCIDX, platform initialization will hang attempting to configure the delay alarm.
Defaulted:
The value here is superseded by previously encountered definitions.
#define BSP430_UPTIME_DELAY_MS (   delay_ms_,
  lpm_bits_,
  exit_expr_ 
)
Value:
do { \
BSP430_UPTIME_DELAY_UTT_NI(BSP430_UPTIME_MS_TO_UTT(delay_ms_), lpm_bits_, exit_expr_); \
} while (0)
#define BSP430_UPTIME_DELAY_UTT_NI(delay_utt_, lpm_bits_, exit_expr_)
Definition: uptime.h:770
#define BSP430_CORE_RESTORE_INTERRUPT_STATE(state_)
Definition: core.h:731
#define BSP430_UPTIME_MS_TO_UTT(ms_)
Definition: uptime.h:335
#define BSP430_CORE_SAVED_INTERRUPT_STATE(var_)
Definition: core.h:719
#define BSP430_CORE_DISABLE_INTERRUPT()
Definition: core.h:762

Wrapper around BSP430_UPTIME_DELAY_MS_NI() suitable for use when interrupts are enabled.

Dependency:
configBSP430_UPTIME_DELAY
#define BSP430_UPTIME_DELAY_MS_NI (   delay_ms_,
  lpm_bits_,
  exit_expr_ 
)
Value:
do { \
BSP430_UPTIME_DELAY_UTT_NI(BSP430_UPTIME_MS_TO_UTT(delay_ms_), lpm_bits_, exit_expr_); \
} while (0)
#define BSP430_UPTIME_DELAY_UTT_NI(delay_utt_, lpm_bits_, exit_expr_)
Definition: uptime.h:770
#define BSP430_UPTIME_MS_TO_UTT(ms_)
Definition: uptime.h:335

Macro to simplify basic delay-in-milliseconds operations.

Wrapper around BSP430_UPTIME_DELAY_UTT_NI() to support delays specified in milliseconds.

Parameters
delay_ms_duration, in milliseconds, that application should sleep
lpm_bits_as with BSP430_UPTIME_DELAY_UTT_NI()
exit_expr_as with BSP430_UPTIME_DELAY_UTT_NI()
See also
BSP430_UPTIME_MS_TO_UTT
Dependency:
configBSP430_UPTIME_DELAY
Examples:
sensors/ds18b20/main.c, and sensors/venus6pps/main.c.
#define BSP430_UPTIME_DELAY_UTT (   delay_utt_,
  lpm_bits_,
  exit_expr_ 
)
Value:
do { \
BSP430_UPTIME_DELAY_UTT_NI(BSP430_UPTIME_UTT_TO_UTT(delay_utt_), lpm_bits_, exit_expr_); \
} while (0)
#define BSP430_UPTIME_DELAY_UTT_NI(delay_utt_, lpm_bits_, exit_expr_)
Definition: uptime.h:770
#define BSP430_CORE_RESTORE_INTERRUPT_STATE(state_)
Definition: core.h:731
#define BSP430_CORE_SAVED_INTERRUPT_STATE(var_)
Definition: core.h:719
#define BSP430_CORE_DISABLE_INTERRUPT()
Definition: core.h:762

Wrapper around BSP430_UPTIME_DELAY_UTT_NI() suitable for use when interrupts are enabled.

Dependency:
configBSP430_UPTIME_DELAY
#define BSP430_UPTIME_DELAY_UTT_NI (   delay_utt_,
  lpm_bits_,
  exit_expr_ 
)
Value:
do { \
unsigned long wake_utt; \
wake_utt = ulBSP430uptime_ni() + (delay_utt_); \
while ((! (exit_expr_)) && (0 < lBSP430uptimeSleepUntil(wake_utt, lpm_bits_))) { \
/* nop */ \
} \
} while (0)
long lBSP430uptimeSleepUntil(unsigned long setting_utt, unsigned int lpm_bits)
static BSP430_CORE_INLINE unsigned long ulBSP430uptime_ni(void)
Definition: uptime.h:361

Macro to simplify basic delay-in-ticks operations

This invokes lBSP430uptimeSleepUntil() in a loop for a specified duration or until another event has occurred.

Parameters
delay_utt_duration, in uptime ticks, that application should sleep
lpm_bits_the LPM mode in which the application should sleep. See corresponding parameter in lBSP430uptimeSleepUntil_ni().
exit_expr_an expression that will be tested prior to sleeping. If it evaluates to true, the delay will be aborted immediately regardless of remaining time. Pass 0 if you wish to delay regardless of other activity.
Dependency:
configBSP430_UPTIME_DELAY
#define BSP430_UPTIME_DIVIDING_SHIFT   0

Shift value dividing BSP430_UPTIME_TASSEL for the uptime clock.

Defaulted:
The value here is superseded by previously encountered definitions.
#define BSP430_UPTIME_MS_TO_UTT (   ms_)    BSP430_CORE_MS_TO_TICKS((ms_), ulBSP430uptimeConversionFrequency_Hz())

Convert from milliseconds to ticks of the uptime timer.

Note
Evaluation is valid only when the uptime timer is running. The result is rounded down.
Examples:
utility/u8glib/main.c.
#define BSP430_UPTIME_TASSEL   TASSEL_1 /* == TASSEL__ACLK */

Source selector for uptime clock. This should be bits suitable for storage into the TASSEL field of a timer control register. (Note that TASSEL and TBSSEL support the same values; this works when using TBx as well.)

Defaulted:
The value here is superseded by previously encountered definitions.
#define BSP430_UPTIME_TIMER_PERIPH_CPPID   include "bsp430_config.h"

Define to the preprocessor-compatible identifier for a timer that should be used to maintain a continuous system clock sourced from ACLK. The define must appear in the BSP430 Configuration subsystem so that functional resource requests are correctly propagated to the underlying resource instances.

Defaulted:
The value here is superseded by previously encountered definitions.
Platform-Based Value:
Undefined here; include <bsp430/platform.h> to obtain the correct value of this macro.
Affects:
BSP430_UPTIME_TIMER_PERIPH_HANDLE
#define BSP430_UPTIME_TIMER_PERIPH_HANDLE   platform or application specific

Defined to the peripheral identifier for a timer that can be used to maintain a continuous system clock sourced from ACLK. This derives directly from BSP430_UPTIME_TIMER_PERIPH_CPPID, but is a timer peripheral handle suitable for use in code.

The corresponding HAL and primary ISR features are automatically enabled for this peripheral. CC0 ISR inclusion is influenced by configBSP430_UPTIME_TIMER_HAL_CC0_ISR.

Dependency:
BSP430_UPTIME_TIMER_PERIPH_CPPID
Examples:
sensors/hh10d/main.c, sensors/venus6pps/main.c, utility/cli/main.c, and utility/u8glib/main.c.
#define BSP430_UPTIME_US_TO_UTT (   us_)    BSP430_CORE_US_TO_TICKS((us_), ulBSP430uptimeConversionFrequency_Hz())

Convert from microseconds to ticks of the uptime timer.

Note
Evaluation is valid only when the uptime timer is running. The result is rounded down.
#define BSP430_UPTIME_UTT_TO_MS (   utt_)    BSP430_CORE_TICKS_TO_MS((utt_), ulBSP430uptimeConversionFrequency_Hz())

Convert from ticks of the uptime timer to milliseconds.

Note
Evaluation is valid only when the uptime timer is running. The result is rounded down.
Examples:
sensors/ds18b20/main.c.
#define BSP430_UPTIME_UTT_TO_US (   utt_)    BSP430_CORE_TICKS_TO_US((utt_), ulBSP430uptimeConversionFrequency_Hz())

Convert from ticks of the uptime timer to microseconds.

Note
Evaluation is valid only when the uptime timer is running. The result is rounded down.
#define configBSP430_UPTIME   0

Define to a true value to enable the uptime infrastructure to maintain a continuous system clock. A timer that will support this must be identified; see BSP430_UPTIME_TIMER_PERIPH_CPPID.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Affects:
BSP430_UPTIME
Defaulted:
The value here is superseded by previously encountered definitions.
#define configBSP430_UPTIME_DELAY   0

Define to a true value to support uptime-driven delays.

This flag enables infrastructure support to use the Alarm-related Timer Functionality infrastructure on the uptime timer to support application delays. The core API for this capability is lBSP430uptimeSleepUntil() and BSP430_UPTIME_DELAY_MS_NI().

Note
Applications that use the delay functionality should normally enable configBSP430_CORE_LPM_EXIT_CLEAR_GIE. See discussion at lBSP430uptimeSleepUntil().
C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Defaulted:
The value here is superseded by previously encountered definitions.
#define configBSP430_UPTIME_EPOCH   0

Define to a true value to support uptime timer epochs.

This flag enables infrastructure support to use the Epoch Support for the Uptime Timer infrastructure to translate between civil time values such as UTC (represented as NTP timestamps or struct timeval) and uptime clocks, by providing a precise epoch that denotes the time at which the uptime timer last rolled over.

See also
Epoch Support for the Uptime Timer
C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Defaulted:
The value here is superseded by previously encountered definitions.

Typedef Documentation

A structure to record the relative levels of activity and sleep.

Primarily this can be used to calculate the duty cycle of an application. This infrastructure assumes that the uptime clock runs continuously, including in sleep mode, and that no active or sleep period exceeds the duration representable in an unsigned long.

See also
vBSP430uptimeActivityInitialize()

Function Documentation

static BSP430_CORE_INLINE bool bBSP430uptimeIsValid ( unsigned long  duration_utt)
static

Determine whether an uptime value is valid.

In some contexts, a clock value of zero may be used used to indicate an unassigned value, and a clock value of ~0UL is used to indicate an assigned invalid value. Determine whether the provided time is valid (i.e., not one of these reserved identifying values).

See also
ulBSP430uptimeValidated()
static BSP430_CORE_INLINE hBSP430halTIMER hBSP430uptimeTimer ( void  )
static

Get access to the timer controlling the uptime infrastructure.

You might need this if you want to hook into its callbacks.

Don't hook into the overflow callback, please.

Examples:
sensors/hh10d/main.c.
int iBSP430uptimeDelaySetEnabled_ni ( int  enablep)

Enable or disable the alarm used by ulBSP430uptimeDelayUntil().

This delegates to iBSP430timerAlarmSetEnabled_ni().

The alarm is enabled by vBSp430uptimeStart_ni() if configBSP430_UPTIME_DELAY is enabled.

Dependency:
configBSP430_UPTIME_DELAY
long lBSP430uptimeSleepUntil ( unsigned long  setting_utt,
unsigned int  lpm_bits 
)

Sleep until the uptime timer reaches a particular value.

This uses BSP430_UPTIME_DELAY_CCIDX and the Alarm-related Timer Functionality to sleep until either a specific time has been reached or an interrupt wakes the processor.

Note
Interrupts are enabled during this sleep, and an interrupt unrelated to the wakeup alarm will cause an early return. If such an interrupt does not clear GIE on exit there will be a short window between wakeup and when this function clears GIE again in which additional interrupts may execute. See Interrupts and Critical Sections.
Warning
This function may enable interrupts and sleep until its completion conditions are met.
Parameters
setting_uttThe uptime counter value at which the application wishes to be awakened if no events have occured before then. Note that the call is a wrapper around iBSP430timerAlarmSet_ni() and may return immediately with an error result if the specified time appears to be in the past.
lpm_bitsThe bits to be set in the status register to control the low power mode used while awaiting the wakeup time. A value such as LPM0_bits or LPM2_bits should be used depending on application needs. GIE will be added to these bits.
Warning
Consider whether the LPM mode might disable the clock or timer on which the wakeup depends. In many recent MCUs the LPM mode will be internally masked to ensure this does not happen. However, on 4xx MCUs setting LPM4_bits when ACLK drives the uptime timer will cause the system to hang. Use LPM3_bits as a default when only the delay is important.
Returns
The number of timer ticks remaining until the originally-requested time. If an error occurs, a zero value will be returned. There is no facility to tell whether wakeup occurred due to the alarm or another interrupt, except that if the return value is positive it is likely another interrupt is the cause.
Note
The function is not implemented unless configBSP430_UPTIME_DELAY is enabled.
Warning
This function does not diagnose specific errors such as invoking it while the uptime timer or the delay alarm are disabled.
Dependency:
configBSP430_UPTIME_DELAY
static BSP430_CORE_INLINE unsigned int uiBSP430uptimeActivity_ppt ( sBSP430uptimeActivityTotals sp)
static

Return the per-mille activity measure.

This is the ratio of total active time to total time, expressed as parts-per-thousand. The value is rounded to the nearest integer.

Parameters
sppointer to the activity record.
static BSP430_CORE_INLINE unsigned int uiBSP430uptimeCounter_ni ( void  )
static

Return the low word of the system uptime counter.

This is suitable for use by applications that wish to configure capture/compare registers on hBSP430uptimeTimer().

Examples:
sensors/hh10d/main.c.
unsigned int uiBSP430uptimeScaleForDisplay ( unsigned long long  duration_utt,
const char **  unitp 
)

Convert a duration in ticks to a scaled value suitable for display.

This is useful when the code needs to accommodate a wide range of times, from microseconds to hours. The duration value is scaled to reduce the number of digits required to represent it, and the selected unit specifier returned in an output parameter. The cutoff for each unit is:

Time Units
< 10ms us
< 10s ms
< 3min s
< 3h min
>= 3h h
Parameters
duration_utta count in ticks
unitpa pointer to where to store the standard unit description for the scaled value
Returns
the duration expressed in units, rounded down to a whole number.
static BSP430_CORE_INLINE unsigned long ulBSP430uptime ( void  )
static

Return the system uptime in clock ticks.

Examples:
periph/timer/alarm/main.c, and utility/m25p/main.c.
static BSP430_CORE_INLINE unsigned long ulBSP430uptime_ni ( void  )
static

Return system uptime in clock ticks with disabled interrupts.

Note
The returned value is adjusted for a single pending overflow event that occurs while interrupts are disabled, but will be wrong if interrupts remain disabled long enough for a second overflow to occur. See ulBSP430timerCounter_ni() for details.

vBSP430timerSafeCounterInitialize_ni() will have been called on BSP430_UPTIME_TIMER_PERIPH_HANDLE so BSP430_TIMER_VALID_COUNTER_READ_CCIDX is reserved to support accurate counter reads.

Examples:
bootstrap/applpm/main.c, rf/cc3000/cli/main.c, sensors/ds18b20/main.c, sensors/hh10d/main.c, sensors/venus6pps/main.c, utility/cli/main.c, and utility/u8glib/main.c.
unsigned long ulBSP430uptimeConversionFrequency_Hz ( void  )

Return the uptime clock conversion frequency.

This is the number of uptime ticks in a standard second, and is used when translating between tick measurements and second-based durations. The default value is the estimated frequency of the timer underlying the uptime clock (per ulBSP430timerFrequency_Hz_ni()), but this may be overridden by ulBSP430uptimeSetConversionFrequency_ni() when a more accurate estimate of actual frequency is available.

This value is set when vBSP430uptimeStart_ni() or vBSP430uptimeResume_ni() are invoked. Its value is undefined when the uptime timer is stopped. Reconfiguration of the timer source or the underlying clock while the timer is running may invalidate its value.

Returns
The conversion frequency of the uptime clock, in Hz.
Examples:
sensors/ds18b20/main.c, sensors/hh10d/main.c, sensors/venus6pps/main.c, and utility/cli/main.c.
unsigned long ulBSP430uptimeSetConversionFrequency_ni ( unsigned long  frequency_Hz)

Set the uptime frequency that will be used for tick/time conversion.

In cases where the uptime clock derives from VLOCLK, the nominal frequency used by default may be off by as much as 10% from the actual frequency. This function can be used when a more accurate estimate of actual frequency is available to decrease the error in converted times.

Parameters
frequency_Hzthe frequency to be used when converting durations in ticks to durations in seconds or related units. If a value of zero is provided, the current nominal frequency will be used in subsequent conversions.
Returns
the previous value of the conversion frequency, which may be 0 if no conversions had occured.
static BSP430_CORE_INLINE unsigned long ulBSP430uptimeValidated ( unsigned long  duration_utt)
static

Adjust a timestamp if necessary to make it valid.

If the value of the timestamp happens to match one of the reserved invalid values, invert the least significant bit so the value is a valid time, albeit off by one tick.

(A legitimate uptime clock will coincidently match one of the invalid values only for two clock ticks at each 32-bit uptime clock rollover.)

See also
bBSP430uptimeIsValid()
static BSP430_CORE_INLINE unsigned long long ullBSP430uptime ( void  )
static

Return the system uptime in clock ticks at its full precision

This incorporates the overflow and the current counter. On the MSP430 the result is expected to be a 64-bit value of which the low 48-bits are valid.

static BSP430_CORE_INLINE unsigned long long ullBSP430uptimeCorrected ( unsigned int  ctr)
static

Adjust a captured 16-bit counter to a full resolution timestamp.

This obtains the current time, then adjusts it backwards to be the most recent time for which the low 16 bits match ctr. The result should be a 48-bit timestamp expressed in a 64-bit unsigned integer.

See also
ullBSP430timerCorrected()
void vBSP430uptimeActivityReset ( sBSP430uptimeActivityTotals sp,
bool  from_now 
)

Initialize state to record activity levels.

This can be used to measure the amount of time spent in active and sleep modes, with the following pattern:

sBSP430uptimeActivityTotals busy;
// initialize the application
vBSP430uptimeActivityReset(&busy, false);
while (1) {
// do stuff
BSP430_CORE_DISABLE_INTERRUPT();
if (go_to_sleep) {
vBSP430uptimeActivityStartSleep_ni(&busy);
BSP430_CORE_LPM_ENTER_NI(LPM4_bits);
vBSP430uptimeActivityStartActive_ni(&busy);
} else {
BSP430_CORE_ENABLE_INTERRUPT();
}
}

See uiBSP430uptimeActivity_ppt() for extracting the basic duty cycle ratio.

Parameters
sppointer to the activity record to initialize
from_nowwhether accounting should start from now. Passing false is normal, and counts active durations from power-up. If the application initialization code should be excluded, pass true to set the last sleep and wake to the current time.
static BSP430_CORE_INLINE void vBSP430uptimeActivityStartActive_ni ( sBSP430uptimeActivityTotals sp)
static

Record activity times after waking from sleep mode.

Parameters
sppointer to the activity record.
See also
vBSP430uptimeActivityReset()
static BSP430_CORE_INLINE void vBSP430uptimeActivityStartSleep_ni ( sBSP430uptimeActivityTotals sp)
static

Record activity times prior to entering sleep mode.

Parameters
sppointer to the activity record.
See also
vBSP430uptimeActivityReset()
void vBSP430uptimeResume_ni ( void  )

Resume the system uptime clock

The clocks are re-enabled to continue counting from their last recorded value. Also, the conversion frequency used by ulBSP430uptimeConversionFrequency_Hz() is updated based on the current timer configuration.

Examples:
bootstrap/applpm/main.c.
void vBSP430uptimeStart_ni ( void  )

Configure the system uptime clock.

The timer associated with the uptime clock is reset to zero and begins counting up.

Warning
This should be invoked once, normally by vBSP430platformInitialize_ni(). Invoking it a second time may result in undefined behavior. Use vBSP430uptimeSuspend_ni() and vBSP430uptimeResume_ni() to turn the uptime timer off and on.
void vBSP430uptimeSuspend_ni ( void  )

Suspend the system uptime clock.

Suspension means that the clocks are halted and interrupts from them inhibited. Counter values are not modified. vBSP430uptimeResume_ni should be invoked to release the clocks to continue counting.

The system clock may be suspended prior to entering certain low power modes.

Examples:
bootstrap/applpm/main.c.
const char* xBSP430uptimeAsText ( unsigned long  duration_utt,
char *  buffer 
)

Convert an uptime count to text HHH:MM:SS.mmm format.

At least the MM:SS.mmm portion is present, with minutes space-padded on the left. If the duration exceeds 59:59.999, then space-padded hours will be included as well, and minutes will be zero-padded.

The conversion factor from ulBSP430uptimeConversionFrequency_Hz() is used.

Parameters
duration_utta duration in uptime ticks
buffera pointer to a buffer large enough to hold the represented data, normally BSP430_UPTIME_AS_TEXT_LENGTH characters
Returns
buffer
Examples:
rf/cc3000/cli/main.c, sensors/hh10d/main.c, sensors/venus6pps/main.c, and utility/m25p/main.c.
const char* xBSP430uptimeAsText_ni ( unsigned long  duration_utt)

Convert an uptime count to text HH:MM:SS.mmm format in a static buffer.

Invokes xBSP430uptimeAsText() with a static 14-character buffer adequate for representing durations up to 999:59:59.999 in contexts where allocating storage is problematic.

Parameters
duration_uttsee xBSP430uptimeAsText()
Returns
a pointer to the static storage holding the formatted time.
Deprecated:
Legacy interface, use xBSP430uptimeAsText().
Examples:
periph/timer/alarm/main.c, rf/cc3000/cli/main.c, sensors/ds18b20/main.c, and utility/cli/main.c.