Staging: add epl stack
[firefly-linux-kernel-4.4.55.git] / drivers / staging / epl / EplEventk.c
1 /****************************************************************************
2
3   (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4       www.systec-electronic.com
5
6   Project:      openPOWERLINK
7
8   Description:  source file for Epl-Kernelspace-Event-Modul
9
10   License:
11
12     Redistribution and use in source and binary forms, with or without
13     modification, are permitted provided that the following conditions
14     are met:
15
16     1. Redistributions of source code must retain the above copyright
17        notice, this list of conditions and the following disclaimer.
18
19     2. Redistributions in binary form must reproduce the above copyright
20        notice, this list of conditions and the following disclaimer in the
21        documentation and/or other materials provided with the distribution.
22
23     3. Neither the name of SYSTEC electronic GmbH nor the names of its
24        contributors may be used to endorse or promote products derived
25        from this software without prior written permission. For written
26        permission, please contact info@systec-electronic.com.
27
28     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32     COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39     POSSIBILITY OF SUCH DAMAGE.
40
41     Severability Clause:
42
43         If a provision of this License is or becomes illegal, invalid or
44         unenforceable in any jurisdiction, that shall not affect:
45         1. the validity or enforceability in that jurisdiction of any other
46            provision of this License; or
47         2. the validity or enforceability in other jurisdictions of that or
48            any other provision of this License.
49
50   -------------------------------------------------------------------------
51
52                 $RCSfile: EplEventk.c,v $
53
54                 $Author: D.Krueger $
55
56                 $Revision: 1.9 $  $Date: 2008/10/17 15:32:32 $
57
58                 $State: Exp $
59
60                 Build Environment:
61                     GCC V3.4
62
63   -------------------------------------------------------------------------
64
65   Revision History:
66
67   2006/06/20 k.t.:   start of the implementation
68
69 ****************************************************************************/
70
71 #include "kernel/EplEventk.h"
72 #include "kernel/EplNmtk.h"
73 #include "kernel/EplDllk.h"
74 #include "kernel/EplDllkCal.h"
75 #include "kernel/EplErrorHandlerk.h"
76 #include "Benchmark.h"
77
78 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
79 #include "kernel/EplPdok.h"
80 #include "kernel/EplPdokCal.h"
81 #endif
82
83 #ifdef EPL_NO_FIFO
84     #include "user/EplEventu.h"
85 #else
86     #include "SharedBuff.h"
87 #endif
88
89 /***************************************************************************/
90 /*                                                                         */
91 /*                                                                         */
92 /*          G L O B A L   D E F I N I T I O N S                            */
93 /*                                                                         */
94 /*                                                                         */
95 /***************************************************************************/
96
97 //---------------------------------------------------------------------------
98 // const defines
99 //---------------------------------------------------------------------------
100
101 // TracePoint support for realtime-debugging
102 #ifdef _DBG_TRACE_POINTS_
103     void  PUBLIC  TgtDbgSignalTracePoint (BYTE bTracePointNumber_p);
104     void  PUBLIC  TgtDbgPostTraceValue (DWORD dwTraceValue_p);
105     #define TGT_DBG_SIGNAL_TRACE_POINT(p)   TgtDbgSignalTracePoint(p)
106     #define TGT_DBG_POST_TRACE_VALUE(v)     TgtDbgPostTraceValue(v)
107 #else
108     #define TGT_DBG_SIGNAL_TRACE_POINT(p)
109     #define TGT_DBG_POST_TRACE_VALUE(v)
110 #endif
111
112 //---------------------------------------------------------------------------
113 // local types
114 //---------------------------------------------------------------------------
115
116 typedef struct
117 {
118 #ifndef EPL_NO_FIFO
119     tShbInstance    m_pShbKernelToUserInstance;
120     tShbInstance    m_pShbUserToKernelInstance;
121 #else
122
123 #endif
124     tEplSyncCb      m_pfnCbSync;
125     unsigned int    m_uiUserToKernelFullCount;
126
127 } tEplEventkInstance;
128
129 //---------------------------------------------------------------------------
130 // modul globale vars
131 //---------------------------------------------------------------------------
132 static tEplEventkInstance EplEventkInstance_g;
133 //---------------------------------------------------------------------------
134 // local function prototypes
135 //---------------------------------------------------------------------------
136
137 // callback function for incoming events
138 #ifndef EPL_NO_FIFO
139 static void  EplEventkRxSignalHandlerCb (
140     tShbInstance pShbRxInstance_p,
141     unsigned long ulDataSize_p);
142 #endif
143
144 /***************************************************************************/
145 /*                                                                         */
146 /*                                                                         */
147 /*          C L A S S  <Epl-Kernelspace-Event>                             */
148 /*                                                                         */
149 /*                                                                         */
150 /***************************************************************************/
151 //
152 // Description:
153 //
154 //
155 /***************************************************************************/
156
157 //=========================================================================//
158 //                                                                         //
159 //          P U B L I C   F U N C T I O N S                                //
160 //                                                                         //
161 //=========================================================================//
162
163 //---------------------------------------------------------------------------
164 //
165 // Function:    EplEventkInit
166 //
167 // Description: function initializes the first instance
168 //
169 // Parameters:  pfnCbSync_p = callback-function for sync event
170 //
171 // Returns:     tEpKernel   = errorcode
172 //
173 // State:
174 //
175 //---------------------------------------------------------------------------
176
177 tEplKernel PUBLIC EplEventkInit(tEplSyncCb pfnCbSync_p)
178 {
179 tEplKernel Ret;
180
181     Ret = EplEventkAddInstance(pfnCbSync_p);
182
183     return Ret;
184
185 }
186
187
188 //---------------------------------------------------------------------------
189 //
190 // Function:    EplEventkAddInstance
191 //
192 // Description: function adds one more instance
193 //
194 // Parameters:  pfnCbSync_p = callback-function for sync event
195 //
196 // Returns:     tEpKernel   = errorcode
197 //
198 // State:
199 //
200 //---------------------------------------------------------------------------
201
202 tEplKernel PUBLIC EplEventkAddInstance(tEplSyncCb pfnCbSync_p)
203 {
204 tEplKernel      Ret;
205 #ifndef EPL_NO_FIFO
206 tShbError       ShbError;
207 unsigned int    fShbNewCreated;
208 #endif
209
210     Ret = kEplSuccessful;
211
212     // init instance structure
213     EplEventkInstance_g.m_uiUserToKernelFullCount = 0;
214
215     // save cb-function
216     EplEventkInstance_g.m_pfnCbSync = pfnCbSync_p;
217
218 #ifndef EPL_NO_FIFO
219     // init shared loop buffer
220     // kernel -> user
221     ShbError = ShbCirAllocBuffer (EPL_EVENT_SIZE_SHB_KERNEL_TO_USER,
222                                   EPL_EVENT_NAME_SHB_KERNEL_TO_USER,
223                                   &EplEventkInstance_g.m_pShbKernelToUserInstance,
224                                   &fShbNewCreated);
225     if(ShbError != kShbOk)
226     {
227         EPL_DBGLVL_EVENTK_TRACE1("EplEventkAddInstance(): ShbCirAllocBuffer(K2U) -> 0x%X\n", ShbError);
228         Ret = kEplNoResource;
229         goto Exit;
230     }
231
232     // user -> kernel
233     ShbError = ShbCirAllocBuffer (EPL_EVENT_SIZE_SHB_USER_TO_KERNEL,
234                                   EPL_EVENT_NAME_SHB_USER_TO_KERNEL,
235                                   &EplEventkInstance_g.m_pShbUserToKernelInstance,
236                                   &fShbNewCreated);
237     if(ShbError != kShbOk)
238     {
239         EPL_DBGLVL_EVENTK_TRACE1("EplEventkAddInstance(): ShbCirAllocBuffer(U2K) -> 0x%X\n", ShbError);
240         Ret = kEplNoResource;
241         goto Exit;
242     }
243
244     // register eventhandler
245     ShbError = ShbCirSetSignalHandlerNewData (EplEventkInstance_g.m_pShbUserToKernelInstance,
246                                     EplEventkRxSignalHandlerCb,
247                                     kshbPriorityHigh);
248     if(ShbError != kShbOk)
249     {
250         EPL_DBGLVL_EVENTK_TRACE1("EplEventkAddInstance(): ShbCirSetSignalHandlerNewData(U2K) -> 0x%X\n", ShbError);
251         Ret = kEplNoResource;
252         goto Exit;
253     }
254
255 Exit:
256 #endif
257
258     return Ret;
259
260 }
261
262
263 //---------------------------------------------------------------------------
264 //
265 // Function:    EplEventkDelInstance
266 //
267 // Description: function deletes instance and frees the buffers
268 //
269 // Parameters:  void
270 //
271 // Returns:     tEpKernel   = errorcode
272 //
273 // State:
274 //
275 //---------------------------------------------------------------------------
276
277 tEplKernel PUBLIC EplEventkDelInstance()
278 {
279 tEplKernel      Ret;
280 #ifndef EPL_NO_FIFO
281 tShbError       ShbError;
282 #endif
283
284     Ret = kEplSuccessful;
285
286 #ifndef EPL_NO_FIFO
287     // set eventhandler to NULL
288     ShbError = ShbCirSetSignalHandlerNewData (EplEventkInstance_g.m_pShbUserToKernelInstance,
289                                     NULL,
290                                     kShbPriorityNormal);
291     if(ShbError != kShbOk)
292     {
293         EPL_DBGLVL_EVENTK_TRACE1("EplEventkDelInstance(): ShbCirSetSignalHandlerNewData(U2K) -> 0x%X\n", ShbError);
294         Ret = kEplNoResource;
295     }
296
297     // free buffer User -> Kernel
298     ShbError = ShbCirReleaseBuffer (EplEventkInstance_g.m_pShbUserToKernelInstance);
299     if(ShbError != kShbOk)
300     {
301         EPL_DBGLVL_EVENTK_TRACE1("EplEventkDelInstance(): ShbCirReleaseBuffer(U2K) -> 0x%X\n", ShbError);
302         Ret = kEplNoResource;
303     }
304     else
305     {
306         EplEventkInstance_g.m_pShbUserToKernelInstance = NULL;
307     }
308
309     // free buffer  Kernel -> User
310     ShbError = ShbCirReleaseBuffer (EplEventkInstance_g.m_pShbKernelToUserInstance);
311     if(ShbError != kShbOk)
312     {
313         EPL_DBGLVL_EVENTK_TRACE1("EplEventkDelInstance(): ShbCirReleaseBuffer(K2U) -> 0x%X\n", ShbError);
314         Ret = kEplNoResource;
315     }
316     else
317     {
318         EplEventkInstance_g.m_pShbKernelToUserInstance = NULL;
319     }
320 #endif
321
322 return Ret;
323
324 }
325
326
327 //---------------------------------------------------------------------------
328 //
329 // Function:    EplEventkProcess
330 //
331 // Description: Kernelthread that dispatches events in kernel part
332 //
333 // Parameters:  pEvent_p    = pointer to event-structure from buffer
334 //
335 // Returns:     tEpKernel   = errorcode
336 //
337 // State:
338 //
339 //---------------------------------------------------------------------------
340
341 tEplKernel PUBLIC EplEventkProcess(tEplEvent* pEvent_p)
342 {
343 tEplKernel              Ret;
344 tEplEventSource         EventSource;
345
346     Ret = kEplSuccessful;
347
348     // error handling if event queue is full
349     if (EplEventkInstance_g.m_uiUserToKernelFullCount > 0)
350     {   // UserToKernel event queue has run out of space -> kEplNmtEventInternComError
351 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
352         tEplEvent   Event;
353         tEplNmtEvent NmtEvent;
354 #endif
355 #ifndef EPL_NO_FIFO
356         tShbError   ShbError;
357 #endif
358
359         // directly call NMTk process function, because event queue is full
360 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
361         NmtEvent = kEplNmtEventInternComError;
362         Event.m_EventSink = kEplEventSinkNmtk;
363         Event.m_NetTime.m_dwNanoSec = 0;
364         Event.m_NetTime.m_dwSec = 0;
365         Event.m_EventType = kEplEventTypeNmtEvent;
366         Event.m_pArg = &NmtEvent;
367         Event.m_uiSize = sizeof(NmtEvent);
368         Ret = EplNmtkProcess(&Event);
369 #endif
370
371         // NMT state machine changed to reset (i.e. NMT_GS_RESET_COMMUNICATION)
372         // now, it is safe to reset the counter and empty the event queue
373 #ifndef EPL_NO_FIFO
374         ShbError = ShbCirResetBuffer (EplEventkInstance_g.m_pShbUserToKernelInstance, 1000, NULL);
375 #endif
376
377         EplEventkInstance_g.m_uiUserToKernelFullCount = 0;
378         TGT_DBG_SIGNAL_TRACE_POINT(22);
379
380         // also discard the current event (it doesn't matter if we lose another event)
381         goto Exit;
382     }
383
384     // check m_EventSink
385     switch(pEvent_p->m_EventSink)
386     {
387         case kEplEventSinkSync:
388         {
389             if (EplEventkInstance_g.m_pfnCbSync != NULL)
390             {
391                 Ret = EplEventkInstance_g.m_pfnCbSync();
392                 if (Ret == kEplSuccessful)
393                 {
394 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
395                     // mark TPDOs as valid
396                     Ret = EplPdokCalSetTpdosValid(TRUE);
397 #endif
398                 }
399                 else if ((Ret != kEplReject) && (Ret != kEplShutdown))
400                 {
401                     EventSource = kEplEventSourceSyncCb;
402
403                     // Error event for API layer
404                     EplEventkPostError(kEplEventSourceEventk,
405                                     Ret,
406                                     sizeof(EventSource),
407                                     &EventSource);
408                 }
409             }
410             break;
411         }
412
413         // NMT-Kernel-Modul
414         case kEplEventSinkNmtk:
415         {
416 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
417             Ret = EplNmtkProcess(pEvent_p);
418             if ((Ret != kEplSuccessful) && (Ret != kEplShutdown))
419             {
420                 EventSource = kEplEventSourceNmtk;
421
422                 // Error event for API layer
423                 EplEventkPostError(kEplEventSourceEventk,
424                                 Ret,
425                                 sizeof(EventSource),
426                                 &EventSource);
427             }
428 #endif
429 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
430             if ((pEvent_p->m_EventType == kEplEventTypeNmtEvent)
431                 && ((*((tEplNmtEvent*)pEvent_p->m_pArg) == kEplNmtEventDllCeSoa)
432 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
433                 || (*((tEplNmtEvent*)pEvent_p->m_pArg) == kEplNmtEventDllMeSoaSent)
434 #endif
435                 ))
436             {   // forward SoA event to error handler
437                 Ret = EplErrorHandlerkProcess(pEvent_p);
438                 if ((Ret != kEplSuccessful) && (Ret != kEplShutdown))
439                 {
440                     EventSource = kEplEventSourceErrk;
441
442                     // Error event for API layer
443                     EplEventkPostError(kEplEventSourceEventk,
444                                     Ret,
445                                     sizeof(EventSource),
446                                     &EventSource);
447                 }
448
449 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
450                 // forward SoA event to PDO module
451                 pEvent_p->m_EventType = kEplEventTypePdoSoa;
452                 Ret = EplPdokProcess(pEvent_p);
453                 if ((Ret != kEplSuccessful) && (Ret != kEplShutdown))
454                 {
455                     EventSource = kEplEventSourcePdok;
456
457                     // Error event for API layer
458                     EplEventkPostError(kEplEventSourceEventk,
459                                     Ret,
460                                     sizeof(EventSource),
461                                     &EventSource);
462                 }
463 #endif
464
465             }
466             break;
467 #endif
468         }
469
470         // events for Dllk module
471         case kEplEventSinkDllk:
472         {
473 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
474             Ret = EplDllkProcess(pEvent_p);
475             if ((Ret != kEplSuccessful) && (Ret != kEplShutdown))
476             {
477                 EventSource = kEplEventSourceDllk;
478
479                 // Error event for API layer
480                 EplEventkPostError(kEplEventSourceEventk,
481                                 Ret,
482                                 sizeof(EventSource),
483                                 &EventSource);
484             }
485 #endif
486             break;
487         }
488
489         // events for DllkCal module
490         case kEplEventSinkDllkCal:
491         {
492 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
493             Ret = EplDllkCalProcess(pEvent_p);
494             if ((Ret != kEplSuccessful) && (Ret != kEplShutdown))
495             {
496                 EventSource = kEplEventSourceDllk;
497
498                 // Error event for API layer
499                 EplEventkPostError(kEplEventSourceEventk,
500                                 Ret,
501                                 sizeof(EventSource),
502                                 &EventSource);
503             }
504 #endif
505             break;
506         }
507
508         //
509         case kEplEventSinkPdok:
510         {
511             // PDO-Module
512 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
513             Ret = EplPdokProcess(pEvent_p);
514             if ((Ret != kEplSuccessful) && (Ret != kEplShutdown))
515             {
516                 EventSource = kEplEventSourcePdok;
517
518                 // Error event for API layer
519                 EplEventkPostError(kEplEventSourceEventk,
520                                 Ret,
521                                 sizeof(EventSource),
522                                 &EventSource);
523             }
524 #endif
525             break;
526         }
527
528         // events for Error handler module
529         case kEplEventSinkErrk:
530         {
531             // only call error handler if DLL is present
532 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
533             Ret = EplErrorHandlerkProcess(pEvent_p);
534             if ((Ret != kEplSuccessful) && (Ret != kEplShutdown))
535             {
536                 EventSource = kEplEventSourceErrk;
537
538                 // Error event for API layer
539                 EplEventkPostError(kEplEventSourceEventk,
540                                 Ret,
541                                 sizeof(EventSource),
542                                 &EventSource);
543             }
544             break;
545 #endif
546         }
547
548         // unknown sink
549         default:
550         {
551             Ret = kEplEventUnknownSink;
552         }
553
554     } // end of switch(pEvent_p->m_EventSink)
555
556 Exit:
557     return Ret;
558
559 }
560
561
562 //---------------------------------------------------------------------------
563 //
564 // Function:    EplEventkPost
565 //
566 // Description: post events from kernel part
567 //
568 // Parameters:  pEvent_p    = pointer to event-structure from buffer
569 //
570 // Returns:     tEpKernel   = errorcode
571 //
572 // State:
573 //
574 //---------------------------------------------------------------------------
575
576 tEplKernel PUBLIC EplEventkPost(tEplEvent * pEvent_p)
577 {
578 tEplKernel      Ret;
579 #ifndef EPL_NO_FIFO
580 tShbError       ShbError;
581 tShbCirChunk    ShbCirChunk;
582 unsigned long   ulDataSize;
583 unsigned int    fBufferCompleted;
584 #endif
585
586     Ret = kEplSuccessful;
587
588
589     // the event must be posted by using the abBuffer
590     // it is neede because the Argument must by copied
591     // to the buffer too and not only the pointer
592
593 #ifndef EPL_NO_FIFO
594     // 2006/08/03 d.k.: Event and argument are posted as separate chunks to the event queue.
595     ulDataSize = sizeof(tEplEvent) + ((pEvent_p->m_pArg != NULL) ? pEvent_p->m_uiSize : 0);
596 #endif
597
598     // decide in which buffer the event have to write
599     switch(pEvent_p->m_EventSink)
600     {
601         // kernelspace modules
602         case kEplEventSinkSync:
603         case kEplEventSinkNmtk:
604         case kEplEventSinkDllk:
605         case kEplEventSinkDllkCal:
606         case kEplEventSinkPdok:
607         case kEplEventSinkErrk:
608         {
609 #ifndef EPL_NO_FIFO
610             // post message
611             BENCHMARK_MOD_27_SET(2);
612             ShbError = ShbCirAllocDataBlock (EplEventkInstance_g.m_pShbUserToKernelInstance,
613                                    &ShbCirChunk,
614                                    ulDataSize);
615             switch (ShbError)
616             {
617                 case kShbOk:
618                     break;
619
620                 case kShbBufferFull:
621                 {
622                     EplEventkInstance_g.m_uiUserToKernelFullCount++;
623                     Ret = kEplEventPostError;
624                     goto Exit;
625                 }
626
627                 default:
628                 {
629                     EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirAllocDataBlock(U2K) -> 0x%X\n", ShbError);
630                     Ret = kEplEventPostError;
631                     goto Exit;
632                 }
633             }
634             ShbError = ShbCirWriteDataChunk (EplEventkInstance_g.m_pShbUserToKernelInstance,
635                                    &ShbCirChunk,
636                                    pEvent_p,
637                                    sizeof (tEplEvent),
638                                    &fBufferCompleted);
639             if (ShbError != kShbOk)
640             {
641                 EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirWriteDataChunk(U2K) -> 0x%X\n", ShbError);
642                 Ret = kEplEventPostError;
643                 goto Exit;
644             }
645             if (fBufferCompleted == FALSE)
646             {
647                 ShbError = ShbCirWriteDataChunk (EplEventkInstance_g.m_pShbUserToKernelInstance,
648                                        &ShbCirChunk,
649                                        pEvent_p->m_pArg,
650                                        (unsigned long) pEvent_p->m_uiSize,
651                                        &fBufferCompleted);
652                 if ((ShbError != kShbOk) || (fBufferCompleted == FALSE))
653                 {
654                     EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirWriteDataChunk2(U2K) -> 0x%X\n", ShbError);
655                     Ret = kEplEventPostError;
656                     goto Exit;
657                 }
658             }
659             BENCHMARK_MOD_27_RESET(2);
660
661 #else
662             Ret = EplEventkProcess(pEvent_p);
663 #endif
664
665             break;
666         }
667
668         // userspace modules
669         case kEplEventSinkNmtu:
670         case kEplEventSinkNmtMnu:
671         case kEplEventSinkSdoAsySeq:
672         case kEplEventSinkApi:
673         case kEplEventSinkDlluCal:
674         case kEplEventSinkErru:
675         {
676 #ifndef EPL_NO_FIFO
677             // post message
678 //            BENCHMARK_MOD_27_SET(3);    // 74 µs until reset
679             ShbError = ShbCirAllocDataBlock (EplEventkInstance_g.m_pShbKernelToUserInstance,
680                                    &ShbCirChunk,
681                                    ulDataSize);
682             if(ShbError != kShbOk)
683             {
684                 EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirAllocDataBlock(K2U) -> 0x%X\n", ShbError);
685                 Ret = kEplEventPostError;
686                 goto Exit;
687             }
688             ShbError = ShbCirWriteDataChunk (EplEventkInstance_g.m_pShbKernelToUserInstance,
689                                    &ShbCirChunk,
690                                    pEvent_p,
691                                    sizeof (tEplEvent),
692                                    &fBufferCompleted);
693             if(ShbError != kShbOk)
694             {
695                 EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirWriteDataChunk(K2U) -> 0x%X\n", ShbError);
696                 Ret = kEplEventPostError;
697                 goto Exit;
698             }
699             if (fBufferCompleted == FALSE)
700             {
701                 ShbError = ShbCirWriteDataChunk (EplEventkInstance_g.m_pShbKernelToUserInstance,
702                                        &ShbCirChunk,
703                                        pEvent_p->m_pArg,
704                                        (unsigned long) pEvent_p->m_uiSize,
705                                        &fBufferCompleted);
706                 if ((ShbError != kShbOk) || (fBufferCompleted == FALSE))
707                 {
708                     EPL_DBGLVL_EVENTK_TRACE1("EplEventkPost(): ShbCirWriteDataChunk2(K2U) -> 0x%X\n", ShbError);
709                     Ret = kEplEventPostError;
710                     goto Exit;
711                 }
712             }
713 //            BENCHMARK_MOD_27_RESET(3);  // 82 µs until ShbCirGetReadDataSize() in EplEventu
714
715 #else
716             Ret = EplEventuProcess(pEvent_p);
717 #endif
718
719             break;
720         }
721
722         default:
723         {
724             Ret = kEplEventUnknownSink;
725         }
726
727
728     }// end of switch(pEvent_p->m_EventSink)
729
730 #ifndef EPL_NO_FIFO
731 Exit:
732 #endif
733     return Ret;
734 }
735
736
737 //---------------------------------------------------------------------------
738 //
739 // Function:    EplEventkPostError
740 //
741 // Description: post error event from kernel part to API layer
742 //
743 // Parameters:  EventSource_p   = source-module of the error event
744 //              EplError_p      = code of occured error
745 //              ArgSize_p       = size of the argument
746 //              pArg_p          = pointer to the argument
747 //
748 // Returns:     tEpKernel       = errorcode
749 //
750 // State:
751 //
752 //---------------------------------------------------------------------------
753
754 tEplKernel PUBLIC EplEventkPostError(tEplEventSource EventSource_p,
755                                      tEplKernel      EplError_p,
756                                      unsigned int    uiArgSize_p,
757                                      void*           pArg_p)
758 {
759 tEplKernel  Ret;
760 BYTE        abBuffer[EPL_MAX_EVENT_ARG_SIZE];
761 tEplEventError* pEventError = (tEplEventError*) abBuffer;
762 tEplEvent   EplEvent;
763
764     Ret = kEplSuccessful;
765
766     // create argument
767     pEventError->m_EventSource = EventSource_p;
768     pEventError->m_EplError = EplError_p;
769     EPL_MEMCPY(&pEventError->m_Arg, pArg_p, uiArgSize_p);
770
771     // create event
772     EplEvent.m_EventType = kEplEventTypeError;
773     EplEvent.m_EventSink = kEplEventSinkApi;
774     EPL_MEMSET(&EplEvent.m_NetTime, 0x00, sizeof(EplEvent.m_NetTime));
775     EplEvent.m_uiSize = (sizeof(EventSource_p)+ sizeof(EplError_p)+ uiArgSize_p);
776     EplEvent.m_pArg = &abBuffer[0];
777
778     // post errorevent
779     Ret = EplEventkPost(&EplEvent);
780
781     return Ret;
782 }
783
784
785 //=========================================================================//
786 //                                                                         //
787 //          P R I V A T E   F U N C T I O N S                              //
788 //                                                                         //
789 //=========================================================================//
790
791 //---------------------------------------------------------------------------
792 //
793 // Function:    EplEventkRxSignalHandlerCb()
794 //
795 // Description: Callback-function for events from user and kernel part
796 //
797 // Parameters:  pShbRxInstance_p    = Instance-pointer of buffer
798 //              ulDataSize_p        = size of data
799 //
800 // Returns: void
801 //
802 // State:
803 //
804 //---------------------------------------------------------------------------
805
806 #ifndef EPL_NO_FIFO
807 static void  EplEventkRxSignalHandlerCb (
808                 tShbInstance pShbRxInstance_p,
809                 unsigned long ulDataSize_p)
810 {
811 tEplEvent      *pEplEvent;
812 tShbError       ShbError;
813 //unsigned long   ulBlockCount;
814 //unsigned long   ulDataSize;
815 BYTE            abDataBuffer[sizeof(tEplEvent) + EPL_MAX_EVENT_ARG_SIZE];
816                 // d.k.: abDataBuffer contains the complete tEplEvent structure
817                 //       and behind this the argument
818
819     TGT_DBG_SIGNAL_TRACE_POINT(20);
820
821     BENCHMARK_MOD_27_RESET(0);
822     // copy data from event queue
823     ShbError = ShbCirReadDataBlock (pShbRxInstance_p,
824                             &abDataBuffer[0],
825                             sizeof(abDataBuffer),
826                             &ulDataSize_p);
827     if(ShbError != kShbOk)
828     {
829         // error goto exit
830         goto Exit;
831     }
832
833     // resolve the pointer to the event structure
834     pEplEvent = (tEplEvent *) abDataBuffer;
835     // set Datasize
836     pEplEvent->m_uiSize = (ulDataSize_p - sizeof(tEplEvent));
837     if(pEplEvent->m_uiSize > 0)
838     {
839         // set pointer to argument
840         pEplEvent->m_pArg = &abDataBuffer[sizeof(tEplEvent)];
841     }
842     else
843     {
844         //set pointer to NULL
845         pEplEvent->m_pArg = NULL;
846     }
847
848     BENCHMARK_MOD_27_SET(0);
849     // call processfunction
850     EplEventkProcess(pEplEvent);
851
852 Exit:
853     return;
854 }
855 #endif
856
857 // EOF
858