versadac  1
versadac - Scalable Recorder Firmware
eiot2srai4.h
1 /*******************************************************************************
2 FILE : eiot2srai4.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 four channel
7  analogue input module
8 
9  Modification for 8Hz execution (for Scalable Recorder)
10 
11 *******************************************************************************/
12 #ifndef __EIOT2SRAI4_H
13 #define __EIOT2SRAI4_H
14 
15 /* The following section is needed by eio_t25sr.c */
16 
17 /* Only the millivolt range can be calibrated on the AI4 module, but a hidden
18  ohms range calibration is needed for CJC measurement */
19 #define AI4_NUMBER_OF_VISIBLE_CALIBRATION_RANGES (AI4_NUMBER_OF_CALIBRATION_RANGES - 1)
20 
21 /* Capability discovery functions use AI4_NUMBER_OF_CALIBRATION_RANGES */
22 enum Ai4CalibrationRangeEnum
23 {
24  AI4_CALIBRATION_RANGE_MILLIVOLTS,
25  AI4_CALIBRATION_RANGE_RTD_OHMS,
26  AI4_NUMBER_OF_CALIBRATION_RANGES
27 };
28 
29 #ifdef __cplusplus
30 
31 /* This section must never be included from C */
32 
33 #include "eio_t25srm.h"
34 #include "dfc_ssm.h"
35 #include "rst_ssm.h"
36 #include "led_ssm.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 // All ranges are polled on a basic 125mS update cycle. Ancilliary readings
43 // such as CJ measurement are interleaved with zero reference measurements on alternate
44 // 125mS cycles. A variable of this type is maintained and toggled on each 125mS
45 // cycle to identify what we are doing.
46 enum Ai4UpdateCycles
47 {
48  AI4_UPDATE_CYCLE_62_5mS,
49  AI4_UPDATE_CYCLE_125mS,
50  AI4_UPDATE_CYCLE_187_5mS,
51  AI4_UPDATE_CYCLE_250mS,
52  AI4_NUMBER_OF_UPDATE_CYCLES,
53 };
54 
55 // The AI4 modules provides 4 channels of measurement using 2 pairs of
56 // channels associated with the 2 DSMs
57 // Channel pair 1/2 associated with DSM 1 provides channels 1 and 2
58 // Channel pair 3/4 associated with DSM 2 provides channels 3 and 4
59 enum Ai4ChannelPairs
60 {
61  AI4_CHANNEL_PAIR_1_2,
62  AI4_CHANNEL_PAIR_3_4,
63  AI4_NUMBER_OF_CHANNEL_PAIRS
64 };
65 
66 enum Ai4Channels
67 {
68  AI4_CHANNEL_1,
69  AI4_CHANNEL_2,
70  AI4_CHANNEL_3,
71  AI4_CHANNEL_4,
72  AI4_NUMBER_OF_CHANNELS,
73 };
74 
75 enum Ai4FilterTypeEnum
76 {
77  AI4_FILTER_TYPE_MAIN,
78  AI4_FILTER_TYPE_AUX,
79  AI4_NUMBER_OF_FILTER_TYPES
80 };
81 
82 enum Ai4OperatingRanges
83 {
84  /*
85  * The following is a list of the different input modes which are
86  * supported by the module.
87  * Note the suffexes BL, and BH determine which way the MeasuredValue drifts
88  * on a input wire break. This does not always correspond with the VWIRE setting
89  */
90  AI4_MODE_OFF, /* +/- 150 milliVolt range is used, output is ignored */
91  AI4_MODE_MA, /* +/- 20 mA range, external resistor */
92  AI4_MODE_MV_BL, /* mV, (Break Low) */
93  AI4_MODE_MV, /* mV, */
94  AI4_MODE_MV_BH, /* mV, (Break High) */
95  AI4_MODE_MA_CJ, /* +/- 20 mA range, external resistor also measure cj */
96  AI4_MODE_MV_CJ_BL, /* Thermocouple with CJC (Break Low) */
97  AI4_MODE_MV_CJ, /* Thermocouple with CJC */
98  AI4_MODE_MV_CJ_BH, /* Thermocouple with CJC (Break High) */
99  AI4_MODE_UNSUPPORTED,/* +/- 150 millivolt range is used, PV is forced to a fault condition */
100  NUMBER_OF_AI4_MODES,
101 };
102 
103 enum Ai4RunStates
104 {
105  EIO_T2500AI4_STATE_MODULE_NEEDS_RESET,
106  EIO_T2500AI4_STATE_INITIALISING,
107  EIO_T2500AI4_STATE_RUNTIME,
108  EIO_T2500AI4_STATE_DELETE,
109  EIO_T2500AI4_STATE_SECONDARY,
110  EIO_T2500AI4_STATE_BECOMING_PRIMARY_1,
111  EIO_T2500AI4_STATE_BECOMING_PRIMARY_2,
112 };
113 
114 enum Ai4EepromAccessState
115 {
116  AI4_EEPROM_RESET_STATE,
117  AI4_EEPROM_READ_CHANNEL_1_USER_CALIBRATION,
118  AI4_EEPROM_READ_CHANNEL_2_USER_CALIBRATION,
119  AI4_EEPROM_READ_CHANNEL_1_FACTORY_CALIBRATION,
120  AI4_EEPROM_READ_CHANNEL_2_FACTORY_CALIBRATION,
121  AI4_EEPROM_IDLE,
122  AI4_EEPROM_WRITE,
123  AI4_EEPROM_WRITE_DONE
124 };
125 
126 // internal states of the calibration state machine
127 enum Ai4CalibrationState
128 {
129  AI4_CAL_STATE_IDLE,
130  AI4_CAL_STATE_WAIT_FOR_RANGE,
131  AI4_CAL_STATE_INIT,
132  AI4_CAL_STATE_RUNNING,
133  AI4_CAL_STATE_DATA_GATHERED,
134  AI4_CAL_STATE_WAIT_FOR_VALUE,
135  AI4_CAL_STATE_POINT_DONE,
136  AI4_CAL_STATE_SAVE,
137  AI4_CAL_STATE_SAVE_LOW_POINT,
138  AI4_CAL_STATE_SAVE_HIGH_POINT,
139  AI4_CAL_STATE_DATA_SAVED,
140  AI4_CAL_STATE_RESTORE,
141  AI4_CAL_STATE_END_CAL
142 };
143 
144 enum Ai4CalibrationPoints
145 {
146  AI4_CAL_POINT_LOW,
147  AI4_CAL_POINT_HIGH,
148  AI4_NUMBER_OF_CALIBRATION_POINTS
149 };
150 
151 typedef struct
152 {
153  DsmTotalConfigDataType m_cycleData[AI4_NUMBER_OF_UPDATE_CYCLES];
154 }Ai4RangeTotalConfig;
155 
156 class EioT2500AI4Module:public EioT2500Module
157 {
158  public:
159  EioT2500AI4Module(unsigned char moduleNumber, EioT2500CycleEnum z_expectedCycleNumber);
160  virtual ~EioT2500AI4Module();
161 
162  protected:
163  virtual void update62_5mS();
164  virtual void update125mS();
165  virtual void updateBuffers125ms();
166  EioBoolean getCalibrated(EioUint8 channel, EioAICalType calType, EioUint8 rangeNumber);
167 
168  private:
169  void decipherCalibration();
170  void checkUserCalibration();
171 
172  Ai4OperatingRanges getOperatingRange(EioUint8 channel);
173  EioUint8 eeCheckBits( EioUint8 *bytePtr);
174  static void secondaryFilter( float sample, float *polep, float divisor, EioSint8 *resetp );
175  void driveChannelLeds();
176  void updateEepromImage125mS();
177  void disableAll62_5mS();
178  void disableAll125mS();
179  void setFaultValues();
180  void updateCalibrationState();
181  bool modCjRequired();
182 
183  Ai4RunStates m_state;
184  Ai4EepromAccessState m_eepromState;
185  Ai4CalibrationState m_calibrationState[AI4_NUMBER_OF_CHANNEL_PAIRS];
186 
187  // if necessary these could be optimised by storing values for channel pairs rather than channels
188  float m_calibrationCoefficient1[AI4_NUMBER_OF_CHANNELS][AI4_NUMBER_OF_CALIBRATION_RANGES];
189  float m_calibrationCoefficient2[AI4_NUMBER_OF_CHANNELS][AI4_NUMBER_OF_CALIBRATION_RANGES];
190  bool m_rangeCalibrated[AI4_NUMBER_OF_CHANNELS][AI4_NUMBER_OF_CALIBRATION_RANGES];
191  EioBoolean m_rangeFactoryCalibrated[AI4_NUMBER_OF_CHANNEL_PAIRS][AI4_NUMBER_OF_CALIBRATION_RANGES];
192  // only the millivolt range can be user calibrated
193  EioBoolean m_rangeUserCalibrated[AI4_NUMBER_OF_CHANNEL_PAIRS];
194 
195  float m_oldCalCoefficient1[AI4_NUMBER_OF_CHANNEL_PAIRS];
196  bool m_oldRangeCalibrated[AI4_NUMBER_OF_CHANNEL_PAIRS];
197 
198  EioUint8 m_calCounter[AI4_NUMBER_OF_CHANNEL_PAIRS];
199  EioUint32 m_calReading[AI4_NUMBER_OF_CHANNEL_PAIRS][AI4_NUMBER_OF_CALIBRATION_POINTS];
200  EioUint32 m_deltaCounts[AI4_NUMBER_OF_CHANNEL_PAIRS];
201  Ai4CalibrationPoints m_calPointIndex[AI4_NUMBER_OF_CHANNEL_PAIRS];
202  float m_actualCalValue[AI4_NUMBER_OF_CHANNEL_PAIRS][AI4_NUMBER_OF_CALIBRATION_POINTS];
203 
204  static float m_calScaleFactor;
205  static float m_calibrationRefLow[AI4_NUMBER_OF_CALIBRATION_RANGES];
206  static float m_calibrationRefHigh[AI4_NUMBER_OF_CALIBRATION_RANGES];
207  static Ai2CalibrationRangeEnum m_calAI2Range[AI4_NUMBER_OF_CALIBRATION_RANGES]; // maps AI4 to AI2 ranges
208  static Ai4RangeTotalConfig m_rangeTotalConfig[NUMBER_OF_AI4_MODES];
209 
210  // recovery messages
211  DfcDelaySpiScheduledMessage * m_delayMessage;
212  ResetSpiScheduledMessage * m_resetMessage;
213  DfcVWireDataReadySpiScheduledMessage * m_channelLedMessage;
214  DfcTotalConfigSpiScheduledMessage * m_dfcTotalConfigMessage;
215 
216  EEReadSpiScheduledMessage * m_eereadCalibration;
217  EEWriteEnableSpiScheduledMessage * m_eeenableWriteCalibration;
218  EEWriteSpiScheduledMessage * m_eewriteCalibration;
219 
220  DfcDsmTotalConfigSpiScheduledMessage * m_totalConfig62_5mS[AI4_NUMBER_OF_CHANNEL_PAIRS];
221  DfcDsmTotalConfigSpiScheduledMessage * m_totalConfig125mS[AI4_NUMBER_OF_CHANNEL_PAIRS];
222 
223  DsmMuxEnum m_currentMux[AI4_NUMBER_OF_CHANNEL_PAIRS];
224  DsmMuxEnum m_previousMux[AI4_NUMBER_OF_CHANNEL_PAIRS];
225 
226  DfcReadFilterCountSpiScheduledMessage * m_readFilter62_5mS[AI4_NUMBER_OF_CHANNEL_PAIRS];
227  DfcReadFilterCountSpiScheduledMessage * m_readFilter125mS[AI4_NUMBER_OF_CHANNEL_PAIRS];
228 
229  LedSpiScheduledMessage * m_moduleLed;
230 
231  bool m_messagesScheduled;
232  EioUint8 m_eepromImage[256];
233 
234  EioSint32 m_filterCount[AI4_NUMBER_OF_CHANNEL_PAIRS][NUMBER_OF_DSM_MUX];
235  EioSint32 m_oldFilterCount[AI4_NUMBER_OF_CHANNEL_PAIRS][NUMBER_OF_DSM_MUX];
236  EioSint32 m_processedCount[AI4_NUMBER_OF_CHANNEL_PAIRS][NUMBER_OF_DSM_MUX];
237 
238  EioUint8 m_filterStatus[AI4_NUMBER_OF_CHANNEL_PAIRS][NUMBER_OF_DSM_MUX];
239  EioUint8 m_oldFilterStatus[AI4_NUMBER_OF_CHANNEL_PAIRS][NUMBER_OF_DSM_MUX];
240  EioUint8 m_processedStatus[AI4_NUMBER_OF_CHANNEL_PAIRS][NUMBER_OF_DSM_MUX];
241 
242  float m_divisor[AI4_NUMBER_OF_CHANNELS];
243  EioSint8 m_filterReset[AI4_NUMBER_OF_CHANNELS][AI4_NUMBER_OF_FILTER_TYPES];
244  EioUint8 m_lastHeartBeat[AI4_NUMBER_OF_CHANNEL_PAIRS];
245  EioUint8 m_rangingCount[AI4_NUMBER_OF_CHANNELS];
246  EioUint8 m_noInterpolation[AI4_NUMBER_OF_CHANNELS];
247  EioAIMeasuredValueData m_measuredValueData[AI4_NUMBER_OF_CHANNELS];
248  EioAIPointConfig m_pointConfig[AI4_NUMBER_OF_CHANNELS];
249  EioAICalibrationData m_calData[AI4_NUMBER_OF_CHANNEL_PAIRS];
250  float m_sensorBreakValue[AI4_NUMBER_OF_CHANNELS];
251 
252  float m_cjValue;
253  EioAIAuxStatus m_cjStatus;
254 
255  Ai4OperatingRanges m_currentRange[AI4_NUMBER_OF_CHANNELS];
256 
257  Ai4UpdateCycles m_updateCycle;
258 
259  EioUint8 m_hideCJ;
260  EioUint8 m_dfcConfigAttempts;
261  EioUint8 m_ignoreCJorZeroCount;
262 };
263 #ifdef __cplusplus
264 } /* extern "C" */
265 #endif
266 #endif /*__cplusplus */
267 #endif /*__EIOT2SRAI4_H */
268 
Definition: eio_t25srm.h:58
Definition: eio_ai.h:44
Definition: dfc_ssm.h:198
Definition: ee_ssm.h:113
Definition: rst_ssm.h:14
Definition: eiot2cal.h:36
Definition: eio_ai.h:76
Definition: dfc_ssm.h:233
Definition: dfc_ssm.h:266
Definition: led_ssm.h:12
Definition: dfc_ssm.h:206
Definition: dfc_ssm.h:306
Definition: ee_ssm.h:126
Definition: ee_ssm.h:59
Definition: dfc_ssm.h:174