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