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