mrfioc2  2.3.0
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
EVRMRM Class Reference

Modular Register Map Event Receivers. More...

#include <drvem.h>

Inheritance diagram for EVRMRM:
Inheritance graph
[legend]
Collaboration diagram for EVRMRM:
Collaboration graph
[legend]

Classes

struct  Config
 

Public Member Functions

 EVRMRM (const std::string &n, bus_configuration &busConfig, const Config *c, volatile unsigned char *, epicsUInt32)
 
virtual ~EVRMRM ()
 
virtual void lock () const OVERRIDE FINAL
 
virtual void unlock () const OVERRIDE FINAL
 
virtual std::string model () const OVERRIDE FINAL
 Hardware model. More...
 
epicsUInt32 fpgaFirmware ()
 
formFactor getFormFactor ()
 
std::string formFactorStr ()
 
virtual MRFVersion version () const OVERRIDE FINAL
 Firmware Version. More...
 
virtual bool enabled () const OVERRIDE FINAL
 
virtual void enable (bool v) OVERRIDE FINAL
 
virtual bool mappedOutputState () const OVERRIDE FINAL
 
MRMGpiogpio ()
 
virtual bool specialMapped (epicsUInt32 code, epicsUInt32 func) const OVERRIDE FINAL
 
virtual void specialSetMap (epicsUInt32 code, epicsUInt32 func, bool) OVERRIDE FINAL
 
virtual double clock () const OVERRIDE FINAL
 
virtual void clockSet (double) OVERRIDE FINAL
 
epicsUInt16 clockMode () const
 
void clockModeSet (epicsUInt16 mode)
 
virtual bool pllLocked () const OVERRIDE FINAL
 Internal PLL Status. More...
 
virtual epicsUInt32 irqCount () const OVERRIDE FINAL
 
virtual bool linkStatus () const OVERRIDE FINAL
 
virtual IOSCANPVT linkChanged () const OVERRIDE FINAL
 
virtual epicsUInt32 recvErrorCount () const OVERRIDE FINAL
 
virtual epicsUInt32 uSecDiv () const OVERRIDE FINAL
 Approximate divider from event clock period to 1us. More...
 
virtual bool extInhib () const OVERRIDE FINAL
 Using external hardware input for inhibit? More...
 
virtual void setExtInhib (bool) OVERRIDE FINAL
 
virtual epicsUInt32 tsDiv () const OVERRIDE FINAL
 When using internal TS source gives the divider from event clock period to TS period. More...
 
virtual void setSourceTS (TSSource) OVERRIDE FINAL
 Select source which increments TS counter. More...
 
virtual TSSource SourceTS () const OVERRIDE FINAL
 
virtual double clockTS () const OVERRIDE FINAL
 
virtual void clockTSSet (double) OVERRIDE FINAL
 
virtual bool interestedInEvent (epicsUInt32 event, bool set) OVERRIDE FINAL
 
virtual bool TimeStampValid () const OVERRIDE FINAL
 
virtual IOSCANPVT TimeStampValidEvent () const OVERRIDE FINAL
 
virtual bool getTimeStamp (epicsTimeStamp *ts, epicsUInt32 event) OVERRIDE FINAL
 
virtual bool getTicks (epicsUInt32 *tks) OVERRIDE FINAL
 
virtual IOSCANPVT eventOccurred (epicsUInt32 event) const OVERRIDE FINAL
 
virtual void eventNotifyAdd (epicsUInt32, eventCallback, void *) OVERRIDE FINAL
 
virtual void eventNotifyDel (epicsUInt32, eventCallback, void *) OVERRIDE FINAL
 
bool convertTS (epicsTimeStamp *ts)
 In place conversion between raw posix sec+ticks to EPICS sec+nsec. More...
 
virtual epicsUInt16 dbus () const OVERRIDE FINAL
 
virtual epicsUInt32 heartbeatTIMOCount () const OVERRIDE FINAL
 
virtual IOSCANPVT heartbeatTIMOOccured () const OVERRIDE FINAL
 
virtual epicsUInt32 FIFOFullCount () const OVERRIDE FINAL
 
virtual epicsUInt32 FIFOOverRate () const OVERRIDE FINAL
 
virtual epicsUInt32 FIFOEvtCount () const OVERRIDE FINAL
 
virtual epicsUInt32 FIFOLoopCount () const OVERRIDE FINAL
 
void enableIRQ (void)
 
bool dcEnabled () const
 
void dcEnable (bool v)
 
double dcTarget () const
 
void dcTargetSet (double)
 
double dcRx () const
 Measured delay. More...
 
double dcInternal () const
 Delay compensation applied. More...
 
epicsUInt32 dcStatusRaw () const
 
epicsUInt32 topId () const
 
epicsUInt32 dummy () const
 
void setEvtCode (epicsUInt32 code) OVERRIDE FINAL
 
epicsUInt32 timeSrc () const
 
void setTimeSrc (epicsUInt32 mode)
 
- Public Member Functions inherited from mrf::ObjectInst< EVRMRM, EVR >
virtual propertyBasegetPropertyBase (const char *pname, const std::type_info &ptype)
 
virtual void visitProperties (bool(*cb)(propertyBase *, void *), void *arg)
 
- Public Member Functions inherited from EVR
 EVR (const std::string &n, bus_configuration &busConfig)
 
virtual ~EVR ()=0
 
std::string versionStr () const
 
virtual std::string versionSw () const
 Software Version. More...
 
virtual std::string position () const
 Position of EVR device in enclosure. More...
 
bus_configurationgetBusConfiguration ()
 
void setSourceTSraw (epicsUInt32 r)
 
epicsUInt32 SourceTSraw () const
 
- Public Member Functions inherited from mrf::Object
const std::string & name () const
 
const Objectparent () const
 
child_iterator beginChild () const
 
child_iterator endChild () const
 
template<typename P >
mrf::auto_ptr< property< P > > getProperty (const char *pname)
 
- Public Member Functions inherited from MRMSPI
 MRMSPI (volatile unsigned char *base)
 
virtual ~MRMSPI ()
 
virtual void select (unsigned id) OVERRIDE FINAL
 Select numbered device. 0 clears selection. More...
 
virtual epicsUInt8 cycle (epicsUInt8 in) OVERRIDE FINAL
 
- Public Member Functions inherited from mrf::SPIInterface
 SPIInterface ()
 
virtual ~SPIInterface ()
 
virtual void cycles (size_t nops, const Operation *ops)
 
double timeout () const
 timeout in seconds for an individual cycle() More...
 
void setTimeout (double t)
 
- Public Member Functions inherited from TimeStampSource
 TimeStampSource (double period)
 
virtual ~TimeStampSource ()
 
void resyncSecond ()
 Call to re-initialize timestamp counter from system time. More...
 
void tickSecond ()
 Call just after the start of each second. More...
 
bool validSeconds () const
 Whether tickSecond() has been called for the past 5 seconds. More...
 
double deltaSeconds () const
 last difference between More...
 
void softSecondsSrc (bool enable)
 enable sending of event 125 by software timer. Simulation of external HW clock More...
 
bool isSoftSeconds () const
 
std::string nextSecond () const
 

Static Public Member Functions

static void isr (EVRMRM *evr, bool pci)
 
static void isr_pci (void *)
 
static void isr_vme (void *)
 
static void isr_poll (void *)
 
- Static Public Member Functions inherited from mrf::ObjectInst< EVRMRM, EVR >
static int initObject ()
 
- Static Public Member Functions inherited from mrf::ObjectInst< EVR >
static int initObject ()
 
- Static Public Member Functions inherited from mrf::Object
static ObjectgetObject (const std::string &name)
 
static ObjectgetCreateObject (const std::string &name, const std::string &klass, const create_args_t &args=create_args_t())
 
static void addFactory (const std::string &klass, create_factory_t fn)
 
static void visitObjects (bool(*)(Object *, void *), void *)
 

Public Attributes

epicsMutex evrLock
 Guards access to instance All callers must take this lock before any operations on this object. More...
 
const Config *const conf
 
volatile unsigned char *const base
 
epicsUInt32 baselen
 
mrmDataBufTx buftx
 
mrmBufRx bufrx
 
mrf::auto_ptr< SFPsfp
 

Friends

struct EVRMRMTSBuffer
 

Additional Inherited Members

- Public Types inherited from EVR
typedef void(* eventCallback) (void *userarg, epicsUInt32 event)
 
- Public Types inherited from mrf::Object
typedef m_obj_children_t::const_iterator child_iterator
 
