versadac  1
versadac - Scalable Recorder Firmware
ai8_ssm.h
1 /*******************************************************************************
2 FILE : ai8_ssm.h
3 VERSION : $Id$
4 AUTHOR : Steve Pickford
5 SYSTEM : Diab C for PowerPC under vxWorks
6 DESCRIPTION : This file contains all of the classes in a heirachy that encapsulate
7  the messages used to communicate with the ai8 io module.
8 *******************************************************************************/
9 #ifndef __AI8_SSM_H
10 #define __AI8_SSM_H
11 #include "spismsg.h"
12 
13 /*#define SIMULATE_MODULE_REPLY */
14 
15 /* Capability discovery functions use AI8_NUMBER_OF_CHANNELS */
16 enum Ai8Channels
17 {
18  AI8_CHANNEL_1,
19  AI8_CHANNEL_2,
20  AI8_CHANNEL_3,
21  AI8_CHANNEL_4,
22  AI8_RT_NUMBER_OF_CHANNELS,
23  AI8_CHANNEL_5 = AI8_RT_NUMBER_OF_CHANNELS,
24  AI8_CHANNEL_6,
25  AI8_CHANNEL_7,
26  AI8_CHANNEL_8,
27  AI8_NUMBER_OF_CHANNELS
28 };
29 
30 #define AI8_MODE_MEASURE (0x00)
31 #define AI8_MODE_CALIBRATE (0x40)
32 #define AI8_MODE_MASK (0xC0)
33 
34 #define AI8_CHANNELS_ALL (0x00)
35 #define AI8_CHANNELS_1_4 (0x00)
36 #define AI8_CHANNELS_5_6 (0x08)
37 #define AI8_CHANNELS_MASK (0x08)
38 
39 #define AI8_BUILD_LEVEL_MASK (0x07)
40 
41 enum Ai8Commands
42 {
43  AI8_CMD_NONE,
44  AI8_CMD_CONFIGURE,
45  AI8_CMD_CAL_START,
46  AI8_CMD_CAL_SET_RANGE,
47  AI8_CMD_CAL_SET_CAL_POINT,
48  AI8_CMD_CAL_RESET_CAL_FILTER,
49  AI8_CMD_CAL_CONFIRM,
50  AI8_CMD_CAL_ABORT,
51  AI8_CMD_CAL_WRITE_STATUS
52 };
53 
54 enum Ai8ChannelStatus
55 {
56  AI8_MV_STATUS_GOOD,
57  AI8_MV_STATUS_OVER_RANGE,
58  AI8_MV_STATUS_UNDER_RANGE,
59  AI8_MV_STATUS_RANGING,
60  AI8_MV_STATUS_INVALID_CONFIG,
61  AI8_MV_STATUS_HARDWARE_ERROR,
62  AI8_MV_STATUS_BAD_FACTORY_CAL,
63  AI8_MV_STATUS_BAD_USER_CAL,
64  AI8_MV_STATUS_BREAK_DETECT,
65  AI8_MV_STATUS_2_WIRE_OHMS,
66  AI8_MV_STATUS_CALIBRATING
67 };
68 
69 enum Ai8AuxStatus
70 {
71  AI8_AUX_STATUS_GOOD,
72  AI8_AUX_STATUS_OUT_OF_RANGE,
73  AI8_AUX_STATUS_HARDWARE_ERROR,
74  AI8_AUX_STATUS_BAD_CAL,
75  AI8_AUX_STATUS_RANGING,
76  AI8_AUX_STATUS_CALIBRATING
77 };
78 
79 
80 #define AI8_RANGE_OFF (0x00)
81 #define AI8_RANGE_20MA (0x10)
82 #define AI8_RANGE_80MV (0x20)
83 #define AI8_RANGE_500_OHM_THREE_WIRE (0x30)
84 #define AI8_RANGE_5000_OHM_THREE_WIRE (0x40)
85 #define AI8_RANGE_500_OHM_TWO_WIRE (0x50)
86 #define AI8_RANGE_5000_OHM_TWO_WIRE (0x60)
87 #define AI8_RANGE_UNSUPPORTED (0xF0)
88 #define AI8_RANGE_MASK (0xF0)
89 
90 #define AI8_SENSOR_BREAK_OFF (0x00)
91 #define AI8_SENSOR_BREAK_ON (0x04)
92 #define AI8_SENSOR_BREAK_MASK (0x0C)
93 
94 #define AI8_USER_CAL_OFF (0x00)
95 #define AI8_USER_CAL_ON (0x01)
96 #define AI8_USER_CAL_MASK (0x03)
97 
98 /* Range Limits */
99 #define AIC_AI8_MV_RANGE_LOW (-80.0) /* -80mV */
100 #define AIC_AI8_MV_RANGE_HIGH (80.0) /* 80mV */
101 #define AIC_AI8_V_RANGE_LOW (0.0) /* 0mV */
102 #define AIC_AI8_V_RANGE_HIGH (1000.0) /* 1000mV */
103 #define AIC_AI8_MA_RANGE_LOW (-20.0) /* -20mA */
104 #define AIC_AI8_MA_RANGE_HIGH (20.0) /* 20mA */
105 #define AIC_AI8_OHM_RANGE_LOW (0.0) /* 0.0 Ohm */
106 #define AIC_AI8_OHM_RANGE_HIGH (500.0) /* 500.0 Ohm */
107 #define AIC_AI8_HOHM_RANGE_LOW (0.0) /* 0.0 Ohm */
108 #define AIC_AI8_HOHM_RANGE_HIGH (5000.0) /* 5000.0 Ohm */
109 
110 
111 // this is the base class for all AI8 transactions. It only provides
112 // module to device mapping.
113 class Ai8SpiScheduledMessage:public SpiScheduledMessage
114 {
115  public:
116  Ai8SpiScheduledMessage(unsigned char module, unsigned char length);
117  virtual ~Ai8SpiScheduledMessage();
118 
119  private:
120  static unsigned short moduleToDevice(unsigned char module);
121 };
122 
123 // This class encapsulates an AI8 configuration message
125 {
126  public:
127  Ai8ConfigSpiScheduledMessage(unsigned char module, EioModuleType z_moduleType, unsigned char length);
128  virtual ~Ai8ConfigSpiScheduledMessage();
129 
130  virtual void setCommand(
131  unsigned char z_mode,
132  unsigned char z_cmd) = 0;
133 
134  virtual void setCommandData(
135  unsigned char z_channel,
136  unsigned char z_number,
137  unsigned char z_value) = 0;
138 
139  bool wasCommandOk();
140 
141  void setConfigChecksum();
142 
143  void clearAllCommandData(
144  unsigned char z_channel);
145 
146  void setChannelConfig(
147  unsigned char z_channel,
148  unsigned char z_config);
149 
150  void startCalibration(
151  unsigned char z_channel,
152  unsigned char z_enable,
153  unsigned char z_calType);
154 
155  void setCalibrationRange(
156  unsigned char z_channel,
157  unsigned char z_range);
158 
159  void setCalibrationPoint(
160  unsigned char z_channel,
161  unsigned char z_calPointIndex,
162  float z_actualCalValue,
163  float z_calRefHigh);
164 
165  virtual float getChannelMeasuredValue(
166  unsigned char z_channel) = 0;
167 
168  virtual EioAIMeasuredValueStatus getChannelStatus(
169  unsigned char z_channel) = 0;
170 
171  EioAIMeasuredValueStatus mapChannelStatus(Ai8ChannelStatus z_status);
172 
173  virtual float getChannelAuxValue(
174  unsigned char z_channel) = 0;
175 
176  virtual EioAIAuxStatus getChannelAuxStatus(
177  unsigned char z_channel) = 0;
178 
179  EioAIAuxStatus mapAuxStatus(Ai8AuxStatus z_status);
180 
181 #ifdef SIMULATE_MODULE_REPLY
182  virtual unsigned char* getTestReply() = 0;
183 #endif
184 
185  protected:
186  unsigned char m_moduleType;
187  unsigned char m_channels;
188  unsigned char m_range[AI8_NUMBER_OF_CHANNELS];
189 };
190 
191 // This class encapsulates an AI8 slow configuration message
193 {
194  public:
196  unsigned char z_module,
197  EioModuleType z_moduleType);
198 
200 
201  void setCommand(
202  unsigned char z_mode,
203  unsigned char z_cmd);
204 
205  void setCommandData(
206  unsigned char z_channel,
207  unsigned char z_number,
208  unsigned char z_value);
209 
210 
211  float getChannelMeasuredValue(
212  unsigned char z_channel);
213 
214  EioAIMeasuredValueStatus getChannelStatus(
215  unsigned char z_channel);
216 
217  float getChannelAuxValue(
218  unsigned char z_channel);
219 
220  EioAIAuxStatus getChannelAuxStatus(
221  unsigned char z_channel);
222 
223 #ifdef SIMULATE_MODULE_REPLY
224  unsigned char* getTestReply();
225 #endif
226 
227  private:
228  unsigned char getChannelBaseIndex(unsigned char z_channel);
229 
230 #ifdef SIMULATE_MODULE_REPLY
231  static unsigned char mv_ma_test_reply[];
232  static unsigned char ohm_test_reply[];
233 #endif
234 
235 
236 };
237 
238 // This class encapsulates an AI8 fast configuration message
240 {
241  public:
243  unsigned char z_module,
244  EioModuleType z_moduleType,
245  unsigned char z_channels);
246 
248 
249  void setCommand(
250  unsigned char z_mode,
251  unsigned char z_cmd);
252 
253  void setCommandData(
254  unsigned char z_channel,
255  unsigned char z_number,
256  unsigned char z_value);
257 
258 
259  float getChannelMeasuredValue(
260  unsigned char z_channel);
261 
262  EioAIMeasuredValueStatus getChannelStatus(
263  unsigned char z_channel);
264 
265  float getChannelAuxValue(
266  unsigned char z_channel);
267 
268  EioAIAuxStatus getChannelAuxStatus(
269  unsigned char z_channel);
270 
271 #ifdef SIMULATE_MODULE_REPLY
272  unsigned char* getTestReply(){return ma_test_reply;};
273 #endif
274 
275  private:
276 
277  unsigned char getChannelBaseIndex(unsigned char z_channel);
278 
279  unsigned char getNibble(unsigned char z_index, unsigned char *z_pBuf);
280 
281 #ifdef SIMULATE_MODULE_REPLY
282  static unsigned char ma_test_reply[];
283 #endif
284 };
285 
286 
287 #endif /*__AI8_SSM_H */
288 
Definition: ai8_ssm.h:192
Definition: ai8_ssm.h:239
Definition: ai8_ssm.h:113
Definition: ai8_ssm.h:124