summaryrefslogtreecommitdiffstats
path: root/drivers/staging/epl/EplNmtMnu.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/epl/EplNmtMnu.c')
-rw-r--r--drivers/staging/epl/EplNmtMnu.c2828
1 files changed, 0 insertions, 2828 deletions
diff --git a/drivers/staging/epl/EplNmtMnu.c b/drivers/staging/epl/EplNmtMnu.c
deleted file mode 100644
index d19434f5f6f8..000000000000
--- a/drivers/staging/epl/EplNmtMnu.c
+++ /dev/null
@@ -1,2828 +0,0 @@
-/****************************************************************************
-
- (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
- www.systec-electronic.com
-
- Project: openPOWERLINK
-
- Description: source file for NMT-MN-Module
-
- License:
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
- 3. Neither the name of SYSTEC electronic GmbH nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without prior written permission. For written
- permission, please contact info@systec-electronic.com.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
- Severability Clause:
-
- If a provision of this License is or becomes illegal, invalid or
- unenforceable in any jurisdiction, that shall not affect:
- 1. the validity or enforceability in that jurisdiction of any other
- provision of this License; or
- 2. the validity or enforceability in other jurisdictions of that or
- any other provision of this License.
-
- -------------------------------------------------------------------------
-
- $RCSfile: EplNmtMnu.c,v $
-
- $Author: D.Krueger $
-
- $Revision: 1.18 $ $Date: 2008/11/19 09:52:24 $
-
- $State: Exp $
-
- Build Environment:
- GCC V3.4
-
- -------------------------------------------------------------------------
-
- Revision History:
-
- 2006/06/09 k.t.: start of the implementation
-
-****************************************************************************/
-
-#include "user/EplNmtMnu.h"
-#include "user/EplTimeru.h"
-#include "user/EplIdentu.h"
-#include "user/EplStatusu.h"
-#include "user/EplObdu.h"
-#include "user/EplDlluCal.h"
-#include "Benchmark.h"
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
-
-#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_OBDU)) == 0) && (EPL_OBD_USE_KERNEL == FALSE)
-#error "EPL NmtMnu module needs EPL module OBDU or OBDK!"
-#endif
-
-//=========================================================================//
-// //
-// P R I V A T E D E F I N I T I O N S //
-// //
-//=========================================================================//
-
-//---------------------------------------------------------------------------
-// const defines
-//---------------------------------------------------------------------------
-
-// TracePoint support for realtime-debugging
-#ifdef _DBG_TRACE_POINTS_
-void TgtDbgSignalTracePoint(u8 bTracePointNumber_p);
-void TgtDbgPostTraceValue(u32 dwTraceValue_p);
-#define TGT_DBG_SIGNAL_TRACE_POINT(p) TgtDbgSignalTracePoint(p)
-#define TGT_DBG_POST_TRACE_VALUE(v) TgtDbgPostTraceValue(v)
-#else
-#define TGT_DBG_SIGNAL_TRACE_POINT(p)
-#define TGT_DBG_POST_TRACE_VALUE(v)
-#endif
-#define EPL_NMTMNU_DBG_POST_TRACE_VALUE(Event_p, uiNodeId_p, wErrorCode_p) \
- TGT_DBG_POST_TRACE_VALUE((kEplEventSinkNmtMnu << 28) | (Event_p << 24) \
- | (uiNodeId_p << 16) | wErrorCode_p)
-
-// defines for flags in node info structure
-#define EPL_NMTMNU_NODE_FLAG_ISOCHRON 0x0001 // CN is being accessed isochronously
-#define EPL_NMTMNU_NODE_FLAG_NOT_SCANNED 0x0002 // CN was not scanned once -> decrement SignalCounter and reset flag
-#define EPL_NMTMNU_NODE_FLAG_HALTED 0x0004 // boot process for this CN is halted
-#define EPL_NMTMNU_NODE_FLAG_NMT_CMD_ISSUED 0x0008 // NMT command was just issued, wrong NMT states will be tolerated
-#define EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ 0x0300 // counter for StatusRequest timer handle
-#define EPL_NMTMNU_NODE_FLAG_COUNT_LONGER 0x0C00 // counter for longer timeouts timer handle
-#define EPL_NMTMNU_NODE_FLAG_INC_STATREQ 0x0100 // increment for StatusRequest timer handle
-#define EPL_NMTMNU_NODE_FLAG_INC_LONGER 0x0400 // increment for longer timeouts timer handle
- // These counters will be incremented at every timer start
- // and copied to timerarg. When the timer event occures
- // both will be compared and if unequal the timer event
- // will be discarded, because it is an old one.
-
-// defines for timer arguments to draw a distinction between serveral events
-#define EPL_NMTMNU_TIMERARG_NODE_MASK 0x000000FFL // mask that contains the node-ID
-#define EPL_NMTMNU_TIMERARG_IDENTREQ 0x00010000L // timer event is for IdentRequest
-#define EPL_NMTMNU_TIMERARG_STATREQ 0x00020000L // timer event is for StatusRequest
-#define EPL_NMTMNU_TIMERARG_LONGER 0x00040000L // timer event is for longer timeouts
-#define EPL_NMTMNU_TIMERARG_STATE_MON 0x00080000L // timer event for StatusRequest to monitor execution of NMT state changes
-#define EPL_NMTMNU_TIMERARG_COUNT_SR 0x00000300L // counter for StatusRequest
-#define EPL_NMTMNU_TIMERARG_COUNT_LO 0x00000C00L // counter for longer timeouts
- // The counters must have the same position as in the node flags above.
-
-#define EPL_NMTMNU_SET_FLAGS_TIMERARG_STATREQ(pNodeInfo_p, uiNodeId_p, TimerArg_p) \
- pNodeInfo_p->m_wFlags = \
- ((pNodeInfo_p->m_wFlags + EPL_NMTMNU_NODE_FLAG_INC_STATREQ) \
- & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) \
- | (pNodeInfo_p->m_wFlags & ~EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
- TimerArg_p.m_ulArg = EPL_NMTMNU_TIMERARG_STATREQ | uiNodeId_p | \
- (pNodeInfo_p->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
- TimerArg_p.m_EventSink = kEplEventSinkNmtMnu;
-
-#define EPL_NMTMNU_SET_FLAGS_TIMERARG_IDENTREQ(pNodeInfo_p, uiNodeId_p, TimerArg_p) \
- pNodeInfo_p->m_wFlags = \
- ((pNodeInfo_p->m_wFlags + EPL_NMTMNU_NODE_FLAG_INC_STATREQ) \
- & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) \
- | (pNodeInfo_p->m_wFlags & ~EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
- TimerArg_p.m_ulArg = EPL_NMTMNU_TIMERARG_IDENTREQ | uiNodeId_p | \
- (pNodeInfo_p->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
- TimerArg_p.m_EventSink = kEplEventSinkNmtMnu;
-
-#define EPL_NMTMNU_SET_FLAGS_TIMERARG_LONGER(pNodeInfo_p, uiNodeId_p, TimerArg_p) \
- pNodeInfo_p->m_wFlags = \
- ((pNodeInfo_p->m_wFlags + EPL_NMTMNU_NODE_FLAG_INC_LONGER) \
- & EPL_NMTMNU_NODE_FLAG_COUNT_LONGER) \
- | (pNodeInfo_p->m_wFlags & ~EPL_NMTMNU_NODE_FLAG_COUNT_LONGER); \
- TimerArg_p.m_ulArg = EPL_NMTMNU_TIMERARG_LONGER | uiNodeId_p | \
- (pNodeInfo_p->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_LONGER); \
- TimerArg_p.m_EventSink = kEplEventSinkNmtMnu;
-
-#define EPL_NMTMNU_SET_FLAGS_TIMERARG_STATE_MON(pNodeInfo_p, uiNodeId_p, TimerArg_p) \
- pNodeInfo_p->m_wFlags = \
- ((pNodeInfo_p->m_wFlags + EPL_NMTMNU_NODE_FLAG_INC_STATREQ) \
- & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) \
- | (pNodeInfo_p->m_wFlags & ~EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
- TimerArg_p.m_ulArg = EPL_NMTMNU_TIMERARG_STATE_MON | uiNodeId_p | \
- (pNodeInfo_p->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ); \
- TimerArg_p.m_EventSink = kEplEventSinkNmtMnu;
-
-// defines for global flags
-#define EPL_NMTMNU_FLAG_HALTED 0x0001 // boot process is halted
-#define EPL_NMTMNU_FLAG_APP_INFORMED 0x0002 // application was informed about possible NMT state change
-
-// return pointer to node info structure for specified node ID
-// d.k. may be replaced by special (hash) function if node ID array is smaller than 254
-#define EPL_NMTMNU_GET_NODEINFO(uiNodeId_p) (&EplNmtMnuInstance_g.m_aNodeInfo[uiNodeId_p - 1])
-
-//---------------------------------------------------------------------------
-// local types
-//---------------------------------------------------------------------------
-
-typedef enum {
- kEplNmtMnuIntNodeEventNoIdentResponse = 0x00,
- kEplNmtMnuIntNodeEventIdentResponse = 0x01,
- kEplNmtMnuIntNodeEventBoot = 0x02,
- kEplNmtMnuIntNodeEventExecReset = 0x03,
- kEplNmtMnuIntNodeEventConfigured = 0x04,
- kEplNmtMnuIntNodeEventNoStatusResponse = 0x05,
- kEplNmtMnuIntNodeEventStatusResponse = 0x06,
- kEplNmtMnuIntNodeEventHeartbeat = 0x07,
- kEplNmtMnuIntNodeEventNmtCmdSent = 0x08,
- kEplNmtMnuIntNodeEventTimerIdentReq = 0x09,
- kEplNmtMnuIntNodeEventTimerStatReq = 0x0A,
- kEplNmtMnuIntNodeEventTimerStateMon = 0x0B,
- kEplNmtMnuIntNodeEventTimerLonger = 0x0C,
- kEplNmtMnuIntNodeEventError = 0x0D,
-
-} tEplNmtMnuIntNodeEvent;
-
-typedef enum {
- kEplNmtMnuNodeStateUnknown = 0x00,
- kEplNmtMnuNodeStateIdentified = 0x01,
- kEplNmtMnuNodeStateResetConf = 0x02, // CN reset after configuration update
- kEplNmtMnuNodeStateConfigured = 0x03, // BootStep1 completed
- kEplNmtMnuNodeStateReadyToOp = 0x04, // BootStep2 completed
- kEplNmtMnuNodeStateComChecked = 0x05, // Communication checked successfully
- kEplNmtMnuNodeStateOperational = 0x06, // CN is in NMT state OPERATIONAL
-
-} tEplNmtMnuNodeState;
-
-typedef struct {
- tEplTimerHdl m_TimerHdlStatReq; // timer to delay StatusRequests and IdentRequests
- tEplTimerHdl m_TimerHdlLonger; // 2nd timer for NMT command EnableReadyToOp and CheckCommunication
- tEplNmtMnuNodeState m_NodeState; // internal node state (kind of sub state of NMT state)
- u32 m_dwNodeCfg; // subindex from 0x1F81
- u16 m_wFlags; // flags: CN is being accessed isochronously
-
-} tEplNmtMnuNodeInfo;
-
-typedef struct {
- tEplNmtMnuNodeInfo m_aNodeInfo[EPL_NMT_MAX_NODE_ID];
- tEplTimerHdl m_TimerHdlNmtState; // timeout for stay in NMT state
- unsigned int m_uiMandatorySlaveCount;
- unsigned int m_uiSignalSlaveCount;
- unsigned long m_ulStatusRequestDelay; // in [ms] (object 0x1006 * EPL_C_NMT_STATREQ_CYCLE)
- unsigned long m_ulTimeoutReadyToOp; // in [ms] (object 0x1F89/5)
- unsigned long m_ulTimeoutCheckCom; // in [ms] (object 0x1006 * MultiplexedCycleCount)
- u16 m_wFlags; // global flags
- u32 m_dwNmtStartup; // object 0x1F80 NMT_StartUp_U32
- tEplNmtMnuCbNodeEvent m_pfnCbNodeEvent;
- tEplNmtMnuCbBootEvent m_pfnCbBootEvent;
-
-} tEplNmtMnuInstance;
-
-//---------------------------------------------------------------------------
-// local vars
-//---------------------------------------------------------------------------
-
-static tEplNmtMnuInstance EplNmtMnuInstance_g;
-
-//---------------------------------------------------------------------------
-// local function prototypes
-//---------------------------------------------------------------------------
-
-static tEplKernel EplNmtMnuCbNmtRequest(tEplFrameInfo *pFrameInfo_p);
-
-static tEplKernel EplNmtMnuCbIdentResponse(unsigned int uiNodeId_p,
- tEplIdentResponse *pIdentResponse_p);
-
-static tEplKernel EplNmtMnuCbStatusResponse(unsigned int uiNodeId_p,
- tEplStatusResponse *pStatusResponse_p);
-
-static tEplKernel EplNmtMnuCheckNmtState(unsigned int uiNodeId_p,
- tEplNmtMnuNodeInfo * pNodeInfo_p,
- tEplNmtState NodeNmtState_p,
- u16 wErrorCode_p,
- tEplNmtState LocalNmtState_p);
-
-static tEplKernel EplNmtMnuStartBootStep1(void);
-
-static tEplKernel EplNmtMnuStartBootStep2(void);
-
-static tEplKernel EplNmtMnuStartCheckCom(void);
-
-static tEplKernel EplNmtMnuNodeBootStep2(unsigned int uiNodeId_p,
- tEplNmtMnuNodeInfo * pNodeInfo_p);
-
-static tEplKernel EplNmtMnuNodeCheckCom(unsigned int uiNodeId_p,
- tEplNmtMnuNodeInfo * pNodeInfo_p);
-
-static tEplKernel EplNmtMnuStartNodes(void);
-
-static tEplKernel EplNmtMnuProcessInternalEvent(unsigned int uiNodeId_p,
- tEplNmtState NodeNmtState_p,
- u16 wErrorCode_p,
- tEplNmtMnuIntNodeEvent
- NodeEvent_p);
-
-static tEplKernel EplNmtMnuReset(void);
-
-//=========================================================================//
-// //
-// P U B L I C F U N C T I O N S //
-// //
-//=========================================================================//
-
-//---------------------------------------------------------------------------
-//
-// Function: EplNmtMnuInit
-//
-// Description: init first instance of the module
-//
-//
-//
-// Parameters:
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplNmtMnuInit(tEplNmtMnuCbNodeEvent pfnCbNodeEvent_p,
- tEplNmtMnuCbBootEvent pfnCbBootEvent_p)
-{
- tEplKernel Ret;
-
- Ret = EplNmtMnuAddInstance(pfnCbNodeEvent_p, pfnCbBootEvent_p);
-
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplNmtMnuAddInstance
-//
-// Description: init other instances of the module
-//
-//
-//
-// Parameters:
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplNmtMnuAddInstance(tEplNmtMnuCbNodeEvent pfnCbNodeEvent_p,
- tEplNmtMnuCbBootEvent pfnCbBootEvent_p)
-{
- tEplKernel Ret;
-
- Ret = kEplSuccessful;
-
- // reset instance structure
- EPL_MEMSET(&EplNmtMnuInstance_g, 0, sizeof(EplNmtMnuInstance_g));
-
- if ((pfnCbNodeEvent_p == NULL) || (pfnCbBootEvent_p == NULL)) {
- Ret = kEplNmtInvalidParam;
- goto Exit;
- }
- EplNmtMnuInstance_g.m_pfnCbNodeEvent = pfnCbNodeEvent_p;
- EplNmtMnuInstance_g.m_pfnCbBootEvent = pfnCbBootEvent_p;
-
- // initialize StatusRequest delay
- EplNmtMnuInstance_g.m_ulStatusRequestDelay = 5000L;
-
- // register NmtMnResponse callback function
- Ret =
- EplDlluCalRegAsndService(kEplDllAsndNmtRequest,
- EplNmtMnuCbNmtRequest,
- kEplDllAsndFilterLocal);
-
- Exit:
- return Ret;
-
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplNmtMnuDelInstance
-//
-// Description: delete instance
-//
-//
-//
-// Parameters:
-//
-//
-// Returns: tEplKernel = errorcode
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplNmtMnuDelInstance(void)
-{
- tEplKernel Ret;
-
- Ret = kEplSuccessful;
-
- // deregister NmtMnResponse callback function
- Ret =
- EplDlluCalRegAsndService(kEplDllAsndNmtRequest, NULL,
- kEplDllAsndFilterNone);
-
- Ret = EplNmtMnuReset();
-
- return Ret;
-
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplNmtMnuSendNmtCommandEx
-//
-// Description: sends the specified NMT command to the specified node.
-//
-// Parameters: uiNodeId_p = node ID to which the NMT command will be sent
-// NmtCommand_p = NMT command
-//
-// Returns: tEplKernel = error code
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplNmtMnuSendNmtCommandEx(unsigned int uiNodeId_p,
- tEplNmtCommand NmtCommand_p,
- void *pNmtCommandData_p,
- unsigned int uiDataSize_p)
-{
- tEplKernel Ret = kEplSuccessful;
- tEplFrameInfo FrameInfo;
- u8 abBuffer[EPL_C_DLL_MINSIZE_NMTCMDEXT];
- tEplFrame *pFrame = (tEplFrame *) abBuffer;
- BOOL fSoftDeleteNode = FALSE;
-
- if ((uiNodeId_p == 0) || (uiNodeId_p > EPL_C_ADR_BROADCAST)) { // invalid node ID specified
- Ret = kEplInvalidNodeId;
- goto Exit;
- }
-
- if ((pNmtCommandData_p != NULL)
- && (uiDataSize_p >
- (EPL_C_DLL_MINSIZE_NMTCMDEXT - EPL_C_DLL_MINSIZE_NMTCMD))) {
- Ret = kEplNmtInvalidParam;
- goto Exit;
- }
- // $$$ d.k. may be check in future versions if the caller wants to perform prohibited state transitions
- // the CN should not perform these transitions, but the expected NMT state will be changed and never fullfilled.
-
- // build frame
- EPL_MEMSET(pFrame, 0x00, sizeof(abBuffer));
- AmiSetByteToLe(&pFrame->m_le_bDstNodeId, (u8) uiNodeId_p);
- AmiSetByteToLe(&pFrame->m_Data.m_Asnd.m_le_bServiceId,
- (u8) kEplDllAsndNmtCommand);
- AmiSetByteToLe(&pFrame->m_Data.m_Asnd.m_Payload.m_NmtCommandService.
- m_le_bNmtCommandId, (u8) NmtCommand_p);
- if ((pNmtCommandData_p != NULL) && (uiDataSize_p > 0)) { // copy command data to frame
- EPL_MEMCPY(&pFrame->m_Data.m_Asnd.m_Payload.m_NmtCommandService.
- m_le_abNmtCommandData[0], pNmtCommandData_p,
- uiDataSize_p);
- }
- // build info structure
- FrameInfo.m_NetTime.m_dwNanoSec = 0;
- FrameInfo.m_NetTime.m_dwSec = 0;
- FrameInfo.m_pFrame = pFrame;
- FrameInfo.m_uiFrameSize = sizeof(abBuffer);
-
- // send NMT-Request
-#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0)
- Ret = EplDlluCalAsyncSend(&FrameInfo, // pointer to frameinfo
- kEplDllAsyncReqPrioNmt); // priority
-#endif
- if (Ret != kEplSuccessful) {
- goto Exit;
- }
-
- EPL_DBGLVL_NMTMN_TRACE2("NMTCmd(%02X->%02X)\n", NmtCommand_p,
- uiNodeId_p);
-
- switch (NmtCommand_p) {
- case kEplNmtCmdStartNode:
- case kEplNmtCmdEnterPreOperational2:
- case kEplNmtCmdEnableReadyToOperate:
- {
- // nothing left to do,
- // because any further processing is done
- // when the NMT command is actually sent
- goto Exit;
- }
-
- case kEplNmtCmdStopNode:
- {
- fSoftDeleteNode = TRUE;
- break;
- }
-
- case kEplNmtCmdResetNode:
- case kEplNmtCmdResetCommunication:
- case kEplNmtCmdResetConfiguration:
- case kEplNmtCmdSwReset:
- {
- break;
- }
-
- default:
- goto Exit;
- }
-
- // remove CN from isochronous phase;
- // This must be done here and not when NMT command is actually sent
- // because it will be too late and may cause unwanted errors
- if (uiNodeId_p != EPL_C_ADR_BROADCAST) {
- if (fSoftDeleteNode == FALSE) { // remove CN immediately from isochronous phase
- Ret = EplDlluCalDeleteNode(uiNodeId_p);
- } else { // remove CN from isochronous phase softly
- Ret = EplDlluCalSoftDeleteNode(uiNodeId_p);
- }
- } else { // do it for all active CNs
- for (uiNodeId_p = 1;
- uiNodeId_p <= tabentries(EplNmtMnuInstance_g.m_aNodeInfo);
- uiNodeId_p++) {
- if ((EPL_NMTMNU_GET_NODEINFO(uiNodeId_p)->
- m_dwNodeCfg & (EPL_NODEASSIGN_NODE_IS_CN |
- EPL_NODEASSIGN_NODE_EXISTS)) != 0) {
- if (fSoftDeleteNode == FALSE) { // remove CN immediately from isochronous phase
- Ret = EplDlluCalDeleteNode(uiNodeId_p);
- } else { // remove CN from isochronous phase softly
- Ret =
- EplDlluCalSoftDeleteNode
- (uiNodeId_p);
- }
- }
- }
- }
-
- Exit:
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplNmtMnuSendNmtCommand
-//
-// Description: sends the specified NMT command to the specified node.
-//
-// Parameters: uiNodeId_p = node ID to which the NMT command will be sent
-// NmtCommand_p = NMT command
-//
-// Returns: tEplKernel = error code
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplNmtMnuSendNmtCommand(unsigned int uiNodeId_p,
- tEplNmtCommand NmtCommand_p)
-{
- tEplKernel Ret = kEplSuccessful;
-
- Ret = EplNmtMnuSendNmtCommandEx(uiNodeId_p, NmtCommand_p, NULL, 0);
-
-//Exit:
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplNmtMnuTriggerStateChange
-//
-// Description: triggers the specified node command for the specified node.
-//
-// Parameters: uiNodeId_p = node ID for which the node command will be executed
-// NodeCommand_p = node command
-//
-// Returns: tEplKernel = error code
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplNmtMnuTriggerStateChange(unsigned int uiNodeId_p,
- tEplNmtNodeCommand NodeCommand_p)
-{
- tEplKernel Ret = kEplSuccessful;
- tEplNmtMnuIntNodeEvent NodeEvent;
- tEplObdSize ObdSize;
- u8 bNmtState;
- u16 wErrorCode = EPL_E_NO_ERROR;
-
- if ((uiNodeId_p == 0) || (uiNodeId_p >= EPL_C_ADR_BROADCAST)) {
- Ret = kEplInvalidNodeId;
- goto Exit;
- }
-
- switch (NodeCommand_p) {
- case kEplNmtNodeCommandBoot:
- {
- NodeEvent = kEplNmtMnuIntNodeEventBoot;
- break;
- }
-
- case kEplNmtNodeCommandConfOk:
- {
- NodeEvent = kEplNmtMnuIntNodeEventConfigured;
- break;
- }
-
- case kEplNmtNodeCommandConfErr:
- {
- NodeEvent = kEplNmtMnuIntNodeEventError;
- wErrorCode = EPL_E_NMT_BPO1_CF_VERIFY;
- break;
- }
-
- case kEplNmtNodeCommandConfReset:
- {
- NodeEvent = kEplNmtMnuIntNodeEventExecReset;
- break;
- }
-
- default:
- { // invalid node command
- goto Exit;
- }
- }
-
- // fetch current NMT state
- ObdSize = 1;
- Ret = EplObduReadEntry(0x1F8E, uiNodeId_p, &bNmtState, &ObdSize);
- if (Ret != kEplSuccessful) {
- goto Exit;
- }
-
- Ret = EplNmtMnuProcessInternalEvent(uiNodeId_p,
- (tEplNmtState) (bNmtState |
- EPL_NMT_TYPE_CS),
- wErrorCode, NodeEvent);
-
- Exit:
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplNmtMnuCbNmtStateChange
-//
-// Description: callback function for NMT state changes
-//
-// Parameters: NmtStateChange_p = NMT state change event
-//
-// Returns: tEplKernel = error code
-//
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplNmtMnuCbNmtStateChange(tEplEventNmtStateChange NmtStateChange_p)
-{
- tEplKernel Ret = kEplSuccessful;
-
- // do work which must be done in that state
- switch (NmtStateChange_p.m_NewNmtState) {
- // EPL stack is not running
-/* case kEplNmtGsOff:
- break;
-
- // first init of the hardware
- case kEplNmtGsInitialising:
- break;
-
- // init of the manufacturer-specific profile area and the
- // standardised device profile area
- case kEplNmtGsResetApplication:
- {
- break;
- }
-
- // init of the communication profile area
- case kEplNmtGsResetCommunication:
- {
- break;
- }
-*/
- // build the configuration with infos from OD
- case kEplNmtGsResetConfiguration:
- {
- u32 dwTimeout;
- tEplObdSize ObdSize;
-
- // read object 0x1F80 NMT_StartUp_U32
- ObdSize = 4;
- Ret =
- EplObduReadEntry(0x1F80, 0,
- &EplNmtMnuInstance_g.
- m_dwNmtStartup, &ObdSize);
- if (Ret != kEplSuccessful) {
- break;
- }
- // compute StatusReqDelay = object 0x1006 * EPL_C_NMT_STATREQ_CYCLE
- ObdSize = sizeof(dwTimeout);
- Ret = EplObduReadEntry(0x1006, 0, &dwTimeout, &ObdSize);
- if (Ret != kEplSuccessful) {
- break;
- }
- if (dwTimeout != 0L) {
- EplNmtMnuInstance_g.m_ulStatusRequestDelay =
- dwTimeout * EPL_C_NMT_STATREQ_CYCLE / 1000L;
- if (EplNmtMnuInstance_g.
- m_ulStatusRequestDelay == 0L) {
- EplNmtMnuInstance_g.m_ulStatusRequestDelay = 1L; // at least 1 ms
- }
- // $$$ fetch and use MultiplexedCycleCount from OD
- EplNmtMnuInstance_g.m_ulTimeoutCheckCom =
- dwTimeout * EPL_C_NMT_STATREQ_CYCLE / 1000L;
- if (EplNmtMnuInstance_g.m_ulTimeoutCheckCom ==
- 0L) {
- EplNmtMnuInstance_g.m_ulTimeoutCheckCom = 1L; // at least 1 ms
- }
- }
- // fetch ReadyToOp Timeout from OD
- ObdSize = sizeof(dwTimeout);
- Ret = EplObduReadEntry(0x1F89, 5, &dwTimeout, &ObdSize);
- if (Ret != kEplSuccessful) {
- break;
- }
- if (dwTimeout != 0L) {
- // convert [us] to [ms]
- dwTimeout /= 1000L;
- if (dwTimeout == 0L) {
- dwTimeout = 1L; // at least 1 ms
- }
- EplNmtMnuInstance_g.m_ulTimeoutReadyToOp =
- dwTimeout;
- } else {
- EplNmtMnuInstance_g.m_ulTimeoutReadyToOp = 0L;
- }
- break;
- }
-/*
- //-----------------------------------------------------------
- // CN part of the state machine
-
- // node liste for EPL-Frames and check timeout
- case kEplNmtCsNotActive:
- {
- break;
- }
-
- // node process only async frames
- case kEplNmtCsPreOperational1:
- {
- break;
- }
-
- // node process isochronus and asynchronus frames
- case kEplNmtCsPreOperational2:
- {
- break;
- }
-
- // node should be configured und application is ready
- case kEplNmtCsReadyToOperate:
- {
- break;
- }
-
- // normal work state
- case kEplNmtCsOperational:
- {
- break;
- }
-
- // node stopped by MN
- // -> only process asynchronus frames
- case kEplNmtCsStopped:
- {
- break;
- }
-
- // no EPL cycle
- // -> normal ethernet communication
- case kEplNmtCsBasicEthernet:
- {
- break;
- }
-*/
- //-----------------------------------------------------------
- // MN part of the state machine
-
- // node listens for EPL-Frames and check timeout
- case kEplNmtMsNotActive:
- {
- break;
- }
-
- // node processes only async frames
- case kEplNmtMsPreOperational1:
- {
- u32 dwTimeout;
- tEplTimerArg TimerArg;
- tEplObdSize ObdSize;
- tEplEvent Event;
-
- // clear global flags, e.g. reenable boot process
- EplNmtMnuInstance_g.m_wFlags = 0;
-
- // reset IdentResponses and running IdentRequests and StatusRequests
- Ret = EplIdentuReset();
- Ret = EplStatusuReset();
-
- // reset timers
- Ret = EplNmtMnuReset();
-
- // 2008/11/18 d.k. reset internal node info is not necessary,
- // because timer flags are important and other
- // things are reset by EplNmtMnuStartBootStep1().
-/*
- EPL_MEMSET(EplNmtMnuInstance_g.m_aNodeInfo,
- 0,
- sizeof (EplNmtMnuInstance_g.m_aNodeInfo));
-*/
-
- // inform DLL about NMT state change,
- // so that it can clear the asynchonous queues and start the reduced cycle
- Event.m_EventSink = kEplEventSinkDllk;
- Event.m_EventType = kEplEventTypeDllkStartReducedCycle;
- EPL_MEMSET(&Event.m_NetTime, 0x00,
- sizeof(Event.m_NetTime));
- Event.m_pArg = NULL;
- Event.m_uiSize = 0;
- Ret = EplEventuPost(&Event);
- if (Ret != kEplSuccessful) {
- break;
- }
- // reset all nodes
- // d.k.: skip this step if was just done before, e.g. because of a ResetNode command from a diagnostic node
- if (NmtStateChange_p.m_NmtEvent ==
- kEplNmtEventTimerMsPreOp1) {
- BENCHMARK_MOD_07_TOGGLE(9);
-
- EPL_NMTMNU_DBG_POST_TRACE_VALUE(0,
- EPL_C_ADR_BROADCAST,
- kEplNmtCmdResetNode);
-
- Ret =
- EplNmtMnuSendNmtCommand(EPL_C_ADR_BROADCAST,
- kEplNmtCmdResetNode);
- if (Ret != kEplSuccessful) {
- break;
- }
- }
- // start network scan
- Ret = EplNmtMnuStartBootStep1();
-
- // start timer for 0x1F89/2 MNTimeoutPreOp1_U32
- ObdSize = sizeof(dwTimeout);
- Ret = EplObduReadEntry(0x1F89, 2, &dwTimeout, &ObdSize);
- if (Ret != kEplSuccessful) {
- break;
- }
- if (dwTimeout != 0L) {
- dwTimeout /= 1000L;
- if (dwTimeout == 0L) {
- dwTimeout = 1L; // at least 1 ms
- }
- TimerArg.m_EventSink = kEplEventSinkNmtMnu;
- TimerArg.m_ulArg = 0;
- Ret =
- EplTimeruModifyTimerMs(&EplNmtMnuInstance_g.
- m_TimerHdlNmtState,
- dwTimeout, TimerArg);
- }
- break;
- }
-
- // node processes isochronous and asynchronous frames
- case kEplNmtMsPreOperational2:
- {
- // add identified CNs to isochronous phase
- // send EnableReadyToOp to all identified CNs
- Ret = EplNmtMnuStartBootStep2();
-
- // wait for NMT state change of CNs
- break;
- }
-
- // node should be configured und application is ready
- case kEplNmtMsReadyToOperate:
- {
- // check if PRes of CNs are OK
- // d.k. that means wait CycleLength * MultiplexCycleCount (i.e. start timer)
- // because Dllk checks PRes of CNs automatically in ReadyToOp
- Ret = EplNmtMnuStartCheckCom();
- break;
- }
-
- // normal work state
- case kEplNmtMsOperational:
- {
- // send StartNode to CNs
- // wait for NMT state change of CNs
- Ret = EplNmtMnuStartNodes();
- break;
- }
-
- // no EPL cycle
- // -> normal ethernet communication
- case kEplNmtMsBasicEthernet:
- {
- break;
- }
-
- default:
- {
-// TRACE0("EplNmtMnuCbNmtStateChange(): unhandled NMT state\n");
- }
- }
-
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplNmtMnuCbCheckEvent
-//
-// Description: callback funktion for NMT events before they are actually executed.
-// The EPL API layer must forward NMT events from NmtCnu module.
-// This module will reject some NMT commands while MN.
-//
-// Parameters: NmtEvent_p = outstanding NMT event for approval
-//
-// Returns: tEplKernel = error code
-// kEplReject = reject the NMT event
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplNmtMnuCbCheckEvent(tEplNmtEvent NmtEvent_p)
-{
- tEplKernel Ret = kEplSuccessful;
-
- return Ret;
-}
-
-//---------------------------------------------------------------------------
-//
-// Function: EplNmtuProcessEvent
-//
-// Description: processes events from event queue
-//
-// Parameters: pEvent_p = pointer to event
-//
-// Returns: tEplKernel = errorcode
-//
-// State:
-//
-//---------------------------------------------------------------------------
-
-tEplKernel EplNmtMnuProcessEvent(tEplEvent *pEvent_p)
-{
- tEplKernel Ret;
-
- Ret = kEplSuccessful;
-
- // process event
- switch (pEvent_p->m_EventType) {
- // timer event
- case kEplEventTypeTimer:
- {
- tEplTimerEventArg *pTimerEventArg =
- (tEplTimerEventArg *) pEvent_p->m_pArg;
- unsigned int uiNodeId;
-
- uiNodeId =
- (unsigned int)(pTimerEventArg->
- m_ulArg &
- EPL_NMTMNU_TIMERARG_NODE_MASK);
- if (uiNodeId != 0) {
- tEplObdSize ObdSize;
- u8 bNmtState;
- tEplNmtMnuNodeInfo *pNodeInfo;
-
- pNodeInfo = EPL_NMTMNU_GET_NODEINFO(uiNodeId);
-
- ObdSize = 1;
- Ret =
- EplObduReadEntry(0x1F8E, uiNodeId,
- &bNmtState, &ObdSize);
- if (Ret != kEplSuccessful) {
- break;
- }
-
- if ((pTimerEventArg->
- m_ulArg & EPL_NMTMNU_TIMERARG_IDENTREQ) !=
- 0L) {
- if ((pNodeInfo->
- m_wFlags &
- EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ)
- != (pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR)) { // this is an old (already deleted or modified) timer
- // but not the current timer
- // so discard it
- EPL_NMTMNU_DBG_POST_TRACE_VALUE
- (kEplNmtMnuIntNodeEventTimerIdentReq,
- uiNodeId,
- ((pNodeInfo->
- m_NodeState << 8)
- | 0xFF));
-
- break;
- }
-/*
- EPL_NMTMNU_DBG_POST_TRACE_VALUE(kEplNmtMnuIntNodeEventTimerIdentReq,
- uiNodeId,
- ((pNodeInfo->m_NodeState << 8)
- | 0x80
- | ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) >> 6)
- | ((pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR) >> 8)));
-*/
- Ret =
- EplNmtMnuProcessInternalEvent
- (uiNodeId,
- (tEplNmtState) (bNmtState |
- EPL_NMT_TYPE_CS),
- EPL_E_NO_ERROR,
- kEplNmtMnuIntNodeEventTimerIdentReq);
- }
-
- else if ((pTimerEventArg->
- m_ulArg & EPL_NMTMNU_TIMERARG_STATREQ)
- != 0L) {
- if ((pNodeInfo->
- m_wFlags &
- EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ)
- != (pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR)) { // this is an old (already deleted or modified) timer
- // but not the current timer
- // so discard it
- EPL_NMTMNU_DBG_POST_TRACE_VALUE
- (kEplNmtMnuIntNodeEventTimerStatReq,
- uiNodeId,
- ((pNodeInfo->
- m_NodeState << 8)
- | 0xFF));
-
- break;
- }
-/*
- EPL_NMTMNU_DBG_POST_TRACE_VALUE(kEplNmtMnuIntNodeEventTimerStatReq,
- uiNodeId,
- ((pNodeInfo->m_NodeState << 8)
- | 0x80
- | ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) >> 6)
- | ((pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR) >> 8)));
-*/
- Ret =
- EplNmtMnuProcessInternalEvent
- (uiNodeId,
- (tEplNmtState) (bNmtState |
- EPL_NMT_TYPE_CS),
- EPL_E_NO_ERROR,
- kEplNmtMnuIntNodeEventTimerStatReq);
- }
-
- else if ((pTimerEventArg->
- m_ulArg &
- EPL_NMTMNU_TIMERARG_STATE_MON) !=
- 0L) {
- if ((pNodeInfo->
- m_wFlags &
- EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ)
- != (pTimerEventArg->m_ulArg & EPL_NMTMNU_TIMERARG_COUNT_SR)) { // this is an old (already deleted or modified) timer
- // but not the current timer
- // so discard it
- EPL_NMTMNU_DBG_POST_TRACE_VALUE
- (kEplNmtMnuIntNodeEventTimerStateMon,
- uiNodeId,
- ((pNodeInfo->
- m_NodeState << 8)
- | 0xFF));
-
- break;
- }
-/*
- EPL_NMTMNU_DBG_POST_TRACE_VALUE(kEplNmtMnuIntNodeEventTimerStatReq,
- uiNodeId,
- ((pNodeInfo->m_NodeState << 8)
- | 0x80
- | ((pNodeInfo->m_wFlags & EPL_NMTMNU_NODE_FLAG_COUNT_STATREQ) >> 6)
-