mrfioc2  2.3.0
Classes | Macros | Functions
ntpShm.cpp File Reference
#include <stdio.h>
#include <errno.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <epicsTime.h>
#include <epicsVersion.h>
#include <epicsMutex.h>
#include <epicsThread.h>
#include <epicsStdio.h>
#include <callback.h>
#include <drvSup.h>
#include <recGbl.h>
#include <longinRecord.h>
#include <aiRecord.h>
#include <menuConvert.h>
#include <dbScan.h>
#include <iocsh.h>
#include <initHooks.h>
#include "evr/evr.h"
#include <epicsExport.h>
Include dependency graph for ntpShm.cpp:

Go to the source code of this file.

Classes

struct  shmSegment
 
struct  ntpShmPriv
 
struct  commonset
 

Macros

#define SYNC()   do{}while(0)
 
#define NTPD_SEG0   0x4E545030
 
#define RETRY_TIME   30.0
 

Functions

void time2ntp (const char *evrname, int segid, int event)
 
 epicsExportAddress (drvet, ntpShared)
 
 epicsExportAddress (dset, devNtpShmLiOk)
 
 epicsExportAddress (dset, devNtpShmLiFail)
 
 epicsExportAddress (dset, devNtpShmAiDelta)
 
 epicsExportRegistrar (ntpShmRegister)
 

Macro Definition Documentation

◆ NTPD_SEG0

#define NTPD_SEG0   0x4E545030

Definition at line 68 of file ntpShm.cpp.

◆ RETRY_TIME

#define RETRY_TIME   30.0

Definition at line 70 of file ntpShm.cpp.

◆ SYNC

#define SYNC ( )    do{}while(0)

Definition at line 64 of file ntpShm.cpp.

Function Documentation

◆ epicsExportAddress() [1/4]

epicsExportAddress ( drvet  ,
ntpShared   
)

◆ epicsExportAddress() [2/4]

epicsExportAddress ( dset  ,
devNtpShmLiOk   
)

◆ epicsExportAddress() [3/4]

epicsExportAddress ( dset  ,
devNtpShmLiFail   
)

◆ epicsExportAddress() [4/4]

epicsExportAddress ( dset  ,
devNtpShmAiDelta   
)

◆ epicsExportRegistrar()

epicsExportRegistrar ( ntpShmRegister  )

◆ time2ntp()

void time2ntp ( const char *  evrname,
int  segid,
int  event 
)

Definition at line 266 of file ntpShm.cpp.

267 {
268  try {
269  if(event==0)
270  event = MRF_EVENT_TS_COUNTER_RST;
271  else if(event<=0 || event >255) {
272  fprintf(stderr, "Invalid 1Hz event # %d\n", event);
273  return;
274  }
275  if(segid<0 || segid>4) {
276  fprintf(stderr, "Invalid segment ID %d\n", segid);
277  return;
278  }
279  mrf::Object *obj = mrf::Object::getObject(evrname);
280  if(!obj) {
281  fprintf(stderr, "Unknown EVR: %s\n", evrname);
282  return;
283  }
284 
285  EVR *evr = dynamic_cast<EVR*>(obj);
286  if(!evr) {
287  fprintf(stderr, "\"%s\" is not an EVR\n", evrname);
288  return;
289  }
290 
291  epicsThreadOnce(&ntponce, &ntpshminit, 0);
292 
293  epicsMutexMustLock(ntpShm.ntplock);
294 
295  if(ntpShm.evr) {
296  epicsMutexUnlock(ntpShm.ntplock);
297  fprintf(stderr, "ntpShm already initialized.\n");
298  return;
299  }
300 
301  ntpShm.event = event;
302  ntpShm.evr = evr;
303  ntpShm.segid = segid;
304 
305  epicsMutexUnlock(ntpShm.ntplock);
306  } catch(std::exception& e) {
307  fprintf(stderr, "Error: %s\n", e.what());
308  }
309 }
epicsUInt32 event
Definition: ntpShm.cpp:102
epicsMutexId ntplock
Definition: ntpShm.cpp:98
Base object inspection.
Definition: object.h:378
static Object * getObject(const std::string &name)
Definition: object.cpp:107
int segid
Definition: ntpShm.cpp:105
Base interface for EVRs.
Definition: evr.h:45
#define MRF_EVENT_TS_COUNTER_RST
Definition: mrfCommon.h:124
EVR * evr
Definition: ntpShm.cpp:104