blob: c4419569183f25404f1daa33edcfbb14222c816f [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 generic EPL API 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: EplApiGeneric.c,v $
53
54 $Author: D.Krueger $
55
56 $Revision: 1.21 $ $Date: 2008/11/21 09:00:38 $
57
58 $State: Exp $
59
60 Build Environment:
61 GCC V3.4
62
63 -------------------------------------------------------------------------
64
65 Revision History:
66
67 2006/09/05 d.k.: start of the implementation, version 1.00
68
69****************************************************************************/
70
71#include "Epl.h"
72#include "kernel/EplDllk.h"
73#include "kernel/EplErrorHandlerk.h"
74#include "kernel/EplEventk.h"
75#include "kernel/EplNmtk.h"
76#include "kernel/EplObdk.h"
77#include "kernel/EplTimerk.h"
78#include "kernel/EplDllkCal.h"
79#include "kernel/EplPdokCal.h"
80#include "user/EplDlluCal.h"
81#include "user/EplLedu.h"
82#include "user/EplNmtCnu.h"
83#include "user/EplNmtMnu.h"
84#include "user/EplSdoComu.h"
85#include "user/EplIdentu.h"
86#include "user/EplStatusu.h"
87
88#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
89#include "kernel/EplPdok.h"
90#endif
91
92#include "SharedBuff.h"
93
Daniel Krueger9d7164c2008-12-19 11:41:57 -080094#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) == 0)
95#error "EPL API layer needs EPL module OBDK!"
96#endif
97
Daniel Krueger9d7164c2008-12-19 11:41:57 -080098/***************************************************************************/
99/* */
100/* */
101/* G L O B A L D E F I N I T I O N S */
102/* */
103/* */
104/***************************************************************************/
105
106//---------------------------------------------------------------------------
107// const defines
108//---------------------------------------------------------------------------
109
110//---------------------------------------------------------------------------
111// local types
112//---------------------------------------------------------------------------
113
114//---------------------------------------------------------------------------
115// modul globale vars
116//---------------------------------------------------------------------------
117
118//---------------------------------------------------------------------------
119// local function prototypes
120//---------------------------------------------------------------------------
121
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800122/***************************************************************************/
123/* */
124/* */
125/* C L A S S EplApi */
126/* */
127/* */
128/***************************************************************************/
129//
130// Description:
131//
132//
133/***************************************************************************/
134
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800135//=========================================================================//
136// //
137// P R I V A T E D E F I N I T I O N S //
138// //
139//=========================================================================//
140
141//---------------------------------------------------------------------------
142// const defines
143//---------------------------------------------------------------------------
144
145//---------------------------------------------------------------------------
146// local types
147//---------------------------------------------------------------------------
148
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800149typedef struct {
150 tEplApiInitParam m_InitParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800151
152} tEplApiInstance;
153
154//---------------------------------------------------------------------------
155// local vars
156//---------------------------------------------------------------------------
157
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800158static tEplApiInstance EplApiInstance_g;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800159
160//---------------------------------------------------------------------------
161// local function prototypes
162//---------------------------------------------------------------------------
163
164// NMT state change event callback function
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700165static tEplKernel EplApiCbNmtStateChange(tEplEventNmtStateChange NmtStateChange_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800166
167// update DLL configuration from OD
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700168static tEplKernel EplApiUpdateDllConfig(BOOL fUpdateIdentity_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800169
170// update OD from init param
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700171static tEplKernel EplApiUpdateObd(void);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800172
173// process events from user event queue
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700174static tEplKernel EplApiProcessEvent(tEplEvent *pEplEvent_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800175
176#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
177// callback function of SDO module
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700178static tEplKernel EplApiCbSdoCon(tEplSdoComFinished *pSdoComFinished_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800179#endif
180
181#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
182// callback functions of NmtMnu module
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700183static tEplKernel EplApiCbNodeEvent(unsigned int uiNodeId_p,
184 tEplNmtNodeEvent NodeEvent_p,
185 tEplNmtState NmtState_p,
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -0700186 u16 wErrorCode_p, BOOL fMandatory_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800187
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700188static tEplKernel EplApiCbBootEvent(tEplNmtBootEvent BootEvent_p,
189 tEplNmtState NmtState_p,
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -0700190 u16 wErrorCode_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800191#endif
192
193#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
194// callback function of Ledu module
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700195static tEplKernel EplApiCbLedStateChange(tEplLedType LedType_p, BOOL fOn_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800196#endif
197
198// OD initialization function (implemented in Objdict.c)
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700199tEplKernel EplObdInitRam(tEplObdInitParam *pInitParam_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800200
201//=========================================================================//
202// //
203// P U B L I C F U N C T I O N S //
204// //
205//=========================================================================//
206
207//---------------------------------------------------------------------------
208//
209// Function: EplApiInitialize()
210//
211// Description: add and initialize new instance of EPL stack.
212// After return from this function the application must start
213// the NMT state machine via
214// EplApiExecNmtCommand(kEplNmtEventSwReset)
215// and thereby the whole EPL stack :-)
216//
217// Parameters: pInitParam_p = initialisation parameters
218//
219// Returns: tEplKernel = error code
220//
221//
222// State:
223//
224//---------------------------------------------------------------------------
225
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700226tEplKernel EplApiInitialize(tEplApiInitParam *pInitParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800227{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800228 tEplKernel Ret = kEplSuccessful;
229 tEplObdInitParam ObdInitParam;
230 tEplDllkInitParam DllkInitParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800231#ifndef EPL_NO_FIFO
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800232 tShbError ShbError;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800233#endif
234
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800235 // reset instance structure
236 EPL_MEMSET(&EplApiInstance_g, 0, sizeof(EplApiInstance_g));
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800237
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800238 EPL_MEMCPY(&EplApiInstance_g.m_InitParam, pInitParam_p,
239 min(sizeof(tEplApiInitParam),
240 pInitParam_p->m_uiSizeOfStruct));
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800241
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800242 // check event callback function pointer
243 if (EplApiInstance_g.m_InitParam.m_pfnCbEvent == NULL) { // application must always have an event callback function
244 Ret = kEplApiInvalidParam;
245 goto Exit;
246 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800247#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800248 // init OD
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800249// FIXME
250// Ret = EplObdInitRam(&ObdInitParam);
251// if (Ret != kEplSuccessful)
252// {
253// goto Exit;
254// }
255
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800256 // initialize EplObd module
257 Ret = EplObdInit(&ObdInitParam);
258 if (Ret != kEplSuccessful) {
259 goto Exit;
260 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800261#endif
262
263#ifndef EPL_NO_FIFO
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800264 ShbError = ShbInit();
265 if (ShbError != kShbOk) {
266 Ret = kEplNoResource;
267 goto Exit;
268 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800269#endif
270
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800271 // initialize EplEventk module
272 Ret = EplEventkInit(EplApiInstance_g.m_InitParam.m_pfnCbSync);
273 if (Ret != kEplSuccessful) {
274 goto Exit;
275 }
276 // initialize EplEventu module
277 Ret = EplEventuInit(EplApiProcessEvent);
278 if (Ret != kEplSuccessful) {
279 goto Exit;
280 }
281 // init EplTimerk module
282 Ret = EplTimerkInit();
283 if (Ret != kEplSuccessful) {
284 goto Exit;
285 }
286 // initialize EplNmtk module before DLL
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800287#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800288 Ret = EplNmtkInit();
289 if (Ret != kEplSuccessful) {
290 goto Exit;
291 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800292#endif
293
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800294 // initialize EplDllk module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800295#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800296 EPL_MEMCPY(DllkInitParam.m_be_abSrcMac,
297 EplApiInstance_g.m_InitParam.m_abMacAddress, 6);
298 Ret = EplDllkAddInstance(&DllkInitParam);
299 if (Ret != kEplSuccessful) {
300 goto Exit;
301 }
302 // initialize EplErrorHandlerk module
303 Ret = EplErrorHandlerkInit();
304 if (Ret != kEplSuccessful) {
305 goto Exit;
306 }
307 // initialize EplDllkCal module
308 Ret = EplDllkCalAddInstance();
309 if (Ret != kEplSuccessful) {
310 goto Exit;
311 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800312#endif
313
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800314 // initialize EplDlluCal module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800315#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800316 Ret = EplDlluCalAddInstance();
317 if (Ret != kEplSuccessful) {
318 goto Exit;
319 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800320#endif
321
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800322 // initialize EplPdok module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800323#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800324 Ret = EplPdokAddInstance();
325 if (Ret != kEplSuccessful) {
326 goto Exit;
327 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800328
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800329 Ret = EplPdokCalAddInstance();
330 if (Ret != kEplSuccessful) {
331 goto Exit;
332 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800333#endif
334
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800335 // initialize EplNmtCnu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800336#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_CN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800337 Ret = EplNmtCnuAddInstance(EplApiInstance_g.m_InitParam.m_uiNodeId);
338 if (Ret != kEplSuccessful) {
339 goto Exit;
340 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800341#endif
342
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800343 // initialize EplNmtu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800344#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800345 Ret = EplNmtuInit();
346 if (Ret != kEplSuccessful) {
347 goto Exit;
348 }
349 // register NMT event callback function
350 Ret = EplNmtuRegisterStateChangeCb(EplApiCbNmtStateChange);
351 if (Ret != kEplSuccessful) {
352 goto Exit;
353 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800354#endif
355
356#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800357 // initialize EplNmtMnu module
358 Ret = EplNmtMnuInit(EplApiCbNodeEvent, EplApiCbBootEvent);
359 if (Ret != kEplSuccessful) {
360 goto Exit;
361 }
362 // initialize EplIdentu module
363 Ret = EplIdentuInit();
364 if (Ret != kEplSuccessful) {
365 goto Exit;
366 }
367 // initialize EplStatusu module
368 Ret = EplStatusuInit();
369 if (Ret != kEplSuccessful) {
370 goto Exit;
371 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800372#endif
373
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800374 // initialize EplLedu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800375#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800376 Ret = EplLeduInit(EplApiCbLedStateChange);
377 if (Ret != kEplSuccessful) {
378 goto Exit;
379 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800380#endif
381
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800382 // init SDO module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800383#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0) || \
384 (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0))
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800385 // init sdo command layer
386 Ret = EplSdoComInit();
387 if (Ret != kEplSuccessful) {
388 goto Exit;
389 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800390#endif
391
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800392 // the application must start NMT state machine
393 // via EplApiExecNmtCommand(kEplNmtEventSwReset)
394 // and thereby the whole EPL stack
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800395
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800396 Exit:
397 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800398}
399
400//---------------------------------------------------------------------------
401//
402// Function: EplApiShutdown()
403//
404// Description: deletes an instance of EPL stack
405//
406// Parameters: (none)
407//
408// Returns: tEplKernel = error code
409//
410//
411// State:
412//
413//---------------------------------------------------------------------------
414
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700415tEplKernel EplApiShutdown(void)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800416{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800417 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800418
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800419 // $$$ d.k.: check if NMT state is NMT_GS_OFF
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800420
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800421 // $$$ d.k.: maybe delete event queues at first, but this implies that
422 // no other module must not use the event queues for communication
423 // during shutdown.
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800424
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800425 // delete instance for all modules
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800426
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800427 // deinitialize EplSdoCom module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800428#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0) || \
429 (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0))
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800430 Ret = EplSdoComDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800431// PRINTF1("EplSdoComDelInstance(): 0x%X\n", Ret);
432#endif
433
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800434 // deinitialize EplLedu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800435#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800436 Ret = EplLeduDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800437// PRINTF1("EplLeduDelInstance(): 0x%X\n", Ret);
438#endif
439
440#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800441 // deinitialize EplNmtMnu module
442 Ret = EplNmtMnuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800443// PRINTF1("EplNmtMnuDelInstance(): 0x%X\n", Ret);
444
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800445 // deinitialize EplIdentu module
446 Ret = EplIdentuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800447// PRINTF1("EplIdentuDelInstance(): 0x%X\n", Ret);
448
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800449 // deinitialize EplStatusu module
450 Ret = EplStatusuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800451// PRINTF1("EplStatusuDelInstance(): 0x%X\n", Ret);
452#endif
453
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800454 // deinitialize EplNmtCnu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800455#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_CN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800456 Ret = EplNmtCnuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800457// PRINTF1("EplNmtCnuDelInstance(): 0x%X\n", Ret);
458#endif
459
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800460 // deinitialize EplNmtu module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800461#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800462 Ret = EplNmtuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800463// PRINTF1("EplNmtuDelInstance(): 0x%X\n", Ret);
464#endif
465
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800466 // deinitialize EplDlluCal module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800467#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800468 Ret = EplDlluCalDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800469// PRINTF1("EplDlluCalDelInstance(): 0x%X\n", Ret);
470
471#endif
472
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800473 // deinitialize EplEventu module
474 Ret = EplEventuDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800475// PRINTF1("EplEventuDelInstance(): 0x%X\n", Ret);
476
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800477 // deinitialize EplNmtk module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800478#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800479 Ret = EplNmtkDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800480// PRINTF1("EplNmtkDelInstance(): 0x%X\n", Ret);
481#endif
482
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800483 // deinitialize EplDllk module
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800484#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800485 Ret = EplDllkDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800486// PRINTF1("EplDllkDelInstance(): 0x%X\n", Ret);
487
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800488 // deinitialize EplDllkCal module
489 Ret = EplDllkCalDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800490// PRINTF1("EplDllkCalDelInstance(): 0x%X\n", Ret);
491#endif
492
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800493 // deinitialize EplEventk module
494 Ret = EplEventkDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800495// PRINTF1("EplEventkDelInstance(): 0x%X\n", Ret);
496
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800497 // deinitialize EplTimerk module
498 Ret = EplTimerkDelInstance();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800499// PRINTF1("EplTimerkDelInstance(): 0x%X\n", Ret);
500
501#ifndef EPL_NO_FIFO
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800502 ShbExit();
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800503#endif
504
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800505 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800506}
507
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800508//----------------------------------------------------------------------------
509// Function: EplApiExecNmtCommand()
510//
511// Description: executes a NMT command, i.e. post the NMT command/event to the
512// NMTk module. NMT commands which are not appropriate in the current
513// NMT state are silently ignored. Please keep in mind that the
514// NMT state may change until the NMT command is actually executed.
515//
516// Parameters: NmtEvent_p = NMT command/event
517//
518// Returns: tEplKernel = error code
519//
520// State:
521//----------------------------------------------------------------------------
522
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700523tEplKernel EplApiExecNmtCommand(tEplNmtEvent NmtEvent_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800524{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800525 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800526
527#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800528 Ret = EplNmtuNmtEvent(NmtEvent_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800529#endif
530
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800531 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800532}
533
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800534//----------------------------------------------------------------------------
535// Function: EplApiLinkObject()
536//
537// Description: Function maps array of application variables onto specified object in OD
538//
539// Parameters: uiObjIndex_p = Function maps variables for this object index
540// pVar_p = Pointer to data memory area for the specified object
541// puiVarEntries_p = IN: pointer to number of entries to map
542// OUT: pointer to number of actually used entries
543// pEntrySize_p = IN: pointer to size of one entry;
544// if size is zero, the actual size will be read from OD
545// OUT: pointer to entire size of all entries mapped
546// uiFirstSubindex_p = This is the first subindex to be mapped.
547//
548// Returns: tEplKernel = error code
549//
550// State:
551//----------------------------------------------------------------------------
552
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700553tEplKernel EplApiLinkObject(unsigned int uiObjIndex_p,
554 void *pVar_p,
555 unsigned int *puiVarEntries_p,
556 tEplObdSize *pEntrySize_p,
557 unsigned int uiFirstSubindex_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800558{
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700559 u8 bVarEntries;
560 u8 bIndexEntries;
561 u8 *pbData;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800562 unsigned int uiSubindex;
563 tEplVarParam VarParam;
564 tEplObdSize EntrySize;
565 tEplObdSize UsedSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800566
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800567 tEplKernel RetCode = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800568
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800569 if ((pVar_p == NULL)
570 || (puiVarEntries_p == NULL)
571 || (*puiVarEntries_p == 0)
572 || (pEntrySize_p == NULL)) {
573 RetCode = kEplApiInvalidParam;
574 goto Exit;
575 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800576
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700577 pbData = (u8 *)pVar_p;
578 bVarEntries = (u8) * puiVarEntries_p;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800579 UsedSize = 0;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800580
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800581 // init VarParam structure with default values
582 VarParam.m_uiIndex = uiObjIndex_p;
583 VarParam.m_ValidFlag = kVarValidAll;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800584
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800585 if (uiFirstSubindex_p != 0) { // check if object exists by reading subindex 0x00,
586 // because user wants to link a variable to a subindex unequal 0x00
587 // read number of entries
588 EntrySize = (tEplObdSize) sizeof(bIndexEntries);
589 RetCode = EplObdReadEntry(uiObjIndex_p,
590 0x00,
Greg Kroah-Hartmanbd3966d2009-03-23 11:37:22 -0700591 (void *)&bIndexEntries,
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800592 &EntrySize);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800593
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800594 if ((RetCode != kEplSuccessful) || (bIndexEntries == 0x00)) {
595 // Object doesn't exist or invalid entry number
596 RetCode = kEplObdIndexNotExist;
597 goto Exit;
598 }
599 } else { // user wants to link a variable to subindex 0x00
600 // that's OK
601 bIndexEntries = 0;
602 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800603
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800604 // Correct number of entries if number read from OD is greater
605 // than the specified number.
606 // This is done, so that we do not set more entries than subindexes the
607 // object actually has.
608 if ((bIndexEntries > (bVarEntries + uiFirstSubindex_p - 1)) &&
609 (bVarEntries != 0x00)) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -0700610 bIndexEntries = (u8) (bVarEntries + uiFirstSubindex_p - 1);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800611 }
612 // map entries
613 for (uiSubindex = uiFirstSubindex_p; uiSubindex <= bIndexEntries;
614 uiSubindex++) {
615 // if passed entry size is 0, then get size from OD
616 if (*pEntrySize_p == 0x00) {
617 // read entry size
618 EntrySize = EplObdGetDataSize(uiObjIndex_p, uiSubindex);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800619
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800620 if (EntrySize == 0x00) {
621 // invalid entry size (maybe object doesn't exist or entry of type DOMAIN is empty)
622 RetCode = kEplObdSubindexNotExist;
623 break;
624 }
625 } else { // use passed entry size
626 EntrySize = *pEntrySize_p;
627 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800628
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800629 VarParam.m_uiSubindex = uiSubindex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800630
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800631 // set pointer to user var
632 VarParam.m_Size = EntrySize;
633 VarParam.m_pData = pbData;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800634
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800635 UsedSize += EntrySize;
636 pbData += EntrySize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800637
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800638 RetCode = EplObdDefineVar(&VarParam);
639 if (RetCode != kEplSuccessful) {
640 break;
641 }
642 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800643
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800644 // set number of mapped entries and entry size
645 *puiVarEntries_p = ((bIndexEntries - uiFirstSubindex_p) + 1);
646 *pEntrySize_p = UsedSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800647
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800648 Exit:
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800649
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800650 return (RetCode);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800651
652}
653
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800654// ----------------------------------------------------------------------------
655//
656// Function: EplApiReadObject()
657//
658// Description: reads the specified entry from the OD of the specified node.
659// If this node is a remote node, it performs a SDO transfer, which
660// means this function returns kEplApiTaskDeferred and the application
661// is informed via the event callback function when the task is completed.
662//
663// Parameters: pSdoComConHdl_p = INOUT: pointer to SDO connection handle (may be NULL in case of local OD access)
664// uiNodeId_p = IN: node ID (0 = itself)
665// uiIndex_p = IN: index of object in OD
666// uiSubindex_p = IN: sub-index of object in OD
667// pDstData_le_p = OUT: pointer to data in little endian
668// puiSize_p = INOUT: pointer to size of data
669// SdoType_p = IN: type of SDO transfer
670// pUserArg_p = IN: user-definable argument pointer,
671// which will be passed to the event callback function
672//
673// Return: tEplKernel = error code
674//
675// ----------------------------------------------------------------------------
676
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700677tEplKernel EplApiReadObject(tEplSdoComConHdl *pSdoComConHdl_p,
678 unsigned int uiNodeId_p,
679 unsigned int uiIndex_p,
680 unsigned int uiSubindex_p,
681 void *pDstData_le_p,
682 unsigned int *puiSize_p,
683 tEplSdoType SdoType_p, void *pUserArg_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800684{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800685 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800686
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800687 if ((uiIndex_p == 0) || (pDstData_le_p == NULL) || (puiSize_p == NULL)
688 || (*puiSize_p == 0)) {
689 Ret = kEplApiInvalidParam;
690 goto Exit;
691 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800692
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800693 if (uiNodeId_p == 0 || uiNodeId_p == EplObdGetNodeId()) { // local OD access can be performed
694 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800695
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800696 ObdSize = (tEplObdSize) * puiSize_p;
697 Ret =
698 EplObdReadEntryToLe(uiIndex_p, uiSubindex_p, pDstData_le_p,
699 &ObdSize);
700 *puiSize_p = (unsigned int)ObdSize;
701 } else { // perform SDO transfer
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800702#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800703 tEplSdoComTransParamByIndex TransParamByIndex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800704// tEplSdoComConHdl SdoComConHdl;
705
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800706 // check if application provides space for handle
707 if (pSdoComConHdl_p == NULL) {
708 Ret = kEplApiInvalidParam;
709 goto Exit;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800710// pSdoComConHdl_p = &SdoComConHdl;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800711 }
712 // init command layer connection
713 Ret = EplSdoComDefineCon(pSdoComConHdl_p, uiNodeId_p, // target node id
714 SdoType_p); // SDO type
715 if ((Ret != kEplSuccessful) && (Ret != kEplSdoComHandleExists)) {
716 goto Exit;
717 }
718 TransParamByIndex.m_pData = pDstData_le_p;
719 TransParamByIndex.m_SdoAccessType = kEplSdoAccessTypeRead;
720 TransParamByIndex.m_SdoComConHdl = *pSdoComConHdl_p;
721 TransParamByIndex.m_uiDataSize = *puiSize_p;
722 TransParamByIndex.m_uiIndex = uiIndex_p;
723 TransParamByIndex.m_uiSubindex = uiSubindex_p;
724 TransParamByIndex.m_pfnSdoFinishedCb = EplApiCbSdoCon;
725 TransParamByIndex.m_pUserArg = pUserArg_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800726
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800727 Ret = EplSdoComInitTransferByIndex(&TransParamByIndex);
728 if (Ret != kEplSuccessful) {
729 goto Exit;
730 }
731 Ret = kEplApiTaskDeferred;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800732
733#else
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800734 Ret = kEplApiInvalidParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800735#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800736 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800737
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800738 Exit:
739 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800740}
741
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800742// ----------------------------------------------------------------------------
743//
744// Function: EplApiWriteObject()
745//
746// Description: writes the specified entry to the OD of the specified node.
747// If this node is a remote node, it performs a SDO transfer, which
748// means this function returns kEplApiTaskDeferred and the application
749// is informed via the event callback function when the task is completed.
750//
751// Parameters: pSdoComConHdl_p = INOUT: pointer to SDO connection handle (may be NULL in case of local OD access)
752// uiNodeId_p = IN: node ID (0 = itself)
753// uiIndex_p = IN: index of object in OD
754// uiSubindex_p = IN: sub-index of object in OD
755// pSrcData_le_p = IN: pointer to data in little endian
756// uiSize_p = IN: size of data in bytes
757// SdoType_p = IN: type of SDO transfer
758// pUserArg_p = IN: user-definable argument pointer,
759// which will be passed to the event callback function
760//
761// Return: tEplKernel = error code
762//
763// ----------------------------------------------------------------------------
764
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700765tEplKernel EplApiWriteObject(tEplSdoComConHdl *pSdoComConHdl_p,
766 unsigned int uiNodeId_p,
767 unsigned int uiIndex_p,
768 unsigned int uiSubindex_p,
769 void *pSrcData_le_p,
770 unsigned int uiSize_p,
771 tEplSdoType SdoType_p, void *pUserArg_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800772{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800773 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800774
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800775 if ((uiIndex_p == 0) || (pSrcData_le_p == NULL) || (uiSize_p == 0)) {
776 Ret = kEplApiInvalidParam;
777 goto Exit;
778 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800779
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800780 if (uiNodeId_p == 0 || uiNodeId_p == EplObdGetNodeId()) { // local OD access can be performed
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800781
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800782 Ret =
783 EplObdWriteEntryFromLe(uiIndex_p, uiSubindex_p,
784 pSrcData_le_p, uiSize_p);
785 } else { // perform SDO transfer
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800786#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800787 tEplSdoComTransParamByIndex TransParamByIndex;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800788// tEplSdoComConHdl SdoComConHdl;
789
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800790 // check if application provides space for handle
791 if (pSdoComConHdl_p == NULL) {
792 Ret = kEplApiInvalidParam;
793 goto Exit;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800794// pSdoComConHdl_p = &SdoComConHdl;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800795 }
796 // d.k.: How to recycle command layer connection?
797 // Try to redefine it, which will return kEplSdoComHandleExists
798 // and the existing command layer handle.
799 // If the returned handle is busy, EplSdoComInitTransferByIndex()
800 // will return with error.
801 // $$$ d.k.: Collisions may occur with Configuration Manager, if both the application and
802 // Configuration Manager, are trying to communicate with the very same node.
803 // possible solution: disallow communication by application if Configuration Manager is busy
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800804
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800805 // init command layer connection
806 Ret = EplSdoComDefineCon(pSdoComConHdl_p, uiNodeId_p, // target node id
807 SdoType_p); // SDO type
808 if ((Ret != kEplSuccessful) && (Ret != kEplSdoComHandleExists)) {
809 goto Exit;
810 }
811 TransParamByIndex.m_pData = pSrcData_le_p;
812 TransParamByIndex.m_SdoAccessType = kEplSdoAccessTypeWrite;
813 TransParamByIndex.m_SdoComConHdl = *pSdoComConHdl_p;
814 TransParamByIndex.m_uiDataSize = uiSize_p;
815 TransParamByIndex.m_uiIndex = uiIndex_p;
816 TransParamByIndex.m_uiSubindex = uiSubindex_p;
817 TransParamByIndex.m_pfnSdoFinishedCb = EplApiCbSdoCon;
818 TransParamByIndex.m_pUserArg = pUserArg_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800819
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800820 Ret = EplSdoComInitTransferByIndex(&TransParamByIndex);
821 if (Ret != kEplSuccessful) {
822 goto Exit;
823 }
824 Ret = kEplApiTaskDeferred;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800825
826#else
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800827 Ret = kEplApiInvalidParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800828#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800829 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800830
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800831 Exit:
832 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800833}
834
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800835// ----------------------------------------------------------------------------
836//
837// Function: EplApiFreeSdoChannel()
838//
839// Description: frees the specified SDO channel.
840// This function must be called after each call to EplApiReadObject()/EplApiWriteObject()
841// which returns kEplApiTaskDeferred and the application
842// is informed via the event callback function when the task is completed.
843//
844// Parameters: SdoComConHdl_p = IN: SDO connection handle
845//
846// Return: tEplKernel = error code
847//
848// ----------------------------------------------------------------------------
849
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700850tEplKernel EplApiFreeSdoChannel(tEplSdoComConHdl SdoComConHdl_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800851{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800852 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800853
854#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
855
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800856 // init command layer connection
857 Ret = EplSdoComUndefineCon(SdoComConHdl_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800858
859#else
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800860 Ret = kEplApiInvalidParam;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800861#endif
862
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800863 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800864}
865
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800866// ----------------------------------------------------------------------------
867//
868// Function: EplApiReadLocalObject()
869//
870// Description: reads the specified entry from the local OD.
871//
872// Parameters: uiIndex_p = IN: index of object in OD
873// uiSubindex_p = IN: sub-index of object in OD
874// pDstData_p = OUT: pointer to data in platform byte order
875// puiSize_p = INOUT: pointer to size of data
876//
877// Return: tEplKernel = error code
878//
879// ----------------------------------------------------------------------------
880
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700881tEplKernel EplApiReadLocalObject(unsigned int uiIndex_p,
882 unsigned int uiSubindex_p,
883 void *pDstData_p, unsigned int *puiSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800884{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800885 tEplKernel Ret = kEplSuccessful;
886 tEplObdSize ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800887
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800888 ObdSize = (tEplObdSize) * puiSize_p;
889 Ret = EplObdReadEntry(uiIndex_p, uiSubindex_p, pDstData_p, &ObdSize);
890 *puiSize_p = (unsigned int)ObdSize;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800891
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800892 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800893}
894
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800895// ----------------------------------------------------------------------------
896//
897// Function: EplApiWriteLocalObject()
898//
899// Description: writes the specified entry to the local OD.
900//
901// Parameters: uiIndex_p = IN: index of object in OD
902// uiSubindex_p = IN: sub-index of object in OD
903// pSrcData_p = IN: pointer to data in platform byte order
904// uiSize_p = IN: size of data in bytes
905//
906// Return: tEplKernel = error code
907//
908// ----------------------------------------------------------------------------
909
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700910tEplKernel EplApiWriteLocalObject(unsigned int uiIndex_p,
911 unsigned int uiSubindex_p,
912 void *pSrcData_p,
913 unsigned int uiSize_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800914{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800915 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800916
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800917 Ret =
918 EplObdWriteEntry(uiIndex_p, uiSubindex_p, pSrcData_p,
919 (tEplObdSize) uiSize_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800920
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800921 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800922}
923
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800924#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
925// ----------------------------------------------------------------------------
926//
927// Function: EplApiMnTriggerStateChange()
928//
929// Description: triggers the specified node command for the specified node.
930//
931// Parameters: uiNodeId_p = node ID for which the node command will be executed
932// NodeCommand_p = node command
933//
934// Return: tEplKernel = error code
935//
936// ----------------------------------------------------------------------------
937
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -0700938tEplKernel EplApiMnTriggerStateChange(unsigned int uiNodeId_p,
939 tEplNmtNodeCommand NodeCommand_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800940{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800941 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800942
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800943 Ret = EplNmtMnuTriggerStateChange(uiNodeId_p, NodeCommand_p);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800944
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800945 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800946}
947
948#endif // (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
949
950//---------------------------------------------------------------------------
951//
952// Function: EplApiCbObdAccess
953//
954// Description: callback function for OD accesses
955//
956// Parameters: pParam_p = OBD parameter
957//
958// Returns: tEplKernel = error code
959//
960//
961// State:
962//
963//---------------------------------------------------------------------------
964
Greg Kroah-Hartman5e9f6bc2009-03-23 12:09:26 -0700965tEplKernel EplApiCbObdAccess(tEplObdCbParam *pParam_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800966{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800967 tEplKernel Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800968
969#if (EPL_API_OBD_FORWARD_EVENT != FALSE)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800970 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800971
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800972 // call user callback
973 // must be disabled for EplApiLinuxKernel.c, because of reentrancy problem
974 // for local OD access. This is not so bad as user callback function in
975 // application does not use OD callbacks at the moment.
976 EventArg.m_ObdCbParam = *pParam_p;
977 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventObdAccess,
978 &EventArg,
979 EplApiInstance_g.
980 m_InitParam.
981 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800982#endif
983
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800984 switch (pParam_p->m_uiIndex) {
985 //case 0x1006: // NMT_CycleLen_U32 (valid on reset)
986 case 0x1C14: // DLL_LossOfFrameTolerance_U32
987 //case 0x1F98: // NMT_CycleTiming_REC (valid on reset)
988 {
989 if (pParam_p->m_ObdEvent == kEplObdEvPostWrite) {
990 // update DLL configuration
991 Ret = EplApiUpdateDllConfig(FALSE);
992 }
993 break;
994 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -0800995
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -0800996 case 0x1020: // CFM_VerifyConfiguration_REC.ConfId_U32 != 0
997 {
998 if ((pParam_p->m_ObdEvent == kEplObdEvPostWrite)
999 && (pParam_p->m_uiSubIndex == 3)
Greg Kroah-Hartmand539cfb2009-03-23 12:51:37 -07001000 && (*((u32 *) pParam_p->m_pArg) != 0)) {
1001 u32 dwVerifyConfInvalid = 0;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001002 // set CFM_VerifyConfiguration_REC.VerifyConfInvalid_U32 to 0
1003 Ret =
1004 EplObdWriteEntry(0x1020, 4,
1005 &dwVerifyConfInvalid, 4);
1006 // ignore any error because this objekt is optional
1007 Ret = kEplSuccessful;
1008 }
1009 break;
1010 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001011
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001012 case 0x1F9E: // NMT_ResetCmd_U8
1013 {
1014 if (pParam_p->m_ObdEvent == kEplObdEvPreWrite) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001015 u8 bNmtCommand;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001016
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001017 bNmtCommand = *((u8 *) pParam_p->m_pArg);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001018 // check value range
1019 switch ((tEplNmtCommand) bNmtCommand) {
1020 case kEplNmtCmdResetNode:
1021 case kEplNmtCmdResetCommunication:
1022 case kEplNmtCmdResetConfiguration:
1023 case kEplNmtCmdSwReset:
1024 case kEplNmtCmdInvalidService:
1025 // valid command identifier specified
1026 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001027
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001028 default:
1029 pParam_p->m_dwAbortCode =
1030 EPL_SDOAC_VALUE_RANGE_EXCEEDED;
1031 Ret = kEplObdAccessViolation;
1032 break;
1033 }
1034 } else if (pParam_p->m_ObdEvent == kEplObdEvPostWrite) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001035 u8 bNmtCommand;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001036
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001037 bNmtCommand = *((u8 *) pParam_p->m_pArg);
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001038 // check value range
1039 switch ((tEplNmtCommand) bNmtCommand) {
1040 case kEplNmtCmdResetNode:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001041#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001042 Ret =
1043 EplNmtuNmtEvent
1044 (kEplNmtEventResetNode);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001045#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001046 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001047
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001048 case kEplNmtCmdResetCommunication:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001049#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001050 Ret =
1051 EplNmtuNmtEvent
1052 (kEplNmtEventResetCom);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001053#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001054 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001055
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001056 case kEplNmtCmdResetConfiguration:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001057#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001058 Ret =
1059 EplNmtuNmtEvent
1060 (kEplNmtEventResetConfig);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001061#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001062 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001063
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001064 case kEplNmtCmdSwReset:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001065#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001066 Ret =
1067 EplNmtuNmtEvent
1068 (kEplNmtEventSwReset);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001069#endif
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001070 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001071
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001072 case kEplNmtCmdInvalidService:
1073 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001074
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001075 default:
1076 pParam_p->m_dwAbortCode =
1077 EPL_SDOAC_VALUE_RANGE_EXCEEDED;
1078 Ret = kEplObdAccessViolation;
1079 break;
1080 }
1081 }
1082 break;
1083 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001084
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001085 default:
1086 break;
1087 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001088
1089//Exit:
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001090 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001091}
1092
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001093//=========================================================================//
1094// //
1095// P R I V A T E F U N C T I O N S //
1096// //
1097//=========================================================================//
1098
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001099//---------------------------------------------------------------------------
1100//
1101// Function: EplApiProcessEvent
1102//
1103// Description: processes events from event queue and forwards these to
1104// the application's event callback function
1105//
1106// Parameters: pEplEvent_p = pointer to event
1107//
1108// Returns: tEplKernel = errorcode
1109//
1110// State:
1111//
1112//---------------------------------------------------------------------------
1113
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001114static tEplKernel EplApiProcessEvent(tEplEvent *pEplEvent_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001115{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001116 tEplKernel Ret;
1117 tEplEventError *pEventError;
1118 tEplApiEventType EventType;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001119
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001120 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001121
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001122 // process event
1123 switch (pEplEvent_p->m_EventType) {
1124 // error event
1125 case kEplEventTypeError:
1126 {
1127 pEventError = (tEplEventError *) pEplEvent_p->m_pArg;
1128 switch (pEventError->m_EventSource) {
1129 // treat the errors from the following sources as critical
1130 case kEplEventSourceEventk:
1131 case kEplEventSourceEventu:
1132 case kEplEventSourceDllk:
1133 {
1134 EventType = kEplApiEventCriticalError;
1135 // halt the stack by entering NMT state Off
1136 Ret =
1137 EplNmtuNmtEvent
1138 (kEplNmtEventCriticalError);
1139 break;
1140 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001141
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001142 // the other errors are just warnings
1143 default:
1144 {
1145 EventType = kEplApiEventWarning;
1146 break;
1147 }
1148 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001149
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001150 // call user callback
1151 Ret =
1152 EplApiInstance_g.m_InitParam.m_pfnCbEvent(EventType,
1153 (tEplApiEventArg
1154 *)
1155 pEventError,
1156 EplApiInstance_g.
1157 m_InitParam.
1158 m_pEventUserArg);
1159 // discard error from callback function, because this could generate an endless loop
1160 Ret = kEplSuccessful;
1161 break;
1162 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001163
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001164 // at present, there are no other events for this module
1165 default:
1166 break;
1167 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001168
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001169 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001170}
1171
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001172//---------------------------------------------------------------------------
1173//
1174// Function: EplApiCbNmtStateChange
1175//
1176// Description: callback function for NMT state changes
1177//
1178// Parameters: NmtStateChange_p = NMT state change event
1179//
1180// Returns: tEplKernel = error code
1181//
1182//
1183// State:
1184//
1185//---------------------------------------------------------------------------
1186
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001187static tEplKernel EplApiCbNmtStateChange(tEplEventNmtStateChange NmtStateChange_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001188{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001189 tEplKernel Ret = kEplSuccessful;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001190 u8 bNmtState;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001191 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001192
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001193 // save NMT state in OD
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001194 bNmtState = (u8) NmtStateChange_p.m_NewNmtState;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001195 Ret = EplObdWriteEntry(0x1F8C, 0, &bNmtState, 1);
1196 if (Ret != kEplSuccessful) {
1197 goto Exit;
1198 }
1199 // do work which must be done in that state
1200 switch (NmtStateChange_p.m_NewNmtState) {
1201 // EPL stack is not running
1202 case kEplNmtGsOff:
1203 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001204
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001205 // first init of the hardware
1206 case kEplNmtGsInitialising:
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001207#if 0
1208#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDO_UDP)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001209 // configure SDO via UDP (i.e. bind it to the EPL ethernet interface)
1210 Ret =
1211 EplSdoUdpuConfig(EplApiInstance_g.m_InitParam.m_dwIpAddress,
1212 EPL_C_SDO_EPL_PORT);
1213 if (Ret != kEplSuccessful) {
1214 goto Exit;
1215 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001216#endif
1217#endif
1218
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001219 break;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001220
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001221 // init of the manufacturer-specific profile area and the
1222 // standardised device profile area
1223 case kEplNmtGsResetApplication:
1224 {
1225 // reset application part of OD
1226 Ret = EplObdAccessOdPart(kEplObdPartApp,
1227 kEplObdDirLoad);
1228 if (Ret != kEplSuccessful) {
1229 goto Exit;
1230 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001231
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001232 break;
1233 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001234
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001235 // init of the communication profile area
1236 case kEplNmtGsResetCommunication:
1237 {
1238 // reset communication part of OD
1239 Ret = EplObdAccessOdPart(kEplObdPartGen,
1240 kEplObdDirLoad);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001241
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001242 if (Ret != kEplSuccessful) {
1243 goto Exit;
1244 }
1245 // $$$ d.k.: update OD only if OD was not loaded from non-volatile memory
1246 Ret = EplApiUpdateObd();
1247 if (Ret != kEplSuccessful) {
1248 goto Exit;
1249 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001250
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001251 break;
1252 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001253
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001254 // build the configuration with infos from OD
1255 case kEplNmtGsResetConfiguration:
1256 {
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001257
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001258 Ret = EplApiUpdateDllConfig(TRUE);
1259 if (Ret != kEplSuccessful) {
1260 goto Exit;
1261 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001262
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 //-----------------------------------------------------------
1267 // CN part of the state machine
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001268
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001269 // node liste for EPL-Frames and check timeout
1270 case kEplNmtCsNotActive:
1271 {
1272 // indicate completion of reset in NMT_ResetCmd_U8
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001273 bNmtState = (u8) kEplNmtCmdInvalidService;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001274 Ret = EplObdWriteEntry(0x1F9E, 0, &bNmtState, 1);
1275 if (Ret != kEplSuccessful) {
1276 goto Exit;
1277 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001278
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001279 break;
1280 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001281
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001282 // node process only async frames
1283 case kEplNmtCsPreOperational1:
1284 {
1285 break;
1286 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001287
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001288 // node process isochronus and asynchronus frames
1289 case kEplNmtCsPreOperational2:
1290 {
1291 break;
1292 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001293
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001294 // node should be configured und application is ready
1295 case kEplNmtCsReadyToOperate:
1296 {
1297 break;
1298 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001299
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001300 // normal work state
1301 case kEplNmtCsOperational:
1302 {
1303 break;
1304 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001305
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001306 // node stopped by MN
1307 // -> only process asynchronus frames
1308 case kEplNmtCsStopped:
1309 {
1310 break;
1311 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001312
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001313 // no EPL cycle
1314 // -> normal ethernet communication
1315 case kEplNmtCsBasicEthernet:
1316 {
1317 break;
1318 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001319
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001320 //-----------------------------------------------------------
1321 // MN part of the state machine
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001322
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001323 // node listens for EPL-Frames and check timeout
1324 case kEplNmtMsNotActive:
1325 {
1326 break;
1327 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001328
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001329 // node processes only async frames
1330 case kEplNmtMsPreOperational1:
1331 {
1332 break;
1333 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001334
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001335 // node processes isochronous and asynchronous frames
1336 case kEplNmtMsPreOperational2:
1337 {
1338 break;
1339 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001340
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001341 // node should be configured und application is ready
1342 case kEplNmtMsReadyToOperate:
1343 {
1344 break;
1345 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001346
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001347 // normal work state
1348 case kEplNmtMsOperational:
1349 {
1350 break;
1351 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001352
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001353 // no EPL cycle
1354 // -> normal ethernet communication
1355 case kEplNmtMsBasicEthernet:
1356 {
1357 break;
1358 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001359
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001360 default:
1361 {
1362 TRACE0
1363 ("EplApiCbNmtStateChange(): unhandled NMT state\n");
1364 }
1365 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001366
1367#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001368 // forward event to Led module
1369 Ret = EplLeduCbNmtStateChange(NmtStateChange_p);
1370 if (Ret != kEplSuccessful) {
1371 goto Exit;
1372 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001373#endif
1374
1375#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001376 // forward event to NmtMn module
1377 Ret = EplNmtMnuCbNmtStateChange(NmtStateChange_p);
1378 if (Ret != kEplSuccessful) {
1379 goto Exit;
1380 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001381#endif
1382
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001383 // call user callback
1384 EventArg.m_NmtStateChange = NmtStateChange_p;
1385 Ret =
1386 EplApiInstance_g.m_InitParam.
1387 m_pfnCbEvent(kEplApiEventNmtStateChange, &EventArg,
1388 EplApiInstance_g.m_InitParam.m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001389
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001390 Exit:
1391 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001392}
1393
1394//---------------------------------------------------------------------------
1395//
1396// Function: EplApiUpdateDllConfig
1397//
1398// Description: update configuration of DLL
1399//
1400// Parameters: fUpdateIdentity_p = TRUE, if identity must be updated
1401//
1402// Returns: tEplKernel = error code
1403//
1404//
1405// State:
1406//
1407//---------------------------------------------------------------------------
1408
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001409static tEplKernel EplApiUpdateDllConfig(BOOL fUpdateIdentity_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001410{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001411 tEplKernel Ret = kEplSuccessful;
1412 tEplDllConfigParam DllConfigParam;
1413 tEplDllIdentParam DllIdentParam;
1414 tEplObdSize ObdSize;
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001415 u16 wTemp;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001416 u8 bTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001417
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001418 // configure Dll
1419 EPL_MEMSET(&DllConfigParam, 0, sizeof(DllConfigParam));
1420 DllConfigParam.m_uiNodeId = EplObdGetNodeId();
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001421
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001422 // Cycle Length (0x1006: NMT_CycleLen_U32) in [us]
1423 ObdSize = 4;
1424 Ret =
1425 EplObdReadEntry(0x1006, 0, &DllConfigParam.m_dwCycleLen, &ObdSize);
1426 if (Ret != kEplSuccessful) {
1427 goto Exit;
1428 }
1429 // 0x1F82: NMT_FeatureFlags_U32
1430 ObdSize = 4;
1431 Ret =
1432 EplObdReadEntry(0x1F82, 0, &DllConfigParam.m_dwFeatureFlags,
1433 &ObdSize);
1434 if (Ret != kEplSuccessful) {
1435 goto Exit;
1436 }
1437 // d.k. There is no dependance between FeatureFlags and async-only CN
1438 DllConfigParam.m_fAsyncOnly = EplApiInstance_g.m_InitParam.m_fAsyncOnly;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001439
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001440 // 0x1C14: DLL_LossOfFrameTolerance_U32 in [ns]
1441 ObdSize = 4;
1442 Ret =
1443 EplObdReadEntry(0x1C14, 0, &DllConfigParam.m_dwLossOfFrameTolerance,
1444 &ObdSize);
1445 if (Ret != kEplSuccessful) {
1446 goto Exit;
1447 }
1448 // 0x1F98: NMT_CycleTiming_REC
1449 // 0x1F98.1: IsochrTxMaxPayload_U16
1450 ObdSize = 2;
1451 Ret = EplObdReadEntry(0x1F98, 1, &wTemp, &ObdSize);
1452 if (Ret != kEplSuccessful) {
1453 goto Exit;
1454 }
1455 DllConfigParam.m_uiIsochrTxMaxPayload = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001456
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001457 // 0x1F98.2: IsochrRxMaxPayload_U16
1458 ObdSize = 2;
1459 Ret = EplObdReadEntry(0x1F98, 2, &wTemp, &ObdSize);
1460 if (Ret != kEplSuccessful) {
1461 goto Exit;
1462 }
1463 DllConfigParam.m_uiIsochrRxMaxPayload = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001464
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001465 // 0x1F98.3: PResMaxLatency_U32
1466 ObdSize = 4;
1467 Ret =
1468 EplObdReadEntry(0x1F98, 3, &DllConfigParam.m_dwPresMaxLatency,
1469 &ObdSize);
1470 if (Ret != kEplSuccessful) {
1471 goto Exit;
1472 }
1473 // 0x1F98.4: PReqActPayloadLimit_U16
1474 ObdSize = 2;
1475 Ret = EplObdReadEntry(0x1F98, 4, &wTemp, &ObdSize);
1476 if (Ret != kEplSuccessful) {
1477 goto Exit;
1478 }
1479 DllConfigParam.m_uiPreqActPayloadLimit = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001480
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001481 // 0x1F98.5: PResActPayloadLimit_U16
1482 ObdSize = 2;
1483 Ret = EplObdReadEntry(0x1F98, 5, &wTemp, &ObdSize);
1484 if (Ret != kEplSuccessful) {
1485 goto Exit;
1486 }
1487 DllConfigParam.m_uiPresActPayloadLimit = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001488
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001489 // 0x1F98.6: ASndMaxLatency_U32
1490 ObdSize = 4;
1491 Ret =
1492 EplObdReadEntry(0x1F98, 6, &DllConfigParam.m_dwAsndMaxLatency,
1493 &ObdSize);
1494 if (Ret != kEplSuccessful) {
1495 goto Exit;
1496 }
1497 // 0x1F98.7: MultiplCycleCnt_U8
1498 ObdSize = 1;
1499 Ret = EplObdReadEntry(0x1F98, 7, &bTemp, &ObdSize);
1500 if (Ret != kEplSuccessful) {
1501 goto Exit;
1502 }
1503 DllConfigParam.m_uiMultiplCycleCnt = bTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001504
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001505 // 0x1F98.8: AsyncMTU_U16
1506 ObdSize = 2;
1507 Ret = EplObdReadEntry(0x1F98, 8, &wTemp, &ObdSize);
1508 if (Ret != kEplSuccessful) {
1509 goto Exit;
1510 }
1511 DllConfigParam.m_uiAsyncMtu = wTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001512
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001513 // $$$ Prescaler
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001514
1515#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001516 // 0x1F8A.1: WaitSoCPReq_U32 in [ns]
1517 ObdSize = 4;
1518 Ret =
1519 EplObdReadEntry(0x1F8A, 1, &DllConfigParam.m_dwWaitSocPreq,
1520 &ObdSize);
1521 if (Ret != kEplSuccessful) {
1522 goto Exit;
1523 }
1524 // 0x1F8A.2: AsyncSlotTimeout_U32 in [ns] (optional)
1525 ObdSize = 4;
1526 Ret =
1527 EplObdReadEntry(0x1F8A, 2, &DllConfigParam.m_dwAsyncSlotTimeout,
1528 &ObdSize);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001529/* if(Ret != kEplSuccessful)
1530 {
1531 goto Exit;
1532 }*/
1533#endif
1534
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001535 DllConfigParam.m_uiSizeOfStruct = sizeof(DllConfigParam);
1536 Ret = EplDllkConfig(&DllConfigParam);
1537 if (Ret != kEplSuccessful) {
1538 goto Exit;
1539 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001540
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001541 if (fUpdateIdentity_p != FALSE) {
1542 // configure Identity
1543 EPL_MEMSET(&DllIdentParam, 0, sizeof(DllIdentParam));
1544 ObdSize = 4;
1545 Ret =
1546 EplObdReadEntry(0x1000, 0, &DllIdentParam.m_dwDeviceType,
1547 &ObdSize);
1548 if (Ret != kEplSuccessful) {
1549 goto Exit;
1550 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001551
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001552 ObdSize = 4;
1553 Ret =
1554 EplObdReadEntry(0x1018, 1, &DllIdentParam.m_dwVendorId,
1555 &ObdSize);
1556 if (Ret != kEplSuccessful) {
1557 goto Exit;
1558 }
1559 ObdSize = 4;
1560 Ret =
1561 EplObdReadEntry(0x1018, 2, &DllIdentParam.m_dwProductCode,
1562 &ObdSize);
1563 if (Ret != kEplSuccessful) {
1564 goto Exit;
1565 }
1566 ObdSize = 4;
1567 Ret =
1568 EplObdReadEntry(0x1018, 3,
1569 &DllIdentParam.m_dwRevisionNumber,
1570 &ObdSize);
1571 if (Ret != kEplSuccessful) {
1572 goto Exit;
1573 }
1574 ObdSize = 4;
1575 Ret =
1576 EplObdReadEntry(0x1018, 4, &DllIdentParam.m_dwSerialNumber,
1577 &ObdSize);
1578 if (Ret != kEplSuccessful) {
1579 goto Exit;
1580 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001581
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001582 DllIdentParam.m_dwIpAddress =
1583 EplApiInstance_g.m_InitParam.m_dwIpAddress;
1584 DllIdentParam.m_dwSubnetMask =
1585 EplApiInstance_g.m_InitParam.m_dwSubnetMask;
1586 EPL_MEMCPY(DllIdentParam.m_sHostname,
1587 EplApiInstance_g.m_InitParam.m_sHostname,
1588 sizeof(DllIdentParam.m_sHostname));
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001589
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001590 ObdSize = 4;
1591 Ret =
1592 EplObdReadEntry(0x1020, 1,
1593 &DllIdentParam.m_dwVerifyConfigurationDate,
1594 &ObdSize);
1595 // ignore any error, because this object is optional
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001596
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001597 ObdSize = 4;
1598 Ret =
1599 EplObdReadEntry(0x1020, 2,
1600 &DllIdentParam.m_dwVerifyConfigurationTime,
1601 &ObdSize);
1602 // ignore any error, because this object is optional
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001603
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001604 // $$$ d.k.: fill rest of ident structure
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001605
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001606 DllIdentParam.m_uiSizeOfStruct = sizeof(DllIdentParam);
1607 Ret = EplDllkSetIdentity(&DllIdentParam);
1608 if (Ret != kEplSuccessful) {
1609 goto Exit;
1610 }
1611 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001612
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001613 Exit:
1614 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001615}
1616
1617//---------------------------------------------------------------------------
1618//
1619// Function: EplApiUpdateObd
1620//
1621// Description: update OD from init param
1622//
1623// Parameters: (none)
1624//
1625// Returns: tEplKernel = error code
1626//
1627//
1628// State:
1629//
1630//---------------------------------------------------------------------------
1631
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001632static tEplKernel EplApiUpdateObd(void)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001633{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001634 tEplKernel Ret = kEplSuccessful;
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001635 u16 wTemp;
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001636 u8 bTemp;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001637
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001638 // set node id in OD
1639 Ret = EplObdSetNodeId(EplApiInstance_g.m_InitParam.m_uiNodeId, // node id
1640 kEplObdNodeIdHardware); // set by hardware
1641 if (Ret != kEplSuccessful) {
1642 goto Exit;
1643 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001644
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001645 if (EplApiInstance_g.m_InitParam.m_dwCycleLen != -1) {
1646 Ret =
1647 EplObdWriteEntry(0x1006, 0,
1648 &EplApiInstance_g.m_InitParam.m_dwCycleLen,
1649 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001650/* if(Ret != kEplSuccessful)
1651 {
1652 goto Exit;
1653 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001654 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001655
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001656 if (EplApiInstance_g.m_InitParam.m_dwLossOfFrameTolerance != -1) {
1657 Ret =
1658 EplObdWriteEntry(0x1C14, 0,
1659 &EplApiInstance_g.m_InitParam.
1660 m_dwLossOfFrameTolerance, 4);
1661 /* if(Ret != kEplSuccessful)
1662 {
1663 goto Exit;
1664 } */
1665 }
1666 // d.k. There is no dependance between FeatureFlags and async-only CN.
1667 if (EplApiInstance_g.m_InitParam.m_dwFeatureFlags != -1) {
1668 Ret =
1669 EplObdWriteEntry(0x1F82, 0,
1670 &EplApiInstance_g.m_InitParam.
1671 m_dwFeatureFlags, 4);
1672 /* if(Ret != kEplSuccessful)
1673 {
1674 goto Exit;
1675 } */
1676 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001677
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001678 wTemp = (u16) EplApiInstance_g.m_InitParam.m_uiIsochrTxMaxPayload;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001679 Ret = EplObdWriteEntry(0x1F98, 1, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001680/* if(Ret != kEplSuccessful)
1681 {
1682 goto Exit;
1683 }*/
1684
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001685 wTemp = (u16) EplApiInstance_g.m_InitParam.m_uiIsochrRxMaxPayload;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001686 Ret = EplObdWriteEntry(0x1F98, 2, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001687/* if(Ret != kEplSuccessful)
1688 {
1689 goto Exit;
1690 }*/
1691
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001692 Ret =
1693 EplObdWriteEntry(0x1F98, 3,
1694 &EplApiInstance_g.m_InitParam.m_dwPresMaxLatency,
1695 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001696/* if(Ret != kEplSuccessful)
1697 {
1698 goto Exit;
1699 }*/
1700
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001701 if (EplApiInstance_g.m_InitParam.m_uiPreqActPayloadLimit <=
1702 EPL_C_DLL_ISOCHR_MAX_PAYL) {
1703 wTemp =
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001704 (u16) EplApiInstance_g.m_InitParam.m_uiPreqActPayloadLimit;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001705 Ret = EplObdWriteEntry(0x1F98, 4, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001706/* if(Ret != kEplSuccessful)
1707 {
1708 goto Exit;
1709 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001710 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001711
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001712 if (EplApiInstance_g.m_InitParam.m_uiPresActPayloadLimit <=
1713 EPL_C_DLL_ISOCHR_MAX_PAYL) {
1714 wTemp =
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001715 (u16) EplApiInstance_g.m_InitParam.m_uiPresActPayloadLimit;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001716 Ret = EplObdWriteEntry(0x1F98, 5, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001717/* if(Ret != kEplSuccessful)
1718 {
1719 goto Exit;
1720 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001721 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001722
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001723 Ret =
1724 EplObdWriteEntry(0x1F98, 6,
1725 &EplApiInstance_g.m_InitParam.m_dwAsndMaxLatency,
1726 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001727/* if(Ret != kEplSuccessful)
1728 {
1729 goto Exit;
1730 }*/
1731
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001732 if (EplApiInstance_g.m_InitParam.m_uiMultiplCycleCnt <= 0xFF) {
Greg Kroah-Hartman2ed53cf2009-03-23 12:36:38 -07001733 bTemp = (u8) EplApiInstance_g.m_InitParam.m_uiMultiplCycleCnt;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001734 Ret = EplObdWriteEntry(0x1F98, 7, &bTemp, 1);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001735/* if(Ret != kEplSuccessful)
1736 {
1737 goto Exit;
1738 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001739 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001740
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001741 if (EplApiInstance_g.m_InitParam.m_uiAsyncMtu <=
1742 EPL_C_DLL_MAX_ASYNC_MTU) {
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001743 wTemp = (u16) EplApiInstance_g.m_InitParam.m_uiAsyncMtu;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001744 Ret = EplObdWriteEntry(0x1F98, 8, &wTemp, 2);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001745/* if(Ret != kEplSuccessful)
1746 {
1747 goto Exit;
1748 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001749 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001750
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001751 if (EplApiInstance_g.m_InitParam.m_uiPrescaler <= 1000) {
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001752 wTemp = (u16) EplApiInstance_g.m_InitParam.m_uiPrescaler;
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001753 Ret = EplObdWriteEntry(0x1F98, 9, &wTemp, 2);
1754 // ignore return code
1755 Ret = kEplSuccessful;
1756 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001757#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001758 if (EplApiInstance_g.m_InitParam.m_dwWaitSocPreq != -1) {
1759 Ret =
1760 EplObdWriteEntry(0x1F8A, 1,
1761 &EplApiInstance_g.m_InitParam.
1762 m_dwWaitSocPreq, 4);
1763 /* if(Ret != kEplSuccessful)
1764 {
1765 goto Exit;
1766 } */
1767 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001768
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001769 if ((EplApiInstance_g.m_InitParam.m_dwAsyncSlotTimeout != 0)
1770 && (EplApiInstance_g.m_InitParam.m_dwAsyncSlotTimeout != -1)) {
1771 Ret =
1772 EplObdWriteEntry(0x1F8A, 2,
1773 &EplApiInstance_g.m_InitParam.
1774 m_dwAsyncSlotTimeout, 4);
1775 /* if(Ret != kEplSuccessful)
1776 {
1777 goto Exit;
1778 } */
1779 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001780#endif
1781
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001782 // configure Identity
1783 if (EplApiInstance_g.m_InitParam.m_dwDeviceType != -1) {
1784 Ret =
1785 EplObdWriteEntry(0x1000, 0,
1786 &EplApiInstance_g.m_InitParam.
1787 m_dwDeviceType, 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001788/* if(Ret != kEplSuccessful)
1789 {
1790 goto Exit;
1791 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001792 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001793
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001794 if (EplApiInstance_g.m_InitParam.m_dwVendorId != -1) {
1795 Ret =
1796 EplObdWriteEntry(0x1018, 1,
1797 &EplApiInstance_g.m_InitParam.m_dwVendorId,
1798 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001799/* if(Ret != kEplSuccessful)
1800 {
1801 goto Exit;
1802 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001803 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001804
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001805 if (EplApiInstance_g.m_InitParam.m_dwProductCode != -1) {
1806 Ret =
1807 EplObdWriteEntry(0x1018, 2,
1808 &EplApiInstance_g.m_InitParam.
1809 m_dwProductCode, 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001810/* if(Ret != kEplSuccessful)
1811 {
1812 goto Exit;
1813 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001814 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001815
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001816 if (EplApiInstance_g.m_InitParam.m_dwRevisionNumber != -1) {
1817 Ret =
1818 EplObdWriteEntry(0x1018, 3,
1819 &EplApiInstance_g.m_InitParam.
1820 m_dwRevisionNumber, 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001821/* if(Ret != kEplSuccessful)
1822 {
1823 goto Exit;
1824 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001825 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001826
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001827 if (EplApiInstance_g.m_InitParam.m_dwSerialNumber != -1) {
1828 Ret =
1829 EplObdWriteEntry(0x1018, 4,
1830 &EplApiInstance_g.m_InitParam.
1831 m_dwSerialNumber, 4);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001832/* if(Ret != kEplSuccessful)
1833 {
1834 goto Exit;
1835 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001836 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001837
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001838 if (EplApiInstance_g.m_InitParam.m_pszDevName != NULL) {
1839 // write Device Name (0x1008)
1840 Ret =
1841 EplObdWriteEntry(0x1008, 0,
Greg Kroah-Hartmanbd3966d2009-03-23 11:37:22 -07001842 (void *)EplApiInstance_g.
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001843 m_InitParam.m_pszDevName,
1844 (tEplObdSize) strlen(EplApiInstance_g.
1845 m_InitParam.
1846 m_pszDevName));
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001847/* if (Ret != kEplSuccessful)
1848 {
1849 goto Exit;
1850 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001851 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001852
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001853 if (EplApiInstance_g.m_InitParam.m_pszHwVersion != NULL) {
1854 // write Hardware version (0x1009)
1855 Ret =
1856 EplObdWriteEntry(0x1009, 0,
Greg Kroah-Hartmanbd3966d2009-03-23 11:37:22 -07001857 (void *)EplApiInstance_g.
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001858 m_InitParam.m_pszHwVersion,
1859 (tEplObdSize) strlen(EplApiInstance_g.
1860 m_InitParam.
1861 m_pszHwVersion));
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001862/* if (Ret != kEplSuccessful)
1863 {
1864 goto Exit;
1865 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001866 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001867
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001868 if (EplApiInstance_g.m_InitParam.m_pszSwVersion != NULL) {
1869 // write Software version (0x100A)
1870 Ret =
1871 EplObdWriteEntry(0x100A, 0,
Greg Kroah-Hartmanbd3966d2009-03-23 11:37:22 -07001872 (void *)EplApiInstance_g.
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001873 m_InitParam.m_pszSwVersion,
1874 (tEplObdSize) strlen(EplApiInstance_g.
1875 m_InitParam.
1876 m_pszSwVersion));
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001877/* if (Ret != kEplSuccessful)
1878 {
1879 goto Exit;
1880 }*/
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001881 }
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001882
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001883 Exit:
1884 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001885}
1886
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001887//---------------------------------------------------------------------------
1888//
1889// Function: EplApiCbSdoCon
1890//
1891// Description: callback function for SDO transfers
1892//
1893// Parameters: pSdoComFinished_p = SDO parameter
1894//
1895// Returns: tEplKernel = error code
1896//
1897//
1898// State:
1899//
1900//---------------------------------------------------------------------------
1901
1902#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001903static tEplKernel EplApiCbSdoCon(tEplSdoComFinished *pSdoComFinished_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001904{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001905 tEplKernel Ret;
1906 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001907
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001908 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001909
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001910 // call user callback
1911 EventArg.m_Sdo = *pSdoComFinished_p;
1912 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventSdo,
1913 &EventArg,
1914 EplApiInstance_g.
1915 m_InitParam.
1916 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001917
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001918 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001919
1920}
1921#endif
1922
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001923#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
1924
1925//---------------------------------------------------------------------------
1926//
1927// Function: EplApiCbNodeEvent
1928//
1929// Description: callback function for node events
1930//
1931// Parameters: uiNodeId_p = node ID of the CN
1932// NodeEvent_p = event from the specified CN
1933// NmtState_p = current NMT state of the CN
1934// wErrorCode_p = EPL error code if NodeEvent_p==kEplNmtNodeEventError
1935// fMandatory_p = flag if CN is mandatory
1936//
1937// Returns: tEplKernel = error code
1938//
1939//
1940// State:
1941//
1942//---------------------------------------------------------------------------
1943
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001944static tEplKernel EplApiCbNodeEvent(unsigned int uiNodeId_p,
1945 tEplNmtNodeEvent NodeEvent_p,
1946 tEplNmtState NmtState_p,
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001947 u16 wErrorCode_p, BOOL fMandatory_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001948{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001949 tEplKernel Ret;
1950 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001951
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001952 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001953
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001954 // call user callback
1955 EventArg.m_Node.m_uiNodeId = uiNodeId_p;
1956 EventArg.m_Node.m_NodeEvent = NodeEvent_p;
1957 EventArg.m_Node.m_NmtState = NmtState_p;
1958 EventArg.m_Node.m_wErrorCode = wErrorCode_p;
1959 EventArg.m_Node.m_fMandatory = fMandatory_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001960
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001961 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventNode,
1962 &EventArg,
1963 EplApiInstance_g.
1964 m_InitParam.
1965 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001966
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001967 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001968
1969}
1970
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001971//---------------------------------------------------------------------------
1972//
1973// Function: EplApiCbBootEvent
1974//
1975// Description: callback function for boot events
1976//
1977// Parameters: BootEvent_p = event from the boot-up process
1978// NmtState_p = current local NMT state
1979// wErrorCode_p = EPL error code if BootEvent_p==kEplNmtBootEventError
1980//
1981// Returns: tEplKernel = error code
1982//
1983//
1984// State:
1985//
1986//---------------------------------------------------------------------------
1987
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07001988static tEplKernel EplApiCbBootEvent(tEplNmtBootEvent BootEvent_p,
1989 tEplNmtState NmtState_p,
Greg Kroah-Hartmandcf53712009-03-23 12:57:39 -07001990 u16 wErrorCode_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001991{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001992 tEplKernel Ret;
1993 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001994
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001995 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08001996
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08001997 // call user callback
1998 EventArg.m_Boot.m_BootEvent = BootEvent_p;
1999 EventArg.m_Boot.m_NmtState = NmtState_p;
2000 EventArg.m_Boot.m_wErrorCode = wErrorCode_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002001
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002002 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventBoot,
2003 &EventArg,
2004 EplApiInstance_g.
2005 m_InitParam.
2006 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002007
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002008 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002009
2010}
2011
2012#endif // (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
2013
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002014#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
2015
2016//---------------------------------------------------------------------------
2017//
2018// Function: EplApiCbLedStateChange
2019//
2020// Description: callback function for LED change events.
2021//
2022// Parameters: LedType_p = type of LED
2023// fOn_p = state of LED
2024//
2025// Returns: tEplKernel = errorcode
2026//
2027// State:
2028//
2029//---------------------------------------------------------------------------
2030
Greg Kroah-Hartmand10f4692009-03-23 10:45:12 -07002031static tEplKernel EplApiCbLedStateChange(tEplLedType LedType_p, BOOL fOn_p)
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002032{
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002033 tEplKernel Ret;
2034 tEplApiEventArg EventArg;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002035
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002036 Ret = kEplSuccessful;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002037
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002038 // call user callback
2039 EventArg.m_Led.m_LedType = LedType_p;
2040 EventArg.m_Led.m_fOn = fOn_p;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002041
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002042 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventLed,
2043 &EventArg,
2044 EplApiInstance_g.
2045 m_InitParam.
2046 m_pEventUserArg);
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002047
Greg Kroah-Hartman833dfbe2008-12-19 17:11:52 -08002048 return Ret;
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002049
2050}
2051
2052#endif
2053
Daniel Krueger9d7164c2008-12-19 11:41:57 -08002054// EOF