From 09194d18718c5d721561c83584dbfc8550846af7 Mon Sep 17 00:00:00 2001 From: "W. Eric Norum" Date: Mon, 24 Apr 2000 19:27:18 +0000 Subject: [PATCH] Rename file to match EPICS C++ convention. --- src/libCom/osi/os/RTEMS/osdTime.cpp | 89 +++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/libCom/osi/os/RTEMS/osdTime.cpp diff --git a/src/libCom/osi/os/RTEMS/osdTime.cpp b/src/libCom/osi/os/RTEMS/osdTime.cpp new file mode 100644 index 000000000..ffafd24c6 --- /dev/null +++ b/src/libCom/osi/os/RTEMS/osdTime.cpp @@ -0,0 +1,89 @@ +/* + * $Id$ + * + * Author: W. Eric Norum + */ +// + +/* + * ANSI C + */ +#include +#include + +/* + * RTEMS + */ +#include +#include + +/* + * EPICS + */ +#define epicsExportSharedSymbols +#include "osiTime.h" +#include "errlog.h" + +extern "C" { +/* + * RTEMS clock rate + */ +rtems_interval rtemsTicksPerSecond; +double rtemsTicksPerSecond_double; + +/* + * RTEMS time begins January 1, 1988 (local time). + * EPICS time begins January 1, 1990 (GMT). + * + * FIXME: How to handle daylight-savings time? + */ +#define EPICS_EPOCH_SEC_PAST_RTEMS_EPOCH ((366+365)*86400) +static unsigned long timeoffset; + +/* + * Get current time + * Allow for this to be called before clockInit() and before + * system time and date have been initialized. + */ +int tsStampGetCurrent (TS_STAMP *pDest) +{ + struct timeval curtime; + rtems_interval t; + rtems_status_code sc; + + for (;;) { + sc = rtems_clock_get (RTEMS_CLOCK_GET_TIME_VALUE, &curtime); + if (sc == RTEMS_SUCCESSFUL) + break; + else if (sc != RTEMS_NOT_DEFINED) + return tsStampERROR; + sc = rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &t); + if (sc != RTEMS_SUCCESSFUL) + return tsStampERROR; + rtems_task_wake_after (t); + } + pDest->nsec = curtime.tv_usec * 1000; + pDest->secPastEpoch = curtime.tv_sec - timeoffset; + return tsStampOK; +} + +/* + * tsStampGetEvent () + */ +int tsStampGetEvent (TS_STAMP *pDest, unsigned eventNumber) +{ + if (eventNumber==tsStampEventCurrentTime) { + return tsStampGetCurrent (pDest); + } + else { + return tsStampERROR; + } +} + +void clockInit(void) +{ + timeoffset = EPICS_EPOCH_SEC_PAST_RTEMS_EPOCH - rtems_bsdnet_timeoffset; + rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &rtemsTicksPerSecond); + rtemsTicksPerSecond_double = rtemsTicksPerSecond; +} +}