blob: 5f1d9986254ec124f9565f409b60b24d4057996c [file] [log] [blame]
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001/****************************************************************************
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
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800100//=========================================================================//
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700124tEplKernel EplObduWriteEntry(unsigned int uiIndex_p,
125 unsigned int uiSubIndex_p,
126 void *pSrcData_p, tEplObdSize Size_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800127{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800128 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800129
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800130 Ret = EplObduCalWriteEntry(uiIndex_p, uiSubIndex_p, pSrcData_p, Size_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800131
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800132 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800133}
134
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800135//---------------------------------------------------------------------------
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700155tEplKernel EplObduReadEntry(unsigned int uiIndex_p,
156 unsigned int uiSubIndex_p,
157 void *pDstData_p,
158 tEplObdSize *pSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800159{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800160 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800161
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800162 Ret = EplObduCalReadEntry(uiIndex_p, uiSubIndex_p, pDstData_p, pSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800163
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800164 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800165}
166
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800167//---------------------------------------------------------------------------
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700181tEplKernel EplObduAccessOdPart(tEplObdPart ObdPart_p, tEplObdDir Direction_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800182{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800183 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800184
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800185 Ret = EplObduCalAccessOdPart(ObdPart_p, Direction_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800186
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800187 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800188}
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700203tEplKernel EplObduDefineVar(tEplVarParam *pVarParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800204{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800205 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800206
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800207 Ret = EplObduCalDefineVar(pVarParam_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800208
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800209 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800210}
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700227void *EplObduGetObjectDataPtr(unsigned int uiIndex_p, unsigned int uiSubIndex_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800228{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800229 void *pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800230
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800231 pData = EplObduCalGetObjectDataPtr(uiIndex_p, uiSubIndex_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800232
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800233 return pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800234}
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))
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700250tEplKernel EplObduRegisterUserOd(tEplObdEntryPtr pUserOd_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800251{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800252 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800253
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800254 Ret = EplObduCalRegisterUserOd(pUserOd_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800255
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800256 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800257
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700275void EplObduInitVarEntry(tEplObdVarEntry *pVarEntry_p, u8 bType_p, tEplObdSize ObdSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800276{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800277 EplObduCalInitVarEntry(pVarEntry_p, bType_p, ObdSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800278}
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700297tEplObdSize EplObduGetDataSize(unsigned int uiIndex_p, unsigned int uiSubIndex_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800298{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800299 tEplObdSize Size;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800300
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800301 Size = EplObduCalGetDataSize(uiIndex_p, uiSubIndex_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800302
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800303 return Size;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800304}
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700320unsigned int EplObduGetNodeId(void)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800321{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800322 unsigned int uiNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800323
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800324 uiNodeId = EplObduCalGetNodeId();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800325
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800326 return uiNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800327}
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700344tEplKernel EplObduSetNodeId(unsigned int uiNodeId_p, tEplObdNodeIdType NodeIdType_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800345{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800346 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800347
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800348 Ret = EplObduCalSetNodeId(uiNodeId_p, NodeIdType_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800349
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800350 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800351}
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700369tEplKernel EplObduGetAccessType(unsigned int uiIndex_p,
370 unsigned int uiSubIndex_p,
371 tEplObdAccess *pAccessTyp_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800372{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800373 tEplObdAccess AccessType;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800374
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800375 AccessType =
376 EplObduCalGetAccessType(uiIndex_p, uiSubIndex_p, pAccessTyp_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800377
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800378 return AccessType;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800379}
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700405tEplKernel EplObduReadEntryToLe(unsigned int uiIndex_p,
406 unsigned int uiSubIndex_p,
407 void *pDstData_p,
408 tEplObdSize *pSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800409{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800410 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800411
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800412 Ret =
413 EplObduCalReadEntryToLe(uiIndex_p, uiSubIndex_p, pDstData_p,
414 pSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800415
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800416 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800417}
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700440tEplKernel EplObduWriteEntryFromLe(unsigned int uiIndex_p,
441 unsigned int uiSubIndex_p,
442 void *pSrcData_p,
443 tEplObdSize Size_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800444{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800445 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800446
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800447 Ret =
448 EplObduCalWriteEntryFromLe(uiIndex_p, uiSubIndex_p, pSrcData_p,
449 Size_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800450
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800451 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800452}
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//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700469tEplKernel EplObduSearchVarEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
470 unsigned int uiSubindex_p,
471 tEplObdVarEntry **ppVarEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800472{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800473 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800474
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800475 Ret = EplObduCalSearchVarEntry(uiIndex_p, uiSubindex_p, ppVarEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800476
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800477 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800478}
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800479
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800480//=========================================================================//
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