typedef std::map< std::string, std::string > create_args_t
 
typedef Object *(* create_factory_t) (const std::string &name, const std::string &klass, const create_args_t &args)
 
- Protected Member Functions inherited from mrf::ObjectInst< EVRMRM, EVR >
 ObjectInst (const std::string &n)
 
 ObjectInst (const std::string &n, A &a)
 
virtual ~ObjectInst ()
 
- Protected Member Functions inherited from mrf::ObjectInst< EVR >
 ObjectInst (const std::string &n)
 
 ObjectInst (const std::string &n, A &a)
 
- Protected Member Functions inherited from mrf::Object
 Object (const std::string &n, const Object *par=0)
 
virtual ~Object ()=0
 
- Protected Member Functions inherited from TimeStampSource
virtual void postSoftSecondsSrc ()
 
- Protected Attributes inherited from mrf::SPIInterface
epicsMutex mutex
 

Detailed Description

Modular Register Map Event Receivers.

Definition at line 86 of file drvem.h.

Constructor & Destructor Documentation

◆ EVRMRM()

EVRMRM::EVRMRM ( const std::string &  n,
bus_configuration busConfig,
const Config c,
volatile unsigned char *  b,
epicsUInt32  bl 
)

Definition at line 120 of file drvem.cpp.

124  :base_t(n,busConfig)
125  ,MRMSPI(b+U32_SPIDData)
126  ,TimeStampSource(1.0)
127  ,evrLock()
128  ,conf(c)
129  ,base(b)
130  ,baselen(bl)
131  ,buftx(n+":BUFTX", b+U32_DataTxCtrl, b+U32_DataTx_base)
132  ,bufrx(n+":BUFRX", b, 10) // Sets depth of Rx queue
133  ,count_recv_error(0)
134  ,count_hardware_irq(0)
135  ,count_heartbeat(0)
136  ,shadowIRQEna(0)
137  ,count_FIFO_overflow(0)
138  ,outputs()
139  ,prescalers()
140  ,pulsers()
141  ,shortcmls()
142  ,gpio_(*this)
143  ,drain_fifo_method(*this)
144  ,drain_fifo_task(drain_fifo_method, "EVRFIFO",
145  epicsThreadGetStackSize(epicsThreadStackBig),
146  epicsThreadPriorityHigh )
147  // 3 because 2 IRQ events, and 1 shutdown event
148  ,drain_fifo_wakeup(3,sizeof(int))
149  ,count_FIFO_sw_overrate(0)
150  ,timeSrcMode(Disable)
151  ,stampClock(0.0)
152  ,shadowSourceTS(TSSourceInternal)
153  ,shadowCounterPS(0)
154  ,timestampValid(0)
155  ,lastInvalidTimestamp(0)
156  ,lastValidTimestamp(0)
157 {
158 try{
159  const epicsUInt32 rawver = fpgaFirmware();
160  const epicsUInt32 boardtype = (rawver&FWVersion_type_mask)>>FWVersion_type_shift;
161  const epicsUInt32 formfactor = (rawver&FWVersion_form_mask)>>FWVersion_form_shift;
162  const MRFVersion ver(rawver);
163 
164  if(boardtype!=0x1)
165  throw std::runtime_error("Address does not correspond to an EVR");
166 
167  if(ver<MRFVersion(0,3))
168  throw std::runtime_error("Firmware 0 version < 3 not supported");
169  else if(ver.firmware()==2 && ver<MRFVersion(2,7))
170  throw std::runtime_error("Firmware 2 version < 207 not supported");
171 
172  if(ver.firmware()==2 && ver<MRFVersion(2,7,6))
173  printf("Warning: Recommended minimum firmware 2 version is 207.6, found %s\n", ver.str().c_str());
174 
175  if(ver.firmware()!=0 && ver.firmware()!=2)
176  printf("Warning: Unknown firmware series %u. Your milage may vary\n", ver.firmware());
177 
178  scanIoInit(&IRQmappedEvent);
179  scanIoInit(&IRQheartbeat);
180  scanIoInit(&IRQrxError);
181  scanIoInit(&IRQfifofull);
182  scanIoInit(&timestampValidChange);
183 
184  CBINIT(&data_rx_cb , priorityHigh, &mrmBufRx::drainbuf, &this->bufrx);
185  CBINIT(&poll_link_cb , priorityMedium, &EVRMRM::poll_link , this);
186 
187  if(ver>=MRFVersion(0, 5)) {
188  std::ostringstream name;
189  name<<n<<":SFP";
190  sfp.reset(new SFP(name.str(), base + U32_SFPEEPROM_base));
191  }
192 
193  if(ver>=MRFVersion(2,7)) {
194  printf("Sequencer capability detected\n");
195  seq.reset(new EvrSeqManager(this));
196  }
197 
198  /*
199  * Create subunit instances
200  */
201 
202  formFactor form = getFormFactor();
203 
204  printf("%s: ", formFactorStr().c_str());
205  printf("Out FP:%u FPUNIV:%u RB:%u IFP:%u GPIO:%u\n",
206  (unsigned int)conf->nOFP,(unsigned int)conf->nOFPUV,
207  (unsigned int)conf->nORB,(unsigned int)conf->nIFP,
208  (unsigned int)conf->nOFPDly);
209 
210  inputs.resize(conf->nIFP);
211  for(size_t i=0; i<conf->nIFP; i++){
212  std::ostringstream name;
213  name<<n<<":FPIn"<<i;
214  inputs[i]=new MRMInput(name.str(), base,i);
215  }
216 
217  // Special output for mapping bus interrupt
218  outputs[std::make_pair(OutputInt,0)]=new MRMOutput(n+":Int", this, OutputInt, 0);
219 
220  for(unsigned int i=0; i<conf->nOFP; i++){
221  std::ostringstream name;
222  name<<n<<":FrontOut"<<i;
223  outputs[std::make_pair(OutputFP,i)]=new MRMOutput(name.str(), this, OutputFP, i);
224  }
225 
226  for(unsigned int i=0; i<conf->nOFPUV; i++){
227  std::ostringstream name;
228  name<<n<<":FrontUnivOut"<<i;
229  outputs[std::make_pair(OutputFPUniv,i)]=new MRMOutput(name.str(), this, OutputFPUniv, i);
230  }
231 
232  delays.resize(conf->nOFPDly);
233  for(unsigned int i=0; i<conf->nOFPDly; i++){
234  std::ostringstream name;
235  name<<n<<":UnivDlyModule"<<i;
236  delays[i]=new DelayModule(name.str(), this, i);
237  }
238 
239  for(unsigned int i=0; i<conf->nORB; i++){
240  std::ostringstream name;
241  name<<n<<":RearUniv"<<i;
242  outputs[std::make_pair(OutputRB,i)]=new MRMOutput(name.str(), this, OutputRB, i);
243  }
244 
245  for(unsigned int i=0; i<conf->nOBack; i++){
246  std::ostringstream name;
247  name<<n<<":Backplane"<<i;
248  outputs[std::make_pair(OutputRB,i)]=new MRMOutput(name.str(), this, OutputBackplane, i);
249  }
250 
251  prescalers.resize(conf->nPS);
252  for(size_t i=0; i<conf->nPS; i++){
253  std::ostringstream name;
254  name<<n<<":PS"<<i;
255  prescalers[i]=new MRMPreScaler(name.str(), *this,base+U32_Scaler(i));
256  }
257 
258  pulsers.resize(32);
259  for(epicsUInt32 i=0; i<conf->nPul; i++){
260  std::ostringstream name;
261  name<<n<<":Pul"<<i;
262  pulsers[i]=new MRMPulser(name.str(), i,*this);
263  }
264  if(ver>=MRFVersion(2,0)) {
265  // masking pulsers
266  for(epicsUInt32 i=28; i<=31; i++){
267  std::ostringstream name;
268  name<<n<<":Pul"<<i;
269  pulsers[i]=new MRMPulser(name.str(), i,*this);
270  }
271 
272  }
273 
274  if(formfactor==formFactor_CPCIFULL) {
275  for(unsigned int i=4; i<8; i++) {
276  std::ostringstream name;
277  name<<n<<":FrontOut"<<i;
278  outputs[std::make_pair(OutputFP,i)]=new MRMOutput(name.str(), this, OutputFP, i);
279  }
280  shortcmls.resize(8, 0);
281  shortcmls[4]=new MRMCML(n+":CML4", 4,*this,MRMCML::typeCML,form);
282  shortcmls[5]=new MRMCML(n+":CML5", 5,*this,MRMCML::typeCML,form);
283  shortcmls[6]=new MRMCML(n+":CML6", 6,*this,MRMCML::typeTG300,form);
284  shortcmls[7]=new MRMCML(n+":CML7", 7,*this,MRMCML::typeTG300,form);
285 
286  } else if(formfactor==formFactor_mTCA) {
287 
288  // mapping to TCLKA and TCLKB as UNIV16, 17
289  // we move down to UNIV0, 1
290  outputs[std::make_pair(OutputFPUniv,0)]=new MRMOutput(SB()<<n<<":FrontUnivOut0", this, OutputFPUniv, 16);
291  outputs[std::make_pair(OutputFPUniv,1)]=new MRMOutput(SB()<<n<<":FrontUnivOut1", this, OutputFPUniv, 17);
292 
293  shortcmls.resize(2);
294  shortcmls[0]=new MRMCML(n+":CML0", 0,*this,MRMCML::typeCML,form);
295  shortcmls[1]=new MRMCML(n+":CML1", 1,*this,MRMCML::typeCML,form);
296 
297  } else if(conf->nCML && ver>=MRFVersion(0,4)){
298  shortcmls.resize(conf->nCML);
299  for(size_t i=0; i<conf->nCML; i++){
300  std::ostringstream name;
301  name<<n<<":CML"<<i;
302  shortcmls[i]=new MRMCML(name.str(), (unsigned char)i,*this,conf->kind,form);
303  }
304 
305  }else if(conf->nCML){
306  printf("CML outputs not supported with this firmware\n");
307  }
308 
309  for(epicsUInt32 i=0; i<NELEMENTS(this->events); i++) {
310  events[i].code=i;
311  events[i].owner=this;
312  CBINIT(&events[i].done_cb, priorityLow, &EVRMRM::sentinel_done , &events[i]);
313  }
314 
315  SCOPED_LOCK(evrLock);
316 
317  memset(_mapped, 0, sizeof(_mapped));
318  // restore mapping ram to a clean state
319  // needed when the IOC is started w/o a device reset (ie Linux)
320  //TODO: find a way to do this that doesn't require clearing
321  // mapping which will shortly be set again...
322  for(size_t i=0; i<255; i++) {
323  WRITE32(base, MappingRam(0, i, Internal), 0);
324  WRITE32(base, MappingRam(0, i, Trigger), 0);
325  WRITE32(base, MappingRam(0, i, Set), 0);
326  WRITE32(base, MappingRam(0, i, Reset), 0);
327  }
328 
329  // restore default special mappings
330  // These may be replaced later
336 
337  // Except for Prescaler reset, which is set with a record
339 
340  eventClock=FracSynthAnalyze(READ32(base, FracDiv),
341  fracref,0)*1e6;
342 
343  shadowCounterPS=READ32(base, CounterPS);
344 
345  if(tsDiv()!=0) {
346  shadowSourceTS=TSSourceInternal;
347  } else {
348  bool usedbus4=(READ32(base, Control) & Control_tsdbus) != 0;
349 
350  if(usedbus4)
351  shadowSourceTS=TSSourceDBus4;
352  else
353  shadowSourceTS=TSSourceEvent;
354  }
355 
356  eventNotifyAdd(MRF_EVENT_TS_COUNTER_RST, &seconds_tick, (void*)this);
357 
358  drain_fifo_task.start();
359 
360  if(busConfig.busType==busType_pci)
361  mrf::SPIDevice::registerDev(n+":FLASH", mrf::SPIDevice(this, 1));
362 
363 } catch (std::exception& e) {
364  printf("Aborting EVR initializtion: %s\n", e.what());
365  cleanup();
366  throw;
367 }
368 }
static void drainbuf(CALLBACK *)
Definition: drvemRxBuf.cpp:74
enum busType busType
#define FWVersion_type_mask
Definition: evrRegMap.h:137
size_t nPS
Definition: drvem.h:101
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
size_t nCML
Definition: drvem.h:106
static void registerDev(const std::string &name, const SPIDevice &)
Definition: spi.cpp:86
#define Control_tsdbus
Definition: evrRegMap.h:73
volatile unsigned char *const base
Definition: drvem.h:223
TimeStampSource(double period)
Definition: mrmtimesrc.cpp:143
MRMSPI(volatile unsigned char *base)
Definition: mrmspi.cpp:36
mrmDataBufTx buftx
Definition: drvem.h:225
formFactor getFormFactor()
Definition: drvem.cpp:421
size_t nOFPDly
Definition: drvem.h:104
#define MRF_EVENT_HEARTBEAT
Definition: mrfCommon.h:116
Internal.
Definition: output.h:19
#define FWVersion_form_shift
Definition: evrRegMap.h:140
#define MRF_EVENT_RST_PRESCALERS
Definition: mrfCommon.h:118
size_t nIFP
Definition: drvem.h:109
formFactor
#define U32_DataTxCtrl
Definition: evrRegMap.h:128
size_t nORB
Definition: drvem.h:103
virtual void specialSetMap(epicsUInt32 code, epicsUInt32 func, bool) OVERRIDE FINAL
Definition: drvem.cpp:524
virtual epicsUInt32 tsDiv() const OVERRIDE FINAL
When using internal TS source gives the divider from event clock period to TS period.
Definition: drvem.h:162
EVRMRM * owner
Definition: drvem.h:52
Rear Breakout.
Definition: output.h:22
#define FWVersion_form_mask
Definition: evrRegMap.h:139
#define CBINIT(ptr, prio, fn, valptr)
Definition: drvem.cpp:75
#define U32_SFPEEPROM_base
Definition: evrRegMap.h:375
size_t nOFP
Definition: drvem.h:103
#define MRF_EVENT_TS_SHIFT_0
Definition: mrfCommon.h:113
size_t nOFPUV
Definition: drvem.h:103
size_t nOBack
Definition: drvem.h:103
Front Panel.
Definition: output.h:20
MRMCML::outkind kind
Definition: drvem.h:107
#define MRF_EVENT_TS_SHIFT_1
Definition: mrfCommon.h:114
#define FWVersion_type_shift
Definition: evrRegMap.h:138
mrmBufRx bufrx
Definition: drvem.h:226
#define U32_DataTx_base
Definition: evrRegMap.h:335
const std::string & name() const
Definition: object.h:393
size_t nPul
Definition: drvem.h:100
FP Universal.
Definition: output.h:21
std::string formFactorStr()
Definition: drvem.cpp:430
#define MRF_EVENT_TS_COUNTER_RST
Definition: mrfCommon.h:124
Backplane lines.
Definition: output.h:23
Definition: sfp.h:16
#define MRF_EVENT_TS_COUNTER_INC
Definition: mrfCommon.h:120
virtual void eventNotifyAdd(epicsUInt32, eventCallback, void *) OVERRIDE FINAL
Definition: drvem.cpp:920
epicsShareExtern epicsFloat64 FracSynthAnalyze(epicsUInt32 ControlWord, epicsFloat64 ReferenceFreq, epicsInt32 PrintFlag)
Definition: mrfFracSynth.c:844
const Config *const conf
Definition: drvem.h:222
epicsUInt8 code
Definition: drvem.h:51
epicsUInt32 fpgaFirmware()
Definition: drvem.cpp:411
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119
#define U32_SPIDData
Definition: mrmspi.cpp:23
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96
mrf::auto_ptr< SFP > sfp
Definition: drvem.h:227
epicsUInt32 baselen
Definition: drvem.h:224
#define U32_Scaler(N)
Definition: evrRegMap.h:192

