summaryrefslogtreecommitdiff
path: root/drivers/staging/epl/EplEventk.c
blob: ef36815c798420e5a48fc26867e6d922e33120d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
/****************************************************************************

  (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
      www.systec-electronic.com

  Project:      openPOWERLINK

  Description:  source file for Epl-Kernelspace-Event-Modul

  License:

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. Neither the name of SYSTEC electronic GmbH nor the names of its
       contributors may be used to endorse or promote products derived
       from this software without prior written permission. For written
       permission, please contact info@systec-electronic.com.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

    Severability Clause:

        If a provision of this License is or becomes illegal, invalid or
        unenforceable in any jurisdiction, that shall not affect:
        1. the validity or enforceability in that jurisdiction of any other
           provision of this License; or
        2. the validity or enforceability in other jurisdictions of that or
           any other provision of this License.

  -------------------------------------------------------------------------

                $RCSfile: EplEventk.c,v $

                $Author: D.Krueger $

                $Revision: 1.9 $  $Date: 2008/10/17 15:32:32 $

                $State: Exp $

                Build Environment:
                    GCC V3.4

  -------------------------------------------------------------------------

  Revision History:

  2006/06/20 k.t.:   start of the implementation

****************************************************************************/

#include "kernel/EplEventk.h"
#include "kernel/EplNmtk.h"
#include "kernel/EplDllk.h"
#include "kernel/EplDllkCal.h"
#include "kernel/EplErrorHandlerk.h"
#include "Benchmark.h"

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
#include "kernel/EplPdok.h"
#include "kernel/EplPdokCal.h"
#endif

#ifdef EPL_NO_FIFO
#include "user/EplEventu.h"
#else
#include "SharedBuff.h"
#endif

/***************************************************************************/
/*                                                                         */
/*                                                                         */
/*          G L O B A L   D E F I N I T I O N S                            */
/*                                                                         */
/*                                                                         */
/***************************************************************************/

//---------------------------------------------------------------------------
// const defines
//---------------------------------------------------------------------------

// TracePoint support for realtime-debugging
#ifdef _DBG_TRACE_POINTS_
void TgtDbgSignalTracePoint(u8 bTracePointNumber_p);
void TgtDbgPostTraceValue(u32 dwTraceValue_p);
#define TGT_DBG_SIGNAL_TRACE_POINT(p)   TgtDbgSignalTracePoint(p)
#define TGT_DBG_POST_TRACE_VALUE(v)     TgtDbgPostTraceValue(v)
#else
#define TGT_DBG_SIGNAL_TRACE_POINT(p)
#define TGT_DBG_POST_TRACE_VALUE(v)
#endif

//---------------------------------------------------------------------------
// local types
//---------------------------------------------------------------------------

typedef struct {
#ifndef EPL_NO_FIFO
	tShbInstance m_pShbKernelToUserInstance;
	tShbInstance m_pShbUserToKernelInstance;
#else

#endif
	tEplSyncCb m_pfnCbSync;
	unsigned int m_uiUserToKernelFullCount;

} tEplEventkInstance;

//---------------------------------------------------------------------------
// modul globale vars
//---------------------------------------------------------------------------
static tEplEventkInstance EplEventkInstance_g;
//---------------------------------------------------------------------------
// local function prototypes
//---------------------------------------------------------------------------

// callback function for incoming events
#ifndef EPL_NO_FIFO
static void EplEventkRxSignalHandlerCb(tShbInstance pShbRxInstance_p,
				       unsigned long ulDataSize_p);
#endif

/***************************************************************************/
/*                                                                         */
/*                                                                         */
/*          C L A S S  <Epl-Kernelspace-Event>                             */
/*                                                                         */
/*                                                                         */
/***************************************************************************/
//
// Description:
//
//
/***************************************************************************/

//=========================================================================//
//                                                                         //
//          P U B L I C   F U N C T I O N S                                //
//                                                                         //
//=========================================================================//

