versadac  1
versadac - Scalable Recorder Firmware
eips_usersys.h
1 /*
2  * Copyright (c) 2002-2013 by Real Time Automation, Inc.
3  *
4  * This software is copyrighted by and is the sole property of
5  * Real Time Automation, Inc. (RTA). All rights, title, ownership,
6  * or other interests in the software remain the property of RTA.
7  * This software may only be used in accordance with the corresponding
8  * license agreement. Any unauthorized use, duplication, transmission,
9  * distribution, or disclosure of this software is expressly forbidden.
10  *
11  * This Copyright notice MAY NOT be removed or modified without prior
12  * written consent of RTA.
13  *
14  * RTA reserves the right to modify this software without notice.
15  *
16  * Real Time Automation
17  * 150 S. Sunny Slope Road USA 262.439.4999
18  * Suite 130 www.rtaautomation.com
19  * Brookfield, WI 53005 software@rtaautomation.com
20  *
21  *************************************************************************
22  *
23  * Version Date: 18APR2013
24  * Version: 2.33
25  * Conformed To: EtherNet/IP Protocol Conformance Test A-9 (16-NOV-2011)
26  * Module Name: eips_usersys.h
27  * Author: Jamin D. Wendorf (jwendorf@rtaautomation.com)
28  * Language: Ansi C
29  * Compile Options: N/A
30  * Compile defines: N/A
31  * Libraries: N/A
32  * Link Options: N/A
33  *
34  * Description.
35  * =======================================================================
36  * This file contains user definitions specific to EtherNet/IP General
37  * behavior.
38  *
39  */
40 
41 #ifndef __EIPS_USERSYS_H__
42 #define __EIPS_USERSYS_H__
43 
44 
45 /* ------------------------------------------- */
46 /* RTA "ADD ON" SUPPORT */
47 /* ------------------------------------------- */
48 #define _CRT_SECURE_NO_WARNINGS /* we don't need to use safe sscanf() in Visual C++ */
49 
50 /* --------------------------------- */
51 /* define if EIP Client is supported */
52 /* --------------------------------- */
53 #define EIPC_CLIENT_USED 1
54 
55 /* ------------------------------------------------- */
56 /* define if Module/Network Status LED is supported */
57 /* ------------------------------------------------- */
58 /* #define EIPS_MODNET_LED_USED 1 */
59 
60 /* -------------------------------------------------------------------------------- */
61 /* define if Module Status LED is supported (can't use if Mod/Net LED is supported) */
62 /* -------------------------------------------------------------------------------- */
63 /* #define EIPS_MOD_LED_USED 1 */
64 
65 /* --------------------------------------------------------------------------------- */
66 /* define if Network Status LED is supported (can't use if Mod/Net LED is supported) */
67 /* --------------------------------------------------------------------------------- */
68  #define EIPS_NTWK_LED_USED 1
69 
70 /* ------------------------------------- */
71 /* define if I/O Status LED is supported */
72 /* ------------------------------------- */
73  #define EIPS_IO_LED_USED 1
74 
75 /* --------------------------------------------------------------------- */
76 /* define if Quality of Service (QoS) is enabled. The RTA stack exposes
77  the parameters and services. The customer is responsible for the
78  actual tagging of the packets */
79 /* --------------------------------------------------------------------- */
80 /* #define EIPS_QOS_USED 1 */
81 
82 /* --------------------------------------------------------------- */
83 /* define to support a 32 character name for Timer subsystem debug */
84 /* --------------------------------------------------------------- */
85 /* #define EIPS_TIMER_NAME_USED 1 */
86 
87 /* ---------------------------------------------------- */
88 /* define if PCCC Server Emulation (PLC5E) is supported */
89 /* ---------------------------------------------------- */
90 /* #define EIPS_PCCC_USED 1 */
91 
92 /* --------------------------------------------------------------- */
93 /* define to support RA Tag Read/Write Data Services as a server
94  RTA stack supports:
95  RA Read Tag Service (0x4C) - "RA_SC_RD_TAG_REQ_REQ"
96  RA Write Tag Service (0x4D) - "RA_SC_WR_TAG_REQ_REQ"
97 NOTE: This is the original version with limited data type support.
98  --------------------------------------------------------------- */
99 /* #define EIPS_CIP_READ_WRITE_DATA_LOGIX 1 */
100 
101 /* --------------------------------------------------------------- */
102 /* define to support RA Tag Fragmented Read/Write Services as a server
103  RTA stack supports:
104  RA Read Tag Service (0x4C) - "RA_SC_RD_TAG_REQ_REQ"
105  RA Write Tag Service (0x4D) - "RA_SC_WR_TAG_REQ_REQ"
106  RA Read Frag Tag Service (0x52) - "RA_SC_RD_FRAG_TAG_REQ_REQ"
107  RA Write Frag Tag Service (0x53) - "RA_SC_WR_FRAG_TAG_REQ_REQ"
108 NOTE: This method requires the user to format ALL data in little
109  endian byte ordering since UDTs are supported. */
110 /* --------------------------------------------------------------- */
111 /* #define EIPS_CIP_READ_WRITE_DATA_LOGIX_ADVANCED 1 */
112 
113 /* --------------------------------------------------------------- */
114 /* define a CPU slot if we emulate the Logix processor (usually 0) */
115 /* --------------------------------------------------------------- */
116 /* #define EIPS_USERSYS_OUR_SLOT_ID 0 */
117 
118 /* ------------------------------------------------ */
119 /* define if a hardware/watchdog reset is supported */
120 /* ------------------------------------------------ */
121 #define EIPS_USERSYS_HWRESET_SUPPORTED 1
122 
123 /* *********************************************** */
124 /* include files needed for the sample application */
125 /* *********************************************** */
126 #ifndef WIN32
127 #define EUROTHERM_VXWORKS (1)
128 #endif
129 
130 // include files needed for the sample application
131 #if EUROTHERM_VXWORKS
132 #include "vxWorks.h"
133 #include "sockLib.h"
134 #include "inetLib.h"
135 #include "stdioLib.h"
136 #include "strLib.h"
137 #include "hostLib.h"
138 #include "stdlib.h"
139 #include <selectLib.h>
140 #include "ioLib.h"
141 #include "stdio.h"
142 #include "string.h"
143 #include "system_ticks.h"
144 #else
145 #include <stdlib.h>
146 #include <string.h>
147 #include <stdio.h>
148 #include <time.h>
149 /*#include <winsock2.h>*/
150 #endif
151 
152 /* --------------------------------------------------------------- */
153 /* TYPE DEFINITIONS */
154 /* --------------------------------------------------------------- */
155 #if EUROTHERM_VXWORKS
156 #ifndef int8
157  #define int8 sint8
158 #endif
159 
160 #ifndef uint8
161  #define uint8 uint8
162 #endif
163 
164 #ifndef int16
165  #define int16 sint16
166 #endif
167 
168 #ifndef uint16
169  #define uint16 uint16
170 #endif
171 
172 #ifndef int32
173  #define int32 sint32
174 #endif
175 
176 #ifndef uint32
177  #define uint32 uint32
178 #endif
179 #else
180 #ifndef int8
181  #define int8 signed char
182 #endif
183 
184 #ifndef uint8
185  #define uint8 unsigned char
186 #endif
187 
188 #ifndef int16
189  #define int16 short
190 #endif
191 
192 #ifndef uint16
193  #define uint16 unsigned short
194 #endif
195 
196 #ifndef int32
197  #define int32 long
198 #endif
199 
200 #ifndef uint32
201  #define uint32 unsigned long
202 #endif
203 #endif
204 
205 #ifndef NULLFNPTR
206  #define NULLFNPTR ((void (*)()) 0)
207 #endif
208 
209 /* --------------------------------------------------------------- */
210 /* GENERIC DEFINITIONS */
211 /* --------------------------------------------------------------- */
212 #ifndef SUCCESS
213  #define SUCCESS 0
214 #endif
215 
216 #ifndef FAILURE
217  #define FAILURE 1
218 #endif
219 
220 #ifndef FAIL
221  #define FAIL 1
222 #endif
223 
224 #ifndef TRUE
225  #define TRUE 1
226 #endif
227 
228 #ifndef FALSE
229  #define FALSE 0
230 #endif
231 
232 #ifndef YES
233  #define YES 1
234 #endif
235 
236 #ifndef NO
237  #define NO 0
238 #endif
239 
240 #ifndef ON
241  #define ON 1
242 #endif
243 
244 #ifndef OFF
245  #define OFF 0
246 #endif
247 
248 #ifndef NULL
249  #define NULL 0x00
250 #endif
251 
252 #ifndef NULLPTR
253  #define NULLPTR NULL
254 #endif
255 
256 /* we put lookup tables in code space to save RAM */
257 #define EIPS_CODESPACE const
258 #define RTA_CODESPACE EIPS_CODESPACE
259 
260 /* --------------------------------------------------------------- */
261 /* MACROS */
262 /* --------------------------------------------------------------- */
263 #define Xmod(v,b) (v - ((v/b)*b))
264 #define RTA_UNUSED_PARAM(a) if(a){}
265 
266 #define EIPS_GET_MUTEX
267 #define EIPS_PUT_MUTEX
268 
269 /* define macros to get the high and low bytes of a word */
270 #define EIPS_LO(l) (uint8)(l&0x00FF)
271 #define EIPS_HI(h) (uint8)((h&0xFF00)>>8)
272 
273 #define RTA_MAX(a,b) (a>b?a:b)
274 #define RTA_MIN(a,b) (a<b?a:b)
275 
276 /* Define the number of path words included in a single
277  explicit message. This should be at least 10. */
278 #define EIPS_USER_MSGRTR_PATH_WORDS 50
279 
280 /* Define the number of extended error words included in
281  a single explicit message. This should be at least 2. */
282 #define EIPS_USER_MSGRTR_EXTSTAT_SIZE 16
283 
284 /* Define the max number of I/O bytes that can be transmitted in
285  each direction. */
286 #ifdef EUROTHERM_VXWORKS
287 #define EIPS_USER_IOBUF_SIZ 600
288 #else
289 #define EIPS_USER_IOBUF_SIZ 200
290 #endif
291 
292 /* Define the amount of data that can sent in a single explicit message. */
293 #define EIPS_USER_MSGRTR_DATA_SIZE (RTA_MAX((EIPS_USER_IOBUF_SIZ+25),600)) /* this number should the larger of the max I/O and max EM, plus a few bytes for overhead */
294 
295 /* Define the max size of the encapsulated message. This should
296  be at least 600, but can go up to 64K based on the needs of
297  the customer. The NOP command is the only command that is
298  supported that can be larger than 600 bytes, but the stack
299  handles the NOP in a special fashion to save on RAM. */
300 #define EIPS_USER_MAX_ENCAP_BUFFER_SIZ (EIPS_USER_MSGRTR_DATA_SIZE+50)
301 
302 /* Define the max number of I/O connections supported. This
303  can be 0 to (EIPS_USER_MAX_NUM_EM_CNXNS_PER_SESSION *
304  EIPS_USER_MAX_NUM_EIP_SESSIONS). */
305 #define EIPS_USER_MAX_NUM_IO_CNXNS 10
306 
307 /* Define the max number of Encapsulation Sessions supported
308  by the device. This should be smaller than the total
309  number of sockets supported. */
310 #define EIPS_USER_MAX_NUM_EIP_SESSIONS 10
311 
312 /* Define the max number of Explicit connections
313  supported by the server. */
314 #define EIPS_USER_MAX_NUM_EM_CNXNS_PER_SESSION 2
315 
316 /* define the resolution of the ticker in in microseconds.
317  1L - one microsecond ticker
318  1000L - one millisecond ticker
319  10000L - ten millisecond ticker
320  1000000L - one second ticker
321 */
322 #ifdef EUROTHERM_VXWORKS
323 #define EIPS_USER_TICK_RES_IN_USECS (1000000L/8) /* us in 1 tick */
324 #define EIPS_USER_TICK_RES_IN_MSSECS (1000L/8) /* ms in 1 tick */
325 
326 // This should be enabled if the execution of the RTA stack is to be
327 // synchronised with the function block execution engine. This will ensure
328 // that all data used in the RTA cache is coherant all be it at a 125ms tick
329 // If this is not enabled the stack will execute ip to 8 times faster but runs
330 // the risk of not having coherant data in the cache.
331 #define EIPS_FB_SYNCHRONISED 1
332 
333 #ifdef EIPS_FB_SYNCHRONISED
334  #define EIPS_USER_MIN_TICK_RES_IN_USEC 125000l /* 125ms min */
335 #else
336  #define EIPS_USER_MIN_TICK_RES_IN_USEC 16000l /* 16ms min */
337 #endif
338 
339 #define EIPS_USER_TICKS_PER_1SEC 8
340 #define EIPS_USER_TICKS_PER_10SEC (10*EIPS_USER_TICKS_PER_1SEC)
341 #define EIPS_USER_TCP_INACTIVITY_TMO (EIPS_USER_TICKS_PER_1SEC*10)
342 
343 /* RTA depends on a timer subsystem. This is the optional number of timers the user code needs.*/
344 #define EIPS_USER_MAX_NUM_TIMERS 150
345 #else
346 #define EIPS_USER_MIN_TICK_RES_IN_USEC 10000l /* 10ms min */
347 #define EIPS_USER_TICK_RES_IN_USECS (1000000L/CLOCKS_PER_SEC) /* us in 1 tick */
348 #define EIPS_USER_TICKS_PER_1SEC CLOCKS_PER_SEC /* ticks per second */
349 #define EIPS_USER_TICKS_PER_10SEC (10*EIPS_USER_TICKS_PER_1SEC)
350 #define EIPS_USER_TCP_INACTIVITY_TMO 0 /* (EIPS_USER_TICKS_PER_1SEC*20) */
351 
352 /* RTA depends on a timer subsystem. This is the optional number of timers the user code needs.*/
353 #define EIPS_USER_MAX_NUM_TIMERS 10
354 #endif
355 
356 /* we need a semaphore to ensure we don't print too fast */
357 #define EIPS_DEBUG 0 /* define this to 1 to enable debug printing */
358 #define EIPS_PRINTALL 1
359 /*
360  define EIPS_PRINTALL to the following...
361  > 0 show assembly configuration print at start up
362  > 1 show all TCP and UDP traffic
363 */
364 #if EIPS_DEBUG > 0
365  #define eips_user_dbprint0(f) printf(f)
366  #define eips_user_dbprint1(f,a1) printf(f,a1)
367  #define eips_user_dbprint2(f,a1,a2) printf(f,a1,a2)
368  #define eips_user_dbprint3(f,a1,a2,a3) printf(f,a1,a2,a3)
369  #define eips_user_dbprint4(f,a1,a2,a3,a4) printf(f,a1,a2,a3,a4)
370  #define eips_user_dbprint5(f,a1,a2,a3,a4,a5) printf(f,a1,a2,a3,a4,a5)
371  #define eips_user_dbprint6(f,a1,a2,a3,a4,a5,a6) printf(f,a1,a2,a3,a4,a5,a6)
372  #define eips_user_dbprint7(f,a1,a2,a3,a4,a5,a6,a7) printf(f,a1,a2,a3,a4,a5,a6,a7)
373 #else
374  #define eips_user_dbprint0(f)
375  #define eips_user_dbprint1(f,a1)
376  #define eips_user_dbprint2(f,a1,a2)
377  #define eips_user_dbprint3(f,a1,a2,a3)
378  #define eips_user_dbprint4(f,a1,a2,a3,a4)
379  #define eips_user_dbprint5(f,a1,a2,a3,a4,a5)
380  #define eips_user_dbprint6(f,a1,a2,a3,a4,a5,a6)
381 #endif
382 
383 /* debug print with the file and line number */
384 /* #define RTA_MARK_CODE_PATH(a) eips_user_dbprint3("%s %d: %s\r\n", __RTA_FILE__,__LINE__,a) */
385 #define RTA_MARK_CODE_PATH(a)
386 
387 /* #define RTA_MARK_TCPCODE_PATH(a) eips_user_dbprint3("%s %d: %s\r\n", __RTA_FILE__,__LINE__,a) */
388 #define RTA_MARK_TCPCODE_PATH(a)
389 #define RTA_TCP_CLOSE_WITH_PRINT(a) {RTA_MARK_TCPCODE_PATH("TCP CLOSE"); eips_usersock_tcpClose(a);}
390 
391 #define eips_error_dbprint(f,a1,a2,a3,a4) printf(f,a1,a2,a3,a4)
392 #define RTA_FATAL_ERROR_WITH_PRINT(a,b) eips_error_dbprint("EIPS - UNEXPECTED ERROR (%s %d) : %s %d\r\n", __RTA_FILE__,__LINE__,a,b)
393 
394 #endif /* __EIPS_USERSYS_H__ */