Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
[linux-2.6] / drivers / staging / epl / EplNmtk.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 NMT-Kernelspace-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: EplNmtk.c,v $
53
54                 $Author: D.Krueger $
55
56                 $Revision: 1.12 $  $Date: 2008/11/13 17:13:09 $
57
58                 $State: Exp $
59
60                 Build Environment:
61                     GCC V3.4
62
63   -------------------------------------------------------------------------
64
65   Revision History:
66
67   2006/06/09 k.t.:   start of the implementation
68
69 ****************************************************************************/
70
71 #include "kernel/EplNmtk.h"
72 #include "kernel/EplTimerk.h"
73
74 #include "kernel/EplDllk.h"     // for EplDllkProcess()
75
76 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
77 /***************************************************************************/
78 /*                                                                         */
79 /*                                                                         */
80 /*          G L O B A L   D E F I N I T I O N S                            */
81 /*                                                                         */
82 /*                                                                         */
83 /***************************************************************************/
84
85 //---------------------------------------------------------------------------
86 // const defines
87 //---------------------------------------------------------------------------
88
89 // TracePoint support for realtime-debugging
90 #ifdef _DBG_TRACE_POINTS_
91 void TgtDbgSignalTracePoint(u8 bTracePointNumber_p);
92 void TgtDbgPostTraceValue(u32 dwTraceValue_p);
93 #define TGT_DBG_SIGNAL_TRACE_POINT(p)   TgtDbgSignalTracePoint(p)
94 #define TGT_DBG_POST_TRACE_VALUE(v)     TgtDbgPostTraceValue(v)
95 #else
96 #define TGT_DBG_SIGNAL_TRACE_POINT(p)
97 #define TGT_DBG_POST_TRACE_VALUE(v)
98 #endif
99 #define EPL_NMTK_DBG_POST_TRACE_VALUE(NmtEvent_p, OldNmtState_p, NewNmtState_p) \
100     TGT_DBG_POST_TRACE_VALUE((kEplEventSinkNmtk << 28) | (NmtEvent_p << 16) \
101                              | ((OldNmtState_p & 0xFF) << 8) \
102                              | (NewNmtState_p & 0xFF))
103
104 //---------------------------------------------------------------------------
105 // local types
106 //---------------------------------------------------------------------------
107 // struct for instance table
108 INSTANCE_TYPE_BEGIN EPL_MCO_DECL_INSTANCE_MEMBER()
109
110 STATIC volatile tEplNmtState m_NmtState;
111 STATIC volatile BOOL m_fEnableReadyToOperate;
112 STATIC volatile BOOL m_fAppReadyToOperate;
113 STATIC volatile BOOL m_fTimerMsPreOp2;
114 STATIC volatile BOOL m_fAllMandatoryCNIdent;
115 STATIC volatile BOOL m_fFrozen;
116
117 INSTANCE_TYPE_END
118 //---------------------------------------------------------------------------
119 // modul globale vars
120 //---------------------------------------------------------------------------
121 // This macro replace the unspecific pointer to an instance through
122 // the modul specific type for the local instance table. This macro
123 // must defined in each modul.
124 //#define tEplPtrInstance             tEplInstanceInfo*
125 EPL_MCO_DECL_INSTANCE_VAR()
126 //---------------------------------------------------------------------------
127 // local function prototypes
128 //---------------------------------------------------------------------------
129 EPL_MCO_DEFINE_INSTANCE_FCT()
130
131 /***************************************************************************/
132 /*                                                                         */
133 /*                                                                         */
134 /*          C L A S S  <NMT_Kernel-Module>                                 */
135 /*                                                                         */
136 /*                                                                         */
137 /***************************************************************************/
138 //
139 // Description: This module realize the NMT-State-Machine of the EPL-Stack
140 //
141 //
142 /***************************************************************************/
143 //=========================================================================//
144 //                                                                         //
145 //          P U B L I C   F U N C T I O N S                                //
146 //                                                                         //
147 //=========================================================================//
148 //---------------------------------------------------------------------------
149 //
150 // Function:        EplNmtkInit
151 //
152 // Description: initializes the first instance
153 //
154 //
155 //
156 // Parameters:  EPL_MCO_DECL_PTR_INSTANCE_PTR = Instance pointer
157 //              uiNodeId_p = Node Id of the lokal node
158 //
159 //
160 // Returns:     tEplKernel  =   Errorcode
161 //
162 //
163 // State:
164 //
165 //---------------------------------------------------------------------------
166 tEplKernel EplNmtkInit(EPL_MCO_DECL_PTR_INSTANCE_PTR)
167 {
168         tEplKernel Ret;
169
170         Ret = EplNmtkAddInstance(EPL_MCO_PTR_INSTANCE_PTR);
171
172         return Ret;
173 }
174
175 //---------------------------------------------------------------------------
176 //
177 // Function:        EplNmtkAddInstance
178 //
179 // Description: adds a new instance
180 //
181 //
182 //
183 // Parameters:  EPL_MCO_DECL_PTR_INSTANCE_PTR = Instance pointer
184 //
185 //
186 // Returns:     tEplKernel  =   Errorcode
187 //
188 //
189 // State:
190 //
191 //---------------------------------------------------------------------------
192 tEplKernel EplNmtkAddInstance(EPL_MCO_DECL_PTR_INSTANCE_PTR)
193 {
194         EPL_MCO_DECL_INSTANCE_PTR_LOCAL tEplKernel Ret;
195 //tEplEvent               Event;
196 //tEplEventNmtStateChange NmtStateChange;
197
198         // check if pointer to instance pointer valid
199         // get free instance and set the globale instance pointer
200         // set also the instance addr to parameterlist
201         EPL_MCO_CHECK_PTR_INSTANCE_PTR();
202         EPL_MCO_GET_FREE_INSTANCE_PTR();
203         EPL_MCO_SET_PTR_INSTANCE_PTR();
204
205         // sign instance as used
206         EPL_MCO_WRITE_INSTANCE_STATE(kStateUsed);
207
208         Ret = kEplSuccessful;
209
210         // initialize intern vaiables
211         // 2006/07/31 d.k.: set NMT-State to kEplNmtGsOff
212         EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtGsOff;
213         // set NMT-State to kEplNmtGsInitialising
214         //EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtGsInitialising;
215
216         // set flags to FALSE
217         EPL_MCO_GLB_VAR(m_fEnableReadyToOperate) = FALSE;
218         EPL_MCO_GLB_VAR(m_fAppReadyToOperate) = FALSE;
219         EPL_MCO_GLB_VAR(m_fTimerMsPreOp2) = FALSE;
220         EPL_MCO_GLB_VAR(m_fAllMandatoryCNIdent) = FALSE;
221         EPL_MCO_GLB_VAR(m_fFrozen) = FALSE;
222
223 //    EPL_MCO_GLB_VAR(m_TimerHdl) = 0;
224
225         // inform higher layer about state change
226         // 2006/07/31 d.k.: The EPL API layer/application has to start NMT state
227         //                  machine via NmtEventSwReset after initialisation of
228         //                  all modules has been completed. DLL has to be initialised
229         //                  after NMTk because NMT state shall not be uninitialised
230         //                  at that time.
231 /*    NmtStateChange.m_NewNmtState = EPL_MCO_GLB_VAR(m_NmtState);
232     NmtStateChange.m_NmtEvent = kEplNmtEventNoEvent;
233     Event.m_EventSink = kEplEventSinkNmtu;
234     Event.m_EventType = kEplEventTypeNmtStateChange;
235     EPL_MEMSET(&Event.m_NetTime, 0x00, sizeof(Event.m_NetTime));
236     Event.m_pArg = &NmtStateChange;
237     Event.m_uiSize = sizeof(NmtStateChange);
238     Ret = EplEventkPost(&Event);
239 */
240         return Ret;
241 }
242
243 //---------------------------------------------------------------------------
244 //
245 // Function:        EplNmtkDelInstance
246 //
247 // Description: delete instance
248 //
249 //
250 //
251 // Parameters:  EPL_MCO_DECL_PTR_INSTANCE_PTR = Instance pointer
252 //
253 //
254 // Returns:     tEplKernel  =   Errorcode
255 //
256 //
257 // State:
258 //
259 //---------------------------------------------------------------------------
260 #if (EPL_USE_DELETEINST_FUNC != FALSE)
261 tEplKernel EplNmtkDelInstance(EPL_MCO_DECL_PTR_INSTANCE_PTR)
262 {
263         tEplKernel Ret = kEplSuccessful;
264         // check for all API function if instance is valid
265         EPL_MCO_CHECK_INSTANCE_STATE();
266
267         // set NMT-State to kEplNmtGsOff
268         EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtGsOff;
269
270         // sign instance as unused
271         EPL_MCO_WRITE_INSTANCE_STATE(kStateUnused);
272
273         // delete timer
274 //    Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
275
276         return Ret;
277 }
278 #endif // (EPL_USE_DELETEINST_FUNC != FALSE)
279
280 //---------------------------------------------------------------------------
281 //
282 // Function:        EplNmtkProcess
283 //
284 // Description: main process function
285 //              -> process NMT-State-Maschine und read NMT-Events from Queue
286 //
287 //
288 //
289 // Parameters:  EPL_MCO_DECL_PTR_INSTANCE_PTR_ = Instance pointer
290 //              pEvent_p    =   Epl-Event with NMT-event to process
291 //
292 //
293 // Returns:     tEplKernel  =   Errorcode
294 //
295 //
296 // State:
297 //
298 //---------------------------------------------------------------------------
299 tEplKernel EplNmtkProcess(EPL_MCO_DECL_PTR_INSTANCE_PTR_ tEplEvent *pEvent_p)
300 {
301         tEplKernel Ret;
302         tEplNmtState OldNmtState;
303         tEplNmtEvent NmtEvent;
304         tEplEvent Event;
305         tEplEventNmtStateChange NmtStateChange;
306
307         // check for all API function if instance is valid
308         EPL_MCO_CHECK_INSTANCE_STATE();
309
310         Ret = kEplSuccessful;
311
312         switch (pEvent_p->m_EventType) {
313         case kEplEventTypeNmtEvent:
314                 {
315                         NmtEvent = *((tEplNmtEvent *) pEvent_p->m_pArg);
316                         break;
317                 }
318
319         case kEplEventTypeTimer:
320                 {
321                         NmtEvent =
322                             (tEplNmtEvent) ((tEplTimerEventArg *) pEvent_p->
323                                             m_pArg)->m_ulArg;
324                         break;
325                 }
326         default:
327                 {
328                         Ret = kEplNmtInvalidEvent;
329                         goto Exit;
330                 }
331         }
332
333         // save NMT-State
334         // needed for later comparison to
335         // inform hgher layer about state change
336         OldNmtState = EPL_MCO_GLB_VAR(m_NmtState);
337
338         // NMT-State-Maschine
339         switch (EPL_MCO_GLB_VAR(m_NmtState)) {
340                 //-----------------------------------------------------------
341                 // general part of the statemaschine
342
343                 // first init of the hardware
344         case kEplNmtGsOff:
345                 {
346                         // leave this state only if higher layer says so
347                         if (NmtEvent == kEplNmtEventSwReset) {  // new state kEplNmtGsInitialising
348                                 EPL_MCO_GLB_VAR(m_NmtState) =
349                                     kEplNmtGsInitialising;
350                         }
351                         break;
352                 }
353
354                 // first init of the hardware
355         case kEplNmtGsInitialising:
356                 {
357                         // leave this state only if higher layer says so
358
359                         // check events
360                         switch (NmtEvent) {
361                                 // 2006/07/31 d.k.: react also on NMT reset commands in ResetApp state
362                                 // NMT Command SwitchOff
363                         case kEplNmtEventCriticalError:
364                         case kEplNmtEventSwitchOff:
365                                 {
366                                         EPL_MCO_GLB_VAR(m_NmtState) =
367                                             kEplNmtGsOff;
368                                         break;
369                                 }
370
371                                 // new state kEplNmtGsResetApplication
372                         case kEplNmtEventEnterResetApp:
373                                 {
374                                         EPL_MCO_GLB_VAR(m_NmtState) =
375                                             kEplNmtGsResetApplication;
376                                         break;
377                                 }
378
379                         default:
380                                 {
381                                         break;
382                                 }
383                         }
384                         break;
385                 }
386
387                 // init of the manufacturer-specific profile area and the
388                 // standardised device profile area
389         case kEplNmtGsResetApplication:
390                 {
391                         // check events
392                         switch (NmtEvent) {
393                                 // 2006/07/31 d.k.: react also on NMT reset commands in ResetApp state
394                                 // NMT Command SwitchOff
395                         case kEplNmtEventCriticalError:
396                         case kEplNmtEventSwitchOff:
397                                 {
398                                         EPL_MCO_GLB_VAR(m_NmtState) =
399                                             kEplNmtGsOff;
400                                         break;
401                                 }
402
403                                 // NMT Command SwReset
404                         case kEplNmtEventSwReset:
405                                 {
406                                         EPL_MCO_GLB_VAR(m_NmtState) =
407                                             kEplNmtGsInitialising;
408                                         break;
409                                 }
410
411                                 // leave this state only if higher layer
412                                 // say so
413                         case kEplNmtEventEnterResetCom:
414                                 {
415                                         // new state kEplNmtGsResetCommunication
416                                         EPL_MCO_GLB_VAR(m_NmtState) =
417                                             kEplNmtGsResetCommunication;
418                                         break;
419                                 }
420
421                         default:
422                                 {
423                                         break;
424                                 }
425                         }
426                         break;
427                 }
428
429                 // init of the communication profile area
430         case kEplNmtGsResetCommunication:
431                 {
432                         // check events
433                         switch (NmtEvent) {
434                                 // 2006/07/31 d.k.: react also on NMT reset commands in ResetComm state
435                                 // NMT Command SwitchOff
436                         case kEplNmtEventCriticalError:
437                         case kEplNmtEventSwitchOff:
438                                 {
439                                         EPL_MCO_GLB_VAR(m_NmtState) =
440                                             kEplNmtGsOff;
441                                         break;
442                                 }
443
444                                 // NMT Command SwReset
445                         case kEplNmtEventSwReset:
446                                 {
447                                         EPL_MCO_GLB_VAR(m_NmtState) =
448                                             kEplNmtGsInitialising;
449                                         break;
450                                 }
451
452                                 // NMT Command ResetNode
453                         case kEplNmtEventResetNode:
454                                 {
455                                         EPL_MCO_GLB_VAR(m_NmtState) =
456                                             kEplNmtGsResetApplication;
457                                         break;
458                                 }
459
460                                 // leave this state only if higher layer
461                                 // say so
462                         case kEplNmtEventEnterResetConfig:
463                                 {
464                                         // new state kEplNmtGsResetCommunication
465                                         EPL_MCO_GLB_VAR(m_NmtState) =
466                                             kEplNmtGsResetConfiguration;
467                                         break;
468                                 }
469
470                         default:
471                                 {
472                                         break;
473                                 }
474                         }
475                         break;
476                 }
477
478                 // build the configuration with infos from OD
479         case kEplNmtGsResetConfiguration:
480                 {
481                         // reset flags
482                         EPL_MCO_GLB_VAR(m_fEnableReadyToOperate) = FALSE;
483                         EPL_MCO_GLB_VAR(m_fAppReadyToOperate) = FALSE;
484                         EPL_MCO_GLB_VAR(m_fFrozen) = FALSE;
485
486                         // check events
487                         switch (NmtEvent) {
488                                 // 2006/07/31 d.k.: react also on NMT reset commands in ResetConf state
489                                 // NMT Command SwitchOff
490                         case kEplNmtEventCriticalError:
491                         case kEplNmtEventSwitchOff:
492                                 {
493                                         EPL_MCO_GLB_VAR(m_NmtState) =
494                                             kEplNmtGsOff;
495                                         break;
496                                 }
497
498                                 // NMT Command SwReset
499                         case kEplNmtEventSwReset:
500                                 {
501                                         EPL_MCO_GLB_VAR(m_NmtState) =
502                                             kEplNmtGsInitialising;
503                                         break;
504                                 }
505
506                                 // NMT Command ResetNode
507                         case kEplNmtEventResetNode:
508                                 {
509                                         EPL_MCO_GLB_VAR(m_NmtState) =
510                                             kEplNmtGsResetApplication;
511                                         break;
512                                 }
513
514                                 // NMT Command ResetCommunication
515                         case kEplNmtEventResetCom:
516                                 {
517                                         EPL_MCO_GLB_VAR(m_NmtState) =
518                                             kEplNmtGsResetCommunication;
519                                         break;
520                                 }
521
522                                 // leave this state only if higher layer says so
523                         case kEplNmtEventEnterCsNotActive:
524                                 {       // Node should be CN
525                                         EPL_MCO_GLB_VAR(m_NmtState) =
526                                             kEplNmtCsNotActive;
527                                         break;
528
529                                 }
530
531                         case kEplNmtEventEnterMsNotActive:
532                                 {       // Node should be CN
533 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) == 0)
534                                         // no MN functionality
535                                         // TODO: -create error E_NMT_BA1_NO_MN_SUPPORT
536                                         EPL_MCO_GLB_VAR(m_fFrozen) = TRUE;
537 #else
538
539                                         EPL_MCO_GLB_VAR(m_NmtState) =
540                                             kEplNmtMsNotActive;
541 #endif
542                                         break;
543
544                                 }
545
546                         default:
547                                 {
548                                         break;
549                                 }
550                         }
551                         break;
552                 }
553
554                 //-----------------------------------------------------------
555                 // CN part of the statemaschine
556
557                 // node liste for EPL-Frames and check timeout
558         case kEplNmtCsNotActive:
559                 {
560
561                         // check events
562                         switch (NmtEvent) {
563                                 // 2006/07/31 d.k.: react also on NMT reset commands in NotActive state
564                                 // NMT Command SwitchOff
565                         case kEplNmtEventCriticalError:
566                         case kEplNmtEventSwitchOff:
567                                 {
568                                         EPL_MCO_GLB_VAR(m_NmtState) =
569                                             kEplNmtGsOff;
570                                         break;
571                                 }
572
573                                 // NMT Command SwReset
574                         case kEplNmtEventSwReset:
575                                 {
576                                         EPL_MCO_GLB_VAR(m_NmtState) =
577                                             kEplNmtGsInitialising;
578 //                    Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
579                                         break;
580                                 }
581
582                                 // NMT Command ResetNode
583                         case kEplNmtEventResetNode:
584                                 {
585                                         EPL_MCO_GLB_VAR(m_NmtState) =
586                                             kEplNmtGsResetApplication;
587 //                    Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
588                                         break;
589                                 }
590
591                                 // NMT Command ResetCommunication
592                                 // or internal Communication error
593                         case kEplNmtEventResetCom:
594                         case kEplNmtEventInternComError:
595                                 {
596                                         EPL_MCO_GLB_VAR(m_NmtState) =
597                                             kEplNmtGsResetCommunication;
598 //                    Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
599                                         break;
600                                 }
601
602                                 // NMT Command Reset Configuration
603                         case kEplNmtEventResetConfig:
604                                 {
605                                         EPL_MCO_GLB_VAR(m_NmtState) =
606                                             kEplNmtGsResetConfiguration;
607 //                    Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
608                                         break;
609                                 }
610
611                                 // see if SoA or SoC received
612                                 // k.t. 20.07.2006: only SoA forces change of state
613                                 // see EPL V2 DS 1.0.0 p.267
614                                 // case kEplNmtEventDllCeSoc:
615                         case kEplNmtEventDllCeSoa:
616                                 {       // new state PRE_OPERATIONAL1
617                                         EPL_MCO_GLB_VAR(m_NmtState) =
618                                             kEplNmtCsPreOperational1;
619 //                    Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
620                                         break;
621                                 }
622                                 // timeout for SoA and Soc
623                         case kEplNmtEventTimerBasicEthernet:
624                                 {
625                                         // new state BASIC_ETHERNET
626                                         EPL_MCO_GLB_VAR(m_NmtState) =
627                                             kEplNmtCsBasicEthernet;
628                                         break;
629                                 }
630
631                         default:
632                                 {
633                                         break;
634                                 }
635                         }       // end of switch(NmtEvent)
636
637                         break;
638                 }
639
640                 // node processes only async frames
641         case kEplNmtCsPreOperational1:
642                 {
643
644                         // check events
645                         switch (NmtEvent) {
646                                 // NMT Command SwitchOff
647                         case kEplNmtEventCriticalError:
648                         case kEplNmtEventSwitchOff:
649                                 {
650                                         EPL_MCO_GLB_VAR(m_NmtState) =
651                                             kEplNmtGsOff;
652                                         break;
653                                 }
654
655                                 // NMT Command SwReset
656                         case kEplNmtEventSwReset:
657                                 {
658                                         EPL_MCO_GLB_VAR(m_NmtState) =
659                                             kEplNmtGsInitialising;
660                                         break;
661                                 }
662
663                                 // NMT Command ResetNode
664                         case kEplNmtEventResetNode:
665                                 {
666                                         EPL_MCO_GLB_VAR(m_NmtState) =
667                                             kEplNmtGsResetApplication;
668                                         break;
669                                 }
670
671                                 // NMT Command ResetCommunication
672                                 // or internal Communication error
673                         case kEplNmtEventResetCom:
674                         case kEplNmtEventInternComError:
675                                 {
676                                         EPL_MCO_GLB_VAR(m_NmtState) =
677                                             kEplNmtGsResetCommunication;
678                                         break;
679                                 }
680
681                                 // NMT Command Reset Configuration
682                         case kEplNmtEventResetConfig:
683                                 {
684                                         EPL_MCO_GLB_VAR(m_NmtState) =
685                                             kEplNmtGsResetConfiguration;
686                                         break;
687                                 }
688
689                                 // NMT Command StopNode
690                         case kEplNmtEventStopNode:
691                                 {
692                                         EPL_MCO_GLB_VAR(m_NmtState) =
693                                             kEplNmtCsStopped;
694                                         break;
695                                 }
696
697                                 // check if SoC received
698                         case kEplNmtEventDllCeSoc:
699                                 {
700                                         EPL_MCO_GLB_VAR(m_NmtState) =
701                                             kEplNmtCsPreOperational2;
702                                         break;
703                                 }
704
705                         default:
706                                 {
707                                         break;
708                                 }
709
710                         }       // end of switch(NmtEvent)
711
712                         break;
713                 }
714
715                 // node processes isochronous and asynchronous frames
716         case kEplNmtCsPreOperational2:
717                 {
718                         // check events
719                         switch (NmtEvent) {
720                                 // NMT Command SwitchOff
721                         case kEplNmtEventCriticalError:
722                         case kEplNmtEventSwitchOff:
723                                 {
724                                         EPL_MCO_GLB_VAR(m_NmtState) =
725                                             kEplNmtGsOff;
726                                         break;
727                                 }
728
729                                 // NMT Command SwReset
730                         case kEplNmtEventSwReset:
731                                 {
732                                         EPL_MCO_GLB_VAR(m_NmtState) =
733                                             kEplNmtGsInitialising;
734                                         break;
735                                 }
736
737                                 // NMT Command ResetNode
738                         case kEplNmtEventResetNode:
739                                 {
740                                         EPL_MCO_GLB_VAR(m_NmtState) =
741                                             kEplNmtGsResetApplication;
742                                         break;
743                                 }
744
745                                 // NMT Command ResetCommunication
746                                 // or internal Communication error
747                         case kEplNmtEventResetCom:
748                         case kEplNmtEventInternComError:
749                                 {
750                                         EPL_MCO_GLB_VAR(m_NmtState) =
751                                             kEplNmtGsResetCommunication;
752                                         break;
753                                 }
754
755                                 // NMT Command Reset Configuration
756                         case kEplNmtEventResetConfig:
757                                 {
758                                         EPL_MCO_GLB_VAR(m_NmtState) =
759                                             kEplNmtGsResetConfiguration;
760                                         break;
761                                 }
762
763                                 // NMT Command StopNode
764                         case kEplNmtEventStopNode:
765                                 {
766                                         // reset flags
767                                         EPL_MCO_GLB_VAR(m_fEnableReadyToOperate)
768                                             = FALSE;
769                                         EPL_MCO_GLB_VAR(m_fAppReadyToOperate) =
770                                             FALSE;
771                                         EPL_MCO_GLB_VAR(m_NmtState) =
772                                             kEplNmtCsStopped;
773                                         break;
774                                 }
775
776                                 // error occured
777                         case kEplNmtEventNmtCycleError:
778                                 {
779                                         // reset flags
780                                         EPL_MCO_GLB_VAR(m_fEnableReadyToOperate)
781                                             = FALSE;
782                                         EPL_MCO_GLB_VAR(m_fAppReadyToOperate) =
783                                             FALSE;
784                                         EPL_MCO_GLB_VAR(m_NmtState) =
785                                             kEplNmtCsPreOperational1;
786                                         break;
787                                 }
788
789                                 // check if application is ready to operate
790                         case kEplNmtEventEnterReadyToOperate:
791                                 {
792                                         // check if command NMTEnableReadyToOperate from MN was received
793                                         if (EPL_MCO_GLB_VAR(m_fEnableReadyToOperate) == TRUE) { // reset flags
794                                                 EPL_MCO_GLB_VAR
795                                                     (m_fEnableReadyToOperate) =
796                                                     FALSE;
797                                                 EPL_MCO_GLB_VAR
798                                                     (m_fAppReadyToOperate) =
799                                                     FALSE;
800                                                 // change state
801                                                 EPL_MCO_GLB_VAR(m_NmtState) =
802                                                     kEplNmtCsReadyToOperate;
803                                         } else {        // set Flag
804                                                 EPL_MCO_GLB_VAR
805                                                     (m_fAppReadyToOperate) =
806                                                     TRUE;
807                                         }
808                                         break;
809                                 }
810
811                                 // NMT Commando EnableReadyToOperate
812                         case kEplNmtEventEnableReadyToOperate:
813                                 {
814                                         // check if application is ready
815                                         if (EPL_MCO_GLB_VAR(m_fAppReadyToOperate) == TRUE) {    // reset flags
816                                                 EPL_MCO_GLB_VAR
817                                                     (m_fEnableReadyToOperate) =
818                                                     FALSE;
819                                                 EPL_MCO_GLB_VAR
820                                                     (m_fAppReadyToOperate) =
821                                                     FALSE;
822                                                 // change state
823                                                 EPL_MCO_GLB_VAR(m_NmtState) =
824                                                     kEplNmtCsReadyToOperate;
825                                         } else {        // set Flag
826                                                 EPL_MCO_GLB_VAR
827                                                     (m_fEnableReadyToOperate) =
828                                                     TRUE;
829                                         }
830                                         break;
831                                 }
832
833                         default:
834                                 {
835                                         break;
836                                 }
837
838                         }       // end of switch(NmtEvent)
839                         break;
840                 }
841
842                 // node should be configured und application is ready
843         case kEplNmtCsReadyToOperate:
844                 {
845                         // check events
846                         switch (NmtEvent) {
847                                 // NMT Command SwitchOff
848                         case kEplNmtEventCriticalError:
849                         case kEplNmtEventSwitchOff:
850                                 {
851                                         EPL_MCO_GLB_VAR(m_NmtState) =
852                                             kEplNmtGsOff;
853                                         break;
854                                 }
855
856                                 // NMT Command SwReset
857                         case kEplNmtEventSwReset:
858                                 {
859                                         EPL_MCO_GLB_VAR(m_NmtState) =
860                                             kEplNmtGsInitialising;
861                                         break;
862                                 }
863
864                                 // NMT Command ResetNode
865                         case kEplNmtEventResetNode:
866                                 {
867                                         EPL_MCO_GLB_VAR(m_NmtState) =
868                                             kEplNmtGsResetApplication;
869                                         break;
870                                 }
871
872                                 // NMT Command ResetCommunication
873                                 // or internal Communication error
874                         case kEplNmtEventResetCom:
875                         case kEplNmtEventInternComError:
876                                 {
877                                         EPL_MCO_GLB_VAR(m_NmtState) =
878                                             kEplNmtGsResetCommunication;
879                                         break;
880                                 }
881
882                                 // NMT Command ResetConfiguration
883                         case kEplNmtEventResetConfig:
884                                 {
885                                         EPL_MCO_GLB_VAR(m_NmtState) =
886                                             kEplNmtGsResetConfiguration;
887                                         break;
888                                 }
889
890                                 // NMT Command StopNode
891                         case kEplNmtEventStopNode:
892                                 {
893                                         EPL_MCO_GLB_VAR(m_NmtState) =
894                                             kEplNmtCsStopped;
895                                         break;
896                                 }
897
898                                 // error occured
899                         case kEplNmtEventNmtCycleError:
900                                 {
901                                         EPL_MCO_GLB_VAR(m_NmtState) =
902                                             kEplNmtCsPreOperational1;
903                                         break;
904                                 }
905
906                                 // NMT Command StartNode
907                         case kEplNmtEventStartNode:
908                                 {
909                                         EPL_MCO_GLB_VAR(m_NmtState) =
910                                             kEplNmtCsOperational;
911                                         break;
912                                 }
913
914                         default:
915                                 {
916                                         break;
917                                 }
918
919                         }       // end of switch(NmtEvent)
920                         break;
921                 }
922
923                 // normal work state
924         case kEplNmtCsOperational:
925                 {
926
927                         // check events
928                         switch (NmtEvent) {
929                                 // NMT Command SwitchOff
930                         case kEplNmtEventCriticalError:
931                         case kEplNmtEventSwitchOff:
932                                 {
933                                         EPL_MCO_GLB_VAR(m_NmtState) =
934                                             kEplNmtGsOff;
935                                         break;
936                                 }
937
938                                 // NMT Command SwReset
939                         case kEplNmtEventSwReset:
940                                 {
941                                         EPL_MCO_GLB_VAR(m_NmtState) =
942                                             kEplNmtGsInitialising;
943                                         break;
944                                 }
945
946                                 // NMT Command ResetNode
947                         case kEplNmtEventResetNode:
948                                 {
949                                         EPL_MCO_GLB_VAR(m_NmtState) =
950                                             kEplNmtGsResetApplication;
951                                         break;
952                                 }
953
954                                 // NMT Command ResetCommunication
955                                 // or internal Communication error
956                         case kEplNmtEventResetCom:
957                         case kEplNmtEventInternComError:
958                                 {
959                                         EPL_MCO_GLB_VAR(m_NmtState) =
960                                             kEplNmtGsResetCommunication;
961                                         break;
962                                 }
963
964                                 // NMT Command ResetConfiguration
965                         case kEplNmtEventResetConfig:
966                                 {
967                                         EPL_MCO_GLB_VAR(m_NmtState) =
968                                             kEplNmtGsResetConfiguration;
969                                         break;
970                                 }
971
972                                 // NMT Command StopNode
973                         case kEplNmtEventStopNode:
974                                 {
975                                         EPL_MCO_GLB_VAR(m_NmtState) =
976                                             kEplNmtCsStopped;
977                                         break;
978                                 }
979
980                                 // NMT Command EnterPreOperational2
981                         case kEplNmtEventEnterPreOperational2:
982                                 {
983                                         EPL_MCO_GLB_VAR(m_NmtState) =
984                                             kEplNmtCsPreOperational2;
985                                         break;
986                                 }
987
988                                 // error occured
989                         case kEplNmtEventNmtCycleError:
990                                 {
991                                         EPL_MCO_GLB_VAR(m_NmtState) =
992                                             kEplNmtCsPreOperational1;
993                                         break;
994                                 }
995
996                         default:
997                                 {
998                                         break;
999                                 }
1000
1001                         }       // end of switch(NmtEvent)
1002                         break;
1003                 }
1004
1005                 // node stopped by MN
1006                 // -> only process asynchronous frames
1007         case kEplNmtCsStopped:
1008                 {
1009                         // check events
1010                         switch (NmtEvent) {
1011                                 // NMT Command SwitchOff
1012                         case kEplNmtEventCriticalError:
1013                         case kEplNmtEventSwitchOff:
1014                                 {
1015                                         EPL_MCO_GLB_VAR(m_NmtState) =
1016                                             kEplNmtGsOff;
1017                                         break;
1018                                 }
1019
1020                                 // NMT Command SwReset
1021                         case kEplNmtEventSwReset:
1022                                 {
1023                                         EPL_MCO_GLB_VAR(m_NmtState) =
1024                                             kEplNmtGsInitialising;
1025                                         break;
1026                                 }
1027
1028                                 // NMT Command ResetNode
1029                         case kEplNmtEventResetNode:
1030                                 {
1031                                         EPL_MCO_GLB_VAR(m_NmtState) =
1032                                             kEplNmtGsResetApplication;
1033                                         break;
1034                                 }
1035
1036                                 // NMT Command ResetCommunication
1037                                 // or internal Communication error
1038                         case kEplNmtEventResetCom:
1039                         case kEplNmtEventInternComError:
1040                                 {
1041                                         EPL_MCO_GLB_VAR(m_NmtState) =
1042                                             kEplNmtGsResetCommunication;
1043                                         break;
1044                                 }
1045
1046                                 // NMT Command ResetConfiguration
1047                         case kEplNmtEventResetConfig:
1048                                 {
1049                                         EPL_MCO_GLB_VAR(m_NmtState) =
1050                                             kEplNmtGsResetConfiguration;
1051                                         break;
1052                                 }
1053
1054                                 // NMT Command EnterPreOperational2
1055                         case kEplNmtEventEnterPreOperational2:
1056                                 {
1057                                         EPL_MCO_GLB_VAR(m_NmtState) =
1058                                             kEplNmtCsPreOperational2;
1059                                         break;
1060                                 }
1061
1062                                 // error occured
1063                         case kEplNmtEventNmtCycleError:
1064                                 {
1065                                         EPL_MCO_GLB_VAR(m_NmtState) =
1066                                             kEplNmtCsPreOperational1;
1067                                         break;
1068                                 }
1069
1070                         default:
1071                                 {
1072                                         break;
1073                                 }
1074
1075                         }       // end of switch(NmtEvent)
1076                         break;
1077                 }
1078
1079                 // no epl cycle
1080                 // -> normal ethernet communication
1081         case kEplNmtCsBasicEthernet:
1082                 {
1083                         // check events
1084                         switch (NmtEvent) {
1085                                 // NMT Command SwitchOff
1086                         case kEplNmtEventCriticalError:
1087                         case kEplNmtEventSwitchOff:
1088                                 {
1089                                         EPL_MCO_GLB_VAR(m_NmtState) =
1090                                             kEplNmtGsOff;
1091                                         break;
1092                                 }
1093
1094                                 // NMT Command SwReset
1095                         case kEplNmtEventSwReset:
1096                                 {
1097                                         EPL_MCO_GLB_VAR(m_NmtState) =
1098                                             kEplNmtGsInitialising;
1099                                         break;
1100                                 }
1101
1102                                 // NMT Command ResetNode
1103                         case kEplNmtEventResetNode:
1104                                 {
1105                                         EPL_MCO_GLB_VAR(m_NmtState) =
1106                                             kEplNmtGsResetApplication;
1107                                         break;
1108                                 }
1109
1110                                 // NMT Command ResetCommunication
1111                                 // or internal Communication error
1112                         case kEplNmtEventResetCom:
1113                         case kEplNmtEventInternComError:
1114                                 {
1115                                         EPL_MCO_GLB_VAR(m_NmtState) =
1116                                             kEplNmtGsResetCommunication;
1117                                         break;
1118                                 }
1119
1120                                 // NMT Command ResetConfiguration
1121                         case kEplNmtEventResetConfig:
1122                                 {
1123                                         EPL_MCO_GLB_VAR(m_NmtState) =
1124                                             kEplNmtGsResetConfiguration;
1125                                         break;
1126                                 }
1127
1128                                 // error occured
1129                                 // d.k.: how does this error occur? on CRC errors
1130 /*                case kEplNmtEventNmtCycleError:
1131                 {
1132                     EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtCsPreOperational1;
1133                     break;
1134                 }
1135 */
1136                         case kEplNmtEventDllCeSoc:
1137                         case kEplNmtEventDllCePreq:
1138                         case kEplNmtEventDllCePres:
1139                         case kEplNmtEventDllCeSoa:
1140                                 {       // Epl-Frame on net -> stop any communication
1141                                         EPL_MCO_GLB_VAR(m_NmtState) =
1142                                             kEplNmtCsPreOperational1;
1143                                         break;
1144                                 }
1145
1146                         default:
1147                                 {
1148                                         break;
1149                                 }
1150
1151                         }       // end of switch(NmtEvent)
1152
1153                         break;
1154                 }
1155
1156                 //-----------------------------------------------------------
1157                 // MN part of the statemaschine
1158
1159                 // MN listen to network
1160                 // -> if no EPL traffic go to next state
1161         case kEplNmtMsNotActive:
1162                 {
1163 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) == 0)
1164                         // no MN functionality
1165                         // TODO: -create error E_NMT_BA1_NO_MN_SUPPORT
1166                         EPL_MCO_GLB_VAR(m_fFrozen) = TRUE;
1167 #else
1168
1169                         // check events
1170                         switch (NmtEvent) {
1171                                 // NMT Command SwitchOff
1172                         case kEplNmtEventCriticalError:
1173                         case kEplNmtEventSwitchOff:
1174                                 {
1175                                         EPL_MCO_GLB_VAR(m_NmtState) =
1176                                             kEplNmtGsOff;
1177                                         break;
1178                                 }
1179
1180                                 // NMT Command SwReset
1181                         case kEplNmtEventSwReset:
1182                                 {
1183                                         EPL_MCO_GLB_VAR(m_NmtState) =
1184                                             kEplNmtGsInitialising;
1185                                         break;
1186                                 }
1187
1188                                 // NMT Command ResetNode
1189                         case kEplNmtEventResetNode:
1190                                 {
1191                                         EPL_MCO_GLB_VAR(m_NmtState) =
1192                                             kEplNmtGsResetApplication;
1193                                         break;
1194                                 }
1195
1196                                 // NMT Command ResetCommunication
1197                                 // or internal Communication error
1198                         case kEplNmtEventResetCom:
1199                         case kEplNmtEventInternComError:
1200                                 {
1201                                         EPL_MCO_GLB_VAR(m_NmtState) =
1202                                             kEplNmtGsResetCommunication;
1203                                         break;
1204                                 }
1205
1206                                 // NMT Command ResetConfiguration
1207                         case kEplNmtEventResetConfig:
1208                                 {
1209                                         EPL_MCO_GLB_VAR(m_NmtState) =
1210                                             kEplNmtGsResetConfiguration;
1211                                         break;
1212                                 }
1213
1214                                 // EPL frames received
1215                         case kEplNmtEventDllCeSoc:
1216                         case kEplNmtEventDllCeSoa:
1217                                 {       // other MN in network
1218                                         // $$$ d.k.: generate error history entry
1219                                         EPL_MCO_GLB_VAR(m_fFrozen) = TRUE;
1220                                         break;
1221                                 }
1222
1223                                 // timeout event
1224                         case kEplNmtEventTimerBasicEthernet:
1225                                 {
1226                                         if (EPL_MCO_GLB_VAR(m_fFrozen) == FALSE) {      // new state BasicEthernet
1227                                                 EPL_MCO_GLB_VAR(m_NmtState) =
1228                                                     kEplNmtMsBasicEthernet;
1229                                         }
1230                                         break;
1231                                 }
1232
1233                                 // timeout event
1234                         case kEplNmtEventTimerMsPreOp1:
1235                                 {
1236                                         if (EPL_MCO_GLB_VAR(m_fFrozen) == FALSE) {      // new state PreOp1
1237                                                 EPL_MCO_GLB_VAR(m_NmtState) =
1238                                                     kEplNmtMsPreOperational1;
1239                                                 EPL_MCO_GLB_VAR
1240                                                     (m_fTimerMsPreOp2) = FALSE;
1241                                                 EPL_MCO_GLB_VAR
1242                                                     (m_fAllMandatoryCNIdent) =
1243                                                     FALSE;
1244
1245                                         }
1246                                         break;
1247                                 }
1248
1249                         default:
1250                                 {
1251                                         break;
1252                                 }
1253
1254                         }       // end of switch(NmtEvent)
1255
1256 #endif // ((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) == 0)
1257
1258                         break;
1259                 }
1260 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
1261                 // MN process reduces epl cycle
1262         case kEplNmtMsPreOperational1:
1263                 {
1264                         // check events
1265                         switch (NmtEvent) {
1266                                 // NMT Command SwitchOff
1267                         case kEplNmtEventCriticalError:
1268                         case kEplNmtEventSwitchOff:
1269                                 {
1270                                         EPL_MCO_GLB_VAR(m_NmtState) =
1271                                             kEplNmtGsOff;
1272                                         break;
1273                                 }
1274
1275                                 // NMT Command SwReset
1276                         case kEplNmtEventSwReset:
1277                                 {
1278                                         EPL_MCO_GLB_VAR(m_NmtState) =
1279                                             kEplNmtGsInitialising;
1280                                         break;
1281                                 }
1282
1283                                 // NMT Command ResetNode
1284                         case kEplNmtEventResetNode:
1285                                 {
1286                                         EPL_MCO_GLB_VAR(m_NmtState) =
1287                                             kEplNmtGsResetApplication;
1288                                         break;
1289                                 }
1290
1291                                 // NMT Command ResetCommunication
1292                                 // or internal Communication error
1293                         case kEplNmtEventResetCom:
1294                         case kEplNmtEventInternComError:
1295                                 {
1296                                         EPL_MCO_GLB_VAR(m_NmtState) =
1297                                             kEplNmtGsResetCommunication;
1298                                         break;
1299                                 }
1300
1301                                 // NMT Command ResetConfiguration
1302                         case kEplNmtEventResetConfig:
1303                                 {
1304                                         EPL_MCO_GLB_VAR(m_NmtState) =
1305                                             kEplNmtGsResetConfiguration;
1306                                         break;
1307                                 }
1308
1309                                 // EPL frames received
1310                         case kEplNmtEventDllCeSoc:
1311                         case kEplNmtEventDllCeSoa:
1312                                 {       // other MN in network
1313                                         // $$$ d.k.: generate error history entry
1314                                         EPL_MCO_GLB_VAR(m_NmtState) =
1315                                             kEplNmtGsResetCommunication;
1316                                         break;
1317                                 }
1318
1319                                 // error occured
1320                                 // d.k. MSPreOp1->CSPreOp1: nonsense -> keep state
1321                                 /*
1322                                    case kEplNmtEventNmtCycleError:
1323                                    {
1324                                    EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtCsPreOperational1;
1325                                    break;
1326                                    }
1327                                  */
1328
1329                         case kEplNmtEventAllMandatoryCNIdent:
1330                                 {       // all mandatory CN identified
1331                                         if (EPL_MCO_GLB_VAR(m_fTimerMsPreOp2) !=
1332                                             FALSE) {
1333                                                 EPL_MCO_GLB_VAR(m_NmtState) =
1334                                                     kEplNmtMsPreOperational2;
1335                                         } else {
1336                                                 EPL_MCO_GLB_VAR
1337                                                     (m_fAllMandatoryCNIdent) =
1338                                                     TRUE;
1339                                         }
1340                                         break;
1341                                 }
1342
1343                         case kEplNmtEventTimerMsPreOp2:
1344                                 {       // residence time for PreOp1 is elapsed
1345                                         if (EPL_MCO_GLB_VAR
1346                                             (m_fAllMandatoryCNIdent) != FALSE) {
1347                                                 EPL_MCO_GLB_VAR(m_NmtState) =
1348                                                     kEplNmtMsPreOperational2;
1349                                         } else {
1350                                                 EPL_MCO_GLB_VAR
1351                                                     (m_fTimerMsPreOp2) = TRUE;
1352                                         }
1353                                         break;
1354                                 }
1355
1356                         default:
1357                                 {
1358                                         break;
1359                                 }
1360
1361                         }       // end of switch(NmtEvent)
1362                         break;
1363                 }
1364
1365                 // MN process full epl cycle
1366         case kEplNmtMsPreOperational2:
1367                 {
1368                         // check events
1369                         switch (NmtEvent) {
1370                                 // NMT Command SwitchOff
1371                         case kEplNmtEventCriticalError:
1372                         case kEplNmtEventSwitchOff:
1373                                 {
1374                                         EPL_MCO_GLB_VAR(m_NmtState) =
1375                                             kEplNmtGsOff;
1376                                         break;
1377                                 }
1378
1379                                 // NMT Command SwReset
1380                         case kEplNmtEventSwReset:
1381                                 {
1382                                         EPL_MCO_GLB_VAR(m_NmtState) =
1383                                             kEplNmtGsInitialising;
1384                                         break;
1385                                 }
1386
1387                                 // NMT Command ResetNode
1388                         case kEplNmtEventResetNode:
1389                                 {
1390                                         EPL_MCO_GLB_VAR(m_NmtState) =
1391                                             kEplNmtGsResetApplication;
1392                                         break;
1393                                 }
1394
1395                                 // NMT Command ResetCommunication
1396                                 // or internal Communication error
1397                         case kEplNmtEventResetCom:
1398                         case kEplNmtEventInternComError:
1399                                 {
1400                                         EPL_MCO_GLB_VAR(m_NmtState) =
1401                                             kEplNmtGsResetCommunication;
1402                                         break;
1403                                 }
1404
1405                                 // NMT Command ResetConfiguration
1406                         case kEplNmtEventResetConfig:
1407                                 {
1408                                         EPL_MCO_GLB_VAR(m_NmtState) =
1409                                             kEplNmtGsResetConfiguration;
1410                                         break;
1411                                 }
1412
1413                                 // EPL frames received
1414                         case kEplNmtEventDllCeSoc:
1415                         case kEplNmtEventDllCeSoa:
1416                                 {       // other MN in network
1417                                         // $$$ d.k.: generate error history entry
1418                                         EPL_MCO_GLB_VAR(m_NmtState) =
1419                                             kEplNmtGsResetCommunication;
1420                                         break;
1421                                 }
1422
1423                                 // error occured
1424                         case kEplNmtEventNmtCycleError:
1425                                 {
1426                                         EPL_MCO_GLB_VAR(m_NmtState) =
1427                                             kEplNmtMsPreOperational1;
1428                                         break;
1429                                 }
1430
1431                         case kEplNmtEventEnterReadyToOperate:
1432                                 {
1433                                         EPL_MCO_GLB_VAR(m_NmtState) =
1434                                             kEplNmtMsReadyToOperate;
1435                                         break;
1436                                 }
1437
1438                         default:
1439                                 {
1440                                         break;
1441                                 }
1442
1443                         }       // end of switch(NmtEvent)
1444
1445                         break;
1446                 }
1447
1448                 // all madatory nodes ready to operate
1449                 // -> MN process full epl cycle
1450         case kEplNmtMsReadyToOperate:
1451                 {
1452
1453                         // check events
1454                         switch (NmtEvent) {
1455                                 // NMT Command SwitchOff
1456                         case kEplNmtEventCriticalError:
1457                         case kEplNmtEventSwitchOff:
1458                                 {
1459                                         EPL_MCO_GLB_VAR(m_NmtState) =
1460                                             kEplNmtGsOff;
1461                                         break;
1462                                 }
1463
1464                                 // NMT Command SwReset
1465                         case kEplNmtEventSwReset:
1466                                 {
1467                                         EPL_MCO_GLB_VAR(m_NmtState) =
1468                                             kEplNmtGsInitialising;
1469                                         break;
1470                                 }
1471
1472                                 // NMT Command ResetNode
1473                         case kEplNmtEventResetNode:
1474                                 {
1475                                         EPL_MCO_GLB_VAR(m_NmtState) =
1476                                             kEplNmtGsResetApplication;
1477                                         break;
1478                                 }
1479
1480                                 // NMT Command ResetCommunication
1481                                 // or internal Communication error
1482                         case kEplNmtEventResetCom:
1483                         case kEplNmtEventInternComError:
1484                                 {
1485                                         EPL_MCO_GLB_VAR(m_NmtState) =
1486                                             kEplNmtGsResetCommunication;
1487                                         break;
1488                                 }
1489
1490                                 // NMT Command ResetConfiguration
1491                         case kEplNmtEventResetConfig:
1492                                 {
1493                                         EPL_MCO_GLB_VAR(m_NmtState) =
1494                                             kEplNmtGsResetConfiguration;
1495                                         break;
1496                                 }
1497
1498                                 // EPL frames received
1499                         case kEplNmtEventDllCeSoc:
1500                         case kEplNmtEventDllCeSoa:
1501                                 {       // other MN in network
1502                                         // $$$ d.k.: generate error history entry
1503                                         EPL_MCO_GLB_VAR(m_NmtState) =
1504                                             kEplNmtGsResetCommunication;
1505                                         break;
1506                                 }
1507
1508                                 // error occured
1509                         case kEplNmtEventNmtCycleError:
1510                                 {
1511                                         EPL_MCO_GLB_VAR(m_NmtState) =
1512                                             kEplNmtMsPreOperational1;
1513                                         break;
1514                                 }
1515
1516                         case kEplNmtEventEnterMsOperational:
1517                                 {
1518                                         EPL_MCO_GLB_VAR(m_NmtState) =
1519                                             kEplNmtMsOperational;
1520                                         break;
1521                                 }
1522
1523                         default:
1524                                 {
1525                                         break;
1526                                 }
1527
1528                         }       // end of switch(NmtEvent)
1529
1530                         break;
1531                 }
1532
1533                 // normal eplcycle processing
1534         case kEplNmtMsOperational:
1535                 {
1536                         // check events
1537                         switch (NmtEvent) {
1538                                 // NMT Command SwitchOff
1539                         case kEplNmtEventCriticalError:
1540                         case kEplNmtEventSwitchOff:
1541                                 {
1542                                         EPL_MCO_GLB_VAR(m_NmtState) =
1543                                             kEplNmtGsOff;
1544                                         break;
1545                                 }
1546
1547                                 // NMT Command SwReset
1548                         case kEplNmtEventSwReset:
1549                                 {
1550                                         EPL_MCO_GLB_VAR(m_NmtState) =
1551                                             kEplNmtGsInitialising;
1552                                         break;
1553                                 }
1554
1555                                 // NMT Command ResetNode
1556                         case kEplNmtEventResetNode:
1557                                 {
1558                                         EPL_MCO_GLB_VAR(m_NmtState) =
1559                                             kEplNmtGsResetApplication;
1560                                         break;
1561                                 }
1562
1563                                 // NMT Command ResetCommunication
1564                                 // or internal Communication error
1565                         case kEplNmtEventResetCom:
1566                         case kEplNmtEventInternComError:
1567                                 {
1568                                         EPL_MCO_GLB_VAR(m_NmtState) =
1569                                             kEplNmtGsResetCommunication;
1570                                         break;
1571                                 }
1572
1573                                 // NMT Command ResetConfiguration
1574                         case kEplNmtEventResetConfig:
1575                                 {
1576                                         EPL_MCO_GLB_VAR(m_NmtState) =
1577                                             kEplNmtGsResetConfiguration;
1578                                         break;
1579                                 }
1580
1581                                 // EPL frames received
1582                         case kEplNmtEventDllCeSoc:
1583                         case kEplNmtEventDllCeSoa:
1584                                 {       // other MN in network
1585                                         // $$$ d.k.: generate error history entry
1586                                         EPL_MCO_GLB_VAR(m_NmtState) =
1587                                             kEplNmtGsResetCommunication;
1588                                         break;
1589                                 }
1590
1591                                 // error occured
1592                         case kEplNmtEventNmtCycleError:
1593                                 {
1594                                         EPL_MCO_GLB_VAR(m_NmtState) =
1595                                             kEplNmtMsPreOperational1;
1596                                         break;
1597                                 }
1598
1599                         default:
1600                                 {
1601                                         break;
1602                                 }
1603
1604                         }       // end of switch(NmtEvent)
1605                         break;
1606                 }
1607
1608                 //  normal ethernet traffic
1609         case kEplNmtMsBasicEthernet:
1610                 {
1611
1612                         // check events
1613                         switch (NmtEvent) {
1614                                 // NMT Command SwitchOff
1615                         case kEplNmtEventCriticalError:
1616                         case kEplNmtEventSwitchOff:
1617                                 {
1618                                         EPL_MCO_GLB_VAR(m_NmtState) =
1619                                             kEplNmtGsOff;
1620                                         break;
1621                                 }
1622
1623                                 // NMT Command SwReset
1624                         case kEplNmtEventSwReset:
1625                                 {
1626                                         EPL_MCO_GLB_VAR(m_NmtState) =
1627                                             kEplNmtGsInitialising;
1628                                         break;
1629                                 }
1630
1631                                 // NMT Command ResetNode
1632                         case kEplNmtEventResetNode:
1633                                 {
1634                                         EPL_MCO_GLB_VAR(m_NmtState) =
1635                                             kEplNmtGsResetApplication;
1636                                         break;
1637                                 }
1638
1639                                 // NMT Command ResetCommunication
1640                                 // or internal Communication error
1641                         case kEplNmtEventResetCom:
1642                         case kEplNmtEventInternComError:
1643                                 {
1644                                         EPL_MCO_GLB_VAR(m_NmtState) =
1645                                             kEplNmtGsResetCommunication;
1646                                         break;
1647                                 }
1648
1649                                 // NMT Command ResetConfiguration
1650                         case kEplNmtEventResetConfig:
1651                                 {
1652                                         EPL_MCO_GLB_VAR(m_NmtState) =
1653                                             kEplNmtGsResetConfiguration;
1654                                         break;
1655                                 }
1656
1657                                 // EPL frames received
1658                         case kEplNmtEventDllCeSoc:
1659                         case kEplNmtEventDllCeSoa:
1660                                 {       // other MN in network
1661                                         // $$$ d.k.: generate error history entry
1662                                         EPL_MCO_GLB_VAR(m_NmtState) =
1663                                             kEplNmtGsResetCommunication;
1664                                         break;
1665                                 }
1666
1667                                 // error occured
1668                                 // d.k. BE->PreOp1 on cycle error? No
1669 /*                case kEplNmtEventNmtCycleError:
1670                 {
1671                     EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtCsPreOperational1;
1672                     break;
1673                 }
1674 */
1675                         default:
1676                                 {
1677                                         break;
1678                                 }
1679
1680                         }       // end of switch(NmtEvent)
1681                         break;
1682                 }
1683 #endif //#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
1684
1685         default:
1686                 {
1687                         //DEBUG_EPL_DBGLVL_NMTK_TRACE0(EPL_DBGLVL_NMT ,"Error in EplNmtProcess: Unknown NMT-State");
1688                         //EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtGsResetApplication;
1689                         Ret = kEplNmtInvalidState;
1690                         goto Exit;
1691                 }
1692
1693         }                       // end of switch(NmtEvent)
1694
1695         // inform higher layer about State-Change if needed
1696         if (OldNmtState != EPL_MCO_GLB_VAR(m_NmtState)) {
1697                 EPL_NMTK_DBG_POST_TRACE_VALUE(NmtEvent, OldNmtState,
1698                                               EPL_MCO_GLB_VAR(m_NmtState));
1699
1700                 // d.k.: memorize NMT state before posting any events
1701                 NmtStateChange.m_NewNmtState = EPL_MCO_GLB_VAR(m_NmtState);
1702
1703                 // inform DLL
1704                 if ((OldNmtState > kEplNmtGsResetConfiguration)
1705                     && (EPL_MCO_GLB_VAR(m_NmtState) <=
1706                         kEplNmtGsResetConfiguration)) {
1707                         // send DLL DEINIT
1708                         Event.m_EventSink = kEplEventSinkDllk;
1709                         Event.m_EventType = kEplEventTypeDllkDestroy;
1710                         EPL_MEMSET(&Event.m_NetTime, 0x00,
1711                                    sizeof(Event.m_NetTime));
1712                         Event.m_pArg = &OldNmtState;
1713                         Event.m_uiSize = sizeof(OldNmtState);
1714                         // d.k.: directly call DLLk process function, because
1715                         //       1. execution of process function is still synchonized and serialized,
1716                         //       2. it is the same as without event queues (i.e. well tested),
1717                         //       3. DLLk will get those necessary events even if event queue is full,
1718                         //       4. event queue is very inefficient
1719 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
1720                         Ret = EplDllkProcess(&Event);
1721 #else
1722                         Ret = EplEventkPost(&Event);
1723 #endif
1724                 } else if ((OldNmtState <= kEplNmtGsResetConfiguration)
1725                            && (EPL_MCO_GLB_VAR(m_NmtState) >
1726                                kEplNmtGsResetConfiguration)) {
1727                         // send DLL INIT
1728                         Event.m_EventSink = kEplEventSinkDllk;
1729                         Event.m_EventType = kEplEventTypeDllkCreate;
1730                         EPL_MEMSET(&Event.m_NetTime, 0x00,
1731                                    sizeof(Event.m_NetTime));
1732                         Event.m_pArg = &NmtStateChange.m_NewNmtState;
1733                         Event.m_uiSize = sizeof(NmtStateChange.m_NewNmtState);
1734                         // d.k.: directly call DLLk process function, because
1735                         //       1. execution of process function is still synchonized and serialized,
1736                         //       2. it is the same as without event queues (i.e. well tested),
1737                         //       3. DLLk will get those necessary events even if event queue is full
1738                         //       4. event queue is very inefficient
1739 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
1740                         Ret = EplDllkProcess(&Event);
1741 #else
1742                         Ret = EplEventkPost(&Event);
1743 #endif
1744                 } else
1745                     if ((EPL_MCO_GLB_VAR(m_NmtState) == kEplNmtCsBasicEthernet)
1746                         || (EPL_MCO_GLB_VAR(m_NmtState) ==
1747                             kEplNmtMsBasicEthernet)) {
1748                         tEplDllAsyncReqPriority AsyncReqPriority;
1749
1750                         // send DLL Fill Async Tx Buffer, because state BasicEthernet was entered
1751                         Event.m_EventSink = kEplEventSinkDllk;
1752                         Event.m_EventType = kEplEventTypeDllkFillTx;
1753                         EPL_MEMSET(&Event.m_NetTime, 0x00,
1754                                    sizeof(Event.m_NetTime));
1755                         AsyncReqPriority = kEplDllAsyncReqPrioGeneric;
1756                         Event.m_pArg = &AsyncReqPriority;
1757                         Event.m_uiSize = sizeof(AsyncReqPriority);
1758                         // d.k.: directly call DLLk process function, because
1759                         //       1. execution of process function is still synchonized and serialized,
1760                         //       2. it is the same as without event queues (i.e. well tested),
1761                         //       3. DLLk will get those necessary events even if event queue is full
1762                         //       4. event queue is very inefficient
1763 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
1764                         Ret = EplDllkProcess(&Event);
1765 #else
1766                         Ret = EplEventkPost(&Event);
1767 #endif
1768                 }
1769                 // inform higher layer about state change
1770                 NmtStateChange.m_NmtEvent = NmtEvent;
1771                 Event.m_EventSink = kEplEventSinkNmtu;
1772                 Event.m_EventType = kEplEventTypeNmtStateChange;
1773                 EPL_MEMSET(&Event.m_NetTime, 0x00, sizeof(Event.m_NetTime));
1774                 Event.m_pArg = &NmtStateChange;
1775                 Event.m_uiSize = sizeof(NmtStateChange);
1776                 Ret = EplEventkPost(&Event);
1777                 EPL_DBGLVL_NMTK_TRACE2
1778                     ("EplNmtkProcess(NMT-Event = 0x%04X): New NMT-State = 0x%03X\n",
1779                      NmtEvent, NmtStateChange.m_NewNmtState);
1780
1781         }
1782
1783       Exit:
1784
1785         return Ret;
1786 }
1787
1788 //---------------------------------------------------------------------------
1789 //
1790 // Function:    EplNmtkGetNmtState
1791 //
1792 // Description: return the actuell NMT-State and the bits
1793 //              to for MN- or CN-mode
1794 //
1795 //
1796 //
1797 // Parameters:  EPL_MCO_DECL_PTR_INSTANCE_PTR_ = Instancepointer
1798 //
1799 //
1800 // Returns:     tEplNmtState = NMT-State
1801 //
1802 //
1803 // State:
1804 //
1805 //---------------------------------------------------------------------------
1806 tEplNmtState EplNmtkGetNmtState(EPL_MCO_DECL_PTR_INSTANCE_PTR)
1807 {
1808         tEplNmtState NmtState;
1809
1810         NmtState = EPL_MCO_GLB_VAR(m_NmtState);
1811
1812         return NmtState;
1813
1814 }
1815
1816 //=========================================================================//
1817 //                                                                         //
1818 //          P R I V A T E   D E F I N I T I O N S                          //
1819 //                                                                         //
1820 //=========================================================================//
1821 EPL_MCO_DECL_INSTANCE_FCT()
1822 //---------------------------------------------------------------------------
1823 //
1824 // Function:
1825 //
1826 // Description:
1827 //
1828 //
1829 //
1830 // Parameters:
1831 //
1832 //
1833 // Returns:
1834 //
1835 //
1836 // State:
1837 //
1838 //---------------------------------------------------------------------------
1839 #endif // #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
1840 // EOF