//---------------------------------------------------------------------------
//
// Function:    EplEventkInit
//
// Description: function initializes the first instance
//
// Parameters:  pfnCbSync_p = callback-function for sync event
//
// Returns:     tEpKernel   = errorcode
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplEventkInit(tEplSyncCb pfnCbSync_p)
{
	tEplKernel Ret;

	Ret = EplEventkAddInstance(pfnCbSync_p);

	return Ret;

}

//---------------------------------------------------------------------------
//
// Function:    EplEventkAddInstance
//
// Description: function adds one more instance
//
// Parameters:  pfnCbSync_p = callback-function for sync event
//
// Returns:     tEpKernel   = errorcode
//
// State:
//
//---------------------------------------------------------------------------

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;

}

//---------------------------------------------------------------------------
//
// Function:    EplEventkDelInstance
//
// Description: function deletes instance and frees the buffers
//
// Parameters:  void
//
// Returns:     tEpKernel   = errorcode
//
// State:
//
//---------------------------------------------------------------------------

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:    EplEventkProcess
//
// Description: Kernelthread that dispatches events in kernel part
//
// Parameters:  pEvent_p    = pointer to event-structure from buffer
//
// Returns:     tEpKernel   = errorcode
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplEventkProcess(tEplEvent *pEvent_p)
{
	tEplKernel Ret;
	tEplEventSource EventSource;

	Ret = kEplSuccessful;

	// error handling if event queue is full
	if (EplEventkInstance_g.m_uiUserToKernelFullCount > 0) {	// UserToKernel event queue has run out of space -> kEplNmtEventInternComError
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
		tEplEvent Event;
		tEplNmtEvent NmtEvent;
#endif
#ifndef EPL_NO_FIFO
		tShbError ShbError;
#endif

		// directly call NMTk process function, because event queue is full
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
		NmtEvent = kEplNmtEventInternComError;
		Event.m_EventSink = kEplEventSinkNmtk;
		Event.m_NetTime.m_dwNanoSec = 0;
		Event.m_NetTime.m_dwSec = 0;
		Event.m_EventType = kEplEventTypeNmtEvent;
		Event.m_pArg = &NmtEvent;
		Event.m_uiSize = sizeof(NmtEvent);
		Ret = EplNmtkProcess(&Event);
#endif

		// NMT state machine changed to reset (i.e. NMT_GS_RESET_COMMUNICATION)
		// now, it is safe to reset the counter and empty the event queue
#ifndef EPL_NO_FIFO
		ShbError =
		    ShbCirResetBuffer(EplEventkInstance_g.
				      m_pShbUserToKernelInstance, 1000, NULL);
#endif

		EplEventkInstance_g.m_uiUserToKernelFullCount = 0;
		TGT_DBG_SIGNAL_TRACE_POINT(22);

		// also discard the current event (it doesn't matter if we lose another event)
		goto Exit;
	}
	// check m_EventSink
	switch (pEvent_p->m_EventSink) {
	case kEplEventSinkSync:
		{
			if (EplEventkInstance_g.m_pfnCbSync != NULL) {
				Ret = EplEventkInstance_g.m_pfnCbSync();
				if (Ret == kEplSuccessful) {
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
					// mark TPDOs as valid
					Ret = EplPdokCalSetTpdosValid(TRUE);
#endif
				} else if ((Ret != kEplReject)
					   && (Ret != kEplShutdown)) {
					EventSource = kEplEventSourceSyncCb;

					// Error event for API layer
					EplEventkPostError
					    (kEplEventSourceEventk, Ret,
					     sizeof(EventSource), &EventSource);
				}
			}
			break;
		}

		// NMT-Kernel-Modul
	case kEplEventSinkNmtk:
		{
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) != 0)
			Ret = EplNmtkProcess(pEvent_p);
			if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
				EventSource = kEplEventSourceNmtk;

				// Error event for API layer
				EplEventkPostError(kEplEventSourceEventk,
						   Ret,
						   sizeof(EventSource),
						   &EventSource);
			}
