nilfs2: segment usage file
[linux-2.6] / drivers / staging / epl / EplObdu.c
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:  source file for Epl-Obd-Userspace-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: EplObdu.c,v $
53
54                 $Author: D.Krueger $
55
56                 $Revision: 1.5 $  $Date: 2008/10/17 15:32:32 $
57
58                 $State: Exp $
59
60                 Build Environment:
61                     GCC V3.4
62
63   -------------------------------------------------------------------------
64
65   Revision History:
66
67   2006/06/19 k.t.:   start of the implementation
68
69 ****************************************************************************/
70
71 #include "EplInc.h"
72 #include "user/EplObdu.h"
73 #include "user/EplObduCal.h"
74
75 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
76 /***************************************************************************/
77 /*                                                                         */
78 /*                                                                         */
79 /*          G L O B A L   D E F I N I T I O N S                            */
80 /*                                                                         */
81 /*                                                                         */
82 /***************************************************************************/
83
84 //---------------------------------------------------------------------------
85 // const defines
86 //---------------------------------------------------------------------------
87
88 //---------------------------------------------------------------------------
89 // local types
90 //---------------------------------------------------------------------------
91
92 //---------------------------------------------------------------------------
93 // modul globale vars
94 //---------------------------------------------------------------------------
95
96 //---------------------------------------------------------------------------
97 // local function prototypes
98 //---------------------------------------------------------------------------
99
100 //=========================================================================//
101 //                                                                         //
102 //          P U B L I C   F U N C T I O N S                                //
103 //                                                                         //
104 //=========================================================================//
105
106 //---------------------------------------------------------------------------
107 //
108 // Function:    EplObduWriteEntry()
109 //
110 // Description: Function writes data to an OBD entry. Strings
111 //              are stored with added '\0' character.
112 //
113 // Parameters:  uiIndex_p       =   Index of the OD entry
114 //              uiSubIndex_p    =   Subindex of the OD Entry
115 //              pSrcData_p      =   Pointer to the data to write
116 //              Size_p          =   Size of the data in Byte
117 //
118 // Return:      tEplKernel      =   Errorcode
119 //
120 //
121 // State:
122 //
123 //---------------------------------------------------------------------------
124 tEplKernel EplObduWriteEntry(unsigned int uiIndex_p,
125                              unsigned int uiSubIndex_p,
126                              void *pSrcData_p, tEplObdSize Size_p)
127 {
128         tEplKernel Ret;
129
130         Ret = EplObduCalWriteEntry(uiIndex_p, uiSubIndex_p, pSrcData_p, Size_p);
131
132         return Ret;
133 }
134
135 //---------------------------------------------------------------------------
136 //
137 // Function:    EplObduReadEntry()
138 //
139 // Description: The function reads an object entry. The application
140 //              can always read the data even if attrib kEplObdAccRead
141 //              is not set. The attrib is only checked up for SDO transfer.
142 //
143 // Parameters:  uiIndex_p       = Index oof the OD entry to read
144 //              uiSubIndex_p    = Subindex to read
145 //              pDstData_p      = pointer to the buffer for data
146 //              Offset_p        = offset in data for read access
147 //              pSize_p         = IN: Size of the buffer
148 //                                OUT: number of readed Bytes
149 //
150 // Return:      tEplKernel      =   errorcode
151 //
152 // State:
153 //
154 //---------------------------------------------------------------------------
155 tEplKernel EplObduReadEntry(unsigned int uiIndex_p,
156                             unsigned int uiSubIndex_p,
157                             void *pDstData_p,
158                             tEplObdSize *pSize_p)
159 {
160         tEplKernel Ret;
161
162         Ret = EplObduCalReadEntry(uiIndex_p, uiSubIndex_p, pDstData_p, pSize_p);
163
164         return Ret;
165 }
166
167 //---------------------------------------------------------------------------
168 //
169 // Function:    EplObdAccessOdPart()
170 //
171 // Description: restores default values of one part of OD
172 //
173 // Parameters:  ObdPart_p       = od-part to reset
174 //              Direction_p     = directory flag for
175 //
176 // Return:      tEplKernel  = errorcode
177 //
178 // State:
179 //
180 //---------------------------------------------------------------------------
181 tEplKernel EplObduAccessOdPart(tEplObdPart ObdPart_p, tEplObdDir Direction_p)
182 {
183         tEplKernel Ret;
184
185         Ret = EplObduCalAccessOdPart(ObdPart_p, Direction_p);
186
187         return Ret;
188 }
189
190 //---------------------------------------------------------------------------
191 //
192 // Function:    EplObduDefineVar()
193 //
194 // Description: defines a variable in OD
195 //
196 // Parameters:  pEplVarParam_p = varentry
197 //
198 // Return:      tEplKernel  =   errorcode
199 //
200 // State:
201 //
202 //---------------------------------------------------------------------------
203 tEplKernel EplObduDefineVar(tEplVarParam *pVarParam_p)
204 {
205         tEplKernel Ret;
206
207         Ret = EplObduCalDefineVar(pVarParam_p);
208
209         return Ret;
210 }
211
212 //---------------------------------------------------------------------------
213 //
214 // Function:    EplObduGetObjectDataPtr()
215 //
216 // Description: It returnes the current data pointer. But if object is an
217 //              constant object it returnes the default pointer.
218 //
219 // Parameters:  uiIndex_p    =   Index of the entry
220 //              uiSubindex_p =   Subindex of the entry
221 //
222 // Return:      void *    = pointer to object data
223 //
224 // State:
225 //
226 //---------------------------------------------------------------------------
227 void *EplObduGetObjectDataPtr(unsigned int uiIndex_p, unsigned int uiSubIndex_p)
228 {
229         void *pData;
230
231         pData = EplObduCalGetObjectDataPtr(uiIndex_p, uiSubIndex_p);
232
233         return pData;
234 }
235
236 //---------------------------------------------------------------------------
237 //
238 // Function:    EplObduRegisterUserOd()
239 //
240 // Description: function registers the user OD
241 //
242 // Parameters:  pUserOd_p   =pointer to user ODd
243 //
244 // Return:     tEplKernel = errorcode
245 //
246 // State:
247 //
248 //---------------------------------------------------------------------------
249 #if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
250 tEplKernel EplObduRegisterUserOd(tEplObdEntryPtr pUserOd_p)
251 {
252         tEplKernel Ret;
253
254         Ret = EplObduCalRegisterUserOd(pUserOd_p);
255
256         return Ret;
257
258 }
259 #endif
260 //---------------------------------------------------------------------------
261 //
262 // Function:    EplObduInitVarEntry()
263 //
264 // Description: function to initialize VarEntry dependened on object type
265 //
266 // Parameters:  pVarEntry_p = pointer to var entry structure
267 //              bType_p     = object type
268 //              ObdSize_p   = size of object data
269 //
270 // Returns:     none
271 //
272 // State:
273 //
274 //---------------------------------------------------------------------------
275 void EplObduInitVarEntry(tEplObdVarEntry *pVarEntry_p, u8 bType_p, tEplObdSize ObdSize_p)
276 {
277         EplObduCalInitVarEntry(pVarEntry_p, bType_p, ObdSize_p);
278 }
279
280 //---------------------------------------------------------------------------
281 //
282 // Function:    EplObduGetDataSize()
283 //
284 // Description: function to initialize VarEntry dependened on object type
285 //
286 //              gets the data size of an object
287 //              for string objects it returnes the string length
288 //
289 // Parameters:  uiIndex_p   =   Index
290 //              uiSubIndex_p=   Subindex
291 //
292 // Return:      tEplObdSize
293 //
294 // State:
295 //
296 //---------------------------------------------------------------------------
297 tEplObdSize EplObduGetDataSize(unsigned int uiIndex_p, unsigned int uiSubIndex_p)
298 {
299         tEplObdSize Size;
300
301         Size = EplObduCalGetDataSize(uiIndex_p, uiSubIndex_p);
302
303         return Size;
304 }
305
306 //---------------------------------------------------------------------------
307 //
308 // Function:    EplObduGetNodeId()
309 //
310 // Description: function returns nodeid from entry 0x1F93
311 //
312 //
313 // Parameters:
314 //
315 // Return:      unsigned int = Node Id
316 //
317 // State:
318 //
319 //---------------------------------------------------------------------------
320 unsigned int EplObduGetNodeId(void)
321 {
322         unsigned int uiNodeId;
323
324         uiNodeId = EplObduCalGetNodeId();
325
326         return uiNodeId;
327 }
328
329 //---------------------------------------------------------------------------
330 //
331 // Function:    EplObduSetNodeId()
332 //
333 // Description: function sets nodeid in entry 0x1F93
334 //
335 //
336 // Parameters:  uiNodeId_p  =   Node Id to set
337 //              NodeIdType_p=   Type on which way the Node Id was set
338 //
339 // Return:      tEplKernel = Errorcode
340 //
341 // State:
342 //
343 //---------------------------------------------------------------------------
344 tEplKernel EplObduSetNodeId(unsigned int uiNodeId_p, tEplObdNodeIdType NodeIdType_p)
345 {
346         tEplKernel Ret;
347
348         Ret = EplObduCalSetNodeId(uiNodeId_p, NodeIdType_p);
349
350         return Ret;
351 }
352
353 //---------------------------------------------------------------------------
354 //
355 // Function:    EplObduGetAccessType()
356 //
357 // Description: Function returns accesstype of the entry
358 //
359 // Parameters:  uiIndex_p       =   Index of the OD entry
360 //              uiSubIndex_p    =   Subindex of the OD Entry
361 //              pAccessTyp_p    =   pointer to buffer to store accesstyp
362 //
363 // Return:      tEplKernel      =   Errorcode
364 //
365 //
366 // State:
367 //
368 //---------------------------------------------------------------------------
369 tEplKernel EplObduGetAccessType(unsigned int uiIndex_p,
370                                 unsigned int uiSubIndex_p,
371                                 tEplObdAccess *pAccessTyp_p)
372 {
373         tEplObdAccess AccessType;
374
375         AccessType =
376             EplObduCalGetAccessType(uiIndex_p, uiSubIndex_p, pAccessTyp_p);
377
378         return AccessType;
379 }
380
381 //---------------------------------------------------------------------------
382 //
383 // Function:    EplObdReaduEntryToLe()
384 //
385 // Description: The function reads an object entry from the byteoder
386 //              of the system to the little endian byteorder for numeric values.
387 //              For other types a normal read will be processed. This is usefull for
388 //              the PDO and SDO module. The application
389 //              can always read the data even if attrib kEplObdAccRead
390 //              is not set. The attrib is only checked up for SDO transfer.
391 //
392 // Parameters:  EPL_MCO_DECL_INSTANCE_PTR_
393 //              uiIndex_p       = Index of the OD entry to read
394 //              uiSubIndex_p    = Subindex to read
395 //              pDstData_p      = pointer to the buffer for data
396 //              Offset_p        = offset in data for read access
397 //              pSize_p         = IN: Size of the buffer
398 //                                OUT: number of readed Bytes
399 //
400 // Return:      tEplKernel
401 //
402 // State:
403 //
404 //---------------------------------------------------------------------------
405 tEplKernel EplObduReadEntryToLe(unsigned int uiIndex_p,
406                                 unsigned int uiSubIndex_p,
407                                 void *pDstData_p,
408                                 tEplObdSize *pSize_p)
409 {
410         tEplKernel Ret;
411
412         Ret =
413             EplObduCalReadEntryToLe(uiIndex_p, uiSubIndex_p, pDstData_p,
414                                     pSize_p);
415
416         return Ret;
417 }
418
419 //---------------------------------------------------------------------------
420 //
421 // Function:    EplObduWriteEntryFromLe()
422 //
423 // Description: Function writes data to an OBD entry from a source with
424 //              little endian byteorder to the od with system specuific
425 //              byteorder. Not numeric values will only by copied. Strings
426 //              are stored with added '\0' character.
427 //
428 // Parameters:  EPL_MCO_DECL_INSTANCE_PTR_
429 //              uiIndex_p       =   Index of the OD entry
430 //              uiSubIndex_p    =   Subindex of the OD Entry
431 //              pSrcData_p      =   Pointer to the data to write
432 //              Size_p          =   Size of the data in Byte
433 //
434 // Return:      tEplKernel      =   Errorcode
435 //
436 //
437 // State:
438 //
439 //---------------------------------------------------------------------------
440 tEplKernel EplObduWriteEntryFromLe(unsigned int uiIndex_p,
441                                    unsigned int uiSubIndex_p,
442                                    void *pSrcData_p,
443                                    tEplObdSize Size_p)
444 {
445         tEplKernel Ret;
446
447         Ret =
448             EplObduCalWriteEntryFromLe(uiIndex_p, uiSubIndex_p, pSrcData_p,
449                                        Size_p);
450
451         return Ret;
452 }
453
454 //---------------------------------------------------------------------------
455 //
456 // Function:    EplObduSearchVarEntry()
457 //
458 // Description: gets variable from OD
459 //
460 // Parameters:  uiIndex_p       =   index of the var entry to search
461 //              uiSubindex_p    =   subindex of var entry to search
462 //              ppVarEntry_p    =   pointer to the pointer to the varentry
463 //
464 // Return:      tEplKernel
465 //
466 // State:
467 //
468 //---------------------------------------------------------------------------
469 tEplKernel EplObduSearchVarEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
470                                  unsigned int uiSubindex_p,
471                                  tEplObdVarEntry **ppVarEntry_p)
472 {
473         tEplKernel Ret;
474
475         Ret = EplObduCalSearchVarEntry(uiIndex_p, uiSubindex_p, ppVarEntry_p);
476
477         return Ret;
478 }
479
480 //=========================================================================//
481 //                                                                         //
482 //          P R I V A T E   F U N C T I O N S                              //
483 //                                                                         //
484 //=========================================================================//
485
486 //---------------------------------------------------------------------------
487 //
488 // Function:
489 //
490 // Description:
491 //
492 //
493 //
494 // Parameters:
495 //
496 //
497 // Returns:
498 //
499 //
500 // State:
501 //
502 //---------------------------------------------------------------------------
503
504 #endif // #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) != 0)
505
506 // EOF