Example #1
0
tEplKernel EplDllkCalProcess(tEplEvent * pEvent_p)
{
tEplKernel      Ret = kEplSuccessful;

    switch (pEvent_p->m_EventType)
    {
        case kEplEventTypeDllkServFilter:
        {
        tEplDllCalAsndServiceIdFilter*  pServFilter;

            pServFilter = (tEplDllCalAsndServiceIdFilter*) pEvent_p->m_pArg;
            Ret = EplDllkSetAsndServiceIdFilter(pServFilter->m_ServiceId, pServFilter->m_Filter);
            break;
        }

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
        case kEplEventTypeDllkIssueReq:
        {
        tEplDllCalIssueRequest*  pIssueReq;

            pIssueReq = (tEplDllCalIssueRequest*) pEvent_p->m_pArg;
            Ret = EplDllkCalIssueRequest(pIssueReq->m_Service, pIssueReq->m_uiNodeId, pIssueReq->m_bSoaFlag1);
            break;
        }
#endif

#if EPL_NMT_MAX_NODE_ID > 0
        case kEplEventTypeDllkConfigNode:
        {
        tEplDllNodeInfo*    pNodeInfo;

            pNodeInfo = (tEplDllNodeInfo*) pEvent_p->m_pArg;
            Ret = EplDllkConfigNode(pNodeInfo);
            break;
        }

        case kEplEventTypeDllkAddNode:
        {
        tEplDllNodeOpParam*    pNodeOpParam;

            pNodeOpParam = (tEplDllNodeOpParam*) pEvent_p->m_pArg;
            Ret = EplDllkAddNode(pNodeOpParam);
            break;
        }

        case kEplEventTypeDllkDelNode:
        {
        tEplDllNodeOpParam*    pNodeOpParam;

            pNodeOpParam = (tEplDllNodeOpParam*) pEvent_p->m_pArg;
            Ret = EplDllkDeleteNode(pNodeOpParam);
            break;
        }
#endif // EPL_NMT_MAX_NODE_ID > 0
/*
        case kEplEventTypeDllkSoftDelNode:
        {
        unsigned int*   puiNodeId;

            puiNodeId = (unsigned int*) pEvent_p->m_pArg;
            Ret = EplDllkSoftDeleteNode(*puiNodeId);
            break;
        }
*/

        case kEplEventTypeDllkIdentity:
        {
        tEplDllIdentParam*  pIdentParam;

            pIdentParam = (tEplDllIdentParam*) pEvent_p->m_pArg;
            if (pIdentParam->m_uiSizeOfStruct > pEvent_p->m_uiSize)
            {
                pIdentParam->m_uiSizeOfStruct = pEvent_p->m_uiSize;
            }
            Ret = EplDllkSetIdentity(pIdentParam);
            break;
        }

        case kEplEventTypeDllkConfig:
        {
        tEplDllConfigParam* pConfigParam;

            pConfigParam = (tEplDllConfigParam*) pEvent_p->m_pArg;
            if (pConfigParam->m_uiSizeOfStruct > pEvent_p->m_uiSize)
            {
                pConfigParam->m_uiSizeOfStruct = pEvent_p->m_uiSize;
            }
            Ret = EplDllkConfig(pConfigParam);
            break;
        }

        default:
        {
            Ret = kEplInvalidEvent;
            break;
        }
    }

//Exit:
    return Ret;
}
tEplKernel EplPdokConfigureChannel(tEplPdoChannelConf* pChannelConf_p)
{
    tEplKernel      Ret = kEplSuccessful;
    tEplPdoChannel* pDestPdoChannel;

    if (pChannelConf_p->m_fTx == FALSE)
    {   // RPDO
#if EPL_NMT_MAX_NODE_ID > 0
        tEplDllNodeOpParam  NodeOpParam;

        NodeOpParam.m_OpNodeType = kEplDllNodeOpTypeFilterPdo;
#endif

        if (pChannelConf_p->m_uiChannelId >= EplPdokInstance_g.m_Allocation.m_uiRxPdoChannelCount)
        {
            Ret = kEplPdoNotExist;
            goto Exit;
        }

        if (pChannelConf_p->m_PdoChannel.m_uiMappObjectCount > tabentries(*EplPdokInstance_g.m_paRxObject))
        {
            Ret = kEplPdoErrorMapp;
            goto Exit;
        }

        pDestPdoChannel = &EplPdokInstance_g.m_pRxPdoChannel[pChannelConf_p->m_uiChannelId];

#if EPL_NMT_MAX_NODE_ID > 0
        if ((pDestPdoChannel->m_uiNodeId != EPL_PDO_INVALID_NODE_ID)
                && (pDestPdoChannel->m_uiNodeId != EPL_PDO_PREQ_NODE_ID))
        {   // disable old PRes filter in DLL
            NodeOpParam.m_uiNodeId = pDestPdoChannel->m_uiNodeId;

            Ret = EplDllkDeleteNode(&NodeOpParam);
            if (Ret != kEplSuccessful)
            {
                goto Exit;
            }
        }
#endif // EPL_NMT_MAX_NODE_ID > 0

        // copy channel configuration to local structure
        EPL_MEMCPY(pDestPdoChannel,
                   &pChannelConf_p->m_PdoChannel,
                   sizeof (pChannelConf_p->m_PdoChannel));

        EPL_MEMCPY(&EplPdokInstance_g.m_paRxObject[pChannelConf_p->m_uiChannelId],
                   &pChannelConf_p->m_aMappObject[0],
                   (pChannelConf_p->m_PdoChannel.m_uiMappObjectCount
                    * sizeof (pChannelConf_p->m_aMappObject[0])));

#if EPL_NMT_MAX_NODE_ID > 0
        if ((pDestPdoChannel->m_uiNodeId != EPL_PDO_INVALID_NODE_ID)
                && (pDestPdoChannel->m_uiNodeId != EPL_PDO_PREQ_NODE_ID))
        {   // enable new PRes filter in DLL
            NodeOpParam.m_uiNodeId = pDestPdoChannel->m_uiNodeId;

            Ret = EplDllkAddNode(&NodeOpParam);
            if (Ret != kEplSuccessful)
            {
                goto Exit;
            }
        }
#endif // EPL_NMT_MAX_NODE_ID > 0

    }
    else
    {   // TPDO
        if (pChannelConf_p->m_uiChannelId >= EplPdokInstance_g.m_Allocation.m_uiTxPdoChannelCount)
        {
            Ret = kEplPdoNotExist;
            goto Exit;
        }

        if (pChannelConf_p->m_PdoChannel.m_uiMappObjectCount > tabentries(*EplPdokInstance_g.m_paTxObject))
        {
            Ret = kEplPdoErrorMapp;
            goto Exit;
        }

        // copy channel configuration to local structure
        EPL_MEMCPY(&EplPdokInstance_g.m_pTxPdoChannel[pChannelConf_p->m_uiChannelId],
                   &pChannelConf_p->m_PdoChannel,
                   sizeof (pChannelConf_p->m_PdoChannel));

        EPL_MEMCPY(&EplPdokInstance_g.m_paTxObject[pChannelConf_p->m_uiChannelId],
                   &pChannelConf_p->m_aMappObject[0],
                   (pChannelConf_p->m_PdoChannel.m_uiMappObjectCount
                    * sizeof (pChannelConf_p->m_aMappObject[0])));

    }

Exit:
    return Ret;
}
//---------------------------------------------------------------------------
//
// Function:    EplErrorHandlerkProcess
//
// Description: processes error events from DLL
//
// Parameters:  pEvent_p = pointer to event-structure from buffer
//
// Returns:     tEpKernel  = errorcode
//
// State:
//
//---------------------------------------------------------------------------
tEplKernel PUBLIC EplErrorHandlerkProcess(tEplEvent* pEvent_p)
{
tEplKernel              Ret;
unsigned long           ulDllErrorEvents;
tEplEvent               Event;
tEplNmtEvent            NmtEvent;

    Ret = kEplSuccessful;


    // check m_EventType
    switch(pEvent_p->m_EventType)
    {
        case kEplEventTypeDllError:
        {
        tEplErrorHandlerkEvent* pErrHandlerEvent = (tEplErrorHandlerkEvent*)pEvent_p->m_pArg;
        tEplErrHistoryEntry     HistoryEntry = {0};

            ulDllErrorEvents = pErrHandlerEvent->m_ulDllErrorEvents;

            HistoryEntry.m_wEntryType = EPL_ERR_ENTRYTYPE_MODE_OCCURRED | EPL_ERR_ENTRYTYPE_PROF_EPL | EPL_ERR_ENTRYTYPE_HISTORY;

            // check the several error events
            if ((ulDllErrorEvents & EPL_DLL_ERR_CN_LOSS_SOC) != 0)
            {   // loss of SoC event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThreshold)
                    {   // threshold is reached
                        // generate error history entry E_DLL_LOSS_SOC_TH
                        HistoryEntry.m_wErrorCode = EPL_E_DLL_LOSS_SOC_TH;
                        HistoryEntry.m_TimeStamp = pEvent_p->m_NetTime;
                        Ret = EplErrorHandlerkPostHistoryEntry(&HistoryEntry);
                        if (Ret != kEplSuccessful)
                        {
                            goto Exit;
                        }

                        BENCHMARK_MOD_02_TOGGLE(7);

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                    EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
                        EPL_DLL_ERR_CN_LOSS_SOC;
                }
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_CN_LOSS_PREQ) != 0)
            {   // loss of PReq event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThreshold)
                    {   // threshold is reached
                        // generate error history entry E_DLL_LOSS_PREQ_TH
                        HistoryEntry.m_wErrorCode = EPL_E_DLL_LOSS_PREQ_TH;
                        HistoryEntry.m_TimeStamp = pEvent_p->m_NetTime;
                        Ret = EplErrorHandlerkPostHistoryEntry(&HistoryEntry);
                        if (Ret != kEplSuccessful)
                        {
                            goto Exit;
                        }

                        BENCHMARK_MOD_02_TOGGLE(7);

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                }
            }

            if ((EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThresholdCnt > 0)
                && ((ulDllErrorEvents & EPL_DLL_ERR_CN_RECVD_PREQ) != 0))
            {   // PReq correctly received
                // decrement threshold counter by 1
                EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThresholdCnt--;
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_CN_CRC) != 0)
            {   // CRC error event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThreshold)
                    {   // threshold is reached
                        // generate error history entry E_DLL_CRC_TH
                        HistoryEntry.m_wErrorCode = EPL_E_DLL_CRC_TH;
                        HistoryEntry.m_TimeStamp = pEvent_p->m_NetTime;
                        Ret = EplErrorHandlerkPostHistoryEntry(&HistoryEntry);
                        if (Ret != kEplSuccessful)
                        {
                            goto Exit;
                        }

                        BENCHMARK_MOD_02_TOGGLE(7);

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                    EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
                        EPL_DLL_ERR_CN_CRC;
                }
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_INVALID_FORMAT) != 0)
            {   // invalid format error occured (only direct reaction)
                // generate error history entry E_DLL_INVALID_FORMAT
                HistoryEntry.m_wErrorCode = EPL_E_DLL_INVALID_FORMAT;
                HistoryEntry.m_TimeStamp = pEvent_p->m_NetTime;
                AmiSetByteToLe(&HistoryEntry.m_abAddInfo[0], (BYTE) pErrHandlerEvent->m_uiNodeId);
                Ret = EplErrorHandlerkPostHistoryEntry(&HistoryEntry);
                if (Ret != kEplSuccessful)
                {
                    goto Exit;
                }

                BENCHMARK_MOD_02_TOGGLE(7);

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
                if (pErrHandlerEvent->m_NmtState >= kEplNmtMsNotActive)
                {   // MN is active
                    if (pErrHandlerEvent->m_uiNodeId != 0)
                    {
                    tEplHeartbeatEvent  HeartbeatEvent;
                    tEplDllNodeOpParam  NodeOpParam;

                        NodeOpParam.m_OpNodeType = kEplDllNodeOpTypeIsochronous;
                        NodeOpParam.m_uiNodeId = pErrHandlerEvent->m_uiNodeId;

                        // remove node from isochronous phase
                        Ret = EplDllkDeleteNode(&NodeOpParam);

                        // inform NmtMnu module about state change, which shall send NMT command ResetNode to this CN
                        HeartbeatEvent.m_uiNodeId = pErrHandlerEvent->m_uiNodeId;
                        HeartbeatEvent.m_NmtState = kEplNmtCsNotActive;
                        HeartbeatEvent.m_wErrorCode = EPL_E_DLL_INVALID_FORMAT;
                        Event.m_EventSink = kEplEventSinkNmtMnu;
                        Event.m_EventType = kEplEventTypeHeartbeat;
                        Event.m_uiSize = sizeof (HeartbeatEvent);
                        Event.m_pArg = &HeartbeatEvent;
                        Ret = EplEventkPost(&Event);
                    }
                    // $$$ and else should lead to InternComError
                }
                else
#endif
                {   // CN is active
                    // post event to NMT state machine
                    NmtEvent = kEplNmtEventInternComError;
                    Event.m_EventSink = kEplEventSinkNmtk;
                    Event.m_EventType = kEplEventTypeNmtEvent;
                    Event.m_pArg = &NmtEvent;
                    Event.m_uiSize = sizeof (NmtEvent);
                    Ret = EplEventkPost(&Event);
                }
            }

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
            if ((ulDllErrorEvents & EPL_DLL_ERR_MN_CRC) != 0)
            {   // CRC error event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThreshold)
                    {   // threshold is reached
                        // generate error history entry E_DLL_CRC_TH
                        HistoryEntry.m_wErrorCode = EPL_E_DLL_CRC_TH;
                        HistoryEntry.m_TimeStamp = pEvent_p->m_NetTime;
                        Ret = EplErrorHandlerkPostHistoryEntry(&HistoryEntry);
                        if (Ret != kEplSuccessful)
                        {
                            goto Exit;
                        }

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                    EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
                        EPL_DLL_ERR_MN_CRC;
                }
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_MN_CYCTIMEEXCEED) != 0)
            {   // cycle time exceeded event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThreshold)
                    {   // threshold is reached
                        // generate error history entry E_DLL_CYCLE_EXCEED_TH
                        HistoryEntry.m_wErrorCode = EPL_E_DLL_CYCLE_EXCEED_TH;
                        HistoryEntry.m_TimeStamp = pEvent_p->m_NetTime;
                        AmiSetWordToLe(&HistoryEntry.m_abAddInfo[0], (WORD) pErrHandlerEvent->m_EplError);
                        Ret = EplErrorHandlerkPostHistoryEntry(&HistoryEntry);
                        if (Ret != kEplSuccessful)
                        {
                            goto Exit;
                        }

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                    else
                    {   // generate error history entry E_DLL_CYCLE_EXCEED
                        HistoryEntry.m_wErrorCode = EPL_E_DLL_CYCLE_EXCEED;
                        HistoryEntry.m_TimeStamp = pEvent_p->m_NetTime;
                        AmiSetWordToLe(&HistoryEntry.m_abAddInfo[0], (WORD) pErrHandlerEvent->m_EplError);
                        Ret = EplErrorHandlerkPostHistoryEntry(&HistoryEntry);
                        if (Ret != kEplSuccessful)
                        {
                            goto Exit;
                        }
                    }

                    EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
                        EPL_DLL_ERR_MN_CYCTIMEEXCEED;
                }
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_MN_CN_LOSS_PRES) != 0)
            {   // CN loss PRes event occured
            unsigned int uiNodeId;

                uiNodeId = pErrHandlerEvent->m_uiNodeId - 1;
                if (uiNodeId < tabentries(EplErrorHandlerkInstance_g.m_adwMnCnLossPresCumCnt))
                {
                    if  (EplErrorHandlerkInstance_g.m_abMnCnLossPresEvent[uiNodeId] == EPL_ERRORHANDLERK_CN_LOSS_PRES_EVENT_NONE)
                    {
                        // increment cumulative counter by 1
                        EplErrorHandlerkInstance_g.m_adwMnCnLossPresCumCnt[uiNodeId]++;

                        if (EplErrorHandlerkInstance_g.m_adwMnCnLossPresThreshold[uiNodeId] > 0)
                        {
                            // increment threshold counter by 8
                            EplErrorHandlerkInstance_g.m_adwMnCnLossPresThrCnt[uiNodeId] += 8;
                            if (EplErrorHandlerkInstance_g.m_adwMnCnLossPresThrCnt[uiNodeId]
                                >= EplErrorHandlerkInstance_g.m_adwMnCnLossPresThreshold[uiNodeId])
                            {   // threshold is reached
                            tEplHeartbeatEvent  HeartbeatEvent;
                            tEplDllNodeOpParam  NodeOpParam;

                                EplErrorHandlerkInstance_g.m_abMnCnLossPresEvent[uiNodeId] = EPL_ERRORHANDLERK_CN_LOSS_PRES_EVENT_THR;

                                NodeOpParam.m_OpNodeType = kEplDllNodeOpTypeIsochronous;
                                NodeOpParam.m_uiNodeId = pErrHandlerEvent->m_uiNodeId;

                                // generate error history entry E_DLL_LOSS_PRES_TH
                                HistoryEntry.m_wErrorCode = EPL_E_DLL_LOSS_PRES_TH;
                                HistoryEntry.m_TimeStamp = pEvent_p->m_NetTime;
                                AmiSetByteToLe(&HistoryEntry.m_abAddInfo[0], (BYTE) pErrHandlerEvent->m_uiNodeId);
                                Ret = EplErrorHandlerkPostHistoryEntry(&HistoryEntry);
                                if (Ret != kEplSuccessful)
                                {
                                    goto Exit;
                                }

                                // remove node from isochronous phase
                                Ret = EplDllkDeleteNode(&NodeOpParam);

                                // inform NmtMnu module about state change, which shall send NMT command ResetNode to this CN
                                HeartbeatEvent.m_uiNodeId = pErrHandlerEvent->m_uiNodeId;
                                HeartbeatEvent.m_NmtState = kEplNmtCsNotActive;
                                HeartbeatEvent.m_wErrorCode = EPL_E_DLL_LOSS_PRES_TH;
                                Event.m_EventSink = kEplEventSinkNmtMnu;
                                Event.m_EventType = kEplEventTypeHeartbeat;
                                Event.m_uiSize = sizeof (HeartbeatEvent);
                                Event.m_pArg = &HeartbeatEvent;
                                Ret = EplEventkPost(&Event);
                            }
                            else
                            {
                                EplErrorHandlerkInstance_g.m_abMnCnLossPresEvent[uiNodeId] = EPL_ERRORHANDLERK_CN_LOSS_PRES_EVENT_OCC;
                            }
                        }
                    }
                }
            }
