This is Unofficial EPICS BASE Doxygen Site
epicsGeneralTime.h File Reference

The generalTime framework provides a mechanism for several time providers to be present within the system. More...

#include "libComAPI.h"
+ Include dependency graph for epicsGeneralTime.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NUM_TIME_EVENTS   256
 The number of time events that are validated. More...
 
#define generalTimeCurrentTpName   generalTimeCurrentProviderName
 Old name provided for backwards compatibility. More...
 
#define generalTimeEventTpName   generalTimeEventProviderName
 Old name provided for backwards compatibility. More...
 

Functions

LIBCOM_API void generalTime_Init (void)
 Initialise the framework. More...
 
LIBCOM_API int installLastResortEventProvider (void)
 Install a Time Event time provider that returns the current time for any Time event number. More...
 
LIBCOM_API void generalTimeResetErrorCounts (void)
 Reset the internal counter of the number of times the time returned was earlier than when previously requested. More...
 
LIBCOM_API int generalTimeGetErrorCounts (void)
 Return the internal counter of the number of times the time returned was earlier than when previously requested. More...
 
LIBCOM_API const char * generalTimeCurrentProviderName (void)
 Return the nume of the provider that last returned a valid current time, or NULL if none. More...
 
LIBCOM_API const char * generalTimeEventProviderName (void)
 Return the name of the provider that last returned a valid Time Event time, or NULL of none. More...
 
LIBCOM_API const char * generalTimeHighestCurrentName (void)
 Return the name of the registered current time provider that has the highest priority. More...
 
LIBCOM_API long generalTimeReport (int interest)
 Provide information about the installed providers and their current best times. More...
 

Detailed Description

The generalTime framework provides a mechanism for several time providers to be present within the system.

There are two types of time provider, one type provides the current wall-clock time, the other provides Event System times. Each time provider is registered with a priority, and installed providers are queried in priority order whenever a time is requested, until one returns successfully. Thus there is a fallback from higher priority providers (smaller value of priority) to lower priority providers (larger value of priority) if the highest priority ones fail. Each architecture has a "last resort" provider, installed at priority 999, usually based on the system clock, which is used in the absence of any other provider.

Targets running VxWorks and RTEMS have an NTP provider installed at priority 100.

Registered providers may also add an interrupt-safe routine that will be called from the epicsTimeGetCurrentInt() or epicsTimeGetEventInt() API routines. These interfaces cannot check the priority queue, so will only succeed if the last-used provider has registered a suitable routine.

Note
There are two interfaces to this framework, epicsGeneralTime.h for consumers to obtain a time and query the framework, and generalTimeSup.h for providers that can supply timestamps.

Definition in file epicsGeneralTime.h.

Macro Definition Documentation

#define generalTimeCurrentTpName   generalTimeCurrentProviderName

Old name provided for backwards compatibility.

Definition at line 140 of file epicsGeneralTime.h.

#define generalTimeEventTpName   generalTimeEventProviderName

Old name provided for backwards compatibility.

Definition at line 142 of file epicsGeneralTime.h.

#define NUM_TIME_EVENTS   256

The number of time events that are validated.

Time Events numbered 0 through (NUM_TIME_EVENTS-1) are validated by code in epicsGeneralTime.c that tests for advancing timestamps and enforces that restriction.

Note
Event numbers greater than or equal to NUM_TIME_EVENTS are now allowed if supported by a custom time provider which should provide its own advancing timestamp validation.

Definition at line 56 of file epicsGeneralTime.h.

Function Documentation

LIBCOM_API void generalTime_Init ( void  )

Initialise the framework.

This routine is called automatically by any function that requires the framework. It does not need to be called explicitly.

Definition at line 99 of file epicsGeneralTime.c.

100 {
101  epicsThreadOnce(&onceId, generalTime_InitOnce, NULL);
102 }
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
LIBCOM_API const char* generalTimeCurrentProviderName ( void  )

Return the nume of the provider that last returned a valid current time, or NULL if none.

Used by stringin device support with:

