Ejemplo n.º 1
0
static tEplKernel EplApiProcessImageDeleteCompletion(
    tEplApiProcessImageCopyJobInt* pCopyJob_p)
{
tEplKernel      Ret = kEplSuccessful;

#if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
    if (pCopyJob_p->m_Event.m_pCompletion != NULL)
    {
        EplApiProcessImagePutUserPages(
                pCopyJob_p->m_Event.m_pCompletion->m_apPageIn, FALSE);
        EplApiProcessImagePutUserPages(
                pCopyJob_p->m_Event.m_pCompletion->m_apPageOut, TRUE);
        EPL_FREE(pCopyJob_p->m_Event.m_pCompletion);
        pCopyJob_p->m_Event.m_pCompletion = NULL;
    }

#elif (TARGET_SYSTEM == _LINUX_) && !defined(__KERNEL__)
    sem_destroy(&pCopyJob_p->m_Event.m_semCompletion);

#elif (TARGET_SYSTEM == _WIN32_)
    if ((pCopyJob_p->m_Event.m_hEvent != NULL)
        && (pCopyJob_p->m_Event.m_hEvent != INVALID_HANDLE_VALUE))
    {
        CloseHandle(pCopyJob_p->m_Event.m_hEvent);
        pCopyJob_p->m_Event.m_hEvent = INVALID_HANDLE_VALUE;
    }

#else
#error "OS currently not supported by EplApiProcessImage!"
#endif

//Exit:
    return Ret;
}
tEplKernel EdrvCyclicSetMaxTxBufferListSize(unsigned int uiMaxListSize_p)
{
tEplKernel  Ret = kEplSuccessful;

    if (EdrvCyclicInstance_l.m_uiMaxTxBufferCount != uiMaxListSize_p)
    {
        EdrvCyclicInstance_l.m_uiMaxTxBufferCount = uiMaxListSize_p;
        if (EdrvCyclicInstance_l.m_paTxBufferList != NULL)
        {
            EPL_FREE(EdrvCyclicInstance_l.m_paTxBufferList);
            EdrvCyclicInstance_l.m_paTxBufferList = NULL;
        }

        EdrvCyclicInstance_l.m_paTxBufferList = EPL_MALLOC(sizeof (*EdrvCyclicInstance_l.m_paTxBufferList) * uiMaxListSize_p * 2);
        if (EdrvCyclicInstance_l.m_paTxBufferList == NULL)
        {
            Ret = kEplEdrvNoFreeBufEntry;
        }

        EdrvCyclicInstance_l.m_uiCurTxBufferList = 0;

        EPL_MEMSET(EdrvCyclicInstance_l.m_paTxBufferList, 0, sizeof (*EdrvCyclicInstance_l.m_paTxBufferList) * uiMaxListSize_p * 2);
    }

    return Ret;
}
Ejemplo n.º 3
0
tEplKernel PUBLIC EplTimeruDelInstance(void)
{
tEplKernel  Ret;

    Ret = kEplSuccessful;

#if (TARGET_SYSTEM == _WIN32_)
    SetEvent( EplTimeruInstance_g.m_ahEvents[TIMERU_EVENT_SHUTDOWN] );

    WaitForSingleObject( EplTimeruInstance_g.m_hProcessThread, INFINITE );

    CloseHandle( EplTimeruInstance_g.m_hProcessThread );
    CloseHandle( EplTimeruInstance_g.m_ahEvents[TIMERU_EVENT_SHUTDOWN] );
    CloseHandle( EplTimeruInstance_g.m_ahEvents[TIMERU_EVENT_WAKEUP] );

    DeleteCriticalSection( &EplTimeruInstance_g.m_aCriticalSections[TIMERU_TIMER_LIST] );
    DeleteCriticalSection( &EplTimeruInstance_g.m_aCriticalSections[TIMERU_FREE_LIST] );
#endif

    EPL_FREE(EplTimeruInstance_g.m_pEntries);

    EplTimeruInstance_g.m_pEntries = NULL;
    EplTimeruInstance_g.m_pFreeListFirst = NULL;
    EplTimeruInstance_g.m_pTimerListFirst = NULL;
    EplTimeruInstance_g.m_uiFreeEntries = 0;

    return Ret;
}
tEplKernel EplObdCdcLoadFile(char* pszCdcFilename_p)
{
tEplKernel      Ret = kEplSuccessful;
tEplObdCdcInfo  CdcInfo;
DWORD           dwErrno;

    EPL_MEMSET(&CdcInfo, 0, sizeof (CdcInfo));
    CdcInfo.m_Type = kEplObdCdcTypeFile;
    CdcInfo.m_Handle.m_hCdcFile = open(pszCdcFilename_p, O_RDONLY | O_BINARY, 0666);
    if (!IS_FD_VALID(CdcInfo.m_Handle.m_hCdcFile))
    {   // error occurred
        dwErrno = (DWORD) errno;
        Ret = EplEventuPostError(kEplEventSourceObdu, kEplObdErrnoSet, sizeof (dwErrno), &dwErrno);
        goto Exit;
    }

    CdcInfo.m_iCdcSize = lseek(CdcInfo.m_Handle.m_hCdcFile, 0, SEEK_END);
    lseek(CdcInfo.m_Handle.m_hCdcFile, 0, SEEK_SET);

    Ret = EplObdCdcProcess(&CdcInfo);

    if (CdcInfo.m_pbCurBuffer != NULL)
    {
        EPL_FREE(CdcInfo.m_pbCurBuffer);
        CdcInfo.m_pbCurBuffer = NULL;
        CdcInfo.m_iBufferSize = 0;
    }

    close(CdcInfo.m_Handle.m_hCdcFile);

Exit:
    return Ret;
}
Ejemplo n.º 5
0
tEplKernel PUBLIC EplCfmuCbObdAccess(tEplObdCbParam MEM* pParam_p)
{
tEplKernel          Ret = kEplSuccessful;
tEplObdVStringDomain*   pMemVStringDomain;
tEplCfmuNodeInfo*       pNodeInfo = NULL;
BYTE*                   pbBuffer;

    pParam_p->m_dwAbortCode = 0;

    if ((pParam_p->m_uiIndex != 0x1F22)
        || (pParam_p->m_ObdEvent != kEplObdEvWrStringDomain))
    {
        goto Exit;
    }

    // abort any running SDO transfer
    pNodeInfo = EPL_CFMU_GET_NODEINFO(pParam_p->m_uiSubIndex);
    if ((pNodeInfo != NULL)
        && (pNodeInfo->m_SdoComConHdl != ~0))
    {
        Ret = EplSdoComSdoAbort(pNodeInfo->m_SdoComConHdl, EPL_SDOAC_DATA_NOT_TRANSF_DUE_DEVICE_STATE);
    }

    pMemVStringDomain = pParam_p->m_pArg;
    if ((pMemVStringDomain->m_ObjSize != pMemVStringDomain->m_DownloadSize)
        || (pMemVStringDomain->m_pData == NULL))
    {
        pNodeInfo = EplCfmuAllocNodeInfo(pParam_p->m_uiSubIndex);
        if (pNodeInfo == NULL)
        {
            pParam_p->m_dwAbortCode = EPL_SDOAC_OUT_OF_MEMORY;
            Ret = kEplNoResource;
            goto Exit;
        }

        pbBuffer = pNodeInfo->m_pbObdBufferConciseDcf;
        if (pbBuffer != NULL)
        {
            EPL_FREE(pbBuffer);
            pNodeInfo->m_pbObdBufferConciseDcf = NULL;
        }
        pbBuffer = EPL_MALLOC(pMemVStringDomain->m_DownloadSize);
        if (pbBuffer == NULL)
        {
            pParam_p->m_dwAbortCode = EPL_SDOAC_OUT_OF_MEMORY;
            Ret = kEplNoResource;
            goto Exit;
        }
        pNodeInfo->m_pbObdBufferConciseDcf = pbBuffer;
        pMemVStringDomain->m_pData = pbBuffer;
        pMemVStringDomain->m_ObjSize = pMemVStringDomain->m_DownloadSize;
    }

Exit:
    return Ret;
}
static void EplApiProcessImageReleaseCompletion(struct kref* pKref_p)
{
    tEplApiProcessImageCompletion* pCompletion = container_of(pKref_p, tEplApiProcessImageCompletion, m_Kref);

    EplApiProcessImagePutUserPages(
        pCompletion->m_apPageIn, FALSE);
    EplApiProcessImagePutUserPages(
        pCompletion->m_apPageOut, TRUE);
    EPL_FREE(pCompletion);
}
tEplKernel EplPdokDelInstance(void)
{
    EplPdokInstance_g.m_Allocation.m_uiRxPdoChannelCount = 0;

    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;
    }

    EplPdokInstance_g.m_Allocation.m_uiTxPdoChannelCount = 0;

    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 (EplPdokInstance_g.m_pfnCbTpdoPreCopy != NULL)
    {
        EplPdokInstance_g.m_pfnCbTpdoPreCopy = NULL;
    }

    if (EplPdokInstance_g.m_pfnCbRpdoPostCopy != NULL)
    {
        EplPdokInstance_g.m_pfnCbRpdoPostCopy = NULL;
    }

    return kEplSuccessful;
}
Ejemplo n.º 8
0
tEplKernel EplCfmuDelInstance(void)
{
tEplKernel          Ret = kEplSuccessful;
unsigned int        uiNodeId;
tEplVarParam        VarParam;
BYTE*               pbBuffer;
tEplCfmuNodeInfo*   pNodeInfo;

    // free domain for object 0x1F22 CFM_ConciseDcfList_ADOM
    VarParam.m_pData = NULL;
    VarParam.m_Size = 0;
    VarParam.m_uiIndex = 0x1F22;
    for (uiNodeId = 1; uiNodeId <= EPL_NMT_MAX_NODE_ID; uiNodeId++)
    {
        pNodeInfo = EPL_CFMU_GET_NODEINFO(uiNodeId);
        if (pNodeInfo != NULL)
        {
            if (pNodeInfo->m_SdoComConHdl != ~0)
            {
                Ret = EplSdoComSdoAbort(pNodeInfo->m_SdoComConHdl, EPL_SDOAC_DATA_NOT_TRANSF_DUE_DEVICE_STATE);
            }

            pbBuffer = pNodeInfo->m_pbObdBufferConciseDcf;
            if (pbBuffer != NULL)
            {
                VarParam.m_uiSubindex = uiNodeId;
                VarParam.m_ValidFlag = kVarValidAll;
                Ret = EplObdDefineVar(&VarParam);
                // ignore return code, because buffer has to be freed anyway

                EPL_FREE(pbBuffer);
                pNodeInfo->m_pbObdBufferConciseDcf = NULL;
            }
            EPL_FREE(pNodeInfo);
            EPL_CFMU_GET_NODEINFO(uiNodeId) = NULL;
        }
    }
    Ret = kEplSuccessful;

//Exit:
    return Ret;
}
tEplKernel EdrvCyclicShutdown(void)
{
    if (EdrvCyclicInstance_l.m_paTxBufferList != NULL)
    {
        EPL_FREE(EdrvCyclicInstance_l.m_paTxBufferList);
        EdrvCyclicInstance_l.m_paTxBufferList = NULL;
        EdrvCyclicInstance_l.m_uiMaxTxBufferCount = 0;
    }

    return kEplSuccessful;
}
Ejemplo n.º 10
0
tEplKernel EplIdentuReset(void)
{
	tEplKernel Ret;
	int iIndex;

	Ret = kEplSuccessful;

	for (iIndex = 0;
	     iIndex < tabentries(EplIdentuInstance_g.m_apIdentResponse);
	     iIndex++) {
		if (EplIdentuInstance_g.m_apIdentResponse[iIndex] != NULL) {	// free memory
			EPL_FREE(EplIdentuInstance_g.m_apIdentResponse[iIndex]);
		}
	}

	EPL_MEMSET(&EplIdentuInstance_g, 0, sizeof(EplIdentuInstance_g));

	return Ret;

}
tEplKernel PUBLIC EplApiProcessImageFree(void)
{
    tEplKernel      Ret = kEplSuccessful;
    tShbError       ShbError;
    tEplApiProcessImageCopyJobInt   CopyJob;

    if ((EplApiProcessImageInstance_g.m_In.m_pImage == NULL)
            && (EplApiProcessImageInstance_g.m_Out.m_pImage == NULL))
    {
        goto Exit;
    }

    EplDllkRegSyncHandler(EplApiProcessImageInstance_g.m_pfnOrgCbSync);

    EplApiProcessImageInstance_g.m_In.m_uiSize = 0;
    EplApiProcessImageInstance_g.m_Out.m_uiSize = 0;

    // signal completion to all queued copy jobs
    for (;;)
    {
        Ret = EplApiProcessImageFetchCopyJob(0, &CopyJob);
        if (Ret == kEplSuccessful)
        {
            Ret = EplApiProcessImageSignalCompletion(&CopyJob);
            if (Ret != kEplSuccessful)
            {
                goto Exit;
            }
        }
        else
        {
            break;
        }
    }

    for (;;)
    {
        Ret = EplApiProcessImageFetchCopyJob(1, &CopyJob);
        if (Ret == kEplSuccessful)
        {
            Ret = EplApiProcessImageSignalCompletion(&CopyJob);
            if (Ret != kEplSuccessful)
            {
                goto Exit;
            }
        }
        else
        {
            break;
        }
    }

    if (Ret == kEplApiPIJobQueueEmpty)
    {
        Ret = kEplSuccessful;
    }

    EPL_FREE(EplApiProcessImageInstance_g.m_In.m_pImage);
    EplApiProcessImageInstance_g.m_In.m_pImage = NULL;
    EPL_FREE(EplApiProcessImageInstance_g.m_Out.m_pImage);
    EplApiProcessImageInstance_g.m_Out.m_pImage = NULL;

    ShbError = ShbCirReleaseBuffer (EplApiProcessImageInstance_g.m_ShbInstanceJobQueueLo);
    if (ShbError != kShbOk)
    {
        Ret = kEplNoResource;
    }
    EplApiProcessImageInstance_g.m_ShbInstanceJobQueueLo = NULL;

    ShbError = ShbCirReleaseBuffer (EplApiProcessImageInstance_g.m_ShbInstanceJobQueueHi);
    if (ShbError != kShbOk)
    {
        Ret = kEplNoResource;
    }
    EplApiProcessImageInstance_g.m_ShbInstanceJobQueueHi = NULL;

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;
}
static tEplKernel EplObdCdcLoadNextBuffer(tEplObdCdcInfo* pCdcInfo_p, size_t iBufferSize)
{
tEplKernel  Ret = kEplSuccessful;
int         iReadSize;
BYTE*       pbBuffer;

    switch (pCdcInfo_p->m_Type)
    {
        case kEplObdCdcTypeFile:
        {
            if (pCdcInfo_p->m_iBufferSize < iBufferSize)
            {
                if (pCdcInfo_p->m_pbCurBuffer != NULL)
                {
                    EPL_FREE(pCdcInfo_p->m_pbCurBuffer);
                    pCdcInfo_p->m_pbCurBuffer = NULL;
                    pCdcInfo_p->m_iBufferSize = 0;
                }
                pCdcInfo_p->m_pbCurBuffer = EPL_MALLOC(iBufferSize);
                if (pCdcInfo_p->m_pbCurBuffer == NULL)
                {
                    Ret = EplEventuPostError(kEplEventSourceObdu, kEplObdOutOfMemory, 0, NULL);
                    if (Ret != kEplSuccessful)
                    {
                        goto Exit;
                    }
                    Ret = kEplReject;
                    goto Exit;
                }
                pCdcInfo_p->m_iBufferSize = iBufferSize;
            }
            pbBuffer = pCdcInfo_p->m_pbCurBuffer;
            do
            {
                iReadSize = read(pCdcInfo_p->m_Handle.m_hCdcFile, pbBuffer, iBufferSize);
                if (iReadSize <= 0)
                {
                    Ret = EplEventuPostError(kEplEventSourceObdu, kEplObdInvalidDcf, 0, NULL);
                    if (Ret != kEplSuccessful)
                    {
                        goto Exit;
                    }
                    Ret = kEplReject;
                    goto Exit;
                }
                pbBuffer += iReadSize;
                iBufferSize -= iReadSize;
                pCdcInfo_p->m_iCdcSize -= iReadSize;
            }
            while (iBufferSize > 0);
            break;
        }

        case kEplObdCdcTypeBuffer:
        {
            if (pCdcInfo_p->m_iBufferSize < iBufferSize)
            {
                Ret = EplEventuPostError(kEplEventSourceObdu, kEplObdInvalidDcf, 0, NULL);
                if (Ret != kEplSuccessful)
                {
                    goto Exit;
                }
                Ret = kEplReject;
                goto Exit;
            }
            pCdcInfo_p->m_pbCurBuffer = pCdcInfo_p->m_Handle.m_pbNextBuffer;
            pCdcInfo_p->m_Handle.m_pbNextBuffer += iBufferSize;
            pCdcInfo_p->m_iBufferSize -= iBufferSize;
            break;
        }
    }

Exit:
    return Ret;
}