#endif

            break;
        }

        // unknown type
        default:
        {
            Ret = kEplInvalidEvent;
            break;
        }

    } // end of switch(pEvent_p->m_EventType)

Exit:
    return Ret;

}
tEplKernel EplPdokAlloc(tEplPdoAllocationParam* pAllocationParam_p)
{
    tEplKernel      Ret = kEplSuccessful;
    unsigned int    uiIndex;
#if EPL_NMT_MAX_NODE_ID > 0
    tEplDllNodeOpParam  NodeOpParam;

    NodeOpParam.m_OpNodeType = kEplDllNodeOpTypeFilterPdo;

    NodeOpParam.m_uiNodeId = EPL_C_ADR_BROADCAST;

    Ret = EplDllkDeleteNode(&NodeOpParam);
    if (Ret != kEplSuccessful)
    {
        goto Exit;
    }
#endif // EPL_NMT_MAX_NODE_ID > 0

    if (EplPdokInstance_g.m_Allocation.m_uiRxPdoChannelCount !=
            pAllocationParam_p->m_uiRxPdoChannelCount)
    {   // allocation should be changed

        EplPdokInstance_g.m_Allocation.m_uiRxPdoChannelCount =
            pAllocationParam_p->m_uiRxPdoChannelCount;

        if (EplPdokInstance_g.m_pRxPdoChannel != NULL)
        {
            EPL_FREE(EplPdokInstance_g.m_pRxPdoChannel);
            EplPdokInstance_g.m_pRxPdoChannel = NULL;
        }

        if (EplPdokInstance_g.m_paRxObject != NULL)
        {
            EPL_FREE(EplPdokInstance_g.m_paRxObject);
            EplPdokInstance_g.m_paRxObject = NULL;
        }

        if (pAllocationParam_p->m_uiRxPdoChannelCount > 0)
        {
            EplPdokInstance_g.m_pRxPdoChannel = EPL_MALLOC(sizeof (*EplPdokInstance_g.m_pRxPdoChannel) * pAllocationParam_p->m_uiRxPdoChannelCount);

            if (EplPdokInstance_g.m_pRxPdoChannel == NULL)
            {
                Ret = kEplPdoInitError;
                goto Exit;
            }

            EplPdokInstance_g.m_paRxObject = EPL_MALLOC(sizeof (*EplPdokInstance_g.m_paRxObject) * pAllocationParam_p->m_uiRxPdoChannelCount);

            if (EplPdokInstance_g.m_paRxObject == NULL)
            {
                Ret = kEplPdoInitError;
                goto Exit;
            }
        }
    }

    // disable all RPDOs
    for (uiIndex = 0; uiIndex < pAllocationParam_p->m_uiRxPdoChannelCount; uiIndex++)
    {
        EplPdokInstance_g.m_pRxPdoChannel[uiIndex].m_uiNodeId = EPL_PDO_INVALID_NODE_ID;
    }

    if (EplPdokInstance_g.m_Allocation.m_uiTxPdoChannelCount !=
            pAllocationParam_p->m_uiTxPdoChannelCount)
    {   // allocation should be changed

        EplPdokInstance_g.m_Allocation.m_uiTxPdoChannelCount =
            pAllocationParam_p->m_uiTxPdoChannelCount;

        if (EplPdokInstance_g.m_pTxPdoChannel != NULL)
        {
            EPL_FREE(EplPdokInstance_g.m_pTxPdoChannel);
            EplPdokInstance_g.m_pTxPdoChannel = NULL;
        }

        if (EplPdokInstance_g.m_paTxObject != NULL)
        {
            EPL_FREE(EplPdokInstance_g.m_paTxObject);
            EplPdokInstance_g.m_paTxObject = NULL;
        }

        if (pAllocationParam_p->m_uiTxPdoChannelCount > 0)
        {
            EplPdokInstance_g.m_pTxPdoChannel = EPL_MALLOC(sizeof (*EplPdokInstance_g.m_pTxPdoChannel) * pAllocationParam_p->m_uiTxPdoChannelCount);

            if (EplPdokInstance_g.m_pTxPdoChannel == NULL)
            {
                Ret = kEplPdoInitError;
                goto Exit;
            }

            EplPdokInstance_g.m_paTxObject = EPL_MALLOC(sizeof (*EplPdokInstance_g.m_paTxObject) * pAllocationParam_p->m_uiTxPdoChannelCount);

            if (EplPdokInstance_g.m_paTxObject == NULL)
            {
                Ret = kEplPdoInitError;
                goto Exit;
            }
        }
    }

    // disable all TPDOs
    for (uiIndex = 0; uiIndex < pAllocationParam_p->m_uiTxPdoChannelCount; uiIndex++)
    {
        EplPdokInstance_g.m_pTxPdoChannel[uiIndex].m_uiNodeId = EPL_PDO_INVALID_NODE_ID;
    }

Exit:
    return Ret;
}
Example #5
0
//---------------------------------------------------------------------------
//
// Function:    EplErrorHandlerkProcess
//
// Description: processes error events from DLL
//
//
//
// Parameters:  pEvent_p = pointer to event-structur from buffer
//
//
// Returns:      tEpKernel  = errorcode
//
//
// State:
//
//---------------------------------------------------------------------------
tEplKernel PUBLIC EplErrorHandlerkProcess(tEplEvent* pEvent_p)
{
tEplKernel              Ret;
unsigned long           ulDllErrorEvents;
tEplEvent               Event;
tEplNmtEvent            NmtEvent;

    Ret = kEplSuccessful;

    // check m_EventType
    switch(pEvent_p->m_EventType)
    {
        case kEplEventTypeDllError:
        {
        tEplErrorHandlerkEvent* pErrHandlerEvent = (tEplErrorHandlerkEvent*)pEvent_p->m_pArg;

            ulDllErrorEvents = pErrHandlerEvent->m_ulDllErrorEvents;

            // check the several error events
            if ((ulDllErrorEvents & EPL_DLL_ERR_CN_LOSS_SOC) != 0)
            {   // loss of SoC event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThreshold)
                    {   // threshold is reached
                        // $$$ d.k.: generate error history entry E_DLL_LOSS_SOC_TH

                        BENCHMARK_MOD_02_TOGGLE(7);

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                    EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
                        EPL_DLL_ERR_CN_LOSS_SOC;
                }
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_CN_LOSS_PREQ) != 0)
            {   // loss of PReq event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThreshold)
                    {   // threshold is reached
                        // $$$ d.k.: generate error history entry E_DLL_LOSS_PREQ_TH

                        BENCHMARK_MOD_02_TOGGLE(7);

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                }
            }

            if ((EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThresholdCnt > 0)
                && ((ulDllErrorEvents & EPL_DLL_ERR_CN_RECVD_PREQ) != 0))
            {   // PReq correctly received
                // decrement threshold counter by 1
                EplErrorHandlerkInstance_g.m_CnLossPreq.m_dwThresholdCnt--;
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_CN_CRC) != 0)
            {   // CRC error event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThreshold)
                    {   // threshold is reached
                        // $$$ d.k.: generate error history entry E_DLL_CRC_TH

                        BENCHMARK_MOD_02_TOGGLE(7);

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                    EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
                        EPL_DLL_ERR_CN_CRC;
                }
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_INVALID_FORMAT) != 0)
            {   // invalid format error occured (only direct reaction)
                // $$$ d.k.: generate error history entry E_DLL_INVALID_FORMAT

                BENCHMARK_MOD_02_TOGGLE(7);

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
                if (pErrHandlerEvent->m_NmtState >= kEplNmtMsNotActive)
                {   // MN is active
                    if (pErrHandlerEvent->m_uiNodeId != 0)
                    {
                    tEplHeartbeatEvent  HeartbeatEvent;
                    tEplDllNodeOpParam  NodeOpParam;

                        NodeOpParam.m_OpNodeType = kEplDllNodeOpTypeIsochronous;
                        NodeOpParam.m_uiNodeId = pErrHandlerEvent->m_uiNodeId;

                        // remove node from isochronous phase
                        Ret = EplDllkDeleteNode(&NodeOpParam);

                        // inform NmtMnu module about state change, which shall send NMT command ResetNode to this CN
                        HeartbeatEvent.m_uiNodeId = pErrHandlerEvent->m_uiNodeId;
                        HeartbeatEvent.m_NmtState = kEplNmtCsNotActive;
                        HeartbeatEvent.m_wErrorCode = EPL_E_DLL_INVALID_FORMAT;
                        Event.m_EventSink = kEplEventSinkNmtMnu;
                        Event.m_EventType = kEplEventTypeHeartbeat;
                        Event.m_uiSize = sizeof (HeartbeatEvent);
                        Event.m_pArg = &HeartbeatEvent;
                        Ret = EplEventkPost(&Event);
                    }
                    // $$$ and else should lead to InternComError
                }
                else
#endif
                {   // CN is active
                    // post event to NMT state machine
                    NmtEvent = kEplNmtEventInternComError;
                    Event.m_EventSink = kEplEventSinkNmtk;
                    Event.m_EventType = kEplEventTypeNmtEvent;
                    Event.m_pArg = &NmtEvent;
                    Event.m_uiSize = sizeof (NmtEvent);
                    Ret = EplEventkPost(&Event);
                }
            }

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
            if ((ulDllErrorEvents & EPL_DLL_ERR_MN_CRC) != 0)
            {   // CRC error event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThreshold)
                    {   // threshold is reached
                        // $$$ d.k.: generate error history entry E_DLL_CRC_TH

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                    EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
                        EPL_DLL_ERR_MN_CRC;
                }
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_MN_CYCTIMEEXCEED) != 0)
            {   // cycle time exceeded event occured
                // increment cumulative counter by 1
                EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwCumulativeCnt++;

                if (EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThreshold > 0)
                {
                    // increment threshold counter by 8
                    EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThresholdCnt += 8;
                    if (EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThresholdCnt
                        >= EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThreshold)
                    {   // threshold is reached
                        // $$$ d.k.: generate error history entry E_DLL_CYCLE_EXCEED_TH

                        // post event to NMT state machine
                        NmtEvent = kEplNmtEventNmtCycleError;
                        Event.m_EventSink = kEplEventSinkNmtk;
                        Event.m_EventType = kEplEventTypeNmtEvent;
                        Event.m_pArg = &NmtEvent;
                        Event.m_uiSize = sizeof (NmtEvent);
                        Ret = EplEventkPost(&Event);
                    }
                    // $$$ d.k.: else generate error history entry E_DLL_CYCLE_EXCEED
                    EplErrorHandlerkInstance_g.m_ulDllErrorEvents |=
                        EPL_DLL_ERR_MN_CYCTIMEEXCEED;
                }
            }

            if ((ulDllErrorEvents & EPL_DLL_ERR_MN_CN_LOSS_PRES) != 0)
            {   // CN loss PRes event occured
            unsigned int uiNodeId;

                uiNodeId = pErrHandlerEvent->m_uiNodeId - 1;
                if (uiNodeId < tabentries(EplErrorHandlerkInstance_g.m_adwMnCnLossPresCumCnt))
                {
                    // increment cumulative counter by 1
                    EplErrorHandlerkInstance_g.m_adwMnCnLossPresCumCnt[uiNodeId]++;

                    if (EplErrorHandlerkInstance_g.m_adwMnCnLossPresThreshold[uiNodeId] > 0)
                    {
                        // increment threshold counter by 8
                        EplErrorHandlerkInstance_g.m_adwMnCnLossPresThrCnt[uiNodeId] += 8;
                        if (EplErrorHandlerkInstance_g.m_adwMnCnLossPresThrCnt[uiNodeId]
                            >= EplErrorHandlerkInstance_g.m_adwMnCnLossPresThreshold[uiNodeId])
                        {   // threshold is reached
                        tEplHeartbeatEvent  HeartbeatEvent;
                        tEplDllNodeOpParam  NodeOpParam;

                            NodeOpParam.m_OpNodeType = kEplDllNodeOpTypeIsochronous;
                            NodeOpParam.m_uiNodeId = pErrHandlerEvent->m_uiNodeId;

                            // $$$ d.k.: generate error history entry E_DLL_LOSS_PRES_TH

                            // remove node from isochronous phase
                            Ret = EplDllkDeleteNode(&NodeOpParam);

                            // inform NmtMnu module about state change, which shall send NMT command ResetNode to this CN
                            HeartbeatEvent.m_uiNodeId = pErrHandlerEvent->m_uiNodeId;
                            HeartbeatEvent.m_NmtState = kEplNmtCsNotActive;
                            HeartbeatEvent.m_wErrorCode = EPL_E_DLL_LOSS_PRES_TH;
                            Event.m_EventSink = kEplEventSinkNmtMnu;
                            Event.m_EventType = kEplEventTypeHeartbeat;
                            Event.m_uiSize = sizeof (HeartbeatEvent);
                            Event.m_pArg = &HeartbeatEvent;
                            Ret = EplEventkPost(&Event);
                        }
                        EplErrorHandlerkInstance_g.m_afMnCnLossPresEvent[uiNodeId] = TRUE;
                    }
                }
            }
