1 /****************************************************************************
3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4 www.systec-electronic.com
8 Description: source file for NMT-Kernelspace-Module
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
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.
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.
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.
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.
50 -------------------------------------------------------------------------
52 $RCSfile: EplNmtk.c,v $
56 $Revision: 1.12 $ $Date: 2008/11/13 17:13:09 $
63 -------------------------------------------------------------------------
67 2006/06/09 k.t.: start of the implementation
69 ****************************************************************************/
71 #include "kernel/EplNmtk.h"
72 #include "kernel/EplTimerk.h"
74 #include "kernel/EplDllk.h" // for EplDllkProcess()
76 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
77 /***************************************************************************/
80 /* G L O B A L D E F I N I T I O N S */
83 /***************************************************************************/
85 //---------------------------------------------------------------------------
87 //---------------------------------------------------------------------------
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)
96 #define TGT_DBG_SIGNAL_TRACE_POINT(p)
97 #define TGT_DBG_POST_TRACE_VALUE(v)
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))
104 //---------------------------------------------------------------------------
106 //---------------------------------------------------------------------------
107 // struct for instance table
108 INSTANCE_TYPE_BEGIN EPL_MCO_DECL_INSTANCE_MEMBER()
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;
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()
131 /***************************************************************************/
134 /* C L A S S <NMT_Kernel-Module> */
137 /***************************************************************************/
139 // Description: This module realize the NMT-State-Machine of the EPL-Stack
142 /***************************************************************************/
143 //=========================================================================//
145 // P U B L I C F U N C T I O N S //
147 //=========================================================================//
148 //---------------------------------------------------------------------------
150 // Function: EplNmtkInit
152 // Description: initializes the first instance
156 // Parameters: EPL_MCO_DECL_PTR_INSTANCE_PTR = Instance pointer
157 // uiNodeId_p = Node Id of the lokal node
160 // Returns: tEplKernel = Errorcode
165 //---------------------------------------------------------------------------
166 tEplKernel EplNmtkInit(EPL_MCO_DECL_PTR_INSTANCE_PTR)
170 Ret = EplNmtkAddInstance(EPL_MCO_PTR_INSTANCE_PTR);
175 //---------------------------------------------------------------------------
177 // Function: EplNmtkAddInstance
179 // Description: adds a new instance
183 // Parameters: EPL_MCO_DECL_PTR_INSTANCE_PTR = Instance pointer
186 // Returns: tEplKernel = Errorcode
191 //---------------------------------------------------------------------------
192 tEplKernel EplNmtkAddInstance(EPL_MCO_DECL_PTR_INSTANCE_PTR)
194 EPL_MCO_DECL_INSTANCE_PTR_LOCAL tEplKernel Ret;
196 //tEplEventNmtStateChange NmtStateChange;
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();
205 // sign instance as used
206 EPL_MCO_WRITE_INSTANCE_STATE(kStateUsed);
208 Ret = kEplSuccessful;
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;
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;
223 // EPL_MCO_GLB_VAR(m_TimerHdl) = 0;
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
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);
243 //---------------------------------------------------------------------------
245 // Function: EplNmtkDelInstance
247 // Description: delete instance
251 // Parameters: EPL_MCO_DECL_PTR_INSTANCE_PTR = Instance pointer
254 // Returns: tEplKernel = Errorcode
259 //---------------------------------------------------------------------------
260 #if (EPL_USE_DELETEINST_FUNC != FALSE)
261 tEplKernel EplNmtkDelInstance(EPL_MCO_DECL_PTR_INSTANCE_PTR)
263 tEplKernel Ret = kEplSuccessful;
264 // check for all API function if instance is valid
265 EPL_MCO_CHECK_INSTANCE_STATE();
267 // set NMT-State to kEplNmtGsOff
268 EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtGsOff;
270 // sign instance as unused
271 EPL_MCO_WRITE_INSTANCE_STATE(kStateUnused);
274 // Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
278 #endif // (EPL_USE_DELETEINST_FUNC != FALSE)
280 //---------------------------------------------------------------------------
282 // Function: EplNmtkProcess
284 // Description: main process function
285 // -> process NMT-State-Maschine und read NMT-Events from Queue
289 // Parameters: EPL_MCO_DECL_PTR_INSTANCE_PTR_ = Instance pointer
290 // pEvent_p = Epl-Event with NMT-event to process
293 // Returns: tEplKernel = Errorcode
298 //---------------------------------------------------------------------------
299 tEplKernel EplNmtkProcess(EPL_MCO_DECL_PTR_INSTANCE_PTR_ tEplEvent *pEvent_p)
302 tEplNmtState OldNmtState;
303 tEplNmtEvent NmtEvent;
305 tEplEventNmtStateChange NmtStateChange;
307 // check for all API function if instance is valid
308 EPL_MCO_CHECK_INSTANCE_STATE();
310 Ret = kEplSuccessful;
312 switch (pEvent_p->m_EventType) {
313 case kEplEventTypeNmtEvent:
315 NmtEvent = *((tEplNmtEvent *) pEvent_p->m_pArg);
319 case kEplEventTypeTimer:
322 (tEplNmtEvent) ((tEplTimerEventArg *) pEvent_p->
328 Ret = kEplNmtInvalidEvent;
334 // needed for later comparison to
335 // inform hgher layer about state change
336 OldNmtState = EPL_MCO_GLB_VAR(m_NmtState);
338 // NMT-State-Maschine
339 switch (EPL_MCO_GLB_VAR(m_NmtState)) {
340 //-----------------------------------------------------------
341 // general part of the statemaschine
343 // first init of the hardware
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;
354 // first init of the hardware
355 case kEplNmtGsInitialising:
357 // leave this state only if higher layer says so
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:
366 EPL_MCO_GLB_VAR(m_NmtState) =
371 // new state kEplNmtGsResetApplication
372 case kEplNmtEventEnterResetApp:
374 EPL_MCO_GLB_VAR(m_NmtState) =
375 kEplNmtGsResetApplication;
387 // init of the manufacturer-specific profile area and the
388 // standardised device profile area
389 case kEplNmtGsResetApplication:
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:
398 EPL_MCO_GLB_VAR(m_NmtState) =
403 // NMT Command SwReset
404 case kEplNmtEventSwReset:
406 EPL_MCO_GLB_VAR(m_NmtState) =
407 kEplNmtGsInitialising;
411 // leave this state only if higher layer
413 case kEplNmtEventEnterResetCom:
415 // new state kEplNmtGsResetCommunication
416 EPL_MCO_GLB_VAR(m_NmtState) =
417 kEplNmtGsResetCommunication;
429 // init of the communication profile area
430 case kEplNmtGsResetCommunication:
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:
439 EPL_MCO_GLB_VAR(m_NmtState) =
444 // NMT Command SwReset
445 case kEplNmtEventSwReset:
447 EPL_MCO_GLB_VAR(m_NmtState) =
448 kEplNmtGsInitialising;
452 // NMT Command ResetNode
453 case kEplNmtEventResetNode:
455 EPL_MCO_GLB_VAR(m_NmtState) =
456 kEplNmtGsResetApplication;
460 // leave this state only if higher layer
462 case kEplNmtEventEnterResetConfig:
464 // new state kEplNmtGsResetCommunication
465 EPL_MCO_GLB_VAR(m_NmtState) =
466 kEplNmtGsResetConfiguration;
478 // build the configuration with infos from OD
479 case kEplNmtGsResetConfiguration:
482 EPL_MCO_GLB_VAR(m_fEnableReadyToOperate) = FALSE;
483 EPL_MCO_GLB_VAR(m_fAppReadyToOperate) = FALSE;
484 EPL_MCO_GLB_VAR(m_fFrozen) = FALSE;
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:
493 EPL_MCO_GLB_VAR(m_NmtState) =
498 // NMT Command SwReset
499 case kEplNmtEventSwReset:
501 EPL_MCO_GLB_VAR(m_NmtState) =
502 kEplNmtGsInitialising;
506 // NMT Command ResetNode
507 case kEplNmtEventResetNode:
509 EPL_MCO_GLB_VAR(m_NmtState) =
510 kEplNmtGsResetApplication;
514 // NMT Command ResetCommunication
515 case kEplNmtEventResetCom:
517 EPL_MCO_GLB_VAR(m_NmtState) =
518 kEplNmtGsResetCommunication;
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) =
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;
539 EPL_MCO_GLB_VAR(m_NmtState) =
554 //-----------------------------------------------------------
555 // CN part of the statemaschine
557 // node liste for EPL-Frames and check timeout
558 case kEplNmtCsNotActive:
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:
568 EPL_MCO_GLB_VAR(m_NmtState) =
573 // NMT Command SwReset
574 case kEplNmtEventSwReset:
576 EPL_MCO_GLB_VAR(m_NmtState) =
577 kEplNmtGsInitialising;
578 // Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
582 // NMT Command ResetNode
583 case kEplNmtEventResetNode:
585 EPL_MCO_GLB_VAR(m_NmtState) =
586 kEplNmtGsResetApplication;
587 // Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
591 // NMT Command ResetCommunication
592 // or internal Communication error
593 case kEplNmtEventResetCom:
594 case kEplNmtEventInternComError:
596 EPL_MCO_GLB_VAR(m_NmtState) =
597 kEplNmtGsResetCommunication;
598 // Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
602 // NMT Command Reset Configuration
603 case kEplNmtEventResetConfig:
605 EPL_MCO_GLB_VAR(m_NmtState) =
606 kEplNmtGsResetConfiguration;
607 // Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
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));
622 // timeout for SoA and Soc
623 case kEplNmtEventTimerBasicEthernet:
625 // new state BASIC_ETHERNET
626 EPL_MCO_GLB_VAR(m_NmtState) =
627 kEplNmtCsBasicEthernet;
635 } // end of switch(NmtEvent)
640 // node processes only async frames
641 case kEplNmtCsPreOperational1:
646 // NMT Command SwitchOff
647 case kEplNmtEventCriticalError:
648 case kEplNmtEventSwitchOff:
650 EPL_MCO_GLB_VAR(m_NmtState) =
655 // NMT Command SwReset
656 case kEplNmtEventSwReset:
658 EPL_MCO_GLB_VAR(m_NmtState) =
659 kEplNmtGsInitialising;
663 // NMT Command ResetNode
664 case kEplNmtEventResetNode:
666 EPL_MCO_GLB_VAR(m_NmtState) =
667 kEplNmtGsResetApplication;
671 // NMT Command ResetCommunication
672 // or internal Communication error
673 case kEplNmtEventResetCom:
674 case kEplNmtEventInternComError:
676 EPL_MCO_GLB_VAR(m_NmtState) =
677 kEplNmtGsResetCommunication;
681 // NMT Command Reset Configuration
682 case kEplNmtEventResetConfig:
684 EPL_MCO_GLB_VAR(m_NmtState) =
685 kEplNmtGsResetConfiguration;
689 // NMT Command StopNode
690 case kEplNmtEventStopNode:
692 EPL_MCO_GLB_VAR(m_NmtState) =
697 // check if SoC received
698 case kEplNmtEventDllCeSoc:
700 EPL_MCO_GLB_VAR(m_NmtState) =
701 kEplNmtCsPreOperational2;
710 } // end of switch(NmtEvent)
715 // node processes isochronous and asynchronous frames
716 case kEplNmtCsPreOperational2:
720 // NMT Command SwitchOff
721 case kEplNmtEventCriticalError:
722 case kEplNmtEventSwitchOff:
724 EPL_MCO_GLB_VAR(m_NmtState) =
729 // NMT Command SwReset
730 case kEplNmtEventSwReset:
732 EPL_MCO_GLB_VAR(m_NmtState) =
733 kEplNmtGsInitialising;
737 // NMT Command ResetNode
738 case kEplNmtEventResetNode:
740 EPL_MCO_GLB_VAR(m_NmtState) =
741 kEplNmtGsResetApplication;
745 // NMT Command ResetCommunication
746 // or internal Communication error
747 case kEplNmtEventResetCom:
748 case kEplNmtEventInternComError:
750 EPL_MCO_GLB_VAR(m_NmtState) =
751 kEplNmtGsResetCommunication;
755 // NMT Command Reset Configuration
756 case kEplNmtEventResetConfig:
758 EPL_MCO_GLB_VAR(m_NmtState) =
759 kEplNmtGsResetConfiguration;
763 // NMT Command StopNode
764 case kEplNmtEventStopNode:
767 EPL_MCO_GLB_VAR(m_fEnableReadyToOperate)
769 EPL_MCO_GLB_VAR(m_fAppReadyToOperate) =
771 EPL_MCO_GLB_VAR(m_NmtState) =
777 case kEplNmtEventNmtCycleError:
780 EPL_MCO_GLB_VAR(m_fEnableReadyToOperate)
782 EPL_MCO_GLB_VAR(m_fAppReadyToOperate) =
784 EPL_MCO_GLB_VAR(m_NmtState) =
785 kEplNmtCsPreOperational1;
789 // check if application is ready to operate
790 case kEplNmtEventEnterReadyToOperate:
792 // check if command NMTEnableReadyToOperate from MN was received
793 if (EPL_MCO_GLB_VAR(m_fEnableReadyToOperate) == TRUE) { // reset flags
795 (m_fEnableReadyToOperate) =
798 (m_fAppReadyToOperate) =
801 EPL_MCO_GLB_VAR(m_NmtState) =
802 kEplNmtCsReadyToOperate;
805 (m_fAppReadyToOperate) =
811 // NMT Commando EnableReadyToOperate
812 case kEplNmtEventEnableReadyToOperate:
814 // check if application is ready
815 if (EPL_MCO_GLB_VAR(m_fAppReadyToOperate) == TRUE) { // reset flags
817 (m_fEnableReadyToOperate) =
820 (m_fAppReadyToOperate) =
823 EPL_MCO_GLB_VAR(m_NmtState) =
824 kEplNmtCsReadyToOperate;
827 (m_fEnableReadyToOperate) =
838 } // end of switch(NmtEvent)
842 // node should be configured und application is ready
843 case kEplNmtCsReadyToOperate:
847 // NMT Command SwitchOff
848 case kEplNmtEventCriticalError:
849 case kEplNmtEventSwitchOff:
851 EPL_MCO_GLB_VAR(m_NmtState) =
856 // NMT Command SwReset
857 case kEplNmtEventSwReset:
859 EPL_MCO_GLB_VAR(m_NmtState) =
860 kEplNmtGsInitialising;
864 // NMT Command ResetNode
865 case kEplNmtEventResetNode:
867 EPL_MCO_GLB_VAR(m_NmtState) =
868 kEplNmtGsResetApplication;
872 // NMT Command ResetCommunication
873 // or internal Communication error
874 case kEplNmtEventResetCom:
875 case kEplNmtEventInternComError:
877 EPL_MCO_GLB_VAR(m_NmtState) =
878 kEplNmtGsResetCommunication;
882 // NMT Command ResetConfiguration
883 case kEplNmtEventResetConfig:
885 EPL_MCO_GLB_VAR(m_NmtState) =
886 kEplNmtGsResetConfiguration;
890 // NMT Command StopNode
891 case kEplNmtEventStopNode:
893 EPL_MCO_GLB_VAR(m_NmtState) =
899 case kEplNmtEventNmtCycleError:
901 EPL_MCO_GLB_VAR(m_NmtState) =
902 kEplNmtCsPreOperational1;
906 // NMT Command StartNode
907 case kEplNmtEventStartNode:
909 EPL_MCO_GLB_VAR(m_NmtState) =
910 kEplNmtCsOperational;
919 } // end of switch(NmtEvent)
924 case kEplNmtCsOperational:
929 // NMT Command SwitchOff
930 case kEplNmtEventCriticalError:
931 case kEplNmtEventSwitchOff:
933 EPL_MCO_GLB_VAR(m_NmtState) =
938 // NMT Command SwReset
939 case kEplNmtEventSwReset:
941 EPL_MCO_GLB_VAR(m_NmtState) =
942 kEplNmtGsInitialising;
946 // NMT Command ResetNode
947 case kEplNmtEventResetNode:
949 EPL_MCO_GLB_VAR(m_NmtState) =
950 kEplNmtGsResetApplication;
954 // NMT Command ResetCommunication
955 // or internal Communication error
956 case kEplNmtEventResetCom:
957 case kEplNmtEventInternComError:
959 EPL_MCO_GLB_VAR(m_NmtState) =
960 kEplNmtGsResetCommunication;
964 // NMT Command ResetConfiguration
965 case kEplNmtEventResetConfig:
967 EPL_MCO_GLB_VAR(m_NmtState) =
968 kEplNmtGsResetConfiguration;
972 // NMT Command StopNode
973 case kEplNmtEventStopNode:
975 EPL_MCO_GLB_VAR(m_NmtState) =
980 // NMT Command EnterPreOperational2
981 case kEplNmtEventEnterPreOperational2:
983 EPL_MCO_GLB_VAR(m_NmtState) =
984 kEplNmtCsPreOperational2;
989 case kEplNmtEventNmtCycleError:
991 EPL_MCO_GLB_VAR(m_NmtState) =
992 kEplNmtCsPreOperational1;
1001 } // end of switch(NmtEvent)
1005 // node stopped by MN
1006 // -> only process asynchronous frames
1007 case kEplNmtCsStopped:
1011 // NMT Command SwitchOff
1012 case kEplNmtEventCriticalError:
1013 case kEplNmtEventSwitchOff:
1015 EPL_MCO_GLB_VAR(m_NmtState) =
1020 // NMT Command SwReset
1021 case kEplNmtEventSwReset:
1023 EPL_MCO_GLB_VAR(m_NmtState) =
1024 kEplNmtGsInitialising;
1028 // NMT Command ResetNode
1029 case kEplNmtEventResetNode:
1031 EPL_MCO_GLB_VAR(m_NmtState) =
1032 kEplNmtGsResetApplication;
1036 // NMT Command ResetCommunication
1037 // or internal Communication error
1038 case kEplNmtEventResetCom:
1039 case kEplNmtEventInternComError:
1041 EPL_MCO_GLB_VAR(m_NmtState) =
1042 kEplNmtGsResetCommunication;
1046 // NMT Command ResetConfiguration
1047 case kEplNmtEventResetConfig:
1049 EPL_MCO_GLB_VAR(m_NmtState) =
1050 kEplNmtGsResetConfiguration;
1054 // NMT Command EnterPreOperational2
1055 case kEplNmtEventEnterPreOperational2:
1057 EPL_MCO_GLB_VAR(m_NmtState) =
1058 kEplNmtCsPreOperational2;
1063 case kEplNmtEventNmtCycleError:
1065 EPL_MCO_GLB_VAR(m_NmtState) =
1066 kEplNmtCsPreOperational1;
1075 } // end of switch(NmtEvent)
1080 // -> normal ethernet communication
1081 case kEplNmtCsBasicEthernet:
1085 // NMT Command SwitchOff
1086 case kEplNmtEventCriticalError:
1087 case kEplNmtEventSwitchOff:
1089 EPL_MCO_GLB_VAR(m_NmtState) =
1094 // NMT Command SwReset
1095 case kEplNmtEventSwReset:
1097 EPL_MCO_GLB_VAR(m_NmtState) =
1098 kEplNmtGsInitialising;
1102 // NMT Command ResetNode
1103 case kEplNmtEventResetNode:
1105 EPL_MCO_GLB_VAR(m_NmtState) =
1106 kEplNmtGsResetApplication;
1110 // NMT Command ResetCommunication
1111 // or internal Communication error
1112 case kEplNmtEventResetCom:
1113 case kEplNmtEventInternComError:
1115 EPL_MCO_GLB_VAR(m_NmtState) =
1116 kEplNmtGsResetCommunication;
1120 // NMT Command ResetConfiguration
1121 case kEplNmtEventResetConfig:
1123 EPL_MCO_GLB_VAR(m_NmtState) =
1124 kEplNmtGsResetConfiguration;
1129 // d.k.: how does this error occur? on CRC errors
1130 /* case kEplNmtEventNmtCycleError:
1132 EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtCsPreOperational1;
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;
1151 } // end of switch(NmtEvent)
1156 //-----------------------------------------------------------
1157 // MN part of the statemaschine
1159 // MN listen to network
1160 // -> if no EPL traffic go to next state
1161 case kEplNmtMsNotActive:
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;
1171 // NMT Command SwitchOff
1172 case kEplNmtEventCriticalError:
1173 case kEplNmtEventSwitchOff:
1175 EPL_MCO_GLB_VAR(m_NmtState) =
1180 // NMT Command SwReset
1181 case kEplNmtEventSwReset:
1183 EPL_MCO_GLB_VAR(m_NmtState) =
1184 kEplNmtGsInitialising;
1188 // NMT Command ResetNode
1189 case kEplNmtEventResetNode:
1191 EPL_MCO_GLB_VAR(m_NmtState) =
1192 kEplNmtGsResetApplication;
1196 // NMT Command ResetCommunication
1197 // or internal Communication error
1198 case kEplNmtEventResetCom:
1199 case kEplNmtEventInternComError:
1201 EPL_MCO_GLB_VAR(m_NmtState) =
1202 kEplNmtGsResetCommunication;
1206 // NMT Command ResetConfiguration
1207 case kEplNmtEventResetConfig:
1209 EPL_MCO_GLB_VAR(m_NmtState) =
1210 kEplNmtGsResetConfiguration;
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;
1224 case kEplNmtEventTimerBasicEthernet:
1226 if (EPL_MCO_GLB_VAR(m_fFrozen) == FALSE) { // new state BasicEthernet
1227 EPL_MCO_GLB_VAR(m_NmtState) =
1228 kEplNmtMsBasicEthernet;
1234 case kEplNmtEventTimerMsPreOp1:
1236 if (EPL_MCO_GLB_VAR(m_fFrozen) == FALSE) { // new state PreOp1
1237 EPL_MCO_GLB_VAR(m_NmtState) =
1238 kEplNmtMsPreOperational1;
1240 (m_fTimerMsPreOp2) = FALSE;
1242 (m_fAllMandatoryCNIdent) =
1254 } // end of switch(NmtEvent)
1256 #endif // ((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) == 0)
1260 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
1261 // MN process reduces epl cycle
1262 case kEplNmtMsPreOperational1:
1266 // NMT Command SwitchOff
1267 case kEplNmtEventCriticalError:
1268 case kEplNmtEventSwitchOff:
1270 EPL_MCO_GLB_VAR(m_NmtState) =
1275 // NMT Command SwReset
1276 case kEplNmtEventSwReset:
1278 EPL_MCO_GLB_VAR(m_NmtState) =
1279 kEplNmtGsInitialising;
1283 // NMT Command ResetNode
1284 case kEplNmtEventResetNode:
1286 EPL_MCO_GLB_VAR(m_NmtState) =
1287 kEplNmtGsResetApplication;
1291 // NMT Command ResetCommunication
1292 // or internal Communication error
1293 case kEplNmtEventResetCom:
1294 case kEplNmtEventInternComError:
1296 EPL_MCO_GLB_VAR(m_NmtState) =
1297 kEplNmtGsResetCommunication;
1301 // NMT Command ResetConfiguration
1302 case kEplNmtEventResetConfig:
1304 EPL_MCO_GLB_VAR(m_NmtState) =
1305 kEplNmtGsResetConfiguration;
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;
1320 // d.k. MSPreOp1->CSPreOp1: nonsense -> keep state
1322 case kEplNmtEventNmtCycleError:
1324 EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtCsPreOperational1;
1329 case kEplNmtEventAllMandatoryCNIdent:
1330 { // all mandatory CN identified
1331 if (EPL_MCO_GLB_VAR(m_fTimerMsPreOp2) !=
1333 EPL_MCO_GLB_VAR(m_NmtState) =
1334 kEplNmtMsPreOperational2;
1337 (m_fAllMandatoryCNIdent) =
1343 case kEplNmtEventTimerMsPreOp2:
1344 { // residence time for PreOp1 is elapsed
1346 (m_fAllMandatoryCNIdent) != FALSE) {
1347 EPL_MCO_GLB_VAR(m_NmtState) =
1348 kEplNmtMsPreOperational2;
1351 (m_fTimerMsPreOp2) = TRUE;
1361 } // end of switch(NmtEvent)
1365 // MN process full epl cycle
1366 case kEplNmtMsPreOperational2:
1370 // NMT Command SwitchOff
1371 case kEplNmtEventCriticalError:
1372 case kEplNmtEventSwitchOff:
1374 EPL_MCO_GLB_VAR(m_NmtState) =
1379 // NMT Command SwReset
1380 case kEplNmtEventSwReset:
1382 EPL_MCO_GLB_VAR(m_NmtState) =
1383 kEplNmtGsInitialising;
1387 // NMT Command ResetNode
1388 case kEplNmtEventResetNode:
1390 EPL_MCO_GLB_VAR(m_NmtState) =
1391 kEplNmtGsResetApplication;
1395 // NMT Command ResetCommunication
1396 // or internal Communication error
1397 case kEplNmtEventResetCom:
1398 case kEplNmtEventInternComError:
1400 EPL_MCO_GLB_VAR(m_NmtState) =
1401 kEplNmtGsResetCommunication;
1405 // NMT Command ResetConfiguration
1406 case kEplNmtEventResetConfig:
1408 EPL_MCO_GLB_VAR(m_NmtState) =
1409 kEplNmtGsResetConfiguration;
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;
1424 case kEplNmtEventNmtCycleError:
1426 EPL_MCO_GLB_VAR(m_NmtState) =
1427 kEplNmtMsPreOperational1;
1431 case kEplNmtEventEnterReadyToOperate:
1433 EPL_MCO_GLB_VAR(m_NmtState) =
1434 kEplNmtMsReadyToOperate;
1443 } // end of switch(NmtEvent)
1448 // all madatory nodes ready to operate
1449 // -> MN process full epl cycle
1450 case kEplNmtMsReadyToOperate:
1455 // NMT Command SwitchOff
1456 case kEplNmtEventCriticalError:
1457 case kEplNmtEventSwitchOff:
1459 EPL_MCO_GLB_VAR(m_NmtState) =
1464 // NMT Command SwReset
1465 case kEplNmtEventSwReset:
1467 EPL_MCO_GLB_VAR(m_NmtState) =
1468 kEplNmtGsInitialising;
1472 // NMT Command ResetNode
1473 case kEplNmtEventResetNode:
1475 EPL_MCO_GLB_VAR(m_NmtState) =
1476 kEplNmtGsResetApplication;
1480 // NMT Command ResetCommunication
1481 // or internal Communication error
1482 case kEplNmtEventResetCom:
1483 case kEplNmtEventInternComError:
1485 EPL_MCO_GLB_VAR(m_NmtState) =
1486 kEplNmtGsResetCommunication;
1490 // NMT Command ResetConfiguration
1491 case kEplNmtEventResetConfig:
1493 EPL_MCO_GLB_VAR(m_NmtState) =
1494 kEplNmtGsResetConfiguration;
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;
1509 case kEplNmtEventNmtCycleError:
1511 EPL_MCO_GLB_VAR(m_NmtState) =
1512 kEplNmtMsPreOperational1;
1516 case kEplNmtEventEnterMsOperational:
1518 EPL_MCO_GLB_VAR(m_NmtState) =
1519 kEplNmtMsOperational;
1528 } // end of switch(NmtEvent)
1533 // normal eplcycle processing
1534 case kEplNmtMsOperational:
1538 // NMT Command SwitchOff
1539 case kEplNmtEventCriticalError:
1540 case kEplNmtEventSwitchOff:
1542 EPL_MCO_GLB_VAR(m_NmtState) =
1547 // NMT Command SwReset
1548 case kEplNmtEventSwReset:
1550 EPL_MCO_GLB_VAR(m_NmtState) =
1551 kEplNmtGsInitialising;
1555 // NMT Command ResetNode
1556 case kEplNmtEventResetNode:
1558 EPL_MCO_GLB_VAR(m_NmtState) =
1559 kEplNmtGsResetApplication;
1563 // NMT Command ResetCommunication
1564 // or internal Communication error
1565 case kEplNmtEventResetCom:
1566 case kEplNmtEventInternComError:
1568 EPL_MCO_GLB_VAR(m_NmtState) =
1569 kEplNmtGsResetCommunication;
1573 // NMT Command ResetConfiguration
1574 case kEplNmtEventResetConfig:
1576 EPL_MCO_GLB_VAR(m_NmtState) =
1577 kEplNmtGsResetConfiguration;
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;
1592 case kEplNmtEventNmtCycleError:
1594 EPL_MCO_GLB_VAR(m_NmtState) =
1595 kEplNmtMsPreOperational1;
1604 } // end of switch(NmtEvent)
1608 // normal ethernet traffic
1609 case kEplNmtMsBasicEthernet:
1614 // NMT Command SwitchOff
1615 case kEplNmtEventCriticalError:
1616 case kEplNmtEventSwitchOff:
1618 EPL_MCO_GLB_VAR(m_NmtState) =
1623 // NMT Command SwReset
1624 case kEplNmtEventSwReset:
1626 EPL_MCO_GLB_VAR(m_NmtState) =
1627 kEplNmtGsInitialising;
1631 // NMT Command ResetNode
1632 case kEplNmtEventResetNode:
1634 EPL_MCO_GLB_VAR(m_NmtState) =
1635 kEplNmtGsResetApplication;
1639 // NMT Command ResetCommunication
1640 // or internal Communication error
1641 case kEplNmtEventResetCom:
1642 case kEplNmtEventInternComError:
1644 EPL_MCO_GLB_VAR(m_NmtState) =
1645 kEplNmtGsResetCommunication;
1649 // NMT Command ResetConfiguration
1650 case kEplNmtEventResetConfig:
1652 EPL_MCO_GLB_VAR(m_NmtState) =
1653 kEplNmtGsResetConfiguration;
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;
1668 // d.k. BE->PreOp1 on cycle error? No
1669 /* case kEplNmtEventNmtCycleError:
1671 EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtCsPreOperational1;
1680 } // end of switch(NmtEvent)
1683 #endif //#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
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;
1693 } // end of switch(NmtEvent)
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));
1700 // d.k.: memorize NMT state before posting any events
1701 NmtStateChange.m_NewNmtState = EPL_MCO_GLB_VAR(m_NmtState);
1704 if ((OldNmtState > kEplNmtGsResetConfiguration)
1705 && (EPL_MCO_GLB_VAR(m_NmtState) <=
1706 kEplNmtGsResetConfiguration)) {
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);
1722 Ret = EplEventkPost(&Event);
1724 } else if ((OldNmtState <= kEplNmtGsResetConfiguration)
1725 && (EPL_MCO_GLB_VAR(m_NmtState) >
1726 kEplNmtGsResetConfiguration)) {
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);
1742 Ret = EplEventkPost(&Event);
1745 if ((EPL_MCO_GLB_VAR(m_NmtState) == kEplNmtCsBasicEthernet)
1746 || (EPL_MCO_GLB_VAR(m_NmtState) ==
1747 kEplNmtMsBasicEthernet)) {
1748 tEplDllAsyncReqPriority AsyncReqPriority;
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);
1766 Ret = EplEventkPost(&Event);
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);
1788 //---------------------------------------------------------------------------
1790 // Function: EplNmtkGetNmtState
1792 // Description: return the actuell NMT-State and the bits
1793 // to for MN- or CN-mode
1797 // Parameters: EPL_MCO_DECL_PTR_INSTANCE_PTR_ = Instancepointer
1800 // Returns: tEplNmtState = NMT-State
1805 //---------------------------------------------------------------------------
1806 tEplNmtState EplNmtkGetNmtState(EPL_MCO_DECL_PTR_INSTANCE_PTR)
1808 tEplNmtState NmtState;
1810 NmtState = EPL_MCO_GLB_VAR(m_NmtState);
1816 //=========================================================================//
1818 // P R I V A T E D E F I N I T I O N S //
1820 //=========================================================================//
1821 EPL_MCO_DECL_INSTANCE_FCT()
1822 //---------------------------------------------------------------------------
1838 //---------------------------------------------------------------------------
1839 #endif // #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)