blob: 1e463234d81ea831328b8376cd121ac1c14212c4 [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-Hartmand9068d62009-03-23 13:26:29 -0700227tEplKernel 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-Hartmand9068d62009-03-23 13:26:29 -0700259tEplKernel 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-Hartmand9068d62009-03-23 13:26:29 -0700304tEplKernel 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-Hartmand9068d62009-03-23 13:26:29 -0700337tEplKernel EplObdWriteEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
338 unsigned int uiSubIndex_p,
339 void *pSrcData_p, tEplObdSize Size_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800340{
341
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800342 tEplKernel Ret;
343 tEplObdEntryPtr pObdEntry;
344 tEplObdSubEntryPtr pSubEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700345 tEplObdCbParam CbParam;
346 void *pDstData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800347 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800348
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800349 Ret = EplObdWriteEntryPre(EPL_MCO_INSTANCE_PTR_
350 uiIndex_p,
351 uiSubIndex_p,
352 pSrcData_p,
353 &pDstData,
354 Size_p,
355 &pObdEntry, &pSubEntry, &CbParam, &ObdSize);
356 if (Ret != kEplSuccessful) {
357 goto Exit;
358 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800359
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800360 Ret = EplObdWriteEntryPost(EPL_MCO_INSTANCE_PTR_
361 pObdEntry,
362 pSubEntry,
363 &CbParam, pSrcData_p, pDstData, ObdSize);
364 if (Ret != kEplSuccessful) {
365 goto Exit;
366 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800367
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800368 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800369
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800370 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800371
372}
373
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800374//---------------------------------------------------------------------------
375//
376// Function: EplObdReadEntry()
377//
378// Description: The function reads an object entry. The application
379// can always read the data even if attrib kEplObdAccRead
380// is not set. The attrib is only checked up for SDO transfer.
381//
382// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
383// uiIndex_p = Index oof the OD entry to read
384// uiSubIndex_p = Subindex to read
385// pDstData_p = pointer to the buffer for data
386// Offset_p = offset in data for read access
387// pSize_p = IN: Size of the buffer
388// OUT: number of readed Bytes
389//
390// Return: tEplKernel
391//
392// State:
393//
394//---------------------------------------------------------------------------
395
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700396tEplKernel EplObdReadEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
397 unsigned int uiSubIndex_p,
398 void *pDstData_p, tEplObdSize *pSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800399{
400
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800401 tEplKernel Ret;
402 tEplObdEntryPtr pObdEntry;
403 tEplObdSubEntryPtr pSubEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700404 tEplObdCbParam CbParam;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800405 void *pSrcData;
406 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800407
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800408 // check for all API function if instance is valid
409 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800410
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800411 ASSERT(pDstData_p != NULL);
412 ASSERT(pSize_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800413
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800414 // get address of index and subindex entry
415 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
416 uiIndex_p, uiSubIndex_p, &pObdEntry, &pSubEntry);
417 if (Ret != kEplSuccessful) {
418 goto Exit;
419 }
420 // get pointer to object data
421 pSrcData = EplObdGetObjectDataPtrIntern(pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800422
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800423 // check source pointer
424 if (pSrcData == NULL) {
425 Ret = kEplObdReadViolation;
426 goto Exit;
427 }
428 //------------------------------------------------------------------------
429 // address of source data to structure of callback parameters
430 // so callback function can change this data before reading
431 CbParam.m_uiIndex = uiIndex_p;
432 CbParam.m_uiSubIndex = uiSubIndex_p;
433 CbParam.m_pArg = pSrcData;
434 CbParam.m_ObdEvent = kEplObdEvPreRead;
435 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
436 pObdEntry->m_fpCallback, &CbParam);
437 if (Ret != kEplSuccessful) {
438 goto Exit;
439 }
440 // get size of data and check if application has reserved enough memory
441 ObdSize = EplObdGetDataSizeIntern(pSubEntry);
442 // check if offset given and calc correct number of bytes to read
443 if (*pSize_p < ObdSize) {
444 Ret = kEplObdValueLengthError;
445 goto Exit;
446 }
447 // read value from object
448 EPL_MEMCPY(pDstData_p, pSrcData, ObdSize);
449 *pSize_p = ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800450
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800451 // write address of destination data to structure of callback parameters
452 // so callback function can change this data after reading
453 CbParam.m_pArg = pDstData_p;
454 CbParam.m_ObdEvent = kEplObdEvPostRead;
455 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
456 pObdEntry->m_fpCallback, &CbParam);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800457
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800458 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800459
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800460 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800461
462}
463
464//---------------------------------------------------------------------------
465//
466// Function: EplObdAccessOdPart()
467//
468// Description: restores default values of one part of OD
469//
470// Parameters: ObdPart_p
471// Direction_p
472//
473// Return: tEplKernel
474//
475// State:
476//
477//---------------------------------------------------------------------------
478
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700479tEplKernel EplObdAccessOdPart(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdPart ObdPart_p,
480 tEplObdDir Direction_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800481{
482
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800483 tEplKernel Ret = kEplSuccessful;
484 BOOL fPartFount;
485 tEplObdEntryPtr pObdEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800486
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800487 // check for all API function if instance is valid
488 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800489
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800490 // part always has to be unequal to NULL
491 pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pPart);
492 ASSERTMSG(pObdEntry != NULL,
493 "EplObdAccessOdPart(): no OD part is defined!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800494
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800495 // if ObdPart_p is not valid fPartFound keeps FALSE and function returns kEplObdIllegalPart
496 fPartFount = FALSE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800497
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800498 // access to part
499 if ((ObdPart_p & kEplObdPartGen) != 0) {
500 fPartFount = TRUE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800501
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800502 Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_
503 kEplObdPartGen, pObdEntry,
504 Direction_p);
505 if (Ret != kEplSuccessful) {
506 goto Exit;
507 }
508 }
509 // access to manufacturer part
510 pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pManufacturerPart);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800511
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800512 if (((ObdPart_p & kEplObdPartMan) != 0) && (pObdEntry != NULL)) {
513 fPartFount = TRUE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800514
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800515 Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_
516 kEplObdPartMan, pObdEntry,
517 Direction_p);
518 if (Ret != kEplSuccessful) {
519 goto Exit;
520 }
521 }
522 // access to device part
523 pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pDevicePart);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800524
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800525 if (((ObdPart_p & kEplObdPartDev) != 0) && (pObdEntry != NULL)) {
526 fPartFount = TRUE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800527
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800528 Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_
529 kEplObdPartDev, pObdEntry,
530 Direction_p);
531 if (Ret != kEplSuccessful) {
532 goto Exit;
533 }
534 }
535#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
536 {
537 // access to user part
538 pObdEntry = EPL_MCO_GLB_VAR(m_ObdInitParam.m_pUserPart);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800539
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800540 if (((ObdPart_p & kEplObdPartUsr) != 0) && (pObdEntry != NULL)) {
541 fPartFount = TRUE;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800542
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800543 Ret = EplObdAccessOdPartIntern(EPL_MCO_INSTANCE_PTR_
544 kEplObdPartUsr,
545 pObdEntry, Direction_p);
546 if (Ret != kEplSuccessful) {
547 goto Exit;
548 }
549 }
550 }
551#endif
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800552
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800553 // no access to an OD part was done? illegal OD part was specified!
554 if (fPartFount == FALSE) {
555 Ret = kEplObdIllegalPart;
556 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800557
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800558 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800559
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800560 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800561
562}
563
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800564//---------------------------------------------------------------------------
565//
566// Function: EplObdDefineVar()
567//
568// Description: defines a variable in OD
569//
570// Parameters: pEplVarParam_p
571//
572// Return: tEplKernel
573//
574// State:
575//
576//---------------------------------------------------------------------------
577
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700578tEplKernel EplObdDefineVar(EPL_MCO_DECL_INSTANCE_PTR_ tEplVarParam *pVarParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800579{
580
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800581 tEplKernel Ret;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700582 tEplObdVarEntry *pVarEntry;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800583 tEplVarParamValid VarValid;
584 tEplObdSubEntryPtr pSubindexEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800585
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800586 // check for all API function if instance is valid
587 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800588
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800589 ASSERT(pVarParam_p != NULL); // is not allowed to be NULL
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800590
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800591 // get address of subindex entry
592 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
593 pVarParam_p->m_uiIndex,
594 pVarParam_p->m_uiSubindex, NULL, &pSubindexEntry);
595 if (Ret != kEplSuccessful) {
596 goto Exit;
597 }
598 // get var entry
599 Ret = EplObdGetVarEntry(pSubindexEntry, &pVarEntry);
600 if (Ret != kEplSuccessful) {
601 goto Exit;
602 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800603
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800604 VarValid = pVarParam_p->m_ValidFlag;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800605
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800606 // copy only this values, which valid flag is set
607 if ((VarValid & kVarValidSize) != 0) {
608 if (pSubindexEntry->m_Type != kEplObdTypDomain) {
609 tEplObdSize DataSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800610
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800611 // check passed size parameter
612 DataSize = EplObdGetObjectSize(pSubindexEntry);
613 if (DataSize != pVarParam_p->m_Size) { // size of variable does not match
614 Ret = kEplObdValueLengthError;
615 goto Exit;
616 }
617 } else { // size can be set only for objects of type DOMAIN
618 pVarEntry->m_Size = pVarParam_p->m_Size;
619 }
620 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800621
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800622 if ((VarValid & kVarValidData) != 0) {
623 pVarEntry->m_pData = pVarParam_p->m_pData;
624 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800625/*
626 #if (EPL_PDO_USE_STATIC_MAPPING == FALSE)
627 {
628 if ((VarValid & kVarValidCallback) != 0)
629 {
630 pVarEntry->m_fpCallback = pVarParam_p->m_fpCallback;
631 }
632
633 if ((VarValid & kVarValidArg) != 0)
634 {
635 pVarEntry->m_pArg = pVarParam_p->m_pArg;
636 }
637 }
638 #endif
639*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800640 // Ret is already set to kEplSuccessful from ObdGetVarIntern()
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800641
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800642 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800643
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800644 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800645
646}
647
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800648//---------------------------------------------------------------------------
649//
650// Function: EplObdGetObjectDataPtr()
651//
652// Description: It returnes the current data pointer. But if object is an
653// constant object it returnes the default pointer.
654//
655// Parameters: uiIndex_p = Index of the entry
656// uiSubindex_p = Subindex of the entry
657//
658// Return: void * = pointer to object data
659//
660// State:
661//
662//---------------------------------------------------------------------------
663
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700664void *EplObdGetObjectDataPtr(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
665 unsigned int uiSubIndex_p)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800666{
667 tEplKernel Ret;
668 void *pData;
669 tEplObdEntryPtr pObdEntry;
670 tEplObdSubEntryPtr pObdSubEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800671
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800672 // get pointer to index structure
673 Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam),
674 uiIndex_p, &pObdEntry);
675 if (Ret != kEplSuccessful) {
676 pData = NULL;
677 goto Exit;
678 }
679 // get pointer to subindex structure
680 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry);
681 if (Ret != kEplSuccessful) {
682 pData = NULL;
683 goto Exit;
684 }
685 // get Datapointer
686 pData = EplObdGetObjectDataPtrIntern(pObdSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800687
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800688 Exit:
689 return pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800690
691}
692
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800693#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
694
695//---------------------------------------------------------------------------
696//
697// Function: EplObdRegisterUserOd()
698//
699// Description: function registers the user OD
700//
701// Parameters: pUserOd_p =pointer to user ODd
702//
703// Return: tEplKernel = errorcode
704//
705// State:
706//
707//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700708tEplKernel EplObdRegisterUserOd(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdEntryPtr pUserOd_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800709{
710
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800711 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800712
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800713 EPL_MCO_GLB_VAR(m_ObdInitParam.m_pUserPart) = pUserOd_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800714
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800715 return kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800716
717}
718
719#endif
720
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800721//---------------------------------------------------------------------------
722//
723// Function: EplObdInitVarEntry()
724//
725// Description: function to initialize VarEntry dependened on object type
726//
727// Parameters: pVarEntry_p = pointer to var entry structure
728// Type_p = object type
729// ObdSize_p = size of object data
730//
731// Returns: none
732//
733// State:
734//
735//---------------------------------------------------------------------------
736
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700737void EplObdInitVarEntry(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdVarEntry *pVarEntry_p,
738 tEplObdType Type_p, tEplObdSize ObdSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800739{
740/*
741 #if (EPL_PDO_USE_STATIC_MAPPING == FALSE)
742 {
743 // reset pointer to VAR callback and argument
744 pVarEntry_p->m_fpCallback = NULL;
745 pVarEntry_p->m_pArg = NULL;
746 }
747 #endif
748*/
749
750// 10-dec-2004 r.d.: this function will not be used for strings
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800751 if ((Type_p == kEplObdTypDomain))
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800752// (bType_p == kEplObdTypVString) /* ||
753// (bType_p == kEplObdTypOString) ||
754// (bType_p == kEplObdTypUString) */ )
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800755 {
756 // variables which are defined as DOMAIN or VSTRING should not point to
757 // trash object, because this trash object contains only 8 bytes. DOMAINS or
758 // STRINGS can be longer.
759 pVarEntry_p->m_pData = NULL;
760 pVarEntry_p->m_Size = 0;
761 } else {
762 // set address to variable data to trash object
763 // This prevents an access violation if user forgets to call EplObdDefineVar()
764 // for this variable but mappes it in a PDO.
765 pVarEntry_p->m_pData = &abEplObdTrashObject_g[0];
766 pVarEntry_p->m_Size = ObdSize_p;
767 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800768
769}
770
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800771//---------------------------------------------------------------------------
772//
773// Function: EplObdGetDataSize()
774//
775// Description: function to initialize VarEntry dependened on object type
776//
777// gets the data size of an object
778// for string objects it returnes the string length
779//
780// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer
781// uiIndex_p = Index
782// uiSubIndex_p= Subindex
783//
784// Return: tEplObdSize
785//
786// State:
787//
788//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700789tEplObdSize EplObdGetDataSize(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
790 unsigned int uiSubIndex_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800791{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800792 tEplKernel Ret;
793 tEplObdSize ObdSize;
794 tEplObdEntryPtr pObdEntry;
795 tEplObdSubEntryPtr pObdSubEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800796
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800797 // get pointer to index structure
798 Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam),
799 uiIndex_p, &pObdEntry);
800 if (Ret != kEplSuccessful) {
801 ObdSize = 0;
802 goto Exit;
803 }
804 // get pointer to subindex structure
805 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry);
806 if (Ret != kEplSuccessful) {
807 ObdSize = 0;
808 goto Exit;
809 }
810 // get size
811 ObdSize = EplObdGetDataSizeIntern(pObdSubEntry);
812 Exit:
813 return ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800814}
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800815
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800816//---------------------------------------------------------------------------
817//
818// Function: EplObdGetNodeId()
819//
820// Description: function returns nodeid from entry 0x1F93
821//
822//
823// Parameters: EPL_MCO_DECL_INSTANCE_PTR = Instancepointer
824//
825// Return: unsigned int = Node Id
826//
827// State:
828//
829//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700830unsigned int EplObdGetNodeId(EPL_MCO_DECL_INSTANCE_PTR)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800831{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800832 tEplKernel Ret;
833 tEplObdSize ObdSize;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700834 u8 bNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800835
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800836 bNodeId = 0;
837 ObdSize = sizeof(bNodeId);
838 Ret = EplObdReadEntry(EPL_MCO_PTR_INSTANCE_PTR_
839 EPL_OBD_NODE_ID_INDEX,
840 EPL_OBD_NODE_ID_SUBINDEX, &bNodeId, &ObdSize);
841 if (Ret != kEplSuccessful) {
842 bNodeId = EPL_C_ADR_INVALID;
843 goto Exit;
844 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800845
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800846 Exit:
847 return (unsigned int)bNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800848
849}
850
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800851//---------------------------------------------------------------------------
852//
853// Function: EplObdSetNodeId()
854//
855// Description: function sets nodeid in entry 0x1F93
856//
857//
858// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer
859// uiNodeId_p = Node Id to set
860// NodeIdType_p= Type on which way the Node Id was set
861//
862// Return: tEplKernel = Errorcode
863//
864// State:
865//
866//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700867tEplKernel EplObdSetNodeId(EPL_MCO_DECL_PTR_INSTANCE_PTR_ unsigned int uiNodeId_p,
868 tEplObdNodeIdType NodeIdType_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800869{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800870 tEplKernel Ret;
871 tEplObdSize ObdSize;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700872 u8 fHwBool;
873 u8 bNodeId;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800874
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800875 // check Node Id
876 if (uiNodeId_p == EPL_C_ADR_INVALID) {
877 Ret = kEplInvalidNodeId;
878 goto Exit;
879 }
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700880 bNodeId = (u8) uiNodeId_p;
881 ObdSize = sizeof(u8);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800882 // write NodeId to OD entry
883 Ret = EplObdWriteEntry(EPL_MCO_PTR_INSTANCE_PTR_
884 EPL_OBD_NODE_ID_INDEX,
885 EPL_OBD_NODE_ID_SUBINDEX, &bNodeId, ObdSize);
886 if (Ret != kEplSuccessful) {
887 goto Exit;
888 }
889 // set HWBOOL-Flag in Subindex EPL_OBD_NODE_ID_HWBOOL_SUBINDEX
890 switch (NodeIdType_p) {
891 // type unknown
892 case kEplObdNodeIdUnknown:
893 {
894 fHwBool = OBD_FALSE;
895 break;
896 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800897
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800898 case kEplObdNodeIdSoftware:
899 {
900 fHwBool = OBD_FALSE;
901 break;
902 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800903
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800904 case kEplObdNodeIdHardware:
905 {
906 fHwBool = OBD_TRUE;
907 break;
908 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800909
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800910 default:
911 {
912 fHwBool = OBD_FALSE;
913 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800914
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800915 } // end of switch (NodeIdType_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800916
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800917 // write flag
918 ObdSize = sizeof(fHwBool);
919 Ret = EplObdWriteEntry(EPL_MCO_PTR_INSTANCE_PTR
920 EPL_OBD_NODE_ID_INDEX,
921 EPL_OBD_NODE_ID_HWBOOL_SUBINDEX,
922 &fHwBool, ObdSize);
923 if (Ret != kEplSuccessful) {
924 goto Exit;
925 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800926
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800927 Exit:
928 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800929}
930
931//---------------------------------------------------------------------------
932//
933// Function: EplObdIsNumerical()
934//
935// Description: function checks if a entry is numerical or not
936//
937//
938// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer
939// uiIndex_p = Index
940// uiSubIndex_p = Subindex
941// pfEntryNumerical_p = pointer to BOOL for returnvalue
942// -> TRUE if entry a numerical value
943// -> FALSE if entry not a numerical value
944//
945// Return: tEplKernel = Errorcode
946//
947// State:
948//
949//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -0700950tEplKernel EplObdIsNumerical(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
951 unsigned int uiSubIndex_p,
952 BOOL *pfEntryNumerical_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800953{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800954 tEplKernel Ret;
955 tEplObdEntryPtr pObdEntry;
956 tEplObdSubEntryPtr pObdSubEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800957
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800958 // get pointer to index structure
959 Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam),
960 uiIndex_p, &pObdEntry);
961 if (Ret != kEplSuccessful) {
962 goto Exit;
963 }
964 // get pointer to subindex structure
965 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry);
966 if (Ret != kEplSuccessful) {
967 goto Exit;
968 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800969
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800970 Ret = EplObdIsNumericalIntern(pObdSubEntry, pfEntryNumerical_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800971
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800972 Exit:
973 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800974
975}
976
977//---------------------------------------------------------------------------
978//
979// Function: EplObdReadEntryToLe()
980//
981// Description: The function reads an object entry from the byteoder
982// of the system to the little endian byteorder for numerical values.
983// For other types a normal read will be processed. This is usefull for
984// the PDO and SDO module. The application
985// can always read the data even if attrib kEplObdAccRead
986// is not set. The attrib is only checked up for SDO transfer.
987//
988// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
989// uiIndex_p = Index of the OD entry to read
990// uiSubIndex_p = Subindex to read
991// pDstData_p = pointer to the buffer for data
992// Offset_p = offset in data for read access
993// pSize_p = IN: Size of the buffer
994// OUT: number of readed Bytes
995//
996// Return: tEplKernel
997//
998// State:
999//
1000//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -07001001tEplKernel EplObdReadEntryToLe(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1002 unsigned int uiSubIndex_p,
1003 void *pDstData_p, tEplObdSize *pSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001004{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001005 tEplKernel Ret;
1006 tEplObdEntryPtr pObdEntry;
1007 tEplObdSubEntryPtr pSubEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001008 tEplObdCbParam CbParam;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001009 void *pSrcData;
1010 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001011
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001012 // check for all API function if instance is valid
1013 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001014
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001015 ASSERT(pDstData_p != NULL);
1016 ASSERT(pSize_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001017
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001018 // get address of index and subindex entry
1019 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
1020 uiIndex_p, uiSubIndex_p, &pObdEntry, &pSubEntry);
1021 if (Ret != kEplSuccessful) {
1022 goto Exit;
1023 }
1024 // get pointer to object data
1025 pSrcData = EplObdGetObjectDataPtrIntern(pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001026
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001027 // check source pointer
1028 if (pSrcData == NULL) {
1029 Ret = kEplObdReadViolation;
1030 goto Exit;
1031 }
1032 //------------------------------------------------------------------------
1033 // address of source data to structure of callback parameters
1034 // so callback function can change this data before reading
1035 CbParam.m_uiIndex = uiIndex_p;
1036 CbParam.m_uiSubIndex = uiSubIndex_p;
1037 CbParam.m_pArg = pSrcData;
1038 CbParam.m_ObdEvent = kEplObdEvPreRead;
1039 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
1040 pObdEntry->m_fpCallback, &CbParam);
1041 if (Ret != kEplSuccessful) {
1042 goto Exit;
1043 }
1044 // get size of data and check if application has reserved enough memory
1045 ObdSize = EplObdGetDataSizeIntern(pSubEntry);
1046 // check if offset given and calc correct number of bytes to read
1047 if (*pSize_p < ObdSize) {
1048 Ret = kEplObdValueLengthError;
1049 goto Exit;
1050 }
1051 // check if numerical type
1052 switch (pSubEntry->m_Type) {
1053 //-----------------------------------------------
1054 // types without ami
1055 case kEplObdTypVString:
1056 case kEplObdTypOString:
1057 case kEplObdTypDomain:
1058 default:
1059 {
1060 // read value from object
1061 EPL_MEMCPY(pDstData_p, pSrcData, ObdSize);
1062 break;
1063 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001064
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001065 //-----------------------------------------------
1066 // numerical type which needs ami-write
1067 // 8 bit or smaller values
1068 case kEplObdTypBool:
1069 case kEplObdTypInt8:
1070 case kEplObdTypUInt8:
1071 {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001072 AmiSetByteToLe(pDstData_p, *((u8 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001073 break;
1074 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001075
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001076 // 16 bit values
1077 case kEplObdTypInt16:
1078 case kEplObdTypUInt16:
1079 {
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001080 AmiSetWordToLe(pDstData_p, *((u16 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001081 break;
1082 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001083
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001084 // 24 bit values
1085 case kEplObdTypInt24:
1086 case kEplObdTypUInt24:
1087 {
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -07001088 AmiSetDword24ToLe(pDstData_p, *((u32 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001089 break;
1090 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001091
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001092 // 32 bit values
1093 case kEplObdTypInt32:
1094 case kEplObdTypUInt32:
1095 case kEplObdTypReal32:
1096 {
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -07001097 AmiSetDwordToLe(pDstData_p, *((u32 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001098 break;
1099 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001100
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001101 // 40 bit values
1102 case kEplObdTypInt40:
1103 case kEplObdTypUInt40:
1104 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001105 AmiSetQword40ToLe(pDstData_p, *((u64 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001106 break;
1107 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001108
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001109 // 48 bit values
1110 case kEplObdTypInt48:
1111 case kEplObdTypUInt48:
1112 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001113 AmiSetQword48ToLe(pDstData_p, *((u64 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001114 break;
1115 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001116
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001117 // 56 bit values
1118 case kEplObdTypInt56:
1119 case kEplObdTypUInt56:
1120 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001121 AmiSetQword56ToLe(pDstData_p, *((u64 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001122 break;
1123 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001124
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001125 // 64 bit values
1126 case kEplObdTypInt64:
1127 case kEplObdTypUInt64:
1128 case kEplObdTypReal64:
1129 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001130 AmiSetQword64ToLe(pDstData_p, *((u64 *) pSrcData));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001131 break;
1132 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001133
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001134 // time of day
1135 case kEplObdTypTimeOfDay:
1136 case kEplObdTypTimeDiff:
1137 {
1138 AmiSetTimeOfDay(pDstData_p, ((tTimeOfDay *) pSrcData));
1139 break;
1140 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001141
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001142 } // end of switch(pSubEntry->m_Type)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001143
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001144 *pSize_p = ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001145
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001146 // write address of destination data to structure of callback parameters
1147 // so callback function can change this data after reading
1148 CbParam.m_pArg = pDstData_p;
1149 CbParam.m_ObdEvent = kEplObdEvPostRead;
1150 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
1151 pObdEntry->m_fpCallback, &CbParam);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001152
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001153 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001154
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001155 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001156
1157}
1158
1159//---------------------------------------------------------------------------
1160//
1161// Function: EplObdWriteEntryFromLe()
1162//
1163// Description: Function writes data to an OBD entry from a source with
1164// little endian byteorder to the od with system specuific
1165// byteorder. Not numerical values will only by copied. Strings
1166// are stored with added '\0' character.
1167//
1168// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
1169// uiIndex_p = Index of the OD entry
1170// uiSubIndex_p = Subindex of the OD Entry
1171// pSrcData_p = Pointer to the data to write
1172// Size_p = Size of the data in Byte
1173//
1174// Return: tEplKernel = Errorcode
1175//
1176//
1177// State:
1178//
1179//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -07001180tEplKernel EplObdWriteEntryFromLe(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1181 unsigned int uiSubIndex_p,
1182 void *pSrcData_p, tEplObdSize Size_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001183{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001184 tEplKernel Ret;
1185 tEplObdEntryPtr pObdEntry;
1186 tEplObdSubEntryPtr pSubEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001187 tEplObdCbParam CbParam;
1188 void *pDstData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001189 tEplObdSize ObdSize;
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001190 u64 qwBuffer;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001191 void *pBuffer = &qwBuffer;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001192
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001193 Ret = EplObdWriteEntryPre(EPL_MCO_INSTANCE_PTR_
1194 uiIndex_p,
1195 uiSubIndex_p,
1196 pSrcData_p,
1197 &pDstData,
1198 Size_p,
1199 &pObdEntry, &pSubEntry, &CbParam, &ObdSize);
1200 if (Ret != kEplSuccessful) {
1201 goto Exit;
1202 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001203
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001204 // check if numerical type
1205 switch (pSubEntry->m_Type) {
1206 //-----------------------------------------------
1207 // types without ami
1208 default:
1209 { // do nothing, i.e. use the given source pointer
1210 pBuffer = pSrcData_p;
1211 break;
1212 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001213
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001214 //-----------------------------------------------
1215 // numerical type which needs ami-write
1216 // 8 bit or smaller values
1217 case kEplObdTypBool:
1218 case kEplObdTypInt8:
1219 case kEplObdTypUInt8:
1220 {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001221 *((u8 *) pBuffer) = AmiGetByteFromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001222 break;
1223 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001224
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001225 // 16 bit values
1226 case kEplObdTypInt16:
1227 case kEplObdTypUInt16:
1228 {
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001229 *((u16 *) pBuffer) = AmiGetWordFromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001230 break;
1231 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001232
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001233 // 24 bit values
1234 case kEplObdTypInt24:
1235 case kEplObdTypUInt24:
1236 {
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -07001237 *((u32 *) pBuffer) = AmiGetDword24FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001238 break;
1239 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001240
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001241 // 32 bit values
1242 case kEplObdTypInt32:
1243 case kEplObdTypUInt32:
1244 case kEplObdTypReal32:
1245 {
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -07001246 *((u32 *) pBuffer) = AmiGetDwordFromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001247 break;
1248 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001249
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001250 // 40 bit values
1251 case kEplObdTypInt40:
1252 case kEplObdTypUInt40:
1253 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001254 *((u64 *) pBuffer) = AmiGetQword40FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001255 break;
1256 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001257
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001258 // 48 bit values
1259 case kEplObdTypInt48:
1260 case kEplObdTypUInt48:
1261 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001262 *((u64 *) pBuffer) = AmiGetQword48FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001263 break;
1264 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001265
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001266 // 56 bit values
1267 case kEplObdTypInt56:
1268 case kEplObdTypUInt56:
1269 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001270 *((u64 *) pBuffer) = AmiGetQword56FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001271 break;
1272 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001273
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001274 // 64 bit values
1275 case kEplObdTypInt64:
1276 case kEplObdTypUInt64:
1277 case kEplObdTypReal64:
1278 {
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001279 *((u64 *) pBuffer) = AmiGetQword64FromLe(pSrcData_p);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001280 break;
1281 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001282
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001283 // time of day
1284 case kEplObdTypTimeOfDay:
1285 case kEplObdTypTimeDiff:
1286 {
1287 AmiGetTimeOfDay(pBuffer, ((tTimeOfDay *) pSrcData_p));
1288 break;
1289 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001290
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001291 } // end of switch(pSubEntry->m_Type)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001292
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001293 Ret = EplObdWriteEntryPost(EPL_MCO_INSTANCE_PTR_
1294 pObdEntry,
1295 pSubEntry,
1296 &CbParam, pBuffer, pDstData, ObdSize);
1297 if (Ret != kEplSuccessful) {
1298 goto Exit;
1299 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001300
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001301 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001302
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001303 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001304
1305}
1306
1307//---------------------------------------------------------------------------
1308//
1309// Function: EplObdGetAccessType()
1310//
1311// Description: Function returns accesstype of the entry
1312//
1313// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
1314// uiIndex_p = Index of the OD entry
1315// uiSubIndex_p = Subindex of the OD Entry
1316// pAccessTyp_p = pointer to buffer to store accesstype
1317//
1318// Return: tEplKernel = errorcode
1319//
1320//
1321// State:
1322//
1323//---------------------------------------------------------------------------
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -07001324tEplKernel EplObdGetAccessType(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1325 unsigned int uiSubIndex_p,
1326 tEplObdAccess *pAccessTyp_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001327{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001328 tEplKernel Ret;
1329 tEplObdEntryPtr pObdEntry;
1330 tEplObdSubEntryPtr pObdSubEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001331
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001332 // get pointer to index structure
1333 Ret = EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam),
1334 uiIndex_p, &pObdEntry);
1335 if (Ret != kEplSuccessful) {
1336 goto Exit;
1337 }
1338 // get pointer to subindex structure
1339 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubIndex_p, &pObdSubEntry);
1340 if (Ret != kEplSuccessful) {
1341 goto Exit;
1342 }
1343 // get accessType
1344 *pAccessTyp_p = pObdSubEntry->m_Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001345
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001346 Exit:
1347 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001348}
1349
1350//---------------------------------------------------------------------------
1351//
1352// Function: EplObdSearchVarEntry()
1353//
1354// Description: gets variable from OD
1355//
1356// Parameters: uiIndex_p = index of the var entry to search
1357// uiSubindex_p = subindex of var entry to search
1358// ppVarEntry_p = pointer to the pointer to the varentry
1359//
1360// Return: tEplKernel
1361//
1362// State:
1363//
1364//---------------------------------------------------------------------------
1365
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001366tEplKernel EplObdSearchVarEntry(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1367 unsigned int uiSubindex_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001368 tEplObdVarEntry **ppVarEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001369{
1370
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001371 tEplKernel Ret;
1372 tEplObdSubEntryPtr pSubindexEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001373
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001374 // check for all API function if instance is valid
1375 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001376
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001377 // get address of subindex entry
1378 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
1379 uiIndex_p, uiSubindex_p, NULL, &pSubindexEntry);
1380 if (Ret == kEplSuccessful) {
1381 // get var entry
1382 Ret = EplObdGetVarEntry(pSubindexEntry, ppVarEntry_p);
1383 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001384
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001385 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001386
1387}
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001388
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001389//=========================================================================//
1390// //
1391// P R I V A T E D E F I N I T I O N S //
1392// //
1393//=========================================================================//
1394
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001395EPL_MCO_DECL_INSTANCE_FCT()
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001396//---------------------------------------------------------------------------
1397//
1398// Function: EplObdCallObjectCallback()
1399//
1400// Description: calls callback function of an object or of a variable
1401//
1402// Parameters: fpCallback_p
1403// pCbParam_p
1404//
1405// Return: tEplKernel
1406//
1407// State:
1408//
1409//---------------------------------------------------------------------------
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001410static tEplKernel EplObdCallObjectCallback(EPL_MCO_DECL_INSTANCE_PTR_
1411 tEplObdCallback fpCallback_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001412 tEplObdCbParam *pCbParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001413{
1414
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001415 tEplKernel Ret;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001416 tEplObdCallback fpCallback;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001417
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001418 // check for all API function if instance is valid
1419 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001420
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001421 ASSERT(pCbParam_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001422
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001423 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001424
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001425 // check address of callback function before calling it
1426 if (fpCallback_p != NULL) {
1427 // KEIL C51 V6.01 has a bug.
1428 // Therefore the parameter fpCallback_p has to be copied in local variable fpCallback.
1429 fpCallback = fpCallback_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001430
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001431 // call callback function for this object
1432 Ret = fpCallback(EPL_MCO_INSTANCE_PARAM_IDX_()
1433 pCbParam_p);
1434 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001435
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001436 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001437}
1438
1439//---------------------------------------------------------------------------
1440//
1441// Function: EplObdGetDataSizeIntern()
1442//
1443// Description: gets the data size of an object
1444// for string objects it returnes the string length
1445//
1446// Parameters: pSubIndexEntry_p
1447//
1448// Return: tEplObdSize
1449//
1450// State:
1451//
1452//---------------------------------------------------------------------------
1453
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001454static tEplObdSize EplObdGetDataSizeIntern(tEplObdSubEntryPtr pSubIndexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001455{
1456
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001457 tEplObdSize DataSize;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001458 void *pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001459
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001460 // If OD entry is defined by macro EPL_OBD_SUBINDEX_ROM_VSTRING
1461 // then the current pointer is always NULL. The function
1462 // returns the length of default string.
1463 DataSize = EplObdGetObjectSize(pSubIndexEntry_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001464
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001465 if (pSubIndexEntry_p->m_Type == kEplObdTypVString) {
1466 // The pointer to current value can be received from EplObdGetObjectCurrentPtr()
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001467 pData = ((void *)EplObdGetObjectCurrentPtr(pSubIndexEntry_p));
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001468 if (pData != NULL) {
1469 DataSize =
1470 EplObdGetStrLen((void *)pData, DataSize,
1471 pSubIndexEntry_p->m_Type);
1472 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001473
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001474 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001475
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001476 return DataSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001477
1478}
1479
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001480//---------------------------------------------------------------------------
1481//
1482// Function: EplObdGetStrLen()
1483//
1484// Description: The function calculates the length of string. The '\0'
1485// character is included!!
1486//
1487// Parameters: pObjData_p = pointer to string
1488// ObjLen_p = max. length of objectr entry
1489// bObjType_p = object type (VSTRING, ...)
1490//
1491// Returns: string length + 1
1492//
1493// State:
1494//
1495//---------------------------------------------------------------------------
1496
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001497static tEplObdSize EplObdGetStrLen(void *pObjData_p,
1498 tEplObdSize ObjLen_p, tEplObdType ObjType_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001499{
1500
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001501 tEplObdSize StrLen = 0;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001502 u8 *pbString;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001503
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001504 if (pObjData_p == NULL) {
1505 goto Exit;
1506 }
1507 //----------------------------------------
1508 // Visible String: data format byte
1509 if (ObjType_p == kEplObdTypVString) {
1510 pbString = pObjData_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001511
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001512 for (StrLen = 0; StrLen < ObjLen_p; StrLen++) {
1513 if (*pbString == '\0') {
1514 StrLen++;
1515 break;
1516 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001517
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001518 pbString++;
1519 }
1520 }
1521 //----------------------------------------
1522 // other string types ...
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001523
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001524 Exit:
1525 return (StrLen);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001526
1527}
1528
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001529#if (EPL_OBD_CHECK_OBJECT_RANGE != FALSE)
1530
1531//---------------------------------------------------------------------------
1532//
1533// Function: EplObdCheckObjectRange()
1534//
1535// Description: function to check value range of object data
1536//
1537// NOTICE: The pointer of data (pData_p) must point out to an even address,
1538// if ObjType is unequal to kEplObdTypInt8 or kEplObdTypUInt8! But it is
1539// always realiced because pointer m_pDefault points always to an
1540// array of the SPECIFIED type.
1541//
1542// Parameters: pSubindexEntry_p
1543// pData_p
1544//
1545// Return: tEplKernel
1546//
1547// State:
1548//
1549//---------------------------------------------------------------------------
1550
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001551static tEplKernel EplObdCheckObjectRange(tEplObdSubEntryPtr pSubindexEntry_p,
1552 void *pData_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001553{
1554
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001555 tEplKernel Ret;
1556 void *pRangeData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001557
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001558 ASSERTMSG(pSubindexEntry_p != NULL,
1559 "EplObdCheckObjectRange(): no address to subindex struct!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001560
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001561 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001562
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001563 // check if data range has to be checked
1564 if ((pSubindexEntry_p->m_Access & kEplObdAccRange) == 0) {
1565 goto Exit;
1566 }
1567 // get address of default data
1568 pRangeData = pSubindexEntry_p->m_pDefault;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001569
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001570 // jump to called object type
1571 switch ((tEplObdType) pSubindexEntry_p->m_Type) {
1572 // -----------------------------------------------------------------
1573 // ObdType kEplObdTypBool will not be checked because there are only
1574 // two possible values 0 or 1.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001575
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001576 // -----------------------------------------------------------------
1577 // ObdTypes which has to be check up because numerical values
1578 case kEplObdTypInt8:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001579
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001580 // switch to lower limit
1581 pRangeData = ((tEplObdInteger8 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001582
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001583 // check if value is to low
1584 if (*((tEplObdInteger8 *) pData_p) <
1585 *((tEplObdInteger8 *) pRangeData)) {
1586 Ret = kEplObdValueTooLow;
1587 break;
1588 }
1589 // switch to higher limit
1590 pRangeData = ((tEplObdInteger8 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001591
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001592 // check if value is to high
1593 if (*((tEplObdInteger8 *) pData_p) >
1594 *((tEplObdInteger8 *) pRangeData)) {
1595 Ret = kEplObdValueTooHigh;
1596 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001597
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001598 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001599
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001600 case kEplObdTypUInt8:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001601
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001602 // switch to lower limit
1603 pRangeData = ((tEplObdUnsigned8 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001604
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001605 // check if value is to low
1606 if (*((tEplObdUnsigned8 *) pData_p) <
1607 *((tEplObdUnsigned8 *) pRangeData)) {
1608 Ret = kEplObdValueTooLow;
1609 break;
1610 }
1611 // switch to higher limit
1612 pRangeData = ((tEplObdUnsigned8 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001613
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001614 // check if value is to high
1615 if (*((tEplObdUnsigned8 *) pData_p) >
1616 *((tEplObdUnsigned8 *) pRangeData)) {
1617 Ret = kEplObdValueTooHigh;
1618 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001619
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001620 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001621
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001622 case kEplObdTypInt16:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001623
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001624 // switch to lower limit
1625 pRangeData = ((tEplObdInteger16 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001626
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001627 // check if value is to low
1628 if (*((tEplObdInteger16 *) pData_p) <
1629 *((tEplObdInteger16 *) pRangeData)) {
1630 Ret = kEplObdValueTooLow;
1631 break;
1632 }
1633 // switch to higher limit
1634 pRangeData = ((tEplObdInteger16 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001635
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001636 // check if value is to high
1637 if (*((tEplObdInteger16 *) pData_p) >
1638 *((tEplObdInteger16 *) pRangeData)) {
1639 Ret = kEplObdValueTooHigh;
1640 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001641
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001642 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001643
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001644 case kEplObdTypUInt16:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001645
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001646 // switch to lower limit
1647 pRangeData = ((tEplObdUnsigned16 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001648
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001649 // check if value is to low
1650 if (*((tEplObdUnsigned16 *) pData_p) <
1651 *((tEplObdUnsigned16 *) pRangeData)) {
1652 Ret = kEplObdValueTooLow;
1653 break;
1654 }
1655 // switch to higher limit
1656 pRangeData = ((tEplObdUnsigned16 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001657
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001658 // check if value is to high
1659 if (*((tEplObdUnsigned16 *) pData_p) >
1660 *((tEplObdUnsigned16 *) pRangeData)) {
1661 Ret = kEplObdValueTooHigh;
1662 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001663
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001664 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001665
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001666 case kEplObdTypInt32:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001667
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001668 // switch to lower limit
1669 pRangeData = ((tEplObdInteger32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001670
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001671 // check if value is to low
1672 if (*((tEplObdInteger32 *) pData_p) <
1673 *((tEplObdInteger32 *) pRangeData)) {
1674 Ret = kEplObdValueTooLow;
1675 break;
1676 }
1677 // switch to higher limit
1678 pRangeData = ((tEplObdInteger32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001679
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001680 // check if value is to high
1681 if (*((tEplObdInteger32 *) pData_p) >
1682 *((tEplObdInteger32 *) pRangeData)) {
1683 Ret = kEplObdValueTooHigh;
1684 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001685
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001686 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001687
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001688 case kEplObdTypUInt32:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001689
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001690 // switch to lower limit
1691 pRangeData = ((tEplObdUnsigned32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001692
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001693 // check if value is to low
1694 if (*((tEplObdUnsigned32 *) pData_p) <
1695 *((tEplObdUnsigned32 *) pRangeData)) {
1696 Ret = kEplObdValueTooLow;
1697 break;
1698 }
1699 // switch to higher limit
1700 pRangeData = ((tEplObdUnsigned32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001701
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001702 // check if value is to high
1703 if (*((tEplObdUnsigned32 *) pData_p) >
1704 *((tEplObdUnsigned32 *) pRangeData)) {
1705 Ret = kEplObdValueTooHigh;
1706 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001707
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001708 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001709
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001710 case kEplObdTypReal32:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001711
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001712 // switch to lower limit
1713 pRangeData = ((tEplObdReal32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001714
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001715 // check if value is to low
1716 if (*((tEplObdReal32 *) pData_p) <
1717 *((tEplObdReal32 *) pRangeData)) {
1718 Ret = kEplObdValueTooLow;
1719 break;
1720 }
1721 // switch to higher limit
1722 pRangeData = ((tEplObdReal32 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001723
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001724 // check if value is to high
1725 if (*((tEplObdReal32 *) pData_p) >
1726 *((tEplObdReal32 *) pRangeData)) {
1727 Ret = kEplObdValueTooHigh;
1728 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001729
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001730 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001731
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001732 // -----------------------------------------------------------------
1733 case kEplObdTypInt40:
1734 case kEplObdTypInt48:
1735 case kEplObdTypInt56:
1736 case kEplObdTypInt64:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001737
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001738 // switch to lower limit
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001739 pRangeData = ((signed u64 *)pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001740
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001741 // check if value is to low
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001742 if (*((signed u64 *)pData_p) < *((signed u64 *)pRangeData)) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001743 Ret = kEplObdValueTooLow;
1744 break;
1745 }
1746 // switch to higher limit
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001747 pRangeData = ((signed u64 *)pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001748
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001749 // check if value is to high
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001750 if (*((signed u64 *)pData_p) > *((signed u64 *)pRangeData)) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001751 Ret = kEplObdValueTooHigh;
1752 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001753
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001754 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001755
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001756 // -----------------------------------------------------------------
1757 case kEplObdTypUInt40:
1758 case kEplObdTypUInt48:
1759 case kEplObdTypUInt56:
1760 case kEplObdTypUInt64:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001761
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001762 // switch to lower limit
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001763 pRangeData = ((unsigned u64 *)pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001764
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001765 // check if value is to low
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001766 if (*((unsigned u64 *)pData_p) <
1767 *((unsigned u64 *)pRangeData)) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001768 Ret = kEplObdValueTooLow;
1769 break;
1770 }
1771 // switch to higher limit
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001772 pRangeData = ((unsigned u64 *)pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001773
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001774 // check if value is to high
Greg Kroah-Hartmana5c30d92009-03-23 12:43:05 -07001775 if (*((unsigned u64 *)pData_p) >
1776 *((unsigned u64 *)pRangeData)) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001777 Ret = kEplObdValueTooHigh;
1778 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001779
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001780 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001781
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001782 // -----------------------------------------------------------------
1783 case kEplObdTypReal64:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001784
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001785 // switch to lower limit
1786 pRangeData = ((tEplObdReal64 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001787
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001788 // check if value is to low
1789 if (*((tEplObdReal64 *) pData_p) <
1790 *((tEplObdReal64 *) pRangeData)) {
1791 Ret = kEplObdValueTooLow;
1792 break;
1793 }
1794 // switch to higher limit
1795 pRangeData = ((tEplObdReal64 *) pRangeData) + 1;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001796
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001797 // check if value is to high
1798 if (*((tEplObdReal64 *) pData_p) >
1799 *((tEplObdReal64 *) pRangeData)) {
1800 Ret = kEplObdValueTooHigh;
1801 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001802
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001803 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001804
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001805 // -----------------------------------------------------------------
1806 case kEplObdTypTimeOfDay:
1807 case kEplObdTypTimeDiff:
1808 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001809
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001810 // -----------------------------------------------------------------
1811 // ObdTypes kEplObdTypXString and kEplObdTypDomain can not be checkt because
1812 // they have no numerical value.
1813 default:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001814
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001815 Ret = kEplObdUnknownObjectType;
1816 break;
1817 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001818
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001819 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001820
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001821 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001822
1823}
1824#endif // (EPL_OBD_CHECK_OBJECT_RANGE != FALSE)
1825
1826//---------------------------------------------------------------------------
1827//
1828// Function: EplObdWriteEntryPre()
1829//
1830// Description: Function prepares write of data to an OBD entry. Strings
1831// are stored with added '\0' character.
1832//
1833// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
1834// uiIndex_p = Index of the OD entry
1835// uiSubIndex_p = Subindex of the OD Entry
1836// pSrcData_p = Pointer to the data to write
1837// Size_p = Size of the data in Byte
1838//
1839// Return: tEplKernel = Errorcode
1840//
1841//
1842// State:
1843//
1844//---------------------------------------------------------------------------
1845
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001846static tEplKernel EplObdWriteEntryPre(EPL_MCO_DECL_INSTANCE_PTR_ unsigned int uiIndex_p,
1847 unsigned int uiSubIndex_p,
1848 void *pSrcData_p,
1849 void **ppDstData_p,
1850 tEplObdSize Size_p,
1851 tEplObdEntryPtr *ppObdEntry_p,
1852 tEplObdSubEntryPtr *ppSubEntry_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001853 tEplObdCbParam *pCbParam_p,
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001854 tEplObdSize *pObdSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001855{
1856
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001857 tEplKernel Ret;
1858 tEplObdEntryPtr pObdEntry;
1859 tEplObdSubEntryPtr pSubEntry;
1860 tEplObdAccess Access;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001861 void *pDstData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001862 tEplObdSize ObdSize;
1863 BOOL fEntryNumerical;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001864
1865#if (EPL_OBD_USE_STRING_DOMAIN_IN_RAM != FALSE)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001866 tEplObdVStringDomain MemVStringDomain;
1867 void *pCurrData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001868#endif
1869
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001870 // check for all API function if instance is valid
1871 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001872
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001873 ASSERT(pSrcData_p != NULL); // should never be NULL
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001874
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001875 //------------------------------------------------------------------------
1876 // get address of index and subindex entry
1877 Ret = EplObdGetEntry(EPL_MCO_INSTANCE_PTR_
1878 uiIndex_p, uiSubIndex_p, &pObdEntry, &pSubEntry);
1879 if (Ret != kEplSuccessful) {
1880 goto Exit;
1881 }
1882 // get pointer to object data
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001883 pDstData = (void *)EplObdGetObjectDataPtrIntern(pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001884
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001885 Access = (tEplObdAccess) pSubEntry->m_Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001886
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001887 // check access for write
1888 // access violation if adress to current value is NULL
1889 if (((Access & kEplObdAccConst) != 0) || (pDstData == NULL)) {
1890 Ret = kEplObdAccessViolation;
1891 goto Exit;
1892 }
1893 //------------------------------------------------------------------------
1894 // get size of object
1895 // -as ObdSize = ObdGetObjectSize (pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001896
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001897 //------------------------------------------------------------------------
1898 // To use the same callback function for ObdWriteEntry as well as for
1899 // an SDO download call at first (kEplObdEvPre...) the callback function
1900 // with the argument pointer to object size.
1901 pCbParam_p->m_uiIndex = uiIndex_p;
1902 pCbParam_p->m_uiSubIndex = uiSubIndex_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001903
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001904 // Because object size and object pointer are
1905 // adapted by user callback function, re-read
1906 // this values.
1907 ObdSize = EplObdGetObjectSize(pSubEntry);
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001908 pDstData = (void *)EplObdGetObjectDataPtrIntern(pSubEntry);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001909
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001910 // 09-dec-2004 r.d.:
1911 // Function EplObdWriteEntry() calls new event kEplObdEvWrStringDomain
1912 // for String or Domain which lets called module directly change
1913 // the data pointer or size. This prevents a recursive call to
1914 // the callback function if it calls EplObdGetEntry().
1915#if (EPL_OBD_USE_STRING_DOMAIN_IN_RAM != FALSE)
1916 if ((pSubEntry->m_Type == kEplObdTypVString) ||
1917 (pSubEntry->m_Type == kEplObdTypDomain) ||
1918 (pSubEntry->m_Type == kEplObdTypOString)) {
1919 if (pSubEntry->m_Type == kEplObdTypVString) {
1920 // reserve one byte for 0-termination
1921 // -as ObdSize -= 1;
1922 Size_p += 1;
1923 }
1924 // fill out new arg-struct
1925 MemVStringDomain.m_DownloadSize = Size_p;
1926 MemVStringDomain.m_ObjSize = ObdSize;
1927 MemVStringDomain.m_pData = pDstData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001928
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001929 pCbParam_p->m_ObdEvent = kEplObdEvWrStringDomain;
1930 pCbParam_p->m_pArg = &MemVStringDomain;
1931 // call user callback
1932 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
1933 pObdEntry->m_fpCallback,
1934 pCbParam_p);
1935 if (Ret != kEplSuccessful) {
1936 goto Exit;
1937 }
1938 // write back new settings
1939 pCurrData = pSubEntry->m_pCurrent;
1940 if ((pSubEntry->m_Type == kEplObdTypVString)
1941 || (pSubEntry->m_Type == kEplObdTypOString)) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001942 ((tEplObdVString *)pCurrData)->m_Size = MemVStringDomain.m_ObjSize;
1943 ((tEplObdVString *)pCurrData)->m_pString = MemVStringDomain.m_pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001944 } else // if (pSdosTableEntry_p->m_bObjType == kEplObdTypDomain)
1945 {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001946 ((tEplObdVarEntry *)pCurrData)->m_Size = MemVStringDomain.m_ObjSize;
1947 ((tEplObdVarEntry *)pCurrData)->m_pData = (void *)MemVStringDomain.m_pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001948 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001949
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001950 // Because object size and object pointer are
1951 // adapted by user callback function, re-read
1952 // this values.
1953 ObdSize = MemVStringDomain.m_ObjSize;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001954 pDstData = (void *)MemVStringDomain.m_pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001955 }
1956#endif //#if (OBD_USE_STRING_DOMAIN_IN_RAM != FALSE)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001957
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001958 // 07-dec-2004 r.d.: size from application is needed because callback function can change the object size
1959 // -as 16.11.04 CbParam.m_pArg = &ObdSize;
1960 // 09-dec-2004 r.d.: CbParam.m_pArg = &Size_p;
1961 pCbParam_p->m_pArg = &ObdSize;
1962 pCbParam_p->m_ObdEvent = kEplObdEvInitWrite;
1963 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
1964 pObdEntry->m_fpCallback, pCbParam_p);
1965 if (Ret != kEplSuccessful) {
1966 goto Exit;
1967 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001968
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001969 if (Size_p > ObdSize) {
1970 Ret = kEplObdValueLengthError;
1971 goto Exit;
1972 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001973
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001974 if (pSubEntry->m_Type == kEplObdTypVString) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07001975 if (((char *)pSrcData_p)[Size_p - 1] == '\0') { // last byte of source string contains null character
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001976
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001977 // reserve one byte in destination for 0-termination
1978 Size_p -= 1;
1979 } else if (Size_p >= ObdSize) { // source string is not 0-terminated
1980 // and destination buffer is too short
1981 Ret = kEplObdValueLengthError;
1982 goto Exit;
1983 }
1984 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001985
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001986 Ret = EplObdIsNumericalIntern(pSubEntry, &fEntryNumerical);
1987 if (Ret != kEplSuccessful) {
1988 goto Exit;
1989 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001990
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001991 if ((fEntryNumerical != FALSE)
1992 && (Size_p != ObdSize)) {
1993 // type is numerical, therefor size has to fit, but it does not.
1994 Ret = kEplObdValueLengthError;
1995 goto Exit;
1996 }
1997 // use given size, because non-numerical objects can be written with shorter values
1998 ObdSize = Size_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001999
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002000 // set output parameters
2001 *pObdSize_p = ObdSize;
2002 *ppObdEntry_p = pObdEntry;
2003 *ppSubEntry_p = pSubEntry;
2004 *ppDstData_p = pDstData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002005
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002006 // all checks are done
2007 // the caller may now convert the numerial source value to platform byte order in a temporary buffer
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002008
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002009 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002010
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002011 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002012
2013}
2014
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002015//---------------------------------------------------------------------------
2016//
2017// Function: EplObdWriteEntryPost()
2018//
2019// Description: Function finishes write of data to an OBD entry. Strings
2020// are stored with added '\0' character.
2021//
2022// Parameters: EPL_MCO_DECL_INSTANCE_PTR_
2023// uiIndex_p = Index of the OD entry
2024// uiSubIndex_p = Subindex of the OD Entry
2025// pSrcData_p = Pointer to the data to write
2026// Size_p = Size of the data in Byte
2027//
2028// Return: tEplKernel = Errorcode
2029//
2030//
2031// State:
2032//
2033//---------------------------------------------------------------------------
2034
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07002035static tEplKernel EplObdWriteEntryPost(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdEntryPtr pObdEntry_p,
2036 tEplObdSubEntryPtr pSubEntry_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002037 tEplObdCbParam *pCbParam_p,
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07002038 void *pSrcData_p,
2039 void *pDstData_p,
2040 tEplObdSize ObdSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002041{
2042
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002043 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002044
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002045 // caller converted the source value to platform byte order
2046 // now the range of the value may be checked
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002047
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002048#if (EPL_OBD_CHECK_OBJECT_RANGE != FALSE)
2049 {
2050 // check data range
2051 Ret = EplObdCheckObjectRange(pSubEntry_p, pSrcData_p);
2052 if (Ret != kEplSuccessful) {
2053 goto Exit;
2054 }
2055 }
2056#endif
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002057
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002058 // now call user callback function to check value
2059 // write address of source data to structure of callback parameters
2060 // so callback function can check this data
2061 pCbParam_p->m_pArg = pSrcData_p;
2062 pCbParam_p->m_ObdEvent = kEplObdEvPreWrite;
2063 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
2064 pObdEntry_p->m_fpCallback, pCbParam_p);
2065 if (Ret != kEplSuccessful) {
2066 goto Exit;
2067 }
2068 // copy object data to OBD
2069 EPL_MEMCPY(pDstData_p, pSrcData_p, ObdSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002070
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002071 // terminate string with 0
2072 if (pSubEntry_p->m_Type == kEplObdTypVString) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002073 ((char *)pDstData_p)[ObdSize_p] = '\0';
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002074 }
2075 // write address of destination to structure of callback parameters
2076 // so callback function can change data subsequently
2077 pCbParam_p->m_pArg = pDstData_p;
2078 pCbParam_p->m_ObdEvent = kEplObdEvPostWrite;
2079 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
2080 pObdEntry_p->m_fpCallback, pCbParam_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002081
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002082 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002083
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002084 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002085
2086}
2087
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002088//---------------------------------------------------------------------------
2089//
2090// Function: EplObdGetObjectSize()
2091//
2092// Description: function to get size of object
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07002093// The function determines if an object type an fixed data type (u8, u16, ...)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002094// or non fixed object (string, domain). This information is used to decide
2095// if download data are stored temporary or not. For objects with fixed data length
2096// and types a value range checking can process.
2097// For strings the function returns the whole object size not the
2098// length of string.
2099//
2100// Parameters: pSubIndexEntry_p
2101//
2102// Return: tEplObdSize
2103//
2104// State:
2105//
2106//---------------------------------------------------------------------------
2107
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002108static tEplObdSize EplObdGetObjectSize(tEplObdSubEntryPtr pSubIndexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002109{
2110
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002111 tEplObdSize DataSize = 0;
2112 void *pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002113
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002114 switch (pSubIndexEntry_p->m_Type) {
2115 // -----------------------------------------------------------------
2116 case kEplObdTypBool:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002117
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002118 DataSize = 1;
2119 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002120
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002121 // -----------------------------------------------------------------
2122 // ObdTypes which has to be check because numerical values
2123 case kEplObdTypInt8:
2124 DataSize = sizeof(tEplObdInteger8);
2125 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002126
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002127 // -----------------------------------------------------------------
2128 case kEplObdTypUInt8:
2129 DataSize = sizeof(tEplObdUnsigned8);
2130 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002131
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002132 // -----------------------------------------------------------------
2133 case kEplObdTypInt16:
2134 DataSize = sizeof(tEplObdInteger16);
2135 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002136
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002137 // -----------------------------------------------------------------
2138 case kEplObdTypUInt16:
2139 DataSize = sizeof(tEplObdUnsigned16);
2140 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002141
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002142 // -----------------------------------------------------------------
2143 case kEplObdTypInt32:
2144 DataSize = sizeof(tEplObdInteger32);
2145 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002146
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002147 // -----------------------------------------------------------------
2148 case kEplObdTypUInt32:
2149 DataSize = sizeof(tEplObdUnsigned32);
2150 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002151
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002152 // -----------------------------------------------------------------
2153 case kEplObdTypReal32:
2154 DataSize = sizeof(tEplObdReal32);
2155 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002156
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002157 // -----------------------------------------------------------------
2158 // ObdTypes which has to be not checked because not NUM values
2159 case kEplObdTypDomain:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002160
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002161 pData = (void *)pSubIndexEntry_p->m_pCurrent;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002162 if ((void *)pData != (void *)NULL) {
2163 DataSize = ((tEplObdVarEntry *) pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002164 }
2165 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002166
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002167 // -----------------------------------------------------------------
2168 case kEplObdTypVString:
2169 //case kEplObdTypUString:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002170
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002171 // If OD entry is defined by macro EPL_OBD_SUBINDEX_ROM_VSTRING
2172 // then the current pointer is always NULL. The function
2173 // returns the length of default string.
2174 pData = (void *)pSubIndexEntry_p->m_pCurrent;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002175 if ((void *)pData != (void *)NULL) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002176 // The max. size of strings defined by STRING-Macro is stored in
2177 // tEplObdVString of current value.
2178 // (types tEplObdVString, tEplObdOString and tEplObdUString has the same members)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002179 DataSize = ((tEplObdVString *) pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002180 } else {
2181 // The current position is not decleared. The string
2182 // is located in ROM, therefor use default pointer.
2183 pData = (void *)pSubIndexEntry_p->m_pDefault;
Greg Kroah-Hartman5d9d5eb2009-03-23 12:24:46 -07002184 if ((const void *)pData != (const void *)NULL) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002185 // The max. size of strings defined by STRING-Macro is stored in
2186 // tEplObdVString of default value.
Greg Kroah-Hartman5d9d5eb2009-03-23 12:24:46 -07002187 DataSize = ((const tEplObdVString *)pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002188 }
2189 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002190
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002191 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002192
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002193 // -----------------------------------------------------------------
2194 case kEplObdTypOString:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002195
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002196 pData = (void *)pSubIndexEntry_p->m_pCurrent;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002197 if ((void *)pData != (void *)NULL) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002198 // The max. size of strings defined by STRING-Macro is stored in
2199 // tEplObdVString of current value.
2200 // (types tEplObdVString, tEplObdOString and tEplObdUString has the same members)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002201 DataSize = ((tEplObdOString *) pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002202 } else {
2203 // The current position is not decleared. The string
2204 // is located in ROM, therefor use default pointer.
2205 pData = (void *)pSubIndexEntry_p->m_pDefault;
Greg Kroah-Hartman5d9d5eb2009-03-23 12:24:46 -07002206 if ((const void *)pData != (const void *)NULL) {
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002207 // The max. size of strings defined by STRING-Macro is stored in
2208 // tEplObdVString of default value.
Greg Kroah-Hartman5d9d5eb2009-03-23 12:24:46 -07002209 DataSize = ((const tEplObdOString *)pData)->m_Size;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002210 }
2211 }
2212 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002213
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002214 // -----------------------------------------------------------------
2215 case kEplObdTypInt24:
2216 case kEplObdTypUInt24:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002217
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002218 DataSize = 3;
2219 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002220
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002221 // -----------------------------------------------------------------
2222 case kEplObdTypInt40:
2223 case kEplObdTypUInt40:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002224
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002225 DataSize = 5;
2226 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002227
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002228 // -----------------------------------------------------------------
2229 case kEplObdTypInt48:
2230 case kEplObdTypUInt48:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002231
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002232 DataSize = 6;
2233 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002234
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002235 // -----------------------------------------------------------------
2236 case kEplObdTypInt56:
2237 case kEplObdTypUInt56:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002238
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002239 DataSize = 7;
2240 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002241
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002242 // -----------------------------------------------------------------
2243 case kEplObdTypInt64:
2244 case kEplObdTypUInt64:
2245 case kEplObdTypReal64:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002246
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002247 DataSize = 8;
2248 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002249
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002250 // -----------------------------------------------------------------
2251 case kEplObdTypTimeOfDay:
2252 case kEplObdTypTimeDiff:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002253
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002254 DataSize = 6;
2255 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002256
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002257 // -----------------------------------------------------------------
2258 default:
2259 break;
2260 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002261
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002262 return DataSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002263}
2264
2265//---------------------------------------------------------------------------
2266//
2267// Function: EplObdGetObjectDefaultPtr()
2268//
2269// Description: function to get the default pointer (type specific)
2270//
2271// Parameters: pSubIndexEntry_p = pointer to subindex structure
2272//
2273// Returns: (void *) = pointer to default value
2274//
2275// State:
2276//
2277//---------------------------------------------------------------------------
2278
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002279static void *EplObdGetObjectDefaultPtr(tEplObdSubEntryPtr pSubIndexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002280{
2281
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002282 void *pDefault;
2283 tEplObdType Type;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002284
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002285 ASSERTMSG(pSubIndexEntry_p != NULL,
2286 "EplObdGetObjectDefaultPtr(): pointer to SubEntry not valid!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002287
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002288 // get address to default data from default pointer
2289 pDefault = pSubIndexEntry_p->m_pDefault;
2290 if (pDefault != NULL) {
2291 // there are some special types, whose default pointer always is NULL or has to get from other structure
2292 // get type from subindex structure
2293 Type = pSubIndexEntry_p->m_Type;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002294
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002295 // check if object type is a string value
2296 if ((Type == kEplObdTypVString) /* ||
2297 (Type == kEplObdTypUString) */ ) {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002298
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002299 // EPL_OBD_SUBINDEX_RAM_VSTRING
2300 // tEplObdSize m_Size; --> size of default string
2301 // char * m_pDefString; --> pointer to default string
2302 // char * m_pString; --> pointer to string in RAM
2303 //
2304 pDefault =
2305 (void *)((tEplObdVString *) pDefault)->m_pString;
2306 } else if (Type == kEplObdTypOString) {
2307 pDefault =
2308 (void *)((tEplObdOString *) pDefault)->m_pString;
2309 }
2310 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002311
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002312 return pDefault;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002313
2314}
2315
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002316//---------------------------------------------------------------------------
2317//
2318// Function: EplObdGetVarEntry()
2319//
2320// Description: gets a variable entry of an object
2321//
2322// Parameters: pSubindexEntry_p
2323// ppVarEntry_p
2324//
2325// Return: tCopKernel
2326//
2327// State:
2328//
2329//---------------------------------------------------------------------------
2330
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002331static tEplKernel EplObdGetVarEntry(tEplObdSubEntryPtr pSubindexEntry_p,
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002332 tEplObdVarEntry **ppVarEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002333{
2334
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002335 tEplKernel Ret = kEplObdVarEntryNotExist;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002336
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002337 ASSERT(ppVarEntry_p != NULL); // is not allowed to be NULL
2338 ASSERT(pSubindexEntry_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002339
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002340 // check VAR-Flag - only this object points to variables
2341 if ((pSubindexEntry_p->m_Access & kEplObdAccVar) != 0) {
2342 // check if object is an array
2343 if ((pSubindexEntry_p->m_Access & kEplObdAccArray) != 0) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002344 *ppVarEntry_p = &((tEplObdVarEntry *)pSubindexEntry_p->m_pCurrent)[pSubindexEntry_p->m_uiSubIndex - 1];
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002345 } else {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002346 *ppVarEntry_p = (tEplObdVarEntry *)pSubindexEntry_p->m_pCurrent;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002347 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002348
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002349 Ret = kEplSuccessful;
2350 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002351
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002352 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002353
2354}
2355
2356//---------------------------------------------------------------------------
2357//
2358// Function: EplObdGetEntry()
2359//
2360// Description: gets a index entry from OD
2361//
2362// Parameters: uiIndex_p = Index number
2363// uiSubindex_p = Subindex number
2364// ppObdEntry_p = pointer to the pointer to the entry
2365// ppObdSubEntry_p = pointer to the pointer to the subentry
2366//
2367// Return: tEplKernel
2368
2369//
2370// State:
2371//
2372//---------------------------------------------------------------------------
2373
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002374static tEplKernel EplObdGetEntry(EPL_MCO_DECL_INSTANCE_PTR_
2375 unsigned int uiIndex_p,
2376 unsigned int uiSubindex_p,
2377 tEplObdEntryPtr * ppObdEntry_p,
2378 tEplObdSubEntryPtr * ppObdSubEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002379{
2380
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002381 tEplObdEntryPtr pObdEntry;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002382 tEplObdCbParam CbParam;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002383 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002384
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002385 // check for all API function if instance is valid
2386 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002387
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002388 //------------------------------------------------------------------------
2389 // get address of entry of index
2390 Ret =
2391 EplObdGetIndexIntern(&EPL_MCO_GLB_VAR(m_ObdInitParam), uiIndex_p,
2392 &pObdEntry);
2393 if (Ret != kEplSuccessful) {
2394 goto Exit;
2395 }
2396 //------------------------------------------------------------------------
2397 // get address of entry of subindex
2398 Ret = EplObdGetSubindexIntern(pObdEntry, uiSubindex_p, ppObdSubEntry_p);
2399 if (Ret != kEplSuccessful) {
2400 goto Exit;
2401 }
2402 //------------------------------------------------------------------------
2403 // call callback function to inform user/stack that an object will be searched
2404 // if the called module returnes an error then we abort the searching with kEplObdIndexNotExist
2405 CbParam.m_uiIndex = uiIndex_p;
2406 CbParam.m_uiSubIndex = uiSubindex_p;
2407 CbParam.m_pArg = NULL;
2408 CbParam.m_ObdEvent = kEplObdEvCheckExist;
2409 Ret = EplObdCallObjectCallback(EPL_MCO_INSTANCE_PTR_
2410 pObdEntry->m_fpCallback, &CbParam);
2411 if (Ret != kEplSuccessful) {
2412 Ret = kEplObdIndexNotExist;
2413 goto Exit;
2414 }
2415 //------------------------------------------------------------------------
2416 // it is allowed to set ppObdEntry_p to NULL
2417 // if so, no address will be written to calling function
2418 if (ppObdEntry_p != NULL) {
2419 *ppObdEntry_p = pObdEntry;
2420 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002421
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002422 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002423
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002424 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002425
2426}
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002427
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002428//---------------------------------------------------------------------------
2429//
2430// Function: EplObdGetObjectCurrentPtr()
2431//
2432// Description: function to get Current pointer (type specific)
2433//
2434// Parameters: pSubIndexEntry_p
2435//
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002436// Return: void *
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002437//
2438// State:
2439//
2440//---------------------------------------------------------------------------
2441
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002442static void *EplObdGetObjectCurrentPtr(tEplObdSubEntryPtr pSubIndexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002443{
2444
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002445 void *pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002446 unsigned int uiArrayIndex;
2447 tEplObdSize Size;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002448
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002449 pData = pSubIndexEntry_p->m_pCurrent;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002450
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002451 // check if constant object
2452 if (pData != NULL) {
2453 // check if object is an array
2454 if ((pSubIndexEntry_p->m_Access & kEplObdAccArray) != 0) {
2455 // calculate correct data pointer
2456 uiArrayIndex = pSubIndexEntry_p->m_uiSubIndex - 1;
2457 if ((pSubIndexEntry_p->m_Access & kEplObdAccVar) != 0) {
2458 Size = sizeof(tEplObdVarEntry);
2459 } else {
2460 Size = EplObdGetObjectSize(pSubIndexEntry_p);
2461 }
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002462 pData = ((u8 *) pData) + (Size * uiArrayIndex);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002463 }
2464 // check if VarEntry
2465 if ((pSubIndexEntry_p->m_Access & kEplObdAccVar) != 0) {
2466 // The data pointer is stored in VarEntry->pData
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002467 pData = ((tEplObdVarEntry *) pData)->m_pData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002468 }
2469 // the default pointer is stored for strings in tEplObdVString
2470 else if ((pSubIndexEntry_p->m_Type == kEplObdTypVString) /* ||
2471 (pSubIndexEntry_p->m_Type == kEplObdTypUString) */
2472 ) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002473 pData = (void *)((tEplObdVString *)pData)->m_pString;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002474 } else if (pSubIndexEntry_p->m_Type == kEplObdTypOString) {
2475 pData =
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002476 (void *)((tEplObdOString *)pData)->m_pString;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002477 }
2478 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002479
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002480 return pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002481
2482}
2483
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002484//---------------------------------------------------------------------------
2485//
2486// Function: EplObdGetIndexIntern()
2487//
2488// Description: gets a index entry from OD
2489//
2490// Parameters: pInitParam_p
2491// uiIndex_p
2492// ppObdEntry_p
2493//
2494// Return: tEplKernel
2495//
2496// State:
2497//
2498//---------------------------------------------------------------------------
2499
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002500static tEplKernel EplObdGetIndexIntern(tEplObdInitParam *pInitParam_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002501 unsigned int uiIndex_p,
2502 tEplObdEntryPtr * ppObdEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002503{
2504
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002505 tEplObdEntryPtr pObdEntry;
2506 tEplKernel Ret;
2507 unsigned int uiIndex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002508
2509#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
2510
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002511 unsigned int nLoop;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002512
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002513 // if user OD is used then objekts also has to be searched in user OD
2514 // there is less code need if we do this in a loop
2515 nLoop = 2;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002516
2517#endif
2518
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002519 ASSERTMSG(ppObdEntry_p != NULL,
2520 "EplObdGetIndexIntern(): pointer to index entry is NULL!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002521
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002522 Ret = kEplObdIndexNotExist;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002523
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002524 // get start address of OD part
2525 // start address depends on object index because
2526 // object dictionary is divided in 3 parts
2527 if ((uiIndex_p >= 0x1000) && (uiIndex_p < 0x2000)) {
2528 pObdEntry = pInitParam_p->m_pPart;
2529 } else if ((uiIndex_p >= 0x2000) && (uiIndex_p < 0x6000)) {
2530 pObdEntry = pInitParam_p->m_pManufacturerPart;
2531 }
2532 // index range 0xA000 to 0xFFFF is reserved for DSP-405
2533 // DS-301 defines that range 0x6000 to 0x9FFF (!!!) is stored if "store" was written to 0x1010/3.
2534 // Therefore default configuration is OBD_INCLUDE_A000_TO_DEVICE_PART = FALSE.
2535 // But a CANopen Application which does not implement dynamic OD or user-OD but wants to use static objets 0xA000...
2536 // should set OBD_INCLUDE_A000_TO_DEVICE_PART to TRUE.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002537
2538#if (EPL_OBD_INCLUDE_A000_TO_DEVICE_PART == FALSE)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002539 else if ((uiIndex_p >= 0x6000) && (uiIndex_p < 0x9FFF))
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002540#else
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002541 else if ((uiIndex_p >= 0x6000) && (uiIndex_p < 0xFFFF))
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002542#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002543 {
2544 pObdEntry = pInitParam_p->m_pDevicePart;
2545 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002546
2547#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
2548
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002549 // if index does not match in static OD then index only has to be searched in user OD
2550 else {
2551 // begin from first entry of user OD part
2552 pObdEntry = pInitParam_p->m_pUserPart;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002553
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002554 // no user OD is available
2555 if (pObdEntry == NULL) {
2556 goto Exit;
2557 }
2558 // loop must only run once
2559 nLoop = 1;
2560 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002561
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002562 do {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002563
2564#else
2565
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002566 // no user OD is available
2567 // so other object can be found in OD
2568 else {
2569 Ret = kEplObdIllegalPart;
2570 goto Exit;
2571 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002572
2573#endif
2574
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002575 // note:
2576 // The end of Index table is marked with m_uiIndex = 0xFFFF.
2577 // If this function will be called with wIndex_p = 0xFFFF, entry
2578 // should not be found. Therefor it is important to use
2579 // while{} instead of do{}while !!!
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002580
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002581 // get first index of index table
2582 uiIndex = pObdEntry->m_uiIndex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002583
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002584 // search Index in OD part
2585 while (uiIndex != EPL_OBD_TABLE_INDEX_END) {
2586 // go to the end of this function if index is found
2587 if (uiIndex_p == uiIndex) {
2588 // write address of OD entry to calling function
2589 *ppObdEntry_p = pObdEntry;
2590 Ret = kEplSuccessful;
2591 goto Exit;
2592 }
2593 // objects are sorted in OD
2594 // if the current index in OD is greater than the index which is to search then break loop
2595 // in this case user OD has to be search too
2596 if (uiIndex_p < uiIndex) {
2597 break;
2598 }
2599 // next entry in index table
2600 pObdEntry++;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002601
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002602 // get next index of index table
2603 uiIndex = pObdEntry->m_uiIndex;
2604 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002605
2606#if (defined (EPL_OBD_USER_OD) && (EPL_OBD_USER_OD != FALSE))
2607
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002608 // begin from first entry of user OD part
2609 pObdEntry = pInitParam_p->m_pUserPart;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002610
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002611 // no user OD is available
2612 if (pObdEntry == NULL) {
2613 goto Exit;
2614 }
2615 // switch next loop for user OD
2616 nLoop--;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002617
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002618}
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002619
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002620while (nLoop > 0) ;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002621
2622#endif
2623
2624 // in this line Index was not found
2625
2626Exit:
2627
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002628return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002629
2630}
2631
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002632//---------------------------------------------------------------------------
2633//
2634// Function: EplObdGetSubindexIntern()
2635//
2636// Description: gets a subindex entry from a index entry
2637//
2638// Parameters: pObdEntry_p
2639// bSubIndex_p
2640// ppObdSubEntry_p
2641//
2642// Return: tEplKernel
2643//
2644// State:
2645//
2646//---------------------------------------------------------------------------
2647
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002648static tEplKernel EplObdGetSubindexIntern(tEplObdEntryPtr pObdEntry_p,
2649 unsigned int uiSubIndex_p,
2650 tEplObdSubEntryPtr * ppObdSubEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002651{
2652
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002653 tEplObdSubEntryPtr pSubEntry;
2654 unsigned int nSubIndexCount;
2655 tEplKernel Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002656
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002657 ASSERTMSG(pObdEntry_p != NULL,
2658 "EplObdGetSubindexIntern(): pointer to index is NULL!\n");
2659 ASSERTMSG(ppObdSubEntry_p != NULL,
2660 "EplObdGetSubindexIntern(): pointer to subindex is NULL!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002661
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002662 Ret = kEplObdSubindexNotExist;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002663
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002664 // get start address of subindex table and count of subindices
2665 pSubEntry = pObdEntry_p->m_pSubIndex;
2666 nSubIndexCount = pObdEntry_p->m_uiCount;
2667 ASSERTMSG((pSubEntry != NULL) && (nSubIndexCount > 0), "ObdGetSubindexIntern(): invalid subindex table within index table!\n"); // should never be NULL
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002668
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002669 // search subindex in subindex table
2670 while (nSubIndexCount > 0) {
2671 // check if array is found
2672 if ((pSubEntry->m_Access & kEplObdAccArray) != 0) {
2673 // check if subindex is in range
2674 if (uiSubIndex_p < pObdEntry_p->m_uiCount) {
2675 // update subindex number (subindex entry of an array is always in RAM !!!)
2676 pSubEntry->m_uiSubIndex = uiSubIndex_p;
2677 *ppObdSubEntry_p = pSubEntry;
2678 Ret = kEplSuccessful;
2679 goto Exit;
2680 }
2681 }
2682 // go to the end of this function if subindex is found
2683 else if (uiSubIndex_p == pSubEntry->m_uiSubIndex) {
2684 *ppObdSubEntry_p = pSubEntry;
2685 Ret = kEplSuccessful;
2686 goto Exit;
2687 }
2688 // objects are sorted in OD
2689 // if the current subindex in OD is greater than the subindex which is to search then break loop
2690 // in this case user OD has to be search too
2691 if (uiSubIndex_p < pSubEntry->m_uiSubIndex) {
2692 break;
2693 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002694
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002695 pSubEntry++;
2696 nSubIndexCount--;
2697 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002698
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002699 // in this line SubIndex was not fount
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002700
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002701 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002702
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002703 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002704
2705}
2706
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002707//---------------------------------------------------------------------------
2708//
2709// Function: EplObdSetStoreLoadObjCallback()
2710//
2711// Description: function set address to callbackfunction for command Store and Load
2712//
2713// Parameters: fpCallback_p
2714//
2715// Return: tEplKernel
2716//
2717// State:
2718//
2719//---------------------------------------------------------------------------
2720#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
Greg Kroah-Hartmand9068d62009-03-23 13:26:29 -07002721tEplKernel EplObdSetStoreLoadObjCallback(EPL_MCO_DECL_INSTANCE_PTR_ tEplObdStoreLoadObjCallback fpCallback_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002722{
2723
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002724 EPL_MCO_CHECK_INSTANCE_STATE();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002725
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002726 // set new address of callback function
2727 EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback) = fpCallback_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002728
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002729 return kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002730
2731}
2732#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
2733
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002734//---------------------------------------------------------------------------
2735//
2736// Function: EplObdAccessOdPartIntern()
2737//
2738// Description: runs through OD and executes a job
2739//
2740// Parameters: CurrentOdPart_p
2741// pObdEnty_p
2742// Direction_p = what is to do (load values from flash or EEPROM, store, ...)
2743//
2744// Return: tEplKernel
2745//
2746// State:
2747//
2748//---------------------------------------------------------------------------
2749
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002750static tEplKernel EplObdAccessOdPartIntern(EPL_MCO_DECL_INSTANCE_PTR_
2751 tEplObdPart CurrentOdPart_p,
2752 tEplObdEntryPtr pObdEnty_p,
2753 tEplObdDir Direction_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002754{
2755
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002756 tEplObdSubEntryPtr pSubIndex;
2757 unsigned int nSubIndexCount;
2758 tEplObdAccess Access;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002759 void *pDstData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002760 void *pDefault;
2761 tEplObdSize ObjSize;
2762 tEplKernel Ret;
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002763 tEplObdCbStoreParam CbStore;
2764 tEplObdVarEntry *pVarEntry;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002765
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002766 ASSERT(pObdEnty_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002767
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002768 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002769
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002770 // prepare structure for STORE RESTORE callback function
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002771 CbStore.m_bCurrentOdPart = (u8) CurrentOdPart_p;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002772 CbStore.m_pData = NULL;
2773 CbStore.m_ObjSize = 0;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002774
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002775 // command of first action depends on direction to access
2776#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
2777 if (Direction_p == kEplObdDirLoad) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002778 CbStore.m_bCommand = (u8) kEplObdCommOpenRead;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002779
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002780 // call callback function for previous command
2781 Ret = EplObdCallStoreCallback(EPL_MCO_INSTANCE_PTR_ & CbStore);
2782 if (Ret != kEplSuccessful) {
2783 goto Exit;
2784 }
2785 // set command for index and subindex loop
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002786 CbStore.m_bCommand = (u8) kEplObdCommReadObj;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002787 } else if (Direction_p == kEplObdDirStore) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002788 CbStore.m_bCommand = (u8) kEplObdCommOpenWrite;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002789
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002790 // call callback function for previous command
2791 Ret = EplObdCallStoreCallback(EPL_MCO_INSTANCE_PTR_ & CbStore);
2792 if (Ret != kEplSuccessful) {
2793 goto Exit;
2794 }
2795 // set command for index and subindex loop
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002796 CbStore.m_bCommand = (u8) kEplObdCommWriteObj;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002797 }
2798#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002799
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002800 // we should not restore the OD values here
2801 // the next NMT command "Reset Node" or "Reset Communication" resets the OD data
2802 if (Direction_p != kEplObdDirRestore) {
2803 // walk through OD part till end is found
2804 while (pObdEnty_p->m_uiIndex != EPL_OBD_TABLE_INDEX_END) {
2805 // get address to subindex table and count of subindices
2806 pSubIndex = pObdEnty_p->m_pSubIndex;
2807 nSubIndexCount = pObdEnty_p->m_uiCount;
2808 ASSERT((pSubIndex != NULL) && (nSubIndexCount > 0)); // should never be NULL
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002809
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002810 // walk through subindex table till all subinices were restored
2811 while (nSubIndexCount != 0) {
2812 Access = (tEplObdAccess) pSubIndex->m_Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002813
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002814 // get pointer to current and default data
2815 pDefault = EplObdGetObjectDefaultPtr(pSubIndex);
2816 pDstData = EplObdGetObjectCurrentPtr(pSubIndex);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002817
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002818 // NOTE (for kEplObdTypVString):
2819 // The function returnes the max. number of bytes for a
2820 // current string.
2821 // r.d.: For stings the default-size will be read in other lines following (kEplObdDirInit).
2822 ObjSize = EplObdGetObjectSize(pSubIndex);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002823
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002824 // switch direction of OD access
2825 switch (Direction_p) {
2826 // --------------------------------------------------------------------------
2827 // VarEntry structures has to be initialized
2828 case kEplObdDirInit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002829
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002830 // If VAR-Flag is set, m_pCurrent means not address of data
2831 // but address of tEplObdVarEntry. Address of data has to be get from
2832 // this structure.
2833 if ((Access & kEplObdAccVar) != 0) {
2834 EplObdGetVarEntry(pSubIndex,
2835 &pVarEntry);
2836 EplObdInitVarEntry(pVarEntry,
2837 pSubIndex->
2838 m_Type,
2839 ObjSize);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002840/*
2841 if ((Access & kEplObdAccArray) == 0)
2842 {
2843 EplObdInitVarEntry (pSubIndex->m_pCurrent, pSubIndex->m_Type, ObjSize);
2844 }
2845 else
2846 {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07002847 EplObdInitVarEntry ((tEplObdVarEntry *) (((u8 *) pSubIndex->m_pCurrent) + (sizeof (tEplObdVarEntry) * pSubIndex->m_uiSubIndex)),
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002848 pSubIndex->m_Type, ObjSize);
2849 }
2850*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002851 // at this time no application variable is defined !!!
2852 // therefore data can not be copied.
2853 break;
2854 } else if (pSubIndex->m_Type ==
2855 kEplObdTypVString) {
2856 // If pointer m_pCurrent is not equal to NULL then the
2857 // string was defined with EPL_OBD_SUBINDEX_RAM_VSTRING. The current
2858 // pointer points to struct tEplObdVString located in MEM.
2859 // The element size includes the max. number of
2860 // bytes. The element m_pString includes the pointer
2861 // to string in MEM. The memory location of default string
2862 // must be copied to memory location of current string.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002863
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002864 pDstData =
2865 pSubIndex->m_pCurrent;
2866 if (pDstData != NULL) {
2867 // 08-dec-2004: code optimization !!!
Greg Kroah-Hartman53184872009-03-23 11:48:19 -07002868 // entries ((tEplObdVStringDef*) pSubIndex->m_pDefault)->m_pString
2869 // and ((tEplObdVStringDef*) pSubIndex->m_pDefault)->m_Size were read
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002870 // twice. thats not necessary!
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002871
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002872 // For copying data we have to set the destination pointer to the real RAM string. This
2873 // pointer to RAM string is located in default string info structure. (translated r.d.)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002874 pDstData = (void *)((tEplObdVStringDef*) pSubIndex->m_pDefault)->m_pString;
Greg Kroah-Hartman53184872009-03-23 11:48:19 -07002875 ObjSize = ((tEplObdVStringDef *)pSubIndex->m_pDefault)->m_Size;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002876
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002877 ((tEplObdVString *)pSubIndex->m_pCurrent)->m_pString = pDstData;
2878 ((tEplObdVString *)pSubIndex->m_pCurrent)->m_Size = ObjSize;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002879 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002880
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002881 } else if (pSubIndex->m_Type ==
2882 kEplObdTypOString) {
2883 pDstData =
2884 pSubIndex->m_pCurrent;
2885 if (pDstData != NULL) {
2886 // 08-dec-2004: code optimization !!!
Greg Kroah-Hartman53184872009-03-23 11:48:19 -07002887 // entries ((tEplObdOStringDef*) pSubIndex->m_pDefault)->m_pString
2888 // and ((tEplObdOStringDef*) pSubIndex->m_pDefault)->m_Size were read
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002889 // twice. thats not necessary!
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002890
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002891 // For copying data we have to set the destination pointer to the real RAM string. This
2892 // pointer to RAM string is located in default string info structure. (translated r.d.)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002893 pDstData = (void *)((tEplObdOStringDef *) pSubIndex->m_pDefault)->m_pString;
Greg Kroah-Hartman53184872009-03-23 11:48:19 -07002894 ObjSize = ((tEplObdOStringDef *)pSubIndex->m_pDefault)->m_Size;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002895
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07002896 ((tEplObdOString *)pSubIndex->m_pCurrent)->m_pString = pDstData;
2897 ((tEplObdOString *)pSubIndex->m_pCurrent)->m_Size = ObjSize;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002898 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002899
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002900 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002901
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002902 // no break !! because copy of data has to done too.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002903
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002904 // --------------------------------------------------------------------------
2905 // all objects has to be restored with default values
2906 case kEplObdDirRestore:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002907
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002908 // 09-dec-2004 r.d.: optimization! the same code for kEplObdDirRestore and kEplObdDirLoad
2909 // is replaced to function ObdCopyObjectData() with a new parameter.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002910
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002911 // restore object data for init phase
2912 EplObdCopyObjectData(pDstData, pDefault,
2913 ObjSize,
2914 pSubIndex->m_Type);
2915 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002916
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002917 // --------------------------------------------------------------------------
2918 // objects with attribute kEplObdAccStore has to be load from EEPROM or from a file
2919 case kEplObdDirLoad:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002920
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002921 // restore object data for init phase
2922 EplObdCopyObjectData(pDstData, pDefault,
2923 ObjSize,
2924 pSubIndex->m_Type);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002925
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002926 // no break !! because callback function has to be called too.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002927
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002928 // --------------------------------------------------------------------------
2929 // objects with attribute kEplObdAccStore has to be stored in EEPROM or in a file
2930 case kEplObdDirStore:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002931
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002932 // when attribute kEplObdAccStore is set, then call callback function
2933#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
2934 if ((Access & kEplObdAccStore) != 0) {
2935 // fill out data pointer and size of data
2936 CbStore.m_pData = pDstData;
2937 CbStore.m_ObjSize = ObjSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002938
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002939 // call callback function for read or write object
2940 Ret =
2941 ObdCallStoreCallback
2942 (EPL_MCO_INSTANCE_PTR_ &
2943 CbStore);
2944 if (Ret != kEplSuccessful) {
2945 goto Exit;
2946 }
2947 }
2948#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
2949 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002950
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002951 // --------------------------------------------------------------------------
2952 // if OD Builder key has to be checked no access to subindex and data should be made
2953 case kEplObdDirOBKCheck:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002954
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002955 // no break !! because we want to break the second loop too.
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002956
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002957 // --------------------------------------------------------------------------
2958 // unknown Direction
2959 default:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002960
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002961 // so we can break the second loop earler
2962 nSubIndexCount = 1;
2963 break;
2964 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002965
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002966 nSubIndexCount--;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002967
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002968 // next subindex entry
2969 if ((Access & kEplObdAccArray) == 0) {
2970 pSubIndex++;
2971 if ((nSubIndexCount > 0)
2972 &&
2973 ((pSubIndex->
2974 m_Access & kEplObdAccArray) !=
2975 0)) {
2976 // next subindex points to an array
2977 // reset subindex number
2978 pSubIndex->m_uiSubIndex = 1;
2979 }
2980 } else {
2981 if (nSubIndexCount > 0) {
2982 // next subindex points to an array
2983 // increment subindex number
2984 pSubIndex->m_uiSubIndex++;
2985 }
2986 }
2987 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002988
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002989 // next index entry
2990 pObdEnty_p++;
2991 }
2992 }
2993 // -----------------------------------------------------------------------------------------
2994 // command of last action depends on direction to access
2995 if (Direction_p == kEplObdDirOBKCheck) {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002996
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002997 goto Exit;
2998 }
2999#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
3000 else {
3001 if (Direction_p == kEplObdDirLoad) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07003002 CbStore.m_bCommand = (u8) kEplObdCommCloseRead;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003003 } else if (Direction_p == kEplObdDirStore) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07003004 CbStore.m_bCommand = (u8) kEplObdCommCloseWrite;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003005 } else if (Direction_p == kEplObdDirRestore) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07003006 CbStore.m_bCommand = (u8) kEplObdCommClear;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003007 } else {
3008 goto Exit;
3009 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003010
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003011 // call callback function for last command
3012 Ret = EplObdCallStoreCallback(EPL_MCO_INSTANCE_PTR_ & CbStore);
3013 }
3014#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003015
3016// goto Exit;
3017
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003018 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003019
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003020 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003021
3022}
3023
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003024// ----------------------------------------------------------------------------
3025// Function: EplObdCopyObjectData()
3026//
3027// Description: checks pointers to object data and copy them from source to destination
3028//
3029// Parameters: pDstData_p = destination pointer
3030// pSrcData_p = source pointer
3031// ObjSize_p = size of object
3032// ObjType_p =
3033//
3034// Returns: tEplKernel = error code
3035// ----------------------------------------------------------------------------
3036
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07003037static void EplObdCopyObjectData(void *pDstData_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003038 void *pSrcData_p,
3039 tEplObdSize ObjSize_p, tEplObdType ObjType_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003040{
3041
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003042 tEplObdSize StrSize = 0;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003043
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003044 // it is allowed to set default and current address to NULL (nothing to copy)
3045 if (pDstData_p != NULL) {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003046
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003047 if (ObjType_p == kEplObdTypVString) {
3048 // The function calculates the really number of characters of string. The
3049 // object entry size can be bigger as string size of default string.
3050 // The '\0'-termination is included. A string with no characters has a
3051 // size of 1.
3052 StrSize =
3053 EplObdGetStrLen((void *)pSrcData_p, ObjSize_p,
3054 kEplObdTypVString);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003055
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003056 // If the string length is greater than or equal to the entry size in OD then only copy
3057 // entry size - 1 and always set the '\0'-termination.
3058 if (StrSize >= ObjSize_p) {
3059 StrSize = ObjSize_p - 1;
3060 }
3061 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003062
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003063 if (pSrcData_p != NULL) {
3064 // copy data
3065 EPL_MEMCPY(pDstData_p, pSrcData_p, ObjSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003066
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003067 if (ObjType_p == kEplObdTypVString) {
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07003068 ((char *)pDstData_p)[StrSize] = '\0';
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003069 }
3070 }
3071 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003072
3073}
3074
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003075//---------------------------------------------------------------------------
3076//
3077// Function: EplObdIsNumericalIntern()
3078//
3079// Description: function checks if a entry is numerical or not
3080//
3081//
3082// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = Instancepointer
3083// uiIndex_p = Index
3084// uiSubIndex_p = Subindex
3085// pfEntryNumerical_p = pointer to BOOL for returnvalue
3086// -> TRUE if entry a numerical value
3087// -> FALSE if entry not a numerical value
3088//
3089// Return: tEplKernel = Errorcode
3090//
3091// State:
3092//
3093//---------------------------------------------------------------------------
3094static tEplKernel EplObdIsNumericalIntern(tEplObdSubEntryPtr pObdSubEntry_p,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003095 BOOL * pfEntryNumerical_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003096{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003097 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003098
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003099 // get Type
3100 if ((pObdSubEntry_p->m_Type == kEplObdTypVString)
3101 || (pObdSubEntry_p->m_Type == kEplObdTypOString)
3102 || (pObdSubEntry_p->m_Type == kEplObdTypDomain)) { // not numerical types
3103 *pfEntryNumerical_p = FALSE;
3104 } else { // numerical types
3105 *pfEntryNumerical_p = TRUE;
3106 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003107
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003108 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003109
3110}
3111
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003112// -------------------------------------------------------------------------
3113// function to classify object type (fixed/non fixed)
3114// -------------------------------------------------------------------------
3115
3116// ----------------------------------------------------------------------------
3117// Function: EplObdCallStoreCallback()
3118//
3119// Description: checks address to callback function and calles it when unequal
3120// to NULL
3121//
3122// Parameters: EPL_MCO_DECL_INSTANCE_PTR_ = (instance pointer)
3123// pCbStoreParam_p = address to callback parameters
3124//
3125// Returns: tEplKernel = error code
3126// ----------------------------------------------------------------------------
3127#if (EPL_OBD_USE_STORE_RESTORE != FALSE)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003128static tEplKernel EplObdCallStoreCallback(EPL_MCO_DECL_INSTANCE_PTR_
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -07003129 tEplObdCbStoreParam *
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003130 pCbStoreParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003131{
3132
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003133 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003134
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003135 ASSERT(pCbStoreParam_p != NULL);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003136
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003137 // check if function pointer is NULL - if so, no callback should be called
3138 if (EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback) != NULL) {
3139 Ret =
3140 EPL_MCO_GLB_VAR(m_fpStoreLoadObjCallback)
3141 (EPL_MCO_INSTANCE_PARAM_IDX_()
3142 pCbStoreParam_p);
3143 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003144
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003145 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003146
3147}
3148#endif // (EPL_OBD_USE_STORE_RESTORE != FALSE)
3149//---------------------------------------------------------------------------
3150//
3151// Function: EplObdGetObjectDataPtrIntern()
3152//
3153// Description: Function gets the data pointer of an object.
3154// It returnes the current data pointer. But if object is an
3155// constant object it returnes the default pointer.
3156//
3157// Parameters: pSubindexEntry_p = pointer to subindex entry
3158//
3159// Return: void * = pointer to object data
3160//
3161// State:
3162//
3163//---------------------------------------------------------------------------
3164
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003165void *EplObdGetObjectDataPtrIntern(tEplObdSubEntryPtr pSubindexEntry_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003166{
3167
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003168 void *pData;
3169 tEplObdAccess Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003170
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003171 ASSERTMSG(pSubindexEntry_p != NULL,
3172 "EplObdGetObjectDataPtrIntern(): pointer to SubEntry not valid!\n");
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003173
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003174 // there are are some objects whose data pointer has to get from other structure
3175 // get access type for this object
3176 Access = pSubindexEntry_p->m_Access;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003177
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003178 // If object has access type = const,
3179 // for data only exists default values.
3180 if ((Access & kEplObdAccConst) != 0) {
3181 // The pointer to defualt value can be received from ObdGetObjectDefaultPtr()
3182 pData = ((void *)EplObdGetObjectDefaultPtr(pSubindexEntry_p));
3183 } else {
3184 // The pointer to current value can be received from ObdGetObjectCurrentPtr()
3185 pData = ((void *)EplObdGetObjectCurrentPtr(pSubindexEntry_p));
3186 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003187
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08003188 return pData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08003189
3190}
3191#endif // end of #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) != 0)
3192// EOF