Exemplo n.º 1
0
//------------------------------------------------------------------------------
static BOOL processCnStateChange(tNmtState newNmtState_p, tOplkError* pRet_p)
{
    tOplkError          ret = kErrorOk;
    BOOL                fHandled = TRUE;
    UINT32              basicEthernetTimeout;
    tObdSize            obdSize;

    switch (newNmtState_p)
    {
        // node listens for POWERLINK frames and check timeout
        case kNmtCsNotActive:
            // create timer to switch automatically to BasicEthernet if no MN
            // is available in the network
            // read NMT_CNBasicEthernetTimeout_U32 from OD
            obdSize = sizeof(basicEthernetTimeout);
            ret = obd_readEntry(0x1F99, 0x00, &basicEthernetTimeout, &obdSize);
            if (ret != kErrorOk)
                break;

            if (basicEthernetTimeout != 0)
            {   // BasicEthernet is enabled
                ret = setupNmtTimerEvent(basicEthernetTimeout, kNmtEventTimerBasicEthernet);
                // potential error is forwarded to event queue which generates error event
            }
            break;

        // node processes only async frames
        case kNmtCsPreOperational1:
            break;

        // node processes isochronous and asynchronous frames
        case kNmtCsPreOperational2:
            ret = nmtu_postNmtEvent(kNmtEventEnterReadyToOperate);
            break;

        // node should be configured and application is ready
        case kNmtCsReadyToOperate:
            break;

        // normal work state
        case kNmtCsOperational:
            break;

        // node stopped by MN
        // -> only process asynchronous frames
        case kNmtCsStopped:
            break;

        // no POWERLINK cycle
        // -> normal ethernet communication
        case kNmtCsBasicEthernet:
            break;

        default:
            fHandled = FALSE;
            break;
    }
    *pRet_p = ret;
    return fHandled;
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
static BOOL processGeneralStateChange(tNmtState newNmtState_p, tOplkError* pRet_p)
{
    tOplkError          ret = kErrorOk;
    UINT                nodeId;
    BOOL                fHandled = TRUE;
#if defined(CONFIG_INCLUDE_NMT_RMN)
    UINT32              startUp;
    tObdSize            obdSize;
#endif

    switch (newNmtState_p)
    {
        // POWERLINK stack is not running
        case kNmtGsOff:
            break;

        // first init of the hardware
        case kNmtGsInitialising:
            ret = nmtu_postNmtEvent(kNmtEventEnterResetApp);
            break;

        // init of the manufacturer-specific profile area and the
        // standardised device profile area
        case kNmtGsResetApplication:
            ret = nmtu_postNmtEvent(kNmtEventEnterResetCom);
            break;

        // init of the communication profile area
        case kNmtGsResetCommunication:
            ret = nmtu_postNmtEvent(kNmtEventEnterResetConfig);
            break;

        // build the configuration with infos from OD
        case kNmtGsResetConfiguration:
#if NMT_MAX_NODE_ID > 0
            // configure the DLL (PReq/PRes payload limits and PRes timeout)
            ret = configureDll();
            if (ret != kErrorOk)
            {
                break;
            }
#endif // NMT_MAX_NODE_ID > 0

#if defined(CONFIG_INCLUDE_NMT_RMN)
            obdSize = sizeof(startUp);
            ret = obd_readEntry(0x1F80, 0x00, &startUp, &obdSize);
            if (ret != kErrorOk)
                break;

            if ((startUp & NMT_STARTUP_REDUNDANCY) != 0)
            {   // NMT_StartUp_U32.Bit14 == 1
                ret = nmtu_postNmtEvent(kNmtEventEnterRmsNotActive);
                break;
            }
#endif
            // get node ID from OD
            nodeId = obd_getNodeId();
            //check node ID if not should be master or slave
            if (nodeId == C_ADR_MN_DEF_NODE_ID)
            {   // node shall be MN
#if defined(CONFIG_INCLUDE_NMT_MN)
                ret = nmtu_postNmtEvent(kNmtEventEnterMsNotActive);
#else
                DEBUG_LVL_ERROR_TRACE("processGeneralStateChange(): no MN functionality implemented\n");
#endif
            }
            else
            {   // node shall be CN
                ret = nmtu_postNmtEvent(kNmtEventEnterCsNotActive);
            }
            break;

        default:
            fHandled = FALSE;
            break;
    }

    *pRet_p = ret;
    return fHandled;
}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
static BOOL processMnStateChange(tNmtState newNmtState_p, tOplkError* pRet_p)
{
    tOplkError          ret = kErrorOk;
    BOOL                fHandled = TRUE;
    UINT32              waitTime;
    UINT32              startUp;
    tNmtEvent           timerEvent = kNmtEventTimerMsPreOp1;
    tObdSize            obdSize;

    switch (newNmtState_p)
    {
        // node listens for POWERLINK frames and check timeout
        case kNmtMsNotActive:
            // create timer to switch automatically to BasicEthernet/PreOp1 if no other MN active in network
            // check NMT_StartUp_U32.Bit13
            obdSize = sizeof(startUp);
            ret = obd_readEntry(0x1F80, 0x00, &startUp, &obdSize);
            if (ret != kErrorOk)
                break;

            if ((startUp & NMT_STARTUP_BASICETHERNET) != 0)
            {   // NMT_StartUp_U32.Bit13 == 1 -> new state BasicEthernet
                timerEvent = kNmtEventTimerBasicEthernet;
            }

        // intentional fall through
        case kNmtRmsNotActive:
            // read NMT_BootTime_REC.MNWaitNotAct_U32 from OD
            obdSize = sizeof(waitTime);
            ret = obd_readEntry(0x1F89, 0x01, &waitTime, &obdSize);
            if (ret != kErrorOk)
                break;

            ret = setupNmtTimerEvent(waitTime, timerEvent);
            // potential error is forwarded to event queue which generates error event
            break;

        // node processes only async frames
        case kNmtMsPreOperational1:
            // create timer to switch automatically to PreOp2 if MN identified all mandatory CNs

            // read NMT_BootTime_REC.MNWaitPreOp1_U32 from OD
            obdSize = sizeof(waitTime);
            ret = obd_readEntry(0x1F89, 0x03, &waitTime, &obdSize);
            if (ret != kErrorOk)
            {
                // ignore error, because this timeout is optional
                waitTime = 0;
            }
            if (waitTime == 0)
            {   // delay is deactivated, immediately post timer event
                ret = nmtu_postNmtEvent(kNmtEventTimerMsPreOp2);
            }
            else
            {
                ret = setupNmtTimerEvent(waitTime, kNmtEventTimerMsPreOp2);
            }
            // potential error is forwarded to event queue which generates error event
            break;

        // node processes isochronous and asynchronous frames
        case kNmtMsPreOperational2:
            break;

        // node should be configured and application is ready
        case kNmtMsReadyToOperate:
            break;

        // normal work state
        case kNmtMsOperational:
            break;

        // no POWERLINK cycle
        // -> normal ethernet communication
        case kNmtMsBasicEthernet:
            break;

        default:
            fHandled = FALSE;
            break;
    }
    *pRet_p = ret;
    return fHandled;
}
Exemplo n.º 4
0
//------------------------------------------------------------------------------
static tOplkError commandCb(tFrameInfo* pFrameInfo_p)
{
    tOplkError      ret = kErrorOk;
    tNmtCommand     nmtCommand;
    BOOL            fNodeIdInList;
    tNmtEvent       nmtEvent = kNmtEventNoEvent;

    if (pFrameInfo_p == NULL)
        return kErrorNmtInvalidFramePointer;

    nmtCommand = getNmtCommand(pFrameInfo_p);
    switch (nmtCommand)
    {
        //------------------------------------------------------------------------
        // plain NMT state commands
        case kNmtCmdStartNode:
            nmtEvent = kNmtEventStartNode;
            break;

        case kNmtCmdStopNode:
            nmtEvent = kNmtEventStopNode;
            break;

        case kNmtCmdEnterPreOperational2:
            nmtEvent = kNmtEventEnterPreOperational2;
            break;

        case kNmtCmdEnableReadyToOperate:
            nmtEvent = kNmtEventEnableReadyToOperate;
            break;

        case kNmtCmdResetNode:
            nmtEvent = kNmtEventResetNode;
            break;

        case kNmtCmdResetCommunication:
            nmtEvent = kNmtEventResetCom;
            break;

        case kNmtCmdResetConfiguration:
            nmtEvent = kNmtEventResetConfig;
            break;

        case kNmtCmdSwReset:
            nmtEvent = kNmtEventSwReset;
            break;

        //------------------------------------------------------------------------
        // extended NMT state commands
        case kNmtCmdStartNodeEx:
            // check if own nodeid is in the POWERLINK node list
            fNodeIdInList = checkNodeIdList(&(pFrameInfo_p->frame.pBuffer->data.asnd.payload.nmtCommandService.aNmtCommandData[0]));
            if (fNodeIdInList != FALSE)
            {   // own nodeid in list
                // send event to process command
                nmtEvent = kNmtEventStartNode;
            }
            break;

        case kNmtCmdStopNodeEx:
            // check if own nodeid is in the POWERLINK node list
            fNodeIdInList = checkNodeIdList(&pFrameInfo_p->frame.pBuffer->data.asnd.payload.nmtCommandService.aNmtCommandData[0]);
            if (fNodeIdInList != FALSE)
            {   // own nodeid in list
                // send event to process command
                nmtEvent = kNmtEventStopNode;
            }
            break;

        case kNmtCmdEnterPreOperational2Ex:
            // check if own nodeid is in the POWERLINK node list
            fNodeIdInList = checkNodeIdList(&pFrameInfo_p->frame.pBuffer->data.asnd.payload.nmtCommandService.aNmtCommandData[0]);
            if (fNodeIdInList != FALSE)
            {   // own nodeid in list
                // send event to process command
                nmtEvent = kNmtEventEnterPreOperational2;
            }
            break;

        case kNmtCmdEnableReadyToOperateEx:
            // check if own nodeid is in the POWERLINK node list
            fNodeIdInList = checkNodeIdList(&pFrameInfo_p->frame.pBuffer->data.asnd.payload.nmtCommandService.aNmtCommandData[0]);
            if (fNodeIdInList != FALSE)
            {   // own nodeid in list
                // send event to process command
                nmtEvent = kNmtEventEnableReadyToOperate;
            }
            break;

        case kNmtCmdResetNodeEx:
            // check if own nodeid is in the POWERLINK node list
            fNodeIdInList = checkNodeIdList(&pFrameInfo_p->frame.pBuffer->data.asnd.payload.nmtCommandService.aNmtCommandData[0]);
            if (fNodeIdInList != FALSE)
            {   // own nodeid in list
                // send event to process command
                nmtEvent = kNmtEventResetNode;
            }
            break;

        case kNmtCmdResetCommunicationEx:
            // check if own nodeid is in the POWERLINK node list
            fNodeIdInList = checkNodeIdList(&pFrameInfo_p->frame.pBuffer->data.asnd.payload.nmtCommandService.aNmtCommandData[0]);
            if (fNodeIdInList != FALSE)
            {   // own nodeid in list
                // send event to process command
                nmtEvent = kNmtEventResetCom;
            }
            break;

        case kNmtCmdResetConfigurationEx:
            // check if own nodeid is in the POWERLINK node list
            fNodeIdInList = checkNodeIdList(&pFrameInfo_p->frame.pBuffer->data.asnd.payload.nmtCommandService.aNmtCommandData[0]);
            if (fNodeIdInList != FALSE)
            {   // own nodeid in list
                // send event to process command
                nmtEvent = kNmtEventResetConfig;
            }
            break;

        case kNmtCmdSwResetEx:
            // check if own nodeid is in the POWERLINK node list
            fNodeIdInList = checkNodeIdList(&pFrameInfo_p->frame.pBuffer->data.asnd.payload.nmtCommandService.aNmtCommandData[0]);
            if (fNodeIdInList != FALSE)
            {   // own nodeid in list
                // send event to process command
                nmtEvent = kNmtEventSwReset;
            }
            break;

        //------------------------------------------------------------------------
        // NMT managing commands
        // TODO: add functions to process managing command (optional)
        case kNmtCmdNetHostNameSet:
            break;

        case kNmtCmdFlushArpEntry:
            break;

        //------------------------------------------------------------------------
        // NMT info services
        // TODO: forward event with infos to the application (optional)
        case kNmtCmdPublishConfiguredCN:
            break;

        case kNmtCmdPublishActiveCN:
            break;

        case kNmtCmdPublishPreOperational1:
            break;

        case kNmtCmdPublishPreOperational2:
            break;

        case kNmtCmdPublishReadyToOperate:
            break;

        case kNmtCmdPublishOperational:
            break;

        case kNmtCmdPublishStopped:
            break;

        case kNmtCmdPublishEmergencyNew:
            break;

        case kNmtCmdPublishTime:
            break;

        //-----------------------------------------------------------------------
        // error from MN
        // -> requested command not supported by MN
        case kNmtCmdInvalidService:
            // TODO: errorevent to application
            break;

        //------------------------------------------------------------------------
        // default
        default:
            return kErrorNmtUnknownCommand;
            break;
    } // end of switch (nmtCommand)

    if (nmtEvent != kNmtEventNoEvent)
    {
        if (nmtCnuInstance_g.pfnCheckEventCb != NULL)
        {
            ret = nmtCnuInstance_g.pfnCheckEventCb(nmtEvent);
            if (ret == kErrorReject)
            {
                return kErrorOk;
            }
            else if (ret != kErrorOk)
            {
                return ret;
            }
        }
        ret = nmtu_postNmtEvent(nmtEvent);
    }

    return ret;
}