ICP  1
period_card.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
3 #include "period_card.h"
4 
5 PeriodCard::PeriodCard(int position, ISISVME* vme, DAEstatus& status) : DAE2Card(position, vme, status)
6 {
7  std::ostringstream message;
8  printStatus(message, status);
9  status.addInfo(FAC_ENVCARD, message.str());
10 }
11 
12 struct period_modes
13 {
14  int bit;
15  const char* unset;
16  const char* set;
17 };
18 
19 static const period_modes mode_list[] = {
20  {10, "Extract Trigger Veto Disabled", "Extract Trigger Veto Enabled" },
21  {9, "50Hz Veto Disabled", "50Hz Veto Enabled" },
22  {8, "Internal Period Clock Mode", "External Period Clock Mode" },
23  {7, "", "Multiple Period sequence complete" },
24  {6, "Single period sequence mode", "Multiple period sequence mode" },
25  {5, "Internal period control mode", "External period control mode" },
26  {4, "Non-period mode", "Period mode"},
27  {3, "", "Run ended AND period sequence completed" },
28  {2, "", "Period sequence complete" },
29  {1, "", "End after period sequence complete has been requested" },
30 };
31 
32 void PeriodCard::printStatus(std::ostream& os, DAEstatus& status)
33 {
34  DAE2Card::printStatus(os, status);
35  isisU32_t value32;
36  isisU16_t value16;
37  int i, nper;
38  os << "This is an PERIOD card" << std::endl;
39  os << "Current period number = " << getCurrentPeriodNumber(status) << (inDwellPeriod(status) ? " (DWELL)" : " (DAQ)") << std::endl;
40  nper = getNumberOfPeriods(status);
41  os << "Number of periods = " << nper << std::endl;
42  readRegister(PSCNT, &value16, status);
43  os << "Period sequence number = " << value16 << std::endl;
44  getExtractTriggerVetoCount(&value32, status);
45  os << "Extract trigger veto count = " << value32 << std::endl;
46  readRegister(PCREG, &value16, status);
47  os << "Summary of period control register" << std::endl;
48  for(i=0; i<sizeof(mode_list)/sizeof(period_modes); i++)
49  {
50  if (value16 & (1 << mode_list[i].bit))
51  {
52  os << "Bit " << mode_list[i].bit << " is SET (" << mode_list[i].set << ")" << std::endl;
53  }
54  else
55  {
56  os << "Bit " << mode_list[i].bit << " is CLEAR (" << mode_list[i].unset << ")" << std::endl;
57  }
58  }
59  isisU16_t* frames_needed = new isisU16_t[nper];
60  isisU32_t* good_frames = new isisU32_t[nper];
61  isisU32_t* raw_frames = new isisU32_t[nper];
62  isisU16_t* dwell_flags = new isisU16_t[nper];
63  isisU32_t* outputs = new isisU32_t[nper];
64  readPERLUT(dwell_flags, frames_needed, nper, status);
65  readOUTLUT(outputs, nper, status);
66  getRawFrames(0, nper, raw_frames, status);
67  getGoodFrames(0, nper, good_frames, status);
68  os << "Summary of period card programming (1st 16 max)" << std::endl;
69  for(i=0; i< (nper < 16 ? nper : 16); i++)
70  {
71  os << "Period " << i << (dwell_flags[i] != 0 ? " (DWELL)" : " (DAQ)") << std::endl;
72  os << "\tRequested frames = " << frames_needed[i] << " logic signal output = 0x" << std::hex << outputs[i] << std::dec << std::endl;
73  os << "\tCurrent counters (should always be ZERO for DWELL): raw = " << raw_frames[i] << " good = " << good_frames[i] << std::endl;
74  }
75  delete[] frames_needed;
76  delete[] good_frames;
77  delete[] raw_frames;
78  delete[] outputs;
79  delete[] dwell_flags;
80  readRegister(MAT_1, &value32, status); os << "Matt's 0x4 register = " << std::hex << value32 << std::dec << std::endl;
81 }
82 
83 int PeriodCard::setPeriodControlBits(isisU32_t mask, bool preserve, DAEstatus& status)
84 {
85  return setRegisterBits(PCREG, mask, preserve, status);
86 }
87 
89 {
90  return clearRegisterBits(PCREG, mask, status);
91 }
92 
94 {
95  return setAndClearRegisterBits(PCREG, mask, preserve, status);
96 }
97 
99 {
100  return setAndClearPeriodControlBits(PCCLRVETO, true, status);
101 }
102 
104 {
105  return readRegister(EXTTRIGVC0, value, status);
106 }
107 
109 {
110  return readRegister(EXTTRIGVC1, value, status);
111 }
112 
114 {
115  return readRegister16As32(EXTTRIGVC0, EXTTRIGVC1, value, status);
116 }
117 
119 {
120  return setPeriodControlBits(PCEXTTRIG, true, status);
121 }
122 
124 {
125  return clearPeriodControlBits(PCEXTTRIG, status);
126 }
127 
129 {
130  return writeRegister16(LOOKTAR, TAROUTLUT, status);
131 }
132 
134 {
135  return writeRegister16(LOOKTAR, TARPERLUT, status);
136 }
137 
139 {
140  return writeRegister16(LOOKTAR, 0, status);
141 }
142 
144 {
145  isisU16_t period;
146  int stat = readRegister(MPCNT, &period, status);
147  period &= 0x3fff;
148  return period;
149 }
150 
152 {
153  isisU16_t period;
154  readRegister(MPCNT, &period, status);
155  return ((period & (1 << 14)) != 0);
156 }
157 
159 {
160  return writeRegister16(MPLIM, n-1, status); // as this is a period number limit register
161 }
162 
164 {
165  isisU16_t n;
166  readRegister(MPLIM, &n, status);
167  if (n >= MAX_NUM_PERIODS)
168  {
169  return MAX_NUM_PERIODS;
170  }
171  else
172  {
173  return n+1; // as this is a period number limit register
174  }
175 }
176 
178 {
179  isisU16_t n;
180  readRegister(PSCNT, &n, status);
181  return n;
182 }
183 
185 {
186 // setAndClearRegisterBits(MAT_1, (1 << 12), true, status);
187  setAndClearPeriodControlBits(PCRESET, true, status);
188  return writeRegister(MAT_1, 0, status); // raise veto to disable data collection
189 }
190 
192 {
193 // setAndClearRegisterBits(MAT_1, (1 << 12), true, status);
194  return setAndClearPeriodControlBits(PCCLRPC, true, status);
195 }
196 
198 {
199  return setPeriodControlBits(PC50HZENAB, true, status);
200 }
201 
203 {
204  return clearPeriodControlBits(PC50HZENAB, status);
205 }
206 
208 {
209  return clearPeriodControlBits(PCEXTPERCLK, status);
210 }
211 
213 {
214  return setPeriodControlBits(PCEXTPERCLK, true, status);
215 }
216 
218 {
219  return clearPeriodControlBits(PCMULENAB, status);
220 }
221 
223 {
224  return setPeriodControlBits(PCMULENAB, true, status);
225 }
226 
228 {
229  return clearPeriodControlBits(PCEXTENAB, status);
230 }
231 
233 {
234  return setPeriodControlBits(PCEXTENAB, true, status);
235 }
236 
238 {
239  return setPeriodControlBits(PCENAB, true, status);
240 }
241 
243 {
244  return clearPeriodControlBits(PCENAB, status);
245 }
246 
248 {
249  return setPeriodControlBits(PCENDAFTER, true, status);
250 }
251 
253 {
254  isisU16_t value;
255  readRegister(PCREG, &value, status);
256  if (value & PCENDSEQCOMP)
257  {
259  return true;
260  }
261  else
262  {
263  return false;
264  }
265 }
266 
268 {
270 }
271 
272 // dwell_flag is 0 for DAQ period, 1 for DWELL period
273 int PeriodCard::programPERLUT(isisU16_t* dwell_flags, isisU16_t* frames, int nperiod, DAEstatus& status)
274 {
275  int i;
276  isisU32_t* pdata = new isisU32_t[nperiod];
277  for(i=0; i<nperiod; i++)
278  {
279  if (frames[i] > 0)
280  {
281  pdata[i] = ((frames[i] - 1) & 0xffff) + (dwell_flags[i] != 0 ? (1 << 31) : 0);
282  }
283  else
284  {
285  pdata[i] = ((frames[i]) & 0xffff) + (dwell_flags[i] != 0 ? (1 << 31) : 0);
286  }
287  }
288  lookupAccessPERLUT(status);
289  zeroMemory(PERLUTSTART, PERLUTSIZE, 0xffffffff, false, false, status);
290  writeMemory(PERLUTSTART, pdata, nperiod, 0xffffffff, false, false, status);
291  lookupFinished(status);
292  delete []pdata;
293  return 0;
294 }
295 
296 int PeriodCard::readPERLUT(isisU16_t* dwell_flags, isisU16_t* frames, int nperiod, DAEstatus& status)
297 {
298  int i;
299  isisU32_t* pdata = new isisU32_t[nperiod];
300  lookupAccessPERLUT(status);
301  readMemory(PERLUTSTART, pdata, nperiod, false, false, status);
302  lookupFinished(status);
303  for(i=0; i<nperiod; i++)
304  {
305  frames[i] = (isisU16_t)((pdata[i] & 0xffff) + 1); // remove dwell flag
306  dwell_flags[i] = ( (pdata[i] & (1 << 31)) ? 1 : 0 );
307  }
308  delete []pdata;
309  return 0;
310 }
311 
312 // may also need to duplicate up last value in location n+1
313 // in case counter in DAE increemnts too far briefly before reset
314 int PeriodCard::programOUTLUT(isisU32_t* outputs, int nperiod, DAEstatus& status)
315 {
316  isisU32_t tmp32;
317  lookupAccessOUTLUT(status);
318  zeroMemory(OUTLUTSTART, OUTLUTSIZE, 0xffffffff, false, false, status);
319  writeMemory(OUTLUTSTART, outputs, nperiod, 0xffffffff, false, false, status);
320 // also write last output value to n+1 location; this is a workaround to catch the small
321 // amout of time that it might get read between a period increment and a period reset
322 // tmp32 = outputs[nperiod-1]; // write last value again
323  tmp32 = 4; // debug value for Matt Roberts
324  writeMemory(OUTLUTSTART + 4*nperiod, &tmp32, 1, 0xffffffff, false, false, status);
325  lookupFinished(status);
326  return 0;
327 }
328 
329 int PeriodCard::readOUTLUT(isisU32_t* outputs, int nperiod, DAEstatus& status)
330 {
331  int i;
332  lookupAccessOUTLUT(status);
333 // we seem to need to start the outlut at address+1
334  readMemory(OUTLUTSTART, outputs, nperiod, false, false, status);
335  lookupFinished(status);
336  for(i=0; i<nperiod; i++)
337  {
338  outputs[i] &= 0xffff; // remove junk from top 16 bits
339  }
340  return 0;
341 }
342 
344 {
345  zeroMemory(RFCNT0START, RFCNT0SIZE, 0xffffffff, false, false, status);
346  zeroMemory(GFCNT0START, GFCNT0SIZE, 0xffffffff, false, false, status);
347  return 0;
348 }
349 
350 int PeriodCard::getPeriodRawFrames(int period, isisU32_t* frames, DAEstatus& status)
351 {
352  return getRawFrames(period, 1, frames, status);
353 }
354 
355 int PeriodCard::getPeriodGoodFrames(int period, isisU32_t* frames, DAEstatus& status)
356 {
357  return getGoodFrames(period, 1, frames, status);
358 }
359 
361 {
362  return getRequestedFrames(period, 1, frames, status);
363 }
364 
365 int PeriodCard::getRequestedFrames(int period_start, int nperiod, isisU32_t frames[], DAEstatus& status)
366 {
367  int i;
368  lookupAccessPERLUT(status);
369  readMemory(PERLUTSTART+4*period_start, frames, nperiod, false, false, status);
370  lookupFinished(status);
371  for(i=0; i<nperiod; i++)
372  {
373  frames[i] = ((frames[i] & 0xffff) + 1); // remove dwell flag
374  }
375  return 0;
376 }
377 
378 int PeriodCard::getRawFrames(int period_start, int nperiod, isisU32_t frames[], DAEstatus& status)
379 {
380  int seq = getCurrentPeriodSequence(status);
381  isisU32_t* req_frames = new isisU32_t[nperiod];
382  getRequestedFrames(period_start, nperiod, req_frames, status);
383  readMemory(RFCNT0START + 4*period_start, frames, nperiod, false, false, status);
384 // not needed now
385 // for(i=0; i<nperiod; i++)
386 // {
387 // frames[i] += (seq * req_frames[i]);
388 // }
389  delete[] req_frames;
390  return status.result();
391 }
392 
393 int PeriodCard::getGoodFrames(int period_start, int nperiod, isisU32_t frames[], DAEstatus& status)
394 {
395  int seq = getCurrentPeriodSequence(status);
396  isisU32_t* req_frames = new isisU32_t[nperiod];
397  getRequestedFrames(period_start, nperiod, req_frames, status);
398  readMemory(GFCNT0START + 4*period_start, frames, nperiod, false, false, status);
399 // not needed now
400 // for(i=0; i<nperiod; i++)
401 // {
402 // frames[i] += (seq * req_frames[i]);
403 // }
404  delete[] req_frames;
405  return status.result();
406 }
407 
409 {
410  return setRegisterBits(MAT_1, (1 << 4), true, status);
411 }
412 
414 {
415  return clearRegisterBits(MAT_1, (1 << 4), status);
416 }
int setMultiplePeriodSequenceMode(DAEstatus &status)
int lookupAccessOUTLUT(DAEstatus &status)
int startDataCollection(DAEstatus &status)
int setPeriodControlBits(isisU32_t mask, bool preserve, DAEstatus &status)
Definition: period_card.cpp:83
#define RFCNT0START
Definition: period_card.h:31
int setInternalPeriodControlMode(DAEstatus &status)
#define RFCNT0SIZE
Definition: period_card.h:36
#define EXTTRIGVC1
Definition: period_card.h:15
#define PCMULENAB
Definition: period_card.h:54
int getExtractTriggerVetoCount(isisU32_t *value, DAEstatus &status)
int getCurrentPeriodSequence(DAEstatus &status)
#define PCENAB
Definition: period_card.h:52
int programPERLUT(isisU16_t *dwell_flags, isisU16_t *frames, int nperiod, DAEstatus &status)
int enableExtractTriggerVeto(DAEstatus &status)
#define GFCNT0START
Definition: period_card.h:33
int readPERLUT(isisU16_t *dwell_flags, isisU16_t *frames, int nperiod, DAEstatus &status)
int setRegisterBits(unsigned long address, isisU32_t mask, bool preserve, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:183
int endRunAfterSequenceCompletes(DAEstatus &status)
int lookupAccessPERLUT(DAEstatus &status)
int setSinglePeriodSequenceMode(DAEstatus &status)
unsigned long isisU32_t
Definition: isisvme_types.h:8
int getNumberOfPeriods(DAEstatus &status)
#define MAX_NUM_PERIODS
Definition: period_card.h:6
int stopDataCollection(DAEstatus &status)
int disable50HzVeto(DAEstatus &status)
int disableExtractTriggerVeto(DAEstatus &status)
int zeroPeriodFrameCounters(DAEstatus &status)
int clearRegisterBits(unsigned long address, isisU32_t mask, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:201
virtual void printStatus(std::ostream &os, DAEstatus &dstatus)
Definition: dae2_card.cpp:453
#define OUTLUTSTART
Definition: period_card.h:28
int getPeriodGoodFrames(int period, isisU32_t *frames, DAEstatus &status)
void abortSequenceCompleteWait(DAEstatus &status)
int enablePeriodMode(DAEstatus &status)
int readOUTLUT(isisU32_t *outputs, int nperiod, DAEstatus &status)
const char * unset
int setAndClearPeriodControlBits(isisU32_t mask, bool preserve, DAEstatus &status)
Definition: period_card.cpp:93
#define TARPERLUT
Definition: period_card.h:42
int readMemory(unsigned long address, typename T *buffer, int len, ISISVME::TransferProps props, DAEstatus &status)
Definition: dae2_card.h:106
#define TAROUTLUT
Definition: period_card.h:43
int writeRegister(unsigned long address, isisU32_t value, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:155
int clearVetoCounters(DAEstatus &status)
Definition: period_card.cpp:98
PeriodCard(int position, ISISVME *vme, DAEstatus &status)
Definition: period_card.cpp:5
int enable50HzVeto(DAEstatus &status)
#define PCEXTENAB
Definition: period_card.h:53
int getPeriodRawFrames(int period, isisU32_t *frames, DAEstatus &status)
int readRegister(unsigned long address, isisU32_t *value, DAEstatus &status, bool little_endian=false, bool retry=true)
Definition: dae2_card.cpp:23
int setAndClearRegisterBits(unsigned long address, isisU32_t mask, bool preserve, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:243
int clearPeriodControlBits(isisU32_t mask, DAEstatus &status)
Definition: period_card.cpp:88
#define PCCLRVETO
Definition: period_card.h:59
#define PCENDSEQCOMP
Definition: period_card.h:51
int disablePeriodMode(DAEstatus &status)
unsigned short isisU16_t
Definition: isisvme_types.h:7
void printStatus(std::ostream &os, DAEstatus &status)
Definition: period_card.cpp:32
#define MAT_1
Definition: period_card.h:4
#define GFCNT0SIZE
Definition: period_card.h:38
#define PCENDAFTER
Definition: period_card.h:49
#define OUTLUTSIZE
Definition: period_card.h:29
#define PERLUTSIZE
Definition: period_card.h:25
#define PCREG
Definition: period_card.h:21
#define PCEXTTRIG
Definition: period_card.h:58
int getExtractTriggerVetoCountHigh(isisU16_t *value, DAEstatus &status)
int lookupFinished(DAEstatus &status)
int getRawFrames(int period_start, int nperiod, isisU32_t frames[], DAEstatus &status)
int getGoodFrames(int period_start, int nperiod, isisU32_t frames[], DAEstatus &status)
int setNumberOfPeriods(isisU16_t n, DAEstatus &status)
bool isRunEndedAndSequenceComplete(DAEstatus &status)
#define EXTTRIGVC0
Definition: period_card.h:14
int clearPeriodCounters(DAEstatus &status)
#define PERLUTSTART
Definition: period_card.h:24
int setExternalPeriodClockMode(DAEstatus &status)
int writeMemory(unsigned long address, T *buffer, int len, uint64_t read_check_mask, ISISVME::TransferProps props, DAEstatus &status)
Definition: dae2_card.h:128
#define PCEXTPERCLK
Definition: period_card.h:56
bool inDwellPeriod(DAEstatus &status)
int programOUTLUT(isisU32_t *outputs, int nperiod, DAEstatus &status)
int resetCard(DAEstatus &status)
#define PCRESET
Definition: period_card.h:61
int writeRegister16(unsigned long address, isisU16_t value, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:169
int getPeriodRequestedFrames(int period, isisU32_t *frames, DAEstatus &status)
#define FAC_ENVCARD
int getExtractTriggerVetoCountLow(isisU16_t *value, DAEstatus &status)
int getCurrentPeriodNumber(DAEstatus &status)
int readRegister16As32(unsigned long address0, unsigned long address1, isisU32_t *value, DAEstatus &status, bool little_endian=false)
Definition: dae2_card.cpp:114
int setExternalPeriodControlMode(DAEstatus &status)
#define MPCNT
Definition: period_card.h:10
int addInfo(int facility, const std::string &text)
Definition: DAEstatus.cpp:86
#define LOOKTAR
Definition: period_card.h:20
#define PC50HZENAB
Definition: period_card.h:57
int result()
Definition: DAEstatus.h:144
#define PSCNT
Definition: period_card.h:12
static const period_modes mode_list[]
Definition: period_card.cpp:19
#define PCCLRPC
Definition: period_card.h:60
int zeroMemory(unsigned long start, int len, uint64_t read_check_mask, ISISVME::TransferProps props, DAEstatus &status)
Definition: dae2_card.h:179
int getRequestedFrames(int period_start, int nperiod, isisU32_t frames[], DAEstatus &status)
#define MPLIM
Definition: period_card.h:11
const char * set
int setInternalPeriodClockMode(DAEstatus &status)