Staging: add epl stack
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / epl / EplInstDef.h
CommitLineData
9d7164cf
DK
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: definitions for generating instances
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: EplInstDef.h,v $
53
54 $Author: D.Krueger $
55
56 $Revision: 1.4 $ $Date: 2008/04/17 21:36:32 $
57
58 $State: Exp $
59
60 Build Environment:
61 ...
62
63 -------------------------------------------------------------------------
64
65 Revision History:
66
67 r.d.: first implementation
68
69****************************************************************************/
70
71#ifndef _EPLINSTDEF_H_
72#define _EPLINSTDEF_H_
73
74
75// =========================================================================
76// types and macros for generating instances
77// =========================================================================
78
79typedef enum
80{
81 kStateUnused = 0,
82 kStateDeleted = 1,
83 kStateUsed = 0xFF
84
85} tInstState;
86
87//------------------------------------------------------------------------------------------
88
89typedef void MEM* tEplPtrInstance;
90typedef BYTE tEplInstanceHdl;
91
92// define const for illegale values
93#define CCM_ILLINSTANCE NULL
94#define CCM_ILLINSTANCE_HDL 0xFF
95
96//------------------------------------------------------------------------------------------
97// if more than one instance then use this macros
98#if (EPL_MAX_INSTANCES > 1)
99
100 //--------------------------------------------------------------------------------------
101 // macro definition for instance table definition
102 //--------------------------------------------------------------------------------------
103
104 // memory attributes for instance table
105 #define INST_NEAR // faster access to variables
106 #define INST_FAR // variables wich have to located in xdata
107 #define STATIC // prevent warnings for variables with same name
108
109 #define INSTANCE_TYPE_BEGIN typedef struct {
110 #define INSTANCE_TYPE_END } tEplInstanceInfo;
111
112
113 //--------------------------------------------------------------------------------------
114 // macro definition for API interface
115 //--------------------------------------------------------------------------------------
116
117 // declaration:
118
119 // macros for declaration within function header or prototype of API functions
120 #define CCM_DECL_INSTANCE_HDL tEplInstanceHdl InstanceHandle
121 #define CCM_DECL_INSTANCE_HDL_ tEplInstanceHdl InstanceHandle,
122
123 // macros for declaration of pointer to instance handle within function header or prototype of API functions
124 #define CCM_DECL_PTR_INSTANCE_HDL tEplInstanceHdl MEM* pInstanceHandle
125 #define CCM_DECL_PTR_INSTANCE_HDL_ tEplInstanceHdl MEM* pInstanceHandle,
126
127 // macros for declaration instance as lokacl variable within functions
128 #define CCM_DECL_INSTANCE_PTR_LOCAL tCcmInstanceInfo MEM* pInstance;
129 #define CCM_DECL_PTR_INSTANCE_HDL_LOCAL tEplInstanceHdl MEM* pInstanceHandle;
130
131 // reference:
132
133 // macros for reference of instance handle for function parameters
134 #define CCM_INSTANCE_HDL InstanceHandle
135 #define CCM_INSTANCE_HDL_ InstanceHandle,
136
137 // macros for reference of instance parameter for function parameters
138 #define CCM_INSTANCE_PARAM(par) par
139 #define CCM_INSTANCE_PARAM_(par) par,
140
141 // macros for reference of instance parameter for writing or reading values
142 #define CCM_INST_ENTRY (*((tEplPtrInstance)pInstance))
143
144 // processing:
145
146 // macros for process instance handle
147 #define CCM_CHECK_INSTANCE_HDL() if (InstanceHandle >= EPL_MAX_INSTANCES) \
148 {return (kEplIllegalInstance);}
149
150
151 // macros for process pointer to instance handle
152 #define CCM_CHECK_PTR_INSTANCE_HDL() if (pInstanceHandle == NULL) \
153 {return (kEplInvalidInstanceParam);}
154
155 // This macro returned the handle and pointer to next free instance.
156 #define CCM_GET_FREE_INSTANCE_AND_HDL() pInstance = CcmGetFreeInstanceAndHandle (pInstanceHandle); \
157 ASSERT (*pInstanceHandle != CCM_ILLINSTANCE_HDL);
158
159 #define CCM_CHECK_INSTANCE_PTR() if (pInstance == CCM_ILLINSTANCE) \
160 {return (kEplNoFreeInstance);}
161
162 #define CCM_GET_INSTANCE_PTR() pInstance = CcmGetInstancePtr (InstanceHandle);
163 #define CCM_GET_FREE_INSTANCE_PTR() pInstance = GetFreeInstance (); \
164 ASSERT (pInstance != CCM_ILLINSTANCE);
165
166
167 //--------------------------------------------------------------------------------------
168 // macro definition for stack interface
169 //--------------------------------------------------------------------------------------
170
171 // macros for declaration within the function header, prototype or local var list
172 // Declaration of pointers within function paramater list must defined as void MEM*
173 // pointer.
174 #define EPL_MCO_DECL_INSTANCE_PTR void MEM* pInstance
175 #define EPL_MCO_DECL_INSTANCE_PTR_ void MEM* pInstance,
176 #define EPL_MCO_DECL_INSTANCE_PTR_LOCAL tEplPtrInstance pInstance;
177
178 // macros for reference of pointer to instance
179 // These macros are used for parameter passing to called function.
180 #define EPL_MCO_INSTANCE_PTR pInstance
181 #define EPL_MCO_INSTANCE_PTR_ pInstance,
182 #define EPL_MCO_ADDR_INSTANCE_PTR_ &pInstance,
183
184 // macro for access of struct members of one instance
185 // An access to a member of instance table must be casted by the local
186 // defined type of instance table.
187 #define EPL_MCO_INST_ENTRY (*(tEplPtrInstance)pInstance)
188 #define EPL_MCO_GLB_VAR(var) (((tEplPtrInstance)pInstance)->var)
189
190 // macros for process pointer to instance
191 #define EPL_MCO_GET_INSTANCE_PTR() pInstance = (tEplPtrInstance) GetInstancePtr (InstanceHandle);
192 #define EPL_MCO_GET_FREE_INSTANCE_PTR() pInstance = (tEplPtrInstance) GetFreeInstance (); \
193 ASSERT (pInstance != CCM_ILLINSTANCE);
194
195 // This macro should be used to check the passed pointer to an public function
196 #define EPL_MCO_CHECK_INSTANCE_STATE() ASSERT (pInstance != NULL); \
197 ASSERT (((tEplPtrInstance)pInstance)->m_InstState == kStateUsed);
198
199 // macros for declaration of pointer to instance pointer
200 #define EPL_MCO_DECL_PTR_INSTANCE_PTR void MEM* MEM* pInstancePtr
201 #define EPL_MCO_DECL_PTR_INSTANCE_PTR_ void MEM* MEM* pInstancePtr,
202
203 // macros for reference of pointer to instance pointer
204 // These macros are used for parameter passing to called function.
205 #define EPL_MCO_PTR_INSTANCE_PTR pInstancePtr
206 #define EPL_MCO_PTR_INSTANCE_PTR_ pInstancePtr,
207
208 // macros for process pointer to instance pointer
209 #define EPL_MCO_CHECK_PTR_INSTANCE_PTR() ASSERT (pInstancePtr != NULL);
210 #define EPL_MCO_SET_PTR_INSTANCE_PTR() (*pInstancePtr = pInstance);
211
212 #define EPL_MCO_INSTANCE_PARAM(a) (a)
213 #define EPL_MCO_INSTANCE_PARAM_(a) (a),
214 #define EPL_MCO_INSTANCE_PARAM_IDX_() EPL_MCO_INSTANCE_PARAM_ (EPL_MCO_GLB_VAR (m_bInstIndex))
215 #define EPL_MCO_INSTANCE_PARAM_IDX() EPL_MCO_INSTANCE_PARAM (EPL_MCO_GLB_VAR (m_bInstIndex))
216 #define EPL_MCO_WRITE_INSTANCE_STATE(a) EPL_MCO_GLB_VAR (m_InstState) = a;
217
218 // this macro deletes all instance entries as unused
219 #define EPL_MCO_DELETE_INSTANCE_TABLE() \
220 { \
221 tEplInstanceInfo MEM* pInstance = &aEplInstanceTable_g[0]; \
222 tFastByte InstNumber = 0; \
223 tFastByte i = EPL_MAX_INSTANCES; \
224 do { \
225 pInstance->m_InstState = (BYTE) kStateUnused; \
226 pInstance->m_bInstIndex = (BYTE) InstNumber; \
227 pInstance++; InstNumber++; i--; \
228 } while (i != 0); \
229 }
230
231 // definition of functions which has to be defined in each module of CANopen stack
232 #define EPL_MCO_DEFINE_INSTANCE_FCT() \
233 static tEplPtrInstance GetInstancePtr (tEplInstanceHdl InstHandle_p); \
234 static tEplPtrInstance GetFreeInstance (void);
235 #define EPL_MCO_DECL_INSTANCE_FCT() \
236 static tEplPtrInstance GetInstancePtr (tEplInstanceHdl InstHandle_p) { \
237 return &aEplInstanceTable_g[InstHandle_p]; } \
238 static tEplPtrInstance GetFreeInstance (void) { \
239 tEplInstanceInfo MEM* pInstance = &aEplInstanceTable_g[0]; \
240 tFastByte i = EPL_MAX_INSTANCES; \
241 do { if (pInstance->m_InstState != kStateUsed) { \
242 return (tEplPtrInstance) pInstance; } \
243 pInstance++; i--; } \
244 while (i != 0); \
245 return CCM_ILLINSTANCE; }
246
247 // this macro defines the instance table. Each entry is reserved for an instance of CANopen.
248 #define EPL_MCO_DECL_INSTANCE_VAR() \
249 static tEplInstanceInfo MEM aEplInstanceTable_g [EPL_MAX_INSTANCES];
250
251 // this macro defines member variables in instance table which are needed in
252 // all modules of Epl stack
253 #define EPL_MCO_DECL_INSTANCE_MEMBER() \
254 STATIC BYTE m_InstState; \
255 STATIC BYTE m_bInstIndex;
256
257 #define EPL_MCO_INSTANCE_PARAM_IDX_() EPL_MCO_INSTANCE_PARAM_ (EPL_MCO_GLB_VAR (m_bInstIndex))
258 #define EPL_MCO_INSTANCE_PARAM_IDX() EPL_MCO_INSTANCE_PARAM (EPL_MCO_GLB_VAR (m_bInstIndex))
259
260#else // only one instance is used
261
262 // Memory attributes for instance table.
263 #define INST_NEAR NEAR // faster access to variables
264 #define INST_FAR MEM // variables wich have to located in xdata
265 #define STATIC static // prevent warnings for variables with same name
266
267 #define INSTANCE_TYPE_BEGIN
268 #define INSTANCE_TYPE_END
269
270// macros for declaration, initializing and member access for instance handle
271// This class of macros are used by API function to inform CCM-modul which
272// instance is to be used.
273
274 // macros for reference of instance handle
275 // These macros are used for parameter passing to CANopen API function.
276 #define CCM_INSTANCE_HDL
277 #define CCM_INSTANCE_HDL_
278
279 #define CCM_DECL_INSTANCE_PTR_LOCAL
280
281 // macros for declaration within the function header or prototype
282 #define CCM_DECL_INSTANCE_HDL void
283 #define CCM_DECL_INSTANCE_HDL_
284
285 // macros for process instance handle
286 #define CCM_CHECK_INSTANCE_HDL()
287
288 // macros for declaration of pointer to instance handle
289 #define CCM_DECL_PTR_INSTANCE_HDL void
290 #define CCM_DECL_PTR_INSTANCE_HDL_
291
292 // macros for process pointer to instance handle
293 #define CCM_CHECK_PTR_INSTANCE_HDL()
294
295 // This macro returned the handle and pointer to next free instance.
296 #define CCM_GET_FREE_INSTANCE_AND_HDL()
297
298 #define CCM_CHECK_INSTANCE_PTR()
299
300 #define CCM_GET_INSTANCE_PTR()
301 #define CCM_GET_FREE_INSTANCE_PTR()
302
303 #define CCM_INSTANCE_PARAM(par)
304 #define CCM_INSTANCE_PARAM_(par)
305
306 #define CCM_INST_ENTRY aCcmInstanceTable_g[0]
307
308// macros for declaration, initializing and member access for instance pointer
309// This class of macros are used by CANopen internal function to point to one instance.
310
311 // macros for declaration within the function header, prototype or local var list
312 #define EPL_MCO_DECL_INSTANCE_PTR void
313 #define EPL_MCO_DECL_INSTANCE_PTR_
314 #define EPL_MCO_DECL_INSTANCE_PTR_LOCAL
315
316 // macros for reference of pointer to instance
317 // These macros are used for parameter passing to called function.
318 #define EPL_MCO_INSTANCE_PTR
319 #define EPL_MCO_INSTANCE_PTR_
320 #define EPL_MCO_ADDR_INSTANCE_PTR_
321
322 // macros for process pointer to instance
323 #define EPL_MCO_GET_INSTANCE_PTR()
324 #define EPL_MCO_GET_FREE_INSTANCE_PTR()
325
326 // This macro should be used to check the passed pointer to an public function
327 #define EPL_MCO_CHECK_INSTANCE_STATE()
328
329 // macros for declaration of pointer to instance pointer
330 #define EPL_MCO_DECL_PTR_INSTANCE_PTR void
331 #define EPL_MCO_DECL_PTR_INSTANCE_PTR_
332
333 // macros for reference of pointer to instance pointer
334 // These macros are used for parameter passing to called function.
335 #define EPL_MCO_PTR_INSTANCE_PTR
336 #define EPL_MCO_PTR_INSTANCE_PTR_
337
338 // macros for process pointer to instance pointer
339 #define EPL_MCO_CHECK_PTR_INSTANCE_PTR()
340 #define EPL_MCO_SET_PTR_INSTANCE_PTR()
341
342 #define EPL_MCO_INSTANCE_PARAM(a)
343 #define EPL_MCO_INSTANCE_PARAM_(a)
344 #define EPL_MCO_INSTANCE_PARAM_IDX_()
345 #define EPL_MCO_INSTANCE_PARAM_IDX()
346
347 // macro for access of struct members of one instance
348 #define EPL_MCO_INST_ENTRY aEplInstanceTable_g[0]
349 #define EPL_MCO_GLB_VAR(var) (var)
350 #define EPL_MCO_WRITE_INSTANCE_STATE(a)
351
352 // this macro deletes all instance entries as unused
353 #define EPL_MCO_DELETE_INSTANCE_TABLE()
354
355 // definition of functions which has to be defined in each module of CANopen stack
356 #define EPL_MCO_DEFINE_INSTANCE_FCT()
357 #define EPL_MCO_DECL_INSTANCE_FCT()
358
359 // this macro defines the instance table. Each entry is reserved for an instance of CANopen.
360 #define EPL_MCO_DECL_INSTANCE_VAR()
361
362 // this macro defines member variables in instance table which are needed in
363 // all modules of CANopen stack
364 #define EPL_MCO_DECL_INSTANCE_MEMBER()
365
366#endif
367
368
369/*
370#if (CDRV_MAX_INSTANCES > 1)
371
372 #define CDRV_REENTRANT REENTRANT
373
374#else
375
376 #define CDRV_REENTRANT
377
378#endif
379*/
380
381
382#endif // _EPLINSTDEF_H_
383
384