1 DTYP = "General Time"
2 INP = "@BESTTCP"
Returns
Provider name

Definition at line 638 of file epicsGeneralTime.c.

639 {
640  if (gtPvt.lastTimeProvider)
641  return gtPvt.lastTimeProvider->name;
642  return NULL;
643 }
#define NULL
Definition: catime.c:38
LIBCOM_API const char* generalTimeEventProviderName ( void  )

Return the name of the provider that last returned a valid Time Event time, or NULL of none.

Used by stringin device support with:

1 DTYP = "General Time"
2 INP = "@BESTTEP"
Returns
Provider name

Definition at line 645 of file epicsGeneralTime.c.

646 {
647  if (gtPvt.lastEventProvider)
648  return gtPvt.lastEventProvider->name;
649  return NULL;
650 }
#define NULL
Definition: catime.c:38
LIBCOM_API int generalTimeGetErrorCounts ( void  )

Return the internal counter of the number of times the time returned was earlier than when previously requested.

Used by device support for longin record with:

1 DTYP = "General Time"
2 INP = "@GETERRCNT"
Returns
Reset error counts

Definition at line 630 of file epicsGeneralTime.c.

631 {
632  int key = epicsInterruptLock();
633  int errors = gtPvt.ErrorCounts;
635  return errors;
636 }
LIBCOM_API void epicsInterruptUnlock(int key)
Definition: osdInterrupt.c:41
LIBCOM_API int epicsInterruptLock(void)
Definition: osdInterrupt.c:34
LIBCOM_API const char* generalTimeHighestCurrentName ( void  )

Return the name of the registered current time provider that has the highest priority.

Used by stringin device support with:

1 DTYP = "General Time"
2 INP = "@TOPTCP"
Returns
Provider name

Definition at line 652 of file epicsGeneralTime.c.

653 {
654  gtProvider *ptp;
655 
656  epicsMutexMustLock(gtPvt.timeListLock);
657  ptp = (gtProvider *)ellFirst(&gtPvt.timeProviders);
658  epicsMutexUnlock(gtPvt.timeListLock);
659  return ptp ? ptp->name : NULL;
660 }
#define NULL
Definition: catime.c:38
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
Definition: epicsMutex.cpp:140
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
Definition: epicsMutex.h:214
#define ellFirst(PLIST)
Find the first node in list.
Definition: ellLib.h:89
LIBCOM_API long generalTimeReport ( int  interest)

Provide information about the installed providers and their current best times.

Parameters
interestDesired interest level to report

Definition at line 529 of file epicsGeneralTime.c.

530 {
531  int items;
532 
533  if (onceId == EPICS_THREAD_ONCE_INIT) {
534  printf("General time framework not yet initialized.\n");
535  return epicsTimeOK;
536  }
537 
538  printf("Backwards time errors prevented %u times.\n\n",
540 
541  /* Use an output buffer to avoid holding mutexes during printing */
542 
543  printf("Current Time Providers:\n");
544  epicsMutexMustLock(gtPvt.timeListLock);
545  if ((items = ellCount(&gtPvt.timeProviders))) {
546  gtProvider *ptp;
547  char *message; /* Temporary output buffer */
548  char *pout;
549 
550  message = calloc(items, 80 * 2); /* Each provider needs 2 lines */
551  if (!message) {
552  epicsMutexUnlock(gtPvt.timeListLock);
553  printf("Out of memory\n");
554  return S_time_noMemory;
555  }
556 
557  pout = message;
558 
559  for (ptp = (gtProvider *)ellFirst(&gtPvt.timeProviders);
560  ptp; ptp = (gtProvider *)ellNext(&ptp->node)) {
561  pout += sprintf(pout, " \"%s\", priority = %d\n",
562  ptp->name, ptp->priority);
563  if (level) {
564  epicsTimeStamp tempTS;
565  if (ptp->get.Time(&tempTS) == epicsTimeOK) {
566  char tempTSText[40];
567  epicsTimeToStrftime(tempTSText, sizeof(tempTSText),
568  "%Y-%m-%d %H:%M:%S.%06f", &tempTS);
569  pout += sprintf(pout, "\tCurrent Time is %s.\n",
570  tempTSText);
571  } else {
572  pout += sprintf(pout, "\tCurrent Time not available\n");
573  }
574  }
575  }
576  epicsMutexUnlock(gtPvt.timeListLock);
577  puts(message);
578  free(message);
579  } else {
580  epicsMutexUnlock(gtPvt.timeListLock);
581  printf("\tNo Providers registered.\n");
582  }
583 
584  printf("Event Time Providers:\n");
585  epicsMutexMustLock(gtPvt.eventListLock);
586  if ((items = ellCount(&gtPvt.eventProviders)))
587  {
588  gtProvider *ptp;
589  char *message; /* Temporary output buffer */
590  char *pout;
591 
592  message = calloc(items, 80); /* Each provider needs 1 line, */
593  if (!message) {
594  epicsMutexUnlock(gtPvt.eventListLock);
595  printf("Out of memory\n");
596  return S_time_noMemory;
597  }
598 
599  pout = message;
600 
601  for (ptp = (gtProvider *)ellFirst(&gtPvt.eventProviders);
602  ptp; ptp = (gtProvider *)ellNext(&ptp->node)) {
603  pout += sprintf(pout, " \"%s\", priority = %d\n",
604  ptp->name, ptp->priority);
605  }
606  epicsMutexUnlock(gtPvt.eventListLock);
607  puts(message);
608  free(message);
609  }
610  else
611  {
612  epicsMutexUnlock(gtPvt.eventListLock);
613  printf("\tNo Providers registered.\n");
614  }
615 
616  return epicsTimeOK;
617 }
#define ellCount(PLIST)
Report the number of nodes in a list.
Definition: ellLib.h:84
union gtProvider::@15 get
#define printf
Definition: epicsStdio.h:41
#define epicsTimeOK
Success.
Definition: epicsTime.h:339
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
Definition: epicsMutex.cpp:140
#define ellNext(PNODE)
Find the next node in list.
Definition: ellLib.h:99
LIBCOM_API size_t epicsStdCall epicsTimeToStrftime(char *pBuff, size_t bufLength, const char *pFormat, const epicsTimeStamp *pTS)
Convert epicsTimeStamp to string. See epicsTime::strftime()
Definition: epicsTime.cpp:1120
#define EPICS_THREAD_ONCE_INIT
Definition: epicsThread.h:109
#define puts
Definition: epicsStdio.h:46
#define S_time_noMemory
Out of memory.
Definition: epicsTime.h:347
TIMECURRENTFUN Time
EPICS time stamp, for use from C code.
Definition: epicsTime.h:33
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
Definition: epicsMutex.h:214
int generalTimeGetErrorCounts(void)
Return the internal counter of the number of times the time returned was earlier than when previously...
#define ellFirst(PLIST)
Find the first node in list.
Definition: ellLib.h:89
LIBCOM_API void generalTimeResetErrorCounts ( void  )

Reset the internal counter of the number of times the time returned was earlier than when previously requested.

Used by device support for binary out record with:

1 DTYP = "General Time"
2 OUT = "@RSTERRCNT"

Definition at line 623 of file epicsGeneralTime.c.

624 {
625  int key = epicsInterruptLock();
626  gtPvt.ErrorCounts = 0;
628 }
LIBCOM_API void epicsInterruptUnlock(int key)
Definition: osdInterrupt.c:41
LIBCOM_API int epicsInterruptLock(void)
Definition: osdInterrupt.c:34
LIBCOM_API int installLastResortEventProvider ( void  )

Install a Time Event time provider that returns the current time for any Time event number.

Note
This is optional as it is site policy whether the last resort for a Time Event time in the absence of any working provider should be a failure, or the current time.

Definition at line 520 of file epicsGeneralTime.c.

521 {
522  return generalTimeEventTpRegister("Last Resort Event",
523  LAST_RESORT_PRIORITY, lastResortGetEvent);
524 }
#define generalTimeEventTpRegister
#define LAST_RESORT_PRIORITY