static tEplKernel EplApiProcessImageCreateCompletion( tEplApiProcessImageCopyJobInt* pCopyJob_p) { tEplKernel Ret = kEplSuccessful; #if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__) pCopyJob_p->m_Event.m_pCompletion = EPL_MALLOC(sizeof (*pCopyJob_p->m_Event.m_pCompletion)); if (pCopyJob_p->m_Event.m_pCompletion == NULL) { Ret = kEplApiPIOutOfMemory; goto Exit; } init_completion(&pCopyJob_p->m_Event.m_pCompletion->m_Completion); kref_init(&pCopyJob_p->m_Event.m_pCompletion->m_Kref); // increment ref counter once again for copy job queue reader kref_get(&pCopyJob_p->m_Event.m_pCompletion->m_Kref); EPL_MEMSET (pCopyJob_p->m_Event.m_pCompletion->m_apPageIn, 0, sizeof (pCopyJob_p->m_Event.m_pCompletion->m_apPageIn)); EPL_MEMSET (pCopyJob_p->m_Event.m_pCompletion->m_apPageOut, 0, sizeof (pCopyJob_p->m_Event.m_pCompletion->m_apPageOut)); // fetch page pointers for userspace memory Ret = EplApiProcessImageGetUserPages(&EplApiProcessImageInstance_g.m_In, &pCopyJob_p->m_CopyJob.m_In, FALSE, pCopyJob_p->m_Event.m_pCompletion->m_apPageIn); if (Ret != kEplSuccessful) { goto Exit; } Ret = EplApiProcessImageGetUserPages(&EplApiProcessImageInstance_g.m_Out, &pCopyJob_p->m_CopyJob.m_Out, TRUE, pCopyJob_p->m_Event.m_pCompletion->m_apPageOut); if (Ret != kEplSuccessful) { goto Exit; } #elif (TARGET_SYSTEM == _LINUX_) && !defined(__KERNEL__) sem_init(&pCopyJob_p->m_Event.m_semCompletion, 0, 0); #elif (TARGET_SYSTEM == _WIN32_) pCopyJob_p->m_Event.m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); #elif (TARGET_SYSTEM == _VXWORKS_) if ((pCopyJob_p->m_Event.m_semCompletion = semBCreate(SEM_Q_FIFO, SEM_EMPTY)) == NULL) { Ret = kEplNoResource; } #else #error "OS currently not supported by EplApiProcessImage!" #endif #if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__) Exit: #endif 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; }
tEplKernel PUBLIC EplEventkPostError(tEplEventSource EventSource_p, tEplKernel EplError_p, unsigned int uiArgSize_p, void* pArg_p) { tEplKernel Ret; tEplEventError EventError; tEplEvent EplEvent; Ret = kEplSuccessful; // create argument EventError.m_EventSource = EventSource_p; EventError.m_EplError = EplError_p; uiArgSize_p = (unsigned int) min ((size_t) uiArgSize_p, sizeof (EventError.m_Arg)); EPL_MEMCPY(&EventError.m_Arg, pArg_p, uiArgSize_p); // create event EplEvent.m_EventType = kEplEventTypeError; EplEvent.m_EventSink = kEplEventSinkApi; EPL_MEMSET(&EplEvent.m_NetTime, 0x00, sizeof(EplEvent.m_NetTime)); EplEvent.m_uiSize = (memberoffs (tEplEventError, m_Arg) + uiArgSize_p); EplEvent.m_pArg = &EventError; // post errorevent Ret = EplEventkPost(&EplEvent); 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; }
tEplKernel PUBLIC EplTimerHighReskAddInstance(void) { tEplKernel Ret; unsigned int uiIndex; Ret = kEplSuccessful; EPL_MEMSET(&EplTimerHighReskInstance_l, 0, sizeof(EplTimerHighReskInstance_l)); #ifndef CONFIG_HIGH_RES_TIMERS printk ("EplTimerHighResk: Kernel symbol CONFIG_HIGH_RES_TIMERS is required.\n"); Ret = kEplNoResource; return Ret; #endif /* * Initialize hrtimer structures for all usable timers. */ for (uiIndex = 0; uiIndex < TIMER_COUNT; uiIndex++) { tEplTimerHighReskTimerInfo *pTimerInfo; struct hrtimer *pTimer; pTimerInfo = &EplTimerHighReskInstance_l.m_aTimerInfo[uiIndex]; pTimer = &pTimerInfo->m_Timer; hrtimer_init(pTimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); pTimer->function = EplTimerHighReskCallback; } return Ret; }
//--------------------------------------------------------------------------- // // Function: EplEventuPostError // // Description: post errorevent from userspace // // // // Parameters: EventSource_p = source-module of the errorevent // EplError_p = code of occured error // uiArgSize_p = size of the argument // pArg_p = pointer to the argument // // // Returns: tEpKernel = errorcode // // // State: // //--------------------------------------------------------------------------- tEplKernel PUBLIC EplEventuPostError(tEplEventSource EventSource_p, tEplKernel EplError_p, unsigned int uiArgSize_p, void* pArg_p) { tEplKernel Ret; BYTE abBuffer[EPL_MAX_EVENT_ARG_SIZE]; tEplEventError* pEventError = (tEplEventError*) abBuffer; tEplEvent EplEvent; Ret = kEplSuccessful; // create argument pEventError->m_EventSource = EventSource_p; pEventError->m_EplError = EplError_p; EPL_MEMCPY(&pEventError->m_Arg, pArg_p, uiArgSize_p); // create event EplEvent.m_EventType = kEplEventTypeError; EplEvent.m_EventSink = kEplEventSinkApi; EPL_MEMSET(&EplEvent.m_NetTime, 0x00, sizeof(EplEvent.m_NetTime)); EplEvent.m_uiSize = (sizeof(EventSource_p)+ sizeof(EplError_p)+ uiArgSize_p); EplEvent.m_pArg = &abBuffer[0]; // post errorevent Ret = EplEventuPost(&EplEvent); return Ret; }
tEplKernel EplPdokAddInstance(tEplPdoCbCopyPdo pfnPdokCbPreCopyTPdo_p, tEplPdoCbCopyPdo pfnPdokCbPostCopyRPdo_p) { tEplKernel Ret = kEplSuccessful; EPL_MEMSET(&EplPdokInstance_g, 0, sizeof(EplPdokInstance_g)); Ret = EplDllkRegTpdoHandler(EplPdokCbProcessTpdo); if (Ret != kEplSuccessful) { return Ret; } // set TPDO callback function if (pfnPdokCbPreCopyTPdo_p != NULL) { EplPdokInstance_g.m_pfnCbTpdoPreCopy = pfnPdokCbPreCopyTPdo_p; } // set RPDO callback function if (pfnPdokCbPostCopyRPdo_p != NULL) { EplPdokInstance_g.m_pfnCbRpdoPostCopy = pfnPdokCbPostCopyRPdo_p; } return Ret; }
//--------------------------------------------------------------------------- // // Function: EplTimeruCbMs // // Description: function to process timer // // // // Parameters: lpParameter = pointer to structur of type tEplTimeruData // // // Returns: (none) // // // State: // //--------------------------------------------------------------------------- static void EplTimeruCbMs(unsigned long ulParameter_p) { tEplKernel Ret = kEplSuccessful; tEplTimeruData *pData; tEplEvent EplEvent; tEplTimerEventArg TimerEventArg; pData = (tEplTimeruData *) ulParameter_p; // call event function TimerEventArg.m_TimerHdl = (tEplTimerHdl) pData; TimerEventArg.m_ulArg = pData->TimerArgument.m_ulArg; EplEvent.m_EventSink = pData->TimerArgument.m_EventSink; EplEvent.m_EventType = kEplEventTypeTimer; EPL_MEMSET(&EplEvent.m_NetTime, 0x00, sizeof(tEplNetTime)); EplEvent.m_pArg = &TimerEventArg; EplEvent.m_uiSize = sizeof(TimerEventArg); Ret = EplEventuPost(&EplEvent); // d.k. do not free memory, user has to call EplTimeruDeleteTimer() //kfree(pData); }
tEplKernel PUBLIC EplTimerSynckDelInstance (void) { tEplKernel Ret = kEplSuccessful; EplTimerSynckDrvCompareInterruptDisable(); EplTimerSynckDrvSetCompareValue( 0 ); #ifdef EPL_TIMER_USE_COMPARE_PDI_INT EplTimerSynckDrvCompareTogPdiInterruptDisable(); EplTimerSynckDrvSetCompareTogPdiValue( 0 ); #endif //EPL_TIMER_USE_COMPARE_PDI_INT #ifdef __NIOS2__ alt_ic_isr_register(EPL_TIMER_SYNC_IRQ_IC_ID, EPL_TIMER_SYNC_IRQ, NULL, NULL, NULL); #elif defined(__MICROBLAZE__) XIntc_RegisterHandler(EPL_TIMER_INTC_BASE, EPL_TIMER_SYNC_IRQ, (XInterruptHandler)NULL, (void*)NULL); #else #error "Configuration unknown!" #endif EPL_MEMSET(&EplTimerSynckInstance_l, 0, sizeof (EplTimerSynckInstance_l)); return Ret; }
tEplKernel EplTimerHighReskAddInstance(void) { tEplKernel Ret; unsigned int uiIndex; Ret = kEplSuccessful; EPL_MEMSET(&EplTimerHighReskInstance_l, 0, sizeof(EplTimerHighReskInstance_l)); /* * Initialize hrtimer structures for all usable timers. */ for (uiIndex = 0; uiIndex < TIMER_COUNT; uiIndex++) { tEplTimerHighReskTimerInfo *pTimerInfo; struct hrtimer *pTimer; pTimerInfo = &EplTimerHighReskInstance_l.m_aTimerInfo[uiIndex]; pTimer = &pTimerInfo->m_Timer; hrtimer_init(pTimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); pTimer->function = EplTimerHighReskCallback; } return Ret; }
//--------------------------------------------------------------------------- // // Function: EplSdoAsnduAddInstance // // Description: init additional instance of the module // // // // Parameters: pReceiveCb_p = functionpointer to Sdo-Sequence layer // callback-function // // // Returns: tEplKernel = Errorcode // // // State: // //--------------------------------------------------------------------------- tEplKernel PUBLIC EplSdoAsnduAddInstance(tEplSequLayerReceiveCb fpReceiveCb_p) { tEplKernel Ret; Ret = kEplSuccessful; // init control structure EPL_MEMSET(&SdoAsndInstance_g, 0x00, sizeof(SdoAsndInstance_g)); // save pointer to callback-function if (fpReceiveCb_p != NULL) { SdoAsndInstance_g.m_fpSdoAsySeqCb = fpReceiveCb_p; } else { Ret = kEplSdoUdpMissCb; } #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0) Ret = EplDlluCalRegAsndService(kEplDllAsndSdo, EplSdoAsnduCb, kEplDllAsndFilterLocal); #endif return Ret; }
tEplKernel EplPdokCalAddInstance(void) { EPL_MEMSET(&EplPdokCalInstance_g, 0, sizeof(EplPdokCalInstance_g)); return kEplSuccessful; }
//--------------------------------------------------------------------------- // // Function: EplSdoUdpuAddInstance // // Description: init additional instance of the module // înit socket and start Listen-Thread // // // // Parameters: pReceiveCb_p = functionpointer to Sdo-Sequence layer // callback-function // // // Returns: tEplKernel = Errorcode // // // State: // //--------------------------------------------------------------------------- tEplKernel EplSdoUdpuAddInstance(tEplSequLayerReceiveCb fpReceiveCb_p) { tEplKernel Ret; // set instance variables to 0 EPL_MEMSET(&SdoUdpInstance_g, 0x00, sizeof(SdoUdpInstance_g)); Ret = kEplSuccessful; // save pointer to callback-function if (fpReceiveCb_p != NULL) { SdoUdpInstance_g.m_fpSdoAsySeqCb = fpReceiveCb_p; } else { Ret = kEplSdoUdpMissCb; goto Exit; } init_completion(&SdoUdpInstance_g.m_CompletionUdpThread); SdoUdpInstance_g.m_iTerminateThread = 0; SdoUdpInstance_g.m_ThreadHandle = 0; SdoUdpInstance_g.m_UdpSocket = INVALID_SOCKET; Ret = EplSdoUdpuConfig(INADDR_ANY, 0); Exit: return Ret; }
tEplKernel EplCfmuAddInstance(tEplCfmCbEventCnProgress pfnCbEventCnProgress_p, tEplCfmCbEventCnResult pfnCbEventCnResult_p) { tEplKernel Ret = kEplSuccessful; unsigned int uiSubindex; tEplVarParam VarParam; EPL_MEMSET(&EplCfmuInstance_g, 0, sizeof(EplCfmuInstance_g)); EplCfmuInstance_g.m_pfnCbEventCnProgress = pfnCbEventCnProgress_p; EplCfmuInstance_g.m_pfnCbEventCnResult = pfnCbEventCnResult_p; // link domain with 4 zero-bytes to object 0x1F22 CFM_ConciseDcfList_ADOM VarParam.m_pData = &EplCfmuInstance_g.m_le_dwDomainSizeNull; VarParam.m_Size = sizeof (EplCfmuInstance_g.m_le_dwDomainSizeNull); VarParam.m_uiIndex = 0x1F22; for (uiSubindex = 1; uiSubindex <= EPL_NMT_MAX_NODE_ID; uiSubindex++) { VarParam.m_uiSubindex = uiSubindex; VarParam.m_ValidFlag = kVarValidAll; Ret = EplObdDefineVar(&VarParam); if ((Ret != kEplSuccessful) && (Ret != kEplObdIndexNotExist) && (Ret != kEplObdSubindexNotExist)) { goto Exit; } } Ret = kEplSuccessful; Exit: return Ret; }
tEplKernel PUBLIC EplApiInitialize(tEplApiInitParam * pInitParam_p) { tEplKernel Ret = kEplSuccessful; const char* pszDrvName; // driver name int iRet; // reset instance structure EPL_MEMSET(&EplApiInstance_g, 0, sizeof (EplApiInstance_g)); EPL_MEMCPY(&EplApiInstance_g.m_InitParam, pInitParam_p, (sizeof (tEplApiInitParam) < pInitParam_p->m_uiSizeOfStruct) ? sizeof (tEplApiInitParam) : pInitParam_p->m_uiSizeOfStruct); // check event callback function pointer if (EplApiInstance_g.m_InitParam.m_pfnCbEvent == NULL) { // application must always have an event callback function Ret = kEplApiInvalidParam; goto Exit; } pszDrvName = "/dev/"EPLLIN_DEV_NAME; EplApiInstance_g.m_hDrvInst = -1; // open driver TRACE1("EPL: Try to open driver '%s'\n", pszDrvName); EplApiInstance_g.m_hDrvInst = open (pszDrvName, O_RDWR); if (EplApiInstance_g.m_hDrvInst > -1) { TRACE2("EPL: open '%s' successful -> hDrvInst=%d\n", pszDrvName, EplApiInstance_g.m_hDrvInst); } else { TRACE1("EPL: ERROR: Can't open '%s'\n", pszDrvName); Ret = kEplNoResource; goto Exit; } // initialize hardware iRet = ioctl (EplApiInstance_g.m_hDrvInst, EPLLIN_CMD_INITIALIZE, (unsigned long)&EplApiInstance_g.m_InitParam); if (iRet < 0) { Ret = kEplNoResource; goto Exit; } else { Ret = (tEplKernel)iRet; } // the application must start NMT state machine // via EplApiExecNmtCommand(kEplNmtEventSwReset) // and thereby the whole EPL stack :-) /*#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTU)) != 0) Ret = EplNmtuNmtEvent(kEplNmtEventSwReset); #endif*/ Exit: return Ret; }
tEplKernel EplDlluCalDelInstance() { tEplKernel Ret = kEplSuccessful; // reset instance structure EPL_MEMSET(&EplDlluCalInstance_g, 0, sizeof(EplDlluCalInstance_g)); return Ret; }
EPLDLLEXPORT tEplKernel PUBLIC EplSyncuReset() { tEplKernel Ret; Ret = kEplSuccessful; // reset instance structure EPL_MEMSET(&EplSyncuInstance_g, 0, sizeof (EplSyncuInstance_g)); return Ret; }
tEplKernel EplStatusuReset(void) { tEplKernel Ret; Ret = kEplSuccessful; // reset instance structure EPL_MEMSET(&EplStatusuInstance_g, 0, sizeof(EplStatusuInstance_g)); return Ret; }
tEplKernel EdrvCyclicInit() { tEplKernel Ret; Ret = kEplSuccessful; // clear instance structure EPL_MEMSET(&EdrvCyclicInstance_l, 0, sizeof (EdrvCyclicInstance_l)); //Exit: return Ret; }
//--------------------------------------------------------------------------- // Function: EplTimerHighReskAddInstance() // // Description: initializes the high resolution timer module. // // Parameters: void // // Return: tEplKernel = error code //--------------------------------------------------------------------------- tEplKernel PUBLIC EplTimerHighReskAddInstance(void) { tEplKernel Ret; UINT uiIndex; struct sched_param schedParam; tEplTimerHighReskTimerInfo* pTimerInfo; Ret = kEplSuccessful; EPL_MEMSET(&EplTimerHighReskInstance_l, 0, sizeof (EplTimerHighReskInstance_l)); /* Initialize timer threads for all usable timers. */ for (uiIndex = 0; uiIndex < TIMER_COUNT; uiIndex++) { pTimerInfo = &EplTimerHighReskInstance_l.m_aTimerInfo[uiIndex]; pTimerInfo->m_fTerminate = FALSE; #ifdef HIGH_RESK_TIMER_LATENCY_DEBUG pTimerInfo->m_maxLatency = 0; pTimerInfo->m_minLatency = 999999999; #endif if (sem_init(&pTimerInfo->m_syncSem, 0, 0) != 0) { EPL_DBGLVL_ERROR_TRACE("%s() Couldn't init semaphore!\n", __func__); Ret = kEplNoResource; goto Exit; } if (pthread_create(&pTimerInfo->m_timerThread, NULL, EplTimerHighReskProcessThread, (void *)uiIndex) != 0) { Ret = kEplNoResource; sem_destroy(&pTimerInfo->m_syncSem); goto Exit; } schedParam.__sched_priority = EPL_THREAD_PRIORITY_HIGH; if (pthread_setschedparam(pTimerInfo->m_timerThread, SCHED_FIFO, &schedParam) != 0) { EPL_DBGLVL_ERROR_TRACE("%s() Couldn't set thread scheduling parameters!\n", __func__); Ret = kEplNoResource; sem_destroy(&pTimerInfo->m_syncSem); pthread_cancel(pTimerInfo->m_timerThread); goto Exit; } } Exit: return Ret; }
tEplKernel PUBLIC EplTimeruProcess(void) { tTimerEntry* pTimerEntry; DWORD dwTimeoutMs; tEplEvent EplEvent; tEplTimerEventArg TimerEventArg; tEplKernel Ret; Ret = kEplSuccessful; EplTimeruEnterCriticalSection(TIMERU_TIMER_LIST); // calculate elapsed time since start time dwTimeoutMs = EplTimeruGetTickCountMs() - EplTimeruInstance_g.m_dwStartTimeMs; // observe first timer entry in timer list pTimerEntry = EplTimeruInstance_g.m_pTimerListFirst; if (pTimerEntry != NULL) { if (dwTimeoutMs >= pTimerEntry->m_dwTimeoutMs) { // timeout elapsed // remove entry from timer list EplTimeruInstance_g.m_pTimerListFirst = pTimerEntry->m_pNext; // adjust start time EplTimeruInstance_g.m_dwStartTimeMs += pTimerEntry->m_dwTimeoutMs; } else { pTimerEntry = NULL; } } EplTimeruLeaveCriticalSection(TIMERU_TIMER_LIST); if (pTimerEntry != NULL) { // call event function TimerEventArg.m_TimerHdl = (tEplTimerHdl) pTimerEntry; EPL_MEMCPY(&TimerEventArg.m_Arg, &pTimerEntry->m_TimerArg.m_Arg, sizeof (TimerEventArg.m_Arg)); EplEvent.m_EventSink = pTimerEntry->m_TimerArg.m_EventSink; EplEvent.m_EventType = kEplEventTypeTimer; EPL_MEMSET(&EplEvent.m_NetTime, 0x00, sizeof(tEplNetTime)); EplEvent.m_pArg = &TimerEventArg; EplEvent.m_uiSize = sizeof(TimerEventArg); Ret = EplEventuPost(&EplEvent); } return Ret; }
//--------------------------------------------------------------------------- // // Function: VEthDelInstance // // Description: deletes the VEth instance // // Parameters: // // Returns: tEplKernel = error code // // // State: // //--------------------------------------------------------------------------- tEplKernel PUBLIC VEthDelInstance(void) { tEplKernel Ret = kEplSuccessful; EPL_MEMSET(&VEthInstance_g, 0 , sizeof(VEthInstance_g)); Ret = VEthClose(); if(Ret != kEplSuccessful) { EPL_DBGLVL_VETH_TRACE("VEthClose: returned 0x%02X\n", Ret); } return Ret; }
EPLDLLEXPORT tEplKernel PUBLIC EplSyncuAddInstance() { tEplKernel Ret; Ret = kEplSuccessful; // reset instance structure EPL_MEMSET(&EplSyncuInstance_g, 0, sizeof (EplSyncuInstance_g)); // register SyncResponse callback function Ret = EplDlluCalRegAsndService(kEplDllAsndSyncResponse, EplSyncuCbSyncResponse, kEplDllAsndFilterAny); return Ret; }
//--------------------------------------------------------------------------- // // Function: EplSdoUdpuAddInstance // // Description: init additional instance of the module // init socket and start Listen-Thread // // // // Parameters: pReceiveCb_p = functionpointer to Sdo-Sequence layer // callback-function // // // Returns: tEplKernel = Errorcode // // // State: // //--------------------------------------------------------------------------- tEplKernel PUBLIC EplSdoUdpuAddInstance(tEplSequLayerReceiveCb fpReceiveCb_p) { tEplKernel Ret; #if (TARGET_SYSTEM == _WIN32_) int iError; WSADATA Wsa; #endif // set instance variables to 0 EPL_MEMSET(&SdoUdpInstance_g, 0x00, sizeof(SdoUdpInstance_g)); Ret = kEplSuccessful; // save pointer to callback-function if (fpReceiveCb_p != NULL) { SdoUdpInstance_g.m_fpSdoAsySeqCb = fpReceiveCb_p; } else { Ret = kEplSdoUdpMissCb; goto Exit; } #if (TARGET_SYSTEM == _WIN32_) // start winsock2 for win32 // windows specific start of socket iError = WSAStartup(MAKEWORD(2,0),&Wsa); if (iError != 0) { Ret = kEplSdoUdpNoSocket; goto Exit; } // create critical section for access of instance variables SdoUdpInstance_g.m_pCriticalSection = &SdoUdpInstance_g.m_CriticalSection; InitializeCriticalSection(SdoUdpInstance_g.m_pCriticalSection); #endif SdoUdpInstance_g.m_ThreadHandle = 0; SdoUdpInstance_g.m_UdpSocket = INVALID_SOCKET; Ret = EplSdoUdpuConfig(INADDR_ANY, 0); Exit: return Ret; }
//--------------------------------------------------------------------------- // // Function: VEthAddInstance // // Description: Add a VEth instance // // Parameters: abSrcMac_p = The MAC Address to set // // Returns: tEplKernel = error code // // // State: // //--------------------------------------------------------------------------- tEplKernel PUBLIC VEthAddInstance(const BYTE abSrcMac_p[6]) { tEplKernel Ret = kEplSuccessful; EPL_MEMSET(&VEthInstance_g, 0 , sizeof(VEthInstance_g)); EPL_MEMCPY(VEthInstance_g.m_abEthMac, abSrcMac_p, sizeof(VEthInstance_g.m_abEthMac) ); Ret = VEthOpen(); if(Ret != kEplSuccessful) { EPL_DBGLVL_VETH_TRACE("VEthOpen: returned 0x%02X\n", Ret); } return Ret; }
//--------------------------------------------------------------------------- // Function: EplTimerHighReskAddInstance() // // Description: initializes the high resolution timer module. // // Parameters: void // // Return: tEplKernel = error code //--------------------------------------------------------------------------- tEplKernel PUBLIC EplTimerHighReskAddInstance(void) { tEplKernel Ret; UINT uiIndex; struct sched_param schedParam; tEplTimerHighReskTimerInfo* pTimerInfo; struct sigevent sev; Ret = kEplSuccessful; EPL_MEMSET(&EplTimerHighReskInstance_l, 0, sizeof (EplTimerHighReskInstance_l)); /* Initialize timer threads for all usable timers. */ for (uiIndex = 0; uiIndex < TIMER_COUNT; uiIndex++) { pTimerInfo = &EplTimerHighReskInstance_l.m_aTimerInfo[uiIndex]; sev.sigev_notify = SIGEV_SIGNAL; sev.sigev_signo = SIGHIGHRES; sev.sigev_value.sival_ptr = pTimerInfo; if (timer_create(CLOCK_MONOTONIC, &sev, &pTimerInfo->m_timer) != 0) { Ret = kEplNoResource; goto Exit; } } if (pthread_create(&EplTimerHighReskInstance_l.m_thread, NULL, EplTimerHighReskProcessThread, NULL) != 0) { Ret = kEplNoResource; goto Exit; } schedParam.__sched_priority = EPL_THREAD_PRIORITY_HIGH; if (pthread_setschedparam(EplTimerHighReskInstance_l.m_thread, SCHED_FIFO, &schedParam) != 0) { EPL_DBGLVL_ERROR_TRACE1("%s() Couldn't set thread scheduling parameters!\n", __func__); Ret = kEplNoResource; pthread_cancel(EplTimerHighReskInstance_l.m_thread); goto Exit; } Exit: return Ret; }
tEplKernel EplIdentuAddInstance(void) { tEplKernel Ret; Ret = kEplSuccessful; // reset instance structure EPL_MEMSET(&EplIdentuInstance_g, 0, sizeof(EplIdentuInstance_g)); // register IdentResponse callback function Ret = EplDlluCalRegAsndService(kEplDllAsndIdentResponse, EplIdentuCbIdentResponse, kEplDllAsndFilterAny); return Ret; }
//--------------------------------------------------------------------------- // // Function: EplSdoAsnduSendData // // Description: send data using exisiting connection // // // // Parameters: SdoConHandle_p = connection handle // pSrcData_p = pointer to data // dwDataSize_p = number of databyte // -> without asnd-header!!! // // Returns: tEplKernel = Errorcode // // // State: // //--------------------------------------------------------------------------- tEplKernel PUBLIC EplSdoAsnduSendData(tEplSdoConHdl SdoConHandle_p, tEplFrame * pSrcData_p, DWORD dwDataSize_p) { tEplKernel Ret; unsigned int uiArray; tEplFrameInfo FrameInfo; Ret = kEplSuccessful; uiArray = (SdoConHandle_p & ~EPL_SDO_ASY_HANDLE_MASK); if (uiArray > EPL_SDO_MAX_CONNECTION_ASND) { Ret = kEplSdoAsndInvalidHandle; goto Exit; } // fillout Asnd header // own node id not needed -> filled by DLL // set message type AmiSetByteToLe(&pSrcData_p->m_le_bMessageType, (BYTE) kEplMsgTypeAsnd); // ASnd == 0x06 // target node id AmiSetByteToLe(&pSrcData_p->m_le_bDstNodeId, (BYTE) SdoAsndInstance_g. m_auiSdoAsndConnection[uiArray]); // set source-nodeid (filled by DLL 0) AmiSetByteToLe(&pSrcData_p->m_le_bSrcNodeId, 0x00); // calc size dwDataSize_p += EPL_ASND_HEADER_SIZE; // send function of DLL FrameInfo.m_uiFrameSize = dwDataSize_p; FrameInfo.m_pFrame = pSrcData_p; EPL_MEMSET(&FrameInfo.m_NetTime, 0x00, sizeof(tEplNetTime)); #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLU)) != 0) Ret = EplDlluCalAsyncSend(&FrameInfo, kEplDllAsyncReqPrioGeneric); #endif Exit: return Ret; }
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 EplTimerSynckAddInstance (void) { tEplKernel Ret = kEplSuccessful; EPL_MEMSET(&EplTimerSynckInstance_l, 0, sizeof (EplTimerSynckInstance_l)); EplTimerSynckDrvCompareInterruptDisable(); EplTimerSynckDrvSetCompareValue( 0 ); #ifdef EPL_TIMER_USE_COMPARE_PDI_INT EplTimerSynckDrvCompareTogPdiInterruptDisable(); EplTimerSynckDrvSetCompareTogPdiValue( 0 ); #endif //EPL_TIMER_USE_COMPARE_PDI_INT #ifdef __NIOS2__ if (alt_ic_isr_register(EPL_TIMER_SYNC_IRQ_IC_ID, EPL_TIMER_SYNC_IRQ, EplTimerSynckDrvInterruptHandler, NULL, NULL)) { Ret = kEplNoResource; } #elif defined(__MICROBLAZE__) { DWORD curIntEn = TSYN_RD32(EPL_TIMER_INTC_BASE, XIN_IER_OFFSET); XIntc_RegisterHandler(EPL_TIMER_INTC_BASE, EPL_TIMER_SYNC_IRQ, (XInterruptHandler)EplTimerSynckDrvInterruptHandler, (void*)NULL); XIntc_EnableIntr(EPL_TIMER_INTC_BASE, EPL_TIMER_SYNC_IRQ_MASK | curIntEn); } #else #error"Configuration unknown!" #endif return Ret; }