//------------------------------------------------------------------------------ tOplkError dllucal_issueRequest(tDllReqServiceId service_p, UINT nodeId_p, UINT8 soaFlag1_p) { tOplkError ret; tEvent event; tDllCalIssueRequest issueReq; // add node to appropriate request queue switch (service_p) { case kDllReqServiceIdent: case kDllReqServiceStatus: issueReq.service = service_p; issueReq.nodeId = nodeId_p; issueReq.soaFlag1 = soaFlag1_p; event.eventSink = kEventSinkDllkCal; event.eventType = kEventTypeDllkIssueReq; event.eventArg.pEventArg = &issueReq; event.eventArgSize = sizeof(issueReq); ret = eventu_postEvent(&event); break; default: ret = kErrorDllInvalidParam; goto Exit; } Exit: return ret; }
//------------------------------------------------------------------------------ tOplkError eventu_postError(tEventSource eventSource_p, tOplkError error_p, UINT argSize_p, const void* pArg_p) { tOplkError ret; tEventError eventError; tEvent event; // Check parameter validity ASSERT((argSize_p == 0) || (pArg_p != NULL)); // create argument eventError.eventSource = eventSource_p; eventError.oplkError = error_p; argSize_p = (UINT)min((size_t)argSize_p, sizeof(eventError.errorArg)); OPLK_MEMCPY(&eventError.errorArg, pArg_p, argSize_p); // create event event.eventType = kEventTypeError; event.eventSink = kEventSinkApi; OPLK_MEMSET(&event.netTime, 0x00, sizeof(event.netTime)); event.eventArgSize = offsetof(tEventError, errorArg) + argSize_p; event.eventArg.pEventArg = &eventError; ret = eventu_postEvent(&event); return ret; }
//------------------------------------------------------------------------------ tOplkError sdotestcom_conCb(tSdoSeqConHdl sdoSeqConHdl_p, tAsySdoConState sdoConState_p) { tOplkError ret = kErrorOk; tSdoTestComCon* pCmdCon; tEvent Event; // Ignore unused parameter (void)sdoSeqConHdl_p; ret = kErrorOk; pCmdCon = &sdoTestComInst.tCmdCon; switch (sdoConState_p) { case kAsySdoConStateConnected: pCmdCon->tState = kOplkTestSdoComStateConnected; // Trigger frame send event OPLK_MEMSET(&Event.netTime, 0x00, sizeof(Event.netTime)); Event.eventType = kEventTypeSdoAsySend; Event.pEventArg = pCmdCon; Event.eventArgSize = sizeof(*pCmdCon); Event.eventSink = kEventSinkSdoTest; ret = eventu_postEvent(&Event); break; case kAsySdoConStateAckReceived: case kAsySdoConStateFrameSent: // These events are not forwarded to the app, and don't require any // handling here, so just do nothing in this case break; default: case kAsySdoConStateInitError: case kAsySdoConStateConClosed: case kAsySdoConStateTimeout: case kAsySdoConStateTransferAbort: // Close connection pCmdCon->tState = kOplkTestSdoComStateIdle; break; } return ret; }
//------------------------------------------------------------------------------ tOplkError nmtu_postNmtEvent(tNmtEvent nmtEvent_p) { tOplkError ret; tEvent event; event.eventSink = kEventSinkNmtk; event.netTime.nsec = 0; event.netTime.sec = 0; event.eventType = kEventTypeNmtEvent; event.pEventArg = &nmtEvent_p; event.eventArgSize = sizeof(nmtEvent_p); ret = eventu_postEvent(&event); return ret; }
//------------------------------------------------------------------------------ tOplkError dllucal_deleteNode(const tDllNodeOpParam* pNodeOpParam_p) { tOplkError ret; tEvent event; // Check parameter validity ASSERT(pNodeOpParam_p != NULL); event.eventSink = kEventSinkDllkCal; event.eventType = kEventTypeDllkDelNode; event.eventArg.pEventArg = (void*)pNodeOpParam_p; event.eventArgSize = sizeof(*pNodeOpParam_p); ret = eventu_postEvent(&event); return ret; }
//------------------------------------------------------------------------------ tOplkError dllucal_setIdentity(const tDllIdentParam* pDllIdentParam_p) { tOplkError ret; tEvent event; // Check parameter validity ASSERT(pDllIdentParam_p != NULL); event.eventSink = kEventSinkDllkCal; event.eventType = kEventTypeDllkIdentity; event.eventArg.pEventArg = (void*)pDllIdentParam_p; event.eventArgSize = sizeof(*pDllIdentParam_p); ret = eventu_postEvent(&event); return ret; }
//------------------------------------------------------------------------------ tOplkError timeru_process(void) { tTimerEntry* pTimerEntry; UINT32 timeoutInMs; tEvent event; tTimerEventArg timerEventArg; tOplkError ret = kErrorOk; enterCriticalSection(TIMERU_TIMER_LIST); // calculate elapsed time since start time timeoutInMs = getTickCount() - timeruInstance_l.startTimeInMs; // observe first timer entry in timer list pTimerEntry = timeruInstance_l.pTimerListFirst; if (pTimerEntry != NULL) { if (timeoutInMs >= pTimerEntry->timeoutInMs) { // timeout elapsed - remove entry from timer list timeruInstance_l.pTimerListFirst = pTimerEntry->pNext; // adjust start time timeruInstance_l.startTimeInMs += pTimerEntry->timeoutInMs; } else { pTimerEntry = NULL; } } leaveCriticalSection(TIMERU_TIMER_LIST); if (pTimerEntry != NULL) { // call event function timerEventArg.timerHdl = (tTimerHdl)pTimerEntry; OPLK_MEMCPY(&timerEventArg.argument, &pTimerEntry->timerArg.argument, sizeof(timerEventArg.argument)); event.eventSink = pTimerEntry->timerArg.eventSink; event.eventType = kEventTypeTimer; OPLK_MEMSET(&event.netTime, 0x00, sizeof(tNetTime)); event.pEventArg = &timerEventArg; event.eventArgSize = sizeof(timerEventArg); ret = eventu_postEvent(&event); } return ret; }
//------------------------------------------------------------------------------ static void cbTimer(const tTimeruData* pData_p) { tOplkError ret; tEvent event; tTimerEventArg timerEventArg; // call event function timerEventArg.timerHdl.handle = (tTimerHdl)pData_p; OPLK_MEMCPY(&timerEventArg.argument, &pData_p->timerArg.argument, sizeof(timerEventArg.argument)); event.eventSink = pData_p->timerArg.eventSink; event.eventType = kEventTypeTimer; OPLK_MEMSET(&event.netTime, 0x00, sizeof(tNetTime)); event.eventArg.pEventArg = &timerEventArg; event.eventArgSize = sizeof(timerEventArg); ret = eventu_postEvent(&event); }
//------------------------------------------------------------------------------ static tOplkError setAsndServiceIdFilter(tDllAsndServiceId serviceId_p, tDllAsndFilter filter_p) { tOplkError ret; tEvent event; tDllCalAsndServiceIdFilter servFilter; servFilter.serviceId = serviceId_p; servFilter.filter = filter_p; event.eventSink = kEventSinkDllkCal; event.eventType = kEventTypeDllkServFilter; event.eventArg.pEventArg = &servFilter; event.eventArgSize = sizeof(servFilter); ret = eventu_postEvent(&event); return ret; }
//------------------------------------------------------------------------------ static void cbTimer(ULONG parameter_p) { tTimeruData* pData; tEvent event; tTimerEventArg timerEventArg; pData = (tTimeruData*)parameter_p; // call event function timerEventArg.timerHdl = (tTimerHdl)pData; OPLK_MEMCPY(&timerEventArg.argument, &pData->timerArgument.argument, sizeof(timerEventArg.argument)); event.eventSink = pData->timerArgument.eventSink; event.eventType = kEventTypeTimer; OPLK_MEMSET(&event.netTime, 0x00, sizeof(tNetTime)); event.pEventArg = &timerEventArg; event.eventArgSize = sizeof(timerEventArg); eventu_postEvent(&event); }
//------------------------------------------------------------------------------ static void cbTimer(ULONG parameter_p) { tOplkError ret = kErrorOk; tTimeruData* pData; tEvent event; tTimerEventArg timerEventArg; pData = (tTimeruData*)parameter_p; // call event function timerEventArg.timerHdl.handle = (tTimerHdl)pData; OPLK_MEMCPY(&timerEventArg.argument, &pData->timerArgument.argument, sizeof(timerEventArg.argument)); event.eventSink = pData->timerArgument.eventSink; event.eventType = kEventTypeTimer; OPLK_MEMSET(&event.netTime, 0x00, sizeof(tNetTime)); event.eventArg.pEventArg = &timerEventArg; event.eventArgSize = sizeof(timerEventArg); ret = eventu_postEvent(&event); // d.k. do not free memory, user has to call timeru_deleteTimer() }
//------------------------------------------------------------------------------ static tOplkError handleRxAsyncFrameInfo(tFrameInfo* pFrameInfo_p) { tOplkError ret; tEvent event; tPlkFrame* pKernelBuffer = pFrameInfo_p->frame.pBuffer; tPlkFrame* pAcqBuffer; // Get Rx buffer from kernel layer pAcqBuffer = (tPlkFrame*)memmap_mapKernelBuffer(pKernelBuffer, pFrameInfo_p->frameSize); if (pAcqBuffer == NULL) { DEBUG_LVL_ERROR_TRACE("%s Getting the Rx buffer from kernel failed!\n", __func__); return kErrorDllOutOfMemory; //jz Use other error code? } // Set reference to kernel buffer for processing pFrameInfo_p->frame.pBuffer = pAcqBuffer; // Now handle the async frame ret = handleRxAsyncFrame(pFrameInfo_p); // Free the acquired kernel buffer memmap_unmapKernelBuffer(pAcqBuffer); // Restore frame info for releasing Rx frame pFrameInfo_p->frame.pBuffer = pKernelBuffer; // call free function for Asnd frame event.eventSink = kEventSinkDllkCal; event.eventType = kEventTypeReleaseRxFrame; event.eventArgSize = sizeof(tFrameInfo); event.eventArg.pEventArg = (void*)pFrameInfo_p; eventu_postEvent(&event); // Return handleRxAsyncFrameInfo() return value (ignore others) return ret; }
//------------------------------------------------------------------------------ tOplkError dllucal_sendAsyncFrame(const tFrameInfo* pFrameInfo_p, tDllAsyncReqPriority priority_p) { tOplkError ret; tEvent event; // Check parameter validity ASSERT(pFrameInfo_p != NULL); switch (priority_p) { case kDllAsyncReqPrioNmt: ret = instance_l.pTxNmtFuncs->pfnInsertDataBlock( instance_l.dllCalQueueTxNmt, (const UINT8*)pFrameInfo_p->frame.pBuffer, pFrameInfo_p->frameSize); break; default: ret = sendGenericAsyncFrame(pFrameInfo_p); break; } if (ret != kErrorOk) goto Exit; // post event to DLL event.eventSink = kEventSinkDllk; event.eventType = kEventTypeDllkFillTx; OPLK_MEMSET(&event.netTime, 0x00, sizeof(event.netTime)); event.eventArg.pEventArg = &priority_p; event.eventArgSize = sizeof(priority_p); ret = eventu_postEvent(&event); Exit: return ret; }
//------------------------------------------------------------------------------ tOplkError sdotestcom_sendFrame(UINT nodeId_p, tSdoType sdoType_p, tAsySdoCom* pSdoCom_p, size_t sdoSize_p) { tOplkError ret; tSdoTestComCon* pCmdCon; tEvent Event; tCircBufError CbError; tPlkFrame* pFrame; tAsySdoCom* pSdoCom_Dst; size_t FrameSize; ret = kErrorOk; pCmdCon = &sdoTestComInst.tCmdCon; FrameSize = PLK_FRAME_OFFSET_SDO_COMU + sdoSize_p; // Check if parameters are valid if (FrameSize > C_DLL_MAX_ASYNC_MTU) { return kErrorInvalidOperation; } if (kOplkTestSdoComStateIdle != pCmdCon->tState) { // If the connection is already in use, node ID and SDO type have to match if ((pCmdCon->nodeId != nodeId_p) || (pCmdCon->tSdoType != sdoType_p)) { return kErrorInvalidOperation; } } // Get frame buffer pFrame = (tPlkFrame *)OPLK_MALLOC(FrameSize); if (pFrame == NULL) { ret = kErrorNoResource; } // Generate frame pSdoCom_Dst = &pFrame->data.asnd.payload.sdoSequenceFrame.sdoSeqPayload; OPLK_MEMSET(pFrame, 0, FrameSize); OPLK_MEMCPY(pSdoCom_Dst, pSdoCom_p, sdoSize_p); // Save frame in shared buffer CbError = circbuf_writeData(pCmdCon->pCbBufInst, pFrame, FrameSize); OPLK_FREE(pFrame); if (kCircBufOk != CbError) { ret = kErrorInvalidOperation; } else { // Sequence layer handling // Either create a new connection, or reuse existing one switch (pCmdCon->tState) { case kOplkTestSdoComStateIdle: // Get new sequence layer connection // When the connection is ready, the callback will trigger sending ret = sdoseq_initCon(&pCmdCon->tSeqHdl, nodeId_p, sdoType_p); pCmdCon->tState = kOplkTestSdoComStateWaitInit; pCmdCon->tSdoType = sdoType_p; pCmdCon->nodeId = nodeId_p; break; case kOplkTestSdoComStateWaitInit: // Connection setup is already in progress // Nothing left to do break; case kOplkTestSdoComStateConnected: // Connection is already up and running, // just trigger frame send event OPLK_MEMSET(&Event.netTime, 0x00, sizeof(Event.netTime)); Event.eventType = kEventTypeSdoAsySend; Event.pEventArg = pCmdCon; Event.eventArgSize = sizeof(*pCmdCon); Event.eventSink = kEventSinkSdoTest; ret = eventu_postEvent(&Event); break; default: // Reject unknown states ret = kErrorInvalidOperation; break; } } return ret; }