#endif

            break;
        }

        // NMT event
        case kEplEventTypeNmtEvent:
        {
            if ((*(tEplNmtEvent*)pEvent_p->m_pArg) == kEplNmtEventDllCeSoa)
            {   // SoA event of CN -> decrement threshold counters

                if ((EplErrorHandlerkInstance_g.m_ulDllErrorEvents & EPL_DLL_ERR_CN_LOSS_SOC) == 0)
                {   // decrement loss of SoC threshold counter, because it didn't occur last cycle
                    if (EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThresholdCnt > 0)
                    {
                        EplErrorHandlerkInstance_g.m_CnLossSoc.m_dwThresholdCnt--;
                    }
                }

                if ((EplErrorHandlerkInstance_g.m_ulDllErrorEvents & EPL_DLL_ERR_CN_CRC) == 0)
                {   // decrement CRC threshold counter, because it didn't occur last cycle
                    if (EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThresholdCnt > 0)
                    {
                        EplErrorHandlerkInstance_g.m_CnCrcErr.m_dwThresholdCnt--;
                    }
                }
            }

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
            else if ((*(tEplNmtEvent*)pEvent_p->m_pArg) == kEplNmtEventDllMeSoaSent)
            {   // SoA event of MN -> decrement threshold counters
            tEplDllkNodeInfo*   pIntNodeInfo;
            unsigned int        uiNodeId;

                Ret = EplDllkGetFirstNodeInfo(&pIntNodeInfo);
                if (Ret != kEplSuccessful)
                {
                    break;
                }
                // iterate through node info structure list
                while (pIntNodeInfo != NULL)
                {
                    uiNodeId = pIntNodeInfo->m_uiNodeId - 1;
                    if (uiNodeId < tabentries(EplErrorHandlerkInstance_g.m_adwMnCnLossPresCumCnt))
                    {
                        if  (EplErrorHandlerkInstance_g.m_afMnCnLossPresEvent[uiNodeId] == FALSE)
                        {
                            if (EplErrorHandlerkInstance_g.m_adwMnCnLossPresThrCnt[uiNodeId] > 0)
                            {
                                EplErrorHandlerkInstance_g.m_adwMnCnLossPresThrCnt[uiNodeId]--;
                            }
                        }
                        else
                        {
                            EplErrorHandlerkInstance_g.m_afMnCnLossPresEvent[uiNodeId] = FALSE;
                        }
                    }
                    pIntNodeInfo = pIntNodeInfo->m_pNextNodeInfo;
                }

                if ((EplErrorHandlerkInstance_g.m_ulDllErrorEvents & EPL_DLL_ERR_MN_CRC) == 0)
                {   // decrement CRC threshold counter, because it didn't occur last cycle
                    if (EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThresholdCnt > 0)
                    {
                        EplErrorHandlerkInstance_g.m_MnCrcErr.m_dwThresholdCnt--;
                    }
                }

                if ((EplErrorHandlerkInstance_g.m_ulDllErrorEvents & EPL_DLL_ERR_MN_CYCTIMEEXCEED) == 0)
                {   // decrement cycle exceed threshold counter, because it didn't occur last cycle
                    if (EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThresholdCnt > 0)
                    {
                        EplErrorHandlerkInstance_g.m_MnCycTimeExceed.m_dwThresholdCnt--;
                    }
                }
            }
#endif

            // reset error events
            EplErrorHandlerkInstance_g.m_ulDllErrorEvents = 0L;

            break;
        }

        // unknown type
        default:
        {
            Ret = kEplInvalidEvent;
            break;
        }

    } // end of switch(pEvent_p->m_EventType)


    return Ret;

}