111 #ifndef BSP430_UTILITY_UPTIME_H
112 #define BSP430_UTILITY_UPTIME_H
125 #ifndef configBSP430_UPTIME
126 #define configBSP430_UPTIME 0
134 #if defined(BSP430_DOXYGEN)
135 #define BSP430_UPTIME include <bsp430/platform.h>
151 #ifndef configBSP430_UPTIME_EPOCH
152 #define configBSP430_UPTIME_EPOCH 0
168 #ifndef configBSP430_UPTIME_DELAY
169 #define configBSP430_UPTIME_DELAY 0
181 #if defined(BSP430_DOXYGEN)
182 #define BSP430_UPTIME_TIMER_PERIPH_CPPID include "bsp430_config.h"
195 #if defined(BSP430_DOXYGEN)
196 #define BSP430_UPTIME_TIMER_PERIPH_HANDLE platform or application specific
200 #elif BSP430_UPTIME_TIMER_PERIPH_CPPID == BSP430_PERIPH_CPPID_TA0
201 #define BSP430_UPTIME_TIMER_PERIPH_HANDLE BSP430_PERIPH_TA0
203 #elif BSP430_UPTIME_TIMER_PERIPH_CPPID == BSP430_PERIPH_CPPID_TA1
204 #define BSP430_UPTIME_TIMER_PERIPH_HANDLE BSP430_PERIPH_TA1
206 #elif BSP430_UPTIME_TIMER_PERIPH_CPPID == BSP430_PERIPH_CPPID_TA2
207 #define BSP430_UPTIME_TIMER_PERIPH_HANDLE BSP430_PERIPH_TA2
209 #elif BSP430_UPTIME_TIMER_PERIPH_CPPID == BSP430_PERIPH_CPPID_TA3
210 #define BSP430_UPTIME_TIMER_PERIPH_HANDLE BSP430_PERIPH_TA3
212 #elif BSP430_UPTIME_TIMER_PERIPH_CPPID == BSP430_PERIPH_CPPID_TB0
213 #define BSP430_UPTIME_TIMER_PERIPH_HANDLE BSP430_PERIPH_TB0
215 #elif BSP430_UPTIME_TIMER_PERIPH_CPPID == BSP430_PERIPH_CPPID_TB1
216 #define BSP430_UPTIME_TIMER_PERIPH_HANDLE BSP430_PERIPH_TB1
218 #elif BSP430_UPTIME_TIMER_PERIPH_CPPID == BSP430_PERIPH_CPPID_TB2
219 #define BSP430_UPTIME_TIMER_PERIPH_HANDLE BSP430_PERIPH_TB2
245 #if defined(BSP430_DOXYGEN)
246 #define configBSP430_UPTIME_TIMER_HAL_CC0_ISR indirectly defaulted
255 #ifndef BSP430_UPTIME_TASSEL
256 #define BSP430_UPTIME_TASSEL TASSEL_1
263 #ifndef BSP430_UPTIME_DIVIDING_SHIFT
264 #define BSP430_UPTIME_DIVIDING_SHIFT 0
277 #if defined(BSP430_DOXYGEN) || (BSP430_UPTIME - 0)
282 return xBSP430uptimeTIMER_;
286 #if (BSP430_UPTIME - 0)
291 extern unsigned long ulBSP430uptimeConversionFrequency_Hz_ni_;
332 #if defined(BSP430_DOXYGEN) || (BSP430_UPTIME - 0)
335 #define BSP430_UPTIME_MS_TO_UTT(ms_) BSP430_CORE_MS_TO_TICKS((ms_), ulBSP430uptimeConversionFrequency_Hz())
338 #define BSP430_UPTIME_UTT_TO_MS(utt_) BSP430_CORE_TICKS_TO_MS((utt_), ulBSP430uptimeConversionFrequency_Hz())
341 #define BSP430_UPTIME_US_TO_UTT(us_) BSP430_CORE_US_TO_TICKS((us_), ulBSP430uptimeConversionFrequency_Hz())
344 #define BSP430_UPTIME_UTT_TO_US(utt_) BSP430_CORE_TICKS_TO_US((utt_), ulBSP430uptimeConversionFrequency_Hz())
347 #if defined(BSP430_DOXYGEN) || (BSP430_UPTIME - 0)
384 unsigned int overflow;
392 return (((
unsigned long long)overflow) << (8 *
sizeof(ul))) | ul;
436 return (0 != duration_utt) && (~0UL != duration_utt);
499 #define BSP430_UPTIME_AS_TEXT_LENGTH sizeof("HHH:MM:SS.mmm")
558 const char ** unitp);
619 #if defined(BSP430_DOXYGEN) || (BSP430_UPTIME - 0)
658 unsigned int duty_ppt = 0;
659 if (0 < period_tck) {
660 duty_ppt = (1000 * sp->
awake_utt + (period_tck / 2)) / period_tck;
685 #if defined(BSP430_DOXYGEN) || (configBSP430_UPTIME_DELAY - 0)
686 #ifndef BSP430_UPTIME_DELAY_CCIDX
687 #define BSP430_UPTIME_DELAY_CCIDX 1
736 #if defined(BSP430_DOXYGEN) || (configBSP430_UPTIME_DELAY - 0)
738 unsigned int lpm_bits);
749 #if defined(BSP430_DOXYGEN) || (configBSP430_UPTIME_DELAY - 0)
769 #if defined(BSP430_DOXYGEN) || (configBSP430_UPTIME_DELAY - 0)
770 #define BSP430_UPTIME_DELAY_UTT_NI(delay_utt_, lpm_bits_, exit_expr_) do { \
771 unsigned long wake_utt; \
772 wake_utt = ulBSP430uptime_ni() + (delay_utt_); \
773 while ((! (exit_expr_)) && (0 < lBSP430uptimeSleepUntil(wake_utt, lpm_bits_))) { \
783 #if defined(BSP430_DOXYGEN) || (configBSP430_UPTIME_DELAY - 0)
784 #define BSP430_UPTIME_DELAY_UTT(delay_utt_, lpm_bits_, exit_expr_) do { \
785 BSP430_CORE_SAVED_INTERRUPT_STATE(istate); \
786 BSP430_CORE_DISABLE_INTERRUPT(); \
787 BSP430_UPTIME_DELAY_UTT_NI(BSP430_UPTIME_UTT_TO_UTT(delay_utt_), lpm_bits_, exit_expr_); \
788 BSP430_CORE_RESTORE_INTERRUPT_STATE(istate); \
806 #if defined(BSP430_DOXYGEN) || (configBSP430_UPTIME_DELAY - 0)
807 #define BSP430_UPTIME_DELAY_MS_NI(delay_ms_, lpm_bits_, exit_expr_) do { \
808 BSP430_UPTIME_DELAY_UTT_NI(BSP430_UPTIME_MS_TO_UTT(delay_ms_), lpm_bits_, exit_expr_); \
816 #if defined(BSP430_DOXYGEN) || (configBSP430_UPTIME_DELAY - 0)
817 #define BSP430_UPTIME_DELAY_MS(delay_ms_, lpm_bits_, exit_expr_) do { \
818 BSP430_CORE_SAVED_INTERRUPT_STATE(istate); \
819 BSP430_CORE_DISABLE_INTERRUPT(); \
820 BSP430_UPTIME_DELAY_UTT_NI(BSP430_UPTIME_MS_TO_UTT(delay_ms_), lpm_bits_, exit_expr_); \
821 BSP430_CORE_RESTORE_INTERRUPT_STATE(istate); \
825 #if defined(BSP430_DOXYGEN) || (configBSP430_UPTIME_EPOCH - 0)
827 #include <sys/time.h>
834 #define BSP430_UPTIME_POSIX_EPOCH_NTPIS 2208988800UL
847 #define BSP430_UPTIME_BYPASS_EPOCH_NTP ((uint64_t)(BSP430_UPTIME_POSIX_EPOCH_NTPIS + 1388534400UL) << 32)
923 #define BSP430_UPTIME_EPOCH_UPDATE_INTERVAL_UTT 0x40000000L
931 #define BSP430_UPTIME_EPOCH_VALID_OFFSET_UTT 0x60000000L
982 unsigned long * putt);
1012 unsigned long when_utt);
1038 int bypass_validation);
1054 struct timeval * tv);
1126 int64_t * adjustment_ntp,
1127 long * adjustment_ms,
1128 unsigned long * rtt_us);
unsigned long ulBSP430timerCounter_ni(hBSP430halTIMER timer, unsigned int *overflowp)
unsigned long ulBSP430uptimeSetConversionFrequency_ni(unsigned long frequency_Hz)
unsigned long sleeps
Definition: uptime.h:576
void vBSP430uptimeResume_ni(void)
static BSP430_CORE_INLINE unsigned int uiBSP430uptimeCounter_ni(void)
Definition: uptime.h:417
#define BSP430_CORE_RESTORE_INTERRUPT_STATE(state_)
Definition: core.h:731
struct sBSP430uptimeNTPPacketHeader sBSP430uptimeNTPPacketHeader
int iBSP430uptimeSetEpochFromTimeval(const struct timeval *tv, unsigned long when_utt)
unsigned long long awake_utt
Definition: uptime.h:572
unsigned long ulBSP430uptimeLastEpochUpdate()
static BSP430_CORE_INLINE unsigned int uiBSP430uptimeActivity_ppt(sBSP430uptimeActivityTotals *sp)
Definition: uptime.h:655
unsigned long last_sleep_utt
Definition: uptime.h:581
struct sBSP430uptimeNTPTimestamp sBSP430uptimeNTPTimestamp
unsigned int uiBSP430uptimeScaleForDisplay(unsigned long long duration_utt, const char **unitp)
static BSP430_CORE_INLINE unsigned long long ullBSP430timerCorrected(hBSP430halTIMER timer, unsigned int ctr)
Definition: timer.h:1308
void vBSP430uptimeActivityReset(sBSP430uptimeActivityTotals *sp, bool from_now)
unsigned long long sleep_utt
Definition: uptime.h:574
static BSP430_CORE_INLINE unsigned long ulBSP430timerCounter(hBSP430halTIMER timer, unsigned int *overflowp)
Definition: timer.h:1279
struct sBSP430uptimeActivityTotals sBSP430uptimeActivityTotals
Clock-related functions implemented on all MSP430 MCUs.
Hardware presentation/abstraction for generic timers (Timer_A/Timer_B)
int iBSP430uptimeAsNTP(unsigned long utt, uint64_t *ntpp, int bypass_validation)
void vBSP430uptimeStart_ni(void)
const char * xBSP430uptimeAsText(unsigned long duration_utt, char *buffer)
int iBSP430uptimeSetEpochFromNTP(uint64_t epoch_ntp)
long lBSP430uptimeEpochAge()
static BSP430_CORE_INLINE hBSP430halTIMER hBSP430uptimeTimer(void)
Definition: uptime.h:280
uint32_t fractional
Definition: uptime.h:868
static BSP430_CORE_INLINE unsigned long ulBSP430uptimeValidated(unsigned long duration_utt)
Definition: uptime.h:451
static BSP430_CORE_INLINE void vBSP430uptimeActivityStartActive_ni(sBSP430uptimeActivityTotals *sp)
Definition: uptime.h:641
static BSP430_CORE_INLINE unsigned long long ullBSP430uptime(void)
Definition: uptime.h:381
#define BSP430_CORE_INLINE
Definition: core.h:439
sBSP430hplHALStatePrefix hal_state
Definition: timer.h:1133
long lBSP430uptimeSleepUntil(unsigned long setting_utt, unsigned int lpm_bits)
static BSP430_CORE_INLINE void vBSP430uptimeActivityStartSleep_ni(sBSP430uptimeActivityTotals *sp)
Definition: uptime.h:627
#define BSP430_CORE_SAVED_INTERRUPT_STATE(var_)
Definition: core.h:719
volatile unsigned char flags
Definition: periph.h:285
uint32_t integral
Definition: uptime.h:867
static BSP430_CORE_INLINE unsigned long long ullBSP430uptimeCorrected(unsigned int ctr)
Definition: uptime.h:405
unsigned long ulBSP430uptimeConversionFrequency_Hz(void)
static BSP430_CORE_INLINE_FORCED unsigned int uiBSP430timerBestCounterRead_ni(volatile sBSP430hplTIMER *const hpl, int flags)
Definition: timer.h:3578
int iBSP430uptimeProcessNTPResponse(const sBSP430uptimeNTPPacketHeader *req, const sBSP430uptimeNTPPacketHeader *resp, uint64_t rec_ntp, int64_t *adjustment_ntp, long *adjustment_ms, unsigned long *rtt_us)
void vBSP430uptimeSuspend_ni(void)
int iBSP430uptimeDelaySetEnabled_ni(int enablep)
int iBSP430uptimeAsTimeval(unsigned long utt, struct timeval *tv)
struct sBSP430uptimeNTPShortFormat sBSP430uptimeNTPShortFormat
#define BSP430_CORE_DISABLE_INTERRUPT()
Definition: core.h:762
static BSP430_CORE_INLINE bool bBSP430uptimeIsValid(unsigned long duration_utt)
Definition: uptime.h:434
int iBSP430uptimeSetNTPXmtField(sBSP430uptimeNTPPacketHeader *ntpp, unsigned long *putt)
volatile sBSP430hplTIMER *const hpl
Definition: timer.h:1136
unsigned long last_wake_utt
Definition: uptime.h:579
int iBSP430uptimeAdjustEpochFromNTP(int64_t adjustment_ntp)
int iBSP430uptimeCheckEpochValidity()
int iBSP430uptimeEpochEra(unsigned long time_utt)
static BSP430_CORE_INLINE unsigned long ulBSP430uptime_ni(void)
Definition: uptime.h:361
time_t xBSP430uptimeAsPOSIXTime(unsigned long utt)
int iBSP430uptimeInitializeNTPRequest(sBSP430uptimeNTPPacketHeader *ntpp)
const char * xBSP430uptimeAsText_ni(unsigned long duration_utt)
static BSP430_CORE_INLINE unsigned long ulBSP430uptime(void)
Definition: uptime.h:369