#endif
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
			if ((pEvent_p->m_EventType == kEplEventTypeNmtEvent)
			    &&
			    ((*((tEplNmtEvent *) pEvent_p->m_pArg) ==
			      kEplNmtEventDllCeSoa)
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
			     || (*((tEplNmtEvent *) pEvent_p->m_pArg) ==
				 kEplNmtEventDllMeSoaSent)
#endif
			    )) {	// forward SoA event to error handler
				Ret = EplErrorHandlerkProcess(pEvent_p);
				if ((Ret != kEplSuccessful)
				    && (Ret != kEplShutdown)) {
					EventSource = kEplEventSourceErrk;

					// Error event for API layer
					EplEventkPostError
					    (kEplEventSourceEventk, Ret,
					     sizeof(EventSource), &EventSource);
				}
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
				// forward SoA event to PDO module
				pEvent_p->m_EventType = kEplEventTypePdoSoa;
				Ret = EplPdokProcess(pEvent_p);
				if ((Ret != kEplSuccessful)
				    && (Ret != kEplShutdown)) {
					EventSource = kEplEventSourcePdok;

					// Error event for API layer
					EplEventkPostError
					    (kEplEventSourceEventk, Ret,
					     sizeof(EventSource), &EventSource);
				}
#endif

			}
			break;
#endif
		}

		// events for Dllk module
	case kEplEventSinkDllk:
		{
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
			Ret = EplDllkProcess(pEvent_p);
			if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
				EventSource = kEplEventSourceDllk;

				// Error event for API layer
				EplEventkPostError(kEplEventSourceEventk,
						   Ret,
						   sizeof(EventSource),
						   &EventSource);
			}
#endif
			break;
		}

		// events for DllkCal module
	case kEplEventSinkDllkCal:
		{
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
			Ret = EplDllkCalProcess(pEvent_p);
			if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
				EventSource = kEplEventSourceDllk;

				// Error event for API layer
				EplEventkPostError(kEplEventSourceEventk,
						   Ret,
						   sizeof(EventSource),
						   &EventSource);
			}
#endif
			break;
		}

		//
	case kEplEventSinkPdok:
		{
			// PDO-Module
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
			Ret = EplPdokProcess(pEvent_p);
			if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
				EventSource = kEplEventSourcePdok;

				// Error event for API layer
				EplEventkPostError(kEplEventSourceEventk,
						   Ret,
						   sizeof(EventSource),
						   &EventSource);
			}
#endif
			break;
		}

		// events for Error handler module
	case kEplEventSinkErrk:
		{
			// only call error handler if DLL is present
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
			Ret = EplErrorHandlerkProcess(pEvent_p);
			if ((Ret != kEplSuccessful) && (Ret != kEplShutdown)) {
				EventSource = kEplEventSourceErrk;

				// Error event for API layer
				EplEventkPostError(kEplEventSourceEventk,
						   Ret,
						   sizeof(EventSource),
						   &EventSource);
			}
			break;
#endif
		}

		// unknown sink
	default:
		{
			Ret = kEplEventUnknownSink;
		}

	}			// end of switch(pEvent_p->m_EventSink)

      Exit:
	return Ret;

}

//---------------------------------------------------------------------------
//
// Function:    EplEventkPost
//
// Description: post events from kernel part
//
// Parameters:  pEvent_p    = pointer to event-structure from buffer
//
// Returns:     tEpKernel   = errorcode
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplEventkPost(tEplEvent *pEvent_p)
{
	tEplKernel Ret;
#ifndef EPL_NO_FIFO
	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

#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
			BENCHMARK_MOD_27_SET(2);
			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;
				}
			}
			BENCHMARK_MOD_27_RESET(2);

#else
			Ret = EplEventkProcess(pEvent_p);
