versadac  1
versadac - Scalable Recorder Firmware
eiot2srao2.h
1 /*******************************************************************************
2 FILE : eiot2srao2.h
3 VERSION : $Id$
4 AUTHOR : David Cozens/Phil Windsor
5 SYSTEM : Diab C for PowerPC under vxWorks
6 DESCRIPTION : This file contains The t2500 module classes
7 
8  Modification for 8Hz execution (for Scalable Recorder)
9 
10 *******************************************************************************/
11 
12 #ifndef __EIOT2SRAO2_H
13 #define __EIOT2SRAO2_H
14 /* The following section is needed by eio_t25sr.c */
15 
16 /*
17  * Defines for the different calibration points, two are used for each range
18  */
19 #define AOC_CAL_MA_LOW (2.0) /* (+/- 20mA) low cal pnt */
20 #define AOC_CAL_MA_HIGH (18.0) /* (+/- 20mA) high cal pnt */
21 #define AOC_CAL_VOLT_LOW (1000.0) /* (+/- 10V) low cal pnt */
22 #define AOC_CAL_VOLT_HIGH (9000.0) /* (+/- 10V) high cal pnt */
23 
24 /* Range Limits */
25 #define AOC_MA_RANGE_LOW (-0.1f) /* -0.1mA */
26 #define AOC_MA_RANGE_HIGH (20.5) /* 20.5mA */
27 #define AOC_VOLT_RANGE_LOW (-500.0) /* -0.5V */
28 #define AOC_VOLT_RANGE_HIGH (10500.0) /* 10.5V */
29 
30 /* Number of update cycles that we allow for the dfc to respond correctly to the IOC update */
31 /* messages before we decide that it has failed and pull it back into reset. */
32 #define AO2_MAX_UPDATES_AFTER_RESET 2
33 
34 enum Ao2CalibrationRangeEnum
35 {
36  AO2_CALIBRATION_RANGE_VOLTS,
37  AO2_CALIBRATION_RANGE_MILLIAMPS,
38  AO2_NUMBER_OF_CALIBRATION_RANGES
39 };
40 
41 typedef struct
42 {
43  EioAOCalRangeType rangeType;
44  float rangeLowLimit;
45  float rangeHighLimit;
46  float calPointLow;
47  float calPointHigh;
49 
50 #ifdef __cplusplus
51 
52 /* Any C++ code should be added after this point */
53 #include "eio_t25srm.h"
54 #include "dfc_ssm.h"
55 #include "rst_ssm.h"
56 #include "led_ssm.h"
57 
58 extern "C" {
59 
60 enum Ao2Channels
61 {
62  AO2_CHANNEL_1,
63  AO2_CHANNEL_2,
64  AO2_NUMBER_OF_CHANNELS,
65 };
66 
67 enum Ao2RunStates
68 {
69  EIO_T2500AO2_STATE_JUST_CREATED,
70  EIO_T2500AO2_STATE_MODULE_HAS_CHANGED,
71  EIO_T2500AO2_STATE_INITIALISING,
72  EIO_T2500AO2_STATE_RUNTIME,
73  EIO_T2500AO2_STATE_DELETE,
74  EIO_T2500AO2_STATE_SECONDARY,
75  EIO_T2500AO2_STATE_BECOMING_PRIMARY_1,
76  EIO_T2500AO2_STATE_BECOMING_PRIMARY_2,
77 };
78 
79 enum Ao2EepromAccessState
80 {
81  AO2_EEPROM_RESET_STATE,
82  AO2_EEPROM_READ,
83  AO2_EEPROM_IDLE,
84  AO2_EEPROM_WRITE,
85  AO2_EEPROM_WRITE_DONE
86 };
87 
88 // internal states of the calibration state machine
89 enum Ao2CalibrationState
90 {
91  AO2_CAL_STATE_IDLE,
92  AO2_CAL_STATE_WAIT_FOR_RANGE,
93  AO2_CAL_STATE_OUTPUT,
94  AO2_CAL_STATE_POINT_DONE,
95  AO2_CAL_STATE_POINT_DONE2,
96  AO2_CAL_STATE_SAVE,
97  AO2_CAL_STATE_DATA_SAVED,
98  AO2_CAL_STATE_DEFAULT,
99  AO2_CAL_STATE_END_CAL,
100  AO2_CAL_STATE_SAVE_LOW_POINT,
101  AO2_CAL_STATE_SAVE_HIGH_POINT,
102  AO2_CAL_STATE_SAVE_CHECKSUM,
103  AO2_CAL_STATE_FACTORY_SAVE_LOW_POINT,
104  AO2_CAL_STATE_FACTORY_SAVE_HIGH_POINT,
105  AO2_CAL_STATE_FACTORY_SAVE_CHECKSUM,
106  AO2_CAL_STATE_CORRUPT_CHECKSUM
107 };
108 
109 /*
110  * This is an image of the calibration data held in the eeprom on
111  * the AO2 module
112  */
113 
114 typedef struct AOC_CAL_DATA_T
115 {
116  EioUint16 lowCounts;
117  EioUint16 hiCounts;
118  EioUint16 checksum;
119 } AOC_CAL_DATA_T;
120 
121 /*
122  * The following defines the layout of the calibration data
123  * within the EEPROM. This structure maps into the channel
124  * area within the eeprom
125  */
126 typedef struct AOC_EE_CAL_DATA_T
127 {
128  AOC_CAL_DATA_T m_factoryCal[AO2_NUMBER_OF_CALIBRATION_RANGES]; /* Currently two ranges supported */
129  AOC_CAL_DATA_T m_refCalOffset[AO2_NUMBER_OF_CALIBRATION_RANGES]; /* User reference cal offset */
130 } AOC_EE_CAL_DATA_T;
131 
132 enum Ao2CalibrationPoints
133 {
134  AO2_CAL_POINT_LOW,
135  AO2_CAL_POINT_HIGH,
136  AO2_NUMBER_OF_CALIBRATION_POINTS
137 };
138 
139 class EioT2500AO2Module:public EioT2500Module
140 {
141  public:
142  EioT2500AO2Module(unsigned char moduleNumber, EioT2500CycleEnum z_expectedCycleNumber);
143  virtual ~EioT2500AO2Module();
144 
145  protected:
146  virtual void update62_5mS();
147  virtual void update125mS();
148  virtual void updateBuffers125ms();
149 
150  private:
151  bool decipherCalibration(int z_channel);
152 
153  EioUint16 eeCheckCal( AOC_CAL_DATA_T *z_calData );
154  void driveChannelLeds();
155  void disableAllDfcMessages();
156  void configureRuntimeMessages();
157  EioUint16 getCounts(int z_channel);
158  int channelToPort(int z_channel){return 1-z_channel;};
159  void generatePointStatus();
160  void updateEepromData125mS();
161  void updateCalibrationState();
162 
163  Ao2RunStates m_state;
164  Ao2EepromAccessState m_eepromState;
165  Ao2CalibrationState m_calibrationState[AO2_NUMBER_OF_CHANNELS];
166 
167  bool m_rangeCalibrated[AO2_NUMBER_OF_CHANNELS][AO2_NUMBER_OF_CALIBRATION_RANGES];
168  EioBoolean m_rangeUserCalibrated[AO2_NUMBER_OF_CHANNELS][AO2_NUMBER_OF_CALIBRATION_RANGES];
169 
170  static float m_calScaleFactor;
171  static float m_calibrationRefLow[AO2_NUMBER_OF_CALIBRATION_RANGES];
172  static float m_calibrationRefHigh[AO2_NUMBER_OF_CALIBRATION_RANGES];
173  static Ao2CalibrationRangeEnum m_calType[EIO_AO_NUMBER_OF_TYPES];
174  static EioAOType m_calOutputType[AO2_NUMBER_OF_CALIBRATION_RANGES];
175 
176  Ao2CalibrationPoints m_calPointIndex[AO2_NUMBER_OF_CHANNELS];
177  float m_actualCalValue[AO2_NUMBER_OF_CHANNELS][AO2_NUMBER_OF_CALIBRATION_POINTS];
178  float m_measuredValue[AO2_NUMBER_OF_CHANNELS][AO2_NUMBER_OF_CALIBRATION_POINTS];
179 
180 
181  // recovery messages
182  DfcDelaySpiScheduledMessage * m_delayMessage;
183  DfcDelaySpiScheduledMessage * m_delayMessage2;
184  ResetSpiScheduledMessage * m_resetMessage;
185  DfcDataReadySpiScheduledMessage * m_ledCh1Message;
186  DfcVWireSpiScheduledMessage * m_ledCh2Message;
187  DfcTotalConfigSpiScheduledMessage * m_dfcTotalConfigMessage;
188 
189  EEReadSpiScheduledMessage * m_eereadCalibration[AO2_NUMBER_OF_CHANNELS];
190  EEWriteEnableSpiScheduledMessage * m_eeenableWriteCalibration;
191  EEWriteSpiScheduledMessage * m_eewriteCalibration;
192 
193  LedSpiScheduledMessage * m_moduleLed;
194 
195  DfcIocTotalConfigSpiScheduledMessage * m_iocTotalConfigMessage[AO2_NUMBER_OF_CHANNELS];
196  DfcIocLimitOutputSpiScheduledMessage * m_iocLimitOutputMessage[AO2_NUMBER_OF_CHANNELS];
197  DfcIocDriveOutputSpiScheduledMessage * m_iocDriveOutputMessage[AO2_NUMBER_OF_CHANNELS];
198  DfcReadFilterCountSpiScheduledMessage * m_DfcReadFilterCountSpiScheduledMessage[AO2_NUMBER_OF_CHANNELS];
199 
200  bool m_haveReadValidCalibration[AO2_NUMBER_OF_CHANNELS];
201 
202  AOC_EE_CAL_DATA_T m_calibrationData[AO2_NUMBER_OF_CHANNELS];
203  AOC_EE_CAL_DATA_T m_oldCalData[AO2_NUMBER_OF_CHANNELS];
204  EioAOCalibrationData m_calSMData[AO2_NUMBER_OF_CHANNELS]; // used in the calibration state machine
205 
206  EioAOStatus m_pointStatus[AO2_NUMBER_OF_CHANNELS];
207  EioAOStatus m_localStatus[AO2_NUMBER_OF_CHANNELS];
208  float m_demand[AO2_NUMBER_OF_CHANNELS];
209  EioAOConfig m_pointConfig[AO2_NUMBER_OF_CHANNELS];
210 
211  bool m_clippedLow[AO2_NUMBER_OF_CHANNELS];
212  bool m_clippedHigh[AO2_NUMBER_OF_CHANNELS];
213  bool m_capabilitiesExceeded[AO2_NUMBER_OF_CHANNELS];
214  bool m_iocError[AO2_NUMBER_OF_CHANNELS];
215  bool m_hadHardwareError[AO2_NUMBER_OF_CHANNELS];
216  EioUint8 m_lastHeartBeat[AO2_NUMBER_OF_CHANNELS];
217 
218  EioSint8 m_rangingTrapCounter[AO2_NUMBER_OF_CHANNELS];
219 
220  EioUint8 m_retryCounter;
221 
222  bool m_messagesScheduled;
223  bool m_iocFilterValid;
224  bool m_heartbeatValid;
225  EioUint8 m_rangingCounter;
226  EioUint8 m_resetCounter;
227 };
228 
229 } /* extern "C" */
230 #endif /* __cplusplus */
231 #endif /*__EIOT2SRAO2_H */
232 
Definition: eio_t25srm.h:58
Definition: dfc_ssm.h:340
Definition: eio_ao.h:46
Definition: dfc_ssm.h:399
Definition: dfc_ssm.h:198
Definition: ee_ssm.h:113
Definition: dfc_ssm.h:363
Definition: rst_ssm.h:14
Definition: dfc_ssm.h:233
Definition: led_ssm.h:12
Definition: dfc_ssm.h:206
Definition: dfc_ssm.h:379
Definition: ee_ssm.h:126
Definition: eiot2cal.h:61
Definition: ee_ssm.h:59
Definition: eiot2srao2.h:41
Definition: dfc_ssm.h:352