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 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)
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 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;
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*
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 EPLDLLEXPORT tEplKernel PUBLIC 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 EPLDLLEXPORT tEplKernel PUBLIC 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 EPLDLLEXPORT tEplKernel PUBLIC 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 EPLDLLEXPORT tEplKernel PUBLIC EplNmtkProcess(EPL_MCO_DECL_PTR_INSTANCE_PTR_
300 tEplEvent * pEvent_p)
303 tEplNmtState OldNmtState;
304 tEplNmtEvent NmtEvent;
306 tEplEventNmtStateChange NmtStateChange;
308 // check for all API function if instance is valid
309 EPL_MCO_CHECK_INSTANCE_STATE();
311 Ret = kEplSuccessful;
313 switch (pEvent_p->m_EventType) {
314 case kEplEventTypeNmtEvent:
316 NmtEvent = *((tEplNmtEvent *) pEvent_p->m_pArg);
320 case kEplEventTypeTimer:
323 (tEplNmtEvent) ((tEplTimerEventArg *) pEvent_p->
329 Ret = kEplNmtInvalidEvent;
335 // needed for later comparison to
336 // inform hgher layer about state change
337 OldNmtState = EPL_MCO_GLB_VAR(m_NmtState);
339 // NMT-State-Maschine
340 switch (EPL_MCO_GLB_VAR(m_NmtState)) {
341 //-----------------------------------------------------------
342 // general part of the statemaschine
344 // first init of the hardware
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;
355 // first init of the hardware
356 case kEplNmtGsInitialising:
358 // leave this state only if higher layer says so
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:
367 EPL_MCO_GLB_VAR(m_NmtState) =
372 // new state kEplNmtGsResetApplication
373 case kEplNmtEventEnterResetApp:
375 EPL_MCO_GLB_VAR(m_NmtState) =
376 kEplNmtGsResetApplication;
388 // init of the manufacturer-specific profile area and the
389 // standardised device profile area
390 case kEplNmtGsResetApplication:
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:
399 EPL_MCO_GLB_VAR(m_NmtState) =
404 // NMT Command SwReset
405 case kEplNmtEventSwReset:
407 EPL_MCO_GLB_VAR(m_NmtState) =
408 kEplNmtGsInitialising;
412 // leave this state only if higher layer
414 case kEplNmtEventEnterResetCom:
416 // new state kEplNmtGsResetCommunication
417 EPL_MCO_GLB_VAR(m_NmtState) =
418 kEplNmtGsResetCommunication;
430 // init of the communication profile area
431 case kEplNmtGsResetCommunication:
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:
440 EPL_MCO_GLB_VAR(m_NmtState) =
445 // NMT Command SwReset
446 case kEplNmtEventSwReset:
448 EPL_MCO_GLB_VAR(m_NmtState) =
449 kEplNmtGsInitialising;
453 // NMT Command ResetNode
454 case kEplNmtEventResetNode:
456 EPL_MCO_GLB_VAR(m_NmtState) =
457 kEplNmtGsResetApplication;
461 // leave this state only if higher layer
463 case kEplNmtEventEnterResetConfig:
465 // new state kEplNmtGsResetCommunication
466 EPL_MCO_GLB_VAR(m_NmtState) =
467 kEplNmtGsResetConfiguration;
479 // build the configuration with infos from OD
480 case kEplNmtGsResetConfiguration:
483 EPL_MCO_GLB_VAR(m_fEnableReadyToOperate) = FALSE;
484 EPL_MCO_GLB_VAR(m_fAppReadyToOperate) = FALSE;
485 EPL_MCO_GLB_VAR(m_fFrozen) = FALSE;
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:
494 EPL_MCO_GLB_VAR(m_NmtState) =
499 // NMT Command SwReset
500 case kEplNmtEventSwReset:
502 EPL_MCO_GLB_VAR(m_NmtState) =
503 kEplNmtGsInitialising;
507 // NMT Command ResetNode
508 case kEplNmtEventResetNode:
510 EPL_MCO_GLB_VAR(m_NmtState) =
511 kEplNmtGsResetApplication;
515 // NMT Command ResetCommunication
516 case kEplNmtEventResetCom:
518 EPL_MCO_GLB_VAR(m_NmtState) =
519 kEplNmtGsResetCommunication;
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) =
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;
540 EPL_MCO_GLB_VAR(m_NmtState) =
555 //-----------------------------------------------------------
556 // CN part of the statemaschine
558 // node liste for EPL-Frames and check timeout
559 case kEplNmtCsNotActive:
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:
569 EPL_MCO_GLB_VAR(m_NmtState) =
574 // NMT Command SwReset
575 case kEplNmtEventSwReset:
577 EPL_MCO_GLB_VAR(m_NmtState) =
578 kEplNmtGsInitialising;
579 // Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
583 // NMT Command ResetNode
584 case kEplNmtEventResetNode:
586 EPL_MCO_GLB_VAR(m_NmtState) =
587 kEplNmtGsResetApplication;
588 // Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
592 // NMT Command ResetCommunication
593 // or internal Communication error
594 case kEplNmtEventResetCom:
595 case kEplNmtEventInternComError:
597 EPL_MCO_GLB_VAR(m_NmtState) =
598 kEplNmtGsResetCommunication;
599 // Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
603 // NMT Command Reset Configuration
604 case kEplNmtEventResetConfig:
606 EPL_MCO_GLB_VAR(m_NmtState) =
607 kEplNmtGsResetConfiguration;
608 // Ret = EplTimerkDeleteTimer(&EPL_MCO_GLB_VAR(m_TimerHdl));
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));
623 // timeout for SoA and Soc
624 case kEplNmtEventTimerBasicEthernet:
626 // new state BASIC_ETHERNET
627 EPL_MCO_GLB_VAR(m_NmtState) =
628 kEplNmtCsBasicEthernet;
636 } // end of switch(NmtEvent)
641 // node processes only async frames
642 case kEplNmtCsPreOperational1:
647 // NMT Command SwitchOff
648 case kEplNmtEventCriticalError:
649 case kEplNmtEventSwitchOff:
651 EPL_MCO_GLB_VAR(m_NmtState) =
656 // NMT Command SwReset
657 case kEplNmtEventSwReset:
659 EPL_MCO_GLB_VAR(m_NmtState) =
660 kEplNmtGsInitialising;
664 // NMT Command ResetNode
665 case kEplNmtEventResetNode:
667 EPL_MCO_GLB_VAR(m_NmtState) =
668 kEplNmtGsResetApplication;
672 // NMT Command ResetCommunication
673 // or internal Communication error
674 case kEplNmtEventResetCom:
675 case kEplNmtEventInternComError:
677 EPL_MCO_GLB_VAR(m_NmtState) =
678 kEplNmtGsResetCommunication;
682 // NMT Command Reset Configuration
683 case kEplNmtEventResetConfig:
685 EPL_MCO_GLB_VAR(m_NmtState) =
686 kEplNmtGsResetConfiguration;
690 // NMT Command StopNode
691 case kEplNmtEventStopNode:
693 EPL_MCO_GLB_VAR(m_NmtState) =
698 // check if SoC received
699 case kEplNmtEventDllCeSoc:
701 EPL_MCO_GLB_VAR(m_NmtState) =
702 kEplNmtCsPreOperational2;
711 } // end of switch(NmtEvent)
716 // node processes isochronous and asynchronous frames
717 case kEplNmtCsPreOperational2:
721 // NMT Command SwitchOff
722 case kEplNmtEventCriticalError:
723 case kEplNmtEventSwitchOff:
725 EPL_MCO_GLB_VAR(m_NmtState) =
730 // NMT Command SwReset
731 case kEplNmtEventSwReset:
733 EPL_MCO_GLB_VAR(m_NmtState) =
734 kEplNmtGsInitialising;
738 // NMT Command ResetNode
739 case kEplNmtEventResetNode:
741 EPL_MCO_GLB_VAR(m_NmtState) =
742 kEplNmtGsResetApplication;
746 // NMT Command ResetCommunication
747 // or internal Communication error
748 case kEplNmtEventResetCom:
749 case kEplNmtEventInternComError:
751 EPL_MCO_GLB_VAR(m_NmtState) =
752 kEplNmtGsResetCommunication;
756 // NMT Command Reset Configuration
757 case kEplNmtEventResetConfig:
759 EPL_MCO_GLB_VAR(m_NmtState) =
760 kEplNmtGsResetConfiguration;
764 // NMT Command StopNode
765 case kEplNmtEventStopNode:
768 EPL_MCO_GLB_VAR(m_fEnableReadyToOperate)
770 EPL_MCO_GLB_VAR(m_fAppReadyToOperate) =
772 EPL_MCO_GLB_VAR(m_NmtState) =
778 case kEplNmtEventNmtCycleError:
781 EPL_MCO_GLB_VAR(m_fEnableReadyToOperate)
783 EPL_MCO_GLB_VAR(m_fAppReadyToOperate) =
785 EPL_MCO_GLB_VAR(m_NmtState) =
786 kEplNmtCsPreOperational1;
790 // check if application is ready to operate
791 case kEplNmtEventEnterReadyToOperate:
793 // check if command NMTEnableReadyToOperate from MN was received
794 if (EPL_MCO_GLB_VAR(m_fEnableReadyToOperate) == TRUE) { // reset flags
796 (m_fEnableReadyToOperate) =
799 (m_fAppReadyToOperate) =
802 EPL_MCO_GLB_VAR(m_NmtState) =
803 kEplNmtCsReadyToOperate;
806 (m_fAppReadyToOperate) =
812 // NMT Commando EnableReadyToOperate
813 case kEplNmtEventEnableReadyToOperate:
815 // check if application is ready
816 if (EPL_MCO_GLB_VAR(m_fAppReadyToOperate) == TRUE) { // reset flags
818 (m_fEnableReadyToOperate) =
821 (m_fAppReadyToOperate) =
824 EPL_MCO_GLB_VAR(m_NmtState) =
825 kEplNmtCsReadyToOperate;
828 (m_fEnableReadyToOperate) =
839 } // end of switch(NmtEvent)
843 // node should be configured und application is ready
844 case kEplNmtCsReadyToOperate:
848 // NMT Command SwitchOff
849 case kEplNmtEventCriticalError:
850 case kEplNmtEventSwitchOff:
852 EPL_MCO_GLB_VAR(m_NmtState) =
857 // NMT Command SwReset
858 case kEplNmtEventSwReset:
860 EPL_MCO_GLB_VAR(m_NmtState) =
861 kEplNmtGsInitialising;
865 // NMT Command ResetNode
866 case kEplNmtEventResetNode:
868 EPL_MCO_GLB_VAR(m_NmtState) =
869 kEplNmtGsResetApplication;
873 // NMT Command ResetCommunication
874 // or internal Communication error
875 case kEplNmtEventResetCom:
876 case kEplNmtEventInternComError:
878 EPL_MCO_GLB_VAR(m_NmtState) =
879 kEplNmtGsResetCommunication;
883 // NMT Command ResetConfiguration
884 case kEplNmtEventResetConfig:
886 EPL_MCO_GLB_VAR(m_NmtState) =
887 kEplNmtGsResetConfiguration;
891 // NMT Command StopNode
892 case kEplNmtEventStopNode:
894 EPL_MCO_GLB_VAR(m_NmtState) =
900 case kEplNmtEventNmtCycleError:
902 EPL_MCO_GLB_VAR(m_NmtState) =
903 kEplNmtCsPreOperational1;
907 // NMT Command StartNode
908 case kEplNmtEventStartNode:
910 EPL_MCO_GLB_VAR(m_NmtState) =
911 kEplNmtCsOperational;
920 } // end of switch(NmtEvent)
925 case kEplNmtCsOperational:
930 // NMT Command SwitchOff
931 case kEplNmtEventCriticalError:
932 case kEplNmtEventSwitchOff:
934 EPL_MCO_GLB_VAR(m_NmtState) =
939 // NMT Command SwReset
940 case kEplNmtEventSwReset:
942 EPL_MCO_GLB_VAR(m_NmtState) =
943 kEplNmtGsInitialising;
947 // NMT Command ResetNode
948 case kEplNmtEventResetNode:
950 EPL_MCO_GLB_VAR(m_NmtState) =
951 kEplNmtGsResetApplication;
955 // NMT Command ResetCommunication
956 // or internal Communication error
957 case kEplNmtEventResetCom:
958 case kEplNmtEventInternComError:
960 EPL_MCO_GLB_VAR(m_NmtState) =
961 kEplNmtGsResetCommunication;
965 // NMT Command ResetConfiguration
966 case kEplNmtEventResetConfig:
968 EPL_MCO_GLB_VAR(m_NmtState) =
969 kEplNmtGsResetConfiguration;
973 // NMT Command StopNode
974 case kEplNmtEventStopNode:
976 EPL_MCO_GLB_VAR(m_NmtState) =
981 // NMT Command EnterPreOperational2
982 case kEplNmtEventEnterPreOperational2:
984 EPL_MCO_GLB_VAR(m_NmtState) =
985 kEplNmtCsPreOperational2;
990 case kEplNmtEventNmtCycleError:
992 EPL_MCO_GLB_VAR(m_NmtState) =
993 kEplNmtCsPreOperational1;
1002 } // end of switch(NmtEvent)
1006 // node stopped by MN
1007 // -> only process asynchronous frames
1008 case kEplNmtCsStopped:
1012 // NMT Command SwitchOff
1013 case kEplNmtEventCriticalError:
1014 case kEplNmtEventSwitchOff:
1016 EPL_MCO_GLB_VAR(m_NmtState) =
1021 // NMT Command SwReset
1022 case kEplNmtEventSwReset:
1024 EPL_MCO_GLB_VAR(m_NmtState) =
1025 kEplNmtGsInitialising;
1029 // NMT Command ResetNode
1030 case kEplNmtEventResetNode:
1032 EPL_MCO_GLB_VAR(m_NmtState) =
1033 kEplNmtGsResetApplication;
1037 // NMT Command ResetCommunication
1038 // or internal Communication error
1039 case kEplNmtEventResetCom:
1040 case kEplNmtEventInternComError:
1042 EPL_MCO_GLB_VAR(m_NmtState) =
1043 kEplNmtGsResetCommunication;
1047 // NMT Command ResetConfiguration
1048 case kEplNmtEventResetConfig:
1050 EPL_MCO_GLB_VAR(m_NmtState) =
1051 kEplNmtGsResetConfiguration;
1055 // NMT Command EnterPreOperational2
1056 case kEplNmtEventEnterPreOperational2:
1058 EPL_MCO_GLB_VAR(m_NmtState) =
1059 kEplNmtCsPreOperational2;
1064 case kEplNmtEventNmtCycleError:
1066 EPL_MCO_GLB_VAR(m_NmtState) =
1067 kEplNmtCsPreOperational1;
1076 } // end of switch(NmtEvent)
1081 // -> normal ethernet communication
1082 case kEplNmtCsBasicEthernet:
1086 // NMT Command SwitchOff
1087 case kEplNmtEventCriticalError:
1088 case kEplNmtEventSwitchOff:
1090 EPL_MCO_GLB_VAR(m_NmtState) =
1095 // NMT Command SwReset
1096 case kEplNmtEventSwReset:
1098 EPL_MCO_GLB_VAR(m_NmtState) =
1099 kEplNmtGsInitialising;
1103 // NMT Command ResetNode
1104 case kEplNmtEventResetNode:
1106 EPL_MCO_GLB_VAR(m_NmtState) =
1107 kEplNmtGsResetApplication;
1111 // NMT Command ResetCommunication
1112 // or internal Communication error
1113 case kEplNmtEventResetCom:
1114 case kEplNmtEventInternComError:
1116 EPL_MCO_GLB_VAR(m_NmtState) =
1117 kEplNmtGsResetCommunication;
1121 // NMT Command ResetConfiguration
1122 case kEplNmtEventResetConfig:
1124 EPL_MCO_GLB_VAR(m_NmtState) =
1125 kEplNmtGsResetConfiguration;
1130 // d.k.: how does this error occur? on CRC errors
1131 /* case kEplNmtEventNmtCycleError:
1133 EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtCsPreOperational1;
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;
1152 } // end of switch(NmtEvent)
1157 //-----------------------------------------------------------
1158 // MN part of the statemaschine
1160 // MN listen to network
1161 // -> if no EPL traffic go to next state
1162 case kEplNmtMsNotActive:
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;
1172 // NMT Command SwitchOff
1173 case kEplNmtEventCriticalError:
1174 case kEplNmtEventSwitchOff:
1176 EPL_MCO_GLB_VAR(m_NmtState) =
1181 // NMT Command SwReset
1182 case kEplNmtEventSwReset:
1184 EPL_MCO_GLB_VAR(m_NmtState) =
1185 kEplNmtGsInitialising;
1189 // NMT Command ResetNode
1190 case kEplNmtEventResetNode:
1192 EPL_MCO_GLB_VAR(m_NmtState) =
1193 kEplNmtGsResetApplication;
1197 // NMT Command ResetCommunication
1198 // or internal Communication error
1199 case kEplNmtEventResetCom:
1200 case kEplNmtEventInternComError:
1202 EPL_MCO_GLB_VAR(m_NmtState) =
1203 kEplNmtGsResetCommunication;
1207 // NMT Command ResetConfiguration
1208 case kEplNmtEventResetConfig:
1210 EPL_MCO_GLB_VAR(m_NmtState) =
1211 kEplNmtGsResetConfiguration;
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;
1225 case kEplNmtEventTimerBasicEthernet:
1227 if (EPL_MCO_GLB_VAR(m_fFrozen) == FALSE) { // new state BasicEthernet
1228 EPL_MCO_GLB_VAR(m_NmtState) =
1229 kEplNmtMsBasicEthernet;
1235 case kEplNmtEventTimerMsPreOp1:
1237 if (EPL_MCO_GLB_VAR(m_fFrozen) == FALSE) { // new state PreOp1
1238 EPL_MCO_GLB_VAR(m_NmtState) =
1239 kEplNmtMsPreOperational1;
1241 (m_fTimerMsPreOp2) = FALSE;
1243 (m_fAllMandatoryCNIdent) =
1255 } // end of switch(NmtEvent)
1257 #endif // ((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) == 0)
1261 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
1262 // MN process reduces epl cycle
1263 case kEplNmtMsPreOperational1:
1267 // NMT Command SwitchOff
1268 case kEplNmtEventCriticalError:
1269 case kEplNmtEventSwitchOff:
1271 EPL_MCO_GLB_VAR(m_NmtState) =
1276 // NMT Command SwReset
1277 case kEplNmtEventSwReset:
1279 EPL_MCO_GLB_VAR(m_NmtState) =
1280 kEplNmtGsInitialising;
1284 // NMT Command ResetNode
1285 case kEplNmtEventResetNode:
1287 EPL_MCO_GLB_VAR(m_NmtState) =
1288 kEplNmtGsResetApplication;
1292 // NMT Command ResetCommunication
1293 // or internal Communication error
1294 case kEplNmtEventResetCom:
1295 case kEplNmtEventInternComError:
1297 EPL_MCO_GLB_VAR(m_NmtState) =
1298 kEplNmtGsResetCommunication;
1302 // NMT Command ResetConfiguration
1303 case kEplNmtEventResetConfig:
1305 EPL_MCO_GLB_VAR(m_NmtState) =
1306 kEplNmtGsResetConfiguration;
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;
1321 // d.k. MSPreOp1->CSPreOp1: nonsense -> keep state
1323 case kEplNmtEventNmtCycleError:
1325 EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtCsPreOperational1;
1330 case kEplNmtEventAllMandatoryCNIdent:
1331 { // all mandatory CN identified
1332 if (EPL_MCO_GLB_VAR(m_fTimerMsPreOp2) !=
1334 EPL_MCO_GLB_VAR(m_NmtState) =
1335 kEplNmtMsPreOperational2;
1338 (m_fAllMandatoryCNIdent) =
1344 case kEplNmtEventTimerMsPreOp2:
1345 { // residence time for PreOp1 is elapsed
1347 (m_fAllMandatoryCNIdent) != FALSE) {
1348 EPL_MCO_GLB_VAR(m_NmtState) =
1349 kEplNmtMsPreOperational2;
1352 (m_fTimerMsPreOp2) = TRUE;
1362 } // end of switch(NmtEvent)
1366 // MN process full epl cycle
1367 case kEplNmtMsPreOperational2:
1371 // NMT Command SwitchOff
1372 case kEplNmtEventCriticalError:
1373 case kEplNmtEventSwitchOff:
1375 EPL_MCO_GLB_VAR(m_NmtState) =
1380 // NMT Command SwReset
1381 case kEplNmtEventSwReset:
1383 EPL_MCO_GLB_VAR(m_NmtState) =
1384 kEplNmtGsInitialising;
1388 // NMT Command ResetNode
1389 case kEplNmtEventResetNode:
1391 EPL_MCO_GLB_VAR(m_NmtState) =
1392 kEplNmtGsResetApplication;
1396 // NMT Command ResetCommunication
1397 // or internal Communication error
1398 case kEplNmtEventResetCom:
1399 case kEplNmtEventInternComError:
1401 EPL_MCO_GLB_VAR(m_NmtState) =
1402 kEplNmtGsResetCommunication;
1406 // NMT Command ResetConfiguration
1407 case kEplNmtEventResetConfig:
1409 EPL_MCO_GLB_VAR(m_NmtState) =
1410 kEplNmtGsResetConfiguration;
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;
1425 case kEplNmtEventNmtCycleError:
1427 EPL_MCO_GLB_VAR(m_NmtState) =
1428 kEplNmtMsPreOperational1;
1432 case kEplNmtEventEnterReadyToOperate:
1434 EPL_MCO_GLB_VAR(m_NmtState) =
1435 kEplNmtMsReadyToOperate;
1444 } // end of switch(NmtEvent)
1449 // all madatory nodes ready to operate
1450 // -> MN process full epl cycle
1451 case kEplNmtMsReadyToOperate:
1456 // NMT Command SwitchOff
1457 case kEplNmtEventCriticalError:
1458 case kEplNmtEventSwitchOff:
1460 EPL_MCO_GLB_VAR(m_NmtState) =
1465 // NMT Command SwReset
1466 case kEplNmtEventSwReset:
1468 EPL_MCO_GLB_VAR(m_NmtState) =
1469 kEplNmtGsInitialising;
1473 // NMT Command ResetNode
1474 case kEplNmtEventResetNode:
1476 EPL_MCO_GLB_VAR(m_NmtState) =
1477 kEplNmtGsResetApplication;
1481 // NMT Command ResetCommunication
1482 // or internal Communication error
1483 case kEplNmtEventResetCom:
1484 case kEplNmtEventInternComError:
1486 EPL_MCO_GLB_VAR(m_NmtState) =
1487 kEplNmtGsResetCommunication;
1491 // NMT Command ResetConfiguration
1492 case kEplNmtEventResetConfig:
1494 EPL_MCO_GLB_VAR(m_NmtState) =
1495 kEplNmtGsResetConfiguration;
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;
1510 case kEplNmtEventNmtCycleError:
1512 EPL_MCO_GLB_VAR(m_NmtState) =
1513 kEplNmtMsPreOperational1;
1517 case kEplNmtEventEnterMsOperational:
1519 EPL_MCO_GLB_VAR(m_NmtState) =
1520 kEplNmtMsOperational;
1529 } // end of switch(NmtEvent)
1534 // normal eplcycle processing
1535 case kEplNmtMsOperational:
1539 // NMT Command SwitchOff
1540 case kEplNmtEventCriticalError:
1541 case kEplNmtEventSwitchOff:
1543 EPL_MCO_GLB_VAR(m_NmtState) =
1548 // NMT Command SwReset
1549 case kEplNmtEventSwReset:
1551 EPL_MCO_GLB_VAR(m_NmtState) =
1552 kEplNmtGsInitialising;
1556 // NMT Command ResetNode
1557 case kEplNmtEventResetNode:
1559 EPL_MCO_GLB_VAR(m_NmtState) =
1560 kEplNmtGsResetApplication;
1564 // NMT Command ResetCommunication
1565 // or internal Communication error
1566 case kEplNmtEventResetCom:
1567 case kEplNmtEventInternComError:
1569 EPL_MCO_GLB_VAR(m_NmtState) =
1570 kEplNmtGsResetCommunication;
1574 // NMT Command ResetConfiguration
1575 case kEplNmtEventResetConfig:
1577 EPL_MCO_GLB_VAR(m_NmtState) =
1578 kEplNmtGsResetConfiguration;
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;
1593 case kEplNmtEventNmtCycleError:
1595 EPL_MCO_GLB_VAR(m_NmtState) =
1596 kEplNmtMsPreOperational1;
1605 } // end of switch(NmtEvent)
1609 // normal ethernet traffic
1610 case kEplNmtMsBasicEthernet:
1615 // NMT Command SwitchOff
1616 case kEplNmtEventCriticalError:
1617 case kEplNmtEventSwitchOff:
1619 EPL_MCO_GLB_VAR(m_NmtState) =
1624 // NMT Command SwReset
1625 case kEplNmtEventSwReset:
1627 EPL_MCO_GLB_VAR(m_NmtState) =
1628 kEplNmtGsInitialising;
1632 // NMT Command ResetNode
1633 case kEplNmtEventResetNode:
1635 EPL_MCO_GLB_VAR(m_NmtState) =
1636 kEplNmtGsResetApplication;
1640 // NMT Command ResetCommunication
1641 // or internal Communication error
1642 case kEplNmtEventResetCom:
1643 case kEplNmtEventInternComError:
1645 EPL_MCO_GLB_VAR(m_NmtState) =
1646 kEplNmtGsResetCommunication;
1650 // NMT Command ResetConfiguration
1651 case kEplNmtEventResetConfig:
1653 EPL_MCO_GLB_VAR(m_NmtState) =
1654 kEplNmtGsResetConfiguration;
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;
1669 // d.k. BE->PreOp1 on cycle error? No
1670 /* case kEplNmtEventNmtCycleError:
1672 EPL_MCO_GLB_VAR(m_NmtState) = kEplNmtCsPreOperational1;
1681 } // end of switch(NmtEvent)
1684 #endif //#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
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;
1694 } // end of switch(NmtEvent)
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));
1701 // d.k.: memorize NMT state before posting any events
1702 NmtStateChange.m_NewNmtState = EPL_MCO_GLB_VAR(m_NmtState);
1705 if ((OldNmtState > kEplNmtGsResetConfiguration)
1706 && (EPL_MCO_GLB_VAR(m_NmtState) <=
1707 kEplNmtGsResetConfiguration)) {
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);
1723 Ret = EplEventkPost(&Event);
1725 } else if ((OldNmtState <= kEplNmtGsResetConfiguration)
1726 && (EPL_MCO_GLB_VAR(m_NmtState) >
1727 kEplNmtGsResetConfiguration)) {
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);
1743 Ret = EplEventkPost(&Event);
1746 if ((EPL_MCO_GLB_VAR(m_NmtState) == kEplNmtCsBasicEthernet)
1747 || (EPL_MCO_GLB_VAR(m_NmtState) ==
1748 kEplNmtMsBasicEthernet)) {
1749 tEplDllAsyncReqPriority AsyncReqPriority;
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);
1767 Ret = EplEventkPost(&Event);
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);
1789 //---------------------------------------------------------------------------
1791 // Function: EplNmtkGetNmtState
1793 // Description: return the actuell NMT-State and the bits
1794 // to for MN- or CN-mode
1798 // Parameters: EPL_MCO_DECL_PTR_INSTANCE_PTR_ = Instancepointer
1801 // Returns: tEplNmtState = NMT-State
1806 //---------------------------------------------------------------------------
1807 EPLDLLEXPORT tEplNmtState PUBLIC
1808 EplNmtkGetNmtState(EPL_MCO_DECL_PTR_INSTANCE_PTR)
1810 tEplNmtState NmtState;
1812 NmtState = EPL_MCO_GLB_VAR(m_NmtState);
1818 //=========================================================================//
1820 // P R I V A T E D E F I N I T I O N S //
1822 //=========================================================================//
1823 EPL_MCO_DECL_INSTANCE_FCT()
1824 //---------------------------------------------------------------------------
1840 //---------------------------------------------------------------------------
1841 #endif // #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)