Staging: add epl stack
[firefly-linux-kernel-4.4.55.git] / drivers / staging / epl / EplObd.h
1 /****************************************************************************
2
3   (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4       www.systec-electronic.com
5
6   Project:      openPOWERLINK
7
8   Description:  include file for api function of EplOBD-Module
9
10   License:
11
12     Redistribution and use in source and binary forms, with or without
13     modification, are permitted provided that the following conditions
14     are met:
15
16     1. Redistributions of source code must retain the above copyright
17        notice, this list of conditions and the following disclaimer.
18
19     2. Redistributions in binary form must reproduce the above copyright
20        notice, this list of conditions and the following disclaimer in the
21        documentation and/or other materials provided with the distribution.
22
23     3. Neither the name of SYSTEC electronic GmbH nor the names of its
24        contributors may be used to endorse or promote products derived
25        from this software without prior written permission. For written
26        permission, please contact info@systec-electronic.com.
27
28     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32     COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39     POSSIBILITY OF SUCH DAMAGE.
40
41     Severability Clause:
42
43         If a provision of this License is or becomes illegal, invalid or
44         unenforceable in any jurisdiction, that shall not affect:
45         1. the validity or enforceability in that jurisdiction of any other
46            provision of this License; or
47         2. the validity or enforceability in other jurisdictions of that or
48            any other provision of this License.
49
50   -------------------------------------------------------------------------
51
52                 $RCSfile: EplObd.h,v $
53
54                 $Author: D.Krueger $
55
56                 $Revision: 1.5 $  $Date: 2008/04/17 21:36:32 $
57
58                 $State: Exp $
59
60                 Build Environment:
61                 Microsoft VC7
62
63   -------------------------------------------------------------------------
64
65   Revision History:
66
67   2006/06/02 k.t.:   start of the implementation, version 1.00
68
69
70 ****************************************************************************/
71
72 #include "EplInc.h"
73
74 #ifndef _EPLOBD_H_
75 #define _EPLOBD_H_
76
77
78 // ============================================================================
79 // defines
80 // ============================================================================
81
82 #define EPL_OBD_TABLE_INDEX_END     0xFFFF
83
84 // for the usage of BOOLEAN in OD
85 #define OBD_TRUE    0x01
86 #define OBD_FALSE   0x00
87
88 // default OD index for Node id
89 #define EPL_OBD_NODE_ID_INDEX               0x1F93
90 // default subindex for NodeId in OD
91 #define EPL_OBD_NODE_ID_SUBINDEX            0x01
92 // default subindex for NodeIDByHW_BOOL
93 #define EPL_OBD_NODE_ID_HWBOOL_SUBINDEX     0x02
94
95 // ============================================================================
96 // enums
97 // ============================================================================
98
99 // directions for access to object dictionary
100 typedef enum
101 {
102     kEplObdDirInit         = 0x00,    // initialising after power on
103     kEplObdDirStore        = 0x01,    // store all object values to non volatile memory
104     kEplObdDirLoad         = 0x02,    // load all object values from non volatile memory
105     kEplObdDirRestore      = 0x03,    // deletes non volatile memory (restore)
106     kEplObdDirOBKCheck     = 0xFF     // reserved
107
108 }tEplObdDir;
109
110 // commands for store
111 typedef enum
112 {
113     kEplObdCommNothing     = 0x00,
114     kEplObdCommOpenWrite   = 0x01,
115     kEplObdCommWriteObj    = 0x02,
116     kEplObdCommCloseWrite  = 0x03,
117     kEplObdCommOpenRead    = 0x04,
118     kEplObdCommReadObj     = 0x05,
119     kEplObdCommCloseRead   = 0x06,
120     kEplObdCommClear       = 0x07,
121     kEplObdCommUnknown     = 0xFF
122 }tEplObdCommand;
123
124 //-----------------------------------------------------------------------------------------------------------
125 // events of object callback function
126 typedef enum
127 {
128 //                                                                                                      m_pArg points to
129 //                                                                                                    ---------------------
130     kEplObdEvCheckExist            = 0x06,    // checking if object does exist (reading and writing)    NULL
131     kEplObdEvPreRead               = 0x00,    // before reading an object                               source data buffer in OD
132     kEplObdEvPostRead              = 0x01,    // after reading an object                                destination data buffer from caller
133     kEplObdEvWrStringDomain        = 0x07,    // event for changing string/domain data pointer or size  struct tEplObdVStringDomain in RAM
134     kEplObdEvInitWrite             = 0x04,    // initializes writing an object (checking object size)   size of object in OD (tEplObdSize)
135     kEplObdEvPreWrite              = 0x02,    // before writing an object                               source data buffer from caller
136     kEplObdEvPostWrite             = 0x03,    // after writing an object                                destination data buffer in OD
137 //    kEplObdEvAbortSdo              = 0x05     // after an abort of an SDO transfer
138
139 } tEplObdEvent;
140
141 // part of OD (bit oriented)
142 typedef unsigned int tEplObdPart;
143
144 #define kEplObdPartNo          0x00    // nothing
145 #define kEplObdPartGen         0x01    //  part      (0x1000 - 0x1FFF)
146 #define kEplObdPartMan         0x02    // manufacturer part (0x2000 - 0x5FFF)
147 #define kEplObdPartDev         0x04    // device part       (0x6000 - 0x9FFF)
148 #define kEplObdPartUsr         0x08    // dynamic part e.g. for ICE61131-3
149
150 // combinations
151 #define kEplObdPartApp         (              kEplObdPartMan | kEplObdPartDev | kEplObdPartUsr)   // manufacturer and device part (0x2000 - 0x9FFF) and user OD
152 #define kEplObdPartAll         (kEplObdPartGen | kEplObdPartMan | kEplObdPartDev | kEplObdPartUsr)   // whole OD
153
154 //-----------------------------------------------------------------------------------------------------------
155 // access types for objects
156 // must be a difine because bit-flags
157 typedef unsigned int tEplObdAccess;
158
159 #define kEplObdAccRead         0x01    // object can be read
160 #define kEplObdAccWrite        0x02    // object can be written
161 #define kEplObdAccConst        0x04    // object contains a constant value
162 #define kEplObdAccPdo          0x08    // object can be mapped in a PDO
163 #define kEplObdAccArray        0x10    // object contains an array of numerical values
164 #define kEplObdAccRange        0x20    // object contains lower and upper limit
165 #define kEplObdAccVar          0x40    // object data is placed in application
166 #define kEplObdAccStore        0x80    // object data can be stored to non volatile memory
167
168 // combinations (not all combinations are required)
169 #define kEplObdAccR            (0            | 0          | 0            | 0          | 0            | 0            | kEplObdAccRead)
170 #define kEplObdAccW            (0            | 0          | 0            | 0          | 0            | kEplObdAccWrite | 0          )
171 #define kEplObdAccRW           (0            | 0          | 0            | 0          | 0            | kEplObdAccWrite | kEplObdAccRead)
172 #define kEplObdAccCR           (0            | 0          | 0            | 0          | kEplObdAccConst | 0            | kEplObdAccRead)
173 #define kEplObdAccGR           (0            | 0          | kEplObdAccRange | 0          | 0            | 0            | kEplObdAccRead)
174 #define kEplObdAccGW           (0            | 0          | kEplObdAccRange | 0          | 0            | kEplObdAccWrite | 0          )
175 #define kEplObdAccGRW          (0            | 0          | kEplObdAccRange | 0          | 0            | kEplObdAccWrite | kEplObdAccRead)
176 #define kEplObdAccVR           (0            | kEplObdAccVar | 0            | 0          | 0            | 0            | kEplObdAccRead)
177 #define kEplObdAccVW           (0            | kEplObdAccVar | 0            | 0          | 0            | kEplObdAccWrite | 0          )
178 #define kEplObdAccVRW          (0            | kEplObdAccVar | 0            | 0          | 0            | kEplObdAccWrite | kEplObdAccRead)
179 #define kEplObdAccVPR          (0            | kEplObdAccVar | 0            | kEplObdAccPdo | 0            | 0            | kEplObdAccRead)
180 #define kEplObdAccVPW          (0            | kEplObdAccVar | 0            | kEplObdAccPdo | 0            | kEplObdAccWrite | 0          )
181 #define kEplObdAccVPRW         (0            | kEplObdAccVar | 0            | kEplObdAccPdo | 0            | kEplObdAccWrite | kEplObdAccRead)
182 #define kEplObdAccVGR          (0            | kEplObdAccVar | kEplObdAccRange | 0          | 0            | 0            | kEplObdAccRead)
183 #define kEplObdAccVGW          (0            | kEplObdAccVar | kEplObdAccRange | 0          | 0            | kEplObdAccWrite | 0          )
184 #define kEplObdAccVGRW         (0            | kEplObdAccVar | kEplObdAccRange | 0          | 0            | kEplObdAccWrite | kEplObdAccRead)
185 #define kEplObdAccVGPR         (0            | kEplObdAccVar | kEplObdAccRange | kEplObdAccPdo | 0            | 0            | kEplObdAccRead)
186 #define kEplObdAccVGPW         (0            | kEplObdAccVar | kEplObdAccRange | kEplObdAccPdo | 0            | kEplObdAccWrite | 0          )
187 #define kEplObdAccVGPRW        (0            | kEplObdAccVar | kEplObdAccRange | kEplObdAccPdo | 0            | kEplObdAccWrite | kEplObdAccRead)
188 #define kEplObdAccSR           (kEplObdAccStore | 0          | 0            | 0          | 0            | 0            | kEplObdAccRead)
189 #define kEplObdAccSW           (kEplObdAccStore | 0          | 0            | 0          | 0            | kEplObdAccWrite | 0          )
190 #define kEplObdAccSRW          (kEplObdAccStore | 0          | 0            | 0          | 0            | kEplObdAccWrite | kEplObdAccRead)
191 #define kEplObdAccSCR          (kEplObdAccStore | 0          | 0            | 0          | kEplObdAccConst | 0            | kEplObdAccRead)
192 #define kEplObdAccSGR          (kEplObdAccStore | 0          | kEplObdAccRange | 0          | 0            | 0            | kEplObdAccRead)
193 #define kEplObdAccSGW          (kEplObdAccStore | 0          | kEplObdAccRange | 0          | 0            | kEplObdAccWrite | 0          )
194 #define kEplObdAccSGRW         (kEplObdAccStore | 0          | kEplObdAccRange | 0          | 0            | kEplObdAccWrite | kEplObdAccRead)
195 #define kEplObdAccSVR          (kEplObdAccStore | kEplObdAccVar | 0            | 0          | 0            | 0            | kEplObdAccRead)
196 #define kEplObdAccSVW          (kEplObdAccStore | kEplObdAccVar | 0            | 0          | 0            | kEplObdAccWrite | 0          )
197 #define kEplObdAccSVRW         (kEplObdAccStore | kEplObdAccVar | 0            | 0          | 0            | kEplObdAccWrite | kEplObdAccRead)
198 #define kEplObdAccSVPR         (kEplObdAccStore | kEplObdAccVar | 0            | kEplObdAccPdo | 0            | 0            | kEplObdAccRead)
199 #define kEplObdAccSVPW         (kEplObdAccStore | kEplObdAccVar | 0            | kEplObdAccPdo | 0            | kEplObdAccWrite | 0          )
200 #define kEplObdAccSVPRW        (kEplObdAccStore | kEplObdAccVar | 0            | kEplObdAccPdo | 0            | kEplObdAccWrite | kEplObdAccRead)
201 #define kEplObdAccSVGR         (kEplObdAccStore | kEplObdAccVar | kEplObdAccRange | 0          | 0            | 0            | kEplObdAccRead)
202 #define kEplObdAccSVGW         (kEplObdAccStore | kEplObdAccVar | kEplObdAccRange | 0          | 0            | kEplObdAccWrite | 0          )
203 #define kEplObdAccSVGRW        (kEplObdAccStore | kEplObdAccVar | kEplObdAccRange | 0          | 0            | kEplObdAccWrite | kEplObdAccRead)
204 #define kEplObdAccSVGPR        (kEplObdAccStore | kEplObdAccVar | kEplObdAccRange | kEplObdAccPdo | 0            | 0            | kEplObdAccRead)
205 #define kEplObdAccSVGPW        (kEplObdAccStore | kEplObdAccVar | kEplObdAccRange | kEplObdAccPdo | 0            | kEplObdAccWrite | 0          )
206 #define kEplObdAccSVGPRW       (kEplObdAccStore | kEplObdAccVar | kEplObdAccRange | kEplObdAccPdo | 0            | kEplObdAccWrite | kEplObdAccRead)
207
208
209
210 typedef unsigned int tEplObdSize; // For all objects as objects size are used an unsigned int.
211
212
213 // -------------------------------------------------------------------------
214 // types for data types defined in DS301
215 // -------------------------------------------------------------------------
216
217 // types of objects in object dictionary
218 // DS-301 defines these types as WORD
219 typedef enum
220 {
221 // types which are always supported
222     kEplObdTypBool         = 0x0001,
223
224     kEplObdTypInt8         = 0x0002,
225     kEplObdTypInt16        = 0x0003,
226     kEplObdTypInt32        = 0x0004,
227     kEplObdTypUInt8        = 0x0005,
228     kEplObdTypUInt16       = 0x0006,
229     kEplObdTypUInt32       = 0x0007,
230     kEplObdTypReal32       = 0x0008,
231     kEplObdTypVString      = 0x0009,
232     kEplObdTypOString      = 0x000A,
233     kEplObdTypDomain       = 0x000F,
234
235     kEplObdTypInt24        = 0x0010,
236     kEplObdTypUInt24       = 0x0016,
237
238     kEplObdTypReal64       = 0x0011,
239     kEplObdTypInt40        = 0x0012,
240     kEplObdTypInt48        = 0x0013,
241     kEplObdTypInt56        = 0x0014,
242     kEplObdTypInt64        = 0x0015,
243     kEplObdTypUInt40       = 0x0018,
244     kEplObdTypUInt48       = 0x0019,
245     kEplObdTypUInt56       = 0x001A,
246     kEplObdTypUInt64       = 0x001B,
247     kEplObdTypTimeOfDay    = 0x000C,
248     kEplObdTypTimeDiff     = 0x000D
249
250 }tEplObdType;
251 // other types are not supported in this version
252
253
254 // -------------------------------------------------------------------------
255 // types for data types defined in DS301
256 // -------------------------------------------------------------------------
257
258 typedef unsigned char       tEplObdBoolean;      // 0001
259 typedef signed char         tEplObdInteger8;     // 0002
260 typedef signed short int    tEplObdInteger16;    // 0003
261 typedef signed long         tEplObdInteger32;    // 0004
262 typedef unsigned char       tEplObdUnsigned8;    // 0005
263 typedef unsigned short int  tEplObdUnsigned16;   // 0006
264 typedef unsigned long       tEplObdUnsigned32;   // 0007
265 typedef float               tEplObdReal32;       // 0008
266 typedef unsigned char       tEplObdDomain;       // 000F
267 typedef signed   long       tEplObdInteger24;    // 0010
268 typedef unsigned long       tEplObdUnsigned24;   // 0016
269
270 typedef signed QWORD        tEplObdInteger40;    // 0012
271 typedef signed QWORD        tEplObdInteger48;    // 0013
272 typedef signed QWORD        tEplObdInteger56;    // 0014
273 typedef signed QWORD        tEplObdInteger64;    // 0015
274
275 typedef unsigned QWORD      tEplObdUnsigned40;   // 0018
276 typedef unsigned QWORD      tEplObdUnsigned48;   // 0019
277 typedef unsigned QWORD      tEplObdUnsigned56;   // 001A
278 typedef unsigned QWORD      tEplObdUnsigned64;   // 001B
279
280 typedef double              tEplObdReal64;       // 0011
281
282 typedef tTimeOfDay          tEplObdTimeOfDay;         // 000C
283 typedef tTimeOfDay          tEplObdTimeDifference;    // 000D
284
285
286 // -------------------------------------------------------------------------
287 // structur for defining a variable
288 // -------------------------------------------------------------------------
289 // -------------------------------------------------------------------------
290 typedef enum
291 {
292     kVarValidSize           = 0x01,
293     kVarValidData           = 0x02,
294 //    kVarValidCallback       = 0x04,
295 //    kVarValidArg            = 0x08,
296
297     kVarValidAll            = 0x03  // currently only size and data are implemented and used
298
299 }tEplVarParamValid;
300
301
302 typedef tEplKernel (PUBLIC ROM* tEplVarCallback) (CCM_DECL_INSTANCE_HDL_
303     void * pParam_p);
304
305 typedef struct
306 {
307     tEplVarParamValid   m_ValidFlag;
308     unsigned int        m_uiIndex;
309     unsigned int        m_uiSubindex;
310     tEplObdSize         m_Size;
311     void MEM*           m_pData;
312 //    tEplVarCallback     m_fpCallback;
313 //    void *       m_pArg;
314
315 } tEplVarParam;
316
317 typedef struct
318 {
319     void MEM*           m_pData;
320     tEplObdSize            m_Size;
321 /*
322     #if (EPL_PDO_USE_STATIC_MAPPING == FALSE)
323         tEplVarCallback    m_fpCallback;
324         void *   m_pArg;
325     #endif
326 */
327 } tEplObdVarEntry;
328
329 typedef struct
330 {
331    tEplObdSize      m_Size;
332    BYTE *           m_pString;
333
334 } tEplObdOString;                          // 000C
335
336 typedef struct
337 {
338    tEplObdSize      m_Size;
339    char *           m_pString;
340 } tEplObdVString;                          // 000D
341
342
343 typedef struct
344 {
345     tEplObdSize      m_Size;
346     char *    m_pDefString;         // $$$ d.k. it is unused, so we could delete it
347     char *    m_pString;
348
349 } tEplObdVStringDef;
350
351 typedef struct
352 {
353    tEplObdSize      m_Size;
354    BYTE *           m_pDefString;   // $$$ d.k. it is unused, so we could delete it
355    BYTE *           m_pString;
356
357 } tEplObdOStringDef;
358
359 //r.d. parameter struct for changing object size and/or pointer to data of Strings or Domains
360 typedef struct
361 {
362    tEplObdSize      m_DownloadSize;     // download size from SDO or APP
363    tEplObdSize      m_ObjSize;          // current object size from OD - should be changed from callback function
364    void *    m_pData;            // current object ptr  from OD - should be changed from callback function
365
366 } tEplObdVStringDomain;                          // 000D
367
368
369 // ============================================================================
370 // types
371 // ============================================================================
372 // -------------------------------------------------------------------------
373 // subindexstruct
374 // -------------------------------------------------------------------------
375
376 // Change not the order for this struct!!!
377 typedef struct
378 {
379     unsigned int    m_uiSubIndex;
380     tEplObdType     m_Type;
381     tEplObdAccess   m_Access;
382     void  *  m_pDefault;
383     void  MEM*      m_pCurrent;     // points always to RAM
384
385 } tEplObdSubEntry;
386
387 // r.d.: has always to be  because new OBD-Macros for arrays
388 typedef tEplObdSubEntry * tEplObdSubEntryPtr;
389
390 // -------------------------------------------------------------------------
391 // callback function for objdictionary modul
392 // -------------------------------------------------------------------------
393
394 // parameters for callback function
395 typedef struct
396 {
397     tEplObdEvent    m_ObdEvent;
398     unsigned int    m_uiIndex;
399     unsigned int    m_uiSubIndex;
400     void *   m_pArg;
401     DWORD           m_dwAbortCode;
402
403 } tEplObdCbParam;
404
405 // define type for callback function: pParam_p points to tEplObdCbParam
406 typedef tEplKernel (PUBLIC ROM* tEplObdCallback) (CCM_DECL_INSTANCE_HDL_
407     tEplObdCbParam MEM* pParam_p);
408
409 // do not change the order for this struct!!!
410
411 typedef struct
412 {
413     unsigned int        m_uiIndex;
414     tEplObdSubEntryPtr  m_pSubIndex;
415     unsigned int        m_uiCount;
416     tEplObdCallback     m_fpCallback;   // function is called back if object access
417
418 } tEplObdEntry;
419
420
421 // allways  pointer
422 typedef tEplObdEntry * tEplObdEntryPtr;
423
424
425
426 // -------------------------------------------------------------------------
427 // structur to initialize OBD module
428 // -------------------------------------------------------------------------
429
430 typedef struct
431 {
432     tEplObdEntryPtr        m_pPart;
433     tEplObdEntryPtr        m_pManufacturerPart;
434     tEplObdEntryPtr        m_pDevicePart;
435
436     #if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
437
438           tEplObdEntryPtr  m_pUserPart;
439
440     #endif
441
442 } tEplObdInitParam;
443
444
445 // -------------------------------------------------------------------------
446 // structur for parameters of STORE RESTORE command
447 // -------------------------------------------------------------------------
448
449 typedef struct
450 {
451     tEplObdCommand  m_bCommand;
452     tEplObdPart        m_bCurrentOdPart;
453     void MEM*       m_pData;
454     tEplObdSize     m_ObjSize;
455
456 } tEplObdCbStoreParam;
457
458
459 typedef tEplKernel (PUBLIC ROM* tInitTabEntryCallback) (
460     void MEM* pTabEntry_p,
461     unsigned int uiObjIndex_p);
462
463 typedef tEplKernel (PUBLIC ROM* tEplObdStoreLoadObjCallback) (CCM_DECL_INSTANCE_HDL_
464     tEplObdCbStoreParam MEM* pCbStoreParam_p);
465
466 // -------------------------------------------------------------------------
467 // this stucture is used for parameters for function ObdInitModuleTab()
468 // -------------------------------------------------------------------------
469 typedef struct
470 {
471     unsigned int            m_uiLowerObjIndex;  // lower limit of ObjIndex
472     unsigned int            m_uiUpperObjIndex;  // upper limit of ObjIndex
473     tInitTabEntryCallback   m_fpInitTabEntry;   // will be called if ObjIndex was found
474     void MEM*               m_pTabBase;         // base address of table
475     unsigned int            m_uiEntrySize;      // size of table entry      // 25-feb-2005 r.d.: expansion from BYTE to WORD necessary for PDO bit mapping
476     unsigned int            m_uiMaxEntries;     // max. tabel entries
477
478 } tEplObdModulTabParam;
479
480 //-------------------------------------------------------------------
481 //  enum for function EplObdSetNodeId
482 //-------------------------------------------------------------------
483 typedef enum
484 {
485     kEplObdNodeIdUnknown    =   0x00,   // unknown how the node id was set
486     kEplObdNodeIdSoftware   =   0x01,   // node id set by software
487     kEplObdNodeIdHardware   =   0x02    // node id set by hardware
488
489 }tEplObdNodeIdType;
490
491 // ============================================================================
492 // global variables
493 // ============================================================================
494
495
496
497 // ============================================================================
498 // public functions
499 // ============================================================================
500
501
502 #endif  // #ifndef _EPLOBD_H_
503
504