]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/epl/EplApiGeneric.c
Staging: epl: run Lindent on *.c files
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / epl / EplApiGeneric.c
CommitLineData
9d7164cf
DK
1/****************************************************************************
2
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
5
6 Project: openPOWERLINK
7
8 Description: source file for 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
9d7164cf
DK
94#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) == 0)
95#error "EPL API layer needs EPL module OBDK!"
96#endif
97
9d7164cf
DK
98/***************************************************************************/
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
9d7164cf
DK
122/***************************************************************************/
123/* */
124/* */
125/* C L A S S EplApi */
126/* */
127/* */
128/***************************************************************************/
129//
130// Description:
131//
132//
133/***************************************************************************/
134
9d7164cf
DK
135//=========================================================================//
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
833dfbe7
GKH
149typedef struct {
150 tEplApiInitParam m_InitParam;
9d7164cf
DK
151
152} tEplApiInstance;
153
154//---------------------------------------------------------------------------
155// local vars
156//---------------------------------------------------------------------------
157
833dfbe7 158static tEplApiInstance EplApiInstance_g;
9d7164cf
DK
159
160//---------------------------------------------------------------------------
161// local function prototypes
162//---------------------------------------------------------------------------
163
164// NMT state change event callback function
833dfbe7
GKH
165static tEplKernel PUBLIC EplApiCbNmtStateChange(tEplEventNmtStateChange
166 NmtStateChange_p);
9d7164cf
DK
167
168// update DLL configuration from OD
169static tEplKernel PUBLIC EplApiUpdateDllConfig(BOOL fUpdateIdentity_p);
170
171// update OD from init param
172static tEplKernel PUBLIC EplApiUpdateObd(void);
173
174// process events from user event queue
833dfbe7 175static tEplKernel PUBLIC EplApiProcessEvent(tEplEvent * pEplEvent_p);
9d7164cf
DK
176
177#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
178// callback function of SDO module
833dfbe7 179static tEplKernel PUBLIC EplApiCbSdoCon(tEplSdoComFinished * pSdoComFinished_p);
9d7164cf
DK
180#endif
181
182#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
183// callback functions of NmtMnu module
833dfbe7
GKH
184static tEplKernel PUBLIC EplApiCbNodeEvent(unsigned int uiNodeId_p,
185 tEplNmtNodeEvent NodeEvent_p,
186 tEplNmtState NmtState_p,
187 WORD wErrorCode_p,
188 BOOL fMandatory_p);
189
190static tEplKernel PUBLIC EplApiCbBootEvent(tEplNmtBootEvent BootEvent_p,
191 tEplNmtState NmtState_p,
192 WORD wErrorCode_p);
9d7164cf
DK
193#endif
194
195#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
196// callback function of Ledu module
833dfbe7
GKH
197static tEplKernel PUBLIC EplApiCbLedStateChange(tEplLedType LedType_p,
198 BOOL fOn_p);
9d7164cf
DK
199#endif
200
201// OD initialization function (implemented in Objdict.c)
833dfbe7 202tEplKernel PUBLIC EplObdInitRam(tEplObdInitParam MEM * pInitParam_p);
9d7164cf
DK
203
204//=========================================================================//
205// //
206// P U B L I C F U N C T I O N S //
207// //
208//=========================================================================//
209
210//---------------------------------------------------------------------------
211//
212// Function: EplApiInitialize()
213//
214// Description: add and initialize new instance of EPL stack.
215// After return from this function the application must start
216// the NMT state machine via
217// EplApiExecNmtCommand(kEplNmtEventSwReset)
218// and thereby the whole EPL stack :-)
219//
220// Parameters: pInitParam_p = initialisation parameters
221//
222// Returns: tEplKernel = error code
223//
224//
225// State:
226//
227//---------------------------------------------------------------------------
228
229tEplKernel PUBLIC EplApiInitialize(tEplApiInitParam * pInitParam_p)
230{
833dfbe7
GKH
231 tEplKernel Ret = kEplSuccessful;
232 tEplObdInitParam ObdInitParam;
233 tEplDllkInitParam DllkInitParam;
9d7164cf 234#ifndef EPL_NO_FIFO
833dfbe7 235 tShbError ShbError;
9d7164cf
DK
236#endif
237
833dfbe7
GKH
238 // reset instance structure
239 EPL_MEMSET(&EplApiInstance_g, 0, sizeof(EplApiInstance_g));
9d7164cf 240
833dfbe7
GKH
241 EPL_MEMCPY(&EplApiInstance_g.m_InitParam, pInitParam_p,
242 min(sizeof(tEplApiInitParam),
243 pInitParam_p->m_uiSizeOfStruct));
9d7164cf 244
833dfbe7
GKH
245 // check event callback function pointer
246 if (EplApiInstance_g.m_InitParam.m_pfnCbEvent == NULL) { // application must always have an event callback function
247 Ret = kEplApiInvalidParam;
248 goto Exit;
249 }
9d7164cf 250#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDK)) != 0)
833dfbe7 251 // init OD
9d7164cf
DK
252// FIXME
253// Ret = EplObdInitRam(&ObdInitParam);
254// if (Ret != kEplSuccessful)
255// {
256// goto Exit;
257// }
258
833dfbe7
GKH
259 // initialize EplObd module
260 Ret = EplObdInit(&ObdInitParam);
261 if (Ret != kEplSuccessful) {
262 goto Exit;
263 }
9d7164cf
DK
264#endif
265
266#ifndef EPL_NO_FIFO
833dfbe7
GKH
267 ShbError = ShbInit();
268 if (ShbError != kShbOk) {
269 Ret = kEplNoResource;
270 goto Exit;
271 }
9d7164cf
DK
272#endif
273
833dfbe7
GKH
274 // initialize EplEventk module
275 Ret = EplEventkInit(EplApiInstance_g.m_InitParam.m_pfnCbSync);
276 if (Ret != kEplSuccessful) {
277 goto Exit;
278 }
279 // initialize EplEventu module
280 Ret = EplEventuInit(EplApiProcessEvent);
281 if (Ret != kEplSuccessful) {
282 goto Exit;
283 }
284 // init EplTimerk module
285 Ret = EplTimerkInit();
286 if (Ret != kEplSuccessful) {
287 goto Exit;
288 }
289 // initialize EplNmtk module before DLL
9d7164cf 290#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
833dfbe7
GKH
291 Ret = EplNmtkInit();
292 if (Ret != kEplSuccessful) {
293 goto Exit;
294 }
9d7164cf
DK
295#endif
296
833dfbe7 297 // initialize EplDllk module
9d7164cf 298#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
833dfbe7
GKH
299 EPL_MEMCPY(DllkInitParam.m_be_abSrcMac,
300 EplApiInstance_g.m_InitParam.m_abMacAddress, 6);
301 Ret = EplDllkAddInstance(&DllkInitParam);
302 if (Ret != kEplSuccessful) {
303 goto Exit;
304 }
305 // initialize EplErrorHandlerk module
306 Ret = EplErrorHandlerkInit();
307 if (Ret != kEplSuccessful) {
308 goto Exit;
309 }
310 // initialize EplDllkCal module
311 Ret = EplDllkCalAddInstance();
312 if (Ret != kEplSuccessful) {
313 goto Exit;
314 }
9d7164cf
DK
315#endif
316
833dfbe7 317 // initialize EplDlluCal module
9d7164cf 318#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
833dfbe7
GKH
319 Ret = EplDlluCalAddInstance();
320 if (Ret != kEplSuccessful) {
321 goto Exit;
322 }
9d7164cf
DK
323#endif
324
833dfbe7 325 // initialize EplPdok module
9d7164cf 326#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
833dfbe7
GKH
327 Ret = EplPdokAddInstance();
328 if (Ret != kEplSuccessful) {
329 goto Exit;
330 }
331
332 Ret = EplPdokCalAddInstance();
333 if (Ret != kEplSuccessful) {
334 goto Exit;
335 }
9d7164cf
DK
336#endif
337
833dfbe7 338 // initialize EplNmtCnu module
9d7164cf 339#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_CN)) != 0)
833dfbe7
GKH
340 Ret = EplNmtCnuAddInstance(EplApiInstance_g.m_InitParam.m_uiNodeId);
341 if (Ret != kEplSuccessful) {
342 goto Exit;
343 }
9d7164cf
DK
344#endif
345
833dfbe7 346 // initialize EplNmtu module
9d7164cf 347#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
833dfbe7
GKH
348 Ret = EplNmtuInit();
349 if (Ret != kEplSuccessful) {
350 goto Exit;
351 }
352 // register NMT event callback function
353 Ret = EplNmtuRegisterStateChangeCb(EplApiCbNmtStateChange);
354 if (Ret != kEplSuccessful) {
355 goto Exit;
356 }
9d7164cf
DK
357#endif
358
359#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
833dfbe7
GKH
360 // initialize EplNmtMnu module
361 Ret = EplNmtMnuInit(EplApiCbNodeEvent, EplApiCbBootEvent);
362 if (Ret != kEplSuccessful) {
363 goto Exit;
364 }
365 // initialize EplIdentu module
366 Ret = EplIdentuInit();
367 if (Ret != kEplSuccessful) {
368 goto Exit;
369 }
370 // initialize EplStatusu module
371 Ret = EplStatusuInit();
372 if (Ret != kEplSuccessful) {
373 goto Exit;
374 }
9d7164cf
DK
375#endif
376
833dfbe7 377 // initialize EplLedu module
9d7164cf 378#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
833dfbe7
GKH
379 Ret = EplLeduInit(EplApiCbLedStateChange);
380 if (Ret != kEplSuccessful) {
381 goto Exit;
382 }
9d7164cf
DK
383#endif
384
833dfbe7 385 // init SDO module
9d7164cf
DK
386#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0) || \
387 (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0))
833dfbe7
GKH
388 // init sdo command layer
389 Ret = EplSdoComInit();
390 if (Ret != kEplSuccessful) {
391 goto Exit;
392 }
9d7164cf
DK
393#endif
394
833dfbe7
GKH
395 // the application must start NMT state machine
396 // via EplApiExecNmtCommand(kEplNmtEventSwReset)
397 // and thereby the whole EPL stack
9d7164cf 398
833dfbe7
GKH
399 Exit:
400 return Ret;
9d7164cf
DK
401}
402
403//---------------------------------------------------------------------------
404//
405// Function: EplApiShutdown()
406//
407// Description: deletes an instance of EPL stack
408//
409// Parameters: (none)
410//
411// Returns: tEplKernel = error code
412//
413//
414// State:
415//
416//---------------------------------------------------------------------------
417
418tEplKernel PUBLIC EplApiShutdown(void)
419{
833dfbe7 420 tEplKernel Ret = kEplSuccessful;
9d7164cf 421
833dfbe7 422 // $$$ d.k.: check if NMT state is NMT_GS_OFF
9d7164cf 423
833dfbe7
GKH
424 // $$$ d.k.: maybe delete event queues at first, but this implies that
425 // no other module must not use the event queues for communication
426 // during shutdown.
9d7164cf 427
833dfbe7 428 // delete instance for all modules
9d7164cf 429
833dfbe7 430 // deinitialize EplSdoCom module
9d7164cf
DK
431#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOS)) != 0) || \
432 (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0))
833dfbe7 433 Ret = EplSdoComDelInstance();
9d7164cf
DK
434// PRINTF1("EplSdoComDelInstance(): 0x%X\n", Ret);
435#endif
436
833dfbe7 437 // deinitialize EplLedu module
9d7164cf 438#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
833dfbe7 439 Ret = EplLeduDelInstance();
9d7164cf
DK
440// PRINTF1("EplLeduDelInstance(): 0x%X\n", Ret);
441#endif
442
443#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
833dfbe7
GKH
444 // deinitialize EplNmtMnu module
445 Ret = EplNmtMnuDelInstance();
9d7164cf
DK
446// PRINTF1("EplNmtMnuDelInstance(): 0x%X\n", Ret);
447
833dfbe7
GKH
448 // deinitialize EplIdentu module
449 Ret = EplIdentuDelInstance();
9d7164cf
DK
450// PRINTF1("EplIdentuDelInstance(): 0x%X\n", Ret);
451
833dfbe7
GKH
452 // deinitialize EplStatusu module
453 Ret = EplStatusuDelInstance();
9d7164cf
DK
454// PRINTF1("EplStatusuDelInstance(): 0x%X\n", Ret);
455#endif
456
833dfbe7 457 // deinitialize EplNmtCnu module
9d7164cf 458#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_CN)) != 0)
833dfbe7 459 Ret = EplNmtCnuDelInstance();
9d7164cf
DK
460// PRINTF1("EplNmtCnuDelInstance(): 0x%X\n", Ret);
461#endif
462
833dfbe7 463 // deinitialize EplNmtu module
9d7164cf 464#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
833dfbe7 465 Ret = EplNmtuDelInstance();
9d7164cf
DK
466// PRINTF1("EplNmtuDelInstance(): 0x%X\n", Ret);
467#endif
468
833dfbe7 469 // deinitialize EplDlluCal module
9d7164cf 470#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
833dfbe7 471 Ret = EplDlluCalDelInstance();
9d7164cf
DK
472// PRINTF1("EplDlluCalDelInstance(): 0x%X\n", Ret);
473
474#endif
475
833dfbe7
GKH
476 // deinitialize EplEventu module
477 Ret = EplEventuDelInstance();
9d7164cf
DK
478// PRINTF1("EplEventuDelInstance(): 0x%X\n", Ret);
479
833dfbe7 480 // deinitialize EplNmtk module
9d7164cf 481#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
833dfbe7 482 Ret = EplNmtkDelInstance();
9d7164cf
DK
483// PRINTF1("EplNmtkDelInstance(): 0x%X\n", Ret);
484#endif
485
833dfbe7 486 // deinitialize EplDllk module
9d7164cf 487#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
833dfbe7 488 Ret = EplDllkDelInstance();
9d7164cf
DK
489// PRINTF1("EplDllkDelInstance(): 0x%X\n", Ret);
490
833dfbe7
GKH
491 // deinitialize EplDllkCal module
492 Ret = EplDllkCalDelInstance();
9d7164cf
DK
493// PRINTF1("EplDllkCalDelInstance(): 0x%X\n", Ret);
494#endif
495
833dfbe7
GKH
496 // deinitialize EplEventk module
497 Ret = EplEventkDelInstance();
9d7164cf
DK
498// PRINTF1("EplEventkDelInstance(): 0x%X\n", Ret);
499
833dfbe7
GKH
500 // deinitialize EplTimerk module
501 Ret = EplTimerkDelInstance();
9d7164cf
DK
502// PRINTF1("EplTimerkDelInstance(): 0x%X\n", Ret);
503
504#ifndef EPL_NO_FIFO
833dfbe7 505 ShbExit();
9d7164cf
DK
506#endif
507
833dfbe7 508 return Ret;
9d7164cf
DK
509}
510
9d7164cf
DK
511//----------------------------------------------------------------------------
512// Function: EplApiExecNmtCommand()
513//
514// Description: executes a NMT command, i.e. post the NMT command/event to the
515// NMTk module. NMT commands which are not appropriate in the current
516// NMT state are silently ignored. Please keep in mind that the
517// NMT state may change until the NMT command is actually executed.
518//
519// Parameters: NmtEvent_p = NMT command/event
520//
521// Returns: tEplKernel = error code
522//
523// State:
524//----------------------------------------------------------------------------
525
526tEplKernel PUBLIC EplApiExecNmtCommand(tEplNmtEvent NmtEvent_p)
527{
833dfbe7 528 tEplKernel Ret = kEplSuccessful;
9d7164cf
DK
529
530#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
833dfbe7 531 Ret = EplNmtuNmtEvent(NmtEvent_p);
9d7164cf
DK
532#endif
533
833dfbe7 534 return Ret;
9d7164cf
DK
535}
536
9d7164cf
DK
537//----------------------------------------------------------------------------
538// Function: EplApiLinkObject()
539//
540// Description: Function maps array of application variables onto specified object in OD
541//
542// Parameters: uiObjIndex_p = Function maps variables for this object index
543// pVar_p = Pointer to data memory area for the specified object
544// puiVarEntries_p = IN: pointer to number of entries to map
545// OUT: pointer to number of actually used entries
546// pEntrySize_p = IN: pointer to size of one entry;
547// if size is zero, the actual size will be read from OD
548// OUT: pointer to entire size of all entries mapped
549// uiFirstSubindex_p = This is the first subindex to be mapped.
550//
551// Returns: tEplKernel = error code
552//
553// State:
554//----------------------------------------------------------------------------
555
833dfbe7
GKH
556tEplKernel PUBLIC EplApiLinkObject(unsigned int uiObjIndex_p,
557 void *pVar_p,
558 unsigned int *puiVarEntries_p,
559 tEplObdSize * pEntrySize_p,
560 unsigned int uiFirstSubindex_p)
9d7164cf 561{
833dfbe7
GKH
562 BYTE bVarEntries;
563 BYTE bIndexEntries;
564 BYTE MEM *pbData;
565 unsigned int uiSubindex;
566 tEplVarParam VarParam;
567 tEplObdSize EntrySize;
568 tEplObdSize UsedSize;
569
570 tEplKernel RetCode = kEplSuccessful;
571
572 if ((pVar_p == NULL)
573 || (puiVarEntries_p == NULL)
574 || (*puiVarEntries_p == 0)
575 || (pEntrySize_p == NULL)) {
576 RetCode = kEplApiInvalidParam;
577 goto Exit;
578 }
579
580 pbData = (BYTE MEM *) pVar_p;
581 bVarEntries = (BYTE) * puiVarEntries_p;
582 UsedSize = 0;
583
584 // init VarParam structure with default values
585 VarParam.m_uiIndex = uiObjIndex_p;
586 VarParam.m_ValidFlag = kVarValidAll;
587
588 if (uiFirstSubindex_p != 0) { // check if object exists by reading subindex 0x00,
589 // because user wants to link a variable to a subindex unequal 0x00
590 // read number of entries
591 EntrySize = (tEplObdSize) sizeof(bIndexEntries);
592 RetCode = EplObdReadEntry(uiObjIndex_p,
593 0x00,
594 (void GENERIC *)&bIndexEntries,
595 &EntrySize);
596
597 if ((RetCode != kEplSuccessful) || (bIndexEntries == 0x00)) {
598 // Object doesn't exist or invalid entry number
599 RetCode = kEplObdIndexNotExist;
600 goto Exit;
601 }
602 } else { // user wants to link a variable to subindex 0x00
603 // that's OK
604 bIndexEntries = 0;
605 }
606
607 // Correct number of entries if number read from OD is greater
608 // than the specified number.
609 // This is done, so that we do not set more entries than subindexes the
610 // object actually has.
611 if ((bIndexEntries > (bVarEntries + uiFirstSubindex_p - 1)) &&
612 (bVarEntries != 0x00)) {
613 bIndexEntries = (BYTE) (bVarEntries + uiFirstSubindex_p - 1);
614 }
615 // map entries
616 for (uiSubindex = uiFirstSubindex_p; uiSubindex <= bIndexEntries;
617 uiSubindex++) {
618 // if passed entry size is 0, then get size from OD
619 if (*pEntrySize_p == 0x00) {
620 // read entry size
621 EntrySize = EplObdGetDataSize(uiObjIndex_p, uiSubindex);
622
623 if (EntrySize == 0x00) {
624 // invalid entry size (maybe object doesn't exist or entry of type DOMAIN is empty)
625 RetCode = kEplObdSubindexNotExist;
626 break;
627 }
628 } else { // use passed entry size
629 EntrySize = *pEntrySize_p;
630 }
631
632 VarParam.m_uiSubindex = uiSubindex;
633
634 // set pointer to user var
635 VarParam.m_Size = EntrySize;
636 VarParam.m_pData = pbData;
637
638 UsedSize += EntrySize;
639 pbData += EntrySize;
640
641 RetCode = EplObdDefineVar(&VarParam);
642 if (RetCode != kEplSuccessful) {
643 break;
644 }
645 }
646
647 // set number of mapped entries and entry size
648 *puiVarEntries_p = ((bIndexEntries - uiFirstSubindex_p) + 1);
649 *pEntrySize_p = UsedSize;
650
651 Exit:
652
653 return (RetCode);
9d7164cf
DK
654
655}
656
9d7164cf
DK
657// ----------------------------------------------------------------------------
658//
659// Function: EplApiReadObject()
660//
661// Description: reads the specified entry from the OD of the specified node.
662// If this node is a remote node, it performs a SDO transfer, which
663// means this function returns kEplApiTaskDeferred and the application
664// is informed via the event callback function when the task is completed.
665//
666// Parameters: pSdoComConHdl_p = INOUT: pointer to SDO connection handle (may be NULL in case of local OD access)
667// uiNodeId_p = IN: node ID (0 = itself)
668// uiIndex_p = IN: index of object in OD
669// uiSubindex_p = IN: sub-index of object in OD
670// pDstData_le_p = OUT: pointer to data in little endian
671// puiSize_p = INOUT: pointer to size of data
672// SdoType_p = IN: type of SDO transfer
673// pUserArg_p = IN: user-definable argument pointer,
674// which will be passed to the event callback function
675//
676// Return: tEplKernel = error code
677//
678// ----------------------------------------------------------------------------
679
833dfbe7
GKH
680tEplKernel PUBLIC EplApiReadObject(tEplSdoComConHdl * pSdoComConHdl_p,
681 unsigned int uiNodeId_p,
682 unsigned int uiIndex_p,
683 unsigned int uiSubindex_p,
684 void *pDstData_le_p,
685 unsigned int *puiSize_p,
686 tEplSdoType SdoType_p, void *pUserArg_p)
9d7164cf 687{
833dfbe7
GKH
688 tEplKernel Ret = kEplSuccessful;
689
690 if ((uiIndex_p == 0) || (pDstData_le_p == NULL) || (puiSize_p == NULL)
691 || (*puiSize_p == 0)) {
692 Ret = kEplApiInvalidParam;
693 goto Exit;
694 }
695
696 if (uiNodeId_p == 0 || uiNodeId_p == EplObdGetNodeId()) { // local OD access can be performed
697 tEplObdSize ObdSize;
698
699 ObdSize = (tEplObdSize) * puiSize_p;
700 Ret =
701 EplObdReadEntryToLe(uiIndex_p, uiSubindex_p, pDstData_le_p,
702 &ObdSize);
703 *puiSize_p = (unsigned int)ObdSize;
704 } else { // perform SDO transfer
9d7164cf 705#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
833dfbe7 706 tEplSdoComTransParamByIndex TransParamByIndex;
9d7164cf
DK
707// tEplSdoComConHdl SdoComConHdl;
708
833dfbe7
GKH
709 // check if application provides space for handle
710 if (pSdoComConHdl_p == NULL) {
711 Ret = kEplApiInvalidParam;
712 goto Exit;
9d7164cf 713// pSdoComConHdl_p = &SdoComConHdl;
833dfbe7
GKH
714 }
715 // init command layer connection
716 Ret = EplSdoComDefineCon(pSdoComConHdl_p, uiNodeId_p, // target node id
717 SdoType_p); // SDO type
718 if ((Ret != kEplSuccessful) && (Ret != kEplSdoComHandleExists)) {
719 goto Exit;
720 }
721 TransParamByIndex.m_pData = pDstData_le_p;
722 TransParamByIndex.m_SdoAccessType = kEplSdoAccessTypeRead;
723 TransParamByIndex.m_SdoComConHdl = *pSdoComConHdl_p;
724 TransParamByIndex.m_uiDataSize = *puiSize_p;
725 TransParamByIndex.m_uiIndex = uiIndex_p;
726 TransParamByIndex.m_uiSubindex = uiSubindex_p;
727 TransParamByIndex.m_pfnSdoFinishedCb = EplApiCbSdoCon;
728 TransParamByIndex.m_pUserArg = pUserArg_p;
729
730 Ret = EplSdoComInitTransferByIndex(&TransParamByIndex);
731 if (Ret != kEplSuccessful) {
732 goto Exit;
733 }
734 Ret = kEplApiTaskDeferred;
9d7164cf
DK
735
736#else
833dfbe7 737 Ret = kEplApiInvalidParam;
9d7164cf 738#endif
833dfbe7 739 }
9d7164cf 740
833dfbe7
GKH
741 Exit:
742 return Ret;
9d7164cf
DK
743}
744
9d7164cf
DK
745// ----------------------------------------------------------------------------
746//
747// Function: EplApiWriteObject()
748//
749// Description: writes the specified entry to the OD of the specified node.
750// If this node is a remote node, it performs a SDO transfer, which
751// means this function returns kEplApiTaskDeferred and the application
752// is informed via the event callback function when the task is completed.
753//
754// Parameters: pSdoComConHdl_p = INOUT: pointer to SDO connection handle (may be NULL in case of local OD access)
755// uiNodeId_p = IN: node ID (0 = itself)
756// uiIndex_p = IN: index of object in OD
757// uiSubindex_p = IN: sub-index of object in OD
758// pSrcData_le_p = IN: pointer to data in little endian
759// uiSize_p = IN: size of data in bytes
760// SdoType_p = IN: type of SDO transfer
761// pUserArg_p = IN: user-definable argument pointer,
762// which will be passed to the event callback function
763//
764// Return: tEplKernel = error code
765//
766// ----------------------------------------------------------------------------
767
833dfbe7
GKH
768tEplKernel PUBLIC EplApiWriteObject(tEplSdoComConHdl * pSdoComConHdl_p,
769 unsigned int uiNodeId_p,
770 unsigned int uiIndex_p,
771 unsigned int uiSubindex_p,
772 void *pSrcData_le_p,
773 unsigned int uiSize_p,
774 tEplSdoType SdoType_p, void *pUserArg_p)
9d7164cf 775{
833dfbe7 776 tEplKernel Ret = kEplSuccessful;
9d7164cf 777
833dfbe7
GKH
778 if ((uiIndex_p == 0) || (pSrcData_le_p == NULL) || (uiSize_p == 0)) {
779 Ret = kEplApiInvalidParam;
780 goto Exit;
781 }
9d7164cf 782
833dfbe7 783 if (uiNodeId_p == 0 || uiNodeId_p == EplObdGetNodeId()) { // local OD access can be performed
9d7164cf 784
833dfbe7
GKH
785 Ret =
786 EplObdWriteEntryFromLe(uiIndex_p, uiSubindex_p,
787 pSrcData_le_p, uiSize_p);
788 } else { // perform SDO transfer
9d7164cf 789#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
833dfbe7 790 tEplSdoComTransParamByIndex TransParamByIndex;
9d7164cf
DK
791// tEplSdoComConHdl SdoComConHdl;
792
833dfbe7
GKH
793 // check if application provides space for handle
794 if (pSdoComConHdl_p == NULL) {
795 Ret = kEplApiInvalidParam;
796 goto Exit;
9d7164cf 797// pSdoComConHdl_p = &SdoComConHdl;
833dfbe7
GKH
798 }
799 // d.k.: How to recycle command layer connection?
800 // Try to redefine it, which will return kEplSdoComHandleExists
801 // and the existing command layer handle.
802 // If the returned handle is busy, EplSdoComInitTransferByIndex()
803 // will return with error.
804 // $$$ d.k.: Collisions may occur with Configuration Manager, if both the application and
805 // Configuration Manager, are trying to communicate with the very same node.
806 // possible solution: disallow communication by application if Configuration Manager is busy
807
808 // init command layer connection
809 Ret = EplSdoComDefineCon(pSdoComConHdl_p, uiNodeId_p, // target node id
810 SdoType_p); // SDO type
811 if ((Ret != kEplSuccessful) && (Ret != kEplSdoComHandleExists)) {
812 goto Exit;
813 }
814 TransParamByIndex.m_pData = pSrcData_le_p;
815 TransParamByIndex.m_SdoAccessType = kEplSdoAccessTypeWrite;
816 TransParamByIndex.m_SdoComConHdl = *pSdoComConHdl_p;
817 TransParamByIndex.m_uiDataSize = uiSize_p;
818 TransParamByIndex.m_uiIndex = uiIndex_p;
819 TransParamByIndex.m_uiSubindex = uiSubindex_p;
820 TransParamByIndex.m_pfnSdoFinishedCb = EplApiCbSdoCon;
821 TransParamByIndex.m_pUserArg = pUserArg_p;
822
823 Ret = EplSdoComInitTransferByIndex(&TransParamByIndex);
824 if (Ret != kEplSuccessful) {
825 goto Exit;
826 }
827 Ret = kEplApiTaskDeferred;
9d7164cf
DK
828
829#else
833dfbe7 830 Ret = kEplApiInvalidParam;
9d7164cf 831#endif
833dfbe7 832 }
9d7164cf 833
833dfbe7
GKH
834 Exit:
835 return Ret;
9d7164cf
DK
836}
837
9d7164cf
DK
838// ----------------------------------------------------------------------------
839//
840// Function: EplApiFreeSdoChannel()
841//
842// Description: frees the specified SDO channel.
843// This function must be called after each call to EplApiReadObject()/EplApiWriteObject()
844// which returns kEplApiTaskDeferred and the application
845// is informed via the event callback function when the task is completed.
846//
847// Parameters: SdoComConHdl_p = IN: SDO connection handle
848//
849// Return: tEplKernel = error code
850//
851// ----------------------------------------------------------------------------
852
833dfbe7 853tEplKernel PUBLIC EplApiFreeSdoChannel(tEplSdoComConHdl SdoComConHdl_p)
9d7164cf 854{
833dfbe7 855 tEplKernel Ret = kEplSuccessful;
9d7164cf
DK
856
857#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
858
833dfbe7
GKH
859 // init command layer connection
860 Ret = EplSdoComUndefineCon(SdoComConHdl_p);
9d7164cf
DK
861
862#else
833dfbe7 863 Ret = kEplApiInvalidParam;
9d7164cf
DK
864#endif
865
833dfbe7 866 return Ret;
9d7164cf
DK
867}
868
9d7164cf
DK
869// ----------------------------------------------------------------------------
870//
871// Function: EplApiReadLocalObject()
872//
873// Description: reads the specified entry from the local OD.
874//
875// Parameters: uiIndex_p = IN: index of object in OD
876// uiSubindex_p = IN: sub-index of object in OD
877// pDstData_p = OUT: pointer to data in platform byte order
878// puiSize_p = INOUT: pointer to size of data
879//
880// Return: tEplKernel = error code
881//
882// ----------------------------------------------------------------------------
883
833dfbe7
GKH
884tEplKernel PUBLIC EplApiReadLocalObject(unsigned int uiIndex_p,
885 unsigned int uiSubindex_p,
886 void *pDstData_p,
887 unsigned int *puiSize_p)
9d7164cf 888{
833dfbe7
GKH
889 tEplKernel Ret = kEplSuccessful;
890 tEplObdSize ObdSize;
9d7164cf 891
833dfbe7
GKH
892 ObdSize = (tEplObdSize) * puiSize_p;
893 Ret = EplObdReadEntry(uiIndex_p, uiSubindex_p, pDstData_p, &ObdSize);
894 *puiSize_p = (unsigned int)ObdSize;
9d7164cf 895
833dfbe7 896 return Ret;
9d7164cf
DK
897}
898
9d7164cf
DK
899// ----------------------------------------------------------------------------
900//
901// Function: EplApiWriteLocalObject()
902//
903// Description: writes the specified entry to the local OD.
904//
905// Parameters: uiIndex_p = IN: index of object in OD
906// uiSubindex_p = IN: sub-index of object in OD
907// pSrcData_p = IN: pointer to data in platform byte order
908// uiSize_p = IN: size of data in bytes
909//
910// Return: tEplKernel = error code
911//
912// ----------------------------------------------------------------------------
913
833dfbe7
GKH
914tEplKernel PUBLIC EplApiWriteLocalObject(unsigned int uiIndex_p,
915 unsigned int uiSubindex_p,
916 void *pSrcData_p,
917 unsigned int uiSize_p)
9d7164cf 918{
833dfbe7 919 tEplKernel Ret = kEplSuccessful;
9d7164cf 920
833dfbe7
GKH
921 Ret =
922 EplObdWriteEntry(uiIndex_p, uiSubindex_p, pSrcData_p,
923 (tEplObdSize) uiSize_p);
9d7164cf 924
833dfbe7 925 return Ret;
9d7164cf
DK
926}
927
9d7164cf
DK
928#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
929// ----------------------------------------------------------------------------
930//
931// Function: EplApiMnTriggerStateChange()
932//
933// Description: triggers the specified node command for the specified node.
934//
935// Parameters: uiNodeId_p = node ID for which the node command will be executed
936// NodeCommand_p = node command
937//
938// Return: tEplKernel = error code
939//
940// ----------------------------------------------------------------------------
941
942tEplKernel PUBLIC EplApiMnTriggerStateChange(unsigned int uiNodeId_p,
833dfbe7 943 tEplNmtNodeCommand NodeCommand_p)
9d7164cf 944{
833dfbe7 945 tEplKernel Ret = kEplSuccessful;
9d7164cf 946
833dfbe7 947 Ret = EplNmtMnuTriggerStateChange(uiNodeId_p, NodeCommand_p);
9d7164cf 948
833dfbe7 949 return Ret;
9d7164cf
DK
950}
951
952#endif // (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
953
954//---------------------------------------------------------------------------
955//
956// Function: EplApiCbObdAccess
957//
958// Description: callback function for OD accesses
959//
960// Parameters: pParam_p = OBD parameter
961//
962// Returns: tEplKernel = error code
963//
964//
965// State:
966//
967//---------------------------------------------------------------------------
968
833dfbe7 969tEplKernel PUBLIC EplApiCbObdAccess(tEplObdCbParam MEM * pParam_p)
9d7164cf 970{
833dfbe7 971 tEplKernel Ret = kEplSuccessful;
9d7164cf
DK
972
973#if (EPL_API_OBD_FORWARD_EVENT != FALSE)
833dfbe7
GKH
974 tEplApiEventArg EventArg;
975
976 // call user callback
977 // must be disabled for EplApiLinuxKernel.c, because of reentrancy problem
978 // for local OD access. This is not so bad as user callback function in
979 // application does not use OD callbacks at the moment.
980 EventArg.m_ObdCbParam = *pParam_p;
981 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventObdAccess,
982 &EventArg,
983 EplApiInstance_g.
984 m_InitParam.
985 m_pEventUserArg);
9d7164cf
DK
986#endif
987
833dfbe7
GKH
988 switch (pParam_p->m_uiIndex) {
989 //case 0x1006: // NMT_CycleLen_U32 (valid on reset)
990 case 0x1C14: // DLL_LossOfFrameTolerance_U32
991 //case 0x1F98: // NMT_CycleTiming_REC (valid on reset)
992 {
993 if (pParam_p->m_ObdEvent == kEplObdEvPostWrite) {
994 // update DLL configuration
995 Ret = EplApiUpdateDllConfig(FALSE);
996 }
997 break;
998 }
999
1000 case 0x1020: // CFM_VerifyConfiguration_REC.ConfId_U32 != 0
1001 {
1002 if ((pParam_p->m_ObdEvent == kEplObdEvPostWrite)
1003 && (pParam_p->m_uiSubIndex == 3)
1004 && (*((DWORD *) pParam_p->m_pArg) != 0)) {
1005 DWORD dwVerifyConfInvalid = 0;
1006 // set CFM_VerifyConfiguration_REC.VerifyConfInvalid_U32 to 0
1007 Ret =
1008 EplObdWriteEntry(0x1020, 4,
1009 &dwVerifyConfInvalid, 4);
1010 // ignore any error because this objekt is optional
1011 Ret = kEplSuccessful;
1012 }
1013 break;
1014 }
1015
1016 case 0x1F9E: // NMT_ResetCmd_U8
1017 {
1018 if (pParam_p->m_ObdEvent == kEplObdEvPreWrite) {
1019 BYTE bNmtCommand;
1020
1021 bNmtCommand = *((BYTE *) pParam_p->m_pArg);
1022 // check value range
1023 switch ((tEplNmtCommand) bNmtCommand) {
1024 case kEplNmtCmdResetNode:
1025 case kEplNmtCmdResetCommunication:
1026 case kEplNmtCmdResetConfiguration:
1027 case kEplNmtCmdSwReset:
1028 case kEplNmtCmdInvalidService:
1029 // valid command identifier specified
1030 break;
1031
1032 default:
1033 pParam_p->m_dwAbortCode =
1034 EPL_SDOAC_VALUE_RANGE_EXCEEDED;
1035 Ret = kEplObdAccessViolation;
1036 break;
1037 }
1038 } else if (pParam_p->m_ObdEvent == kEplObdEvPostWrite) {
1039 BYTE bNmtCommand;
1040
1041 bNmtCommand = *((BYTE *) pParam_p->m_pArg);
1042 // check value range
1043 switch ((tEplNmtCommand) bNmtCommand) {
1044 case kEplNmtCmdResetNode:
9d7164cf 1045#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
833dfbe7
GKH
1046 Ret =
1047 EplNmtuNmtEvent
1048 (kEplNmtEventResetNode);
9d7164cf 1049#endif
833dfbe7 1050 break;
9d7164cf 1051
833dfbe7 1052 case kEplNmtCmdResetCommunication:
9d7164cf 1053#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
833dfbe7
GKH
1054 Ret =
1055 EplNmtuNmtEvent
1056 (kEplNmtEventResetCom);
9d7164cf 1057#endif
833dfbe7 1058 break;
9d7164cf 1059
833dfbe7 1060 case kEplNmtCmdResetConfiguration:
9d7164cf 1061#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
833dfbe7
GKH
1062 Ret =
1063 EplNmtuNmtEvent
1064 (kEplNmtEventResetConfig);
9d7164cf 1065#endif
833dfbe7 1066 break;
9d7164cf 1067
833dfbe7 1068 case kEplNmtCmdSwReset:
9d7164cf 1069#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0)
833dfbe7
GKH
1070 Ret =
1071 EplNmtuNmtEvent
1072 (kEplNmtEventSwReset);
9d7164cf 1073#endif
833dfbe7 1074 break;
9d7164cf 1075
833dfbe7
GKH
1076 case kEplNmtCmdInvalidService:
1077 break;
9d7164cf 1078
833dfbe7
GKH
1079 default:
1080 pParam_p->m_dwAbortCode =
1081 EPL_SDOAC_VALUE_RANGE_EXCEEDED;
1082 Ret = kEplObdAccessViolation;
1083 break;
1084 }
1085 }
1086 break;
1087 }
9d7164cf 1088
833dfbe7
GKH
1089 default:
1090 break;
1091 }
9d7164cf
DK
1092
1093//Exit:
833dfbe7 1094 return Ret;
9d7164cf
DK
1095}
1096
9d7164cf
DK
1097//=========================================================================//
1098// //
1099// P R I V A T E F U N C T I O N S //
1100// //
1101//=========================================================================//
1102
9d7164cf
DK
1103//---------------------------------------------------------------------------
1104//
1105// Function: EplApiProcessEvent
1106//
1107// Description: processes events from event queue and forwards these to
1108// the application's event callback function
1109//
1110// Parameters: pEplEvent_p = pointer to event
1111//
1112// Returns: tEplKernel = errorcode
1113//
1114// State:
1115//
1116//---------------------------------------------------------------------------
1117
833dfbe7 1118static tEplKernel PUBLIC EplApiProcessEvent(tEplEvent * pEplEvent_p)
9d7164cf 1119{
833dfbe7
GKH
1120 tEplKernel Ret;
1121 tEplEventError *pEventError;
1122 tEplApiEventType EventType;
1123
1124 Ret = kEplSuccessful;
1125
1126 // process event
1127 switch (pEplEvent_p->m_EventType) {
1128 // error event
1129 case kEplEventTypeError:
1130 {
1131 pEventError = (tEplEventError *) pEplEvent_p->m_pArg;
1132 switch (pEventError->m_EventSource) {
1133 // treat the errors from the following sources as critical
1134 case kEplEventSourceEventk:
1135 case kEplEventSourceEventu:
1136 case kEplEventSourceDllk:
1137 {
1138 EventType = kEplApiEventCriticalError;
1139 // halt the stack by entering NMT state Off
1140 Ret =
1141 EplNmtuNmtEvent
1142 (kEplNmtEventCriticalError);
1143 break;
1144 }
1145
1146 // the other errors are just warnings
1147 default:
1148 {
1149 EventType = kEplApiEventWarning;
1150 break;
1151 }
1152 }
1153
1154 // call user callback
1155 Ret =
1156 EplApiInstance_g.m_InitParam.m_pfnCbEvent(EventType,
1157 (tEplApiEventArg
1158 *)
1159 pEventError,
1160 EplApiInstance_g.
1161 m_InitParam.
1162 m_pEventUserArg);
1163 // discard error from callback function, because this could generate an endless loop
1164 Ret = kEplSuccessful;
1165 break;
1166 }
1167
1168 // at present, there are no other events for this module
1169 default:
1170 break;
1171 }
1172
1173 return Ret;
9d7164cf
DK
1174}
1175
9d7164cf
DK
1176//---------------------------------------------------------------------------
1177//
1178// Function: EplApiCbNmtStateChange
1179//
1180// Description: callback function for NMT state changes
1181//
1182// Parameters: NmtStateChange_p = NMT state change event
1183//
1184// Returns: tEplKernel = error code
1185//
1186//
1187// State:
1188//
1189//---------------------------------------------------------------------------
1190
833dfbe7
GKH
1191static tEplKernel PUBLIC EplApiCbNmtStateChange(tEplEventNmtStateChange
1192 NmtStateChange_p)
9d7164cf 1193{
833dfbe7
GKH
1194 tEplKernel Ret = kEplSuccessful;
1195 BYTE bNmtState;
1196 tEplApiEventArg EventArg;
1197
1198 // save NMT state in OD
1199 bNmtState = (BYTE) NmtStateChange_p.m_NewNmtState;
1200 Ret = EplObdWriteEntry(0x1F8C, 0, &bNmtState, 1);
1201 if (Ret != kEplSuccessful) {
1202 goto Exit;
1203 }
1204 // do work which must be done in that state
1205 switch (NmtStateChange_p.m_NewNmtState) {
1206 // EPL stack is not running
1207 case kEplNmtGsOff:
1208 break;
1209
1210 // first init of the hardware
1211 case kEplNmtGsInitialising:
9d7164cf
DK
1212#if 0
1213#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDO_UDP)) != 0)
833dfbe7
GKH
1214 // configure SDO via UDP (i.e. bind it to the EPL ethernet interface)
1215 Ret =
1216 EplSdoUdpuConfig(EplApiInstance_g.m_InitParam.m_dwIpAddress,
1217 EPL_C_SDO_EPL_PORT);
1218 if (Ret != kEplSuccessful) {
1219 goto Exit;
1220 }
9d7164cf
DK
1221#endif
1222#endif
1223
833dfbe7
GKH
1224 break;
1225
1226 // init of the manufacturer-specific profile area and the
1227 // standardised device profile area
1228 case kEplNmtGsResetApplication:
1229 {
1230 // reset application part of OD
1231 Ret = EplObdAccessOdPart(kEplObdPartApp,
1232 kEplObdDirLoad);
1233 if (Ret != kEplSuccessful) {
1234 goto Exit;
1235 }
1236
1237 break;
1238 }
1239
1240 // init of the communication profile area
1241 case kEplNmtGsResetCommunication:
1242 {
1243 // reset communication part of OD
1244 Ret = EplObdAccessOdPart(kEplObdPartGen,
1245 kEplObdDirLoad);
1246
1247 if (Ret != kEplSuccessful) {
1248 goto Exit;
1249 }
1250 // $$$ d.k.: update OD only if OD was not loaded from non-volatile memory
1251 Ret = EplApiUpdateObd();
1252 if (Ret != kEplSuccessful) {
1253 goto Exit;
1254 }
1255
1256 break;
1257 }
1258
1259 // build the configuration with infos from OD
1260 case kEplNmtGsResetConfiguration:
1261 {
1262
1263 Ret = EplApiUpdateDllConfig(TRUE);
1264 if (Ret != kEplSuccessful) {
1265 goto Exit;
1266 }
1267
1268 break;
1269 }
1270
1271 //-----------------------------------------------------------
1272 // CN part of the state machine
1273
1274 // node liste for EPL-Frames and check timeout
1275 case kEplNmtCsNotActive:
1276 {
1277 // indicate completion of reset in NMT_ResetCmd_U8
1278 bNmtState = (BYTE) kEplNmtCmdInvalidService;
1279 Ret = EplObdWriteEntry(0x1F9E, 0, &bNmtState, 1);
1280 if (Ret != kEplSuccessful) {
1281 goto Exit;
1282 }
1283
1284 break;
1285 }
1286
1287 // node process only async frames
1288 case kEplNmtCsPreOperational1:
1289 {
1290 break;
1291 }
1292
1293 // node process isochronus and asynchronus frames
1294 case kEplNmtCsPreOperational2:
1295 {
1296 break;
1297 }
1298
1299 // node should be configured und application is ready
1300 case kEplNmtCsReadyToOperate:
1301 {
1302 break;
1303 }
1304
1305 // normal work state
1306 case kEplNmtCsOperational:
1307 {
1308 break;
1309 }
1310
1311 // node stopped by MN
1312 // -> only process asynchronus frames
1313 case kEplNmtCsStopped:
1314 {
1315 break;
1316 }
1317
1318 // no EPL cycle
1319 // -> normal ethernet communication
1320 case kEplNmtCsBasicEthernet:
1321 {
1322 break;
1323 }
1324
1325 //-----------------------------------------------------------
1326 // MN part of the state machine
1327
1328 // node listens for EPL-Frames and check timeout
1329 case kEplNmtMsNotActive:
1330 {
1331 break;
1332 }
1333
1334 // node processes only async frames
1335 case kEplNmtMsPreOperational1:
1336 {
1337 break;
1338 }
1339
1340 // node processes isochronous and asynchronous frames
1341 case kEplNmtMsPreOperational2:
1342 {
1343 break;
1344 }
1345
1346 // node should be configured und application is ready
1347 case kEplNmtMsReadyToOperate:
1348 {
1349 break;
1350 }
1351
1352 // normal work state
1353 case kEplNmtMsOperational:
1354 {
1355 break;
1356 }
1357
1358 // no EPL cycle
1359 // -> normal ethernet communication
1360 case kEplNmtMsBasicEthernet:
1361 {
1362 break;
1363 }
1364
1365 default:
1366 {
1367 TRACE0
1368 ("EplApiCbNmtStateChange(): unhandled NMT state\n");
1369 }
1370 }
9d7164cf
DK
1371
1372#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
833dfbe7
GKH
1373 // forward event to Led module
1374 Ret = EplLeduCbNmtStateChange(NmtStateChange_p);
1375 if (Ret != kEplSuccessful) {
1376 goto Exit;
1377 }
9d7164cf
DK
1378#endif
1379
1380#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
833dfbe7
GKH
1381 // forward event to NmtMn module
1382 Ret = EplNmtMnuCbNmtStateChange(NmtStateChange_p);
1383 if (Ret != kEplSuccessful) {
1384 goto Exit;
1385 }
9d7164cf
DK
1386#endif
1387
833dfbe7
GKH
1388 // call user callback
1389 EventArg.m_NmtStateChange = NmtStateChange_p;
1390 Ret =
1391 EplApiInstance_g.m_InitParam.
1392 m_pfnCbEvent(kEplApiEventNmtStateChange, &EventArg,
1393 EplApiInstance_g.m_InitParam.m_pEventUserArg);
9d7164cf 1394
833dfbe7
GKH
1395 Exit:
1396 return Ret;
9d7164cf
DK
1397}
1398
1399//---------------------------------------------------------------------------
1400//
1401// Function: EplApiUpdateDllConfig
1402//
1403// Description: update configuration of DLL
1404//
1405// Parameters: fUpdateIdentity_p = TRUE, if identity must be updated
1406//
1407// Returns: tEplKernel = error code
1408//
1409//
1410// State:
1411//
1412//---------------------------------------------------------------------------
1413
1414static tEplKernel PUBLIC EplApiUpdateDllConfig(BOOL fUpdateIdentity_p)
1415{
833dfbe7
GKH
1416 tEplKernel Ret = kEplSuccessful;
1417 tEplDllConfigParam DllConfigParam;
1418 tEplDllIdentParam DllIdentParam;
1419 tEplObdSize ObdSize;
1420 WORD wTemp;
1421 BYTE bTemp;
1422
1423 // configure Dll
1424 EPL_MEMSET(&DllConfigParam, 0, sizeof(DllConfigParam));
1425 DllConfigParam.m_uiNodeId = EplObdGetNodeId();
1426
1427 // Cycle Length (0x1006: NMT_CycleLen_U32) in [us]
1428 ObdSize = 4;
1429 Ret =
1430 EplObdReadEntry(0x1006, 0, &DllConfigParam.m_dwCycleLen, &ObdSize);
1431 if (Ret != kEplSuccessful) {
1432 goto Exit;
1433 }
1434 // 0x1F82: NMT_FeatureFlags_U32
1435 ObdSize = 4;
1436 Ret =
1437 EplObdReadEntry(0x1F82, 0, &DllConfigParam.m_dwFeatureFlags,
1438 &ObdSize);
1439 if (Ret != kEplSuccessful) {
1440 goto Exit;
1441 }
1442 // d.k. There is no dependance between FeatureFlags and async-only CN
1443 DllConfigParam.m_fAsyncOnly = EplApiInstance_g.m_InitParam.m_fAsyncOnly;
1444
1445 // 0x1C14: DLL_LossOfFrameTolerance_U32 in [ns]
1446 ObdSize = 4;
1447 Ret =
1448 EplObdReadEntry(0x1C14, 0, &DllConfigParam.m_dwLossOfFrameTolerance,
1449 &ObdSize);
1450 if (Ret != kEplSuccessful) {
1451 goto Exit;
1452 }
1453 // 0x1F98: NMT_CycleTiming_REC
1454 // 0x1F98.1: IsochrTxMaxPayload_U16
1455 ObdSize = 2;
1456 Ret = EplObdReadEntry(0x1F98, 1, &wTemp, &ObdSize);
1457 if (Ret != kEplSuccessful) {
1458 goto Exit;
1459 }
1460 DllConfigParam.m_uiIsochrTxMaxPayload = wTemp;
1461
1462 // 0x1F98.2: IsochrRxMaxPayload_U16
1463 ObdSize = 2;
1464 Ret = EplObdReadEntry(0x1F98, 2, &wTemp, &ObdSize);
1465 if (Ret != kEplSuccessful) {
1466 goto Exit;
1467 }
1468 DllConfigParam.m_uiIsochrRxMaxPayload = wTemp;
1469
1470 // 0x1F98.3: PResMaxLatency_U32
1471 ObdSize = 4;
1472 Ret =
1473 EplObdReadEntry(0x1F98, 3, &DllConfigParam.m_dwPresMaxLatency,
1474 &ObdSize);
1475 if (Ret != kEplSuccessful) {
1476 goto Exit;
1477 }
1478 // 0x1F98.4: PReqActPayloadLimit_U16
1479 ObdSize = 2;
1480 Ret = EplObdReadEntry(0x1F98, 4, &wTemp, &ObdSize);
1481 if (Ret != kEplSuccessful) {
1482 goto Exit;
1483 }
1484 DllConfigParam.m_uiPreqActPayloadLimit = wTemp;
1485
1486 // 0x1F98.5: PResActPayloadLimit_U16
1487 ObdSize = 2;
1488 Ret = EplObdReadEntry(0x1F98, 5, &wTemp, &ObdSize);
1489 if (Ret != kEplSuccessful) {
1490 goto Exit;
1491 }
1492 DllConfigParam.m_uiPresActPayloadLimit = wTemp;
1493
1494 // 0x1F98.6: ASndMaxLatency_U32
1495 ObdSize = 4;
1496 Ret =
1497 EplObdReadEntry(0x1F98, 6, &DllConfigParam.m_dwAsndMaxLatency,
1498 &ObdSize);
1499 if (Ret != kEplSuccessful) {
1500 goto Exit;
1501 }
1502 // 0x1F98.7: MultiplCycleCnt_U8
1503 ObdSize = 1;
1504 Ret = EplObdReadEntry(0x1F98, 7, &bTemp, &ObdSize);
1505 if (Ret != kEplSuccessful) {
1506 goto Exit;
1507 }
1508 DllConfigParam.m_uiMultiplCycleCnt = bTemp;
1509
1510 // 0x1F98.8: AsyncMTU_U16
1511 ObdSize = 2;
1512 Ret = EplObdReadEntry(0x1F98, 8, &wTemp, &ObdSize);
1513 if (Ret != kEplSuccessful) {
1514 goto Exit;
1515 }
1516 DllConfigParam.m_uiAsyncMtu = wTemp;
1517
1518 // $$$ Prescaler
9d7164cf
DK
1519
1520#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
833dfbe7
GKH
1521 // 0x1F8A.1: WaitSoCPReq_U32 in [ns]
1522 ObdSize = 4;
1523 Ret =
1524 EplObdReadEntry(0x1F8A, 1, &DllConfigParam.m_dwWaitSocPreq,
1525 &ObdSize);
1526 if (Ret != kEplSuccessful) {
1527 goto Exit;
1528 }
1529 // 0x1F8A.2: AsyncSlotTimeout_U32 in [ns] (optional)
1530 ObdSize = 4;
1531 Ret =
1532 EplObdReadEntry(0x1F8A, 2, &DllConfigParam.m_dwAsyncSlotTimeout,
1533 &ObdSize);
9d7164cf
DK
1534/* if(Ret != kEplSuccessful)
1535 {
1536 goto Exit;
1537 }*/
1538#endif
1539
833dfbe7
GKH
1540 DllConfigParam.m_uiSizeOfStruct = sizeof(DllConfigParam);
1541 Ret = EplDllkConfig(&DllConfigParam);
1542 if (Ret != kEplSuccessful) {
1543 goto Exit;
1544 }
1545
1546 if (fUpdateIdentity_p != FALSE) {
1547 // configure Identity
1548 EPL_MEMSET(&DllIdentParam, 0, sizeof(DllIdentParam));
1549 ObdSize = 4;
1550 Ret =
1551 EplObdReadEntry(0x1000, 0, &DllIdentParam.m_dwDeviceType,
1552 &ObdSize);
1553 if (Ret != kEplSuccessful) {
1554 goto Exit;
1555 }
1556
1557 ObdSize = 4;
1558 Ret =
1559 EplObdReadEntry(0x1018, 1, &DllIdentParam.m_dwVendorId,
1560 &ObdSize);
1561 if (Ret != kEplSuccessful) {
1562 goto Exit;
1563 }
1564 ObdSize = 4;
1565 Ret =
1566 EplObdReadEntry(0x1018, 2, &DllIdentParam.m_dwProductCode,
1567 &ObdSize);
1568 if (Ret != kEplSuccessful) {
1569 goto Exit;
1570 }
1571 ObdSize = 4;
1572 Ret =
1573 EplObdReadEntry(0x1018, 3,
1574 &DllIdentParam.m_dwRevisionNumber,
1575 &ObdSize);
1576 if (Ret != kEplSuccessful) {
1577 goto Exit;
1578 }
1579 ObdSize = 4;
1580 Ret =
1581 EplObdReadEntry(0x1018, 4, &DllIdentParam.m_dwSerialNumber,
1582 &ObdSize);
1583 if (Ret != kEplSuccessful) {
1584 goto Exit;
1585 }
1586
1587 DllIdentParam.m_dwIpAddress =
1588 EplApiInstance_g.m_InitParam.m_dwIpAddress;
1589 DllIdentParam.m_dwSubnetMask =
1590 EplApiInstance_g.m_InitParam.m_dwSubnetMask;
1591 EPL_MEMCPY(DllIdentParam.m_sHostname,
1592 EplApiInstance_g.m_InitParam.m_sHostname,
1593 sizeof(DllIdentParam.m_sHostname));
1594
1595 ObdSize = 4;
1596 Ret =
1597 EplObdReadEntry(0x1020, 1,
1598 &DllIdentParam.m_dwVerifyConfigurationDate,
1599 &ObdSize);
1600 // ignore any error, because this object is optional
1601
1602 ObdSize = 4;
1603 Ret =
1604 EplObdReadEntry(0x1020, 2,
1605 &DllIdentParam.m_dwVerifyConfigurationTime,
1606 &ObdSize);
1607 // ignore any error, because this object is optional
1608
1609 // $$$ d.k.: fill rest of ident structure
1610
1611 DllIdentParam.m_uiSizeOfStruct = sizeof(DllIdentParam);
1612 Ret = EplDllkSetIdentity(&DllIdentParam);
1613 if (Ret != kEplSuccessful) {
1614 goto Exit;
1615 }
1616 }
1617
1618 Exit:
1619 return Ret;
9d7164cf
DK
1620}
1621
1622//---------------------------------------------------------------------------
1623//
1624// Function: EplApiUpdateObd
1625//
1626// Description: update OD from init param
1627//
1628// Parameters: (none)
1629//
1630// Returns: tEplKernel = error code
1631//
1632//
1633// State:
1634//
1635//---------------------------------------------------------------------------
1636
1637static tEplKernel PUBLIC EplApiUpdateObd(void)
1638{
833dfbe7
GKH
1639 tEplKernel Ret = kEplSuccessful;
1640 WORD wTemp;
1641 BYTE bTemp;
1642
1643 // set node id in OD
1644 Ret = EplObdSetNodeId(EplApiInstance_g.m_InitParam.m_uiNodeId, // node id
1645 kEplObdNodeIdHardware); // set by hardware
1646 if (Ret != kEplSuccessful) {
1647 goto Exit;
1648 }
1649
1650 if (EplApiInstance_g.m_InitParam.m_dwCycleLen != -1) {
1651 Ret =
1652 EplObdWriteEntry(0x1006, 0,
1653 &EplApiInstance_g.m_InitParam.m_dwCycleLen,
1654 4);
9d7164cf
DK
1655/* if(Ret != kEplSuccessful)
1656 {
1657 goto Exit;
1658 }*/
833dfbe7
GKH
1659 }
1660
1661 if (EplApiInstance_g.m_InitParam.m_dwLossOfFrameTolerance != -1) {
1662 Ret =
1663 EplObdWriteEntry(0x1C14, 0,
1664 &EplApiInstance_g.m_InitParam.
1665 m_dwLossOfFrameTolerance, 4);
1666 /* if(Ret != kEplSuccessful)
1667 {
1668 goto Exit;
1669 } */
1670 }
1671 // d.k. There is no dependance between FeatureFlags and async-only CN.
1672 if (EplApiInstance_g.m_InitParam.m_dwFeatureFlags != -1) {
1673 Ret =
1674 EplObdWriteEntry(0x1F82, 0,
1675 &EplApiInstance_g.m_InitParam.
1676 m_dwFeatureFlags, 4);
1677 /* if(Ret != kEplSuccessful)
1678 {
1679 goto Exit;
1680 } */
1681 }
1682
1683 wTemp = (WORD) EplApiInstance_g.m_InitParam.m_uiIsochrTxMaxPayload;
1684 Ret = EplObdWriteEntry(0x1F98, 1, &wTemp, 2);
9d7164cf
DK
1685/* if(Ret != kEplSuccessful)
1686 {
1687 goto Exit;
1688 }*/
1689
833dfbe7
GKH
1690 wTemp = (WORD) EplApiInstance_g.m_InitParam.m_uiIsochrRxMaxPayload;
1691 Ret = EplObdWriteEntry(0x1F98, 2, &wTemp, 2);
9d7164cf
DK
1692/* if(Ret != kEplSuccessful)
1693 {
1694 goto Exit;
1695 }*/
1696
833dfbe7
GKH
1697 Ret =
1698 EplObdWriteEntry(0x1F98, 3,
1699 &EplApiInstance_g.m_InitParam.m_dwPresMaxLatency,
1700 4);
9d7164cf
DK
1701/* if(Ret != kEplSuccessful)
1702 {
1703 goto Exit;
1704 }*/
1705
833dfbe7
GKH
1706 if (EplApiInstance_g.m_InitParam.m_uiPreqActPayloadLimit <=
1707 EPL_C_DLL_ISOCHR_MAX_PAYL) {
1708 wTemp =
1709 (WORD) EplApiInstance_g.m_InitParam.m_uiPreqActPayloadLimit;
1710 Ret = EplObdWriteEntry(0x1F98, 4, &wTemp, 2);
9d7164cf
DK
1711/* if(Ret != kEplSuccessful)
1712 {
1713 goto Exit;
1714 }*/
833dfbe7 1715 }
9d7164cf 1716
833dfbe7
GKH
1717 if (EplApiInstance_g.m_InitParam.m_uiPresActPayloadLimit <=
1718 EPL_C_DLL_ISOCHR_MAX_PAYL) {
1719 wTemp =
1720 (WORD) EplApiInstance_g.m_InitParam.m_uiPresActPayloadLimit;
1721 Ret = EplObdWriteEntry(0x1F98, 5, &wTemp, 2);
9d7164cf
DK
1722/* if(Ret != kEplSuccessful)
1723 {
1724 goto Exit;
1725 }*/
833dfbe7 1726 }
9d7164cf 1727
833dfbe7
GKH
1728 Ret =
1729 EplObdWriteEntry(0x1F98, 6,
1730 &EplApiInstance_g.m_InitParam.m_dwAsndMaxLatency,
1731 4);
9d7164cf
DK
1732/* if(Ret != kEplSuccessful)
1733 {
1734 goto Exit;
1735 }*/
1736
833dfbe7
GKH
1737 if (EplApiInstance_g.m_InitParam.m_uiMultiplCycleCnt <= 0xFF) {
1738 bTemp = (BYTE) EplApiInstance_g.m_InitParam.m_uiMultiplCycleCnt;
1739 Ret = EplObdWriteEntry(0x1F98, 7, &bTemp, 1);
9d7164cf
DK
1740/* if(Ret != kEplSuccessful)
1741 {
1742 goto Exit;
1743 }*/
833dfbe7 1744 }
9d7164cf 1745
833dfbe7
GKH
1746 if (EplApiInstance_g.m_InitParam.m_uiAsyncMtu <=
1747 EPL_C_DLL_MAX_ASYNC_MTU) {
1748 wTemp = (WORD) EplApiInstance_g.m_InitParam.m_uiAsyncMtu;
1749 Ret = EplObdWriteEntry(0x1F98, 8, &wTemp, 2);
9d7164cf
DK
1750/* if(Ret != kEplSuccessful)
1751 {
1752 goto Exit;
1753 }*/
833dfbe7
GKH
1754 }
1755
1756 if (EplApiInstance_g.m_InitParam.m_uiPrescaler <= 1000) {
1757 wTemp = (WORD) EplApiInstance_g.m_InitParam.m_uiPrescaler;
1758 Ret = EplObdWriteEntry(0x1F98, 9, &wTemp, 2);
1759 // ignore return code
1760 Ret = kEplSuccessful;
1761 }
9d7164cf 1762#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
833dfbe7
GKH
1763 if (EplApiInstance_g.m_InitParam.m_dwWaitSocPreq != -1) {
1764 Ret =
1765 EplObdWriteEntry(0x1F8A, 1,
1766 &EplApiInstance_g.m_InitParam.
1767 m_dwWaitSocPreq, 4);
1768 /* if(Ret != kEplSuccessful)
1769 {
1770 goto Exit;
1771 } */
1772 }
1773
1774 if ((EplApiInstance_g.m_InitParam.m_dwAsyncSlotTimeout != 0)
1775 && (EplApiInstance_g.m_InitParam.m_dwAsyncSlotTimeout != -1)) {
1776 Ret =
1777 EplObdWriteEntry(0x1F8A, 2,
1778 &EplApiInstance_g.m_InitParam.
1779 m_dwAsyncSlotTimeout, 4);
1780 /* if(Ret != kEplSuccessful)
1781 {
1782 goto Exit;
1783 } */
1784 }
9d7164cf
DK
1785#endif
1786
833dfbe7
GKH
1787 // configure Identity
1788 if (EplApiInstance_g.m_InitParam.m_dwDeviceType != -1) {
1789 Ret =
1790 EplObdWriteEntry(0x1000, 0,
1791 &EplApiInstance_g.m_InitParam.
1792 m_dwDeviceType, 4);
9d7164cf
DK
1793/* if(Ret != kEplSuccessful)
1794 {
1795 goto Exit;
1796 }*/
833dfbe7 1797 }
9d7164cf 1798
833dfbe7
GKH
1799 if (EplApiInstance_g.m_InitParam.m_dwVendorId != -1) {
1800 Ret =
1801 EplObdWriteEntry(0x1018, 1,
1802 &EplApiInstance_g.m_InitParam.m_dwVendorId,
1803 4);
9d7164cf
DK
1804/* if(Ret != kEplSuccessful)
1805 {
1806 goto Exit;
1807 }*/
833dfbe7 1808 }
9d7164cf 1809
833dfbe7
GKH
1810 if (EplApiInstance_g.m_InitParam.m_dwProductCode != -1) {
1811 Ret =
1812 EplObdWriteEntry(0x1018, 2,
1813 &EplApiInstance_g.m_InitParam.
1814 m_dwProductCode, 4);
9d7164cf
DK
1815/* if(Ret != kEplSuccessful)
1816 {
1817 goto Exit;
1818 }*/
833dfbe7 1819 }
9d7164cf 1820
833dfbe7
GKH
1821 if (EplApiInstance_g.m_InitParam.m_dwRevisionNumber != -1) {
1822 Ret =
1823 EplObdWriteEntry(0x1018, 3,
1824 &EplApiInstance_g.m_InitParam.
1825 m_dwRevisionNumber, 4);
9d7164cf
DK
1826/* if(Ret != kEplSuccessful)
1827 {
1828 goto Exit;
1829 }*/
833dfbe7 1830 }
9d7164cf 1831
833dfbe7
GKH
1832 if (EplApiInstance_g.m_InitParam.m_dwSerialNumber != -1) {
1833 Ret =
1834 EplObdWriteEntry(0x1018, 4,
1835 &EplApiInstance_g.m_InitParam.
1836 m_dwSerialNumber, 4);
9d7164cf
DK
1837/* if(Ret != kEplSuccessful)
1838 {
1839 goto Exit;
1840 }*/
833dfbe7
GKH
1841 }
1842
1843 if (EplApiInstance_g.m_InitParam.m_pszDevName != NULL) {
1844 // write Device Name (0x1008)
1845 Ret =
1846 EplObdWriteEntry(0x1008, 0,
1847 (void GENERIC *)EplApiInstance_g.
1848 m_InitParam.m_pszDevName,
1849 (tEplObdSize) strlen(EplApiInstance_g.
1850 m_InitParam.
1851 m_pszDevName));
9d7164cf
DK
1852/* if (Ret != kEplSuccessful)
1853 {
1854 goto Exit;
1855 }*/
833dfbe7
GKH
1856 }
1857
1858 if (EplApiInstance_g.m_InitParam.m_pszHwVersion != NULL) {
1859 // write Hardware version (0x1009)
1860 Ret =
1861 EplObdWriteEntry(0x1009, 0,
1862 (void GENERIC *)EplApiInstance_g.
1863 m_InitParam.m_pszHwVersion,
1864 (tEplObdSize) strlen(EplApiInstance_g.
1865 m_InitParam.
1866 m_pszHwVersion));
9d7164cf
DK
1867/* if (Ret != kEplSuccessful)
1868 {
1869 goto Exit;
1870 }*/
833dfbe7
GKH
1871 }
1872
1873 if (EplApiInstance_g.m_InitParam.m_pszSwVersion != NULL) {
1874 // write Software version (0x100A)
1875 Ret =
1876 EplObdWriteEntry(0x100A, 0,
1877 (void GENERIC *)EplApiInstance_g.
1878 m_InitParam.m_pszSwVersion,
1879 (tEplObdSize) strlen(EplApiInstance_g.
1880 m_InitParam.
1881 m_pszSwVersion));
9d7164cf
DK
1882/* if (Ret != kEplSuccessful)
1883 {
1884 goto Exit;
1885 }*/
833dfbe7 1886 }
9d7164cf 1887
833dfbe7
GKH
1888 Exit:
1889 return Ret;
9d7164cf
DK
1890}
1891
9d7164cf
DK
1892//---------------------------------------------------------------------------
1893//
1894// Function: EplApiCbSdoCon
1895//
1896// Description: callback function for SDO transfers
1897//
1898// Parameters: pSdoComFinished_p = SDO parameter
1899//
1900// Returns: tEplKernel = error code
1901//
1902//
1903// State:
1904//
1905//---------------------------------------------------------------------------
1906
1907#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_SDOC)) != 0)
833dfbe7 1908static tEplKernel PUBLIC EplApiCbSdoCon(tEplSdoComFinished * pSdoComFinished_p)
9d7164cf 1909{
833dfbe7
GKH
1910 tEplKernel Ret;
1911 tEplApiEventArg EventArg;
9d7164cf 1912
833dfbe7 1913 Ret = kEplSuccessful;
9d7164cf 1914
833dfbe7
GKH
1915 // call user callback
1916 EventArg.m_Sdo = *pSdoComFinished_p;
1917 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventSdo,
1918 &EventArg,
1919 EplApiInstance_g.
1920 m_InitParam.
1921 m_pEventUserArg);
9d7164cf 1922
833dfbe7 1923 return Ret;
9d7164cf
DK
1924
1925}
1926#endif
1927
9d7164cf
DK
1928#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
1929
1930//---------------------------------------------------------------------------
1931//
1932// Function: EplApiCbNodeEvent
1933//
1934// Description: callback function for node events
1935//
1936// Parameters: uiNodeId_p = node ID of the CN
1937// NodeEvent_p = event from the specified CN
1938// NmtState_p = current NMT state of the CN
1939// wErrorCode_p = EPL error code if NodeEvent_p==kEplNmtNodeEventError
1940// fMandatory_p = flag if CN is mandatory
1941//
1942// Returns: tEplKernel = error code
1943//
1944//
1945// State:
1946//
1947//---------------------------------------------------------------------------
1948
833dfbe7
GKH
1949static tEplKernel PUBLIC EplApiCbNodeEvent(unsigned int uiNodeId_p,
1950 tEplNmtNodeEvent NodeEvent_p,
1951 tEplNmtState NmtState_p,
1952 WORD wErrorCode_p, BOOL fMandatory_p)
9d7164cf 1953{
833dfbe7
GKH
1954 tEplKernel Ret;
1955 tEplApiEventArg EventArg;
9d7164cf 1956
833dfbe7 1957 Ret = kEplSuccessful;
9d7164cf 1958
833dfbe7
GKH
1959 // call user callback
1960 EventArg.m_Node.m_uiNodeId = uiNodeId_p;
1961 EventArg.m_Node.m_NodeEvent = NodeEvent_p;
1962 EventArg.m_Node.m_NmtState = NmtState_p;
1963 EventArg.m_Node.m_wErrorCode = wErrorCode_p;
1964 EventArg.m_Node.m_fMandatory = fMandatory_p;
9d7164cf 1965
833dfbe7
GKH
1966 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventNode,
1967 &EventArg,
1968 EplApiInstance_g.
1969 m_InitParam.
1970 m_pEventUserArg);
9d7164cf 1971
833dfbe7 1972 return Ret;
9d7164cf
DK
1973
1974}
1975
9d7164cf
DK
1976//---------------------------------------------------------------------------
1977//
1978// Function: EplApiCbBootEvent
1979//
1980// Description: callback function for boot events
1981//
1982// Parameters: BootEvent_p = event from the boot-up process
1983// NmtState_p = current local NMT state
1984// wErrorCode_p = EPL error code if BootEvent_p==kEplNmtBootEventError
1985//
1986// Returns: tEplKernel = error code
1987//
1988//
1989// State:
1990//
1991//---------------------------------------------------------------------------
1992
833dfbe7
GKH
1993static tEplKernel PUBLIC EplApiCbBootEvent(tEplNmtBootEvent BootEvent_p,
1994 tEplNmtState NmtState_p,
1995 WORD wErrorCode_p)
9d7164cf 1996{
833dfbe7
GKH
1997 tEplKernel Ret;
1998 tEplApiEventArg EventArg;
9d7164cf 1999
833dfbe7 2000 Ret = kEplSuccessful;
9d7164cf 2001
833dfbe7
GKH
2002 // call user callback
2003 EventArg.m_Boot.m_BootEvent = BootEvent_p;
2004 EventArg.m_Boot.m_NmtState = NmtState_p;
2005 EventArg.m_Boot.m_wErrorCode = wErrorCode_p;
9d7164cf 2006
833dfbe7
GKH
2007 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventBoot,
2008 &EventArg,
2009 EplApiInstance_g.
2010 m_InitParam.
2011 m_pEventUserArg);
9d7164cf 2012
833dfbe7 2013 return Ret;
9d7164cf
DK
2014
2015}
2016
2017#endif // (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
2018
9d7164cf
DK
2019#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_LEDU)) != 0)
2020
2021//---------------------------------------------------------------------------
2022//
2023// Function: EplApiCbLedStateChange
2024//
2025// Description: callback function for LED change events.
2026//
2027// Parameters: LedType_p = type of LED
2028// fOn_p = state of LED
2029//
2030// Returns: tEplKernel = errorcode
2031//
2032// State:
2033//
2034//---------------------------------------------------------------------------
2035
833dfbe7
GKH
2036static tEplKernel PUBLIC EplApiCbLedStateChange(tEplLedType LedType_p,
2037 BOOL fOn_p)
9d7164cf 2038{
833dfbe7
GKH
2039 tEplKernel Ret;
2040 tEplApiEventArg EventArg;
9d7164cf 2041
833dfbe7 2042 Ret = kEplSuccessful;
9d7164cf 2043
833dfbe7
GKH
2044 // call user callback
2045 EventArg.m_Led.m_LedType = LedType_p;
2046 EventArg.m_Led.m_fOn = fOn_p;
9d7164cf 2047
833dfbe7
GKH
2048 Ret = EplApiInstance_g.m_InitParam.m_pfnCbEvent(kEplApiEventLed,
2049 &EventArg,
2050 EplApiInstance_g.
2051 m_InitParam.
2052 m_pEventUserArg);
9d7164cf 2053
833dfbe7 2054 return Ret;
9d7164cf
DK
2055
2056}
2057
2058#endif
2059
9d7164cf 2060// EOF