Staging: epl: remove REENTRANT
[linux-2.6/mini2440.git] / drivers / staging / epl / EplInstDef.h
blob756ac635324a2a25e2dc8ca25a0c11ed36dd1c33
1 /****************************************************************************
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
6 Project: openPOWERLINK
8 Description: definitions for generating instances
10 License:
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
14 are met:
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
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.
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.
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.
41 Severability Clause:
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.
50 -------------------------------------------------------------------------
52 $RCSfile: EplInstDef.h,v $
54 $Author: D.Krueger $
56 $Revision: 1.4 $ $Date: 2008/04/17 21:36:32 $
58 $State: Exp $
60 Build Environment:
61 ...
63 -------------------------------------------------------------------------
65 Revision History:
67 r.d.: first implementation
69 ****************************************************************************/
71 #ifndef _EPLINSTDEF_H_
72 #define _EPLINSTDEF_H_
74 // =========================================================================
75 // types and macros for generating instances
76 // =========================================================================
78 typedef enum {
79 kStateUnused = 0,
80 kStateDeleted = 1,
81 kStateUsed = 0xFF
82 } tInstState;
84 //------------------------------------------------------------------------------------------
86 typedef void *tEplPtrInstance;
87 typedef BYTE tEplInstanceHdl;
89 // define const for illegale values
90 #define CCM_ILLINSTANCE NULL
91 #define CCM_ILLINSTANCE_HDL 0xFF
93 //------------------------------------------------------------------------------------------
94 // if more than one instance then use this macros
95 #if (EPL_MAX_INSTANCES > 1)
97 //--------------------------------------------------------------------------------------
98 // macro definition for instance table definition
99 //--------------------------------------------------------------------------------------
101 // memory attributes for instance table
102 #define STATIC // prevent warnings for variables with same name
104 #define INSTANCE_TYPE_BEGIN typedef struct {
105 #define INSTANCE_TYPE_END } tEplInstanceInfo;
107 //--------------------------------------------------------------------------------------
108 // macro definition for API interface
109 //--------------------------------------------------------------------------------------
111 // declaration:
113 // macros for declaration within function header or prototype of API functions
114 #define CCM_DECL_INSTANCE_HDL tEplInstanceHdl InstanceHandle
115 #define CCM_DECL_INSTANCE_HDL_ tEplInstanceHdl InstanceHandle,
117 // macros for declaration of pointer to instance handle within function header or prototype of API functions
118 #define CCM_DECL_PTR_INSTANCE_HDL tEplInstanceHdl *pInstanceHandle
119 #define CCM_DECL_PTR_INSTANCE_HDL_ tEplInstanceHdl *pInstanceHandle,
121 // macros for declaration instance as lokacl variable within functions
122 #define CCM_DECL_INSTANCE_PTR_LOCAL tCcmInstanceInfo *pInstance;
123 #define CCM_DECL_PTR_INSTANCE_HDL_LOCAL tEplInstanceHdl *pInstanceHandle;
125 // reference:
127 // macros for reference of instance handle for function parameters
128 #define CCM_INSTANCE_HDL InstanceHandle
129 #define CCM_INSTANCE_HDL_ InstanceHandle,
131 // macros for reference of instance parameter for function parameters
132 #define CCM_INSTANCE_PARAM(par) par
133 #define CCM_INSTANCE_PARAM_(par) par,
135 // macros for reference of instance parameter for writing or reading values
136 #define CCM_INST_ENTRY (*((tEplPtrInstance)pInstance))
138 // processing:
140 // macros for process instance handle
141 #define CCM_CHECK_INSTANCE_HDL() if (InstanceHandle >= EPL_MAX_INSTANCES) \
142 {return (kEplIllegalInstance);}
144 // macros for process pointer to instance handle
145 #define CCM_CHECK_PTR_INSTANCE_HDL() if (pInstanceHandle == NULL) \
146 {return (kEplInvalidInstanceParam);}
148 // This macro returned the handle and pointer to next free instance.
149 #define CCM_GET_FREE_INSTANCE_AND_HDL() pInstance = CcmGetFreeInstanceAndHandle (pInstanceHandle); \
150 ASSERT (*pInstanceHandle != CCM_ILLINSTANCE_HDL);
152 #define CCM_CHECK_INSTANCE_PTR() if (pInstance == CCM_ILLINSTANCE) \
153 {return (kEplNoFreeInstance);}
155 #define CCM_GET_INSTANCE_PTR() pInstance = CcmGetInstancePtr (InstanceHandle);
156 #define CCM_GET_FREE_INSTANCE_PTR() pInstance = GetFreeInstance (); \
157 ASSERT (pInstance != CCM_ILLINSTANCE);
159 //--------------------------------------------------------------------------------------
160 // macro definition for stack interface
161 //--------------------------------------------------------------------------------------
163 // macros for declaration within the function header, prototype or local var list
164 // Declaration of pointers within function paramater list must defined as void *
165 // pointer.
166 #define EPL_MCO_DECL_INSTANCE_PTR void *pInstance
167 #define EPL_MCO_DECL_INSTANCE_PTR_ void *pInstance,
168 #define EPL_MCO_DECL_INSTANCE_PTR_LOCAL tEplPtrInstance pInstance;
170 // macros for reference of pointer to instance
171 // These macros are used for parameter passing to called function.
172 #define EPL_MCO_INSTANCE_PTR pInstance
173 #define EPL_MCO_INSTANCE_PTR_ pInstance,
174 #define EPL_MCO_ADDR_INSTANCE_PTR_ &pInstance,
176 // macro for access of struct members of one instance
177 // An access to a member of instance table must be casted by the local
178 // defined type of instance table.
179 #define EPL_MCO_INST_ENTRY (*(tEplPtrInstance)pInstance)
180 #define EPL_MCO_GLB_VAR(var) (((tEplPtrInstance)pInstance)->var)
182 // macros for process pointer to instance
183 #define EPL_MCO_GET_INSTANCE_PTR() pInstance = (tEplPtrInstance) GetInstancePtr (InstanceHandle);
184 #define EPL_MCO_GET_FREE_INSTANCE_PTR() pInstance = (tEplPtrInstance) GetFreeInstance (); \
185 ASSERT (pInstance != CCM_ILLINSTANCE);
187 // This macro should be used to check the passed pointer to an public function
188 #define EPL_MCO_CHECK_INSTANCE_STATE() ASSERT (pInstance != NULL); \
189 ASSERT (((tEplPtrInstance)pInstance)->m_InstState == kStateUsed);
191 // macros for declaration of pointer to instance pointer
192 #define EPL_MCO_DECL_PTR_INSTANCE_PTR void **pInstancePtr
193 #define EPL_MCO_DECL_PTR_INSTANCE_PTR_ void **pInstancePtr,
195 // macros for reference of pointer to instance pointer
196 // These macros are used for parameter passing to called function.
197 #define EPL_MCO_PTR_INSTANCE_PTR pInstancePtr
198 #define EPL_MCO_PTR_INSTANCE_PTR_ pInstancePtr,
200 // macros for process pointer to instance pointer
201 #define EPL_MCO_CHECK_PTR_INSTANCE_PTR() ASSERT (pInstancePtr != NULL);
202 #define EPL_MCO_SET_PTR_INSTANCE_PTR() (*pInstancePtr = pInstance);
204 #define EPL_MCO_INSTANCE_PARAM(a) (a)
205 #define EPL_MCO_INSTANCE_PARAM_(a) (a),
206 #define EPL_MCO_INSTANCE_PARAM_IDX_() EPL_MCO_INSTANCE_PARAM_ (EPL_MCO_GLB_VAR (m_bInstIndex))
207 #define EPL_MCO_INSTANCE_PARAM_IDX() EPL_MCO_INSTANCE_PARAM (EPL_MCO_GLB_VAR (m_bInstIndex))
208 #define EPL_MCO_WRITE_INSTANCE_STATE(a) EPL_MCO_GLB_VAR (m_InstState) = a;
210 // this macro deletes all instance entries as unused
211 #define EPL_MCO_DELETE_INSTANCE_TABLE() \
213 tEplInstanceInfo * pInstance = &aEplInstanceTable_g[0]; \
214 tFastByte InstNumber = 0; \
215 tFastByte i = EPL_MAX_INSTANCES; \
216 do { \
217 pInstance->m_InstState = (BYTE) kStateUnused; \
218 pInstance->m_bInstIndex = (BYTE) InstNumber; \
219 pInstance++; InstNumber++; i--; \
220 } while (i != 0); \
223 // definition of functions which has to be defined in each module of CANopen stack
224 #define EPL_MCO_DEFINE_INSTANCE_FCT() \
225 static tEplPtrInstance GetInstancePtr (tEplInstanceHdl InstHandle_p); \
226 static tEplPtrInstance GetFreeInstance (void);
227 #define EPL_MCO_DECL_INSTANCE_FCT() \
228 static tEplPtrInstance GetInstancePtr (tEplInstanceHdl InstHandle_p) { \
229 return &aEplInstanceTable_g[InstHandle_p]; } \
230 static tEplPtrInstance GetFreeInstance (void) { \
231 tEplInstanceInfo *pInstance = &aEplInstanceTable_g[0]; \
232 tFastByte i = EPL_MAX_INSTANCES; \
233 do { if (pInstance->m_InstState != kStateUsed) { \
234 return (tEplPtrInstance) pInstance; } \
235 pInstance++; i--; } \
236 while (i != 0); \
237 return CCM_ILLINSTANCE; }
239 // this macro defines the instance table. Each entry is reserved for an instance of CANopen.
240 #define EPL_MCO_DECL_INSTANCE_VAR() \
241 static tEplInstanceInfo aEplInstanceTable_g [EPL_MAX_INSTANCES];
243 // this macro defines member variables in instance table which are needed in
244 // all modules of Epl stack
245 #define EPL_MCO_DECL_INSTANCE_MEMBER() \
246 STATIC BYTE m_InstState; \
247 STATIC BYTE m_bInstIndex;
249 #define EPL_MCO_INSTANCE_PARAM_IDX_() EPL_MCO_INSTANCE_PARAM_ (EPL_MCO_GLB_VAR (m_bInstIndex))
250 #define EPL_MCO_INSTANCE_PARAM_IDX() EPL_MCO_INSTANCE_PARAM (EPL_MCO_GLB_VAR (m_bInstIndex))
252 #else // only one instance is used
254 // Memory attributes for instance table.
255 #define STATIC static // prevent warnings for variables with same name
257 #define INSTANCE_TYPE_BEGIN
258 #define INSTANCE_TYPE_END
260 // macros for declaration, initializing and member access for instance handle
261 // This class of macros are used by API function to inform CCM-modul which
262 // instance is to be used.
264 // macros for reference of instance handle
265 // These macros are used for parameter passing to CANopen API function.
266 #define CCM_INSTANCE_HDL
267 #define CCM_INSTANCE_HDL_
269 #define CCM_DECL_INSTANCE_PTR_LOCAL
271 // macros for declaration within the function header or prototype
272 #define CCM_DECL_INSTANCE_HDL void
273 #define CCM_DECL_INSTANCE_HDL_
275 // macros for process instance handle
276 #define CCM_CHECK_INSTANCE_HDL()
278 // macros for declaration of pointer to instance handle
279 #define CCM_DECL_PTR_INSTANCE_HDL void
280 #define CCM_DECL_PTR_INSTANCE_HDL_
282 // macros for process pointer to instance handle
283 #define CCM_CHECK_PTR_INSTANCE_HDL()
285 // This macro returned the handle and pointer to next free instance.
286 #define CCM_GET_FREE_INSTANCE_AND_HDL()
288 #define CCM_CHECK_INSTANCE_PTR()
290 #define CCM_GET_INSTANCE_PTR()
291 #define CCM_GET_FREE_INSTANCE_PTR()
293 #define CCM_INSTANCE_PARAM(par)
294 #define CCM_INSTANCE_PARAM_(par)
296 #define CCM_INST_ENTRY aCcmInstanceTable_g[0]
298 // macros for declaration, initializing and member access for instance pointer
299 // This class of macros are used by CANopen internal function to point to one instance.
301 // macros for declaration within the function header, prototype or local var list
302 #define EPL_MCO_DECL_INSTANCE_PTR void
303 #define EPL_MCO_DECL_INSTANCE_PTR_
304 #define EPL_MCO_DECL_INSTANCE_PTR_LOCAL
306 // macros for reference of pointer to instance
307 // These macros are used for parameter passing to called function.
308 #define EPL_MCO_INSTANCE_PTR
309 #define EPL_MCO_INSTANCE_PTR_
310 #define EPL_MCO_ADDR_INSTANCE_PTR_
312 // macros for process pointer to instance
313 #define EPL_MCO_GET_INSTANCE_PTR()
314 #define EPL_MCO_GET_FREE_INSTANCE_PTR()
316 // This macro should be used to check the passed pointer to an public function
317 #define EPL_MCO_CHECK_INSTANCE_STATE()
319 // macros for declaration of pointer to instance pointer
320 #define EPL_MCO_DECL_PTR_INSTANCE_PTR void
321 #define EPL_MCO_DECL_PTR_INSTANCE_PTR_
323 // macros for reference of pointer to instance pointer
324 // These macros are used for parameter passing to called function.
325 #define EPL_MCO_PTR_INSTANCE_PTR
326 #define EPL_MCO_PTR_INSTANCE_PTR_
328 // macros for process pointer to instance pointer
329 #define EPL_MCO_CHECK_PTR_INSTANCE_PTR()
330 #define EPL_MCO_SET_PTR_INSTANCE_PTR()
332 #define EPL_MCO_INSTANCE_PARAM(a)
333 #define EPL_MCO_INSTANCE_PARAM_(a)
334 #define EPL_MCO_INSTANCE_PARAM_IDX_()
335 #define EPL_MCO_INSTANCE_PARAM_IDX()
337 // macro for access of struct members of one instance
338 #define EPL_MCO_INST_ENTRY aEplInstanceTable_g[0]
339 #define EPL_MCO_GLB_VAR(var) (var)
340 #define EPL_MCO_WRITE_INSTANCE_STATE(a)
342 // this macro deletes all instance entries as unused
343 #define EPL_MCO_DELETE_INSTANCE_TABLE()
345 // definition of functions which has to be defined in each module of CANopen stack
346 #define EPL_MCO_DEFINE_INSTANCE_FCT()
347 #define EPL_MCO_DECL_INSTANCE_FCT()
349 // this macro defines the instance table. Each entry is reserved for an instance of CANopen.
350 #define EPL_MCO_DECL_INSTANCE_VAR()
352 // this macro defines member variables in instance table which are needed in
353 // all modules of CANopen stack
354 #define EPL_MCO_DECL_INSTANCE_MEMBER()
356 #endif
358 #endif // _EPLINSTDEF_H_
360 // Die letzte Zeile muß unbedingt eine leere Zeile sein, weil manche Compiler
361 // damit ein Problem haben, wenn das nicht so ist (z.B. GNU oder Borland C++ Builder).