ICP  1
sim_period_card.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
3 #include "vme_simulation.h"
4 #include "sim_period_card.h"
5 #include "isisvme.h"
6 
7 SIMPeriodCard::SIMPeriodCard(int position, VMESimulation* vme, FaultMode fault_mode, DAEstatus& status) :
8  SIMDAE2Card(position, vme, ((1 << 30) | (1 << 31)), false, Working, status)
9 {
11 
16  addMapping(MPCNT, 1, &m_main_period_counter, "", true, true, NULL, 0, false, false, fault_mode);
17  addMapping(MPLIM, 1, &m_main_period_limit, "", true, true, NULL, 0, false, false, fault_mode);
18  addMapping(PSCNT, 1, &m_main_period_sequence_counter, "", true, true, NULL, 0, false, false, fault_mode);
19  addMapping(EXTTRIGVC0, 1, &m_extract_vc_low, "", true, true, NULL, 0, false, false, fault_mode);
20  addMapping(EXTTRIGVC1, 1, &m_extract_vc_high, "", true, true, NULL, 0, false, false, fault_mode);
21  addMapping(LOOKTAR, 1, &m_lookup, "", true, true, NULL, 0, false, false, fault_mode);
22  addMapping(PCREG, 1, &m_period_control, "", true, true, NULL, 0, false, false, fault_mode);
23  addMapping(PERLUTSTART, PERLUTSIZE, m_perlut, "perlut", true, true, &m_lookup, TARPERLUT, false, false, fault_mode);
24  addMapping(OUTLUTSTART, OUTLUTSIZE, m_outlut, "outlut", true, true, &m_lookup, TAROUTLUT, false, false, fault_mode);
25  addMapping(RFCNT0START, RFCNT0SIZE, m_rawframes, "raw frames", true, true, NULL, 0, false, false, fault_mode);
26  addMapping(GFCNT0START, GFCNT0SIZE, m_goodframes, "good frames", true, true, NULL, 0, false, false, fault_mode);
27 
28  addMapping(MAT_1, 1, &m_mat_counter, "", true, true, NULL, 0, false, false, fault_mode);
29 
30  m_is_running = true;
31  m_veto_raised = false;
33 }
34 
35 void SIMPeriodCard::printStatus(std::ostream& os)
36 {
37  os << "SIMPeriod card at position " << m_position;
38 }
39 
41 {
43  {
45  m_period_control = PCRESET; // clears all bits except reset bit
47  m_lookup = 0;
49  }
51  {
54  }
56  {
58  }
59 }
60 
61 // this is here just so we can set a breakpoint easily on a card read
63 {
64 }
65 
66 void SIMPeriodCard::simulate(int delay)
67 {
68 // pcount * 1.738e-6 = uahours
69  int frame_incr = delay / 20; // an isis frame is 20 milliseconds
70  int proton_incr = (int)( 180.0 * (double)delay / (1000.0 * 3600.0 * 1.738e-6) ) ; // 180uA current
71  if (!(m_period_control & PCENAB))
72  {
73  return; // not using periods
74  }
76  {
77  return;
78  }
79  if (!(m_period_control & PCEXTTRIG))
80  {
81  return;
82  }
84  {
85  return; // using external periods
86  }
88  {
89  return; // using external periods
90  }
91  bool is_dwell;
92  int current_period, max_period, max_frames;
93  current_period = m_main_period_counter & 0x3fff; // lower 14 bits
94  is_dwell = ((m_main_period_counter & (1 << 14)) != 0);
95  max_period = m_main_period_limit & 0x3fff;
96  max_frames = 1 + (m_perlut[current_period] & 0xffff);
97  if ( m_vme->isRunning() )
98  {
99  if (m_period_control & PCENDSEQCOMP) // pcard has finished sequence but env card still says running, so veto
100  {
101  m_veto_raised = true;
103  increment(frame_incr, m_rawframes[current_period]);
104  }
105  else if (is_dwell)
106  {
107  m_veto_raised = true;
109  increment(frame_incr, m_rawframes[current_period]);
110  increment(frame_incr, m_goodframes[current_period]);
111  }
112  else
113  {
114  m_veto_raised = false;
115  increment(frame_incr, m_rawframes[current_period]);
116  increment(frame_incr, m_goodframes[current_period]);
117  }
118  if (m_goodframes[current_period] >= max_frames*(1+m_main_period_sequence_counter) )
119  {
120  if (current_period < max_period)
121  {
122  current_period++;
123  m_main_period_counter = (current_period & 0x3fff) |
124  ((m_perlut[current_period] & 0x80000000) >> 17);
125  if (!(m_perlut[current_period] & 0x80000000)) // not dwell
126  {
128  }
129 // m_rawframes[current_period] = m_goodframes[current_period] = 0;
130  }
131  else if (m_period_control & PCENDAFTER)
132  {
134  }
135  else
136  {
137  current_period = 0;
139  m_main_period_counter = (current_period & 0x3fff) |
140  ((m_perlut[current_period] & 0x80000000) >> 17);
142 // m_rawframes[current_period] = m_goodframes[current_period] = 0;
143  }
144  }
145  }
146 }
147 
149 {
150  delete[] m_perlut;
151  delete[] m_outlut;
152  delete[] m_rawframes;
153  delete[] m_goodframes;
154 }
virtual void simulate(int delay)
#define RFCNT0START
Definition: period_card.h:31
static void increment2(int value, isisU32_t &low, isisU32_t &high)
isisU32_t m_main_period_sequence_counter
CardType m_type
Definition: sim_dae2_card.h:85
virtual void updateCardAfterWrite(DAEstatus &status)
isisU32_t * m_goodframes
#define RFCNT0SIZE
Definition: period_card.h:36
#define EXTTRIGVC1
Definition: period_card.h:15
#define PCMULENAB
Definition: period_card.h:54
#define PCENAB
Definition: period_card.h:52
#define GFCNT0START
Definition: period_card.h:33
isisU32_t m_main_period_counter
virtual void printStatus(std::ostream &os)
unsigned long isisU32_t
Definition: isisvme_types.h:8
isisU32_t m_extract_vc_low
virtual int resetDetectorCardPeriod()=0
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)
#define OUTLUTSTART
Definition: period_card.h:28
static void increment(int value, isisU32_t &low)
virtual int incrementDetectorCardPeriod()=0
#define TARPERLUT
Definition: period_card.h:42
VMESimulationIface * m_vme
Definition: sim_dae2_card.h:86
#define TAROUTLUT
Definition: period_card.h:43
#define PCEXTENAB
Definition: period_card.h:53
#define PCCLRVETO
Definition: period_card.h:59
static bool isRunning()
#define PCENDSEQCOMP
Definition: period_card.h:51
#define MAT_1
Definition: period_card.h:4
isisU32_t * m_rawframes
isisU32_t m_lookup
#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
isisU32_t * m_perlut
virtual ~SIMPeriodCard()
#define EXTTRIGVC0
Definition: period_card.h:14
isisU32_t m_period_control
#define PERLUTSTART
Definition: period_card.h:24
#define PCEXTPERCLK
Definition: period_card.h:56
isisU32_t m_main_period_limit
#define PCRESET
Definition: period_card.h:61
virtual void updateCardAfterRead(DAEstatus &status)
bool m_is_running
Definition: sim_dae2_card.h:88
SIMPeriodCard(int position, VMESimulation *vme, FaultMode fault_mode, DAEstatus &status)
bool m_veto_raised
Definition: sim_dae2_card.h:87
isisU32_t m_mat_counter
#define MPCNT
Definition: period_card.h:10
isisU32_t m_extract_vc_high
#define LOOKTAR
Definition: period_card.h:20
FaultMode
Definition: sim_dae2_card.h:10
#define PSCNT
Definition: period_card.h:12
#define PCCLRPC
Definition: period_card.h:60
#define MPLIM
Definition: period_card.h:11
isisU32_t * m_outlut