//--------------------------------------------------------------------------- // // Function: EplEventuAddInstance // // Description: function add one more instance // // // // Parameters: pfnApiProcessEventCb_p = function pointer for API event callback // // // Returns: tEpKernel = errorcode // // // State: // //--------------------------------------------------------------------------- tEplKernel PUBLIC EplEventuAddInstance(tEplProcessEventCb pfnApiProcessEventCb_p) { tEplKernel Ret; #if EPL_USE_SHAREDBUFF != FALSE tShbError ShbError; unsigned int fShbNewCreated; #endif Ret = kEplSuccessful; // init instance variables EplEventuInstance_g.m_pfnApiProcessEventCb = pfnApiProcessEventCb_p; #if EPL_USE_SHAREDBUFF != FALSE // init shared loop buffer // kernel -> user ShbError = ShbCirAllocBuffer (EPL_EVENT_SIZE_SHB_KERNEL_TO_USER, EPL_EVENT_NAME_SHB_KERNEL_TO_USER, &EplEventuInstance_g.m_pShbKernelToUserInstance, &fShbNewCreated); if(ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventuAddInstance(): ShbCirAllocBuffer(K2U) -> 0x%X\n", ShbError); Ret = kEplNoResource; goto Exit; } #if EPL_EVENT_USE_KERNEL_QUEUE != FALSE // user -> kernel ShbError = ShbCirAllocBuffer (EPL_EVENT_SIZE_SHB_USER_TO_KERNEL, EPL_EVENT_NAME_SHB_USER_TO_KERNEL, &EplEventuInstance_g.m_pShbUserToKernelInstance, &fShbNewCreated); if(ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventuAddInstance(): ShbCirAllocBuffer(U2K) -> 0x%X\n", ShbError); Ret = kEplNoResource; goto Exit; } #endif // register eventhandler ShbError = ShbCirSetSignalHandlerNewData (EplEventuInstance_g.m_pShbKernelToUserInstance, EplEventuRxSignalHandlerCb, kShbPriorityNormal); if(ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventuAddInstance(): ShbCirSetSignalHandlerNewData(K2U) -> 0x%X\n", ShbError); Ret = kEplNoResource; goto Exit; } Exit: #endif return Ret; }
tEplKernel PUBLIC EplEventkAddInstance(void) { tEplKernel Ret; #if EPL_USE_SHAREDBUFF != FALSE tShbError ShbError; unsigned int fShbNewCreated; #endif Ret = kEplSuccessful; // init instance structure #if EPL_EVENT_USE_KERNEL_QUEUE != FALSE EplEventkInstance_g.m_uiUserToKernelFullCount = 0; #endif #if EPL_USE_SHAREDBUFF != FALSE // init shared loop buffer // kernel -> user ShbError = ShbCirAllocBuffer (EPL_EVENT_SIZE_SHB_KERNEL_TO_USER, EPL_EVENT_NAME_SHB_KERNEL_TO_USER, &EplEventkInstance_g.m_pShbKernelToUserInstance, &fShbNewCreated); if(ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventkAddInstance(): ShbCirAllocBuffer(K2U) -> 0x%X\n", ShbError); Ret = kEplNoResource; goto Exit; } #if EPL_EVENT_USE_KERNEL_QUEUE != FALSE // user -> kernel ShbError = ShbCirAllocBuffer (EPL_EVENT_SIZE_SHB_USER_TO_KERNEL, EPL_EVENT_NAME_SHB_USER_TO_KERNEL, &EplEventkInstance_g.m_pShbUserToKernelInstance, &fShbNewCreated); if(ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventkAddInstance(): ShbCirAllocBuffer(U2K) -> 0x%X\n", ShbError); Ret = kEplNoResource; goto Exit; } // register eventhandler ShbError = ShbCirSetSignalHandlerNewData (EplEventkInstance_g.m_pShbUserToKernelInstance, EplEventkRxSignalHandlerCb, kShbPriorityHigh); if(ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventkAddInstance(): ShbCirSetSignalHandlerNewData(U2K) -> 0x%X\n", ShbError); Ret = kEplNoResource; goto Exit; } #endif Exit: #endif return Ret; }
//--------------------------------------------------------------------------- // // Function: EplEventuDelInstance // // Description: function delete instance an free the bufferstructure // // // // Parameters: // // // Returns: tEpKernel = errorcode // // // State: // //--------------------------------------------------------------------------- tEplKernel PUBLIC EplEventuDelInstance() { tEplKernel Ret; #if EPL_USE_SHAREDBUFF != FALSE tShbError ShbError; #endif Ret = kEplSuccessful; #if EPL_USE_SHAREDBUFF != FALSE // set eventhandler to NULL ShbError = ShbCirSetSignalHandlerNewData (EplEventuInstance_g.m_pShbKernelToUserInstance, NULL, kShbPriorityNormal); if(ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventuDelInstance(): ShbCirSetSignalHandlerNewData(K2U) -> 0x%X\n", ShbError); Ret = kEplNoResource; } #if EPL_EVENT_USE_KERNEL_QUEUE != FALSE // free buffer User -> Kernel ShbError = ShbCirReleaseBuffer (EplEventuInstance_g.m_pShbUserToKernelInstance); if((ShbError != kShbOk) && (ShbError != kShbMemUsedByOtherProcs)) { EPL_DBGLVL_EVENTK_TRACE1("EplEventuDelInstance(): ShbCirReleaseBuffer(U2K) -> 0x%X\n", ShbError); Ret = kEplNoResource; } else { EplEventuInstance_g.m_pShbUserToKernelInstance = NULL; } #endif // free buffer Kernel -> User ShbError = ShbCirReleaseBuffer (EplEventuInstance_g.m_pShbKernelToUserInstance); if((ShbError != kShbOk) && (ShbError != kShbMemUsedByOtherProcs)) { EPL_DBGLVL_EVENTK_TRACE1("EplEventuDelInstance(): ShbCirReleaseBuffer(K2U) -> 0x%X\n", ShbError); Ret = kEplNoResource; } else { EplEventuInstance_g.m_pShbKernelToUserInstance = NULL; } #endif return Ret; }
tEplKernel EplEventkDelInstance(void) { tEplKernel Ret; #ifndef EPL_NO_FIFO tShbError ShbError; #endif Ret = kEplSuccessful; #ifndef EPL_NO_FIFO // set eventhandler to NULL ShbError = ShbCirSetSignalHandlerNewData(EplEventkInstance_g. m_pShbUserToKernelInstance, NULL, kShbPriorityNormal); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventkDelInstance(): ShbCirSetSignalHandlerNewData(U2K) -> 0x%X\n", ShbError); Ret = kEplNoResource; } // free buffer User -> Kernel ShbError = ShbCirReleaseBuffer(EplEventkInstance_g.m_pShbUserToKernelInstance); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventkDelInstance(): ShbCirReleaseBuffer(U2K) -> 0x%X\n", ShbError); Ret = kEplNoResource; } else { EplEventkInstance_g.m_pShbUserToKernelInstance = NULL; } // free buffer Kernel -> User ShbError = ShbCirReleaseBuffer(EplEventkInstance_g.m_pShbKernelToUserInstance); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventkDelInstance(): ShbCirReleaseBuffer(K2U) -> 0x%X\n", ShbError); Ret = kEplNoResource; } else { EplEventkInstance_g.m_pShbKernelToUserInstance = NULL; } #endif return Ret; }
//--------------------------------------------------------------------------- // // Function: EplEventuPost // // Description: post events from userspace // // // // Parameters: pEvent_p = pointer to event-structur from buffer // // // Returns: tEpKernel = errorcode // // // State: // //--------------------------------------------------------------------------- tEplKernel EplEventuPost(tEplEvent *pEvent_p) { tEplKernel Ret; #ifndef EPL_NO_FIFO tShbError ShbError; tShbCirChunk ShbCirChunk; unsigned long ulDataSize; unsigned int fBufferCompleted; #endif Ret = kEplSuccessful; #ifndef EPL_NO_FIFO // 2006/08/03 d.k.: Event and argument are posted as separate chunks to the event queue. ulDataSize = sizeof(tEplEvent) + ((pEvent_p->m_pArg != NULL) ? pEvent_p->m_uiSize : 0); #endif // decide in which buffer the event have to write switch (pEvent_p->m_EventSink) { // kernelspace modules case kEplEventSinkSync: case kEplEventSinkNmtk: case kEplEventSinkDllk: case kEplEventSinkDllkCal: case kEplEventSinkPdok: case kEplEventSinkErrk: { #ifndef EPL_NO_FIFO // post message ShbError = ShbCirAllocDataBlock(EplEventuInstance_g. m_pShbUserToKernelInstance, &ShbCirChunk, ulDataSize); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventuPost(): ShbCirAllocDataBlock(U2K) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } ShbError = ShbCirWriteDataChunk(EplEventuInstance_g. m_pShbUserToKernelInstance, &ShbCirChunk, pEvent_p, sizeof(tEplEvent), &fBufferCompleted); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventuPost(): ShbCirWriteDataChunk(U2K) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } if (fBufferCompleted == FALSE) { ShbError = ShbCirWriteDataChunk(EplEventuInstance_g. m_pShbUserToKernelInstance, &ShbCirChunk, pEvent_p->m_pArg, (unsigned long) pEvent_p->m_uiSize, &fBufferCompleted); if ((ShbError != kShbOk) || (fBufferCompleted == FALSE)) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventuPost(): ShbCirWriteDataChunk2(U2K) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } } #else Ret = EplEventkProcess(pEvent_p); #endif break; } // userspace modules case kEplEventSinkNmtMnu: case kEplEventSinkNmtu: case kEplEventSinkSdoAsySeq: case kEplEventSinkApi: case kEplEventSinkDlluCal: case kEplEventSinkErru: case kEplEventSinkLedu: { #ifndef EPL_NO_FIFO // post message ShbError = ShbCirAllocDataBlock(EplEventuInstance_g. m_pShbKernelToUserInstance, &ShbCirChunk, ulDataSize); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventuPost(): ShbCirAllocDataBlock(K2U) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } ShbError = ShbCirWriteDataChunk(EplEventuInstance_g. m_pShbKernelToUserInstance, &ShbCirChunk, pEvent_p, sizeof(tEplEvent), &fBufferCompleted); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventuPost(): ShbCirWriteDataChunk(K2U) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } if (fBufferCompleted == FALSE) { ShbError = ShbCirWriteDataChunk(EplEventuInstance_g. m_pShbKernelToUserInstance, &ShbCirChunk, pEvent_p->m_pArg, (unsigned long) pEvent_p->m_uiSize, &fBufferCompleted); if ((ShbError != kShbOk) || (fBufferCompleted == FALSE)) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventuPost(): ShbCirWriteDataChunk2(K2U) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } } #else Ret = EplEventuProcess(pEvent_p); #endif break; } default: { Ret = kEplEventUnknownSink; } } // end of switch(pEvent_p->m_EventSink) #ifndef EPL_NO_FIFO Exit: #endif return Ret; }
tEplKernel PUBLIC EplEventkPost(tEplEvent * pEvent_p) { tEplKernel Ret; #if EPL_USE_SHAREDBUFF != FALSE tShbError ShbError; tShbCirChunk ShbCirChunk; unsigned long ulDataSize; unsigned int fBufferCompleted; #endif Ret = kEplSuccessful; // the event must be posted by using the abBuffer // it is neede because the Argument must by copied // to the buffer too and not only the pointer #if EPL_USE_SHAREDBUFF != FALSE // 2006/08/03 d.k.: Event and argument are posted as separate chunks to the event queue. ulDataSize = sizeof(tEplEvent) + ((pEvent_p->m_pArg != NULL) ? pEvent_p->m_uiSize : 0); #endif // decide in which buffer the event have to write switch(pEvent_p->m_EventSink) { // kernelspace modules case kEplEventSinkSync: case kEplEventSinkNmtk: case kEplEventSinkDllk: case kEplEventSinkDllkCal: case kEplEventSinkPdok: case kEplEventSinkPdokCal: case kEplEventSinkErrk: { BENCHMARK_MOD_27_SET(2); #if (EPL_USE_SHAREDBUFF != FALSE) \ && (EPL_EVENT_USE_KERNEL_QUEUE != FALSE) // post message ShbError = ShbCirAllocDataBlock (EplEventkInstance_g.m_pShbUserToKernelInstance, &ShbCirChunk, ulDataSize); switch (ShbError) { case kShbOk: break; case kShbBufferFull: { EplEventkInstance_g.m_uiUserToKernelFullCount++; Ret = kEplEventPostError; goto Exit; } default: { EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirAllocDataBlock(U2K) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } } ShbError = ShbCirWriteDataChunk (EplEventkInstance_g.m_pShbUserToKernelInstance, &ShbCirChunk, pEvent_p, sizeof (tEplEvent), &fBufferCompleted); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirWriteDataChunk(U2K) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } if (fBufferCompleted == FALSE) { ShbError = ShbCirWriteDataChunk (EplEventkInstance_g.m_pShbUserToKernelInstance, &ShbCirChunk, pEvent_p->m_pArg, (unsigned long) pEvent_p->m_uiSize, &fBufferCompleted); if ((ShbError != kShbOk) || (fBufferCompleted == FALSE)) { EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirWriteDataChunk2(U2K) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } } #else #if EPL_EVENT_USE_KERNEL_QUEUE == FALSE EplTgtEnableGlobalInterrupt(FALSE); #endif Ret = EplEventkProcess(pEvent_p); #if EPL_EVENT_USE_KERNEL_QUEUE == FALSE EplTgtEnableGlobalInterrupt(TRUE); #endif #endif BENCHMARK_MOD_27_RESET(2); break; } // userspace modules case kEplEventSinkNmtu: case kEplEventSinkNmtMnu: case kEplEventSinkSdoAsySeq: case kEplEventSinkApi: case kEplEventSinkDlluCal: case kEplEventSinkErru: { #if EPL_USE_SHAREDBUFF != FALSE // post message // BENCHMARK_MOD_27_SET(3); // 74 µs until reset ShbError = ShbCirAllocDataBlock (EplEventkInstance_g.m_pShbKernelToUserInstance, &ShbCirChunk, ulDataSize); if(ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirAllocDataBlock(K2U) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } ShbError = ShbCirWriteDataChunk (EplEventkInstance_g.m_pShbKernelToUserInstance, &ShbCirChunk, pEvent_p, sizeof (tEplEvent), &fBufferCompleted); if(ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirWriteDataChunk(K2U) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } if (fBufferCompleted == FALSE) { ShbError = ShbCirWriteDataChunk (EplEventkInstance_g.m_pShbKernelToUserInstance, &ShbCirChunk, pEvent_p->m_pArg, (unsigned long) pEvent_p->m_uiSize, &fBufferCompleted); if ((ShbError != kShbOk) || (fBufferCompleted == FALSE)) { EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirWriteDataChunk2(K2U) -> 0x%X\n", ShbError); Ret = kEplEventPostError; goto Exit; } } // BENCHMARK_MOD_27_RESET(3); // 82 µs until ShbCirGetReadDataSize() in EplEventu #else Ret = EplEventuProcess(pEvent_p); #endif break; } default: { Ret = kEplEventUnknownSink; } }// end of switch(pEvent_p->m_EventSink) #if EPL_USE_SHAREDBUFF != FALSE Exit: #endif return Ret; }
tEplKernel EplEventkAddInstance(tEplSyncCb pfnCbSync_p) { tEplKernel Ret; #ifndef EPL_NO_FIFO tShbError ShbError; unsigned int fShbNewCreated; #endif Ret = kEplSuccessful; // init instance structure EplEventkInstance_g.m_uiUserToKernelFullCount = 0; // save cb-function EplEventkInstance_g.m_pfnCbSync = pfnCbSync_p; #ifndef EPL_NO_FIFO // init shared loop buffer // kernel -> user ShbError = ShbCirAllocBuffer(EPL_EVENT_SIZE_SHB_KERNEL_TO_USER, EPL_EVENT_NAME_SHB_KERNEL_TO_USER, &EplEventkInstance_g. m_pShbKernelToUserInstance, &fShbNewCreated); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventkAddInstance(): ShbCirAllocBuffer(K2U) -> 0x%X\n", ShbError); Ret = kEplNoResource; goto Exit; } // user -> kernel ShbError = ShbCirAllocBuffer(EPL_EVENT_SIZE_SHB_USER_TO_KERNEL, EPL_EVENT_NAME_SHB_USER_TO_KERNEL, &EplEventkInstance_g. m_pShbUserToKernelInstance, &fShbNewCreated); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventkAddInstance(): ShbCirAllocBuffer(U2K) -> 0x%X\n", ShbError); Ret = kEplNoResource; goto Exit; } // register eventhandler ShbError = ShbCirSetSignalHandlerNewData(EplEventkInstance_g. m_pShbUserToKernelInstance, EplEventkRxSignalHandlerCb, kshbPriorityHigh); if (ShbError != kShbOk) { EPL_DBGLVL_EVENTK_TRACE1 ("EplEventkAddInstance(): ShbCirSetSignalHandlerNewData(U2K) -> 0x%X\n", ShbError); Ret = kEplNoResource; goto Exit; } Exit: #endif return Ret; }