blob: ab0966ea6559c960bdbb9cf48ec1072eb497ed7b [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 api function of EplOBD-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: EplObd.c,v $
53
54 $Author: D.Krueger $
55
56 $Revision: 1.12 $ $Date: 2008/10/17 15:32:32 $
57
58 $State: Exp $
59
60 Build Environment:
61 Microsoft VC7
62
63 -------------------------------------------------------------------------
64
65 Revision History:
66
67 2006/06/02 k.t.: start of the implementation, version 1.00
68 ->based on CANopen OBD-Modul
69
70****************************************************************************/
71
72#include "EplInc.h"
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -080073#include "kernel/EplObdk.h" // function prototyps of the EplOBD-Modul
Daniel Krueger9d7164c2008-12-19 11:41:57 -080074
75#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) != 0)
76
77/***************************************************************************/
78/* */
79/* */
80/* G L O B A L D E F I N I T I O N S */
81/* */
82/* */
83/***************************************************************************/
84
85//---------------------------------------------------------------------------
86// const defines
87//---------------------------------------------------------------------------
88
89// float definitions and macros
90#define _SHIFTED_EXPONENT_MASK_SP 0xff
91#define _BIAS_SP 126
92#define T_SP 23
93#define EXPONENT_DENORM_SP (-_BIAS_SP)
94#define BASE_TO_THE_T_SP ((float) 8388608.0)
95#define GET_EXPONENT_SP(x) ((((x) >> T_SP) & _SHIFTED_EXPONENT_MASK_SP) - _BIAS_SP)
96
Daniel Krueger9d7164c2008-12-19 11:41:57 -080097//---------------------------------------------------------------------------
98// local types
99//---------------------------------------------------------------------------
100
101// struct for instance table
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800102INSTANCE_TYPE_BEGIN EPL_MCO_DECL_INSTANCE_MEMBER()
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800103
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700104STATIC tEplObdInitParam m_ObdInitParam;
Greg Kroah-Hartman44b71172009-03-23 11:39:15 -0700105STATIC tEplObdStoreLoadObjCallback m_fpStoreLoadObjCallback;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800106
107INSTANCE_TYPE_END
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800108// decomposition of float
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800109typedef union {
110 tEplObdReal32 m_flRealPart;
111 int m_nIntegerPart;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800112
113} tEplObdRealParts;
114
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800115//---------------------------------------------------------------------------
116// modul globale vars
117//---------------------------------------------------------------------------
118
119// This macro replace the unspecific pointer to an instance through
120// the modul specific type for the local instance table. This macro
121// must defined in each modul.
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700122//#define tEplPtrInstance tEplInstanceInfo *
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800123
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800124EPL_MCO_DECL_INSTANCE_VAR()
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800125
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700126u8 abEplObdTrashObject_g[8];
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800127
128//---------------------------------------------------------------------------
129// local function prototypes
130//---------------------------------------------------------------------------
131
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800132EPL_MCO_DEFINE_INSTANCE_FCT()
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800133
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800134static tEplKernel EplObdCallObjectCallback(EPL_MCO_DECL_INSTANCE_PTR_
135 tEplObdCallback fpCallback_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700136 tEplObdCbParam *pCbParam_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800137
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800138static tEplObdSize EplObdGetDataSizeIntern(tEplObdSubEntryPtr pSubIndexEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800139
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800140static tEplObdSize EplObdGetStrLen(void *pObjData_p,
141 tEplObdSize ObjLen_p, tEplObdType ObjType_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800142
143#if (EPL_OBD_CHECK_OBJECT_RANGE != FALSE)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800144static tEplKernel EplObdCheckObjectRange(tEplObdSubEntryPtr pSubindexEntry_p,
145 void *pData_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800146#endif
147
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800148static tEplKernel EplObdGetVarEntry(tEplObdSubEntryPtr pSubindexEntry_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700149 tEplObdVarEntry **ppVarEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800150
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800151static tEplKernel EplObdGetEntry(EPL_MCO_DECL_INSTANCE_PTR_
152 unsigned int uiIndex_p,
153 unsigned int uiSubindex_p,
154 tEplObdEntryPtr * ppObdEntry_p,
155 tEplObdSubEntryPtr * ppObdSubEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800156
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800157static tEplObdSize EplObdGetObjectSize(tEplObdSubEntryPtr pSubIndexEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800158
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700159static tEplKernel EplObdGetIndexIntern(tEplObdInitParam *pInitParam_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800160 unsigned int uiIndex_p,
161 tEplObdEntryPtr * ppObdEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800162
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800163static tEplKernel EplObdGetSubindexIntern(tEplObdEntryPtr pObdEntry_p,
164 unsigned int uiSubIndex_p,
165 tEplObdSubEntryPtr * ppObdSubEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800166
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800167static tEplKernel EplObdAccessOdPartIntern(EPL_MCO_DECL_INSTANCE_PTR_
168 tEplObdPart CurrentOdPart_p,
169 tEplObdEntryPtr pObdEnty_p,
170 tEplObdDir Direction_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800171
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800172static void *EplObdGetObjectDefaultPtr(tEplObdSubEntryPtr pSubIndexEntry_p);
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700173static void *EplObdGetObjectCurrentPtr(tEplObdSubEntryPtr pSubIndexEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800174
175#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
176
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700177static tEplKernel EplObdCallStoreCallback(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdCbStoreParam *pCbStoreParam_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800178
179#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
180
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700181static void EplObdCopyObjectData(void *pDstData_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800182 void *pSrcData_p,
183 tEplObdSize ObjSize_p, tEplObdType ObjType_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800184
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800185void *EplObdGetObjectDataPtrIntern(tEplObdSubEntryPtr pSubindexEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800186
187static tEplKernel EplObdIsNumericalIntern(tEplObdSubEntryPtr pObdSubEntry_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800188 BOOL * pfEntryNumerical_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800189
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700190static tEplKernel EplObdWriteEntryPre(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
191 unsigned int uiSubIndex_p,
192 void *pSrcData_p,
193 void **ppDstData_p,
194 tEplObdSize Size_p,
195 tEplObdEntryPtr *ppObdEntry_p,
196 tEplObdSubEntryPtr *ppSubEntry_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700197 tEplObdCbParam *pCbParam_p,
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700198 tEplObdSize *pObdSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800199
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700200static tEplKernel EplObdWriteEntryPost(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdEntryPtr pObdEntry_p,
201 tEplObdSubEntryPtr pSubEntry_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700202 tEplObdCbParam *pCbParam_p,
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700203 void *pSrcData_p,
204 void *pDstData_p,
205 tEplObdSize ObdSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800206
207//=========================================================================//
208// //
209// P U B L I C F U N C T I O N S //
210// //
211//=========================================================================//
212
213//---------------------------------------------------------------------------
214//
215// Function: EplObdInit()
216//
217// Description: initializes the first instance
218//
219// Parameters: pInitParam_p = init parameter
220//
221// Return: tEplKernel = errorcode
222//
223// State:
224//
225//---------------------------------------------------------------------------
226
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700227EPLDLLEXPORT tEplKernel EplObdInit(EPL_MCO_DECL_PTR_INSTANCE_PTR_ tEplObdInitParam *pInitParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800228{
229
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800230 tEplKernel Ret;
231 EPL_MCO_DELETE_INSTANCE_TABLE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800232
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800233 if (pInitParam_p == NULL) {
234 Ret = kEplSuccessful;
235 goto Exit;
236 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800237
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800238 Ret = EplObdAddInstance(EPL_MCO_PTR_INSTANCE_PTR_ pInitParam_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800239
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800240 Exit:
241 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800242
243}
244
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800245//---------------------------------------------------------------------------
246//
247// Function: EplObdAddInstance()
248//
249// Description: adds a new instance
250//
251// Parameters: pInitParam_p
252//
253// Return: tEplKernel
254//
255// State:
256//
257//---------------------------------------------------------------------------
258
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700259EPLDLLEXPORT tEplKernel EplObdAddInstance(EPL_MCO_DECL_PTR_INSTANCE_PTR_ tEplObdInitParam *pInitParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800260{
261
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800262 EPL_MCO_DECL_INSTANCE_PTR_LOCAL tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800263
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800264 // check if pointer to instance pointer valid
265 // get free instance and set the globale instance pointer
266 // set also the instance addr to parameterlist
267 EPL_MCO_CHECK_PTR_INSTANCE_PTR();
268 EPL_MCO_GET_FREE_INSTANCE_PTR();
269 EPL_MCO_SET_PTR_INSTANCE_PTR();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800270
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800271 // save init parameters
272 EPL_MEMCPY(&EPL_MCO_GLB_VAR(m_ObdInitParam), pInitParam_p,
273 sizeof(tEplObdInitParam));
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800274
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800275 // clear callback function for command LOAD and STORE
276 EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback) = NULL;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800277
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800278 // sign instance as used
279 EPL_MCO_WRITE_INSTANCE_STATE(kStateUsed);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800280
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800281 // initialize object dictionary
282 // so all all VarEntries will be initialized to trash object and default values will be set to current data
283 Ret = EplObdAccessOdPart(EPL_MCO_INSTANCE_PTR_
284 kEplObdPartAll, kEplObdDirInit);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800285
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800286 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800287
288}
289
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800290//---------------------------------------------------------------------------
291//
292// Function: EplObdDeleteInstance()
293//
294// Description: delete instance
295//
296// Parameters: EPL_MCO_DECL_INSTANCE_PTR
297//
298// Return: tEplKernel
299//
300// State:
301//
302//---------------------------------------------------------------------------
303#if (EPL_USE_DELETEINST_FUNC != FALSE)
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700304EPLDLLEXPORT tEplKernel EplObdDeleteInstance(EPL_MCO_DECL_INSTANCE_PTR)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800305{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800306 // check for all API function if instance is valid
307 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800308
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800309 // sign instance as unused
310 EPL_MCO_WRITE_INSTANCE_STATE(kStateUnused);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800311
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800312 return kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800313
314}
315#endif // (EPL_USE_DELETEINST_FUNC != FALSE)
316
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800317//---------------------------------------------------------------------------
318//
319// Function: EplObdWriteEntry()
320//
321// Description: Function writes data to an OBD entry. Strings
322// are stored with added '\0' character.
323//
324// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
325// uiIndex_p = Index of the OD entry
326// uiSubIndex_p = Subindex of the OD Entry
327// pSrcData_p = Pointer to the data to write
328// Size_p = Size of the data in Byte
329//
330// Return: tEplKernel = Errorcode
331//
332//
333// State:
334//
335//---------------------------------------------------------------------------
336
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700337EPLDLLEXPORT tEplKernel EplObdWriteEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
338 unsigned int uiSubIndex_p,
339 void *pSrcData_p,
340 tEplObdSize Size_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800341{
342
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800343 tEplKernel Ret;
344 tEplObdEntryPtr pObdEntry;
345 tEplObdSubEntryPtr pSubEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700346 tEplObdCbParam CbParam;
347 void *pDstData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800348 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800349
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800350 Ret = EplObdWriteEntryPre(EPL_MCO_INSTANCE_PTR_
351 uiIndex_p,
352 uiSubIndex_p,
353 pSrcData_p,
354 &pDstData,
355 Size_p,
356 &pObdEntry, &pSubEntry, &CbParam, &ObdSize);
357 if (Ret != kEplSuccessful) {
358 goto Exit;
359 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800360
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800361 Ret = EplObdWriteEntryPost(EPL_MCO_INSTANCE_PTR_
362 pObdEntry,
363 pSubEntry,
364 &CbParam, pSrcData_p, pDstData, ObdSize);
365 if (Ret != kEplSuccessful) {
366 goto Exit;
367 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800368
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800369 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800370
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800371 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800372
373}
374
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800375//---------------------------------------------------------------------------
376//
377// Function: EplObdReadEntry()
378//
379// Description: The function reads an object entry. The application
380// can always read the data even if attrib kEplObdAccRead
381// is not set. The attrib is only checked up for SDO transfer.
382//
383// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
384// uiIndex_p = Index oof the OD entry to read
385// uiSubIndex_p = Subindex to read
386// pDstData_p = pointer to the buffer for data
387// Offset_p = offset in data for read access
388// pSize_p = IN: Size of the buffer
389// OUT: number of readed Bytes
390//
391// Return: tEplKernel
392//
393// State:
394//
395//---------------------------------------------------------------------------
396
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700397EPLDLLEXPORT tEplKernel EplObdReadEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
398 unsigned int uiSubIndex_p,
399 void *pDstData_p,
400 tEplObdSize *pSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800401{
402
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800403 tEplKernel Ret;
404 tEplObdEntryPtr pObdEntry;
405 tEplObdSubEntryPtr pSubEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700406 tEplObdCbParam CbParam;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800407 void *pSrcData;
408 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800409
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800410 // check for all API function if instance is valid
411 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800412
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800413 ASSERT(pDstData_p != NULL);
414 ASSERT(pSize_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800415
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800416 // get address of index and subindex entry
417 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
418 uiIndex_p, uiSubIndex_p, &pObdEntry, &pSubEntry);
419 if (Ret != kEplSuccessful) {
420 goto Exit;
421 }
422 // get pointer to object data
423 pSrcData = EplObdGetObjectDataPtrIntern(pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800424
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800425 // check source pointer
426 if (pSrcData == NULL) {
427 Ret = kEplObdReadViolation;
428 goto Exit;
429 }
430 //------------------------------------------------------------------------
431 // address of source data to structure of callback parameters
432 // so callback function can change this data before reading
433 CbParam.m_uiIndex = uiIndex_p;
434 CbParam.m_uiSubIndex = uiSubIndex_p;
435 CbParam.m_pArg = pSrcData;
436 CbParam.m_ObdEvent = kEplObdEvPreRead;
437 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
438 pObdEntry->m_fpCallback, &CbParam);
439 if (Ret != kEplSuccessful) {
440 goto Exit;
441 }
442 // get size of data and check if application has reserved enough memory
443 ObdSize = EplObdGetDataSizeIntern(pSubEntry);
444 // check if offset given and calc correct number of bytes to read
445 if (*pSize_p < ObdSize) {
446 Ret = kEplObdValueLengthError;
447 goto Exit;
448 }
449 // read value from object
450 EPL_MEMCPY(pDstData_p, pSrcData, ObdSize);
451 *pSize_p = ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800452
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800453 // write address of destination data to structure of callback parameters
454 // so callback function can change this data after reading
455 CbParam.m_pArg = pDstData_p;
456 CbParam.m_ObdEvent = kEplObdEvPostRead;
457 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
458 pObdEntry->m_fpCallback, &CbParam);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800459
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800460 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800461
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800462 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800463
464}
465
466//---------------------------------------------------------------------------
467//
468// Function: EplObdAccessOdPart()
469//
470// Description: restores default values of one part of OD
471//
472// Parameters: ObdPart_p
473// Direction_p
474//
475// Return: tEplKernel
476//
477// State:
478//
479//---------------------------------------------------------------------------
480
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700481EPLDLLEXPORT tEplKernel EplObdAccessOdPart(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdPart ObdPart_p,
482 tEplObdDir Direction_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800483{
484
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800485 tEplKernel Ret = kEplSuccessful;
486 BOOL fPartFount;
487 tEplObdEntryPtr pObdEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800488
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800489 // check for all API function if instance is valid
490 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800491
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800492 // part always has to be unequal to NULL
493 pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pPart);
494 ASSERTMSG(pObdEntry != NULL,
495 "EplObdAccessOdPart(): no OD part is defined!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800496
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800497 // if ObdPart_p is not valid fPartFound keeps FALSE and function returns kEplObdIllegalPart
498 fPartFount = FALSE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800499
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800500 // access to part
501 if ((ObdPart_p & kEplObdPartGen) != 0) {
502 fPartFount = TRUE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800503
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800504 Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_
505 kEplObdPartGen, pObdEntry,
506 Direction_p);
507 if (Ret != kEplSuccessful) {
508 goto Exit;
509 }
510 }
511 // access to manufacturer part
512 pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pManufacturerPart);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800513
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800514 if (((ObdPart_p & kEplObdPartMan) != 0) && (pObdEntry != NULL)) {
515 fPartFount = TRUE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800516
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800517 Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_
518 kEplObdPartMan, pObdEntry,
519 Direction_p);
520 if (Ret != kEplSuccessful) {
521 goto Exit;
522 }
523 }
524 // access to device part
525 pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pDevicePart);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800526
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800527 if (((ObdPart_p & kEplObdPartDev) != 0) && (pObdEntry != NULL)) {
528 fPartFount = TRUE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800529
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800530 Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_
531 kEplObdPartDev, pObdEntry,
532 Direction_p);
533 if (Ret != kEplSuccessful) {
534 goto Exit;
535 }
536 }
537#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
538 {
539 // access to user part
540 pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pUserPart);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800541
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800542 if (((ObdPart_p & kEplObdPartUsr) != 0) && (pObdEntry != NULL)) {
543 fPartFount = TRUE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800544
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800545 Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_
546 kEplObdPartUsr,
547 pObdEntry, Direction_p);
548 if (Ret != kEplSuccessful) {
549 goto Exit;
550 }
551 }
552 }
553#endif
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800554
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800555 // no access to an OD part was done? illegal OD part was specified!
556 if (fPartFount == FALSE) {
557 Ret = kEplObdIllegalPart;
558 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800559
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800560 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800561
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800562 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800563
564}
565
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800566//---------------------------------------------------------------------------
567//
568// Function: EplObdDefineVar()
569//
570// Description: defines a variable in OD
571//
572// Parameters: pEplVarParam_p
573//
574// Return: tEplKernel
575//
576// State:
577//
578//---------------------------------------------------------------------------
579
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700580EPLDLLEXPORT tEplKernel EplObdDefineVar(EPL_MCO_DECL_INSTANCE_PTR_ tEplVarParam *pVarParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800581{
582
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800583 tEplKernel Ret;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700584 tEplObdVarEntry *pVarEntry;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800585 tEplVarParamValid VarValid;
586 tEplObdSubEntryPtr pSubindexEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800587
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800588 // check for all API function if instance is valid
589 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800590
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800591 ASSERT(pVarParam_p != NULL); // is not allowed to be NULL
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800592
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800593 // get address of subindex entry
594 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
595 pVarParam_p->m_uiIndex,
596 pVarParam_p->m_uiSubindex, NULL, &pSubindexEntry);
597 if (Ret != kEplSuccessful) {
598 goto Exit;
599 }
600 // get var entry
601 Ret = EplObdGetVarEntry(pSubindexEntry, &pVarEntry);
602 if (Ret != kEplSuccessful) {
603 goto Exit;
604 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800605
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800606 VarValid = pVarParam_p->m_ValidFlag;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800607
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800608 // copy only this values, which valid flag is set
609 if ((VarValid & kVarValidSize) != 0) {
610 if (pSubindexEntry->m_Type != kEplObdTypDomain) {
611 tEplObdSize DataSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800612
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800613 // check passed size parameter
614 DataSize = EplObdGetObjectSize(pSubindexEntry);
615 if (DataSize != pVarParam_p->m_Size) { // size of variable does not match
616 Ret = kEplObdValueLengthError;
617 goto Exit;
618 }
619 } else { // size can be set only for objects of type DOMAIN
620 pVarEntry->m_Size = pVarParam_p->m_Size;
621 }
622 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800623
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800624 if ((VarValid & kVarValidData) != 0) {
625 pVarEntry->m_pData = pVarParam_p->m_pData;
626 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800627/*
628 #if (EPL_PDO_USE_STATIC_MAPPING == FALSE)
629 {
630 if ((VarValid & kVarValidCallback) != 0)
631 {
632 pVarEntry->m_fpCallback = pVarParam_p->m_fpCallback;
633 }
634
635 if ((VarValid & kVarValidArg) != 0)
636 {
637 pVarEntry->m_pArg = pVarParam_p->m_pArg;
638 }
639 }
640 #endif
641*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800642 // Ret is already set to kEplSuccessful from ObdGetVarIntern()
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800643
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800644 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800645
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800646 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800647
648}
649
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800650//---------------------------------------------------------------------------
651//
652// Function: EplObdGetObjectDataPtr()
653//
654// Description: It returnes the current data pointer. But if object is an
655// constant object it returnes the default pointer.
656//
657// Parameters: uiIndex_p = Index of the entry
658// uiSubindex_p = Subindex of the entry
659//
660// Return: void * = pointer to object data
661//
662// State:
663//
664//---------------------------------------------------------------------------
665
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700666EPLDLLEXPORT void *EplObdGetObjectDataPtr(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
667 unsigned int uiSubIndex_p)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800668{
669 tEplKernel Ret;
670 void *pData;
671 tEplObdEntryPtr pObdEntry;
672 tEplObdSubEntryPtr pObdSubEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800673
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800674 // get pointer to index structure
675 Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam),
676 uiIndex_p, &pObdEntry);
677 if (Ret != kEplSuccessful) {
678 pData = NULL;
679 goto Exit;
680 }
681 // get pointer to subindex structure
682 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry);
683 if (Ret != kEplSuccessful) {
684 pData = NULL;
685 goto Exit;
686 }
687 // get Datapointer
688 pData = EplObdGetObjectDataPtrIntern(pObdSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800689
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800690 Exit:
691 return pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800692
693}
694
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800695#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
696
697//---------------------------------------------------------------------------
698//
699// Function: EplObdRegisterUserOd()
700//
701// Description: function registers the user OD
702//
703// Parameters: pUserOd_p =pointer to user ODd
704//
705// Return: tEplKernel = errorcode
706//
707// State:
708//
709//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700710EPLDLLEXPORT tEplKernel EplObdRegisterUserOd(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdEntryPtr pUserOd_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800711{
712
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800713 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800714
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800715 EPL_MCO_GLB_VAR(m_ObdInitParam.m_pUserPart) = pUserOd_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800716
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800717 return kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800718
719}
720
721#endif
722
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800723//---------------------------------------------------------------------------
724//
725// Function: EplObdInitVarEntry()
726//
727// Description: function to initialize VarEntry dependened on object type
728//
729// Parameters: pVarEntry_p = pointer to var entry structure
730// Type_p = object type
731// ObdSize_p = size of object data
732//
733// Returns: none
734//
735// State:
736//
737//---------------------------------------------------------------------------
738
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700739EPLDLLEXPORT void EplObdInitVarEntry(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdVarEntry *pVarEntry_p,
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700740 tEplObdType Type_p, tEplObdSize ObdSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800741{
742/*
743 #if (EPL_PDO_USE_STATIC_MAPPING == FALSE)
744 {
745 // reset pointer to VAR callback and argument
746 pVarEntry_p->m_fpCallback = NULL;
747 pVarEntry_p->m_pArg = NULL;
748 }
749 #endif
750*/
751
752// 10-dec-2004 r.d.: this function will not be used for strings
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800753 if ((Type_p == kEplObdTypDomain))
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800754// (bType_p == kEplObdTypVString) /* ||
755// (bType_p == kEplObdTypOString) ||
756// (bType_p == kEplObdTypUString) */ )
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800757 {
758 // variables which are defined as DOMAIN or VSTRING should not point to
759 // trash object, because this trash object contains only 8 bytes. DOMAINS or
760 // STRINGS can be longer.
761 pVarEntry_p->m_pData = NULL;
762 pVarEntry_p->m_Size = 0;
763 } else {
764 // set address to variable data to trash object
765 // This prevents an access violation if user forgets to call EplObdDefineVar()
766 // for this variable but mappes it in a PDO.
767 pVarEntry_p->m_pData = &abEplObdTrashObject_g[0];
768 pVarEntry_p->m_Size = ObdSize_p;
769 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800770
771}
772
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800773//---------------------------------------------------------------------------
774//
775// Function: EplObdGetDataSize()
776//
777// Description: function to initialize VarEntry dependened on object type
778//
779// gets the data size of an object
780// for string objects it returnes the string length
781//
782// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer
783// uiIndex_p = Index
784// uiSubIndex_p= Subindex
785//
786// Return: tEplObdSize
787//
788// State:
789//
790//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700791EPLDLLEXPORT tEplObdSize EplObdGetDataSize(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
792 unsigned int uiSubIndex_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800793{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800794 tEplKernel Ret;
795 tEplObdSize ObdSize;
796 tEplObdEntryPtr pObdEntry;
797 tEplObdSubEntryPtr pObdSubEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800798
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800799 // get pointer to index structure
800 Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam),
801 uiIndex_p, &pObdEntry);
802 if (Ret != kEplSuccessful) {
803 ObdSize = 0;
804 goto Exit;
805 }
806 // get pointer to subindex structure
807 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry);
808 if (Ret != kEplSuccessful) {
809 ObdSize = 0;
810 goto Exit;
811 }
812 // get size
813 ObdSize = EplObdGetDataSizeIntern(pObdSubEntry);
814 Exit:
815 return ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800816}
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800817
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800818//---------------------------------------------------------------------------
819//
820// Function: EplObdGetNodeId()
821//
822// Description: function returns nodeid from entry 0x1F93
823//
824//
825// Parameters: EPL_MCO_DECL_INSTANCE_PTR = Instancepointer
826//
827// Return: unsigned int = Node Id
828//
829// State:
830//
831//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700832EPLDLLEXPORT unsigned int EplObdGetNodeId(EPL_MCO_DECL_INSTANCE_PTR)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800833{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800834 tEplKernel Ret;
835 tEplObdSize ObdSize;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700836 u8 bNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800837
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800838 bNodeId = 0;
839 ObdSize = sizeof(bNodeId);
840 Ret = EplObdReadEntry(EPL_MCO_PTR_INSTANCE_PTR_
841 EPL_OBD_NODE_ID_INDEX,
842 EPL_OBD_NODE_ID_SUBINDEX, &bNodeId, &ObdSize);
843 if (Ret != kEplSuccessful) {
844 bNodeId = EPL_C_ADR_INVALID;
845 goto Exit;
846 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800847
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800848 Exit:
849 return (unsigned int)bNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800850
851}
852
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800853//---------------------------------------------------------------------------
854//
855// Function: EplObdSetNodeId()
856//
857// Description: function sets nodeid in entry 0x1F93
858//
859//
860// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer
861// uiNodeId_p = Node Id to set
862// NodeIdType_p= Type on which way the Node Id was set
863//
864// Return: tEplKernel = Errorcode
865//
866// State:
867//
868//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700869EPLDLLEXPORT tEplKernel EplObdSetNodeId(EPL_MCO_DECL_PTR_INSTANCE_PTR_ unsigned int uiNodeId_p,
870 tEplObdNodeIdType NodeIdType_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800871{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800872 tEplKernel Ret;
873 tEplObdSize ObdSize;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700874 u8 fHwBool;
875 u8 bNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800876
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800877 // check Node Id
878 if (uiNodeId_p == EPL_C_ADR_INVALID) {
879 Ret = kEplInvalidNodeId;
880 goto Exit;
881 }
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700882 bNodeId = (u8) uiNodeId_p;
883 ObdSize = sizeof(u8);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800884 // write NodeId to OD entry
885 Ret = EplObdWriteEntry(EPL_MCO_PTR_INSTANCE_PTR_
886 EPL_OBD_NODE_ID_INDEX,
887 EPL_OBD_NODE_ID_SUBINDEX, &bNodeId, ObdSize);
888 if (Ret != kEplSuccessful) {
889 goto Exit;
890 }
891 // set HWBOOL-Flag in Subindex EPL_OBD_NODE_ID_HWBOOL_SUBINDEX
892 switch (NodeIdType_p) {
893 // type unknown
894 case kEplObdNodeIdUnknown:
895 {
896 fHwBool = OBD_FALSE;
897 break;
898 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800899
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800900 case kEplObdNodeIdSoftware:
901 {
902 fHwBool = OBD_FALSE;
903 break;
904 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800905
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800906 case kEplObdNodeIdHardware:
907 {
908 fHwBool = OBD_TRUE;
909 break;
910 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800911
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800912 default:
913 {
914 fHwBool = OBD_FALSE;
915 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800916
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800917 } // end of switch (NodeIdType_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800918
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800919 // write flag
920 ObdSize = sizeof(fHwBool);
921 Ret = EplObdWriteEntry(EPL_MCO_PTR_INSTANCE_PTR
922 EPL_OBD_NODE_ID_INDEX,
923 EPL_OBD_NODE_ID_HWBOOL_SUBINDEX,
924 &fHwBool, ObdSize);
925 if (Ret != kEplSuccessful) {
926 goto Exit;
927 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800928
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800929 Exit:
930 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800931}
932
933//---------------------------------------------------------------------------
934//
935// Function: EplObdIsNumerical()
936//
937// Description: function checks if a entry is numerical or not
938//
939//
940// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer
941// uiIndex_p = Index
942// uiSubIndex_p = Subindex
943// pfEntryNumerical_p = pointer to BOOL for returnvalue
944// -> TRUE if entry a numerical value
945// -> FALSE if entry not a numerical value
946//
947// Return: tEplKernel = Errorcode
948//
949// State:
950//
951//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700952EPLDLLEXPORT tEplKernel EplObdIsNumerical(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
953 unsigned int uiSubIndex_p,
954 BOOL *pfEntryNumerical_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800955{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800956 tEplKernel Ret;
957 tEplObdEntryPtr pObdEntry;
958 tEplObdSubEntryPtr pObdSubEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800959
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800960 // get pointer to index structure
961 Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam),
962 uiIndex_p, &pObdEntry);
963 if (Ret != kEplSuccessful) {
964 goto Exit;
965 }
966 // get pointer to subindex structure
967 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry);
968 if (Ret != kEplSuccessful) {
969 goto Exit;
970 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800971
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800972 Ret = EplObdIsNumericalIntern(pObdSubEntry, pfEntryNumerical_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800973
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800974 Exit:
975 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800976
977}
978
979//---------------------------------------------------------------------------
980//
981// Function: EplObdReadEntryToLe()
982//
983// Description: The function reads an object entry from the byteoder
984// of the system to the little endian byteorder for numerical values.
985// For other types a normal read will be processed. This is usefull for
986// the PDO and SDO module. The application
987// can always read the data even if attrib kEplObdAccRead
988// is not set. The attrib is only checked up for SDO transfer.
989//
990// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
991// uiIndex_p = Index of the OD entry to read
992// uiSubIndex_p = Subindex to read
993// pDstData_p = pointer to the buffer for data
994// Offset_p = offset in data for read access
995// pSize_p = IN: Size of the buffer
996// OUT: number of readed Bytes
997//
998// Return: tEplKernel
999//
1000// State:
1001//
1002//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001003EPLDLLEXPORT tEplKernel EplObdReadEntryToLe(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1004 unsigned int uiSubIndex_p,
1005 void *pDstData_p,
1006 tEplObdSize *pSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001007{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001008 tEplKernel Ret;
1009 tEplObdEntryPtr pObdEntry;
1010 tEplObdSubEntryPtr pSubEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001011 tEplObdCbParam CbParam;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001012 void *pSrcData;
1013 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001014
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001015 // check for all API function if instance is valid
1016 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001017
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001018 ASSERT(pDstData_p != NULL);
1019 ASSERT(pSize_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001020
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001021 // get address of index and subindex entry
1022 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
1023 uiIndex_p, uiSubIndex_p, &pObdEntry, &pSubEntry);
1024 if (Ret != kEplSuccessful) {
1025 goto Exit;
1026 }
1027 // get pointer to object data
1028 pSrcData = EplObdGetObjectDataPtrIntern(pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001029
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001030 // check source pointer
1031 if (pSrcData == NULL) {
1032 Ret = kEplObdReadViolation;
1033 goto Exit;
1034 }
1035 //------------------------------------------------------------------------
1036 // address of source data to structure of callback parameters
1037 // so callback function can change this data before reading
1038 CbParam.m_uiIndex = uiIndex_p;
1039 CbParam.m_uiSubIndex = uiSubIndex_p;
1040 CbParam.m_pArg = pSrcData;
1041 CbParam.m_ObdEvent = kEplObdEvPreRead;
1042 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
1043 pObdEntry->m_fpCallback, &CbParam);
1044 if (Ret != kEplSuccessful) {
1045 goto Exit;
1046 }
1047 // get size of data and check if application has reserved enough memory
1048 ObdSize = EplObdGetDataSizeIntern(pSubEntry);
1049 // check if offset given and calc correct number of bytes to read
1050 if (*pSize_p < ObdSize) {
1051 Ret = kEplObdValueLengthError;
1052 goto Exit;
1053 }
1054 // check if numerical type
1055 switch (pSubEntry->m_Type) {
1056 //-----------------------------------------------
1057 // types without ami
1058 case kEplObdTypVString:
1059 case kEplObdTypOString:
1060 case kEplObdTypDomain:
1061 default:
1062 {
1063 // read value from object
1064 EPL_MEMCPY(pDstData_p, pSrcData, ObdSize);
1065 break;
1066 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001067
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001068 //-----------------------------------------------
1069 // numerical type which needs ami-write
1070 // 8 bit or smaller values
1071 case kEplObdTypBool:
1072 case kEplObdTypInt8:
1073 case kEplObdTypUInt8:
1074 {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001075 AmiSetByteToLe(pDstData_p, *((u8 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001076 break;
1077 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001078
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001079 // 16 bit values
1080 case kEplObdTypInt16:
1081 case kEplObdTypUInt16:
1082 {
1083 AmiSetWordToLe(pDstData_p, *((WORD *) pSrcData));
1084 break;
1085 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001086
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001087 // 24 bit values
1088 case kEplObdTypInt24:
1089 case kEplObdTypUInt24:
1090 {
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -07001091 AmiSetDword24ToLe(pDstData_p, *((u32 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001092 break;
1093 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001094
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001095 // 32 bit values
1096 case kEplObdTypInt32:
1097 case kEplObdTypUInt32:
1098 case kEplObdTypReal32:
1099 {
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -07001100 AmiSetDwordToLe(pDstData_p, *((u32 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001101 break;
1102 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001103
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001104 // 40 bit values
1105 case kEplObdTypInt40:
1106 case kEplObdTypUInt40:
1107 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001108 AmiSetQword40ToLe(pDstData_p, *((u64 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001109 break;
1110 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001111
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001112 // 48 bit values
1113 case kEplObdTypInt48:
1114 case kEplObdTypUInt48:
1115 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001116 AmiSetQword48ToLe(pDstData_p, *((u64 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001117 break;
1118 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001119
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001120 // 56 bit values
1121 case kEplObdTypInt56:
1122 case kEplObdTypUInt56:
1123 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001124 AmiSetQword56ToLe(pDstData_p, *((u64 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001125 break;
1126 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001127
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001128 // 64 bit values
1129 case kEplObdTypInt64:
1130 case kEplObdTypUInt64:
1131 case kEplObdTypReal64:
1132 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001133 AmiSetQword64ToLe(pDstData_p, *((u64 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001134 break;
1135 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001136
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001137 // time of day
1138 case kEplObdTypTimeOfDay:
1139 case kEplObdTypTimeDiff:
1140 {
1141 AmiSetTimeOfDay(pDstData_p, ((tTimeOfDay *) pSrcData));
1142 break;
1143 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001144
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001145 } // end of switch(pSubEntry->m_Type)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001146
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001147 *pSize_p = ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001148
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001149 // write address of destination data to structure of callback parameters
1150 // so callback function can change this data after reading
1151 CbParam.m_pArg = pDstData_p;
1152 CbParam.m_ObdEvent = kEplObdEvPostRead;
1153 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
1154 pObdEntry->m_fpCallback, &CbParam);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001155
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001156 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001157
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001158 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001159
1160}
1161
1162//---------------------------------------------------------------------------
1163//
1164// Function: EplObdWriteEntryFromLe()
1165//
1166// Description: Function writes data to an OBD entry from a source with
1167// little endian byteorder to the od with system specuific
1168// byteorder. Not numerical values will only by copied. Strings
1169// are stored with added '\0' character.
1170//
1171// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
1172// uiIndex_p = Index of the OD entry
1173// uiSubIndex_p = Subindex of the OD Entry
1174// pSrcData_p = Pointer to the data to write
1175// Size_p = Size of the data in Byte
1176//
1177// Return: tEplKernel = Errorcode
1178//
1179//
1180// State:
1181//
1182//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001183EPLDLLEXPORT tEplKernel EplObdWriteEntryFromLe(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1184 unsigned int uiSubIndex_p,
1185 void *pSrcData_p,
1186 tEplObdSize Size_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001187{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001188 tEplKernel Ret;
1189 tEplObdEntryPtr pObdEntry;
1190 tEplObdSubEntryPtr pSubEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001191 tEplObdCbParam CbParam;
1192 void *pDstData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001193 tEplObdSize ObdSize;
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001194 u64 qwBuffer;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001195 void *pBuffer = &qwBuffer;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001196
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001197 Ret = EplObdWriteEntryPre(EPL_MCO_INSTANCE_PTR_
1198 uiIndex_p,
1199 uiSubIndex_p,
1200 pSrcData_p,
1201 &pDstData,
1202 Size_p,
1203 &pObdEntry, &pSubEntry, &CbParam, &ObdSize);
1204 if (Ret != kEplSuccessful) {
1205 goto Exit;
1206 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001207
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001208 // check if numerical type
1209 switch (pSubEntry->m_Type) {
1210 //-----------------------------------------------
1211 // types without ami
1212 default:
1213 { // do nothing, i.e. use the given source pointer
1214 pBuffer = pSrcData_p;
1215 break;
1216 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001217
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001218 //-----------------------------------------------
1219 // numerical type which needs ami-write
1220 // 8 bit or smaller values
1221 case kEplObdTypBool:
1222 case kEplObdTypInt8:
1223 case kEplObdTypUInt8:
1224 {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001225 *((u8 *) pBuffer) = AmiGetByteFromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001226 break;
1227 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001228
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001229 // 16 bit values
1230 case kEplObdTypInt16:
1231 case kEplObdTypUInt16:
1232 {
1233 *((WORD *) pBuffer) = AmiGetWordFromLe(pSrcData_p);
1234 break;
1235 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001236
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001237 // 24 bit values
1238 case kEplObdTypInt24:
1239 case kEplObdTypUInt24:
1240 {
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -07001241 *((u32 *) pBuffer) = AmiGetDword24FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001242 break;
1243 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001244
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001245 // 32 bit values
1246 case kEplObdTypInt32:
1247 case kEplObdTypUInt32:
1248 case kEplObdTypReal32:
1249 {
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -07001250 *((u32 *) pBuffer) = AmiGetDwordFromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001251 break;
1252 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001253
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001254 // 40 bit values
1255 case kEplObdTypInt40:
1256 case kEplObdTypUInt40:
1257 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001258 *((u64 *) pBuffer) = AmiGetQword40FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001259 break;
1260 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001261
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001262 // 48 bit values
1263 case kEplObdTypInt48:
1264 case kEplObdTypUInt48:
1265 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001266 *((u64 *) pBuffer) = AmiGetQword48FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001267 break;
1268 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001269
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001270 // 56 bit values
1271 case kEplObdTypInt56:
1272 case kEplObdTypUInt56:
1273 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001274 *((u64 *) pBuffer) = AmiGetQword56FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001275 break;
1276 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001277
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001278 // 64 bit values
1279 case kEplObdTypInt64:
1280 case kEplObdTypUInt64:
1281 case kEplObdTypReal64:
1282 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001283 *((u64 *) pBuffer) = AmiGetQword64FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001284 break;
1285 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001286
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001287 // time of day
1288 case kEplObdTypTimeOfDay:
1289 case kEplObdTypTimeDiff:
1290 {
1291 AmiGetTimeOfDay(pBuffer, ((tTimeOfDay *) pSrcData_p));
1292 break;
1293 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001294
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001295 } // end of switch(pSubEntry->m_Type)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001296
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001297 Ret = EplObdWriteEntryPost(EPL_MCO_INSTANCE_PTR_
1298 pObdEntry,
1299 pSubEntry,
1300 &CbParam, pBuffer, pDstData, ObdSize);
1301 if (Ret != kEplSuccessful) {
1302 goto Exit;
1303 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001304
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001305 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001306
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001307 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001308
1309}
1310
1311//---------------------------------------------------------------------------
1312//
1313// Function: EplObdGetAccessType()
1314//
1315// Description: Function returns accesstype of the entry
1316//
1317// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
1318// uiIndex_p = Index of the OD entry
1319// uiSubIndex_p = Subindex of the OD Entry
1320// pAccessTyp_p = pointer to buffer to store accesstype
1321//
1322// Return: tEplKernel = errorcode
1323//
1324//
1325// State:
1326//
1327//---------------------------------------------------------------------------
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001328EPLDLLEXPORT tEplKernel EplObdGetAccessType(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1329 unsigned int uiSubIndex_p,
1330 tEplObdAccess *pAccessTyp_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001331{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001332 tEplKernel Ret;
1333 tEplObdEntryPtr pObdEntry;
1334 tEplObdSubEntryPtr pObdSubEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001335
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001336 // get pointer to index structure
1337 Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam),
1338 uiIndex_p, &pObdEntry);
1339 if (Ret != kEplSuccessful) {
1340 goto Exit;
1341 }
1342 // get pointer to subindex structure
1343 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry);
1344 if (Ret != kEplSuccessful) {
1345 goto Exit;
1346 }
1347 // get accessType
1348 *pAccessTyp_p = pObdSubEntry->m_Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001349
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001350 Exit:
1351 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001352}
1353
1354//---------------------------------------------------------------------------
1355//
1356// Function: EplObdSearchVarEntry()
1357//
1358// Description: gets variable from OD
1359//
1360// Parameters: uiIndex_p = index of the var entry to search
1361// uiSubindex_p = subindex of var entry to search
1362// ppVarEntry_p = pointer to the pointer to the varentry
1363//
1364// Return: tEplKernel
1365//
1366// State:
1367//
1368//---------------------------------------------------------------------------
1369
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001370tEplKernel EplObdSearchVarEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1371 unsigned int uiSubindex_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001372 tEplObdVarEntry **ppVarEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001373{
1374
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001375 tEplKernel Ret;
1376 tEplObdSubEntryPtr pSubindexEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001377
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001378 // check for all API function if instance is valid
1379 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001380
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001381 // get address of subindex entry
1382 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
1383 uiIndex_p, uiSubindex_p, NULL, &pSubindexEntry);
1384 if (Ret == kEplSuccessful) {
1385 // get var entry
1386 Ret = EplObdGetVarEntry(pSubindexEntry, ppVarEntry_p);
1387 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001388
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001389 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001390
1391}
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001392
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001393//=========================================================================//
1394// //
1395// P R I V A T E D E F I N I T I O N S //
1396// //
1397//=========================================================================//
1398
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001399EPL_MCO_DECL_INSTANCE_FCT()
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001400//---------------------------------------------------------------------------
1401//
1402// Function: EplObdCallObjectCallback()
1403//
1404// Description: calls callback function of an object or of a variable
1405//
1406// Parameters: fpCallback_p
1407// pCbParam_p
1408//
1409// Return: tEplKernel
1410//
1411// State:
1412//
1413//---------------------------------------------------------------------------
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001414static tEplKernel EplObdCallObjectCallback(EPL_MCO_DECL_INSTANCE_PTR_
1415 tEplObdCallback fpCallback_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001416 tEplObdCbParam *pCbParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001417{
1418
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001419 tEplKernel Ret;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001420 tEplObdCallback fpCallback;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001421
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001422 // check for all API function if instance is valid
1423 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001424
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001425 ASSERT(pCbParam_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001426
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001427 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001428
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001429 // check address of callback function before calling it
1430 if (fpCallback_p != NULL) {
1431 // KEIL C51 V6.01 has a bug.
1432 // Therefore the parameter fpCallback_p has to be copied in local variable fpCallback.
1433 fpCallback = fpCallback_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001434
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001435 // call callback function for this object
1436 Ret = fpCallback(EPL_MCO_INSTANCE_PARAM_IDX_()
1437 pCbParam_p);
1438 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001439
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001440 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001441}
1442
1443//---------------------------------------------------------------------------
1444//
1445// Function: EplObdGetDataSizeIntern()
1446//
1447// Description: gets the data size of an object
1448// for string objects it returnes the string length
1449//
1450// Parameters: pSubIndexEntry_p
1451//
1452// Return: tEplObdSize
1453//
1454// State:
1455//
1456//---------------------------------------------------------------------------
1457
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001458static tEplObdSize EplObdGetDataSizeIntern(tEplObdSubEntryPtr pSubIndexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001459{
1460
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001461 tEplObdSize DataSize;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001462 void *pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001463
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001464 // If OD entry is defined by macro EPL_OBD_SUBINDEX_ROM_VSTRING
1465 // then the current pointer is always NULL. The function
1466 // returns the length of default string.
1467 DataSize = EplObdGetObjectSize(pSubIndexEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001468
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001469 if (pSubIndexEntry_p->m_Type == kEplObdTypVString) {
1470 // The pointer to current value can be received from EplObdGetObjectCurrentPtr()
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001471 pData = ((void *)EplObdGetObjectCurrentPtr(pSubIndexEntry_p));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001472 if (pData != NULL) {
1473 DataSize =
1474 EplObdGetStrLen((void *)pData, DataSize,
1475 pSubIndexEntry_p->m_Type);
1476 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001477
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001478 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001479
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001480 return DataSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001481
1482}
1483
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001484//---------------------------------------------------------------------------
1485//
1486// Function: EplObdGetStrLen()
1487//
1488// Description: The function calculates the length of string. The '\0'
1489// character is included!!
1490//
1491// Parameters: pObjData_p = pointer to string
1492// ObjLen_p = max. length of objectr entry
1493// bObjType_p = object type (VSTRING, ...)
1494//
1495// Returns: string length + 1
1496//
1497// State:
1498//
1499//---------------------------------------------------------------------------
1500
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001501static tEplObdSize EplObdGetStrLen(void *pObjData_p,
1502 tEplObdSize ObjLen_p, tEplObdType ObjType_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001503{
1504
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001505 tEplObdSize StrLen = 0;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001506 u8 *pbString;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001507
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001508 if (pObjData_p == NULL) {
1509 goto Exit;
1510 }
1511 //----------------------------------------
1512 // Visible String: data format byte
1513 if (ObjType_p == kEplObdTypVString) {
1514 pbString = pObjData_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001515
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001516 for (StrLen = 0; StrLen < ObjLen_p; StrLen++) {
1517 if (*pbString == '\0') {
1518 StrLen++;
1519 break;
1520 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001521
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001522 pbString++;
1523 }
1524 }
1525 //----------------------------------------
1526 // other string types ...
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001527
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001528 Exit:
1529 return (StrLen);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001530
1531}
1532
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001533#if (EPL_OBD_CHECK_OBJECT_RANGE != FALSE)
1534
1535//---------------------------------------------------------------------------
1536//
1537// Function: EplObdCheckObjectRange()
1538//
1539// Description: function to check value range of object data
1540//
1541// NOTICE: The pointer of data (pData_p) must point out to an even address,
1542// if ObjType is unequal to kEplObdTypInt8 or kEplObdTypUInt8! But it is
1543// always realiced because pointer m_pDefault points always to an
1544// array of the SPECIFIED type.
1545//
1546// Parameters: pSubindexEntry_p
1547// pData_p
1548//
1549// Return: tEplKernel
1550//
1551// State:
1552//
1553//---------------------------------------------------------------------------
1554
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001555static tEplKernel EplObdCheckObjectRange(tEplObdSubEntryPtr pSubindexEntry_p,
1556 void *pData_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001557{
1558
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001559 tEplKernel Ret;
1560 void *pRangeData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001561
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001562 ASSERTMSG(pSubindexEntry_p != NULL,
1563 "EplObdCheckObjectRange(): no address to subindex struct!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001564
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001565 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001566
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001567 // check if data range has to be checked
1568 if ((pSubindexEntry_p->m_Access & kEplObdAccRange) == 0) {
1569 goto Exit;
1570 }
1571 // get address of default data
1572 pRangeData = pSubindexEntry_p->m_pDefault;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001573
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001574 // jump to called object type
1575 switch ((tEplObdType) pSubindexEntry_p->m_Type) {
1576 // -----------------------------------------------------------------
1577 // ObdType kEplObdTypBool will not be checked because there are only
1578 // two possible values 0 or 1.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001579
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001580 // -----------------------------------------------------------------
1581 // ObdTypes which has to be check up because numerical values
1582 case kEplObdTypInt8:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001583
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001584 // switch to lower limit
1585 pRangeData = ((tEplObdInteger8 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001586
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001587 // check if value is to low
1588 if (*((tEplObdInteger8 *) pData_p) <
1589 *((tEplObdInteger8 *) pRangeData)) {
1590 Ret = kEplObdValueTooLow;
1591 break;
1592 }
1593 // switch to higher limit
1594 pRangeData = ((tEplObdInteger8 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001595
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001596 // check if value is to high
1597 if (*((tEplObdInteger8 *) pData_p) >
1598 *((tEplObdInteger8 *) pRangeData)) {
1599 Ret = kEplObdValueTooHigh;
1600 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001601
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001602 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001603
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001604 case kEplObdTypUInt8:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001605
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001606 // switch to lower limit
1607 pRangeData = ((tEplObdUnsigned8 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001608
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001609 // check if value is to low
1610 if (*((tEplObdUnsigned8 *) pData_p) <
1611 *((tEplObdUnsigned8 *) pRangeData)) {
1612 Ret = kEplObdValueTooLow;
1613 break;
1614 }
1615 // switch to higher limit
1616 pRangeData = ((tEplObdUnsigned8 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001617
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001618 // check if value is to high
1619 if (*((tEplObdUnsigned8 *) pData_p) >
1620 *((tEplObdUnsigned8 *) pRangeData)) {
1621 Ret = kEplObdValueTooHigh;
1622 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001623
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001624 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001625
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001626 case kEplObdTypInt16:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001627
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001628 // switch to lower limit
1629 pRangeData = ((tEplObdInteger16 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001630
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001631 // check if value is to low
1632 if (*((tEplObdInteger16 *) pData_p) <
1633 *((tEplObdInteger16 *) pRangeData)) {
1634 Ret = kEplObdValueTooLow;
1635 break;
1636 }
1637 // switch to higher limit
1638 pRangeData = ((tEplObdInteger16 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001639
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001640 // check if value is to high
1641 if (*((tEplObdInteger16 *) pData_p) >
1642 *((tEplObdInteger16 *) pRangeData)) {
1643 Ret = kEplObdValueTooHigh;
1644 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001645
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001646 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001647
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001648 case kEplObdTypUInt16:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001649
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001650 // switch to lower limit
1651 pRangeData = ((tEplObdUnsigned16 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001652
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001653 // check if value is to low
1654 if (*((tEplObdUnsigned16 *) pData_p) <
1655 *((tEplObdUnsigned16 *) pRangeData)) {
1656 Ret = kEplObdValueTooLow;
1657 break;
1658 }
1659 // switch to higher limit
1660 pRangeData = ((tEplObdUnsigned16 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001661
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001662 // check if value is to high
1663 if (*((tEplObdUnsigned16 *) pData_p) >
1664 *((tEplObdUnsigned16 *) pRangeData)) {
1665 Ret = kEplObdValueTooHigh;
1666 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001667
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001668 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001669
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001670 case kEplObdTypInt32:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001671
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001672 // switch to lower limit
1673 pRangeData = ((tEplObdInteger32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001674
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001675 // check if value is to low
1676 if (*((tEplObdInteger32 *) pData_p) <
1677 *((tEplObdInteger32 *) pRangeData)) {
1678 Ret = kEplObdValueTooLow;
1679 break;
1680 }
1681 // switch to higher limit
1682 pRangeData = ((tEplObdInteger32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001683
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001684 // check if value is to high
1685 if (*((tEplObdInteger32 *) pData_p) >
1686 *((tEplObdInteger32 *) pRangeData)) {
1687 Ret = kEplObdValueTooHigh;
1688 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001689
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001690 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001691
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001692 case kEplObdTypUInt32:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001693
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001694 // switch to lower limit
1695 pRangeData = ((tEplObdUnsigned32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001696
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001697 // check if value is to low
1698 if (*((tEplObdUnsigned32 *) pData_p) <
1699 *((tEplObdUnsigned32 *) pRangeData)) {
1700 Ret = kEplObdValueTooLow;
1701 break;
1702 }
1703 // switch to higher limit
1704 pRangeData = ((tEplObdUnsigned32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001705
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001706 // check if value is to high
1707 if (*((tEplObdUnsigned32 *) pData_p) >
1708 *((tEplObdUnsigned32 *) pRangeData)) {
1709 Ret = kEplObdValueTooHigh;
1710 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001711
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001712 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001713
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001714 case kEplObdTypReal32:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001715
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001716 // switch to lower limit
1717 pRangeData = ((tEplObdReal32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001718
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001719 // check if value is to low
1720 if (*((tEplObdReal32 *) pData_p) <
1721 *((tEplObdReal32 *) pRangeData)) {
1722 Ret = kEplObdValueTooLow;
1723 break;
1724 }
1725 // switch to higher limit
1726 pRangeData = ((tEplObdReal32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001727
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001728 // check if value is to high
1729 if (*((tEplObdReal32 *) pData_p) >
1730 *((tEplObdReal32 *) pRangeData)) {
1731 Ret = kEplObdValueTooHigh;
1732 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001733
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001734 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001735
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001736 // -----------------------------------------------------------------
1737 case kEplObdTypInt40:
1738 case kEplObdTypInt48:
1739 case kEplObdTypInt56:
1740 case kEplObdTypInt64:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001741
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001742 // switch to lower limit
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001743 pRangeData = ((signed u64 *)pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001744
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001745 // check if value is to low
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001746 if (*((signed u64 *)pData_p) < *((signed u64 *)pRangeData)) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001747 Ret = kEplObdValueTooLow;
1748 break;
1749 }
1750 // switch to higher limit
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001751 pRangeData = ((signed u64 *)pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001752
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001753 // check if value is to high
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001754 if (*((signed u64 *)pData_p) > *((signed u64 *)pRangeData)) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001755 Ret = kEplObdValueTooHigh;
1756 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001757
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001758 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001759
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001760 // -----------------------------------------------------------------
1761 case kEplObdTypUInt40:
1762 case kEplObdTypUInt48:
1763 case kEplObdTypUInt56:
1764 case kEplObdTypUInt64:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001765
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001766 // switch to lower limit
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001767 pRangeData = ((unsigned u64 *)pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001768
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001769 // check if value is to low
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001770 if (*((unsigned u64 *)pData_p) <
1771 *((unsigned u64 *)pRangeData)) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001772 Ret = kEplObdValueTooLow;
1773 break;
1774 }
1775 // switch to higher limit
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001776 pRangeData = ((unsigned u64 *)pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001777
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001778 // check if value is to high
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001779 if (*((unsigned u64 *)pData_p) >
1780 *((unsigned u64 *)pRangeData)) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001781 Ret = kEplObdValueTooHigh;
1782 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001783
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001784 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001785
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001786 // -----------------------------------------------------------------
1787 case kEplObdTypReal64:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001788
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001789 // switch to lower limit
1790 pRangeData = ((tEplObdReal64 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001791
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001792 // check if value is to low
1793 if (*((tEplObdReal64 *) pData_p) <
1794 *((tEplObdReal64 *) pRangeData)) {
1795 Ret = kEplObdValueTooLow;
1796 break;
1797 }
1798 // switch to higher limit
1799 pRangeData = ((tEplObdReal64 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001800
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001801 // check if value is to high
1802 if (*((tEplObdReal64 *) pData_p) >
1803 *((tEplObdReal64 *) pRangeData)) {
1804 Ret = kEplObdValueTooHigh;
1805 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001806
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001807 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001808
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001809 // -----------------------------------------------------------------
1810 case kEplObdTypTimeOfDay:
1811 case kEplObdTypTimeDiff:
1812 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001813
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001814 // -----------------------------------------------------------------
1815 // ObdTypes kEplObdTypXString and kEplObdTypDomain can not be checkt because
1816 // they have no numerical value.
1817 default:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001818
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001819 Ret = kEplObdUnknownObjectType;
1820 break;
1821 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001822
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001823 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001824
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001825 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001826
1827}
1828#endif // (EPL_OBD_CHECK_OBJECT_RANGE != FALSE)
1829
1830//---------------------------------------------------------------------------
1831//
1832// Function: EplObdWriteEntryPre()
1833//
1834// Description: Function prepares write of data to an OBD entry. Strings
1835// are stored with added '\0' character.
1836//
1837// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
1838// uiIndex_p = Index of the OD entry
1839// uiSubIndex_p = Subindex of the OD Entry
1840// pSrcData_p = Pointer to the data to write
1841// Size_p = Size of the data in Byte
1842//
1843// Return: tEplKernel = Errorcode
1844//
1845//
1846// State:
1847//
1848//---------------------------------------------------------------------------
1849
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001850static tEplKernel EplObdWriteEntryPre(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1851 unsigned int uiSubIndex_p,
1852 void *pSrcData_p,
1853 void **ppDstData_p,
1854 tEplObdSize Size_p,
1855 tEplObdEntryPtr *ppObdEntry_p,
1856 tEplObdSubEntryPtr *ppSubEntry_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001857 tEplObdCbParam *pCbParam_p,
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001858 tEplObdSize *pObdSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001859{
1860
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001861 tEplKernel Ret;
1862 tEplObdEntryPtr pObdEntry;
1863 tEplObdSubEntryPtr pSubEntry;
1864 tEplObdAccess Access;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001865 void *pDstData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001866 tEplObdSize ObdSize;
1867 BOOL fEntryNumerical;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001868
1869#if (EPL_OBD_USE_STRING_DOMAIN_IN_RAM != FALSE)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001870 tEplObdVStringDomain MemVStringDomain;
1871 void *pCurrData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001872#endif
1873
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001874 // check for all API function if instance is valid
1875 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001876
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001877 ASSERT(pSrcData_p != NULL); // should never be NULL
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001878
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001879 //------------------------------------------------------------------------
1880 // get address of index and subindex entry
1881 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
1882 uiIndex_p, uiSubIndex_p, &pObdEntry, &pSubEntry);
1883 if (Ret != kEplSuccessful) {
1884 goto Exit;
1885 }
1886 // get pointer to object data
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001887 pDstData = (void *)EplObdGetObjectDataPtrIntern(pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001888
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001889 Access = (tEplObdAccess) pSubEntry->m_Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001890
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001891 // check access for write
1892 // access violation if adress to current value is NULL
1893 if (((Access & kEplObdAccConst) != 0) || (pDstData == NULL)) {
1894 Ret = kEplObdAccessViolation;
1895 goto Exit;
1896 }
1897 //------------------------------------------------------------------------
1898 // get size of object
1899 // -as ObdSize = ObdGetObjectSize (pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001900
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001901 //------------------------------------------------------------------------
1902 // To use the same callback function for ObdWriteEntry as well as for
1903 // an SDO download call at first (kEplObdEvPre...) the callback function
1904 // with the argument pointer to object size.
1905 pCbParam_p->m_uiIndex = uiIndex_p;
1906 pCbParam_p->m_uiSubIndex = uiSubIndex_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001907
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001908 // Because object size and object pointer are
1909 // adapted by user callback function, re-read
1910 // this values.
1911 ObdSize = EplObdGetObjectSize(pSubEntry);
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001912 pDstData = (void *)EplObdGetObjectDataPtrIntern(pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001913
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001914 // 09-dec-2004 r.d.:
1915 // Function EplObdWriteEntry() calls new event kEplObdEvWrStringDomain
1916 // for String or Domain which lets called module directly change
1917 // the data pointer or size. This prevents a recursive call to
1918 // the callback function if it calls EplObdGetEntry().
1919#if (EPL_OBD_USE_STRING_DOMAIN_IN_RAM != FALSE)
1920 if ((pSubEntry->m_Type == kEplObdTypVString) ||
1921 (pSubEntry->m_Type == kEplObdTypDomain) ||
1922 (pSubEntry->m_Type == kEplObdTypOString)) {
1923 if (pSubEntry->m_Type == kEplObdTypVString) {
1924 // reserve one byte for 0-termination
1925 // -as ObdSize -= 1;
1926 Size_p += 1;
1927 }
1928 // fill out new arg-struct
1929 MemVStringDomain.m_DownloadSize = Size_p;
1930 MemVStringDomain.m_ObjSize = ObdSize;
1931 MemVStringDomain.m_pData = pDstData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001932
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001933 pCbParam_p->m_ObdEvent = kEplObdEvWrStringDomain;
1934 pCbParam_p->m_pArg = &MemVStringDomain;
1935 // call user callback
1936 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
1937 pObdEntry->m_fpCallback,
1938 pCbParam_p);
1939 if (Ret != kEplSuccessful) {
1940 goto Exit;
1941 }
1942 // write back new settings
1943 pCurrData = pSubEntry->m_pCurrent;
1944 if ((pSubEntry->m_Type == kEplObdTypVString)
1945 || (pSubEntry->m_Type == kEplObdTypOString)) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001946 ((tEplObdVString *)pCurrData)->m_Size = MemVStringDomain.m_ObjSize;
1947 ((tEplObdVString *)pCurrData)->m_pString = MemVStringDomain.m_pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001948 } else // if (pSdosTableEntry_p->m_bObjType == kEplObdTypDomain)
1949 {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001950 ((tEplObdVarEntry *)pCurrData)->m_Size = MemVStringDomain.m_ObjSize;
1951 ((tEplObdVarEntry *)pCurrData)->m_pData = (void *)MemVStringDomain.m_pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001952 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001953
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001954 // Because object size and object pointer are
1955 // adapted by user callback function, re-read
1956 // this values.
1957 ObdSize = MemVStringDomain.m_ObjSize;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001958 pDstData = (void *)MemVStringDomain.m_pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001959 }
1960#endif //#if (OBD_USE_STRING_DOMAIN_IN_RAM != FALSE)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001961
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001962 // 07-dec-2004 r.d.: size from application is needed because callback function can change the object size
1963 // -as 16.11.04 CbParam.m_pArg = &ObdSize;
1964 // 09-dec-2004 r.d.: CbParam.m_pArg = &Size_p;
1965 pCbParam_p->m_pArg = &ObdSize;
1966 pCbParam_p->m_ObdEvent = kEplObdEvInitWrite;
1967 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
1968 pObdEntry->m_fpCallback, pCbParam_p);
1969 if (Ret != kEplSuccessful) {
1970 goto Exit;
1971 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001972
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001973 if (Size_p > ObdSize) {
1974 Ret = kEplObdValueLengthError;
1975 goto Exit;
1976 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001977
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001978 if (pSubEntry->m_Type == kEplObdTypVString) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001979 if (((char *)pSrcData_p)[Size_p - 1] == '\0') { // last byte of source string contains null character
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001980
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001981 // reserve one byte in destination for 0-termination
1982 Size_p -= 1;
1983 } else if (Size_p >= ObdSize) { // source string is not 0-terminated
1984 // and destination buffer is too short
1985 Ret = kEplObdValueLengthError;
1986 goto Exit;
1987 }
1988 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001989
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001990 Ret = EplObdIsNumericalIntern(pSubEntry, &fEntryNumerical);
1991 if (Ret != kEplSuccessful) {
1992 goto Exit;
1993 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001994
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001995 if ((fEntryNumerical != FALSE)
1996 && (Size_p != ObdSize)) {
1997 // type is numerical, therefor size has to fit, but it does not.
1998 Ret = kEplObdValueLengthError;
1999 goto Exit;
2000 }
2001 // use given size, because non-numerical objects can be written with shorter values
2002 ObdSize = Size_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002003
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002004 // set output parameters
2005 *pObdSize_p = ObdSize;
2006 *ppObdEntry_p = pObdEntry;
2007 *ppSubEntry_p = pSubEntry;
2008 *ppDstData_p = pDstData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002009
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002010 // all checks are done
2011 // the caller may now convert the numerial source value to platform byte order in a temporary buffer
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002012
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002013 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002014
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002015 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002016
2017}
2018
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002019//---------------------------------------------------------------------------
2020//
2021// Function: EplObdWriteEntryPost()
2022//
2023// Description: Function finishes write of data to an OBD entry. Strings
2024// are stored with added '\0' character.
2025//
2026// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
2027// uiIndex_p = Index of the OD entry
2028// uiSubIndex_p = Subindex of the OD Entry
2029// pSrcData_p = Pointer to the data to write
2030// Size_p = Size of the data in Byte
2031//
2032// Return: tEplKernel = Errorcode
2033//
2034//
2035// State:
2036//
2037//---------------------------------------------------------------------------
2038
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07002039static tEplKernel EplObdWriteEntryPost(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdEntryPtr pObdEntry_p,
2040 tEplObdSubEntryPtr pSubEntry_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002041 tEplObdCbParam *pCbParam_p,
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07002042 void *pSrcData_p,
2043 void *pDstData_p,
2044 tEplObdSize ObdSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002045{
2046
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002047 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002048
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002049 // caller converted the source value to platform byte order
2050 // now the range of the value may be checked
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002051
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002052#if (EPL_OBD_CHECK_OBJECT_RANGE != FALSE)
2053 {
2054 // check data range
2055 Ret = EplObdCheckObjectRange(pSubEntry_p, pSrcData_p);
2056 if (Ret != kEplSuccessful) {
2057 goto Exit;
2058 }
2059 }
2060#endif
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002061
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002062 // now call user callback function to check value
2063 // write address of source data to structure of callback parameters
2064 // so callback function can check this data
2065 pCbParam_p->m_pArg = pSrcData_p;
2066 pCbParam_p->m_ObdEvent = kEplObdEvPreWrite;
2067 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
2068 pObdEntry_p->m_fpCallback, pCbParam_p);
2069 if (Ret != kEplSuccessful) {
2070 goto Exit;
2071 }
2072 // copy object data to OBD
2073 EPL_MEMCPY(pDstData_p, pSrcData_p, ObdSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002074
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002075 // terminate string with 0
2076 if (pSubEntry_p->m_Type == kEplObdTypVString) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002077 ((char *)pDstData_p)[ObdSize_p] = '\0';
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002078 }
2079 // write address of destination to structure of callback parameters
2080 // so callback function can change data subsequently
2081 pCbParam_p->m_pArg = pDstData_p;
2082 pCbParam_p->m_ObdEvent = kEplObdEvPostWrite;
2083 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
2084 pObdEntry_p->m_fpCallback, pCbParam_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002085
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002086 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002087
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002088 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002089
2090}
2091
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002092//---------------------------------------------------------------------------
2093//
2094// Function: EplObdGetObjectSize()
2095//
2096// Description: function to get size of object
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002097// The function determines if an object type an fixed data type (u8, WORD, ...)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002098// or non fixed object (string, domain). This information is used to decide
2099// if download data are stored temporary or not. For objects with fixed data length
2100// and types a value range checking can process.
2101// For strings the function returns the whole object size not the
2102// length of string.
2103//
2104// Parameters: pSubIndexEntry_p
2105//
2106// Return: tEplObdSize
2107//
2108// State:
2109//
2110//---------------------------------------------------------------------------
2111
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002112static tEplObdSize EplObdGetObjectSize(tEplObdSubEntryPtr pSubIndexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002113{
2114
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002115 tEplObdSize DataSize = 0;
2116 void *pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002117
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002118 switch (pSubIndexEntry_p->m_Type) {
2119 // -----------------------------------------------------------------
2120 case kEplObdTypBool:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002121
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002122 DataSize = 1;
2123 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002124
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002125 // -----------------------------------------------------------------
2126 // ObdTypes which has to be check because numerical values
2127 case kEplObdTypInt8:
2128 DataSize = sizeof(tEplObdInteger8);
2129 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002130
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002131 // -----------------------------------------------------------------
2132 case kEplObdTypUInt8:
2133 DataSize = sizeof(tEplObdUnsigned8);
2134 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002135
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002136 // -----------------------------------------------------------------
2137 case kEplObdTypInt16:
2138 DataSize = sizeof(tEplObdInteger16);
2139 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002140
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002141 // -----------------------------------------------------------------
2142 case kEplObdTypUInt16:
2143 DataSize = sizeof(tEplObdUnsigned16);
2144 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002145
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002146 // -----------------------------------------------------------------
2147 case kEplObdTypInt32:
2148 DataSize = sizeof(tEplObdInteger32);
2149 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002150
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002151 // -----------------------------------------------------------------
2152 case kEplObdTypUInt32:
2153 DataSize = sizeof(tEplObdUnsigned32);
2154 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002155
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002156 // -----------------------------------------------------------------
2157 case kEplObdTypReal32:
2158 DataSize = sizeof(tEplObdReal32);
2159 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002160
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002161 // -----------------------------------------------------------------
2162 // ObdTypes which has to be not checked because not NUM values
2163 case kEplObdTypDomain:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002164
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002165 pData = (void *)pSubIndexEntry_p->m_pCurrent;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002166 if ((void *)pData != (void *)NULL) {
2167 DataSize = ((tEplObdVarEntry *) pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002168 }
2169 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002170
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002171 // -----------------------------------------------------------------
2172 case kEplObdTypVString:
2173 //case kEplObdTypUString:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002174
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002175 // If OD entry is defined by macro EPL_OBD_SUBINDEX_ROM_VSTRING
2176 // then the current pointer is always NULL. The function
2177 // returns the length of default string.
2178 pData = (void *)pSubIndexEntry_p->m_pCurrent;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002179 if ((void *)pData != (void *)NULL) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002180 // The max. size of strings defined by STRING-Macro is stored in
2181 // tEplObdVString of current value.
2182 // (types tEplObdVString, tEplObdOString and tEplObdUString has the same members)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002183 DataSize = ((tEplObdVString *) pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002184 } else {
2185 // The current position is not decleared. The string
2186 // is located in ROM, therefor use default pointer.
2187 pData = (void *)pSubIndexEntry_p->m_pDefault;
Greg Kroah-Hartman5d9d5eb2009-03-23 12:24:46 -07002188 if ((const void *)pData != (const void *)NULL) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002189 // The max. size of strings defined by STRING-Macro is stored in
2190 // tEplObdVString of default value.
Greg Kroah-Hartman5d9d5eb2009-03-23 12:24:46 -07002191 DataSize = ((const tEplObdVString *)pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002192 }
2193 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002194
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002195 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002196
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002197 // -----------------------------------------------------------------
2198 case kEplObdTypOString:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002199
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002200 pData = (void *)pSubIndexEntry_p->m_pCurrent;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002201 if ((void *)pData != (void *)NULL) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002202 // The max. size of strings defined by STRING-Macro is stored in
2203 // tEplObdVString of current value.
2204 // (types tEplObdVString, tEplObdOString and tEplObdUString has the same members)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002205 DataSize = ((tEplObdOString *) pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002206 } else {
2207 // The current position is not decleared. The string
2208 // is located in ROM, therefor use default pointer.
2209 pData = (void *)pSubIndexEntry_p->m_pDefault;
Greg Kroah-Hartman5d9d5eb2009-03-23 12:24:46 -07002210 if ((const void *)pData != (const void *)NULL) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002211 // The max. size of strings defined by STRING-Macro is stored in
2212 // tEplObdVString of default value.
Greg Kroah-Hartman5d9d5eb2009-03-23 12:24:46 -07002213 DataSize = ((const tEplObdOString *)pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002214 }
2215 }
2216 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002217
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002218 // -----------------------------------------------------------------
2219 case kEplObdTypInt24:
2220 case kEplObdTypUInt24:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002221
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002222 DataSize = 3;
2223 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002224
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002225 // -----------------------------------------------------------------
2226 case kEplObdTypInt40:
2227 case kEplObdTypUInt40:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002228
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002229 DataSize = 5;
2230 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002231
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002232 // -----------------------------------------------------------------
2233 case kEplObdTypInt48:
2234 case kEplObdTypUInt48:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002235
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002236 DataSize = 6;
2237 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002238
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002239 // -----------------------------------------------------------------
2240 case kEplObdTypInt56:
2241 case kEplObdTypUInt56:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002242
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002243 DataSize = 7;
2244 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002245
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002246 // -----------------------------------------------------------------
2247 case kEplObdTypInt64:
2248 case kEplObdTypUInt64:
2249 case kEplObdTypReal64:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002250
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002251 DataSize = 8;
2252 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002253
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002254 // -----------------------------------------------------------------
2255 case kEplObdTypTimeOfDay:
2256 case kEplObdTypTimeDiff:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002257
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002258 DataSize = 6;
2259 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002260
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002261 // -----------------------------------------------------------------
2262 default:
2263 break;
2264 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002265
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002266 return DataSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002267}
2268
2269//---------------------------------------------------------------------------
2270//
2271// Function: EplObdGetObjectDefaultPtr()
2272//
2273// Description: function to get the default pointer (type specific)
2274//
2275// Parameters: pSubIndexEntry_p = pointer to subindex structure
2276//
2277// Returns: (void *) = pointer to default value
2278//
2279// State:
2280//
2281//---------------------------------------------------------------------------
2282
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002283static void *EplObdGetObjectDefaultPtr(tEplObdSubEntryPtr pSubIndexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002284{
2285
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002286 void *pDefault;
2287 tEplObdType Type;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002288
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002289 ASSERTMSG(pSubIndexEntry_p != NULL,
2290 "EplObdGetObjectDefaultPtr(): pointer to SubEntry not valid!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002291
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002292 // get address to default data from default pointer
2293 pDefault = pSubIndexEntry_p->m_pDefault;
2294 if (pDefault != NULL) {
2295 // there are some special types, whose default pointer always is NULL or has to get from other structure
2296 // get type from subindex structure
2297 Type = pSubIndexEntry_p->m_Type;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002298
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002299 // check if object type is a string value
2300 if ((Type == kEplObdTypVString) /* ||
2301 (Type == kEplObdTypUString) */ ) {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002302
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002303 // EPL_OBD_SUBINDEX_RAM_VSTRING
2304 // tEplObdSize m_Size; --> size of default string
2305 // char * m_pDefString; --> pointer to default string
2306 // char * m_pString; --> pointer to string in RAM
2307 //
2308 pDefault =
2309 (void *)((tEplObdVString *) pDefault)->m_pString;
2310 } else if (Type == kEplObdTypOString) {
2311 pDefault =
2312 (void *)((tEplObdOString *) pDefault)->m_pString;
2313 }
2314 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002315
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002316 return pDefault;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002317
2318}
2319
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002320//---------------------------------------------------------------------------
2321//
2322// Function: EplObdGetVarEntry()
2323//
2324// Description: gets a variable entry of an object
2325//
2326// Parameters: pSubindexEntry_p
2327// ppVarEntry_p
2328//
2329// Return: tCopKernel
2330//
2331// State:
2332//
2333//---------------------------------------------------------------------------
2334
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002335static tEplKernel EplObdGetVarEntry(tEplObdSubEntryPtr pSubindexEntry_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002336 tEplObdVarEntry **ppVarEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002337{
2338
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002339 tEplKernel Ret = kEplObdVarEntryNotExist;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002340
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002341 ASSERT(ppVarEntry_p != NULL); // is not allowed to be NULL
2342 ASSERT(pSubindexEntry_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002343
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002344 // check VAR-Flag - only this object points to variables
2345 if ((pSubindexEntry_p->m_Access & kEplObdAccVar) != 0) {
2346 // check if object is an array
2347 if ((pSubindexEntry_p->m_Access & kEplObdAccArray) != 0) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002348 *ppVarEntry_p = &((tEplObdVarEntry *)pSubindexEntry_p->m_pCurrent)[pSubindexEntry_p->m_uiSubIndex - 1];
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002349 } else {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002350 *ppVarEntry_p = (tEplObdVarEntry *)pSubindexEntry_p->m_pCurrent;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002351 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002352
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002353 Ret = kEplSuccessful;
2354 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002355
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002356 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002357
2358}
2359
2360//---------------------------------------------------------------------------
2361//
2362// Function: EplObdGetEntry()
2363//
2364// Description: gets a index entry from OD
2365//
2366// Parameters: uiIndex_p = Index number
2367// uiSubindex_p = Subindex number
2368// ppObdEntry_p = pointer to the pointer to the entry
2369// ppObdSubEntry_p = pointer to the pointer to the subentry
2370//
2371// Return: tEplKernel
2372
2373//
2374// State:
2375//
2376//---------------------------------------------------------------------------
2377
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002378static tEplKernel EplObdGetEntry(EPL_MCO_DECL_INSTANCE_PTR_
2379 unsigned int uiIndex_p,
2380 unsigned int uiSubindex_p,
2381 tEplObdEntryPtr * ppObdEntry_p,
2382 tEplObdSubEntryPtr * ppObdSubEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002383{
2384
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002385 tEplObdEntryPtr pObdEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002386 tEplObdCbParam CbParam;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002387 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002388
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002389 // check for all API function if instance is valid
2390 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002391
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002392 //------------------------------------------------------------------------
2393 // get address of entry of index
2394 Ret =
2395 EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam), uiIndex_p,
2396 &pObdEntry);
2397 if (Ret != kEplSuccessful) {
2398 goto Exit;
2399 }
2400 //------------------------------------------------------------------------
2401 // get address of entry of subindex
2402 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubindex_p, ppObdSubEntry_p);
2403 if (Ret != kEplSuccessful) {
2404 goto Exit;
2405 }
2406 //------------------------------------------------------------------------
2407 // call callback function to inform user/stack that an object will be searched
2408 // if the called module returnes an error then we abort the searching with kEplObdIndexNotExist
2409 CbParam.m_uiIndex = uiIndex_p;
2410 CbParam.m_uiSubIndex = uiSubindex_p;
2411 CbParam.m_pArg = NULL;
2412 CbParam.m_ObdEvent = kEplObdEvCheckExist;
2413 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
2414 pObdEntry->m_fpCallback, &CbParam);
2415 if (Ret != kEplSuccessful) {
2416 Ret = kEplObdIndexNotExist;
2417 goto Exit;
2418 }
2419 //------------------------------------------------------------------------
2420 // it is allowed to set ppObdEntry_p to NULL
2421 // if so, no address will be written to calling function
2422 if (ppObdEntry_p != NULL) {
2423 *ppObdEntry_p = pObdEntry;
2424 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002425
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002426 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002427
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002428 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002429
2430}
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002431
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002432//---------------------------------------------------------------------------
2433//
2434// Function: EplObdGetObjectCurrentPtr()
2435//
2436// Description: function to get Current pointer (type specific)
2437//
2438// Parameters: pSubIndexEntry_p
2439//
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002440// Return: void *
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002441//
2442// State:
2443//
2444//---------------------------------------------------------------------------
2445
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002446static void *EplObdGetObjectCurrentPtr(tEplObdSubEntryPtr pSubIndexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002447{
2448
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002449 void *pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002450 unsigned int uiArrayIndex;
2451 tEplObdSize Size;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002452
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002453 pData = pSubIndexEntry_p->m_pCurrent;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002454
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002455 // check if constant object
2456 if (pData != NULL) {
2457 // check if object is an array
2458 if ((pSubIndexEntry_p->m_Access & kEplObdAccArray) != 0) {
2459 // calculate correct data pointer
2460 uiArrayIndex = pSubIndexEntry_p->m_uiSubIndex - 1;
2461 if ((pSubIndexEntry_p->m_Access & kEplObdAccVar) != 0) {
2462 Size = sizeof(tEplObdVarEntry);
2463 } else {
2464 Size = EplObdGetObjectSize(pSubIndexEntry_p);
2465 }
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002466 pData = ((u8 *) pData) + (Size * uiArrayIndex);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002467 }
2468 // check if VarEntry
2469 if ((pSubIndexEntry_p->m_Access & kEplObdAccVar) != 0) {
2470 // The data pointer is stored in VarEntry->pData
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002471 pData = ((tEplObdVarEntry *) pData)->m_pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002472 }
2473 // the default pointer is stored for strings in tEplObdVString
2474 else if ((pSubIndexEntry_p->m_Type == kEplObdTypVString) /* ||
2475 (pSubIndexEntry_p->m_Type == kEplObdTypUString) */
2476 ) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002477 pData = (void *)((tEplObdVString *)pData)->m_pString;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002478 } else if (pSubIndexEntry_p->m_Type == kEplObdTypOString) {
2479 pData =
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002480 (void *)((tEplObdOString *)pData)->m_pString;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002481 }
2482 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002483
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002484 return pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002485
2486}
2487
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002488//---------------------------------------------------------------------------
2489//
2490// Function: EplObdGetIndexIntern()
2491//
2492// Description: gets a index entry from OD
2493//
2494// Parameters: pInitParam_p
2495// uiIndex_p
2496// ppObdEntry_p
2497//
2498// Return: tEplKernel
2499//
2500// State:
2501//
2502//---------------------------------------------------------------------------
2503
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002504static tEplKernel EplObdGetIndexIntern(tEplObdInitParam *pInitParam_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002505 unsigned int uiIndex_p,
2506 tEplObdEntryPtr * ppObdEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002507{
2508
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002509 tEplObdEntryPtr pObdEntry;
2510 tEplKernel Ret;
2511 unsigned int uiIndex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002512
2513#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
2514
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002515 unsigned int nLoop;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002516
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002517 // if user OD is used then objekts also has to be searched in user OD
2518 // there is less code need if we do this in a loop
2519 nLoop = 2;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002520
2521#endif
2522
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002523 ASSERTMSG(ppObdEntry_p != NULL,
2524 "EplObdGetIndexIntern(): pointer to index entry is NULL!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002525
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002526 Ret = kEplObdIndexNotExist;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002527
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002528 // get start address of OD part
2529 // start address depends on object index because
2530 // object dictionary is divided in 3 parts
2531 if ((uiIndex_p >= 0x1000) && (uiIndex_p < 0x2000)) {
2532 pObdEntry = pInitParam_p->m_pPart;
2533 } else if ((uiIndex_p >= 0x2000) && (uiIndex_p < 0x6000)) {
2534 pObdEntry = pInitParam_p->m_pManufacturerPart;
2535 }
2536 // index range 0xA000 to 0xFFFF is reserved for DSP-405
2537 // DS-301 defines that range 0x6000 to 0x9FFF (!!!) is stored if "store" was written to 0x1010/3.
2538 // Therefore default configuration is OBD_INCLUDE_A000_TO_DEVICE_PART = FALSE.
2539 // But a CANopen Application which does not implement dynamic OD or user-OD but wants to use static objets 0xA000...
2540 // should set OBD_INCLUDE_A000_TO_DEVICE_PART to TRUE.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002541
2542#if (EPL_OBD_INCLUDE_A000_TO_DEVICE_PART == FALSE)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002543 else if ((uiIndex_p >= 0x6000) && (uiIndex_p < 0x9FFF))
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002544#else
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002545 else if ((uiIndex_p >= 0x6000) && (uiIndex_p < 0xFFFF))
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002546#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002547 {
2548 pObdEntry = pInitParam_p->m_pDevicePart;
2549 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002550
2551#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
2552
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002553 // if index does not match in static OD then index only has to be searched in user OD
2554 else {
2555 // begin from first entry of user OD part
2556 pObdEntry = pInitParam_p->m_pUserPart;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002557
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002558 // no user OD is available
2559 if (pObdEntry == NULL) {
2560 goto Exit;
2561 }
2562 // loop must only run once
2563 nLoop = 1;
2564 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002565
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002566 do {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002567
2568#else
2569
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002570 // no user OD is available
2571 // so other object can be found in OD
2572 else {
2573 Ret = kEplObdIllegalPart;
2574 goto Exit;
2575 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002576
2577#endif
2578
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002579 // note:
2580 // The end of Index table is marked with m_uiIndex = 0xFFFF.
2581 // If this function will be called with wIndex_p = 0xFFFF, entry
2582 // should not be found. Therefor it is important to use
2583 // while{} instead of do{}while !!!
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002584
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002585 // get first index of index table
2586 uiIndex = pObdEntry->m_uiIndex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002587
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002588 // search Index in OD part
2589 while (uiIndex != EPL_OBD_TABLE_INDEX_END) {
2590 // go to the end of this function if index is found
2591 if (uiIndex_p == uiIndex) {
2592 // write address of OD entry to calling function
2593 *ppObdEntry_p = pObdEntry;
2594 Ret = kEplSuccessful;
2595 goto Exit;
2596 }
2597 // objects are sorted in OD
2598 // if the current index in OD is greater than the index which is to search then break loop
2599 // in this case user OD has to be search too
2600 if (uiIndex_p < uiIndex) {
2601 break;
2602 }
2603 // next entry in index table
2604 pObdEntry++;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002605
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002606 // get next index of index table
2607 uiIndex = pObdEntry->m_uiIndex;
2608 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002609
2610#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
2611
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002612 // begin from first entry of user OD part
2613 pObdEntry = pInitParam_p->m_pUserPart;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002614
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002615 // no user OD is available
2616 if (pObdEntry == NULL) {
2617 goto Exit;
2618 }
2619 // switch next loop for user OD
2620 nLoop--;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002621
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002622}
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002623
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002624while (nLoop > 0) ;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002625
2626#endif
2627
2628 // in this line Index was not found
2629
2630Exit:
2631
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002632return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002633
2634}
2635
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002636//---------------------------------------------------------------------------
2637//
2638// Function: EplObdGetSubindexIntern()
2639//
2640// Description: gets a subindex entry from a index entry
2641//
2642// Parameters: pObdEntry_p
2643// bSubIndex_p
2644// ppObdSubEntry_p
2645//
2646// Return: tEplKernel
2647//
2648// State:
2649//
2650//---------------------------------------------------------------------------
2651
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002652static tEplKernel EplObdGetSubindexIntern(tEplObdEntryPtr pObdEntry_p,
2653 unsigned int uiSubIndex_p,
2654 tEplObdSubEntryPtr * ppObdSubEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002655{
2656
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002657 tEplObdSubEntryPtr pSubEntry;
2658 unsigned int nSubIndexCount;
2659 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002660
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002661 ASSERTMSG(pObdEntry_p != NULL,
2662 "EplObdGetSubindexIntern(): pointer to index is NULL!\n");
2663 ASSERTMSG(ppObdSubEntry_p != NULL,
2664 "EplObdGetSubindexIntern(): pointer to subindex is NULL!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002665
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002666 Ret = kEplObdSubindexNotExist;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002667
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002668 // get start address of subindex table and count of subindices
2669 pSubEntry = pObdEntry_p->m_pSubIndex;
2670 nSubIndexCount = pObdEntry_p->m_uiCount;
2671 ASSERTMSG((pSubEntry != NULL) && (nSubIndexCount > 0), "ObdGetSubindexIntern(): invalid subindex table within index table!\n"); // should never be NULL
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002672
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002673 // search subindex in subindex table
2674 while (nSubIndexCount > 0) {
2675 // check if array is found
2676 if ((pSubEntry->m_Access & kEplObdAccArray) != 0) {
2677 // check if subindex is in range
2678 if (uiSubIndex_p < pObdEntry_p->m_uiCount) {
2679 // update subindex number (subindex entry of an array is always in RAM !!!)
2680 pSubEntry->m_uiSubIndex = uiSubIndex_p;
2681 *ppObdSubEntry_p = pSubEntry;
2682 Ret = kEplSuccessful;
2683 goto Exit;
2684 }
2685 }
2686 // go to the end of this function if subindex is found
2687 else if (uiSubIndex_p == pSubEntry->m_uiSubIndex) {
2688 *ppObdSubEntry_p = pSubEntry;
2689 Ret = kEplSuccessful;
2690 goto Exit;
2691 }
2692 // objects are sorted in OD
2693 // if the current subindex in OD is greater than the subindex which is to search then break loop
2694 // in this case user OD has to be search too
2695 if (uiSubIndex_p < pSubEntry->m_uiSubIndex) {
2696 break;
2697 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002698
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002699 pSubEntry++;
2700 nSubIndexCount--;
2701 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002702
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002703 // in this line SubIndex was not fount
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002704
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002705 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002706
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002707 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002708
2709}
2710
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002711//---------------------------------------------------------------------------
2712//
2713// Function: EplObdSetStoreLoadObjCallback()
2714//
2715// Description: function set address to callbackfunction for command Store and Load
2716//
2717// Parameters: fpCallback_p
2718//
2719// Return: tEplKernel
2720//
2721// State:
2722//
2723//---------------------------------------------------------------------------
2724#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07002725EPLDLLEXPORT tEplKernel EplObdSetStoreLoadObjCallback(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdStoreLoadObjCallback fpCallback_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002726{
2727
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002728 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002729
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002730 // set new address of callback function
2731 EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback) = fpCallback_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002732
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002733 return kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002734
2735}
2736#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
2737
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002738//---------------------------------------------------------------------------
2739//
2740// Function: EplObdAccessOdPartIntern()
2741//
2742// Description: runs through OD and executes a job
2743//
2744// Parameters: CurrentOdPart_p
2745// pObdEnty_p
2746// Direction_p = what is to do (load values from flash or EEPROM, store, ...)
2747//
2748// Return: tEplKernel
2749//
2750// State:
2751//
2752//---------------------------------------------------------------------------
2753
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002754static tEplKernel EplObdAccessOdPartIntern(EPL_MCO_DECL_INSTANCE_PTR_
2755 tEplObdPart CurrentOdPart_p,
2756 tEplObdEntryPtr pObdEnty_p,
2757 tEplObdDir Direction_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002758{
2759
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002760 tEplObdSubEntryPtr pSubIndex;
2761 unsigned int nSubIndexCount;
2762 tEplObdAccess Access;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002763 void *pDstData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002764 void *pDefault;
2765 tEplObdSize ObjSize;
2766 tEplKernel Ret;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002767 tEplObdCbStoreParam CbStore;
2768 tEplObdVarEntry *pVarEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002769
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002770 ASSERT(pObdEnty_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002771
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002772 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002773
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002774 // prepare structure for STORE RESTORE callback function
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002775 CbStore.m_bCurrentOdPart = (u8) CurrentOdPart_p;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002776 CbStore.m_pData = NULL;
2777 CbStore.m_ObjSize = 0;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002778
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002779 // command of first action depends on direction to access
2780#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
2781 if (Direction_p == kEplObdDirLoad) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002782 CbStore.m_bCommand = (u8) kEplObdCommOpenRead;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002783
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002784 // call callback function for previous command
2785 Ret = EplObdCallStoreCallback(EPL_MCO_INSTANCE_PTR_ & CbStore);
2786 if (Ret != kEplSuccessful) {
2787 goto Exit;
2788 }
2789 // set command for index and subindex loop
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002790 CbStore.m_bCommand = (u8) kEplObdCommReadObj;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002791 } else if (Direction_p == kEplObdDirStore) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002792 CbStore.m_bCommand = (u8) kEplObdCommOpenWrite;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002793
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002794 // call callback function for previous command
2795 Ret = EplObdCallStoreCallback(EPL_MCO_INSTANCE_PTR_ & CbStore);
2796 if (Ret != kEplSuccessful) {
2797 goto Exit;
2798 }
2799 // set command for index and subindex loop
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002800 CbStore.m_bCommand = (u8) kEplObdCommWriteObj;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002801 }
2802#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002803
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002804 // we should not restore the OD values here
2805 // the next NMT command "Reset Node" or "Reset Communication" resets the OD data
2806 if (Direction_p != kEplObdDirRestore) {
2807 // walk through OD part till end is found
2808 while (pObdEnty_p->m_uiIndex != EPL_OBD_TABLE_INDEX_END) {
2809 // get address to subindex table and count of subindices
2810 pSubIndex = pObdEnty_p->m_pSubIndex;
2811 nSubIndexCount = pObdEnty_p->m_uiCount;
2812 ASSERT((pSubIndex != NULL) && (nSubIndexCount > 0)); // should never be NULL
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002813
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002814 // walk through subindex table till all subinices were restored
2815 while (nSubIndexCount != 0) {
2816 Access = (tEplObdAccess) pSubIndex->m_Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002817
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002818 // get pointer to current and default data
2819 pDefault = EplObdGetObjectDefaultPtr(pSubIndex);
2820 pDstData = EplObdGetObjectCurrentPtr(pSubIndex);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002821
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002822 // NOTE (for kEplObdTypVString):
2823 // The function returnes the max. number of bytes for a
2824 // current string.
2825 // r.d.: For stings the default-size will be read in other lines following (kEplObdDirInit).
2826 ObjSize = EplObdGetObjectSize(pSubIndex);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002827
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002828 // switch direction of OD access
2829 switch (Direction_p) {
2830 // --------------------------------------------------------------------------
2831 // VarEntry structures has to be initialized
2832 case kEplObdDirInit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002833
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002834 // If VAR-Flag is set, m_pCurrent means not address of data
2835 // but address of tEplObdVarEntry. Address of data has to be get from
2836 // this structure.
2837 if ((Access & kEplObdAccVar) != 0) {
2838 EplObdGetVarEntry(pSubIndex,
2839 &pVarEntry);
2840 EplObdInitVarEntry(pVarEntry,
2841 pSubIndex->
2842 m_Type,
2843 ObjSize);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002844/*
2845 if ((Access & kEplObdAccArray) == 0)
2846 {
2847 EplObdInitVarEntry (pSubIndex->m_pCurrent, pSubIndex->m_Type, ObjSize);
2848 }
2849 else
2850 {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002851 EplObdInitVarEntry ((tEplObdVarEntry *) (((u8 *) pSubIndex->m_pCurrent) + (sizeof (tEplObdVarEntry) * pSubIndex->m_uiSubIndex)),
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002852 pSubIndex->m_Type, ObjSize);
2853 }
2854*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002855 // at this time no application variable is defined !!!
2856 // therefore data can not be copied.
2857 break;
2858 } else if (pSubIndex->m_Type ==
2859 kEplObdTypVString) {
2860 // If pointer m_pCurrent is not equal to NULL then the
2861 // string was defined with EPL_OBD_SUBINDEX_RAM_VSTRING. The current
2862 // pointer points to struct tEplObdVString located in MEM.
2863 // The element size includes the max. number of
2864 // bytes. The element m_pString includes the pointer
2865 // to string in MEM. The memory location of default string
2866 // must be copied to memory location of current string.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002867
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002868 pDstData =
2869 pSubIndex->m_pCurrent;
2870 if (pDstData != NULL) {
2871 // 08-dec-2004: code optimization !!!
Greg Kroah-Hartman53184872009-03-23 11:48:19 -07002872 // entries ((tEplObdVStringDef*) pSubIndex->m_pDefault)->m_pString
2873 // and ((tEplObdVStringDef*) pSubIndex->m_pDefault)->m_Size were read
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002874 // twice. thats not necessary!
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002875
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002876 // For copying data we have to set the destination pointer to the real RAM string. This
2877 // pointer to RAM string is located in default string info structure. (translated r.d.)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002878 pDstData = (void *)((tEplObdVStringDef*) pSubIndex->m_pDefault)->m_pString;
Greg Kroah-Hartman53184872009-03-23 11:48:19 -07002879 ObjSize = ((tEplObdVStringDef *)pSubIndex->m_pDefault)->m_Size;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002880
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002881 ((tEplObdVString *)pSubIndex->m_pCurrent)->m_pString = pDstData;
2882 ((tEplObdVString *)pSubIndex->m_pCurrent)->m_Size = ObjSize;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002883 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002884
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002885 } else if (pSubIndex->m_Type ==
2886 kEplObdTypOString) {
2887 pDstData =
2888 pSubIndex->m_pCurrent;
2889 if (pDstData != NULL) {
2890 // 08-dec-2004: code optimization !!!
Greg Kroah-Hartman53184872009-03-23 11:48:19 -07002891 // entries ((tEplObdOStringDef*) pSubIndex->m_pDefault)->m_pString
2892 // and ((tEplObdOStringDef*) pSubIndex->m_pDefault)->m_Size were read
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002893 // twice. thats not necessary!
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002894
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002895 // For copying data we have to set the destination pointer to the real RAM string. This
2896 // pointer to RAM string is located in default string info structure. (translated r.d.)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002897 pDstData = (void *)((tEplObdOStringDef *) pSubIndex->m_pDefault)->m_pString;
Greg Kroah-Hartman53184872009-03-23 11:48:19 -07002898 ObjSize = ((tEplObdOStringDef *)pSubIndex->m_pDefault)->m_Size;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002899
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002900 ((tEplObdOString *)pSubIndex->m_pCurrent)->m_pString = pDstData;
2901 ((tEplObdOString *)pSubIndex->m_pCurrent)->m_Size = ObjSize;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002902 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002903
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002904 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002905
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002906 // no break !! because copy of data has to done too.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002907
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002908 // --------------------------------------------------------------------------
2909 // all objects has to be restored with default values
2910 case kEplObdDirRestore:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002911
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002912 // 09-dec-2004 r.d.: optimization! the same code for kEplObdDirRestore and kEplObdDirLoad
2913 // is replaced to function ObdCopyObjectData() with a new parameter.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002914
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002915 // restore object data for init phase
2916 EplObdCopyObjectData(pDstData, pDefault,
2917 ObjSize,
2918 pSubIndex->m_Type);
2919 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002920
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002921 // --------------------------------------------------------------------------
2922 // objects with attribute kEplObdAccStore has to be load from EEPROM or from a file
2923 case kEplObdDirLoad:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002924
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002925 // restore object data for init phase
2926 EplObdCopyObjectData(pDstData, pDefault,
2927 ObjSize,
2928 pSubIndex->m_Type);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002929
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002930 // no break !! because callback function has to be called too.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002931
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002932 // --------------------------------------------------------------------------
2933 // objects with attribute kEplObdAccStore has to be stored in EEPROM or in a file
2934 case kEplObdDirStore:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002935
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002936 // when attribute kEplObdAccStore is set, then call callback function
2937#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
2938 if ((Access & kEplObdAccStore) != 0) {
2939 // fill out data pointer and size of data
2940 CbStore.m_pData = pDstData;
2941 CbStore.m_ObjSize = ObjSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002942
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002943 // call callback function for read or write object
2944 Ret =
2945 ObdCallStoreCallback
2946 (EPL_MCO_INSTANCE_PTR_ &
2947 CbStore);
2948 if (Ret != kEplSuccessful) {
2949 goto Exit;
2950 }
2951 }
2952#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
2953 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002954
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002955 // --------------------------------------------------------------------------
2956 // if OD Builder key has to be checked no access to subindex and data should be made
2957 case kEplObdDirOBKCheck:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002958
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002959 // no break !! because we want to break the second loop too.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002960
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002961 // --------------------------------------------------------------------------
2962 // unknown Direction
2963 default:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002964
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002965 // so we can break the second loop earler
2966 nSubIndexCount = 1;
2967 break;
2968 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002969
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002970 nSubIndexCount--;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002971
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002972 // next subindex entry
2973 if ((Access & kEplObdAccArray) == 0) {
2974 pSubIndex++;
2975 if ((nSubIndexCount > 0)
2976 &&
2977 ((pSubIndex->
2978 m_Access & kEplObdAccArray) !=
2979 0)) {
2980 // next subindex points to an array
2981 // reset subindex number
2982 pSubIndex->m_uiSubIndex = 1;
2983 }
2984 } else {
2985 if (nSubIndexCount > 0) {
2986 // next subindex points to an array
2987 // increment subindex number
2988 pSubIndex->m_uiSubIndex++;
2989 }
2990 }
2991 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002992
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002993 // next index entry
2994 pObdEnty_p++;
2995 }
2996 }
2997 // -----------------------------------------------------------------------------------------
2998 // command of last action depends on direction to access
2999 if (Direction_p == kEplObdDirOBKCheck) {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003000
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003001 goto Exit;
3002 }
3003#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
3004 else {
3005 if (Direction_p == kEplObdDirLoad) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07003006 CbStore.m_bCommand = (u8) kEplObdCommCloseRead;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003007 } else if (Direction_p == kEplObdDirStore) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07003008 CbStore.m_bCommand = (u8) kEplObdCommCloseWrite;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003009 } else if (Direction_p == kEplObdDirRestore) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07003010 CbStore.m_bCommand = (u8) kEplObdCommClear;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003011 } else {
3012 goto Exit;
3013 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003014
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003015 // call callback function for last command
3016 Ret = EplObdCallStoreCallback(EPL_MCO_INSTANCE_PTR_ & CbStore);
3017 }
3018#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003019
3020// goto Exit;
3021
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003022 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003023
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003024 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003025
3026}
3027
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003028// ----------------------------------------------------------------------------
3029// Function: EplObdCopyObjectData()
3030//
3031// Description: checks pointers to object data and copy them from source to destination
3032//
3033// Parameters: pDstData_p = destination pointer
3034// pSrcData_p = source pointer
3035// ObjSize_p = size of object
3036// ObjType_p =
3037//
3038// Returns: tEplKernel = error code
3039// ----------------------------------------------------------------------------
3040
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07003041static void EplObdCopyObjectData(void *pDstData_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003042 void *pSrcData_p,
3043 tEplObdSize ObjSize_p, tEplObdType ObjType_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003044{
3045
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003046 tEplObdSize StrSize = 0;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003047
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003048 // it is allowed to set default and current address to NULL (nothing to copy)
3049 if (pDstData_p != NULL) {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003050
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003051 if (ObjType_p == kEplObdTypVString) {
3052 // The function calculates the really number of characters of string. The
3053 // object entry size can be bigger as string size of default string.
3054 // The '\0'-termination is included. A string with no characters has a
3055 // size of 1.
3056 StrSize =
3057 EplObdGetStrLen((void *)pSrcData_p, ObjSize_p,
3058 kEplObdTypVString);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003059
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003060 // If the string length is greater than or equal to the entry size in OD then only copy
3061 // entry size - 1 and always set the '\0'-termination.
3062 if (StrSize >= ObjSize_p) {
3063 StrSize = ObjSize_p - 1;
3064 }
3065 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003066
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003067 if (pSrcData_p != NULL) {
3068 // copy data
3069 EPL_MEMCPY(pDstData_p, pSrcData_p, ObjSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003070
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003071 if (ObjType_p == kEplObdTypVString) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07003072 ((char *)pDstData_p)[StrSize] = '\0';
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003073 }
3074 }
3075 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003076
3077}
3078
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003079//---------------------------------------------------------------------------
3080//
3081// Function: EplObdIsNumericalIntern()
3082//
3083// Description: function checks if a entry is numerical or not
3084//
3085//
3086// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer
3087// uiIndex_p = Index
3088// uiSubIndex_p = Subindex
3089// pfEntryNumerical_p = pointer to BOOL for returnvalue
3090// -> TRUE if entry a numerical value
3091// -> FALSE if entry not a numerical value
3092//
3093// Return: tEplKernel = Errorcode
3094//
3095// State:
3096//
3097//---------------------------------------------------------------------------
3098static tEplKernel EplObdIsNumericalIntern(tEplObdSubEntryPtr pObdSubEntry_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003099 BOOL * pfEntryNumerical_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003100{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003101 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003102
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003103 // get Type
3104 if ((pObdSubEntry_p->m_Type == kEplObdTypVString)
3105 || (pObdSubEntry_p->m_Type == kEplObdTypOString)
3106 || (pObdSubEntry_p->m_Type == kEplObdTypDomain)) { // not numerical types
3107 *pfEntryNumerical_p = FALSE;
3108 } else { // numerical types
3109 *pfEntryNumerical_p = TRUE;
3110 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003111
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003112 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003113
3114}
3115
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003116// -------------------------------------------------------------------------
3117// function to classify object type (fixed/non fixed)
3118// -------------------------------------------------------------------------
3119
3120// ----------------------------------------------------------------------------
3121// Function: EplObdCallStoreCallback()
3122//
3123// Description: checks address to callback function and calles it when unequal
3124// to NULL
3125//
3126// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = (instance pointer)
3127// pCbStoreParam_p = address to callback parameters
3128//
3129// Returns: tEplKernel = error code
3130// ----------------------------------------------------------------------------
3131#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003132static tEplKernel EplObdCallStoreCallback(EPL_MCO_DECL_INSTANCE_PTR_
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07003133 tEplObdCbStoreParam *
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003134 pCbStoreParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003135{
3136
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003137 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003138
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003139 ASSERT(pCbStoreParam_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003140
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003141 // check if function pointer is NULL - if so, no callback should be called
3142 if (EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback) != NULL) {
3143 Ret =
3144 EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback)
3145 (EPL_MCO_INSTANCE_PARAM_IDX_()
3146 pCbStoreParam_p);
3147 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003148
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003149 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003150
3151}
3152#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
3153//---------------------------------------------------------------------------
3154//
3155// Function: EplObdGetObjectDataPtrIntern()
3156//
3157// Description: Function gets the data pointer of an object.
3158// It returnes the current data pointer. But if object is an
3159// constant object it returnes the default pointer.
3160//
3161// Parameters: pSubindexEntry_p = pointer to subindex entry
3162//
3163// Return: void * = pointer to object data
3164//
3165// State:
3166//
3167//---------------------------------------------------------------------------
3168
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003169void *EplObdGetObjectDataPtrIntern(tEplObdSubEntryPtr pSubindexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003170{
3171
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003172 void *pData;
3173 tEplObdAccess Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003174
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003175 ASSERTMSG(pSubindexEntry_p != NULL,
3176 "EplObdGetObjectDataPtrIntern(): pointer to SubEntry not valid!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003177
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003178 // there are are some objects whose data pointer has to get from other structure
3179 // get access type for this object
3180 Access = pSubindexEntry_p->m_Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003181
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003182 // If object has access type = const,
3183 // for data only exists default values.
3184 if ((Access & kEplObdAccConst) != 0) {
3185 // The pointer to defualt value can be received from ObdGetObjectDefaultPtr()
3186 pData = ((void *)EplObdGetObjectDefaultPtr(pSubindexEntry_p));
3187 } else {
3188 // The pointer to current value can be received from ObdGetObjectCurrentPtr()
3189 pData = ((void *)EplObdGetObjectCurrentPtr(pSubindexEntry_p));
3190 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003191
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003192 return pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003193
3194}
3195#endif // end of #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) != 0)
3196// EOF