sata_fsl: Add power mgmt support
[linux-2.6] / 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 TgtDbgSignalTracePoint(u8 bTracePointNumber_p);
104 void TgtDbgPostTraceValue(u32 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 #ifndef EPL_NO_FIFO
118         tShbInstance m_pShbKernelToUserInstance;
119         tShbInstance m_pShbUserToKernelInstance;
120 #else
121
122 #endif
123         tEplSyncCb m_pfnCbSync;
124         unsigned int m_uiUserToKernelFullCount;
125
126 } tEplEventkInstance;
127
128 //---------------------------------------------------------------------------
129 // modul globale vars
130 //---------------------------------------------------------------------------
131 static tEplEventkInstance EplEventkInstance_g;
132 //---------------------------------------------------------------------------
133 // local function prototypes
134 //---------------------------------------------------------------------------
135
136 // callback function for incoming events
137 #ifndef EPL_NO_FIFO
138 static void EplEventkRxSignalHandlerCb(tShbInstance pShbRxInstance_p,
139                                        unsigned long ulDataSize_p);
140 #endif
141
142 /***************************************************************************/
143 /*                                                                         */
144 /*                                                                         */
145 /*          C L A S S  <Epl-Kernelspace-Event>                             */
146 /*                                                                         */
147 /*                                                                         */
148 /***************************************************************************/
149 //
150 // Description:
151 //
152 //
153 /***************************************************************************/
154
155 //=========================================================================//
156 //                                                                         //
157 //          P U B L I C   F U N C T I O N S                                //
158 //                                                                         //
159 //=========================================================================//
160
161 //---------------------------------------------------------------------------
162 //
163 // Function:    EplEventkInit
164 //
165 // Description: function initializes the first instance
166 //
167 // Parameters:  pfnCbSync_p = callback-function for sync event
168 //
169 // Returns:     tEpKernel   = errorcode
170 //
171 // State:
172 //
173 //---------------------------------------------------------------------------
174
175 tEplKernel EplEventkInit(tEplSyncCb pfnCbSync_p)
176 {
177         tEplKernel Ret;
178
179         Ret = EplEventkAddInstance(pfnCbSync_p);
180
181         return Ret;
182
183 }
184
185 //---------------------------------------------------------------------------
186 //
187 // Function:    EplEventkAddInstance
188 //
189 // Description: function adds one more instance
190 //
191 // Parameters:  pfnCbSync_p = callback-function for sync event
192 //
193 // Returns:     tEpKernel   = errorcode
194 //
195 // State:
196 //
197 //---------------------------------------------------------------------------
198
199 tEplKernel EplEventkAddInstance(tEplSyncCb pfnCbSync_p)
200 {
201         tEplKernel Ret;
202 #ifndef EPL_NO_FIFO
203         tShbError ShbError;
204         unsigned int fShbNewCreated;
205 #endif
206
207         Ret = kEplSuccessful;
208
209         // init instance structure
210         EplEventkInstance_g.m_uiUserToKernelFullCount = 0;
211
212         // save cb-function
213         EplEventkInstance_g.m_pfnCbSync = pfnCbSync_p;
214
215 #ifndef EPL_NO_FIFO
216         // init shared loop buffer
217         // kernel -> user
218         ShbError = ShbCirAllocBuffer(EPL_EVENT_SIZE_SHB_KERNEL_TO_USER,
219                                      EPL_EVENT_NAME_SHB_KERNEL_TO_USER,
220                                      &EplEventkInstance_g.
221                                      m_pShbKernelToUserInstance,
222                                      &fShbNewCreated);
223         if (ShbError != kShbOk) {
224                 EPL_DBGLVL_EVENTK_TRACE1
225                     ("EplEventkAddInstance(): ShbCirAllocBuffer(K2U) -> 0x%X\n",
226                      ShbError);
227                 Ret = kEplNoResource;
228                 goto Exit;
229         }
230         // user -> kernel
231         ShbError = ShbCirAllocBuffer(EPL_EVENT_SIZE_SHB_USER_TO_KERNEL,
232                                      EPL_EVENT_NAME_SHB_USER_TO_KERNEL,
233                                      &EplEventkInstance_g.
234                                      m_pShbUserToKernelInstance,
235                                      &fShbNewCreated);
236         if (ShbError != kShbOk) {
237                 EPL_DBGLVL_EVENTK_TRACE1
238                     ("EplEventkAddInstance(): ShbCirAllocBuffer(U2K) -> 0x%X\n",
239                      ShbError);
240                 Ret = kEplNoResource;
241                 goto Exit;
242         }
243         // register eventhandler
244         ShbError =
245             ShbCirSetSignalHandlerNewData(EplEventkInstance_g.
246                                           m_pShbUserToKernelInstance,
247                                           EplEventkRxSignalHandlerCb,
248                                           kshbPriorityHigh);
249         if (ShbError != kShbOk) {
250                 EPL_DBGLVL_EVENTK_TRACE1
251                     ("EplEventkAddInstance(): ShbCirSetSignalHandlerNewData(U2K) -> 0x%X\n",
252                      ShbError);
253                 Ret = kEplNoResource;
254                 goto Exit;
255         }
256
257       Exit:
258 #endif
259
260         return Ret;
261
262 }
263
264 //---------------------------------------------------------------------------
265 //
266 // Function:    EplEventkDelInstance
267 //
268 // Description: function deletes instance and frees the buffers
269 //
270 // Parameters:  void
271 //
272 // Returns:     tEpKernel   = errorcode
273 //
274 // State:
275 //
276 //---------------------------------------------------------------------------
277
278 tEplKernel EplEventkDelInstance(void)
279 {
280         tEplKernel Ret;
281 #ifndef EPL_NO_FIFO
282         tShbError ShbError;
283 #endif
284
285         Ret = kEplSuccessful;
286
287 #ifndef EPL_NO_FIFO
288         // set eventhandler to NULL
289         ShbError =
290             ShbCirSetSignalHandlerNewData(EplEventkInstance_g.
291                                           m_pShbUserToKernelInstance, NULL,
292                                           kShbPriorityNormal);
293         if (ShbError != kShbOk) {
294                 EPL_DBGLVL_EVENTK_TRACE1
295                     ("EplEventkDelInstance(): ShbCirSetSignalHandlerNewData(U2K) -> 0x%X\n",
296                      ShbError);
297                 Ret = kEplNoResource;
298         }
299         // free buffer User -> Kernel
300         ShbError =
301             ShbCirReleaseBuffer(EplEventkInstance_g.m_pShbUserToKernelInstance);
302         if (ShbError != kShbOk) {
303                 EPL_DBGLVL_EVENTK_TRACE1
304                     ("EplEventkDelInstance(): ShbCirReleaseBuffer(U2K) -> 0x%X\n",
305                      ShbError);
306                 Ret = kEplNoResource;
307         } else {
308                 EplEventkInstance_g.m_pShbUserToKernelInstance = NULL;
309         }
310
311         // free buffer  Kernel -> User
312         ShbError =
313             ShbCirReleaseBuffer(EplEventkInstance_g.m_pShbKernelToUserInstance);
314         if (ShbError != kShbOk) {
315                 EPL_DBGLVL_EVENTK_TRACE1
316                     ("EplEventkDelInstance(): ShbCirReleaseBuffer(K2U) -> 0x%X\n",
317                      ShbError);
318                 Ret = kEplNoResource;
319         } else {
320                 EplEventkInstance_g.m_pShbKernelToUserInstance = NULL;
321         }
322 #endif
323
324         return Ret;
325
326 }
327
328 //---------------------------------------------------------------------------
329 //
330 // Function:    EplEventkProcess
331 //
332 // Description: Kernelthread that dispatches events in kernel part
333 //
334 // Parameters:  pEvent_p    = pointer to event-structure from buffer
335 //
336 // Returns:     tEpKernel   = errorcode
337 //
338 // State:
339 //
340 //---------------------------------------------------------------------------
341
342 tEplKernel EplEventkProcess(tEplEvent *pEvent_p)
343 {
344         tEplKernel Ret;
345         tEplEventSource EventSource;
346
347         Ret = kEplSuccessful;
348
349         // error handling if event queue is full
350         if (EplEventkInstance_g.m_uiUserToKernelFullCount > 0) {        // 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 =
375                     ShbCirResetBuffer(EplEventkInstance_g.
376                                       m_pShbUserToKernelInstance, 1000, NULL);
377 #endif
378
379                 EplEventkInstance_g.m_uiUserToKernelFullCount = 0;
380                 TGT_DBG_SIGNAL_TRACE_POINT(22);
381
382                 // also discard the current event (it doesn't matter if we lose another event)
383                 goto Exit;
384         }
385         // check m_EventSink
386         switch (pEvent_p->m_EventSink) {
387         case kEplEventSinkSync:
388                 {
389                         if (EplEventkInstance_g.m_pfnCbSync != NULL) {
390                                 Ret = EplEventkInstance_g.m_pfnCbSync();
391                                 if (Ret == kEplSuccessful) {
392 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
393                                         // mark TPDOs as valid
394                                         Ret = EplPdokCalSetTpdosValid(TRUE);
395 #endif
396                                 } else if ((Ret != kEplReject)
397                                            && (Ret != kEplShutdown)) {
398                                         EventSource = kEplEventSourceSyncCb;
399
400                                         // Error event for API layer
401                                         EplEventkPostError
402                                             (kEplEventSourceEventk, Ret,
403                                              sizeof(EventSource), &EventSource);
404                                 }
405                         }
406                         break;
407                 }
408
409                 // NMT-Kernel-Modul
410         case kEplEventSinkNmtk:
411                 {
412 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
413                         Ret = EplNmtkProcess(pEvent_p);
414                         if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
415                                 EventSource = kEplEventSourceNmtk;
416
417                                 // Error event for API layer
418                                 EplEventkPostError(kEplEventSourceEventk,
419                                                    Ret,
420                                                    sizeof(EventSource),
421                                                    &EventSource);
422                         }
423 #endif
424 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
425                         if ((pEvent_p->m_EventType == kEplEventTypeNmtEvent)
426                             &&
427                             ((*((tEplNmtEvent *) pEvent_p->m_pArg) ==
428                               kEplNmtEventDllCeSoa)
429 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
430                              || (*((tEplNmtEvent *) pEvent_p->m_pArg) ==
431                                  kEplNmtEventDllMeSoaSent)
432 #endif
433                             )) {        // forward SoA event to error handler
434                                 Ret = EplErrorHandlerkProcess(pEvent_p);
435                                 if ((Ret != kEplSuccessful)
436                                     && (Ret != kEplShutdown)) {
437                                         EventSource = kEplEventSourceErrk;
438
439                                         // Error event for API layer
440                                         EplEventkPostError
441                                             (kEplEventSourceEventk, Ret,
442                                              sizeof(EventSource), &EventSource);
443                                 }
444 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
445                                 // forward SoA event to PDO module
446                                 pEvent_p->m_EventType = kEplEventTypePdoSoa;
447                                 Ret = EplPdokProcess(pEvent_p);
448                                 if ((Ret != kEplSuccessful)
449                                     && (Ret != kEplShutdown)) {
450                                         EventSource = kEplEventSourcePdok;
451
452                                         // Error event for API layer
453                                         EplEventkPostError
454                                             (kEplEventSourceEventk, Ret,
455                                              sizeof(EventSource), &EventSource);
456                                 }
457 #endif
458
459                         }
460                         break;
461 #endif
462                 }
463
464                 // events for Dllk module
465         case kEplEventSinkDllk:
466                 {
467 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
468                         Ret = EplDllkProcess(pEvent_p);
469                         if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
470                                 EventSource = kEplEventSourceDllk;
471
472                                 // Error event for API layer
473                                 EplEventkPostError(kEplEventSourceEventk,
474                                                    Ret,
475                                                    sizeof(EventSource),
476                                                    &EventSource);
477                         }
478 #endif
479                         break;
480                 }
481
482                 // events for DllkCal module
483         case kEplEventSinkDllkCal:
484                 {
485 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
486                         Ret = EplDllkCalProcess(pEvent_p);
487                         if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
488                                 EventSource = kEplEventSourceDllk;
489
490                                 // Error event for API layer
491                                 EplEventkPostError(kEplEventSourceEventk,
492                                                    Ret,
493                                                    sizeof(EventSource),
494                                                    &EventSource);
495                         }
496 #endif
497                         break;
498                 }
499
500                 //
501         case kEplEventSinkPdok:
502                 {
503                         // PDO-Module
504 #if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
505                         Ret = EplPdokProcess(pEvent_p);
506                         if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
507                                 EventSource = kEplEventSourcePdok;
508
509                                 // Error event for API layer
510                                 EplEventkPostError(kEplEventSourceEventk,
511                                                    Ret,
512                                                    sizeof(EventSource),
513                                                    &EventSource);
514                         }
515 #endif
516                         break;
517                 }
518
519                 // events for Error handler module
520         case kEplEventSinkErrk:
521                 {
522                         // only call error handler if DLL is present
523 #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
524                         Ret = EplErrorHandlerkProcess(pEvent_p);
525                         if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
526                                 EventSource = kEplEventSourceErrk;
527
528                                 // Error event for API layer
529                                 EplEventkPostError(kEplEventSourceEventk,
530                                                    Ret,
531                                                    sizeof(EventSource),
532                                                    &EventSource);
533                         }
534                         break;
535 #endif
536                 }
537
538                 // unknown sink
539         default:
540                 {
541                         Ret = kEplEventUnknownSink;
542                 }
543
544         }                       // end of switch(pEvent_p->m_EventSink)
545
546       Exit:
547         return Ret;
548
549 }
550
551 //---------------------------------------------------------------------------
552 //
553 // Function:    EplEventkPost
554 //
555 // Description: post events from kernel part
556 //
557 // Parameters:  pEvent_p    = pointer to event-structure from buffer
558 //
559 // Returns:     tEpKernel   = errorcode
560 //
561 // State:
562 //
563 //---------------------------------------------------------------------------
564
565 tEplKernel EplEventkPost(tEplEvent *pEvent_p)
566 {
567         tEplKernel Ret;
568 #ifndef EPL_NO_FIFO
569         tShbError ShbError;
570         tShbCirChunk ShbCirChunk;
571         unsigned long ulDataSize;
572         unsigned int fBufferCompleted;
573 #endif
574
575         Ret = kEplSuccessful;
576
577         // the event must be posted by using the abBuffer
578         // it is neede because the Argument must by copied
579         // to the buffer too and not only the pointer
580
581 #ifndef EPL_NO_FIFO
582         // 2006/08/03 d.k.: Event and argument are posted as separate chunks to the event queue.
583         ulDataSize =
584             sizeof(tEplEvent) +
585             ((pEvent_p->m_pArg != NULL) ? pEvent_p->m_uiSize : 0);
586 #endif
587
588         // decide in which buffer the event have to write
589         switch (pEvent_p->m_EventSink) {
590                 // kernelspace modules
591         case kEplEventSinkSync:
592         case kEplEventSinkNmtk:
593         case kEplEventSinkDllk:
594         case kEplEventSinkDllkCal:
595         case kEplEventSinkPdok:
596         case kEplEventSinkErrk:
597                 {
598 #ifndef EPL_NO_FIFO
599                         // post message
600                         BENCHMARK_MOD_27_SET(2);
601                         ShbError =
602                             ShbCirAllocDataBlock(EplEventkInstance_g.
603                                                  m_pShbUserToKernelInstance,
604                                                  &ShbCirChunk, ulDataSize);
605                         switch (ShbError) {
606                         case kShbOk:
607                                 break;
608
609                         case kShbBufferFull:
610                                 {
611                                         EplEventkInstance_g.
612                                             m_uiUserToKernelFullCount++;
613                                         Ret = kEplEventPostError;
614                                         goto Exit;
615                                 }
616
617                         default:
618                                 {
619                                         EPL_DBGLVL_EVENTK_TRACE1
620                                             ("EplEventkPost(): ShbCirAllocDataBlock(U2K) -> 0x%X\n",
621                                              ShbError);
622                                         Ret = kEplEventPostError;
623                                         goto Exit;
624                                 }
625                         }
626                         ShbError =
627                             ShbCirWriteDataChunk(EplEventkInstance_g.
628                                                  m_pShbUserToKernelInstance,
629                                                  &ShbCirChunk, pEvent_p,
630                                                  sizeof(tEplEvent),
631                                                  &fBufferCompleted);
632                         if (ShbError != kShbOk) {
633                                 EPL_DBGLVL_EVENTK_TRACE1
634                                     ("EplEventkPost(): ShbCirWriteDataChunk(U2K) -> 0x%X\n",
635                                      ShbError);
636                                 Ret = kEplEventPostError;
637                                 goto Exit;
638                         }
639                         if (fBufferCompleted == FALSE) {
640                                 ShbError =
641                                     ShbCirWriteDataChunk(EplEventkInstance_g.
642                                                          m_pShbUserToKernelInstance,
643                                                          &ShbCirChunk,
644                                                          pEvent_p->m_pArg,
645                                                          (unsigned long)
646                                                          pEvent_p->m_uiSize,
647                                                          &fBufferCompleted);
648                                 if ((ShbError != kShbOk)
649                                     || (fBufferCompleted == FALSE)) {
650                                         EPL_DBGLVL_EVENTK_TRACE1
651                                             ("EplEventkPost(): ShbCirWriteDataChunk2(U2K) -> 0x%X\n",
652                                              ShbError);
653                                         Ret = kEplEventPostError;
654                                         goto Exit;
655                                 }
656                         }
657                         BENCHMARK_MOD_27_RESET(2);
658
659 #else
660                         Ret = EplEventkProcess(pEvent_p);
661 #endif
662
663                         break;
664                 }
665
666                 // userspace modules
667         case kEplEventSinkNmtu:
668         case kEplEventSinkNmtMnu:
669         case kEplEventSinkSdoAsySeq:
670         case kEplEventSinkApi:
671         case kEplEventSinkDlluCal:
672         case kEplEventSinkErru:
673                 {
674 #ifndef EPL_NO_FIFO
675                         // post message
676 //            BENCHMARK_MOD_27_SET(3);    // 74 µs until reset
677                         ShbError =
678                             ShbCirAllocDataBlock(EplEventkInstance_g.
679                                                  m_pShbKernelToUserInstance,
680                                                  &ShbCirChunk, ulDataSize);
681                         if (ShbError != kShbOk) {
682                                 EPL_DBGLVL_EVENTK_TRACE1
683                                     ("EplEventkPost(): ShbCirAllocDataBlock(K2U) -> 0x%X\n",
684                                      ShbError);
685                                 Ret = kEplEventPostError;
686                                 goto Exit;
687                         }
688                         ShbError =
689                             ShbCirWriteDataChunk(EplEventkInstance_g.
690                                                  m_pShbKernelToUserInstance,
691                                                  &ShbCirChunk, pEvent_p,
692                                                  sizeof(tEplEvent),
693                                                  &fBufferCompleted);
694                         if (ShbError != kShbOk) {
695                                 EPL_DBGLVL_EVENTK_TRACE1
696                                     ("EplEventkPost(): ShbCirWriteDataChunk(K2U) -> 0x%X\n",
697                                      ShbError);
698                                 Ret = kEplEventPostError;
699                                 goto Exit;
700                         }
701                         if (fBufferCompleted == FALSE) {
702                                 ShbError =
703                                     ShbCirWriteDataChunk(EplEventkInstance_g.
704                                                          m_pShbKernelToUserInstance,
705                                                          &ShbCirChunk,
706                                                          pEvent_p->m_pArg,
707                                                          (unsigned long)
708                                                          pEvent_p->m_uiSize,
709                                                          &fBufferCompleted);
710                                 if ((ShbError != kShbOk)
711                                     || (fBufferCompleted == FALSE)) {
712                                         EPL_DBGLVL_EVENTK_TRACE1
713                                             ("EplEventkPost(): ShbCirWriteDataChunk2(K2U) -> 0x%X\n",
714                                              ShbError);
715                                         Ret = kEplEventPostError;
716                                         goto Exit;
717                                 }
718                         }
719 //            BENCHMARK_MOD_27_RESET(3);  // 82 µs until ShbCirGetReadDataSize() in EplEventu
720
721 #else
722                         Ret = EplEventuProcess(pEvent_p);
723 #endif
724
725                         break;
726                 }
727
728         default:
729                 {
730                         Ret = kEplEventUnknownSink;
731                 }
732
733         }                       // end of switch(pEvent_p->m_EventSink)
734
735 #ifndef EPL_NO_FIFO
736       Exit:
737 #endif
738         return Ret;
739 }
740
741 //---------------------------------------------------------------------------
742 //
743 // Function:    EplEventkPostError
744 //
745 // Description: post error event from kernel part to API layer
746 //
747 // Parameters:  EventSource_p   = source-module of the error event
748 //              EplError_p      = code of occured error
749 //              ArgSize_p       = size of the argument
750 //              pArg_p          = pointer to the argument
751 //
752 // Returns:     tEpKernel       = errorcode
753 //
754 // State:
755 //
756 //---------------------------------------------------------------------------
757
758 tEplKernel EplEventkPostError(tEplEventSource EventSource_p,
759                               tEplKernel EplError_p,
760                               unsigned int uiArgSize_p, void *pArg_p)
761 {
762         tEplKernel Ret;
763         u8 abBuffer[EPL_MAX_EVENT_ARG_SIZE];
764         tEplEventError *pEventError = (tEplEventError *) abBuffer;
765         tEplEvent EplEvent;
766
767         Ret = kEplSuccessful;
768
769         // create argument
770         pEventError->m_EventSource = EventSource_p;
771         pEventError->m_EplError = EplError_p;
772         EPL_MEMCPY(&pEventError->m_Arg, pArg_p, uiArgSize_p);
773
774         // create event
775         EplEvent.m_EventType = kEplEventTypeError;
776         EplEvent.m_EventSink = kEplEventSinkApi;
777         EPL_MEMSET(&EplEvent.m_NetTime, 0x00, sizeof(EplEvent.m_NetTime));
778         EplEvent.m_uiSize =
779             (sizeof(EventSource_p) + sizeof(EplError_p) + uiArgSize_p);
780         EplEvent.m_pArg = &abBuffer[0];
781
782         // post errorevent
783         Ret = EplEventkPost(&EplEvent);
784
785         return Ret;
786 }
787
788 //=========================================================================//
789 //                                                                         //
790 //          P R I V A T E   F U N C T I O N S                              //
791 //                                                                         //
792 //=========================================================================//
793
794 //---------------------------------------------------------------------------
795 //
796 // Function:    EplEventkRxSignalHandlerCb()
797 //
798 // Description: Callback-function for events from user and kernel part
799 //
800 // Parameters:  pShbRxInstance_p    = Instance-pointer of buffer
801 //              ulDataSize_p        = size of data
802 //
803 // Returns: void
804 //
805 // State:
806 //
807 //---------------------------------------------------------------------------
808
809 #ifndef EPL_NO_FIFO
810 static void EplEventkRxSignalHandlerCb(tShbInstance pShbRxInstance_p,
811                                        unsigned long ulDataSize_p)
812 {
813         tEplEvent *pEplEvent;
814         tShbError ShbError;
815 //unsigned long   ulBlockCount;
816 //unsigned long   ulDataSize;
817         u8 abDataBuffer[sizeof(tEplEvent) + EPL_MAX_EVENT_ARG_SIZE];
818         // d.k.: abDataBuffer contains the complete tEplEvent structure
819         //       and behind this the argument
820
821         TGT_DBG_SIGNAL_TRACE_POINT(20);
822
823         BENCHMARK_MOD_27_RESET(0);
824         // copy data from event queue
825         ShbError = ShbCirReadDataBlock(pShbRxInstance_p,
826                                        &abDataBuffer[0],
827                                        sizeof(abDataBuffer), &ulDataSize_p);
828         if (ShbError != kShbOk) {
829                 // error goto exit
830                 goto Exit;
831         }
832         // resolve the pointer to the event structure
833         pEplEvent = (tEplEvent *) abDataBuffer;
834         // set Datasize
835         pEplEvent->m_uiSize = (ulDataSize_p - sizeof(tEplEvent));
836         if (pEplEvent->m_uiSize > 0) {
837                 // set pointer to argument
838                 pEplEvent->m_pArg = &abDataBuffer[sizeof(tEplEvent)];
839         } else {
840                 //set pointer to NULL
841                 pEplEvent->m_pArg = NULL;
842         }
843
844         BENCHMARK_MOD_27_SET(0);
845         // call processfunction
846         EplEventkProcess(pEplEvent);
847
848       Exit:
849         return;
850 }
851 #endif
852
853 // EOF