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