◆ ~EVRMRM()

EVRMRM::~EVRMRM ( )
virtual

Definition at line 370 of file drvem.cpp.

371 {
374  cleanup();
375 }
static void unregisterDev(const std::string &name)
Definition: spi.cpp:93
const std::string & name() const
Definition: object.h:393
bus_configuration * getBusConfiguration()
Definition: evr.cpp:49

Member Function Documentation

◆ clock()

virtual double EVRMRM::clock ( ) const
inlinevirtual

Find current LO settings

Returns
Clock rate in Hz

Implements EVR.

Definition at line 141 of file drvem.h.

142  {SCOPED_LOCK(evrLock);return eventClock;}
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ clockMode()

epicsUInt16 EVRMRM::clockMode ( ) const

Definition at line 611 of file drvem.cpp.

612 {
614 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define ClkCtrl_clkmd_SHIFT
Definition: evrRegMap.h:151
#define ClkCtrl_clkmd_MASK
Definition: evrRegMap.h:150

◆ clockModeSet()

void EVRMRM::clockModeSet ( epicsUInt16  mode)

Definition at line 617 of file drvem.cpp.

618 {
619  epicsUInt32 cur = READ32(base, ClkCtrl);
620  cur &= ~ClkCtrl_clkmd_MASK;
621  cur |= (epicsUInt32(mode)<<ClkCtrl_clkmd_SHIFT)&ClkCtrl_clkmd_MASK;
622  WRITE32(base, ClkCtrl, cur);
623 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define ClkCtrl_clkmd_SHIFT
Definition: evrRegMap.h:151
#define ClkCtrl_clkmd_MASK
Definition: evrRegMap.h:150
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119

◆ clockSet()

void EVRMRM::clockSet ( double  clk)
virtual

Set LO frequency

Parameters
clkClock rate in Hz

Implements EVR.

Definition at line 570 of file drvem.cpp.

571 {
572  double err;
573  // Set both the fractional synthesiser and microsecond
574  // divider.
575  printf("Set EVR clock %f\n",freq);
576 
577  freq/=1e6;
578 
579  epicsUInt32 newfrac=FracSynthControlWord(
580  freq, fracref, 0, &err);
581 
582  if(newfrac==0)
583  throw std::out_of_range("New frequency can't be used");
584 
585  SCOPED_LOCK(evrLock);
586 
587  epicsUInt32 oldfrac=READ32(base, FracDiv);
588 
589  if(newfrac!=oldfrac){
590  // Changing the control word disturbes the phase
591  // of the synthesiser which will cause a glitch.
592  // Don't change the control word unless needed.
593 
594  WRITE32(base, FracDiv, newfrac);
595 
596  eventClock=FracSynthAnalyze(READ32(base, FracDiv),
597  fracref,0)*1e6;
598  }
599 
600  // USecDiv is accessed as a 32 bit register, but
601  // only 16 are used.
602  epicsUInt16 oldudiv=READ32(base, USecDiv);
603  epicsUInt16 newudiv=(epicsUInt16)freq;
604 
605  if(newudiv!=oldudiv){
606  WRITE32(base, USecDiv, newudiv);
607  }
608 }
epicsShareExtern epicsUInt32 FracSynthControlWord(epicsFloat64 DesiredFreq, epicsFloat64 ReferenceFreq, epicsInt32 debugFlag, epicsFloat64 *Error)
Definition: mrfFracSynth.c:552
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
epicsShareExtern epicsFloat64 FracSynthAnalyze(epicsUInt32 ControlWord, epicsFloat64 ReferenceFreq, epicsInt32 PrintFlag)
Definition: mrfFracSynth.c:844
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ clockTS()

double EVRMRM::clockTS ( ) const
virtual

Find current TS settings

Returns
Clock rate in Hz

Implements EVR.

Definition at line 704 of file drvem.cpp.

705 {
706  //Note: acquires evrLock 3 times.
707 
708  TSSource src=SourceTS();
709  double eclk=clock();
710 
711  if( (src!=TSSourceInternal) ||
712  ((src==TSSourceInternal) && (stampClock>eclk)))
713  return stampClock;
714 
715  epicsUInt16 div=tsDiv();
716 
717  return eclk/div;
718 }
virtual double clock() const OVERRIDE FINAL
Definition: drvem.h:141
TSSource
Definition: evr.h:31
virtual TSSource SourceTS() const OVERRIDE FINAL
Definition: drvem.h:166
virtual epicsUInt32 tsDiv() const OVERRIDE FINAL
When using internal TS source gives the divider from event clock period to TS period.
Definition: drvem.h:162

◆ clockTSSet()

void EVRMRM::clockTSSet ( double  )
virtual

Set TS frequency

Parameters
clkClock rate in Hz

Implements EVR.

Definition at line 721 of file drvem.cpp.

722 {
723  if(clk<0.0 || !isfinite(clk))
724  throw std::out_of_range("TS Clock rate invalid");
725 
726  TSSource src=SourceTS();
727  double eclk=clock();
728 
729  if(clk>eclk*1.01 || clk==0.0)
730  clk=eclk;
731 
732  SCOPED_LOCK(evrLock);
733 
734  if(src==TSSourceInternal){
735  epicsUInt16 div=roundToUInt(eclk/clk, 0xffff);
736  WRITE32(base, CounterPS, div);
737 
738  shadowCounterPS=div;
739  }
740 
741  stampClock=clk;
742 }
virtual double clock() const OVERRIDE FINAL
Definition: drvem.h:141
volatile unsigned char *const base
Definition: drvem.h:223
TSSource
Definition: evr.h:31
#define isfinite
Definition: mrfCommon.h:326
virtual TSSource SourceTS() const OVERRIDE FINAL
Definition: drvem.h:166
epicsUInt32 roundToUInt(double val, epicsUInt32 max)
Definition: mrfCommon.cpp:43
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ convertTS()

bool EVRMRM::convertTS ( epicsTimeStamp *  ts)

In place conversion between raw posix sec+ticks to EPICS sec+nsec.

Returns
false if conversion failed

Definition at line 837 of file drvem.cpp.

838 {
839  // First validate the input
840 
841  //Has it been initialized?
842  if(ts->secPastEpoch==0 || ts->nsec==0){
843  return false;
844  }
845 
846  // recurrence of an invalid time
847  if(ts->secPastEpoch==lastInvalidTimestamp) {
848  timestampValid=0;
849  scanIoRequest(timestampValidChange);
850  if(evrMrmTimeDebug>0)
851  errlogPrintf("TS convert repeats known bad value new %08x bad %08x\n",
852  (unsigned)ts->secPastEpoch, (unsigned)lastInvalidTimestamp);
853  return false;
854  }
855 
856  /* Reported seconds timestamp should be no more
857  * then 1sec in the future.
858  * reporting values in the past should be caught by
859  * generalTime
860  */
861  if(ts->secPastEpoch > lastValidTimestamp+1)
862  {
863  errlogPrintf("EVR ignoring invalid TS %08x %08x (expect %08x)\n",
864  ts->secPastEpoch, ts->nsec, lastValidTimestamp);
865  timestampValid=0;
866  scanIoRequest(timestampValidChange);
867  return false;
868  }
869 
870  // Convert ticks to nanoseconds
871  double period=1e9/clockTS(); // in nanoseconds
872 
873  if(period<=0 || !isfinite(period))
874  return false;
875 
876  ts->nsec=(epicsUInt32)(ts->nsec*period);
877 
878  // 1 sec. reset is late
879  if(ts->nsec>=1000000000u) {
880  if(evrMrmTimeDebug>0)
881  errlogPrintf("TS convert NS overflow %08x %08x oflow=%u\n",
882  (unsigned)ts->secPastEpoch, (unsigned)ts->nsec,
883  unsigned(ts->nsec-1000000000u));
884 
885  // out of bounds
886  if(int(ts->nsec-1000000000u)>=evrMrmTimeNSOverflowThreshold) {
887  timestampValid=0;
888  lastInvalidTimestamp=ts->secPastEpoch;
889  scanIoRequest(timestampValidChange);
890 
891  return false;
892  }
893  // otherwise, truncate
894  ts->nsec = 999999999u;
895  }
896 
897  //Link seconds counter is POSIX time
898  ts->secPastEpoch-=POSIX_TIME_AT_EPICS_EPOCH;
899 
900  return true;
901 }
#define isfinite
Definition: mrfCommon.h:326
int evrMrmTimeDebug
Definition: drvem.cpp:61
virtual double clockTS() const OVERRIDE FINAL
Definition: drvem.cpp:704
int evrMrmTimeNSOverflowThreshold
Definition: drvem.cpp:66

◆ dbus()

epicsUInt16 EVRMRM::dbus ( ) const
virtual

Implements EVR.

Definition at line 946 of file drvem.cpp.

947 {
948  return (READ32(base, Status) & Status_dbus_mask) >> Status_dbus_shift;
949 }
#define Status_dbus_mask
Definition: evrRegMap.h:45
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define Status_dbus_shift
Definition: evrRegMap.h:46

◆ dcEnable()

void EVRMRM::dcEnable ( bool  v)

Definition at line 958 of file drvem.cpp.

959 {
960  if(v)
961  BITSET32(base, Control, Control_DCEna);
962  else
963  BITCLR32(base, Control, Control_DCEna);
964 }
#define BITSET32(base, offset, mask)
Definition: mrfCommonIO.h:124
volatile unsigned char *const base
Definition: drvem.h:223
#define BITCLR32(base, offset, mask)
Definition: mrfCommonIO.h:129
#define Control_DCEna
Definition: evrRegMap.h:70

◆ dcEnabled()

bool EVRMRM::dcEnabled ( ) const

Definition at line 952 of file drvem.cpp.

953 {
954  return READ32(base, Control) & Control_DCEna;
955 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define Control_DCEna
Definition: evrRegMap.h:70

◆ dcInternal()

double EVRMRM::dcInternal ( ) const

Delay compensation applied.

Definition at line 991 of file drvem.cpp.

992 {
993  double period=1e9/clock(); // in nanoseconds
994  return double(READ32(base, DCIntVal))/65536.0*period;
995 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
virtual double clock() const OVERRIDE FINAL
Definition: drvem.h:141
volatile unsigned char *const base
Definition: drvem.h:223

◆ dcRx()

double EVRMRM::dcRx ( ) const

Measured delay.

Definition at line 984 of file drvem.cpp.

985 {
986  double period=1e9/clock(); // in nanoseconds
987  return double(READ32(base, DCRxVal))/65536.0*period;
988 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
virtual double clock() const OVERRIDE FINAL
Definition: drvem.h:141
volatile unsigned char *const base
Definition: drvem.h:223

◆ dcStatusRaw()

epicsUInt32 EVRMRM::dcStatusRaw ( ) const

Definition at line 998 of file drvem.cpp.

999 {
1000  return READ32(base, DCStatus);
1001 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223

◆ dcTarget()

double EVRMRM::dcTarget ( ) const

Definition at line 967 of file drvem.cpp.

968 {
969  double period=1e9/clock(); // in nanoseconds
970  return double(READ32(base, DCTarget))/65536.0*period;
971 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
virtual double clock() const OVERRIDE FINAL
Definition: drvem.h:141
volatile unsigned char *const base
Definition: drvem.h:223

◆ dcTargetSet()

void EVRMRM::dcTargetSet ( double  val)

Definition at line 974 of file drvem.cpp.

975 {
976  double period=1e9/clock(); // in nanoseconds
977 
978  val /= period;
979  val *= 65536.0;
980  WRITE32(base, DCTarget, val);
981 }
virtual double clock() const OVERRIDE FINAL
Definition: drvem.h:141
volatile unsigned char *const base
Definition: drvem.h:223
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119

◆ dummy()

epicsUInt32 EVRMRM::dummy ( ) const
inline

Definition at line 208 of file drvem.h.

208 { return 0; }

◆ enable()

void EVRMRM::enable ( bool  v)
virtual

Implements EVR.

Definition at line 483 of file drvem.cpp.

484 {
485  SCOPED_LOCK(evrLock);
486  if(v)
488  else
490 }
#define BITCLR(ord, len, base, offset, mask)
Definition: mrfBitOps.h:26
volatile unsigned char *const base
Definition: drvem.h:223
#define Control_outena
Definition: evrRegMap.h:62
#define Control_mapena
Definition: evrRegMap.h:77
#define Control_enable
Definition: evrRegMap.h:53
#define Control_evtfwd
Definition: evrRegMap.h:55
#define BITSET(ord, len, base, offset, mask)
Definition: mrfBitOps.h:21
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ enabled()

bool EVRMRM::enabled ( ) const
virtual

Implements EVR.

Definition at line 476 of file drvem.cpp.

477 {
478  epicsUInt32 v = READ32(base, Control);
479  return (v&Control_enable) != 0;
480 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define Control_enable
Definition: evrRegMap.h:53

◆ enableIRQ()

void EVRMRM::enableIRQ ( void  )

Definition at line 1090 of file drvem.cpp.

1091 {
1092  interruptLock I;
1093 
1094  shadowIRQEna = IRQ_Enable
1096  |IRQ_Heartbeat
1098  |IRQ_SoS |IRQ_EoS;
1099 
1100  // IRQ PCIe enable flag should not be changed. Possible RACER here
1101  shadowIRQEna |= (IRQ_PCIee & (READ32(base, IRQEnable)));
1102 
1103  WRITE32(base, IRQEnable, shadowIRQEna);
1104 }
#define IRQ_SoS
Definition: evrRegMap.h:89
#define IRQ_Heartbeat
Definition: mrf.h:111
#define IRQ_FIFOFull
Definition: mrf.h:112
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define IRQ_PCIee
Definition: mrf.h:119
#define IRQEnable
Definition: mrf.h:115
#define IRQ_RXErr
Definition: mrf.h:113
#define IRQ_Event
Definition: mrf.h:110
#define IRQ_Enable
Definition: mrf.h:117
#define IRQ_EoS
Definition: evrRegMap.h:88
#define IRQ_BufFull
Definition: mrf.h:108
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119

◆ eventNotifyAdd()

void EVRMRM::eventNotifyAdd ( epicsUInt32  event,
eventCallback  cb,
void *  arg 
)
virtual

Implements EVR.

Definition at line 920 of file drvem.cpp.

921 {
922  if (event==0 || event>255)
923  throw std::out_of_range("Invalid event number");
924 
925  SCOPED_LOCK2(evrLock, guard);
926 
927  events[event].notifiees.push_back( std::make_pair(cb,arg));
928 
929  interestedInEvent(event, true);
930 }
virtual bool interestedInEvent(epicsUInt32 event, bool set) OVERRIDE FINAL
Definition: drvem.cpp:745
notifiees_t notifiees
Definition: drvem.h:68
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ eventNotifyDel()

void EVRMRM::eventNotifyDel ( epicsUInt32  event,
eventCallback  cb,
void *  arg 
)
virtual

Implements EVR.

Definition at line 933 of file drvem.cpp.

934 {
935  if (event==0 || event>255)
936  throw std::out_of_range("Invalid event number");
937 
938  SCOPED_LOCK2(evrLock, guard);
939 
940  events[event].notifiees.remove(std::make_pair(cb,arg));
941 
942  interestedInEvent(event, false);
943 }
virtual bool interestedInEvent(epicsUInt32 event, bool set) OVERRIDE FINAL
Definition: drvem.cpp:745
notifiees_t notifiees
Definition: drvem.h:68
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ eventOccurred()

IOSCANPVT EVRMRM::eventOccurred ( epicsUInt32  event) const
virtual

Implements EVR.

Definition at line 911 of file drvem.cpp.

912 {
913  if (event>0 && event<=255)
914  return events[event].occured;
915  else
916  return NULL;
917 }
IOSCANPVT occured
Definition: drvem.h:65

◆ extInhib()

bool EVRMRM::extInhib ( ) const
virtual

Using external hardware input for inhibit?

Implements EVR.

Definition at line 632 of file drvem.cpp.

633 {
634  epicsUInt32 v = READ32(base, Control);
635  return (v&Control_GTXio) != 0;
636 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define Control_GTXio
Definition: evrRegMap.h:68

◆ FIFOEvtCount()

virtual epicsUInt32 EVRMRM::FIFOEvtCount ( ) const
inlinevirtual

Implements EVR.

Definition at line 192 of file drvem.h.

192 {return count_fifo_events;}

◆ FIFOFullCount()

virtual epicsUInt32 EVRMRM::FIFOFullCount ( ) const
inlinevirtual

Implements EVR.

Definition at line 188 of file drvem.h.

189  {SCOPED_LOCK(evrLock);return count_FIFO_overflow;}
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ FIFOLoopCount()

virtual epicsUInt32 EVRMRM::FIFOLoopCount ( ) const
inlinevirtual

Implements EVR.

Definition at line 193 of file drvem.h.

193 {return count_fifo_loops;}

◆ FIFOOverRate()

virtual epicsUInt32 EVRMRM::FIFOOverRate ( ) const
inlinevirtual

Implements EVR.

Definition at line 190 of file drvem.h.

191  {SCOPED_LOCK(evrLock);return count_FIFO_sw_overrate;}
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ formFactorStr()

std::string EVRMRM::formFactorStr ( )

Definition at line 430 of file drvem.cpp.

430  {
431  std::string text;
432  formFactor form;
433 
434  form = getFormFactor();
435  switch(form){
436  case formFactor_CPCI:
437  text = "CompactPCI 3U";
438  break;
439 
440  case formFactor_CPCIFULL:
441  text = "CompactPCI 6U";
442  break;
443 
444  case formFactor_CRIO:
445  text = "CompactRIO";
446  break;
447 
448  case formFactor_PCIe:
449  text = "PCIe";
450  break;
451 
452  case formFactor_mTCA:
453  text = "mTCA";
454  break;
455 
456  case formFactor_PXIe:
457  text = "PXIe";
458  break;
459 
460  case formFactor_PMC:
461  text = "PMC";
462  break;
463 
464  case formFactor_VME64:
465  text = "VME 64";
466  break;
467 
468  default:
469  text = "Unknown form factor";
470  }
471 
472  return text;
473 }
formFactor getFormFactor()
Definition: drvem.cpp:421
formFactor

◆ fpgaFirmware()

epicsUInt32 EVRMRM::fpgaFirmware ( )

Definition at line 411 of file drvem.cpp.

411  {
412  return READ32(base, FWVersion);
413 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223

◆ getFormFactor()

formFactor EVRMRM::getFormFactor ( )

Definition at line 421 of file drvem.cpp.

421  {
422  epicsUInt32 v = READ32(base, FWVersion);
423  epicsUInt32 form = (v&FWVersion_form_mask)>>FWVersion_form_shift;
424 
425  if(form <= formFactor_mTCA) return (formFactor)form;
426  else return formFactor_unknown;
427 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define FWVersion_form_shift
Definition: evrRegMap.h:140
formFactor
#define FWVersion_form_mask
Definition: evrRegMap.h:139

◆ getTicks()

bool EVRMRM::getTicks ( epicsUInt32 *  tks)
virtual

Returns the current value of the Timestamp Event Counter

Parameters
tksPointer to be filled with the counter value
Returns
false if the counter value is not valid

Implements EVR.

Definition at line 904 of file drvem.cpp.

905 {
906  *tks=READ32(base, TSEvt);
907  return true;
908 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223

◆ getTimeStamp()

bool EVRMRM::getTimeStamp ( epicsTimeStamp *  ts,
epicsUInt32  event 
)
virtual

Gives the current time stamp as sec+nsec

Parameters
tsThis pointer will be filled in with the current time
eventN<=0 Return the current wall clock time
eventN>0 Return the time the most recent event # N was received.
Returns
true When ts was updated
false When ts could not be updated

Implements EVR.

Definition at line 775 of file drvem.cpp.

776 {
777  if(!ret) throw std::runtime_error("Invalid argument");
778  epicsTimeStamp ts;
779 
780  SCOPED_LOCK(evrLock);
781  if(timestampValid<TSValidThreshold) return false;
782 
783  if(event>0 && event<=255) {
784  // Get time of last event code #
785 
786  eventCode *entry=&events[event];
787 
788  // Fail if event is not mapped
789  if (!entry->interested ||
790  ( entry->last_sec==0 &&
791  entry->last_evt==0) )
792  {
793  return false;
794  }
795 
796  ts.secPastEpoch=entry->last_sec;
797  ts.nsec=entry->last_evt;
798 
799 
800  } else {
801  // Get current absolute time
802 
803  epicsUInt32 ctrl=READ32(base, Control);
804 
805  // Latch timestamp
806  WRITE32(base, Control, ctrl|Control_tsltch);
807 
808  ts.secPastEpoch=READ32(base, TSSecLatch);
809  ts.nsec=READ32(base, TSEvtLatch);
810 
811  /* BUG: There was a firmware bug which occasionally
812  * causes the previous write to fail with a VME bus
813  * error, and 0 the Control register.
814  *
815  * This issues has been fixed in VME firmwares EVRv 5
816  * pre2 and EVG v3 pre2. Feb 2011
817  */
818  epicsUInt32 ctrl2=READ32(base, Control);
819  if (ctrl2!=ctrl) { // tsltch bit is write-only
820  printf("Get timestamp: control register write fault. Written: %08x, readback: %08x\n",ctrl,ctrl2);
821  WRITE32(base, Control, ctrl);
822  }
823 
824  }
825 
826  if(!convertTS(&ts))
827  return false;
828 
829  *ret = ts;
830  return true;
831 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
size_t interested
Definition: drvem.h:57
volatile unsigned char *const base
Definition: drvem.h:223
bool convertTS(epicsTimeStamp *ts)
In place conversion between raw posix sec+ticks to EPICS sec+nsec.
Definition: drvem.cpp:837
epicsUInt32 last_evt
Definition: drvem.h:60
#define Control_tsltch
Definition: evrRegMap.h:75
epicsUInt32 last_sec
Definition: drvem.h:59
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96
#define TSValidThreshold
Definition: drvem.cpp:114

◆ gpio()

MRMGpio * EVRMRM::gpio ( )

Definition at line 500 of file drvem.cpp.

500  {
501  return &gpio_;
502 }

◆ heartbeatTIMOCount()

virtual epicsUInt32 EVRMRM::heartbeatTIMOCount ( ) const
inlinevirtual

Implements EVR.

Definition at line 185 of file drvem.h.

185 {return count_heartbeat;}

◆ heartbeatTIMOOccured()

virtual IOSCANPVT EVRMRM::heartbeatTIMOOccured ( ) const
inlinevirtual

Implements EVR.

Definition at line 186 of file drvem.h.

186 {return IRQheartbeat;}

◆ interestedInEvent()

bool EVRMRM::interestedInEvent ( epicsUInt32  event,
bool  set 
)
virtual

Indicate (lack of) interest in a particular event code. This allows an EVR to ignore event codes which are not needed.

Implements EVR.

Definition at line 745 of file drvem.cpp.

746 {
747  if (!event || event>255) return false;
748 
749  eventCode *entry=&events[event];
750 
751  SCOPED_LOCK(evrLock);
752 
753  if ( (set && entry->interested==0) // first interested
754  || (!set && entry->interested==1) // or last un-interested
755  ) {
756  specialSetMap(event, ActionFIFOSave, set);
757  }
758 
759  if (set)
760  entry->interested++;
761  else
762  entry->interested--;
763 
764  return true;
765 }
size_t interested
Definition: drvem.h:57
virtual void specialSetMap(epicsUInt32 code, epicsUInt32 func, bool) OVERRIDE FINAL
Definition: drvem.cpp:524
#define ActionFIFOSave
Definition: evrRegMap.h:362
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ irqCount()

virtual epicsUInt32 EVRMRM::irqCount ( ) const
inlinevirtual

Implements EVR.

Definition at line 150 of file drvem.h.

150 {return count_hardware_irq;}

◆ isr()

void EVRMRM::isr ( EVRMRM evr,
bool  pci 
)
static

Definition at line 1142 of file drvem.cpp.

1143 {
1144 
1145  epicsUInt32 flags=READ32(evr->base, IRQFlag);
1146 
1147  epicsUInt32 active=flags&evr->shadowIRQEna;
1148 
1149 #if defined(vxWorks) || defined(__rtems__)
1150  if(!active) {
1151 # ifdef __rtems__
1152  if(!pci)
1153  printk("EVRMRM::isr with no active VME IRQ 0x%08x 0x%08x\n", flags, evr->shadowIRQEna);
1154 #else
1155  (void)pci;
1156 # endif
1157  // this is a shared interrupt
1158  return;
1159  }
1160  // Note that VME devices do not normally shared interrupts
1161 #else
1162  // for Linux, shared interrupts are detected by the kernel module
1163  // so any notifications to userspace are real interrupts by this device
1164  (void)pci;
1165 #endif
1166 
1167  if(active&IRQ_RXErr){
1168  evr->count_recv_error++;
1169  scanIoRequest(evr->IRQrxError);
1170 
1171  evr->shadowIRQEna &= ~IRQ_RXErr;
1172  callbackRequest(&evr->poll_link_cb);
1173  }
1174  if(active&IRQ_BufFull){
1175  // Silence interrupt
1176  BITSET(NAT,32,evr->base, DataBufCtrl, DataBufCtrl_stop);
1177 
1178  callbackRequest(&evr->data_rx_cb);
1179  }
1180  if(active&IRQ_HWMapped){
1181  evr->shadowIRQEna &= ~IRQ_HWMapped;
1182  //TODO: think of a way to use this feature...
1183  }
1184  if(active&IRQ_Event){
1185  //FIFO not-empty
1186  evr->shadowIRQEna &= ~IRQ_Event;
1187  int wakeup=0;
1188  evr->drain_fifo_wakeup.trySend(&wakeup, sizeof(wakeup));
1189  }
1190  if(active&IRQ_Heartbeat){
1191  evr->count_heartbeat++;
1192  scanIoRequest(evr->IRQheartbeat);
1193  }
1194  if(active&IRQ_FIFOFull){
1195  evr->shadowIRQEna &= ~IRQ_FIFOFull;
1196  int wakeup=0;
1197  evr->drain_fifo_wakeup.trySend(&wakeup, sizeof(wakeup));
1198 
1199  scanIoRequest(evr->IRQfifofull);
1200  }
1201  if(active&IRQ_SoS && evr->seq.get()){
1202  evr->seq->doStartOfSequence(0);
1203  }
1204  if(active&IRQ_EoS && evr->seq.get()){
1205  evr->seq->doEndOfSequence(0);
1206  }
1207  evr->count_hardware_irq++;
1208 
1209  // IRQ PCIe enable flag should not be changed. Possible RACER here
1210  evr->shadowIRQEna |= (IRQ_PCIee & (READ32(evr->base, IRQEnable)));
1211 
1212  WRITE32(evr->base, IRQFlag, flags);
1213  WRITE32(evr->base, IRQEnable, evr->shadowIRQEna);
1214  // Ensure IRQFlags is written before returning.
1216 }
#define IRQ_SoS
Definition: evrRegMap.h:89
#define IRQ_Heartbeat
Definition: mrf.h:111
#define IRQ_FIFOFull
Definition: mrf.h:112
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define IRQ_PCIee
Definition: mrf.h:119
#define IRQEnable
Definition: mrf.h:115
#define IRQ_RXErr
Definition: mrf.h:113
volatile epicsUInt32 evrMrmIsrFlagsTrashCan
Definition: drvem.cpp:1139
#define IRQ_Event
Definition: mrf.h:110
#define DataBufCtrl_stop
Definition: evrRegMap.h:123
#define IRQFlag
Definition: mrf.h:106
#define IRQ_EoS
Definition: evrRegMap.h:88
#define IRQ_BufFull
Definition: mrf.h:108
#define IRQ_HWMapped
Definition: mrf.h:109
#define BITSET(ord, len, base, offset, mask)
Definition: mrfBitOps.h:21
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119

◆ isr_pci()

void EVRMRM::isr_pci ( void *  arg)
static

Definition at line 1107 of file drvem.cpp.

1107  {
1108  EVRMRM *evr=static_cast<EVRMRM*>(arg);
1109 
1110  // Calling the default platform-independent interrupt routine
1111  evr->isr(evr, true);
1112 
1113 #if defined(__linux__) || defined(_WIN32)
1114  if(devPCIEnableInterrupt((const epicsPCIDevice*)evr->isrLinuxPvt)) {
1115  printf("Failed to re-enable interrupt. Stuck...\n");
1116  }
1117 #endif
1118 }
Modular Register Map Event Receivers.
Definition: drvem.h:86
static void isr(EVRMRM *evr, bool pci)
Definition: drvem.cpp:1142

◆ isr_poll()

void EVRMRM::isr_poll ( void *  arg)
static

Definition at line 1129 of file drvem.cpp.

1129  {
1130  EVRMRM *evr=static_cast<EVRMRM*>(arg);
1131 
1132  // Calling the default platform-independent interrupt routine
1133  evr->isr(evr, true);
1134 }
Modular Register Map Event Receivers.
Definition: drvem.h:86
static void isr(EVRMRM *evr, bool pci)
Definition: drvem.cpp:1142

◆ isr_vme()

void EVRMRM::isr_vme ( void *  arg)
static

Definition at line 1121 of file drvem.cpp.

1121  {
1122  EVRMRM *evr=static_cast<EVRMRM*>(arg);
1123 
1124  // Calling the default platform-independent interrupt routine
1125  evr->isr(evr, false);
1126 }
Modular Register Map Event Receivers.
Definition: drvem.h:86
static void isr(EVRMRM *evr, bool pci)
Definition: drvem.cpp:1142

◆ linkChanged()

virtual IOSCANPVT EVRMRM::linkChanged ( ) const
inlinevirtual

Implements EVR.

Definition at line 153 of file drvem.h.

153 {return IRQrxError;}

◆ linkStatus()

bool EVRMRM::linkStatus ( ) const
virtual

Implements EVR.

Definition at line 659 of file drvem.cpp.

660 {
661  return !(READ32(base, Status) & Status_legvio);
662 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define Status_legvio
Definition: evrRegMap.h:47

◆ lock()

virtual void EVRMRM::lock ( ) const
inlinevirtual

Implements mrf::Object.

Definition at line 121 of file drvem.h.

121 {evrLock.lock();}
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ mappedOutputState()

bool EVRMRM::mappedOutputState ( ) const
virtual

Implements EVR.

Definition at line 493 of file drvem.cpp.

494 {
496  return NAT_READ32(base, IRQFlag) & IRQ_HWMapped;
497 }
volatile unsigned char *const base
Definition: drvem.h:223
#define NAT_READ32(base, offset)
Definition: mrfCommonIO.h:145
#define IRQFlag
Definition: mrf.h:106
#define NAT_WRITE32(base, offset, value)
Definition: mrfCommonIO.h:148
#define IRQ_HWMapped
Definition: mrf.h:109

◆ model()

string EVRMRM::model ( ) const
virtual

Hardware model.

Implements EVR.

Definition at line 405 of file drvem.cpp.

406 {
407  return conf->model;
408 }
const char * model
Definition: drvem.h:99
const Config *const conf
Definition: drvem.h:222

◆ pllLocked()

bool EVRMRM::pllLocked ( ) const
virtual

Internal PLL Status.

Implements EVR.

Definition at line 649 of file drvem.cpp.

650 {
651  epicsUInt32 cur = READ32(base, ClkCtrl);
652  epicsUInt32 mask = ClkCtrl_cglock;
653  if(version()>=MRFVersion(2, 7, 0))
654  mask |= ClkCtrl_plllock;
655  return (cur&mask)==mask;
656 }
#define ClkCtrl_cglock
Definition: evrRegMap.h:152
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define ClkCtrl_plllock
Definition: evrRegMap.h:149
virtual MRFVersion version() const OVERRIDE FINAL
Firmware Version.
Definition: drvem.cpp:415

◆ recvErrorCount()

virtual epicsUInt32 EVRMRM::recvErrorCount ( ) const
inlinevirtual

Implements EVR.

Definition at line 154 of file drvem.h.

154 {return count_recv_error;}

◆ setEvtCode()

void EVRMRM::setEvtCode ( epicsUInt32  code)
virtual

Implements TimeStampSource.

Definition at line 1010 of file drvem.cpp.

1011 {
1012  if(code==0) return;
1013  else if(code>255) throw std::runtime_error("Event code out of range");
1014  SCOPED_LOCK(evrLock);
1015 
1016  unsigned i;
1017 
1018  // spin fast
1019  for(i=0; i<100 && READ32(base, SwEvent) & SwEvent_Pend; i++) {}
1020 
1021  if(i==100) {
1022  // spin slow for <= 50ms
1023  for(i=0; i<5 && READ32(base, SwEvent) & SwEvent_Pend; i++)
1024  epicsThreadSleep(0.01);
1025 
1026  if(i==5)
1027  throw std::runtime_error("SwEvent timeout");
1028  }
1029 
1031 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
#define SwEvent_Code_SHIFT
Definition: evgRegMap.h:91
#define SwEvent_Ena
Definition: evgRegMap.h:88
#define SwEvent_Pend
Definition: evgRegMap.h:89
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ setExtInhib()

void EVRMRM::setExtInhib ( bool  v)
virtual

Implements EVR.

Definition at line 639 of file drvem.cpp.

640 {
641  SCOPED_LOCK(evrLock);
642  if(v)
643  BITSET(NAT,32,base, Control, Control_GTXio);
644  else
645  BITCLR(NAT,32,base, Control, Control_GTXio);
646 }
#define BITCLR(ord, len, base, offset, mask)
Definition: mrfBitOps.h:26
volatile unsigned char *const base
Definition: drvem.h:223
#define Control_GTXio
Definition: evrRegMap.h:68
#define BITSET(ord, len, base, offset, mask)
Definition: mrfBitOps.h:21
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ setSourceTS()

void EVRMRM::setSourceTS ( TSSource  )
virtual

Select source which increments TS counter.

Implements EVR.

Definition at line 665 of file drvem.cpp.

666 {
667  double clk=clockTS(), eclk=clock();
668  epicsUInt16 div=0;
669 
670  if(clk<=0 || !isfinite(clk))
671  throw std::out_of_range("TS Clock rate invalid");
672 
673  switch(src){
674  case TSSourceInternal:
675  case TSSourceEvent:
676  case TSSourceDBus4:
677  break;
678  default:
679  throw std::out_of_range("TS source invalid");
680  }
681 
682  SCOPED_LOCK(evrLock);
683 
684  switch(src){
685  case TSSourceInternal:
686  // div!=0 selects src internal
687  div=(epicsUInt16)(eclk/clk);
688  break;
689  case TSSourceEvent:
690  BITCLR(NAT,32, base, Control, Control_tsdbus);
691  // div=0
692  break;
693  case TSSourceDBus4:
694  BITSET(NAT,32, base, Control, Control_tsdbus);
695  // div=0
696  break;
697  }
698  WRITE32(base, CounterPS, div);
699  shadowCounterPS=div;
700  shadowSourceTS=src;
701 }
#define BITCLR(ord, len, base, offset, mask)
Definition: mrfBitOps.h:26
virtual double clock() const OVERRIDE FINAL
Definition: drvem.h:141
#define Control_tsdbus
Definition: evrRegMap.h:73
volatile unsigned char *const base
Definition: drvem.h:223
#define isfinite
Definition: mrfCommon.h:326
virtual double clockTS() const OVERRIDE FINAL
Definition: drvem.cpp:704
#define BITSET(ord, len, base, offset, mask)
Definition: mrfBitOps.h:21
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ setTimeSrc()

void EVRMRM::setTimeSrc ( epicsUInt32  mode)

Definition at line 1039 of file drvem.cpp.

1040 {
1041  switch((timeSrcMode_t)raw) {
1042  case Disable:
1043  case External:
1044  case SysClk:
1045  break;
1046  default:
1047  throw std::runtime_error("Unsupported time source mode");
1048  }
1049  timeSrcMode_t mode((timeSrcMode_t)raw);
1050 
1051  bool changed;
1052  {
1053  SCOPED_LOCK(evrLock);
1054 
1055  changed = timeSrcMode!=mode;
1056 
1057  timeSrcMode = mode;
1058  }
1059 
1060  if(changed)
1061  softSecondsSrc(mode==SysClk);
1062 }
void softSecondsSrc(bool enable)
enable sending of event 125 by software timer. Simulation of external HW clock
Definition: mrmtimesrc.cpp:231
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ SourceTS()

virtual TSSource EVRMRM::SourceTS ( ) const
inlinevirtual

Implements EVR.

Definition at line 166 of file drvem.h.

167  {SCOPED_LOCK(evrLock);return shadowSourceTS;}
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ specialMapped()

bool EVRMRM::specialMapped ( epicsUInt32  code,
epicsUInt32  func 
) const
virtual

Hook to handle general event mapping table manipulation. Allows 'special' events only (ie heartbeat, log, led, etc) Normal mappings (pulsers, outputs) must be made through the appropriate class (Pulser, Output).

Note: this is one place where Device Support will have some depth.

Implements EVR.

Definition at line 505 of file drvem.cpp.

506 {
507  if(code>255)
508  throw std::out_of_range("Event code is out of range (0-255)");
509  if(func>127 || func<96 ||
510  (func<=121 && func>=102) )
511  {
512  throw std::out_of_range("Special function code is out of range. Valid ranges: 96-101 and 122-127");
513  }
514 
515  if(code==0)
516  return false;
517 
518  SCOPED_LOCK(evrLock);
519 
520  return _ismap(code,func-96);
521 }
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ specialSetMap()

void EVRMRM::specialSetMap ( epicsUInt32  code,
epicsUInt32  func,
bool  v 
)
virtual

Implements EVR.

Definition at line 524 of file drvem.cpp.

525 {
526  if(code>255)
527  throw std::out_of_range("Event code is out of range");
528  /* The special function codes are the range 96 to 127, excluding 102 to 121
529  */
530  if(func>127 || func<96 ||
531  (func<=121 && func>=102) )
532  {
533  errlogPrintf("EVR %s code %02x func %3d out of range. Code range is 0-255, where function rangs are 96-101 and 122-127\n",
534  name().c_str(), code, func);
535  throw std::out_of_range("Special function code is out of range. Valid ranges: 96-101 and 122-127");
536  }
537 
538  if(code==0)
539  return;
540 
541  /* The way the latch timestamp is implimented in hardware (no status bit)
542  * makes it impossible to use the latch mapping and the latch control register
543  * bits at the same time. We use the control register bits.
544  * However, there is not much loss of functionality since all events
545  * can be timestamped in the FIFO.
546  */
547  if(func==126)
548  throw std::out_of_range("Use of latch timestamp special function code is not allowed");
549 
550  epicsUInt32 bit =func%32;
551  epicsUInt32 mask=1<<bit;
552 
553  SCOPED_LOCK(evrLock);
554 
555  epicsUInt32 val=READ32(base, MappingRam(0, code, Internal));
556 
557  if (v == _ismap(code,func-96)) {
558  // mapping already set defined
559 
560  } else if(v) {
561  _map(code,func-96);
562  WRITE32(base, MappingRam(0, code, Internal), val|mask);
563  } else {
564  _unmap(code,func-96);
565  WRITE32(base, MappingRam(0, code, Internal), val&~mask);
566  }
567 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223
const std::string & name() const
Definition: object.h:393
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ timeSrc()

epicsUInt32 EVRMRM::timeSrc ( ) const

Definition at line 1033 of file drvem.cpp.

1034 {
1035  SCOPED_LOCK(evrLock);
1036  return timeSrcMode;
1037 }
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ TimeStampValid()

bool EVRMRM::TimeStampValid ( ) const
virtual

Implements EVR.

Definition at line 768 of file drvem.cpp.

769 {
770  SCOPED_LOCK(evrLock);
771  return timestampValid>=TSValidThreshold;
772 }
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96
#define TSValidThreshold
Definition: drvem.cpp:114

◆ TimeStampValidEvent()

virtual IOSCANPVT EVRMRM::TimeStampValidEvent ( ) const
inlinevirtual

Implements EVR.

Definition at line 173 of file drvem.h.

173 {return timestampValidChange;}

◆ topId()

epicsUInt32 EVRMRM::topId ( ) const

Definition at line 1004 of file drvem.cpp.

1005 {
1006  return READ32(base, TOPID);
1007 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223

◆ tsDiv()

virtual epicsUInt32 EVRMRM::tsDiv ( ) const
inlinevirtual

When using internal TS source gives the divider from event clock period to TS period.

Implements EVR.

Definition at line 162 of file drvem.h.

163  {SCOPED_LOCK(evrLock);return shadowCounterPS;}
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ unlock()

virtual void EVRMRM::unlock ( ) const
inlinevirtual

Implements mrf::Object.

Definition at line 122 of file drvem.h.

122 {evrLock.unlock();};
epicsMutex evrLock
Guards access to instance All callers must take this lock before any operations on this object...
Definition: drvem.h:96

◆ uSecDiv()

epicsUInt32 EVRMRM::uSecDiv ( ) const
virtual

Approximate divider from event clock period to 1us.

Implements EVR.

Definition at line 626 of file drvem.cpp.

627 {
628  return READ32(base, USecDiv);
629 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223

◆ version()

MRFVersion EVRMRM::version ( ) const
virtual

Firmware Version.

Implements EVR.

Definition at line 415 of file drvem.cpp.

416 {
417  return MRFVersion(READ32(base, FWVersion));
418 }
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
volatile unsigned char *const base
Definition: drvem.h:223

Friends And Related Function Documentation

◆ EVRMRMTSBuffer

friend struct EVRMRMTSBuffer
friend

Definition at line 322 of file drvem.h.

Member Data Documentation

◆ base

volatile unsigned char* const EVRMRM::base

Definition at line 223 of file drvem.h.

◆ baselen

epicsUInt32 EVRMRM::baselen

Definition at line 224 of file drvem.h.

◆ bufrx

mrmBufRx EVRMRM::bufrx

Definition at line 226 of file drvem.h.

◆ buftx

mrmDataBufTx EVRMRM::buftx

Definition at line 225 of file drvem.h.

◆ conf

const Config* const EVRMRM::conf

Definition at line 222 of file drvem.h.

◆ evrLock

epicsMutex EVRMRM::evrLock
mutable

Guards access to instance All callers must take this lock before any operations on this object.

Definition at line 96 of file drvem.h.

◆ sfp

mrf::auto_ptr<SFP> EVRMRM::sfp

Definition at line 227 of file drvem.h.


The documentation for this class was generated from the following files: