ICP  1
sim_env_period_card.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
3 #include "vme_simulation.h"
4 #include "sim_env_period_card.h"
5 #include "isisvme.h"
6 
7 template <class EnvPeriodPolicy>
9  SIMDAE2Card(position, vme, ((1 << 30) | (1 << 25)), true, Working, status)
10 {
11  setLoggerName("SIMEnvPeriodCard");
13 
18  m_rawproton0 = new EnvPeriodPolicy::ppp_memory_t[RPCNT0SIZE];
19  m_goodproton0 = new EnvPeriodPolicy::ppp_memory_t[GPCNT0SIZE];
20  m_rawproton1 = new isisU32_t[RPCNT1SIZE];
21  m_goodproton1 = new isisU32_t[GPCNT1SIZE];
22  m_spare0 = new isisU32_t[SPARE0SIZE];
23  m_spare1 = new isisU32_t[SPARE1SIZE];
24 
25  isisU32_t* lookup_reg = NULL;
27  {
28  lookup_reg = &m_lookup;
29  addMapping(ISISVME::TransferIORegisterSpace, LOOKTAR, 1, &m_lookup, "", true, true, NULL, 0, false, false, fault_mode);
30  }
31  addMapping(ISISVME::TransferIORegisterSpace, MPCNT, 1, &m_main_period_counter, "", true, false, NULL, 0, false, false, fault_mode);
32  addMapping(ISISVME::TransferIORegisterSpace, MPLIM, 1, &m_main_period_limit, "", true, true, NULL, 0, false, false, fault_mode);
33  addMapping(ISISVME::TransferIORegisterSpace, PSCNT, 1, &m_period_sequence_counter, "", true, false, NULL, 0, false, false, fault_mode);
34  addMapping(ISISVME::TransferIORegisterSpace, PSLR, 1, &m_period_sequence_limit, "", true, true, NULL, 0, false, false, fault_mode);
35  addMapping(ISISVME::TransferIORegisterSpace, EXTPEROVFVC, 1, &m_ext_period_overflow_veto_counter, "", true, true, NULL, 0, false, false, fault_mode);
36  addMapping(ISISVME::TransferIORegisterSpace, PERINCTOT, 1, &m_period_increment_total, "", true, true, NULL, 0, false, false, fault_mode);
37 
38  addMapping(ISISVME::TransferIORegisterSpace, PEROUTDEL, 1, &m_period_output_delay, "", true, true, NULL, 0, false, false, fault_mode);
39  addMapping(ISISVME::TransferIORegisterSpace, PCREG, 1, &m_period_control, "", true, true, NULL, 0, false, false, fault_mode);
40  addMapping(ISISVME::TransferIORegisterSpace, ALT1SFV, 1, &m_alt1_fw, "", true, false, NULL, 0, false, false, fault_mode);
41  addMapping(ISISVME::TransferLUTSpace, PERLUTSTART, PERLUTSIZE, m_perlut, "perlut", true, true, lookup_reg, TARPERLUT, false, false, fault_mode);
42  addMapping(ISISVME::TransferLUTSpace, OUTLUTSTART, OUTLUTSIZE, m_outlut, "outlut", true, true, lookup_reg, TAROUTLUT, false, false, fault_mode);
43  addMapping(ISISVME::TransferLUTSpace, RFCNT0START, RFCNT0SIZE, m_rawframes, "raw frames", true, true, NULL, 0, false, false, fault_mode);
44  addMapping(ISISVME::TransferLUTSpace, GFCNT0START, GFCNT0SIZE, m_goodframes, "good frames", true, true, NULL, 0, false, false, fault_mode);
45  addMapping(ISISVME::TransferLUTSpace, RPCNT0START, RPCNT0SIZE, m_rawproton0, "raw proton0", true, true, NULL, 0, false, false, fault_mode);
46  addMapping(ISISVME::TransferLUTSpace, GPCNT0START, GPCNT0SIZE, m_goodproton0, "good proton0", true, true, NULL, 0, false, false, fault_mode);
47  addMapping(ISISVME::TransferLUTSpace, RPCNT1START, RPCNT1SIZE, m_rawproton1, "raw proton1", true, true, NULL, 0, false, false, fault_mode);
48  addMapping(ISISVME::TransferLUTSpace, GPCNT1START, GPCNT1SIZE, m_goodproton1, "good proton1", true, true, NULL, 0, false, false, fault_mode);
49  addMapping(ISISVME::TransferLUTSpace, SPARE0START, SPARE0SIZE, m_spare0, "spare0", true, true, NULL, 0, false, false, fault_mode);
50  addMapping(ISISVME::TransferLUTSpace, SPARE1START, SPARE1SIZE, m_spare1, "spare1", true, true, NULL, 0, false, false, fault_mode);
51 
52 // env card
53  addMapping(ISISVME::TransferIORegisterSpace, FCOUNTR, 1, &m_raw_frames, "", true, false, NULL, 0, false, false, fault_mode);
54  addMapping(ISISVME::TransferIORegisterSpace, FCOUNTG, 1, &m_good_frames, "", true, false, NULL, 0, false, false, fault_mode);
55  addMapping(ISISVME::TransferIORegisterSpace, PCOUNTR0, 1, &m_raw_proton_low, "", true, false, NULL, 0, false, false, fault_mode);
56  addMapping(ISISVME::TransferIORegisterSpace, PCOUNTR1, 1, &m_raw_proton_high, "", true, false, NULL, 0, false, false, fault_mode);
57  addMapping(ISISVME::TransferIORegisterSpace, PCOUNTG0, 1, &m_good_proton_low, "", true, false, NULL, 0, false, false, fault_mode);
58  addMapping(ISISVME::TransferIORegisterSpace, PCOUNTG1, 1, &m_good_proton_high, "", true, false, NULL, 0, false, false, fault_mode);
59  addMapping(ISISVME::TransferIORegisterSpace, FIFOVETFRM, 1, &m_fifo_veto_frames, "", true, false, NULL, 0, false, false, fault_mode);
60  addMapping(ISISVME::TransferIORegisterSpace, SMPVETFRM, 1, &m_smp_veto_frames, "", true, false, NULL, 0, false, false, fault_mode);
61  addMapping(ISISVME::TransferIORegisterSpace, INTVETFRM, 1, &m_internal_veto_frames, "", true, false, NULL, 0, false, false, fault_mode);
62  addMapping(ISISVME::TransferIORegisterSpace, EXT0VETFRM, 1, &m_external_veto0_frames, "", true, false, NULL, 0, false, false, fault_mode);
63  addMapping(ISISVME::TransferIORegisterSpace, EXT1VETFRM, 1, &m_external_veto1_frames, "", true, false, NULL, 0, false, false, fault_mode);
64  addMapping(ISISVME::TransferIORegisterSpace, EXT2VETFRM, 1, &m_external_veto2_frames, "", true, false, NULL, 0, false, false, fault_mode);
65  addMapping(ISISVME::TransferIORegisterSpace, EXT3VETFRM, 1, &m_external_veto3_frames, "", true, false, NULL, 0, false, false, fault_mode);
66  addMapping(ISISVME::TransferIORegisterSpace, FSDELAY, 1, &m_fs_delay, "", true, true, NULL, 0, false, false, fault_mode);
67  addMapping(ISISVME::TransferIORegisterSpace, FC0WINDLY, 1, &m_chopper_window_delay, "", true, true, NULL, 0, false, false, fault_mode);
68  addMapping(ISISVME::TransferIORegisterSpace, FC0WINWTH, 1, &m_chopper_window_width, "", true, true, NULL, 0, false, false, fault_mode);
69  addMapping(ISISVME::TransferIORegisterSpace, FC0VETFRM, 1, &m_chopper_veto_frames, "", true, false, NULL, 0, false, false, fault_mode);
70  addMapping(ISISVME::TransferIORegisterSpace, MSMVETFRM, 1, &m_ms_veto_frames, "", true, false, NULL, 0, false, false, fault_mode);
71  addMapping(ISISVME::TransferIORegisterSpace, RCONTROL, 1, &m_run_control, "", true, true, NULL, 0, false, false, fault_mode);
72  addMapping(ISISVME::TransferIORegisterSpace, RVETO, 1, &m_veto, "", true, true, NULL, 0, false, false, fault_mode);
73  addMapping(ISISVME::TransferIORegisterSpace, TS2PVETFRM, 1, &m_ts2_pulse_veto_frames, "", true, true, NULL, 0, false, false, fault_mode);
74  addMapping(ISISVME::TransferIORegisterSpace, HZ50VETFRM, 1, &m_50hz_veto_frames, "", true, true, NULL, 0, false, false, fault_mode);
75 
76  addMapping(ISISVME::TransferIORegisterSpace, FRAMETIME0, 1, &m_frame_time_low, "", true, true, NULL, 0, false, false, fault_mode);
77  addMapping(ISISVME::TransferIORegisterSpace, FRAMETIME1, 1, &m_frame_time_high, "", true, true, NULL, 0, false, false, fault_mode);
78 
79  m_veto_raised = false;
80  m_lookup = 0;
85 
86  m_is_running = (m_run_control & RCSTART ? true : false);
87  LOGSTR_INFORMATION("SIMEnvPeriod card at position " << m_position);
88 }
89 
90 template <class EnvPeriodPolicy>
92 {
93  os << "SIMEnvPeriod card at position " << m_position << " using policy " << EnvPeriodPolicy::env_period_policy_name;
94 }
95 
96 template <class EnvPeriodPolicy>
98 {
99  if (m_period_control & PCRESET)
100  {
101  m_main_period_counter = 0;
102  m_period_control = PCRESET; // clears all bits except reset bit
103  m_lookup = 0;
104  m_period_sequence_counter = 0;
105  }
106  if (m_period_control & PCCLRPC)
107  {
108  m_main_period_counter = 0;
109  m_period_sequence_counter = 0;
110  }
111  if (m_run_control & RCFCLEAR)
112  {
113  m_raw_frames = 0;
114  m_good_frames = 0;
115  m_fifo_veto_frames = 0;
116  m_smp_veto_frames = 0;
117  m_internal_veto_frames = 0;
118  m_external_veto0_frames = 0;
119  m_external_veto1_frames = 0;
120  m_external_veto2_frames = 0;
121  m_external_veto3_frames = 0;
122  m_chopper_veto_frames = 0;
123  m_ms_veto_frames = 0;
124  }
125  if (m_run_control & RCPCLEAR)
126  {
127  m_raw_proton_low = m_raw_proton_high = 0;
128  m_good_proton_low = m_good_proton_high = 0;
129  }
130  if (m_run_control & RCSTART)
131  {
132  m_is_running = true;
133  }
134  else
135  {
136  m_is_running = false;
137  }
138 }
139 
140 // this is here just so we can set a breakpoint easily on a card read
141 template <class EnvPeriodPolicy>
143 {
144 }
145 
146 template <class EnvPeriodPolicy>
148 {
149 // pcount * 1.738e-6 = uahours
150  delay = 20; // we don't want to add more than 1 frame at a time now, so no scaling to 50Hz
151  int frame_incr = delay / 20; // an isis frame is 20 milliseconds
152  int proton_incr = (int)( 180.0 * (double)delay / (1000.0 * 3600.0 * 1.738e-6) ) ; // 180uA current if 50Hz
153 // if ( (m_run_control & RCFSSEL) == RCFSTOF1P ) // running at 10Hz?
154 // {
155 // frame_incr /= 5;
156 // proton_incr /= 5;
157 // }
158 
159  if (!(m_run_control & RCPERSZEQZERO)) // delayed start enabled
160  {
161  return;
162  }
163  if (m_vme->isRunning())
164  {
165  m_raw_frames += frame_incr;
166  increment32(proton_incr, m_raw_proton_low, m_raw_proton_high);
167  if ( !m_vme->isVetoing() )
168  {
169  m_good_frames += frame_incr;
170  increment32(proton_incr, m_good_proton_low, m_good_proton_high);
171  }
172  }
173  if (!(m_period_control & PCENAB))
174  {
175  return; // not using periods
176  }
177  bool is_dwell;
178  int current_period, max_period, max_frames;
179  current_period = m_main_period_counter & 0x3fff; // lower 14 bits
180  is_dwell = ((m_main_period_counter & (1 << 14)) != 0);
181  max_period = m_main_period_limit & 0x3fff;
182  max_frames = 1 + (m_perlut[current_period] & 0xffff);
183  if ( m_vme->isRunning() )
184  {
185  if ((m_period_control & PCENDSEQCOMP) || (m_period_control & PCMULCOMP)) // pcard has finished sequence
186  {
187  m_veto_raised = true;
188  increment(frame_incr, m_internal_veto_frames);
189  increment(frame_incr, m_rawframes[current_period]);
190  increment32(proton_incr, m_rawproton0[current_period], m_rawproton1[current_period]);
191  }
192  else if (is_dwell)
193  {
194  m_veto_raised = true;
195  increment(frame_incr, m_internal_veto_frames);
196  increment(frame_incr, m_rawframes[current_period]);
197  increment(frame_incr, m_goodframes[current_period]);
198  increment32(proton_incr, m_rawproton0[current_period], m_rawproton1[current_period]);
199  }
200  else
201  {
202  m_veto_raised = false;
203  increment(frame_incr, m_rawframes[current_period]);
204  increment(frame_incr, m_goodframes[current_period]);
205  increment32(proton_incr, m_rawproton0[current_period], m_rawproton1[current_period]);
206  increment32(proton_incr, m_goodproton0[current_period], m_goodproton1[current_period]);
207  }
208  if (m_goodframes[current_period] >= max_frames*(1+m_period_sequence_counter) )
209  {
210  if (++current_period < max_period)
211  {
212  m_main_period_counter = (current_period & 0x3fff) |
213  ((m_perlut[current_period] & 0x80000000) >> 17);
214  if (!(m_perlut[current_period] & 0x80000000)) // not dwell
215  {
216  m_vme->incrementDetectorCardPeriod();
217  }
218 // m_rawframes[current_period] = m_goodframes[current_period] = 0;
219  }
220  else if (m_period_control & PCENDAFTER)
221  {
222  m_period_control |= PCENDSEQCOMP;
223  }
224  else if ((m_period_control & PCMULENAB) &&
225  (m_period_sequence_counter > m_period_sequence_limit))
226  {
227  m_period_control |= PCMULCOMP;
228  }
229  else
230  {
231  current_period = 0;
232  m_period_sequence_counter++;
233  m_main_period_counter = (current_period & 0x3fff) |
234  ((m_perlut[current_period] & 0x80000000) >> 17);
235  m_vme->resetDetectorCardPeriod();
236 // m_rawframes[current_period] = m_goodframes[current_period] = 0;
237  }
238  }
239  }
240 }
241 
242 template <class EnvPeriodPolicy>
244 {
245  delete[] m_perlut;
246  delete[] m_outlut;
247  delete[] m_rawframes;
248  delete[] m_goodframes;
249 }
250 
isisU32_t * m_goodframes
#define RFCNT0START
Definition: period_card.h:31
virtual void updateCardAfterRead(DAEstatus &status)
isisU32_t m_internal_veto_frames
#define RFCNT0SIZE
Definition: period_card.h:36
#define PCMULENAB
Definition: period_card.h:54
isisU32_t m_chopper_veto_frames
virtual void simulate(int delay)
#define PCENAB
Definition: period_card.h:52
isisU32_t m_main_period_limit
#define GFCNT0START
Definition: period_card.h:33
isisU32_t * m_rawproton1
unsigned long isisU32_t
Definition: isisvme_types.h:8
SIMEnvPeriodCard(int position, VMESimulationIface *vme, FaultMode fault_mode, DAEstatus &status)
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)
isisU32_t m_main_period_counter
#define OUTLUTSTART
Definition: period_card.h:28
isisU32_t m_fifo_veto_frames
isisU32_t m_period_sequence_limit
bool isRegisterUsed(const T &address)
registers are either &quot;unsigned&quot; or &quot;unused_t&quot;
Definition: dae_policy.h:8
#define TARPERLUT
Definition: period_card.h:42
isisU32_t m_period_output_delay
isisU32_t * m_goodproton1
#define TAROUTLUT
Definition: period_card.h:43
#define PSLR
Definition: period_card.h:13
#define LOGSTR_INFORMATION(__arg)
Definition: IsisBase.h:78
isisU32_t m_external_veto0_frames
#define PCENDSEQCOMP
Definition: period_card.h:51
#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
isisU32_t m_external_veto2_frames
EnvPeriodPolicy::ppp_memory_t * m_goodproton0
isisU32_t m_period_sequence_counter
#define RPCNT0START
Definition: period_card.h:35
#define GPCNT0START
Definition: period_card.h:37
#define PERLUTSTART
Definition: period_card.h:24
#define PCRESET
Definition: period_card.h:61
isisU32_t m_ext_period_overflow_veto_counter
#define PCMULCOMP
Definition: period_card.h:55
void setLoggerName(const std::string &logger_name)
Definition: IsisBase.h:17
isisU32_t m_chopper_window_delay
isisU32_t m_external_veto1_frames
virtual void printStatus(std::ostream &os)
EnvPeriodPolicy::ppp_memory_t * m_rawproton0
#define MPCNT
Definition: period_card.h:10
isisU32_t m_ts2_pulse_veto_frames
#define LOOKTAR
Definition: period_card.h:20
FaultMode
Definition: sim_dae2_card.h:10
virtual void updateCardAfterWrite(DAEstatus &status)
isisU32_t m_period_increment_total
#define PSCNT
Definition: period_card.h:12
#define PCCLRPC
Definition: period_card.h:60
isisU32_t m_external_veto3_frames
isisU32_t m_50hz_veto_frames
isisU32_t m_chopper_window_width
isisU32_t m_good_proton_high
#define MPLIM
Definition: period_card.h:11