versadac  1
versadac - Scalable Recorder Firmware
eiot2srai3.h
1 /*******************************************************************************
2 FILE : eiot2srai3.h
3 VERSION : $Id$
4 AUTHOR : Phil Windsor
5 SYSTEM : Diab C for PowerPC under vxWorks
6 DESCRIPTION : This file contains The t2500 module classes for the three channel
7  analogue input module
8 
9  Modification for 8Hz execution (for Scalable Recorder)
10 
11 *******************************************************************************/
12 #ifndef __EIOT2SRAI3_H
13 #define __EIOT2SRAI3_H
14 
15 /* The following section is needed by eio_t25sr.c */
16 
17 /* Capability discovery functions use AI3_NUMBER_OF_CALIBRATION_RANGES */
18 enum Ai3CalibrationRangeEnum
19 {
20  AI3_CALIBRATION_RANGE_MILLIAMPS,
21  AI3_NUMBER_OF_CALIBRATION_RANGES
22 };
23 
24 #ifdef __cplusplus
25 
26 /* This section must never be included from C */
27 
28 #include "eio_t25srm.h"
29 #include "dfc_ssm.h"
30 #include "rst_ssm.h"
31 #include "led_ssm.h"
32 #include "sla_ssm.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 // Channel 3 is completely updated on every 125ms cycle. Positive and negative
39 // readings are sampled on alternate 62.5ms cycles.
40 // Channels 1 and 2 are completely updated on every 250ms cycle. Positive and
41 // negative readings are sampled on alternate 125ms cycles.
42 // A variable of this type is maintained to identify what we are doing.
43 enum AI3UpdateCycles
44 {
45  AI3_UPDATE_CYCLE_62_5mS,
46  AI3_UPDATE_CYCLE_125mS,
47  AI3_UPDATE_CYCLE_187_5mS,
48  AI3_UPDATE_CYCLE_250mS,
49  AI3_NUMBER_OF_UPDATE_CYCLES,
50 };
51 
52 // These identify positive and negative readings
53 enum AI3Polarity
54 {
55  AI3_MINUS,
56  AI3_PLUS,
57  AI3_NUMBER_OF_READINGS_PER_CHANNEL
58 };
59 
60 // The AI3 modules provides 3 channels of measurement using 3 DSMs
61 // and 1 DFC. DFC Filter 1 provides readings from channels 1 and 2.
62 // DFC Filter 2 provides readings from channel 3.
63 enum AI3Filters
64 {
65  AI3_FILTER_1,
66  AI3_FILTER_2,
67  AI3_NUMBER_OF_FILTERS
68 };
69 
70 // DFC Port 1 takes input from channels 1 and 2.
71 // DFC Port 2 takes input from channel 3.
72 enum AI3Ports
73 {
74  AI3_PORT_1,
75  AI3_PORT_2,
76  AI3_NUMBER_OF_PORTS
77 };
78 
79 enum AI3Channels
80 {
81  AI3_CHANNEL_1,
82  AI3_CHANNEL_2,
83  AI3_CHANNEL_3,
84  AI3_NUMBER_OF_CHANNELS,
85 };
86 
87 enum AI3OperatingRanges
88 {
89  /*
90  * The following is a list of the different input modes which are
91  * supported by the module.
92  */
93  AI3_MODE_OFF, /* +/- 30 mA range is used, output is ignored */
94  AI3_MODE_MA, /* +/- 30 mA range */
95  AI3_MODE_UNSUPPORTED,/* +/- 30 mA range is used, PV is forced to a fault condition */
96  NUMBER_OF_AI3_MODES,
97 };
98 
99 enum AI3RunStates
100 {
101  EIO_T2500AI3_STATE_MODULE_NEEDS_RESET,
102  EIO_T2500AI3_STATE_INITIALISING,
103  EIO_T2500AI3_STATE_RUNTIME,
104  EIO_T2500AI3_STATE_DELETE,
105  EIO_T2500AI3_STATE_SECONDARY,
106  EIO_T2500AI3_STATE_BECOMING_PRIMARY_1,
107  EIO_T2500AI3_STATE_BECOMING_PRIMARY_2,
108  EIO_T2500AI3_STATE_BECOMING_PRIMARY_3,
109 };
110 
111 enum Ai3EepromAccessState
112 {
113  AI3_EEPROM_RESET_STATE,
114  AI3_EEPROM_READ_CHANNEL_1_USER_CALIBRATION,
115  AI3_EEPROM_READ_CHANNEL_2_USER_CALIBRATION,
116  AI3_EEPROM_READ_CHANNEL_3_USER_CALIBRATION,
117  AI3_EEPROM_READ_CHANNEL_1_FACTORY_CALIBRATION,
118  AI3_EEPROM_READ_CHANNEL_2_FACTORY_CALIBRATION,
119  AI3_EEPROM_READ_CHANNEL_3_FACTORY_CALIBRATION,
120  AI3_EEPROM_WRITE,
121  AI3_EEPROM_WRITE_DONE,
122  AI3_EEPROM_IDLE
123 };
124 
125 // internal states of the calibration state machine
126 enum Ai3CalibrationState
127 {
128  AI3_CAL_STATE_IDLE,
129  AI3_CAL_STATE_WAIT_FOR_RANGE,
130  AI3_CAL_STATE_INIT,
131  AI3_CAL_STATE_RUNNING,
132  AI3_CAL_STATE_DATA_GATHERED,
133  AI3_CAL_STATE_WAIT_FOR_VALUE,
134  AI3_CAL_STATE_POINT_DONE,
135  AI3_CAL_STATE_SAVE,
136  AI3_CAL_STATE_SAVE_LOW_POINT,
137  AI3_CAL_STATE_SAVE_HIGH_POINT,
138  AI3_CAL_STATE_DATA_SAVED,
139  AI3_CAL_STATE_RESTORE,
140  AI3_CAL_STATE_END_CAL
141 };
142 
143 enum Ai3CalibrationPoints
144 {
145  AI3_CAL_POINT_LOW,
146  AI3_CAL_POINT_HIGH,
147  AI3_NUMBER_OF_CALIBRATION_POINTS
148 };
149 
150 typedef struct
151 {
152  DsmMuxEnum m_mux;
153  EioUint8 m_filter1Input;
154  AI3Channels m_filter1Channel;
155  AI3Polarity m_filter1Sign;
156  AI3Channels m_filter2Channel;
157  AI3Polarity m_filter2Sign;
158 }AI3CycleDataType;
159 
160 
161 class EioT2500AI3Module:public EioT2500Module
162 {
163  public:
164  EioT2500AI3Module(unsigned char moduleNumber, EioT2500CycleEnum z_expectedCycleNumber);
165  virtual ~EioT2500AI3Module();
166 
167  protected:
168  virtual void update62_5mS();
169  virtual void update125mS();
170  virtual void updateBuffers125ms();
171  EioBoolean getCalibrated(EioUint8 channel, EioAICalType calType, EioUint8 rangeNumber);
172 
173  private:
174  void decipherCalibration();
175  void checkUserCalibration();
176 
177  AI3OperatingRanges getOperatingRange(EioUint8 channel);
178  EioUint8 eeCheckBits( EioUint8 *bytePtr);
179  static void secondaryFilter( float sample, float *polep, float divisor, EioSint8 *resetp );
180  void driveChannelLeds();
181  void updateEepromImage125mS();
182  void disableAll62_5mS();
183  void disableAll125mS();
184  void setFaultValues();
185  void updateCalibrationState();
186 
187  AI3RunStates m_state;
188  Ai3EepromAccessState m_eepromState;
189  Ai3CalibrationState m_calibrationState[AI3_NUMBER_OF_CHANNELS];
190 
191  float m_calibrationCoefficient1[AI3_NUMBER_OF_CHANNELS];
192  float m_calibrationCoefficient2[AI3_NUMBER_OF_CHANNELS];
193  float m_oldCalCoefficient1[AI3_NUMBER_OF_CHANNELS];
194  float m_oldCalCoefficient2[AI3_NUMBER_OF_CHANNELS];
195  bool m_rangeCalibrated[AI3_NUMBER_OF_CHANNELS];
196  bool m_oldRangeCalibrated[AI3_NUMBER_OF_CHANNELS];
197  EioBoolean m_rangeFactoryCalibrated[AI3_NUMBER_OF_CHANNELS];
198  EioBoolean m_rangeUserCalibrated[AI3_NUMBER_OF_CHANNELS];
199  EioUint8 m_calCounter[AI3_NUMBER_OF_CHANNELS];
200  EioUint32 m_calReading[AI3_NUMBER_OF_CHANNELS][AI3_NUMBER_OF_CALIBRATION_POINTS];
201  EioUint32 m_deltaCounts[AI3_NUMBER_OF_CHANNELS];
202  Ai3CalibrationPoints m_calPointIndex[AI3_NUMBER_OF_CHANNELS];
203  float m_actualCalValue[AI3_NUMBER_OF_CHANNELS][AI3_NUMBER_OF_CALIBRATION_POINTS];
204 
205  static float m_calScaleFactor;
206  static float m_calibrationRefLow;
207  static float m_calibrationRefHigh;
208  static AI3CycleDataType m_cycleData[AI3_NUMBER_OF_UPDATE_CYCLES];
209 
210  EioUint8 m_spiLatchOutputs;
211 
212  // recovery messages
213  SlaWriteSpiScheduledMessage * m_resetOn1Message;
214  SlaDDRSpiScheduledMessage * m_initSlaMessage;
215  SlaWriteSpiScheduledMessage * m_resetOn2Message;
216  SlaWriteSpiScheduledMessage * m_resetOff1Message;
217  SlaWriteSpiScheduledMessage * m_resetOn3Message;
218  SlaWriteSpiScheduledMessage * m_resetOff2Message;
219 
220  DfcTotalConfigSpiScheduledMessage * m_dfcTotalConfigMessage;
221 
222  EEReadSpiScheduledMessage * m_eereadCalibration;
223  EEWriteEnableSpiScheduledMessage * m_eeenableWriteCalibration;
224  EEWriteSpiScheduledMessage * m_eewriteCalibration;
225 
226  SlaWriteSpiScheduledMessage * m_slaDataMessage;
227  DfcDsmTotalConfigSpiScheduledMessage * m_totalConfig62_5mS;
228  DfcDsmTotalConfigSpiScheduledMessage * m_totalConfig125mS;
229 
230  DfcFilterConfigSpiScheduledMessage * m_dfcFilter1Config62_5mS;
231  DfcFilterConfigSpiScheduledMessage * m_dfcFilter1Config125mS;
232 
233  DfcReadFilterCountSpiScheduledMessage * m_readFilter62_5mS[AI3_NUMBER_OF_FILTERS];
234  DfcReadFilterCountSpiScheduledMessage * m_readFilter125mS[AI3_NUMBER_OF_FILTERS];
235 
236  bool m_messagesScheduled;
237  EioUint8 m_eepromImage[256];
238 
239  EioSint32 m_filterCount[AI3_NUMBER_OF_CHANNELS][AI3_NUMBER_OF_READINGS_PER_CHANNEL];
240  EioUint8 m_filterStatus[AI3_NUMBER_OF_CHANNELS][AI3_NUMBER_OF_READINGS_PER_CHANNEL];
241 
242  float m_divisor[AI3_NUMBER_OF_CHANNELS];
243  EioSint8 m_filterReset[AI3_NUMBER_OF_CHANNELS];
244  EioUint8 m_rangingCount[AI3_NUMBER_OF_CHANNELS];
245  EioAIMeasuredValueData m_measuredValueData[AI3_NUMBER_OF_CHANNELS];
246  EioAIPointConfig m_pointConfig[AI3_NUMBER_OF_CHANNELS];
247  EioAICalibrationData m_calData[AI3_NUMBER_OF_CHANNELS];
248  float m_sensorBreakValue[AI3_NUMBER_OF_CHANNELS];
249  EioUint8 m_psuResetTimer;
250 
251  AI3OperatingRanges m_currentRange[AI3_NUMBER_OF_CHANNELS];
252 
253  AI3UpdateCycles m_updateCycle;
254  AI3UpdateCycles m_muxCycle;
255  EioUint8 m_dfcConfigAttempts;
256 };
257 #ifdef __cplusplus
258 } /* extern "C" */
259 #endif
260 #endif /* __cplusplus */
261 #endif /*__EIOT2SRAI3_H */
262 
Definition: eio_t25srm.h:58
Definition: eio_ai.h:44
Definition: ee_ssm.h:113
Definition: sla_ssm.h:162
Definition: eiot2cal.h:36
Definition: dfc_ssm.h:322
Definition: eio_ai.h:76
Definition: dfc_ssm.h:233
Definition: dfc_ssm.h:266
Definition: dfc_ssm.h:206
Definition: sla_ssm.h:172
Definition: ee_ssm.h:126
Definition: ee_ssm.h:59