versadac  1
versadac - Scalable Recorder Firmware
mb.h
1 /*****************************************************************************
2 FILE : MB.h
3 AUTHOR : Karl Wakeham
4 SYSTEM : GNU C++ for ARM
5 DESCRIPTION : Contains system wide declarations
6 *****************************************************************************/
7 
8 #ifndef __MB_H
9 #define __MB_H
10 
11 extern "C"
12 {
13  #include "OSTask.h"
14  #include "unicodestringhandler.h"
15  #include "priority.h"
16  #include "stack.h"
17  #include "exchange.h"
18  #include "classnums.h"
19  #include "exec.h"
20  #include "modbus_common.h"
21 
22 }
23 
24 #define DEBUG_MB_VERBOSE 0
25 
26 /************************************************
27  Global constants
28 ************************************************/
29 #define MB_COMAPNY_ID 500
30 #define MB_NANO_PRODUCT_ID 0x3600
31 
32 #define MAX_SERIAL_PORTS 1
33 #define MB_SLAVE_PORT_NUMBER (502)
34 
35 #define OVER_RANGE 32767
36 #define UNDER_RANGE -32767
37 
38 #define MAX_ALARMS_PER_POINT 2
39 
40 #define ALWAYS_ZERO 0
41 #define NO_ERROR 0
42 #define IEEE_FORMAT 0
43 #define SCALED_FORMAT 1
44 #define MB_BYTES_IN_WORD 2
45 #define UNCONFIGURED_REG 0x8000
46 #define REGISTER_65535 0xFFFF
47 #define LOW_WORD 0x0000FFFF
48 #define UPPER_WORD 0xFFFF0000
49 
50 #define NETWORK_MAC_ADDRESS_START 0x5FE0
51 #define NETWORK_MAC_ADDRESS_END 0x5FEF
52 
53 /************************************************
54  Exception response constantsd
55 ************************************************/
56 #define EXCEPTION_MSG_LENGTH 3
57 #define WRITE_REPLY_SIZE 6
58 #define WRITE_REPLY_SIZE_106 8
59 #define MIN_RAW_DATA_SIZE 2
60 #define EXCEPTION_ERROR 128
61 #define ILLEGAL_FUNCTION 1
62 #define ILLEGAL_ADDRESS 2
63 #define ILLEGAL_DATA_VALUE 3
64 #define SLAVE_DEVICE_FAIL 4
65 #define ILLEGAL_REGION 5
66 #define REGION_LOCKED 6
67 #define ILLEGAL_LOGIN_STATUS 10
68 #define SINGLE_REGISTER 1
69 
70 /************************************************
71  Permenant id table addressing (1)
72 ************************************************/
73 #define MB_PID_SIZE 0x0000
74 #define MB_PID_START 0x0000
75 
76 /************************************************
77  Modbus instrument addressing (1)
78 ************************************************/
79 #define MB_INST_SIZE 0x007A
80 #define MB_INST_START 0x0001
81 #define MB_INST_GLOBAL_ALM_ACK 0x0020
82 /* Size in registers - including spares for unicode */
83 #define MB_START_AT_CONFIG_COUNTER 21
84 #define INST_DESC_SIZE 20
85 #define MB_INST_TIME_DATE_SIZE 8
86 #define MB_INST_SPARE_1 75
87 
88 /* reduced to 11 to allow an extra 32 bit register at 108-109 for
89  the product serial number */
90 #define MB_INST_SPARE_2 11
91 
92 /************************************************
93  Feature id table addressing (1)
94 ************************************************/
95 #define MB_FIT_SIZE 0x007A
96 #define MB_FIT_START 0xCC26
97 #define MB_NO_OF_FEATURES 0x0003
98 #define MB_INDIRECT_REF 0x0001
99 #define MB_FC_ID_REF 0x0004
100 #define MB_LOGIN_REF 0x0009
101 #define MB_SUPPORTED_FC 0x80AC //32940
102 #define MB_USERNAME_START 0xCC30
103 #define MB_PASSWORD_START 0xCC58
104 #define MB_USERNAME_SIZE 41
105 
106 /************************************************
107  R/O Indirection table addressing (1 per connection)
108 ************************************************/
109 #define MB_RO_INDIRECT_SIZE 0x0201 /* 512 + 1 for the number of entries */
110 #define MB_RO_INDIRECT_START 0xCCE5
111 #define MB_RO_INDIRECT_END 0xCEE5
112 #define MB_RO_DATA_ACCESS_START 0xCEE6
113 #define MB_RO_DATA_ACCESS_END 0xD0E5
114 #define MB_NUM_OF_RO_ENTRIES 512
115 
116 /************************************************
117  R/W Indirection table addressing (1 per connection)
118 ************************************************/
119 #define MB_RW_INDIRECT_SIZE 0x0201 /* 512 + 1 for the number of entries */
120 #define MB_RW_INDIRECT_START 0xD0E6
121 #define MB_RW_INDIRECT_END 0xD2E6
122 #define MB_RW_DATA_ACCESS_START 0xD2E7
123 #define MB_RW_DATA_ACCESS_END 0xD4E6
124 #define MB_NUM_OF_RW_ENTRIES 512
125 
126 /************************************************
127  Group addressing (1-16)
128 ************************************************/
129 #define GROUP_1 0
130 #define MB_GRP_SIZE 0x0275 /* 629 */
131 #define MB_GRP_START 0xA4D6
132 #define MB_BATCH_TEXT_1_START 0xA57F
133 #define MB_BATCH_TEXT_2_START 0xA5BB
134 #define MB_BATCH_TEXT_3_START 0xA5F7
135 #define MB_BATCH_TEXT_4_START 0xA633
136 #define MB_BATCH_TEXT_5_START 0xA66F
137 #define MB_BATCH_TEXT_6_START 0xA6AB
138 #define MB_BATCH_START_1 0xA57C
139 #define MB_BATCH_STOP_1 0xA57D
140 #define MB_WRITE_TEXT_START_1 0xA540
141 #define MB_TEXT_LENGTH_GRP1 0xA4FF
142 #define MB_READ_TXT_GRP1_START 0xA4FF /* PDR11695: changed from 0xA504 */
143 #define MB_READ_TXT_GRP1_END 0xA53F
144 
145 #define MB_TEXT_LEN_OFFSET 41
146 #define MB_TEXT_DATA_SIZE 65
147 
148 #define MB_MAX_RAW_MSG_SIZE 500
149 
150 /* Size in registers - including spares for unicode */
151 #define GRP_DESC_SIZE 20
152 #define ASCII_GROUP_TEXT_SIZE 60 /* max of 60 characters */
153 #define GROUP_NULL_TERMINATOR 59 /*array index 0-59 */
154 #define ASCII_BATCH_TEXT_SIZE 60
155 #define UC_GROUP_TEXT_SIZE 120
156 #define GROUP_CONTENTS_SIZE 16
157 
158 #define MB_QUEUE_SIZE 12000
159 
160 #define MB_GRP_SPARE_1 10
161 #define MB_START_AT_TEXT_LEN 41
162 #define MB_GRP_MATHS_CHAN_START 4
163 #define MB_GRP_TOT_CHAN_START 10
164 #define MB_GRP_COUNT_CHAN_START 14
165 
166 /************************************************
167  Channel - General constants
168 ************************************************/
169 #define POINT_1 0
170 #define MB_FLOAT_SCALE 2
171 
172 /************************************************
173  Point - Config data constants
174 ************************************************/
175 #define MB_PNT_CNFG_SIZE 162
176 #define MB_MAX_NUM_MODBUS_IP_CHANS 75
177 #define MB_MAX_NUM_EIP_CHANS 100
178 #define MB_MAX_NUM_MATHS 100
179 #define MB_MAX_NUM_TOTALISER 50
180 #define MB_MAX_NUM_COUNTERS 30
181 
182 /* need to store enough data for 100 channels, as we now
183  have up to 100 configurable channels on the target */
184 #define MB_MAX_CHANNELS 100
185 
186 /* Size in registers - includes spares for unicode */
187 #define UNITS_TEXT_SIZE 5
188 #define OPEN_TEXT_SIZE 8
189 #define CLOSE_TEXT_SIZE 8
190 #define CHAN_DESC_SIZE 20
191 #define MB_PNT_ALRM_SIZE 13
192 #define MB_PNT_CNFG_SPARE_1 60
193 #define MB_PNT_CNFG_SPARE_2 10
194 
195 /* IEEE format of the above point config data */
196 #define MB_PNT_IEEE_CNFG_SIZE 36
197 #define MB_PNT_IEEE_SPARE_1 20
198 #define MB_PNT_IEEE_ALM_SIZE 2
199 
200 /************************************************
201  Channel specific - Config data addressing region 1
202 ************************************************/
203 #define MB_CHAN1_CNFG_START 0x007B
204 #define MB_CHAN1_ALARM_SP_1 0x00EB
205 #define MB_CHAN1_ALARM_SP_2 0x00F8
206 #define MB_CHAN1_ALARM_SP_3 0x0105
207 #define MB_CHAN1_ALARM_SP_4 0x0112
208 #define MB_CHAN1_MDP (MB_CHAN1_CNFG_START + 5)
209 
210 /************************************************
211  Channel specific - Config data addressing
212  Additional 25 channels in memeory map region 2
213 ************************************************/
214 #define MB_CHAN2_CNFG_START 0xFDA0
215 #define MB_CHAN2_ALARM_SP_1 0xFE10
216 #define MB_CHAN2_ALARM_SP_2 0xFE1D
217 #define MB_CHAN2_ALARM_SP_3 0xFE2A
218 #define MB_CHAN2_ALARM_SP_4 0xFE37
219 #define MB_CHAN2_MDP (MB_CHAN2_CNFG_START + 5)
220 
221 /************************************************
222  Maths specific - Config data addressing
223 ************************************************/
224 #define MB_MATH1_CNFG_START (MB_CHAN1_CNFG_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
225 #define MB_MATH1_ALARM_SP_1 (MB_CHAN1_ALARM_SP_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
226 #define MB_MATH1_ALARM_SP_2 (MB_CHAN1_ALARM_SP_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
227 #define MB_MATH1_ALARM_SP_3 (MB_CHAN1_ALARM_SP_3 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
228 #define MB_MATH1_ALARM_SP_4 (MB_CHAN1_ALARM_SP_4 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_CNFG_SIZE))
229 #define MB_MATH1_MDP (MB_MATH1_CNFG_START + 5)
230 
231 /************************************************
232  Totaliser specific - Config data addressing
233 ************************************************/
234 #define MB_TOT1_CNFG_START (MB_MATH1_CNFG_START + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
235 #define MB_TOT1_ALARM_SP_1 (MB_MATH1_ALARM_SP_1 + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
236 #define MB_TOT1_ALARM_SP_2 (MB_MATH1_ALARM_SP_2 + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
237 #define MB_TOT1_ALARM_SP_3 (MB_MATH1_ALARM_SP_3 + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
238 #define MB_TOT1_ALARM_SP_4 (MB_MATH1_ALARM_SP_4 + (MB_MAX_NUM_MATHS * MB_PNT_CNFG_SIZE))
239 #define MB_TOT1_MDP (MB_TOT1_CNFG_START + 5)
240 
241 /************************************************
242  Counter specific - Config data addressing
243 ************************************************/
244 #define MB_COUNT1_CNFG_START (MB_TOT1_CNFG_START + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
245 #define MB_COUNT1_ALARM_SP_1 (MB_TOT1_ALARM_SP_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
246 #define MB_COUNT1_ALARM_SP_2 (MB_TOT1_ALARM_SP_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
247 #define MB_COUNT1_ALARM_SP_3 (MB_TOT1_ALARM_SP_3 + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
248 #define MB_COUNT1_ALARM_SP_4 (MB_TOT1_ALARM_SP_4 + (MB_MAX_NUM_TOTALISER * MB_PNT_CNFG_SIZE))
249 #define MB_COUNT1_MDP (MB_COUNT1_CNFG_START + 5)
250 
251 
252 /************************************************
253  Channel specific - IEEE Config data addressing
254 ************************************************/
255 #define MB_CHAN1_IEEE_CNFG_START 0xD4E7
256 #define MB_CHAN1_IEEE_SP1_REG_1 0xD4EF
257 #define MB_CHAN1_IEEE_SP1_REG_2 0xD4F0
258 #define MB_CHAN1_IEEE_SP2_REG_1 0xD4F1
259 #define MB_CHAN1_IEEE_SP2_REG_2 0xD4F2
260 #define MB_CHAN1_IEEE_SP3_REG_1 0xD4F3
261 #define MB_CHAN1_IEEE_SP3_REG_2 0xD4F4
262 #define MB_CHAN1_IEEE_SP4_REG_1 0xD4F5
263 #define MB_CHAN1_IEEE_SP4_REG_2 0xD4F6
264 
265 /************************************************
266  Maths specific - IEEE Config data addressing
267 ************************************************/
268 #define MB_MATH1_IEEE_CNFG_START (MB_CHAN1_IEEE_CNFG_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
269 #define MB_MATH1_IEEE_SP1_REG_1 (MB_CHAN1_IEEE_SP1_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
270 #define MB_MATH1_IEEE_SP1_REG_2 (MB_CHAN1_IEEE_SP1_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
271 #define MB_MATH1_IEEE_SP2_REG_1 (MB_CHAN1_IEEE_SP2_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
272 #define MB_MATH1_IEEE_SP2_REG_2 (MB_CHAN1_IEEE_SP2_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
273 #define MB_MATH1_IEEE_SP3_REG_1 (MB_CHAN1_IEEE_SP3_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
274 #define MB_MATH1_IEEE_SP3_REG_2 (MB_CHAN1_IEEE_SP3_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
275 #define MB_MATH1_IEEE_SP4_REG_1 (MB_CHAN1_IEEE_SP4_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
276 #define MB_MATH1_IEEE_SP4_REG_2 (MB_CHAN1_IEEE_SP4_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_CNFG_SIZE))
277 
278 /************************************************
279  Totalisers specific - IEEE Config data addressing
280 ************************************************/
281 #define MB_TOT1_IEEE_CNFG_START (MB_MATH1_IEEE_CNFG_START + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
282 #define MB_TOT1_IEEE_SP1_REG_1 (MB_MATH1_IEEE_SP1_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
283 #define MB_TOT1_IEEE_SP1_REG_2 (MB_MATH1_IEEE_SP1_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
284 #define MB_TOT1_IEEE_SP2_REG_1 (MB_MATH1_IEEE_SP2_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
285 #define MB_TOT1_IEEE_SP2_REG_2 (MB_MATH1_IEEE_SP2_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
286 #define MB_TOT1_IEEE_SP3_REG_1 (MB_MATH1_IEEE_SP3_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
287 #define MB_TOT1_IEEE_SP3_REG_2 (MB_MATH1_IEEE_SP3_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
288 #define MB_TOT1_IEEE_SP4_REG_1 (MB_MATH1_IEEE_SP4_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
289 #define MB_TOT1_IEEE_SP4_REG_2 (MB_MATH1_IEEE_SP4_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_CNFG_SIZE))
290 
291 /************************************************
292  Counter specific - IEEE Config data addressing
293 ************************************************/
294 #define MB_COUNT1_IEEE_CNFG_START (MB_TOT1_IEEE_CNFG_START + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
295 #define MB_COUNT1_IEEE_SP1_REG_1 (MB_TOT1_IEEE_SP1_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
296 #define MB_COUNT1_IEEE_SP1_REG_2 (MB_TOT1_IEEE_SP1_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
297 #define MB_COUNT1_IEEE_SP2_REG_1 (MB_TOT1_IEEE_SP2_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
298 #define MB_COUNT1_IEEE_SP2_REG_2 (MB_TOT1_IEEE_SP2_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
299 #define MB_COUNT1_IEEE_SP3_REG_1 (MB_TOT1_IEEE_SP3_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
300 #define MB_COUNT1_IEEE_SP3_REG_2 (MB_TOT1_IEEE_SP3_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
301 #define MB_COUNT1_IEEE_SP4_REG_1 (MB_TOT1_IEEE_SP4_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
302 #define MB_COUNT1_IEEE_SP4_REG_2 (MB_TOT1_IEEE_SP4_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_CNFG_SIZE))
303 
304 /************************************************
305  Point - run time data constants
306 ************************************************/
307 #define MB_PNT_RUN_SIZE 3
308 
309 /* IEEE format of the above point run time data */
310 #define MB_PNT_IEEE_RUN_SIZE 4
311 
312 /************************************************
313  Channel - run time data addressing
314 ************************************************/
315 #define MB_CHAN1_RUN_START 0xA1D9
316 #define MB_CHAN1_PV_1_START 0xA1D9
317 #define MB_CHAN1_ALARM_ACK 0xA1DB
318 
319 /************************************************
320  Channel - (region 2) run time data addressing
321  Additional 25 channels in memeory map
322 ************************************************/
323 #define MB_CHAN2_PNT_OFFSET MB_MAX_NUM_MODBUS_IP_CHANS
324 #define MB_CHAN2_RUN_START 0xFCBF
325 #define MB_CHAN2_PV_1_START 0xFCBF
326 #define MB_CHAN2_ALARM_ACK 0xFCC1
327 
328 /************************************************
329  Maths - run time data addressing
330 ************************************************/
331 #define MB_MATH1_RUN_START (MB_CHAN1_RUN_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_RUN_SIZE))
332 #define MB_MATH1_PV_1_START (MB_CHAN1_PV_1_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_RUN_SIZE))
333 #define MB_MATH1_ALARM_ACK (MB_CHAN1_ALARM_ACK + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_RUN_SIZE))
334 
335 /************************************************
336  Totaliser - run time data addressing
337 ************************************************/
338 #define MB_TOT1_RUN_START (MB_MATH1_RUN_START + (MB_MAX_NUM_MATHS * MB_PNT_RUN_SIZE))
339 #define MB_TOT1_PV_1_START (MB_MATH1_PV_1_START + (MB_MAX_NUM_MATHS * MB_PNT_RUN_SIZE))
340 #define MB_TOT1_ALARM_ACK (MB_MATH1_ALARM_ACK + (MB_MAX_NUM_MATHS * MB_PNT_RUN_SIZE))
341 
342 /************************************************
343  Counter - run time data addressing
344 ************************************************/
345 #define MB_COUNT1_RUN_START (MB_TOT1_RUN_START + (MB_MAX_NUM_TOTALISER * MB_PNT_RUN_SIZE))
346 #define MB_COUNT1_PV_1_START (MB_TOT1_PV_1_START + (MB_MAX_NUM_TOTALISER * MB_PNT_RUN_SIZE))
347 #define MB_COUNT1_ALARM_ACK (MB_TOT1_ALARM_ACK + (MB_MAX_NUM_TOTALISER * MB_PNT_RUN_SIZE))
348 
349 /************************************************
350  Channels - IEEE run time data addressing
351 ************************************************/
352 #define MB_CHAN1_IEEE_RUN_START 0xF8C3
353 #define MB_CHAN1_IEEE_PV_1_REG_1 0xF8C3
354 #define MB_CHAN1_IEEE_PV_1_REG_2 0xF8C4
355 #define MB_CHAN1_IEEE_ALARM_ACK 0xF8C6
356 
357 /************************************************
358  Maths - IEEE run time data addressing
359 ************************************************/
360 #define MB_MATH1_IEEE_RUN_START (MB_CHAN1_IEEE_RUN_START + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_RUN_SIZE))
361 #define MB_MATH1_IEEE_PV_1_REG_1 (MB_CHAN1_IEEE_PV_1_REG_1 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_RUN_SIZE))
362 #define MB_MATH1_IEEE_PV_1_REG_2 (MB_CHAN1_IEEE_PV_1_REG_2 + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_RUN_SIZE))
363 #define MB_MATH1_IEEE_ALARM_ACK (MB_CHAN1_IEEE_ALARM_ACK + (MB_MAX_NUM_MODBUS_IP_CHANS * MB_PNT_IEEE_RUN_SIZE))
364 
365 /************************************************
366  Totalisers - IEEE run time data addressing
367 ************************************************/
368 #define MB_TOT1_IEEE_RUN_START (MB_MATH1_IEEE_RUN_START + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_RUN_SIZE))
369 #define MB_TOT1_IEEE_PV_1_REG_1 (MB_MATH1_IEEE_PV_1_REG_1 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_RUN_SIZE))
370 #define MB_TOT1_IEEE_PV_1_REG_2 (MB_MATH1_IEEE_PV_1_REG_2 + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_RUN_SIZE))
371 #define MB_TOT1_IEEE_ALARM_ACK (MB_MATH1_IEEE_ALARM_ACK + (MB_MAX_NUM_MATHS * MB_PNT_IEEE_RUN_SIZE))
372 
373 /************************************************
374  Counter - IEEE run time data addressing
375 ************************************************/
376 #define MB_COUNT1_IEEE_RUN_START (MB_TOT1_IEEE_RUN_START + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_RUN_SIZE))
377 #define MB_COUNT1_IEEE_PV_1_REG_1 (MB_TOT1_IEEE_PV_1_REG_1 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_RUN_SIZE))
378 #define MB_COUNT1_IEEE_PV_1_REG_2 (MB_TOT1_IEEE_PV_1_REG_2 + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_RUN_SIZE))
379 #define MB_COUNT1_IEEE_ALARM_ACK (MB_TOT1_IEEE_ALARM_ACK + (MB_MAX_NUM_TOTALISER * MB_PNT_IEEE_RUN_SIZE))
380 
381 /************************************************
382  modbus memory map final address
383 ************************************************/
384 #define MB_MEM_MAP_END 0xFFF5 /* 65525 */
385 
386 /************************************************
387  Message exchange queue names
388 ************************************************/
389 #define DRV_NAME "DRVX"
390 #define SCOMMS1_NAME "SCX0"
391 #define CON_1_NAME "CX"
392 
393 /************************************************************************************
394  Message sizes - changed so that drivers adhere to updated modbus specifications
395  from www.modbus.org:
396  - MODBUS MESSAGING ON TCP/IP IMPLEMENTATION GUIDE V1.0b (October 24, 2006)
397  - MODBUS APPLICATION PROTOCOL SPECIFICATION V1.1b (December 28, 2006)
398  These specifications state that:
399  - the Modbus TCP MBAP (header) is 7 bytes
400  - the maximum number of data bytes is 253 bytes
401  - the maximum packet size is 260 bytes (header + data bytes)
402  Therefore the maximum read request size is 126 registers (252 bytes)
403 *************************************************************************************/
404 #define MB_MAX_TRANSACTION_SIZE 261 // to handle function codes 103/106 (used by GWE)
405 #define MB_MAX_REPLY_SIZE 260
406 #define MB_MAX_READ_REQ_SIZE 126
407 
408 enum MB_TransactionParsing
409 {
410  /************************************************
411  Request/Response transaction header enums
412  ************************************************/
413  MB_HEADER_SIZE = 6,
414  MB_TRAN_ID_HI = 0,
415  MB_TRAN_ID_LO = 1,
416  MB_PROT_ID_HI = 2,
417  MB_PROT_ID_LO = 3,
418  MB_LEN_HI = 4,
419  MB_LEN_LO = 5,
420 
421  /************************************************
422  Request transaction enums
423  ************************************************/
424  /* The len represents the number of bytes following from here */
425  MB_UNIT_ID = 6,
426  MB_FUNC_CODE = 7,
427  /* Request data array is presumed to start from here */
428  RCV_ADR_HI = 0,
429  RCV_ADR_LO = 1,
430  /* Data quantitiy for fc 3,4 & 16 */
431  RCV_DATA_QTY_HI = 2,
432  RCV_DATA_QTY_LO = 3,
433  /* Preset values for fc 6 only */
434  RCV_PRESET_HI = 2,
435  RCV_PRESET_LO = 3,
436  /* The following are for fc 16 only */
437  RCV_BYTE_COUNT = 4,
438  RCV_DATA_HI = 5,
439  RCV_DATA_LO = 6,
440  /* Used for diagnostics requests only */
441  DIAG_SUBFUNC_HI = 0,
442  DIAG_SUBFUNC_LO = 1,
443  DIAG_DATA_HI = 2,
444  DIAG_DATA_LO = 3,
445 
446  /************************************************
447  Read Response transaction enums
448  ************************************************/
449  /* Reply data array is presumed to start from here for fc 3 & 4 */
450  SND_BYTE_COUNT = 8,
451  /* Reply data array is presumed to start from here for fc 6 & 16 */
452  SND_ADR_HI = 8,
453  SND_ADR_LO = 9,
454  SND_DATA_QTY_HI = 10,
455  SND_DATA_QTY_LO = 11,
456  /* The byte count is the 4th byte after the header in a request response from the master */
457  SND_DATA_HI = 12,
458  SND_DATA_LO = 13,
459 
460  WRITE_REPLY_START = 8,
461  EX_REPLY_START = 8,
462  READ_REPLY_START = 9,
463  DIAG_REPLY_START = 8,
464 };
465 
466 enum MB_ExchangeCodes
467 {
468  MB_REQUEST_MSG,
469  MB_REPLY_MSG,
470  MB_LOGIN_MSG,
471  MB_DISCONNECT_MSG,
472  MB_CODE_B_MSG
473 };
474 
475 enum MB_FunctionCodes
476 {
477  MB_FUNCTION_CODE_3 = 3,
478  MB_FUNCTION_CODE_4 = 4,
479  MB_FUNCTION_CODE_6 = 6,
480  MB_FUNCTION_CODE_8 = 8,
481  MB_FUNCTION_CODE_16 = 16,
482 
483  // Specials for flash/CISP reading/writing
484  MB_FUNCTION_CODE_103 = 103,
485  MB_FUNCTION_CODE_104 = 104,
486  MB_FUNCTION_CODE_106 = 106,
487  MB_FUNCTION_CODE_107 = 107
488 };
489 
490 enum MB_Diagnostics
491 {
492  RETURN_QUERY_DATA = 0,
493  DIAG_00_REPLY_SIZE = 6
494 };
495 
496 enum MB_Special
497 {
498  MAC_ADDRESS_WRITE = 1
499 };
500 
501 enum MB_AddressRegions
502 {
503  /* Modbus address regions */
504  MB_NOT_USED,
505  MB_INSTRUMENT,
506  MB_CHAN_CONFIG,
507  MB_MATH_CONFIG,
508  MB_TOTALISER_CONFIG,
509  MB_COUNTER_CONFIG,
510  MB_CHAN_RUNTIME,
511  MB_MATH_RUNTIME,
512  MB_TOTALISER_RUNTIME,
513  MB_COUNTER_RUNTIME,
514  MB_GROUP_DATA,
515  MB_FEATURE_ID,
516  MB_RO_INDIRECTION,
517  MB_RO_DATA_ACCESS,
518  MB_RW_INDIRECTION,
519  MB_RW_DATA_ACCESS,
520  MB_CHAN_IEEE_CONFIG,
521  MB_MATH_IEEE_CONFIG,
522  MB_TOTALISER_IEEE_CONFIG,
523  MB_COUNTER_IEEE_CONFIG,
524  MB_CHAN_IEEE_RUNTIME,
525  MB_MATH_IEEE_RUNTIME,
526  MB_TOTALISER_IEEE_RUNTIME,
527  MB_COUNTER_IEEE_RUNTIME,
528  MB_CHAN2_RUNTIME,
529  MB_CHAN2_CONFIG,
530  MB_PERMENANT_ID,
531  MB_MAX_NUMBER_OF_REGIONS = MB_PERMENANT_ID + 2
532 };
533 
535 {
536  uint8 tran_id_hi;
537  uint8 tran_id_lo;
538  uint8 prot_id_hi;
539  uint8 prot_id_lo;
540  uint8 len_hi;
541  uint8 len_lo;
542  uint8 unit_id;
543  uint8 func_code;
544  uint8 request[MB_MAX_TRANSACTION_SIZE];
545  uint32 length;
546  /* When a response transaction is created all data will go here including
547  the header to the message, length will define this entire size */
548  uint8 reply[MB_MAX_REPLY_SIZE];
549  uint16 connectionNumber;
550  char *masterAddress;
551 };
552 
553 #endif /* __MB_H */
Definition: mb.h:534