ICP  1
sim_dae2_card.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
3 #include "sim_dae2_card.h"
4 #include "isisvme.h"
5 
6 // fw32 means 32bit firmware reg - now all are 32 bit
7 template <class DAECardPolicy>
8 SIMDAE2Card<DAECardPolicy>::SIMDAE2Card(int position, VMESimulationIface* vme, isisU32_t firmware, bool fw32, FaultMode fault_mode, DAEstatus& status) : Base(), m_position(position), m_type(UnknownCard), m_vme(vme), m_veto_raised(false), m_is_running(true), m_firmware(firmware)
9 {
10  m_firmware = firmware;
11  addMapping(ISISVME::TransferIORegisterSpace, FIRMVERS, 1, &m_firmware, "", true, false, NULL, 0, false, false, fault_mode);
12 }
13 
14 template <class DAECardPolicy>
16 {
17  os << "SIMDAE2 card at position " << m_position;
18 }
19 
20 template <class DAECardPolicy>
21 int SIMDAE2Card<DAECardPolicy>::addMapping(ISISVME::TransferProps props, isisU32_t address, int n, isisU32_t* var, const char* name, bool readable,
22  bool writable, isisU32_t* access_reg, unsigned access_bit, bool wrap,
23  bool sixteen_bit_access, FaultMode fault_mode)
24 {
25  if (n > 0)
26  {
27  m_mapping.push_back(sim_mapping(props, address, n, sizeof(isisU32_t), var, name, readable, writable, access_reg, access_bit, wrap, sixteen_bit_access, fault_mode));
28  }
29  return 0;
30 }
31 
32 template <class DAECardPolicy>
33 int SIMDAE2Card<DAECardPolicy>::addMapping(ISISVME::TransferProps props, isisU32_t address, int n, uint64_t* var, const char* name, bool readable,
34  bool writable, isisU32_t* access_reg, unsigned access_bit, bool wrap,
35  bool sixteen_bit_access, FaultMode fault_mode)
36 {
37  if (n > 0)
38  {
39  m_mapping.push_back(sim_mapping(props, address, n, sizeof(uint64_t), var, name, readable, writable, access_reg, access_bit, wrap, sixteen_bit_access, fault_mode));
40  }
41  return 0;
42 }
43 
44 template <class __type, class DAECardPolicy>
45 static int simulateRead(SIMDAE2Card<DAECardPolicy>* d2card, ISISVME::TransferProps props, unsigned long address, __type *data, long nitems, DAEstatus& status)
46 {
47  int i, j, card;
48  int ts = sizeof(__type);
49  bool access_reg_ok;
50  card = DAECardPolicy::cardFromAddress(address);
51  bool done = false;
52  if (card != d2card->position())
53  {
54  return ISISVME::Error;
55  }
56  std::vector<sim_mapping>& mapping = d2card->mapping();
57  address = DAECardPolicy::baseAddress(address); // clear card number bit
58  __type *var;
59  for(i=0; i<mapping.size() && !done; i++)
60  {
61  access_reg_ok = ( (mapping[i].access_reg == NULL) || ((*(mapping[i].access_reg) & mapping[i].access_bit) != 0) );
62  if ( access_reg_ok && (address >= mapping[i].address) && (props & mapping[i].props) )
63  {
64  if (mapping[i].fault_mode != Working)
65  {
66  continue;
67  }
68  else if ( (address + ts * nitems) <= (mapping[i].address + ts * mapping[i].n) )
69  {
70  address -= mapping[i].address;
71  var = mapping[i].var<__type>();
72  for(j=0; j<nitems; j++)
73  {
74  data[j] = var[j + address/4];
75  }
76  done = true;
77  }
78  else if (mapping[i].wrap)
79  {
80  address -= mapping[i].address;
81  var = mapping[i].var<__type>();
82  for(j=0; j<nitems; j++)
83  {
84  data[j] = var[(j + address/ts) % mapping[i].n];
85  }
86  done = true;
87  }
88  }
89  }
90  if (done)
91  {
92  return ISISVME::Success;
93  }
94  else
95  {
96  return ISISVME::Error;
97  }
98 }
99 
100 template <class __type, class DAECardPolicy>
101 static int simulateWrite(SIMDAE2Card<DAECardPolicy>* d2card, ISISVME::TransferProps props, unsigned long address, __type *data, long nitems, DAEstatus& status)
102 {
103  int i, j, card;
104  int ts = sizeof(__type);
105  card = DAECardPolicy::cardFromAddress(address);
106  bool done = false;
107  if (card != d2card->position())
108  {
109  return ISISVME::Error;
110  }
111  std::vector<sim_mapping>& mapping = d2card->mapping();
112  address = DAECardPolicy::baseAddress(address); // clear card number bit
113  for(i=0; i<mapping.size() && !done; i++)
114  {
115  if ( (address >= mapping[i].address) && (props & mapping[i].props) &&
116  ( (mapping[i].access_reg == NULL) || ((*(mapping[i].access_reg) & mapping[i].access_bit) != 0) ) )
117  {
118  if (mapping[i].fault_mode != Working)
119  {
120  continue;
121  }
122  else if (address + ts * nitems <= mapping[i].address + mapping[i].ws * mapping[i].n)
123  {
124  address -= mapping[i].address;
125  for(j=0; j<nitems; j++)
126  {
127  (mapping[i].var<__type>())[j + address/ts] = data[j];
128  }
129  done = true;
130  }
131  else if (mapping[i].wrap)
132  {
133  address -= mapping[i].address;
134  for(j=0; j<nitems; j++)
135  {
136  (mapping[i].var<__type>())[(j + address/ts) % mapping[i].n] = data[j];
137  }
138  done = true;
139  }
140  }
141  }
142  if (done)
143  {
144  return ISISVME::Success;
145  }
146  else
147  {
148  return ISISVME::Error;
149  }
150 }
151 
152 
153 template <class DAECardPolicy>
154 int SIMDAE2Card<DAECardPolicy>::read16(ISISVME::TransferProps props, unsigned long address, isisU16_t* data16, long nitems, DAEstatus& status)
155 {
156  return simulateRead<isisU16_t>(this, props, address, data16, nitems, status);
157 }
158 
159 template <class DAECardPolicy>
160 int SIMDAE2Card<DAECardPolicy>::read32(ISISVME::TransferProps props, unsigned long address, isisU32_t* data32, long nitems, DAEstatus& status)
161 {
162  return simulateRead<isisU32_t>(this, props, address, data32, nitems, status);
163 }
164 
165 template <class DAECardPolicy>
166 int SIMDAE2Card<DAECardPolicy>::write16(ISISVME::TransferProps props, unsigned long address, isisU16_t* data16, long nitems, DAEstatus& status)
167 {
168  return simulateWrite<isisU16_t>(this, props, address, data16, nitems, status);
169 }
170 
171 template <class DAECardPolicy>
172 int SIMDAE2Card<DAECardPolicy>::write32(ISISVME::TransferProps props, unsigned long address, isisU32_t* data32, long nitems, DAEstatus& status)
173 {
174  return simulateWrite<isisU32_t>(this, props, address, data32, nitems, status);
175 }
176 
177 
178 template <class DAECardPolicy>
180 {
181  low += value;
182 }
183 
184 
185 template <class DAECardPolicy>
187 {
188  low += value;
189  while(low > 0xffff)
190  {
191  low -= 65536;
192  ++high;
193  }
194 }
195 
196 template <class DAECardPolicy>
198 {
199  if ((low + (isisU32_t)value) < low)
200  {
201  ++high;
202  }
203  low += (isisU32_t)value;
204 }
205 
206 template <class DAECardPolicy>
207 void SIMDAE2Card<DAECardPolicy>::increment32(int value, uint64_t& low, isisU32_t& high)
208 {
209  if ((low + (uint64_t)value) < low)
210  {
211  ++high;
212  }
213  low += (uint64_t)value;
214 }
215 
216 template <class DAECardPolicy>
218 {
219  low += value;
220  while (low > 0xffff)
221  {
222  low -= 65536;
223  if (++middle > 0xffff)
224  {
225  middle = 0;
226  ++high;
227  }
228  }
229 }
230 
231 template class SIMDAE2Card<DAE2CardPolicy>;
232 template class SIMDAE2Card<DAE2EnvPeriodPolicy>;
233 template class SIMDAE2Card<DAE2DetCardPolicy>;
234 
235 template class SIMDAE2Card<DAE3CardPolicy>;
236 template class SIMDAE2Card<DAE3EnvPeriodPolicy>;
237 template class SIMDAE2Card<DAE3DetCardPolicy>;
uint32_t TransferProps
combination of TransferProp values
Definition: isisvme.h:16
isisU32_t m_firmware
Definition: sim_dae2_card.h:91
int position()
Definition: sim_dae2_card.h:45
static void increment2(int value, isisU32_t &low, isisU32_t &high)
int read32(ISISVME::TransferProps props, unsigned long address, isisU32_t *data32, long nitems, DAEstatus &status)
int write32(ISISVME::TransferProps props, unsigned long address, isisU32_t *data32, long nitems, DAEstatus &status)
int read16(ISISVME::TransferProps props, unsigned long address, isisU16_t *data16, long nitems, DAEstatus &status)
virtual void printStatus(std::ostream &os)=0
unsigned long isisU32_t
Definition: isisvme_types.h:8
static void increment32(int value, isisU32_t &low, isisU32_t &high)
static int simulateWrite(SIMDAE2Card< DAECardPolicy > *d2card, ISISVME::TransferProps props, unsigned long address, __type *data, long nitems, DAEstatus &status)
static void increment3(int value, isisU32_t &low, isisU32_t &middle, isisU32_t &high)
int addMapping(ISISVME::TransferProps props, isisU32_t address, int n, isisU32_t *var, const char *name, bool readable, bool writable, isisU32_t *access_reg, unsigned access_bit, bool wrap, bool sixteen_bit_access, FaultMode fault_mode)
static void increment(int value, isisU32_t &low)
SIMDAE2Card(int position, VMESimulationIface *vme, isisU32_t firmware, bool fw32, FaultMode fault_mode, DAEstatus &status)
unsigned short isisU16_t
Definition: isisvme_types.h:7
std::vector< sim_mapping > & mapping()
Definition: sim_dae2_card.h:59
int write16(ISISVME::TransferProps props, unsigned long address, isisU16_t *data16, long nitems, DAEstatus &status)
static int simulateRead(SIMDAE2Card< DAECardPolicy > *d2card, ISISVME::TransferProps props, unsigned long address, __type *data, long nitems, DAEstatus &status)
FaultMode
Definition: sim_dae2_card.h:10