mrfioc2  2.3.0
drvemOutput.cpp
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2013 Brookhaven Science Associates, as Operator of
3 * Brookhaven National Laboratory.
4 * mrfioc2 is distributed subject to a Software License Agreement found
5 * in file LICENSE that is included with this distribution.
6 \*************************************************************************/
7 /*
8  * Author: Michael Davidsaver <mdavidsaver@gmail.com>
9  */
10 
11 
12 #include "evrRegMap.h"
13 #include "drvem.h"
14 
15 #include <mrfCommon.h>
16 #include <mrfCommonIO.h>
17 #include <mrfBitOps.h>
18 
19 #include <stdexcept>
20 #include "drvemOutput.h"
21 
22 MRMOutput::MRMOutput(const std::string& n, EVRMRM* o, OutputType t, unsigned int idx)
23  :base_t(n)
24  ,owner(o)
25  ,type(t)
26  ,N(idx)
27  ,isEnabled(true)
28 {
29  shadowSource = sourceInternal();
30 }
31 
33 
34 void MRMOutput::lock() const{owner->lock();}
35 void MRMOutput::unlock() const{owner->unlock();}
36 
37 epicsUInt32
39 {
40  return shadowSource&0xff;
41 }
42 
43 epicsUInt32
45 {
46  return (shadowSource>>8)&0xff;
47 }
48 
49 void
50 MRMOutput::setSource(epicsUInt32 v)
51 {
52  if( ! ( (v<=63 && v>=61) ||
53  (v<=55 && v>=48) ||
54  (v<=42 && v>=32) ||
55  (v<=15) )
56  )
57  throw std::out_of_range("Mapping code is out of range");
58 
59  shadowSource &= 0xff00;
60  shadowSource |= v;
61 
62  if(isEnabled)
63  setSourceInternal();
64 }
65 
66 void
67 MRMOutput::setSource2(epicsUInt32 v)
68 {
69  if( ! ( (v<=63 && v>=61) ||
70  (v<=55 && v>=48) ||
71  (v<=42 && v>=32) ||
72  (v<=15) )
73  )
74  throw std::out_of_range("Mapping code is out of range");
75 
76  shadowSource &= 0x00ff;
77  shadowSource |= v<<8;
78 
79  if(isEnabled)
80  setSourceInternal();
81 }
82 
83 bool
85 {
86  return isEnabled;
87 }
88 
89 void
91 {
92  if(e==isEnabled)
93  return;
94 
95  isEnabled = e;
96 
97  setSourceInternal();
98 }
99 
100 epicsUInt32
101 MRMOutput::sourceInternal() const
102 {
103  epicsUInt32 val=64; // an invalid value
104  switch(type) {
105  case OutputInt:
106  return READ32(owner->base, IRQPulseMap) & 0xffff;
107  case OutputFP:
108  val = READ32(owner->base, OutputMapFP(N)); break;
109  case OutputFPUniv:
110  val = READ32(owner->base, OutputMapFPUniv(N)); break;
111  case OutputRB:
112  val = READ32(owner->base, OutputMapRB(N)); break;
113  case OutputBackplane:
114  val = READ32(owner->base, OutputMapBackplane(N)); break;
115  }
116  val &= Output_mask(N);
117  val >>= Output_shift(N);
118  return val;
119 }
120 
121 void
122 MRMOutput::setSourceInternal()
123 {
124  epicsUInt32 regval = shadowSource;
125  if(!isEnabled)
126  regval = 0x3f3f; // Force Low (TODO: when to tri-state?)
127 
128  epicsUInt32 val=63;
129  switch(type) {
130  case OutputInt:
131  WRITE32(owner->base, IRQPulseMap, regval); return;
132  case OutputFP:
133  val = READ32(owner->base, OutputMapFP(N)); break;
134  case OutputFPUniv:
135  val = READ32(owner->base, OutputMapFPUniv(N)); break;
136  case OutputRB:
137  val = READ32(owner->base, OutputMapRB(N)); break;
138  case OutputBackplane:
139  val = READ32(owner->base, OutputMapBackplane(N)); break;
140  }
141 
142  val &= ~Output_mask(N);
143  val |= regval << Output_shift(N);
144 
145  switch(type) {
146  case OutputInt:
147  break; // will not get here
148  case OutputFP:
149  WRITE32(owner->base, OutputMapFP(N), val); break;
150  case OutputFPUniv:
151  WRITE32(owner->base, OutputMapFPUniv(N), val); break;
152  case OutputRB:
153  WRITE32(owner->base, OutputMapRB(N), val); break;
154  case OutputBackplane:
155  WRITE32(owner->base, OutputMapBackplane(N), val); break;
156  }
157 }
158 
virtual ~MRMOutput()
Definition: drvemOutput.cpp:32
#define READ32(base, offset)
Definition: mrfCommonIO.h:114
MRMOutput(const std::string &n, EVRMRM *owner, OutputType t, unsigned int idx)
Definition: drvemOutput.cpp:22
virtual void setSource(epicsUInt32) OVERRIDE FINAL
Definition: drvemOutput.cpp:50
volatile unsigned char *const base
Definition: drvem.h:223
virtual void lock() const OVERRIDE FINAL
Definition: drvemOutput.cpp:34
virtual void enable(bool) OVERRIDE FINAL
Definition: drvemOutput.cpp:90
Internal.
Definition: output.h:19
#define OBJECT_BEGIN2(klass, Base)
Definition: object.h:507
Modular Register Map Event Receivers.
Definition: drvem.h:86
Definition: output.h:26
virtual epicsUInt32 source() const OVERRIDE FINAL
Definition: drvemOutput.cpp:38
virtual void unlock() const OVERRIDE FINAL
Definition: drvemOutput.cpp:35
void setSource2(epicsUInt32)
Definition: drvemOutput.cpp:67
virtual bool enabled() const OVERRIDE FINAL
Definition: drvemOutput.cpp:84
#define Output_shift(N)
Definition: evrRegMap.h:229
Rear Breakout.
Definition: output.h:22
virtual void lock() const OVERRIDE FINAL
Definition: drvem.h:121
#define OBJECT_END(klass)
Definition: object.h:523
Front Panel.
Definition: output.h:20
FP Universal.
Definition: output.h:21
Backplane lines.
Definition: output.h:23
OBJECT_PROP2("Map2", &MRMOutput::source2, &MRMOutput::setSource2)
epicsUInt32 source2() const
Definition: drvemOutput.cpp:44
#define WRITE32(base, offset, value)
Definition: mrfCommonIO.h:119
#define Output_mask(N)
Definition: evrRegMap.h:228
OutputType
Definition: output.h:18
virtual void unlock() const OVERRIDE FINAL
Definition: drvem.h:122