24 #define NSEC_PER_SEC 1000000000 25 #define ClockTimeSyncInterval_initial 1.0 26 #define ClockTimeSyncInterval_normal 60.0 43 #if defined(CLOCK_REALTIME) && !defined(_WIN32) && !defined(__APPLE__) 53 #if defined(vxWorks) || defined(__rtems__) 54 static void ClockTimeSync(
void *
dummy);
59 static const iocshArg *
const ReportArgs[1] = { &ReportArg0 };
60 static const iocshFuncDef ReportFuncDef = {
"ClockTime_Report", 1, ReportArgs};
68 static void ShutdownCallFunc(
const iocshArgBuf *args)
76 static void ClockTime_InitOnce(
void *pfirst)
104 #if defined(vxWorks) || defined(__rtems__) 110 ClockTimeSync,
NULL);
112 errlogPrintf(
"Clock synchronization must be performed by the OS\n");
144 *pDest = ClockTimePvt.startTime;
150 #if defined(vxWorks) || defined(__rtems__) 151 CLOCKTIME_SYNCHOOK ClockTime_syncHook =
NULL;
153 static void ClockTimeSync(
void *
dummy)
158 ClockTimePvt.ClockTimeSyncInterval);
161 ClockTimePvt.ClockTimeSyncInterval)) {
170 if (clock_settime(CLOCK_REALTIME, &clockNow)) {
176 if (!ClockTimePvt.synchronized) {
177 ClockTimePvt.startTime = timeNow;
178 ClockTimePvt.synchronized = 1;
180 ClockTimePvt.syncFromPriority = priority;
181 ClockTimePvt.syncTime = timeNow;
184 if (ClockTime_syncHook)
185 ClockTime_syncHook(1);
191 ClockTimePvt.synchronized = 0;
192 if (ClockTime_syncHook)
193 ClockTime_syncHook(0);
206 #ifdef CLOCK_REALTIME_HR 207 clock_gettime(CLOCK_REALTIME_HR, &clockNow) &&
210 clock_gettime(CLOCK_REALTIME, &clockNow);
212 if (!ClockTimePvt.synchronized &&
215 clockNow.tv_nsec = 0;
217 #if defined(vxWorks) || defined(__rtems__) 218 clock_settime(CLOCK_REALTIME, &clockNow);
219 errlogPrintf(
"WARNING: OS Clock time was read before being set.\n" 220 "Using 1990-01-02 00:00:00.000000 UTC\n");
222 errlogPrintf(
"WARNING: OS Clock pre-dates the EPICS epoch!\n" 223 "Using 1990-01-02 00:00:00.000000 UTC\n");
232 #define UNINIT_ERROR "initialized" 234 #define UNINIT_ERROR "available" 255 synchronized = ClockTimePvt.synchronized;
256 syncFromPriority = ClockTimePvt.syncFromPriority;
257 startTime = ClockTimePvt.startTime;
258 syncTime = ClockTimePvt.syncTime;
262 printf(
"OS Clock driver is synchronized to a priority=%d provider\n",
266 "%Y-%m-%d %H:%M:%S.%06f", &startTime);
267 printf(
"Initial sync was at %s\n", timebuf);
269 "%Y-%m-%d %H:%M:%S.%06f", &syncTime);
270 printf(
"Last successful sync was at %s\n", timebuf);
272 printf(
"Syncronization interval = %.0f seconds\n",
273 ClockTimePvt.ClockTimeSyncInterval);
276 printf(
"OS Clock driver is *not* synchronized\n");
280 "%Y-%m-%d %H:%M:%S.%06f", &ClockTimePvt.startTime);
281 printf(
"Program started at %s\n", timebuf);
282 printf(
"OS Clock synchronization thread not running.\n");
LIBCOM_API int epicsStdCall epicsTimeFromTimespec(epicsTimeStamp *pDest, const struct timespec *pSrc)
Set epicsTimeStamp from struct timespec
The generalTime framework provides a mechanism for several time providers to be present within the sy...
int generalTimeRegisterCurrentProvider(const char *name, int priority, TIMECURRENTFUN getTime)
void taskwdInsert(epicsThreadId tid, TASKWDFUNC callback, void *usr)
void ClockTime_Init(int synchronize)
LIBCOM_API void ClockTime_GetProgramStart(epicsTimeStamp *pDest)
LIBCOM_API int epicsStdCall epicsTimeToTimespec(struct timespec *pDest, const epicsTimeStamp *pSrc)
Convert epicsTimeStamp to struct timespec
void epicsStdCall iocshRegister(const iocshFuncDef *piocshFuncDef, iocshCallFunc func)
#define epicsTimeOK
Success.
LIBCOM_API epicsEventStatus epicsEventWaitWithTimeout(epicsEventId id, double timeOut)
Wait an the event or until the specified timeout period is over.
LIBCOM_API epicsEventId epicsEventMustCreate(epicsEventInitialState initialState)
Create an epicsEvent for use from C code.
void epicsStdCall epicsMutexUnlock(epicsMutexId pmutexNode)
Release the semaphore.
LIBCOM_API unsigned int epicsStdCall epicsThreadGetStackSize(epicsThreadStackSizeClass size)
epicsThreadId epicsStdCall epicsThreadCreate(const char *name, unsigned int priority, unsigned int stackSize, EPICSTHREADFUNC funptr, void *parm)
int osdTimeGetCurrent(epicsTimeStamp *pDest)
LIBCOM_API size_t epicsStdCall epicsTimeToStrftime(char *pBuff, size_t bufLength, const char *pFormat, const epicsTimeStamp *pTS)
Convert epicsTimeStamp to string. See epicsTime::strftime()
#define EPICS_THREAD_ONCE_INIT
#define epicsEventSignal(ID)
A synonym for epicsEventTrigger().
APIs for the epicsMutex mutual exclusion semaphore.
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
Extended replacement for the Posix exit and atexit routines.
#define POSIX_TIME_AT_EPICS_EPOCH
The EPICS Epoch is 00:00:00 Jan 1, 1990 UTC.
#define ClockTimeSyncInterval_initial
int errlogPrintf(const char *pFormat,...)
#define LAST_RESORT_PRIORITY
APIs for the epicsEvent binary semaphore.
epics::pvData::PVStructurePtr dummy
#define epicsThreadPriorityHigh
void taskwdRemove(epicsThreadId tid)
int generalTimeGetExceptPriority(epicsTimeStamp *pDest, int *pPrio, int ignore)
EPICS time stamp, for use from C code.
#define epicsMutexCreate()
Create an epicsMutex semaphore for use from C code.
void ClockTime_Shutdown(void *dummy)
Defined by POSIX Real Time.
#define ClockTimeSyncInterval_normal
#define epicsAtExit(F, A)
Convenience macro to register a function and context value to be run when the process exits...
int ClockTime_Report(int level)
C++ and C descriptions for a thread.
#define epicsMutexMustLock(ID)
Claim a semaphore (see epicsMutexLock()).
double ClockTimeSyncInterval