#endif

			break;
		}

		// userspace modules
	case kEplEventSinkNmtu:
	case kEplEventSinkNmtMnu:
	case kEplEventSinkSdoAsySeq:
	case kEplEventSinkApi:
	case kEplEventSinkDlluCal:
	case kEplEventSinkErru:
		{
#ifndef EPL_NO_FIFO
			// 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)

#ifndef EPL_NO_FIFO
      Exit:
#endif
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplEventkPostError
//
// Description: post error event from kernel part to API layer
//
// Parameters:  EventSource_p   = source-module of the error event
//              EplError_p      = code of occured error
//              ArgSize_p       = size of the argument
//              pArg_p          = pointer to the argument
//
// Returns:     tEpKernel       = errorcode
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplEventkPostError(tEplEventSource EventSource_p,
			      tEplKernel EplError_p,
			      unsigned int uiArgSize_p, void *pArg_p)
{
	tEplKernel Ret;
	u8 abBuffer[EPL_MAX_EVENT_ARG_SIZE];
	tEplEventError *pEventError = (tEplEventError *) abBuffer;
	tEplEvent EplEvent;

	Ret = kEplSuccessful;

	// create argument
	pEventError->m_EventSource = EventSource_p;
	pEventError->m_EplError = EplError_p;
	EPL_MEMCPY(&pEventError->m_Arg, pArg_p, uiArgSize_p);

	// create event
	EplEvent.m_EventType = kEplEventTypeError;
	EplEvent.m_EventSink = kEplEventSinkApi;
	EPL_MEMSET(&EplEvent.m_NetTime, 0x00, sizeof(EplEvent.m_NetTime));
	EplEvent.m_uiSize =
	    (sizeof(EventSource_p) + sizeof(EplError_p) + uiArgSize_p);
	EplEvent.m_pArg = &abBuffer[0];

	// post errorevent
	Ret = EplEventkPost(&EplEvent);

	return Ret;
}

//=========================================================================//
//                                                                         //
//          P R I V A T E   F U N C T I O N S                              //
//                                                                         //
//=========================================================================//

//---------------------------------------------------------------------------
//
// Function:    EplEventkRxSignalHandlerCb()
//
// Description: Callback-function for events from user and kernel part
//
// Parameters:  pShbRxInstance_p    = Instance-pointer of buffer
//              ulDataSize_p        = size of data
//
// Returns: void
//
// State:
//
//---------------------------------------------------------------------------

#ifndef EPL_NO_FIFO
static void EplEventkRxSignalHandlerCb(tShbInstance pShbRxInstance_p,
				       unsigned long ulDataSize_p)
{
	tEplEvent *pEplEvent;
	tShbError ShbError;
//unsigned long   ulBlockCount;
//unsigned long   ulDataSize;
	u8 abDataBuffer[sizeof(tEplEvent) + EPL_MAX_EVENT_ARG_SIZE];
	// d.k.: abDataBuffer contains the complete tEplEvent structure
	//       and behind this the argument

	TGT_DBG_SIGNAL_TRACE_POINT(20);

	BENCHMARK_MOD_27_RESET(0);
	// copy data from event queue
	ShbError = ShbCirReadDataBlock(pShbRxInstance_p,
				       &abDataBuffer[0],
				       sizeof(abDataBuffer), &ulDataSize_p);
	if (ShbError != kShbOk) {
		// error goto exit
		goto Exit;
	}
	// resolve the pointer to the event structure
	pEplEvent = (tEplEvent *) abDataBuffer;
	// set Datasize
	pEplEvent->m_uiSize = (ulDataSize_p - sizeof(tEplEvent));
	if (pEplEvent->m_uiSize > 0) {
		// set pointer to argument
		pEplEvent->m_pArg = &abDataBuffer[sizeof(tEplEvent)];
	} else {
		//set pointer to NULL
		pEplEvent->m_pArg = NULL;
	}

	BENCHMARK_MOD_27_SET(0);
	// call processfunction
	EplEventkProcess(pEplEvent);

      Exit:
	return;
}
#endif

// EOF