aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging/epl/EplDllk.c
blob: 9e22641055c61cd7066410603c73d74e99d198fa (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
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
/****************************************************************************

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

  Project:      openPOWERLINK

  Description:  source file for kernel DLL module

  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: EplDllk.c,v $

                $Author: D.Krueger $

                $Revision: 1.21 $  $Date: 2008/11/13 17:13:09 $

                $State: Exp $

                Build Environment:
                    GCC V3.4

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

  Revision History:

  2006/06/12 d.k.:   start of the implementation, version 1.00

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

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

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

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_VETH)) != 0)
#include "kernel/VirtualEthernet.h"
#endif

//#if EPL_TIMER_USE_HIGHRES != FALSE
#include "kernel/EplTimerHighResk.h"
//#endif

#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)

#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMTK)) == 0)
#error "EPL module DLLK needs EPL module NMTK!"
#endif

#if (EPL_DLL_PRES_READY_AFTER_SOA != FALSE) && (EPL_DLL_PRES_READY_AFTER_SOC != FALSE)
#error "EPL module DLLK: select only one of EPL_DLL_PRES_READY_AFTER_SOA and EPL_DLL_PRES_READY_AFTER_SOC."
#endif

#if ((EPL_DLL_PRES_READY_AFTER_SOA != FALSE) || (EPL_DLL_PRES_READY_AFTER_SOC != FALSE)) \
    && (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) == 0)
#error "EPL module DLLK: currently, EPL_DLL_PRES_READY_AFTER_* is not supported if EPL_MODULE_NMT_MN is enabled."
#endif

#if (EDRV_FAST_TXFRAMES == FALSE) && \
    ((EPL_DLL_PRES_READY_AFTER_SOA != FALSE) || (EPL_DLL_PRES_READY_AFTER_SOC != FALSE))
#error "EPL module DLLK: EPL_DLL_PRES_READY_AFTER_* is enabled, but not EDRV_FAST_TXFRAMES."
#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 PUBLIC TgtDbgSignalTracePoint(BYTE bTracePointNumber_p);
void PUBLIC TgtDbgPostTraceValue(DWORD 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
#define EPL_DLLK_DBG_POST_TRACE_VALUE(Event_p, uiNodeId_p, wErrorCode_p) \
    TGT_DBG_POST_TRACE_VALUE((kEplEventSinkDllk << 28) | (Event_p << 24) \
                             | (uiNodeId_p << 16) | wErrorCode_p)

/***************************************************************************/
/*                                                                         */
/*                                                                         */
/*          C L A S S  EplDllk                                             */
/*                                                                         */
/*                                                                         */
/***************************************************************************/
//
// Description:
//
//
/***************************************************************************/

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

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

// defines for indexes of tEplDllInstance.m_pTxFrameInfo
#define EPL_DLLK_TXFRAME_IDENTRES   0	// IdentResponse on CN / MN
#define EPL_DLLK_TXFRAME_STATUSRES  1	// StatusResponse on CN / MN
#define EPL_DLLK_TXFRAME_NMTREQ     2	// NMT Request from FIFO on CN / MN
#define EPL_DLLK_TXFRAME_NONEPL     3	// non-EPL frame from FIFO on CN / MN
#define EPL_DLLK_TXFRAME_PRES       4	// PRes on CN / MN
#define EPL_DLLK_TXFRAME_SOC        5	// SoC on MN
#define EPL_DLLK_TXFRAME_SOA        6	// SoA on MN
#define EPL_DLLK_TXFRAME_PREQ       7	// PReq on MN
#if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
#define EPL_DLLK_TXFRAME_COUNT      (7 + EPL_D_NMT_MaxCNNumber_U8 + 2)	// on MN: 7 + MaxPReq of regular CNs + 1 Diag + 1 Router
#else
#define EPL_DLLK_TXFRAME_COUNT      5	// on CN: 5
#endif

#define EPL_DLLK_BUFLEN_EMPTY       0	// buffer is empty
#define EPL_DLLK_BUFLEN_FILLING     1	// just the buffer is being filled
#define EPL_DLLK_BUFLEN_MIN         60	// minimum ethernet frame length

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

typedef enum {
	kEplDllGsInit = 0x00,	// MN/CN: initialisation (< PreOp2)
	kEplDllCsWaitPreq = 0x01,	// CN: wait for PReq frame
	kEplDllCsWaitSoc = 0x02,	// CN: wait for SoC frame
	kEplDllCsWaitSoa = 0x03,	// CN: wait for SoA frame
	kEplDllMsNonCyclic = 0x04,	// MN: reduced EPL cycle (PreOp1)
	kEplDllMsWaitSocTrig = 0x05,	// MN: wait for SoC trigger (cycle timer)
	kEplDllMsWaitPreqTrig = 0x06,	// MN: wait for (first) PReq trigger (WaitSoCPReq_U32)
	kEplDllMsWaitPres = 0x07,	// MN: wait for PRes frame from CN
	kEplDllMsWaitSoaTrig = 0x08,	// MN: wait for SoA trigger (PRes transmitted)
	kEplDllMsWaitAsndTrig = 0x09,	// MN: wait for ASnd trigger (SoA transmitted)
	kEplDllMsWaitAsnd = 0x0A,	// MN: wait for ASnd frame if SoA contained invitation

} tEplDllState;

typedef struct {
	BYTE m_be_abSrcMac[6];
	tEdrvTxBuffer *m_pTxBuffer;	// Buffers for Tx-Frames
	unsigned int m_uiMaxTxFrames;
	BYTE m_bFlag1;		// Flag 1 with EN, EC for PRes, StatusRes
	BYTE m_bMnFlag1;	// Flag 1 with EA, ER from PReq, SoA of MN
	BYTE m_bFlag2;		// Flag 2 with PR and RS for PRes, StatusRes, IdentRes
	tEplDllConfigParam m_DllConfigParam;
	tEplDllIdentParam m_DllIdentParam;
	tEplDllState m_DllState;
	tEplDllkCbAsync m_pfnCbAsync;
	tEplDllAsndFilter m_aAsndFilter[EPL_DLL_MAX_ASND_SERVICE_ID];

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
	tEplDllkNodeInfo *m_pFirstNodeInfo;
	tEplDllkNodeInfo *m_pCurNodeInfo;
	tEplDllkNodeInfo m_aNodeInfo[EPL_NMT_MAX_NODE_ID];
	tEplDllReqServiceId m_LastReqServiceId;
	unsigned int m_uiLastTargetNodeId;
#endif

#if EPL_TIMER_USE_HIGHRES != FALSE
	tEplTimerHdl m_TimerHdlCycle;	// used for EPL cycle monitoring on CN and generation on MN
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
	tEplTimerHdl m_TimerHdlResponse;	// used for CN response monitoring
#endif				//(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
#endif

	unsigned int m_uiCycleCount;	// cycle counter (needed for multiplexed cycle support)
	unsigned long long m_ullFrameTimeout;	// frame timeout (cycle length + loss of frame tolerance)

} tEplDllkInstance;

//---------------------------------------------------------------------------
// local vars
//---------------------------------------------------------------------------

// if no dynamic memory allocation shall be used
// define structures statically
static tEplDllkInstance EplDllkInstance_g;

static tEdrvTxBuffer aEplDllkTxBuffer_l[EPL_DLLK_TXFRAME_COUNT];

//---------------------------------------------------------------------------
// local function prototypes
//---------------------------------------------------------------------------

// change DLL state on event
static tEplKernel EplDllkChangeState(tEplNmtEvent NmtEvent_p,
				     tEplNmtState NmtState_p);

// called from EdrvInterruptHandler()
static void EplDllkCbFrameReceived(tEdrvRxBuffer * pRxBuffer_p);

// called from EdrvInterruptHandler()
static void EplDllkCbFrameTransmitted(tEdrvTxBuffer * pTxBuffer_p);

// check frame and set missing information
static tEplKernel EplDllkCheckFrame(tEplFrame * pFrame_p,
				    unsigned int uiFrameSize_p);

// called by high resolution timer module to monitor EPL cycle as CN
#if EPL_TIMER_USE_HIGHRES != FALSE
static tEplKernel PUBLIC EplDllkCbCnTimer(tEplTimerEventArg * pEventArg_p);
#endif

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
// MN: returns internal node info structure
static tEplDllkNodeInfo *EplDllkGetNodeInfo(unsigned int uiNodeId_p);

// transmit SoA
static tEplKernel EplDllkMnSendSoa(tEplNmtState NmtState_p,
				   tEplDllState * pDllStateProposed_p,
				   BOOL fEnableInvitation_p);

static tEplKernel EplDllkMnSendSoc(void);

static tEplKernel EplDllkMnSendPreq(tEplNmtState NmtState_p,
				    tEplDllState * pDllStateProposed_p);

static tEplKernel EplDllkAsyncFrameNotReceived(tEplDllReqServiceId
					       ReqServiceId_p,
					       unsigned int uiNodeId_p);

static tEplKernel PUBLIC EplDllkCbMnTimerCycle(tEplTimerEventArg * pEventArg_p);

static tEplKernel PUBLIC EplDllkCbMnTimerResponse(tEplTimerEventArg *
						  pEventArg_p);

#endif

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

//---------------------------------------------------------------------------
//
// Function:    EplDllkAddInstance()
//
// Description: add and initialize new instance of EPL stack
//
// Parameters:  pInitParam_p            = initialisation parameters like MAC address
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkAddInstance(tEplDllkInitParam * pInitParam_p)
{
	tEplKernel Ret = kEplSuccessful;
	unsigned int uiIndex;
	tEdrvInitParam EdrvInitParam;

	// reset instance structure
	EPL_MEMSET(&EplDllkInstance_g, 0, sizeof(EplDllkInstance_g));

#if EPL_TIMER_USE_HIGHRES != FALSE
	Ret = EplTimerHighReskInit();
	if (Ret != kEplSuccessful) {	// error occured while initializing high resolution timer module
		goto Exit;
	}
#endif

	// if dynamic memory allocation available
	// allocate instance structure
	// allocate TPDO and RPDO table with default size

	// initialize and link pointers in instance structure to frame tables
	EplDllkInstance_g.m_pTxBuffer = aEplDllkTxBuffer_l;
	EplDllkInstance_g.m_uiMaxTxFrames =
	    sizeof(aEplDllkTxBuffer_l) / sizeof(tEdrvTxBuffer);

	// initialize state
	EplDllkInstance_g.m_DllState = kEplDllGsInit;

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
	// set up node info structure
	for (uiIndex = 0; uiIndex < tabentries(EplDllkInstance_g.m_aNodeInfo);
	     uiIndex++) {
		EplDllkInstance_g.m_aNodeInfo[uiIndex].m_uiNodeId = uiIndex + 1;
		EplDllkInstance_g.m_aNodeInfo[uiIndex].m_wPresPayloadLimit =
		    0xFFFF;
	}
#endif

	// initialize Edrv
	EPL_MEMCPY(EdrvInitParam.m_abMyMacAddr, pInitParam_p->m_be_abSrcMac, 6);
	EdrvInitParam.m_pfnRxHandler = EplDllkCbFrameReceived;
	EdrvInitParam.m_pfnTxHandler = EplDllkCbFrameTransmitted;
	Ret = EdrvInit(&EdrvInitParam);
	if (Ret != kEplSuccessful) {	// error occured while initializing ethernet driver
		goto Exit;
	}
	// copy local MAC address from Ethernet driver back to local instance structure
	// because Ethernet driver may have read it from controller EEPROM
	EPL_MEMCPY(EplDllkInstance_g.m_be_abSrcMac, EdrvInitParam.m_abMyMacAddr,
		   6);
	EPL_MEMCPY(pInitParam_p->m_be_abSrcMac, EdrvInitParam.m_abMyMacAddr, 6);

	// initialize TxBuffer array
	for (uiIndex = 0; uiIndex < EplDllkInstance_g.m_uiMaxTxFrames;
	     uiIndex++) {
		EplDllkInstance_g.m_pTxBuffer[uiIndex].m_pbBuffer = NULL;
	}

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_VETH)) != 0)
	Ret = VEthAddInstance(pInitParam_p);
#endif

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkDelInstance()
//
// Description: deletes an instance of EPL stack
//
// Parameters:  (none)
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkDelInstance(void)
{
	tEplKernel Ret = kEplSuccessful;

	// reset state
	EplDllkInstance_g.m_DllState = kEplDllGsInit;

#if EPL_TIMER_USE_HIGHRES != FALSE
	Ret = EplTimerHighReskDelInstance();
#endif

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_VETH)) != 0)
	Ret = VEthDelInstance();
#endif

	Ret = EdrvShutdown();
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkCreateTxFrame
//
// Description: creates the buffer for a Tx frame and registers it to the
//              ethernet driver
//
// Parameters:  puiHandle_p             = OUT: handle to frame buffer
//              ppFrame_p               = OUT: pointer to pointer of EPL frame
//              puiFrameSize_p          = IN/OUT: pointer to size of frame
//                                        returned size is always equal or larger than
//                                        requested size, if that is not possible
//                                        an error will be returned
//              MsgType_p               = EPL message type
//              ServiceId_p             = Service ID in case of ASnd frame, otherwise
//                                        kEplDllAsndNotDefined
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkCreateTxFrame(unsigned int *puiHandle_p,
				tEplFrame ** ppFrame_p,
				unsigned int *puiFrameSize_p,
				tEplMsgType MsgType_p,
				tEplDllAsndServiceId ServiceId_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplFrame *pTxFrame;
	unsigned int uiHandle = EplDllkInstance_g.m_uiMaxTxFrames;
	tEdrvTxBuffer *pTxBuffer = NULL;

	if (MsgType_p == kEplMsgTypeAsnd) {
		// search for fixed Tx buffers
		if (ServiceId_p == kEplDllAsndIdentResponse) {
			uiHandle = EPL_DLLK_TXFRAME_IDENTRES;
		} else if (ServiceId_p == kEplDllAsndStatusResponse) {
			uiHandle = EPL_DLLK_TXFRAME_STATUSRES;
		} else if ((ServiceId_p == kEplDllAsndNmtRequest)
			   || (ServiceId_p == kEplDllAsndNmtCommand)) {
			uiHandle = EPL_DLLK_TXFRAME_NMTREQ;
		}

		if (uiHandle >= EplDllkInstance_g.m_uiMaxTxFrames) {	// look for free entry
			uiHandle = EPL_DLLK_TXFRAME_PREQ;
			pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[uiHandle];
			for (; uiHandle < EplDllkInstance_g.m_uiMaxTxFrames;
			     uiHandle++, pTxBuffer++) {
				if (pTxBuffer->m_pbBuffer == NULL) {	// free entry found
					break;
				}
			}
		}
	} else if (MsgType_p == kEplMsgTypeNonEpl) {
		uiHandle = EPL_DLLK_TXFRAME_NONEPL;
	} else if (MsgType_p == kEplMsgTypePres) {
		uiHandle = EPL_DLLK_TXFRAME_PRES;
	} else if (MsgType_p == kEplMsgTypeSoc) {
		uiHandle = EPL_DLLK_TXFRAME_SOC;
	} else if (MsgType_p == kEplMsgTypeSoa) {
		uiHandle = EPL_DLLK_TXFRAME_SOA;
	} else {		// look for free entry
		uiHandle = EPL_DLLK_TXFRAME_PREQ;
		pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[uiHandle];
		for (; uiHandle < EplDllkInstance_g.m_uiMaxTxFrames;
		     uiHandle++, pTxBuffer++) {
			if (pTxBuffer->m_pbBuffer == NULL) {	// free entry found
				break;
			}
		}
		if (pTxBuffer->m_pbBuffer != NULL) {
			Ret = kEplEdrvNoFreeBufEntry;
			goto Exit;
		}
	}

	// test if requested entry is free
	pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[uiHandle];
	if (pTxBuffer->m_pbBuffer != NULL) {	// entry is not free
		Ret = kEplEdrvNoFreeBufEntry;
		goto Exit;
	}
	// setup Tx buffer
	pTxBuffer->m_EplMsgType = MsgType_p;
	pTxBuffer->m_uiMaxBufferLen = *puiFrameSize_p;

	Ret = EdrvAllocTxMsgBuffer(pTxBuffer);
	if (Ret != kEplSuccessful) {	// error occured while registering Tx frame
		goto Exit;
	}
	// because buffer size may be larger than requested
	// memorize real length of frame
	pTxBuffer->m_uiTxMsgLen = *puiFrameSize_p;

	// fill whole frame with 0
	EPL_MEMSET(pTxBuffer->m_pbBuffer, 0, pTxBuffer->m_uiMaxBufferLen);

	pTxFrame = (tEplFrame *) pTxBuffer->m_pbBuffer;

	if (MsgType_p != kEplMsgTypeNonEpl) {	// fill out Frame only if it is an EPL frame
		// ethertype
		AmiSetWordToBe(&pTxFrame->m_be_wEtherType,
			       EPL_C_DLL_ETHERTYPE_EPL);
		// source node ID
		AmiSetByteToLe(&pTxFrame->m_le_bSrcNodeId,
			       (BYTE) EplDllkInstance_g.m_DllConfigParam.
			       m_uiNodeId);
		// source MAC address
		EPL_MEMCPY(&pTxFrame->m_be_abSrcMac[0],
			   &EplDllkInstance_g.m_be_abSrcMac[0], 6);
		switch (MsgType_p) {
		case kEplMsgTypeAsnd:
			// destination MAC address
			AmiSetQword48ToBe(&pTxFrame->m_be_abDstMac[0],
					  EPL_C_DLL_MULTICAST_ASND);
			// destination node ID
			switch (ServiceId_p) {
			case kEplDllAsndIdentResponse:
			case kEplDllAsndStatusResponse:
				{	// IdentResponses and StatusResponses are Broadcast
					AmiSetByteToLe(&pTxFrame->
						       m_le_bDstNodeId,
						       (BYTE)
						       EPL_C_ADR_BROADCAST);
					break;
				}

			default:
				break;
			}
			// ASnd Service ID
			AmiSetByteToLe(&pTxFrame->m_Data.m_Asnd.m_le_bServiceId,
				       ServiceId_p);
			break;

		case kEplMsgTypeSoc:
			// destination MAC address
			AmiSetQword48ToBe(&pTxFrame->m_be_abDstMac[0],
					  EPL_C_DLL_MULTICAST_SOC);
			// destination node ID
			AmiSetByteToLe(&pTxFrame->m_le_bDstNodeId,
				       (BYTE) EPL_C_ADR_BROADCAST);
			// reset Flags
			//AmiSetByteToLe(&pTxFrame->m_Data.m_Soc.m_le_bFlag1, (BYTE) 0);
			//AmiSetByteToLe(&pTxFrame->m_Data.m_Soc.m_le_bFlag2, (BYTE) 0);
			break;

		case kEplMsgTypeSoa:
			// destination MAC address
			AmiSetQword48ToBe(&pTxFrame->m_be_abDstMac[0],
					  EPL_C_DLL_MULTICAST_SOA);
			// destination node ID
			AmiSetByteToLe(&pTxFrame->m_le_bDstNodeId,
				       (BYTE) EPL_C_ADR_BROADCAST);
			// reset Flags
			//AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.m_le_bFlag1, (BYTE) 0);
			//AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.m_le_bFlag2, (BYTE) 0);
			// EPL profile version
			AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.m_le_bEplVersion,
				       (BYTE) EPL_SPEC_VERSION);
			break;

		case kEplMsgTypePres:
			// destination MAC address
			AmiSetQword48ToBe(&pTxFrame->m_be_abDstMac[0],
					  EPL_C_DLL_MULTICAST_PRES);
			// destination node ID
			AmiSetByteToLe(&pTxFrame->m_le_bDstNodeId,
				       (BYTE) EPL_C_ADR_BROADCAST);
			// reset Flags
			//AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.m_le_bFlag1, (BYTE) 0);
			//AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.m_le_bFlag2, (BYTE) 0);
			// PDO size
			//AmiSetWordToLe(&pTxFrame->m_Data.m_Pres.m_le_wSize, 0);
			break;

		case kEplMsgTypePreq:
			// reset Flags
			//AmiSetByteToLe(&pTxFrame->m_Data.m_Preq.m_le_bFlag1, (BYTE) 0);
			//AmiSetByteToLe(&pTxFrame->m_Data.m_Preq.m_le_bFlag2, (BYTE) 0);
			// PDO size
			//AmiSetWordToLe(&pTxFrame->m_Data.m_Preq.m_le_wSize, 0);
			break;

		default:
			break;
		}
		// EPL message type
		AmiSetByteToLe(&pTxFrame->m_le_bMessageType, (BYTE) MsgType_p);
	}

	*ppFrame_p = pTxFrame;
	*puiFrameSize_p = pTxBuffer->m_uiMaxBufferLen;
	*puiHandle_p = uiHandle;

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkDeleteTxFrame
//
// Description: deletes the buffer for a Tx frame and frees it in the
//              ethernet driver
//
// Parameters:  uiHandle_p              = IN: handle to frame buffer
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkDeleteTxFrame(unsigned int uiHandle_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEdrvTxBuffer *pTxBuffer = NULL;

	if (uiHandle_p >= EplDllkInstance_g.m_uiMaxTxFrames) {	// handle is not valid
		Ret = kEplDllIllegalHdl;
		goto Exit;
	}

	pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[uiHandle_p];

	// mark buffer as free so that frame will not be send in future anymore
	// $$$ d.k. What's up with running transmissions?
	pTxBuffer->m_uiTxMsgLen = EPL_DLLK_BUFLEN_EMPTY;
	pTxBuffer->m_pbBuffer = NULL;

	// delete Tx buffer
	Ret = EdrvReleaseTxMsgBuffer(pTxBuffer);
	if (Ret != kEplSuccessful) {	// error occured while releasing Tx frame
		goto Exit;
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkProcess
//
// Description: process the passed event
//
// Parameters:  pEvent_p                = event to be processed
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkProcess(tEplEvent * pEvent_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplFrame *pTxFrame;
	tEdrvTxBuffer *pTxBuffer;
	unsigned int uiHandle;
	unsigned int uiFrameSize;
	BYTE abMulticastMac[6];
	tEplDllAsyncReqPriority AsyncReqPriority;
	unsigned int uiFrameCount;
	tEplNmtState NmtState;
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
	tEplFrameInfo FrameInfo;
#endif

	switch (pEvent_p->m_EventType) {
	case kEplEventTypeDllkCreate:
		{
			// $$$ reset ethernet driver

			NmtState = *((tEplNmtState *) pEvent_p->m_pArg);

			// initialize flags for PRes and StatusRes
			EplDllkInstance_g.m_bFlag1 = EPL_FRAME_FLAG1_EC;
			EplDllkInstance_g.m_bMnFlag1 = 0;
			EplDllkInstance_g.m_bFlag2 = 0;

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
			// initialize linked node list
			EplDllkInstance_g.m_pFirstNodeInfo = NULL;
#endif

			// register TxFrames in Edrv

			// IdentResponse
			uiFrameSize = EPL_C_DLL_MINSIZE_IDENTRES;
			Ret =
			    EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
						 &uiFrameSize, kEplMsgTypeAsnd,
						 kEplDllAsndIdentResponse);
			if (Ret != kEplSuccessful) {	// error occured while registering Tx frame
				goto Exit;
			}
			// EPL profile version
			AmiSetByteToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
				       m_IdentResponse.m_le_bEplProfileVersion,
				       (BYTE) EPL_SPEC_VERSION);
			// FeatureFlags
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwFeatureFlags,
					EplDllkInstance_g.m_DllConfigParam.
					m_dwFeatureFlags);
			// MTU
			AmiSetWordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
				       m_IdentResponse.m_le_wMtu,
				       (WORD) EplDllkInstance_g.
				       m_DllConfigParam.m_uiAsyncMtu);
			// PollInSize
			AmiSetWordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
				       m_IdentResponse.m_le_wPollInSize,
				       (WORD) EplDllkInstance_g.
				       m_DllConfigParam.
				       m_uiPreqActPayloadLimit);
			// PollOutSize
			AmiSetWordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
				       m_IdentResponse.m_le_wPollOutSize,
				       (WORD) EplDllkInstance_g.
				       m_DllConfigParam.
				       m_uiPresActPayloadLimit);
			// ResponseTime / PresMaxLatency
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwResponseTime,
					EplDllkInstance_g.m_DllConfigParam.
					m_dwPresMaxLatency);
			// DeviceType
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwDeviceType,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwDeviceType);
			// VendorId
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwVendorId,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwVendorId);
			// ProductCode
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwProductCode,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwProductCode);
			// RevisionNumber
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwRevisionNumber,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwRevisionNumber);
			// SerialNumber
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwSerialNumber,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwSerialNumber);
			// VendorSpecificExt1
			AmiSetQword64ToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					  m_IdentResponse.
					  m_le_qwVendorSpecificExt1,
					  EplDllkInstance_g.m_DllIdentParam.
					  m_qwVendorSpecificExt1);
			// VerifyConfigurationDate
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.
					m_le_dwVerifyConfigurationDate,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwVerifyConfigurationDate);
			// VerifyConfigurationTime
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.
					m_le_dwVerifyConfigurationTime,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwVerifyConfigurationTime);
			// ApplicationSwDate
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.
					m_le_dwApplicationSwDate,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwApplicationSwDate);
			// ApplicationSwTime
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.
					m_le_dwApplicationSwTime,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwApplicationSwTime);
			// IPAddress
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwIpAddress,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwIpAddress);
			// SubnetMask
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwSubnetMask,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwSubnetMask);
			// DefaultGateway
			AmiSetDwordToLe(&pTxFrame->m_Data.m_Asnd.m_Payload.
					m_IdentResponse.m_le_dwDefaultGateway,
					EplDllkInstance_g.m_DllIdentParam.
					m_dwDefaultGateway);
			// HostName
			EPL_MEMCPY(&pTxFrame->m_Data.m_Asnd.m_Payload.
				   m_IdentResponse.m_le_sHostname[0],
				   &EplDllkInstance_g.m_DllIdentParam.
				   m_sHostname[0],
				   sizeof(EplDllkInstance_g.m_DllIdentParam.
					  m_sHostname));
			// VendorSpecificExt2
			EPL_MEMCPY(&pTxFrame->m_Data.m_Asnd.m_Payload.
				   m_IdentResponse.m_le_abVendorSpecificExt2[0],
				   &EplDllkInstance_g.m_DllIdentParam.
				   m_abVendorSpecificExt2[0],
				   sizeof(EplDllkInstance_g.m_DllIdentParam.
					  m_abVendorSpecificExt2));

			// StatusResponse
			uiFrameSize = EPL_C_DLL_MINSIZE_STATUSRES;
			Ret =
			    EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
						 &uiFrameSize, kEplMsgTypeAsnd,
						 kEplDllAsndStatusResponse);
			if (Ret != kEplSuccessful) {	// error occured while registering Tx frame
				goto Exit;
			}
			// PRes $$$ maybe move this to PDO module
			if ((EplDllkInstance_g.m_DllConfigParam.m_fAsyncOnly ==
			     FALSE)
			    && (EplDllkInstance_g.m_DllConfigParam.m_uiPresActPayloadLimit >= 36)) {	// it is not configured as async-only CN,
				// so take part in isochronous phase and register PRes frame
				uiFrameSize =
				    EplDllkInstance_g.m_DllConfigParam.
				    m_uiPresActPayloadLimit + 24;
				Ret =
				    EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
							 &uiFrameSize,
							 kEplMsgTypePres,
							 kEplDllAsndNotDefined);
				if (Ret != kEplSuccessful) {	// error occured while registering Tx frame
					goto Exit;
				}
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
				// initially encode TPDO -> inform PDO module
				FrameInfo.m_pFrame = pTxFrame;
				FrameInfo.m_uiFrameSize = uiFrameSize;
				Ret = EplPdokCbPdoTransmitted(&FrameInfo);
#endif
				// reset cycle counter
				EplDllkInstance_g.m_uiCycleCount = 0;
			} else {	// it is an async-only CN
				// fool EplDllkChangeState() to think that PRes was not expected
				EplDllkInstance_g.m_uiCycleCount = 1;
			}

			// NMT request
			uiFrameSize = EPL_C_IP_MAX_MTU;
			Ret =
			    EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
						 &uiFrameSize, kEplMsgTypeAsnd,
						 kEplDllAsndNmtRequest);
			if (Ret != kEplSuccessful) {	// error occured while registering Tx frame
				goto Exit;
			}
			// mark Tx buffer as empty
			EplDllkInstance_g.m_pTxBuffer[uiHandle].m_uiTxMsgLen =
			    EPL_DLLK_BUFLEN_EMPTY;

			// non-EPL frame
			uiFrameSize = EPL_C_IP_MAX_MTU;
			Ret =
			    EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
						 &uiFrameSize,
						 kEplMsgTypeNonEpl,
						 kEplDllAsndNotDefined);
			if (Ret != kEplSuccessful) {	// error occured while registering Tx frame
				goto Exit;
			}
			// mark Tx buffer as empty
			EplDllkInstance_g.m_pTxBuffer[uiHandle].m_uiTxMsgLen =
			    EPL_DLLK_BUFLEN_EMPTY;

			// register multicast MACs in ethernet driver
			AmiSetQword48ToBe(&abMulticastMac[0],
					  EPL_C_DLL_MULTICAST_SOC);
			Ret = EdrvDefineRxMacAddrEntry(abMulticastMac);
			AmiSetQword48ToBe(&abMulticastMac[0],
					  EPL_C_DLL_MULTICAST_SOA);
			Ret = EdrvDefineRxMacAddrEntry(abMulticastMac);
			AmiSetQword48ToBe(&abMulticastMac[0],
					  EPL_C_DLL_MULTICAST_PRES);
			Ret = EdrvDefineRxMacAddrEntry(abMulticastMac);
			AmiSetQword48ToBe(&abMulticastMac[0],
					  EPL_C_DLL_MULTICAST_ASND);
			Ret = EdrvDefineRxMacAddrEntry(abMulticastMac);

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
			if (NmtState >= kEplNmtMsNotActive) {	// local node is MN
				unsigned int uiIndex;

				// SoC
				uiFrameSize = EPL_C_DLL_MINSIZE_SOC;
				Ret =
				    EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
							 &uiFrameSize,
							 kEplMsgTypeSoc,
							 kEplDllAsndNotDefined);
				if (Ret != kEplSuccessful) {	// error occured while registering Tx frame
					goto Exit;
				}
				// SoA
				uiFrameSize = EPL_C_DLL_MINSIZE_SOA;
				Ret =
				    EplDllkCreateTxFrame(&uiHandle, &pTxFrame,
							 &uiFrameSize,
							 kEplMsgTypeSoa,
							 kEplDllAsndNotDefined);
				if (Ret != kEplSuccessful) {	// error occured while registering Tx frame
					goto Exit;
				}

				for (uiIndex = 0;
				     uiIndex <
				     tabentries(EplDllkInstance_g.m_aNodeInfo);
				     uiIndex++) {
//                    EplDllkInstance_g.m_aNodeInfo[uiIndex].m_uiNodeId = uiIndex + 1;
					EplDllkInstance_g.m_aNodeInfo[uiIndex].
					    m_wPresPayloadLimit =
					    (WORD) EplDllkInstance_g.
					    m_DllConfigParam.
					    m_uiIsochrRxMaxPayload;
				}

				// calculate cycle length
				EplDllkInstance_g.m_ullFrameTimeout = 1000LL
				    *
				    ((unsigned long long)EplDllkInstance_g.
				     m_DllConfigParam.m_dwCycleLen);
			}
#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)

			Ret = EplDllkCalAsyncClearBuffer();

			break;
		}

	case kEplEventTypeDllkDestroy:
		{
			// destroy all data structures

			NmtState = *((tEplNmtState *) pEvent_p->m_pArg);

			// delete Tx frames
			Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_IDENTRES);
			if (Ret != kEplSuccessful) {	// error occured while deregistering Tx frame
				goto Exit;
			}

			Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_STATUSRES);
			if (Ret != kEplSuccessful) {	// error occured while deregistering Tx frame
				goto Exit;
			}

			Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_PRES);
			if (Ret != kEplSuccessful) {	// error occured while deregistering Tx frame
				goto Exit;
			}

			Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_NMTREQ);
			if (Ret != kEplSuccessful) {	// error occured while deregistering Tx frame
				goto Exit;
			}

			Ret = EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_NONEPL);
			if (Ret != kEplSuccessful) {	// error occured while deregistering Tx frame
				goto Exit;
			}
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
			if (NmtState >= kEplNmtMsNotActive) {	// local node was MN
				unsigned int uiIndex;

				Ret =
				    EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_SOC);
				if (Ret != kEplSuccessful) {	// error occured while deregistering Tx frame
					goto Exit;
				}

				Ret =
				    EplDllkDeleteTxFrame(EPL_DLLK_TXFRAME_SOA);
				if (Ret != kEplSuccessful) {	// error occured while deregistering Tx frame
					goto Exit;
				}

				for (uiIndex = 0;
				     uiIndex <
				     tabentries(EplDllkInstance_g.m_aNodeInfo);
				     uiIndex++) {
					if (EplDllkInstance_g.
					    m_aNodeInfo[uiIndex].
					    m_pPreqTxBuffer != NULL) {
						uiHandle =
						    EplDllkInstance_g.
						    m_aNodeInfo[uiIndex].
						    m_pPreqTxBuffer -
						    EplDllkInstance_g.
						    m_pTxBuffer;
						EplDllkInstance_g.
						    m_aNodeInfo[uiIndex].
						    m_pPreqTxBuffer = NULL;
						Ret =
						    EplDllkDeleteTxFrame
						    (uiHandle);
						if (Ret != kEplSuccessful) {	// error occured while deregistering Tx frame
							goto Exit;
						}

					}
					EplDllkInstance_g.m_aNodeInfo[uiIndex].
					    m_wPresPayloadLimit = 0xFFFF;
				}
			}
#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)

			// deregister multicast MACs in ethernet driver
			AmiSetQword48ToBe(&abMulticastMac[0],
					  EPL_C_DLL_MULTICAST_SOC);
			Ret = EdrvUndefineRxMacAddrEntry(abMulticastMac);
			AmiSetQword48ToBe(&abMulticastMac[0],
					  EPL_C_DLL_MULTICAST_SOA);
			Ret = EdrvUndefineRxMacAddrEntry(abMulticastMac);
			AmiSetQword48ToBe(&abMulticastMac[0],
					  EPL_C_DLL_MULTICAST_PRES);
			Ret = EdrvUndefineRxMacAddrEntry(abMulticastMac);
			AmiSetQword48ToBe(&abMulticastMac[0],
					  EPL_C_DLL_MULTICAST_ASND);
			Ret = EdrvUndefineRxMacAddrEntry(abMulticastMac);

			// delete timer
#if EPL_TIMER_USE_HIGHRES != FALSE
			Ret =
			    EplTimerHighReskDeleteTimer(&EplDllkInstance_g.
							m_TimerHdlCycle);
#endif

			break;
		}

	case kEplEventTypeDllkFillTx:
		{
			// fill TxBuffer of specified priority with new frame if empty

			pTxFrame = NULL;
			AsyncReqPriority =
			    *((tEplDllAsyncReqPriority *) pEvent_p->m_pArg);
			switch (AsyncReqPriority) {
			case kEplDllAsyncReqPrioNmt:	// NMT request priority
				{
					pTxBuffer =
					    &EplDllkInstance_g.
					    m_pTxBuffer
					    [EPL_DLLK_TXFRAME_NMTREQ];
					if (pTxBuffer->m_pbBuffer != NULL) {	// NmtRequest does exist
						// check if frame is empty and not being filled
						if (pTxBuffer->m_uiTxMsgLen ==
						    EPL_DLLK_BUFLEN_EMPTY) {
							// mark Tx buffer as filling is in process
							pTxBuffer->
							    m_uiTxMsgLen =
							    EPL_DLLK_BUFLEN_FILLING;
							// set max buffer size as input parameter
							uiFrameSize =
							    pTxBuffer->
							    m_uiMaxBufferLen;
							// copy frame from shared loop buffer to Tx buffer
							Ret =
							    EplDllkCalAsyncGetTxFrame
							    (pTxBuffer->
							     m_pbBuffer,
							     &uiFrameSize,
							     AsyncReqPriority);
							if (Ret ==
							    kEplSuccessful) {
								pTxFrame =
								    (tEplFrame
								     *)
								    pTxBuffer->
								    m_pbBuffer;
								Ret =
								    EplDllkCheckFrame
								    (pTxFrame,
								     uiFrameSize);

								// set buffer valid
								pTxBuffer->
								    m_uiTxMsgLen
								    =
								    uiFrameSize;
							} else if (Ret == kEplDllAsyncTxBufferEmpty) {	// empty Tx buffer is not a real problem
								// so just ignore it
								Ret =
								    kEplSuccessful;
								// mark Tx buffer as empty
								pTxBuffer->
								    m_uiTxMsgLen
								    =
								    EPL_DLLK_BUFLEN_EMPTY;
							}
						}
					}
					break;
				}

			default:	// generic priority
				{
					pTxBuffer =
					    &EplDllkInstance_g.
					    m_pTxBuffer
					    [EPL_DLLK_TXFRAME_NONEPL];
					if (pTxBuffer->m_pbBuffer != NULL) {	// non-EPL frame does exist
						// check if frame is empty and not being filled
						if (pTxBuffer->m_uiTxMsgLen ==
						    EPL_DLLK_BUFLEN_EMPTY) {
							// mark Tx buffer as filling is in process
							pTxBuffer->
							    m_uiTxMsgLen =
							    EPL_DLLK_BUFLEN_FILLING;
							// set max buffer size as input parameter
							uiFrameSize =
							    pTxBuffer->
							    m_uiMaxBufferLen;
							// copy frame from shared loop buffer to Tx buffer
							Ret =
							    EplDllkCalAsyncGetTxFrame
							    (pTxBuffer->
							     m_pbBuffer,
							     &uiFrameSize,
							     AsyncReqPriority);
							if (Ret ==
							    kEplSuccessful) {
								pTxFrame =
								    (tEplFrame
								     *)
								    pTxBuffer->
								    m_pbBuffer;
								Ret =
								    EplDllkCheckFrame
								    (pTxFrame,
								     uiFrameSize);

								// set buffer valid
								pTxBuffer->
								    m_uiTxMsgLen
								    =
								    uiFrameSize;
							} else if (Ret == kEplDllAsyncTxBufferEmpty) {	// empty Tx buffer is not a real problem
								// so just ignore it
								Ret =
								    kEplSuccessful;
								// mark Tx buffer as empty
								pTxBuffer->
								    m_uiTxMsgLen
								    =
								    EPL_DLLK_BUFLEN_EMPTY;
							}
						}
					}
					break;
				}
			}

			NmtState = EplNmtkGetNmtState();

			if ((NmtState == kEplNmtCsBasicEthernet) || (NmtState == kEplNmtMsBasicEthernet)) {	// send frame immediately
				if (pTxFrame != NULL) {	// frame is present
					// padding is done by Edrv or ethernet controller
					Ret = EdrvSendTxMsg(pTxBuffer);
				} else {	// no frame moved to TxBuffer
					// check if TxBuffers contain unsent frames
					if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NMTREQ].m_uiTxMsgLen > EPL_DLLK_BUFLEN_EMPTY) {	// NMT request Tx buffer contains a frame
						Ret =
						    EdrvSendTxMsg
						    (&EplDllkInstance_g.
						     m_pTxBuffer
						     [EPL_DLLK_TXFRAME_NMTREQ]);
					} else if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NONEPL].m_uiTxMsgLen > EPL_DLLK_BUFLEN_EMPTY) {	// non-EPL Tx buffer contains a frame
						Ret =
						    EdrvSendTxMsg
						    (&EplDllkInstance_g.
						     m_pTxBuffer
						     [EPL_DLLK_TXFRAME_NONEPL]);
					}
					if (Ret == kEplInvalidOperation) {	// ignore error if caused by already active transmission
						Ret = kEplSuccessful;
					}
				}
				// reset PRes flag 2
				EplDllkInstance_g.m_bFlag2 = 0;
			} else {
				// update Flag 2 (PR, RS)
				Ret =
				    EplDllkCalAsyncGetTxCount(&AsyncReqPriority,
							      &uiFrameCount);
				if (AsyncReqPriority == kEplDllAsyncReqPrioNmt) {	// non-empty FIFO with hightest priority is for NMT requests
					if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NMTREQ].m_uiTxMsgLen > EPL_DLLK_BUFLEN_EMPTY) {	// NMT request Tx buffer contains a frame
						// add one more frame
						uiFrameCount++;
					}
				} else {	// non-empty FIFO with highest priority is for generic frames
					if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NMTREQ].m_uiTxMsgLen > EPL_DLLK_BUFLEN_EMPTY) {	// NMT request Tx buffer contains a frame
						// use NMT request FIFO, because of higher priority
						uiFrameCount = 1;
						AsyncReqPriority =
						    kEplDllAsyncReqPrioNmt;
					} else if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NONEPL].m_uiTxMsgLen > EPL_DLLK_BUFLEN_EMPTY) {	// non-EPL Tx buffer contains a frame
						// use NMT request FIFO, because of higher priority
						// add one more frame
						uiFrameCount++;
					}
				}

				if (uiFrameCount > 7) {	// limit frame request to send counter to 7
					uiFrameCount = 7;
				}
				if (uiFrameCount > 0) {
					EplDllkInstance_g.m_bFlag2 =
					    (BYTE) (((AsyncReqPriority <<
						      EPL_FRAME_FLAG2_PR_SHIFT)
						     & EPL_FRAME_FLAG2_PR)
						    | (uiFrameCount &
						       EPL_FRAME_FLAG2_RS));
				} else {
					EplDllkInstance_g.m_bFlag2 = 0;
				}
			}

			break;
		}

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
	case kEplEventTypeDllkStartReducedCycle:
		{
			// start the reduced cycle by programming the cycle timer
			// it is issued by NMT MN module, when PreOp1 is entered

			// clear the asynchronous queues
			Ret = EplDllkCalAsyncClearQueues();

			// reset cycle counter (everytime a SoA is triggerd in PreOp1 the counter is incremented
			// and when it reaches EPL_C_DLL_PREOP1_START_CYCLES the SoA may contain invitations)
			EplDllkInstance_g.m_uiCycleCount = 0;

			// remove any CN from isochronous phase
			while (EplDllkInstance_g.m_pFirstNodeInfo != NULL) {
				EplDllkDeleteNode(EplDllkInstance_g.
						  m_pFirstNodeInfo->m_uiNodeId);
			}

			// change state to NonCyclic,
			// hence EplDllkChangeState() will not ignore the next call
			EplDllkInstance_g.m_DllState = kEplDllMsNonCyclic;

#if EPL_TIMER_USE_HIGHRES != FALSE
			if (EplDllkInstance_g.m_DllConfigParam.
			    m_dwAsyncSlotTimeout != 0) {
				Ret =
				    EplTimerHighReskModifyTimerNs
				    (&EplDllkInstance_g.m_TimerHdlCycle,
				     EplDllkInstance_g.m_DllConfigParam.
				     m_dwAsyncSlotTimeout,
				     EplDllkCbMnTimerCycle, 0L, FALSE);
			}
#endif

			break;
		}
#endif

#if EPL_DLL_PRES_READY_AFTER_SOA != FALSE
	case kEplEventTypeDllkPresReady:
		{
			// post PRes to transmit FIFO

			NmtState = EplNmtkGetNmtState();

			if (NmtState != kEplNmtCsBasicEthernet) {
				// Does PRes exist?
				if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_PRES].m_pbBuffer != NULL) {	// PRes does exist
					pTxFrame =
					    (tEplFrame *) EplDllkInstance_g.
					    m_pTxBuffer[EPL_DLLK_TXFRAME_PRES].
					    m_pbBuffer;
					// update frame (NMT state, RD, RS, PR, MS, EN flags)
					if (NmtState < kEplNmtCsPreOperational2) {	// NMT state is not PreOp2, ReadyToOp or Op
						// fake NMT state PreOp2, because PRes will be sent only in PreOp2 or greater
						NmtState =
						    kEplNmtCsPreOperational2;
					}
					AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.
						       m_le_bNmtStatus,
						       (BYTE) NmtState);
					AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.
						       m_le_bFlag2,
						       EplDllkInstance_g.
						       m_bFlag2);
					if (NmtState != kEplNmtCsOperational) {	// mark PDO as invalid in NMT state Op
						// $$$ reset only RD flag; set other flags appropriately
						AmiSetByteToLe(&pTxFrame->
							       m_Data.m_Pres.
							       m_le_bFlag1, 0);
					}
					// $$$ make function that updates Pres, StatusRes
					// mark PRes frame as ready for transmission
					Ret =
					    EdrvTxMsgReady(&EplDllkInstance_g.
							   m_pTxBuffer
							   [EPL_DLLK_TXFRAME_PRES]);
				}
			}

			break;
		}
#endif
	default:
		{
			ASSERTMSG(FALSE,
				  "EplDllkProcess(): unhandled event type!\n");
		}
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkConfig
//
// Description: configure parameters of DLL
//
// Parameters:  pDllConfigParam_p       = configuration parameters
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkConfig(tEplDllConfigParam * pDllConfigParam_p)
{
	tEplKernel Ret = kEplSuccessful;

// d.k. check of NMT state disabled, because CycleLen is programmed at run time by MN without reset of CN
/*tEplNmtState    NmtState;

    NmtState = EplNmtkGetNmtState();

    if (NmtState > kEplNmtGsResetConfiguration)
    {   // only allowed in state DLL_GS_INIT
        Ret = kEplInvalidOperation;
        goto Exit;
    }
*/
	EPL_MEMCPY(&EplDllkInstance_g.m_DllConfigParam, pDllConfigParam_p,
		   (pDllConfigParam_p->m_uiSizeOfStruct <
		    sizeof(tEplDllConfigParam) ? pDllConfigParam_p->
		    m_uiSizeOfStruct : sizeof(tEplDllConfigParam)));

	if ((EplDllkInstance_g.m_DllConfigParam.m_dwCycleLen != 0)
	    && (EplDllkInstance_g.m_DllConfigParam.m_dwLossOfFrameTolerance != 0)) {	// monitor EPL cycle, calculate frame timeout
		EplDllkInstance_g.m_ullFrameTimeout = (1000LL
						       *
						       ((unsigned long long)
							EplDllkInstance_g.
							m_DllConfigParam.
							m_dwCycleLen))
		    +
		    ((unsigned long long)EplDllkInstance_g.m_DllConfigParam.
		     m_dwLossOfFrameTolerance);
	} else {
		EplDllkInstance_g.m_ullFrameTimeout = 0LL;
	}

	if (EplDllkInstance_g.m_DllConfigParam.m_fAsyncOnly != FALSE) {	// it is configured as async-only CN
		// disable multiplexed cycle, that m_uiCycleCount will not be incremented spuriously on SoC
		EplDllkInstance_g.m_DllConfigParam.m_uiMultiplCycleCnt = 0;
	}
//Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkSetIdentity
//
// Description: configure identity of local node for IdentResponse
//
// Parameters:  pDllIdentParam_p        = identity
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkSetIdentity(tEplDllIdentParam * pDllIdentParam_p)
{
	tEplKernel Ret = kEplSuccessful;

	EPL_MEMCPY(&EplDllkInstance_g.m_DllIdentParam, pDllIdentParam_p,
		   (pDllIdentParam_p->m_uiSizeOfStruct <
		    sizeof(tEplDllIdentParam) ? pDllIdentParam_p->
		    m_uiSizeOfStruct : sizeof(tEplDllIdentParam)));

	// $$$ if IdentResponse frame exists update it

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkRegAsyncHandler
//
// Description: registers handler for non-EPL frames
//
// Parameters:  pfnDllkCbAsync_p        = pointer to callback function
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkRegAsyncHandler(tEplDllkCbAsync pfnDllkCbAsync_p)
{
	tEplKernel Ret = kEplSuccessful;

	if (EplDllkInstance_g.m_pfnCbAsync == NULL) {	// no handler registered yet
		EplDllkInstance_g.m_pfnCbAsync = pfnDllkCbAsync_p;
	} else {		// handler already registered
		Ret = kEplDllCbAsyncRegistered;
	}

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkDeregAsyncHandler
//
// Description: deregisters handler for non-EPL frames
//
// Parameters:  pfnDllkCbAsync_p        = pointer to callback function
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkDeregAsyncHandler(tEplDllkCbAsync pfnDllkCbAsync_p)
{
	tEplKernel Ret = kEplSuccessful;

	if (EplDllkInstance_g.m_pfnCbAsync == pfnDllkCbAsync_p) {	// same handler is registered
		// deregister it
		EplDllkInstance_g.m_pfnCbAsync = NULL;
	} else {		// wrong handler or no handler registered
		Ret = kEplDllCbAsyncRegistered;
	}

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkSetAsndServiceIdFilter()
//
// Description: sets the specified node ID filter for the specified
//              AsndServiceId. It registers C_DLL_MULTICAST_ASND in ethernet
//              driver if any AsndServiceId is open.
//
// Parameters:  ServiceId_p             = ASnd Service ID
//              Filter_p                = node ID filter
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkSetAsndServiceIdFilter(tEplDllAsndServiceId ServiceId_p,
					 tEplDllAsndFilter Filter_p)
{
	tEplKernel Ret = kEplSuccessful;

	if (ServiceId_p < tabentries(EplDllkInstance_g.m_aAsndFilter)) {
		EplDllkInstance_g.m_aAsndFilter[ServiceId_p] = Filter_p;
	}

	return Ret;
}

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)

//---------------------------------------------------------------------------
//
// Function:    EplDllkSetFlag1OfNode()
//
// Description: sets Flag1 (for PReq and SoA) of the specified node ID.
//
// Parameters:  uiNodeId_p              = node ID
//              bSoaFlag1_p             = flag1
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkSetFlag1OfNode(unsigned int uiNodeId_p, BYTE bSoaFlag1_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplDllkNodeInfo *pNodeInfo;

	pNodeInfo = EplDllkGetNodeInfo(uiNodeId_p);
	if (pNodeInfo == NULL) {	// no node info structure available
		Ret = kEplDllNoNodeInfo;
		goto Exit;
	}
	// store flag1 in internal node info structure
	pNodeInfo->m_bSoaFlag1 = bSoaFlag1_p;

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkGetFirstNodeInfo()
//
// Description: returns first info structure of first node in isochronous phase.
//              It is only useful for ErrorHandlerk module.
//
// Parameters:  ppNodeInfo_p            = pointer to pointer of internal node info structure
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkGetFirstNodeInfo(tEplDllkNodeInfo ** ppNodeInfo_p)
{
	tEplKernel Ret = kEplSuccessful;

	*ppNodeInfo_p = EplDllkInstance_g.m_pFirstNodeInfo;

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkAddNode()
//
// Description: adds the specified node to the isochronous phase.
//
// Parameters:  pNodeInfo_p             = pointer of node info structure
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkAddNode(tEplDllNodeInfo * pNodeInfo_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplDllkNodeInfo *pIntNodeInfo;
	tEplDllkNodeInfo **ppIntNodeInfo;
	unsigned int uiHandle;
	tEplFrame *pFrame;
	unsigned int uiFrameSize;

	pIntNodeInfo = EplDllkGetNodeInfo(pNodeInfo_p->m_uiNodeId);
	if (pIntNodeInfo == NULL) {	// no node info structure available
		Ret = kEplDllNoNodeInfo;
		goto Exit;
	}

	EPL_DLLK_DBG_POST_TRACE_VALUE(kEplEventTypeDllkAddNode,
				      pNodeInfo_p->m_uiNodeId, 0);

	// copy node configuration
	pIntNodeInfo->m_dwPresTimeout = pNodeInfo_p->m_dwPresTimeout;
	pIntNodeInfo->m_wPresPayloadLimit = pNodeInfo_p->m_wPresPayloadLimit;

	// $$$ d.k.: actually add node only if MN. On CN it is sufficient to update the node configuration
	if (pNodeInfo_p->m_uiNodeId == EplDllkInstance_g.m_DllConfigParam.m_uiNodeId) {	// we shall send PRes ourself
		// insert our node at the end of the list
		ppIntNodeInfo = &EplDllkInstance_g.m_pFirstNodeInfo;
		while ((*ppIntNodeInfo != NULL)
		       && ((*ppIntNodeInfo)->m_pNextNodeInfo != NULL)) {
			ppIntNodeInfo = &(*ppIntNodeInfo)->m_pNextNodeInfo;
		}
		if (*ppIntNodeInfo != NULL) {
			if ((*ppIntNodeInfo)->m_uiNodeId == pNodeInfo_p->m_uiNodeId) {	// node was already added to list
				// $$$ d.k. maybe this should be an error
				goto Exit;
			} else {	// add our node at the end of the list
				ppIntNodeInfo =
				    &(*ppIntNodeInfo)->m_pNextNodeInfo;
			}
		}
		// set "PReq"-TxBuffer to PRes-TxBuffer
		pIntNodeInfo->m_pPreqTxBuffer =
		    &EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_PRES];
	} else {		// normal CN shall be added to isochronous phase
		// insert node into list in ascending order
		ppIntNodeInfo = &EplDllkInstance_g.m_pFirstNodeInfo;
		while ((*ppIntNodeInfo != NULL)
		       && ((*ppIntNodeInfo)->m_uiNodeId <
			   pNodeInfo_p->m_uiNodeId)
		       && ((*ppIntNodeInfo)->m_uiNodeId !=
			   EplDllkInstance_g.m_DllConfigParam.m_uiNodeId)) {
			ppIntNodeInfo = &(*ppIntNodeInfo)->m_pNextNodeInfo;
		}
		if ((*ppIntNodeInfo != NULL) && ((*ppIntNodeInfo)->m_uiNodeId == pNodeInfo_p->m_uiNodeId)) {	// node was already added to list
			// $$$ d.k. maybe this should be an error
			goto Exit;
		}
	}

	// initialize elements of internal node info structure
	pIntNodeInfo->m_bSoaFlag1 = 0;
	pIntNodeInfo->m_fSoftDelete = FALSE;
	pIntNodeInfo->m_NmtState = kEplNmtCsNotActive;
	if (pIntNodeInfo->m_pPreqTxBuffer == NULL) {	// create TxBuffer entry
		uiFrameSize = pNodeInfo_p->m_wPreqPayloadLimit + 24;
		Ret =
		    EplDllkCreateTxFrame(&uiHandle, &pFrame, &uiFrameSize,
					 kEplMsgTypePreq,
					 kEplDllAsndNotDefined);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}
		pIntNodeInfo->m_pPreqTxBuffer =
		    &EplDllkInstance_g.m_pTxBuffer[uiHandle];
		AmiSetByteToLe(&pFrame->m_le_bDstNodeId,
			       (BYTE) pNodeInfo_p->m_uiNodeId);

		// set up destination MAC address
		EPL_MEMCPY(pFrame->m_be_abDstMac, pIntNodeInfo->m_be_abMacAddr,
			   6);

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
		{
			tEplFrameInfo FrameInfo;

			// initially encode TPDO -> inform PDO module
			FrameInfo.m_pFrame = pFrame;
			FrameInfo.m_uiFrameSize = uiFrameSize;
			Ret = EplPdokCbPdoTransmitted(&FrameInfo);
		}
#endif
	}
	pIntNodeInfo->m_ulDllErrorEvents = 0L;
	// add node to list
	pIntNodeInfo->m_pNextNodeInfo = *ppIntNodeInfo;
	*ppIntNodeInfo = pIntNodeInfo;

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkDeleteNode()
//
// Description: removes the specified node from the isochronous phase.
//
// Parameters:  uiNodeId_p              = node ID
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkDeleteNode(unsigned int uiNodeId_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplDllkNodeInfo *pIntNodeInfo;
	tEplDllkNodeInfo **ppIntNodeInfo;
	unsigned int uiHandle;

	pIntNodeInfo = EplDllkGetNodeInfo(uiNodeId_p);
	if (pIntNodeInfo == NULL) {	// no node info structure available
		Ret = kEplDllNoNodeInfo;
		goto Exit;
	}

	EPL_DLLK_DBG_POST_TRACE_VALUE(kEplEventTypeDllkDelNode, uiNodeId_p, 0);

	// search node in whole list
	ppIntNodeInfo = &EplDllkInstance_g.m_pFirstNodeInfo;
	while ((*ppIntNodeInfo != NULL)
	       && ((*ppIntNodeInfo)->m_uiNodeId != uiNodeId_p)) {
		ppIntNodeInfo = &(*ppIntNodeInfo)->m_pNextNodeInfo;
	}
	if ((*ppIntNodeInfo == NULL) || ((*ppIntNodeInfo)->m_uiNodeId != uiNodeId_p)) {	// node was not found in list
		// $$$ d.k. maybe this should be an error
		goto Exit;
	}
	// remove node from list
	*ppIntNodeInfo = pIntNodeInfo->m_pNextNodeInfo;

	if ((pIntNodeInfo->m_pPreqTxBuffer != NULL)
	    && (pIntNodeInfo->m_pPreqTxBuffer != &EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_PRES])) {	// delete TxBuffer entry
		uiHandle =
		    pIntNodeInfo->m_pPreqTxBuffer -
		    EplDllkInstance_g.m_pTxBuffer;
		pIntNodeInfo->m_pPreqTxBuffer = NULL;
		Ret = EplDllkDeleteTxFrame(uiHandle);
/*        if (Ret != kEplSuccessful)
        {
            goto Exit;
        }*/
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkSoftDeleteNode()
//
// Description: removes the specified node not immediately from the isochronous phase.
//              Instead the will be removed after error (late/loss PRes) without
//              charging the error.
//
// Parameters:  uiNodeId_p              = node ID
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

tEplKernel EplDllkSoftDeleteNode(unsigned int uiNodeId_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplDllkNodeInfo *pIntNodeInfo;

	pIntNodeInfo = EplDllkGetNodeInfo(uiNodeId_p);
	if (pIntNodeInfo == NULL) {	// no node info structure available
		Ret = kEplDllNoNodeInfo;
		goto Exit;
	}

	EPL_DLLK_DBG_POST_TRACE_VALUE(kEplEventTypeDllkSoftDelNode,
				      uiNodeId_p, 0);

	pIntNodeInfo->m_fSoftDelete = TRUE;

      Exit:
	return Ret;
}

#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)

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

//---------------------------------------------------------------------------
//
// Function:    EplDllkChangeState
//
// Description: change DLL state on event and diagnose some communication errors
//
// Parameters:  NmtEvent_p              = DLL event (wrapped in NMT event)
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplDllkChangeState(tEplNmtEvent NmtEvent_p,
				     tEplNmtState NmtState_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplEvent Event;
	tEplErrorHandlerkEvent DllEvent;

	DllEvent.m_ulDllErrorEvents = 0;
	DllEvent.m_uiNodeId = 0;
	DllEvent.m_NmtState = NmtState_p;

	switch (NmtState_p) {
	case kEplNmtGsOff:
	case kEplNmtGsInitialising:
	case kEplNmtGsResetApplication:
	case kEplNmtGsResetCommunication:
	case kEplNmtGsResetConfiguration:
	case kEplNmtCsBasicEthernet:
		// enter DLL_GS_INIT
		EplDllkInstance_g.m_DllState = kEplDllGsInit;
		break;

	case kEplNmtCsNotActive:
	case kEplNmtCsPreOperational1:
		// reduced EPL cycle is active
		if (NmtEvent_p == kEplNmtEventDllCeSoc) {	// SoC received
			// enter DLL_CS_WAIT_PREQ
			EplDllkInstance_g.m_DllState = kEplDllCsWaitPreq;
		} else {
			// enter DLL_GS_INIT
			EplDllkInstance_g.m_DllState = kEplDllGsInit;
		}
		break;

	case kEplNmtCsPreOperational2:
	case kEplNmtCsReadyToOperate:
	case kEplNmtCsOperational:
		// full EPL cycle is active

		switch (EplDllkInstance_g.m_DllState) {
		case kEplDllCsWaitPreq:
			switch (NmtEvent_p) {
				// DLL_CT2
			case kEplNmtEventDllCePreq:
				// enter DLL_CS_WAIT_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_RECVD_PREQ;
				EplDllkInstance_g.m_DllState = kEplDllCsWaitSoa;
				break;

				// DLL_CT8
			case kEplNmtEventDllCeFrameTimeout:
				if (NmtState_p == kEplNmtCsPreOperational2) {	// ignore frame timeout in PreOp2,
					// because the previously configured cycle len
					// may be wrong.
					// 2008/10/15 d.k. If it would not be ignored,
					// we would go cyclically to PreOp1 and on next
					// SoC back to PreOp2.
					break;
				}
				// report DLL_CEV_LOSS_SOC and DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA |
				    EPL_DLL_ERR_CN_LOSS_SOC;

				// enter DLL_CS_WAIT_SOC
				EplDllkInstance_g.m_DllState = kEplDllCsWaitSoc;
				break;

			case kEplNmtEventDllCeSoa:
				// check if multiplexed and PReq should have been received in this cycle
				// and if >= NMT_CS_READY_TO_OPERATE
				if ((EplDllkInstance_g.m_uiCycleCount == 0)
				    && (NmtState_p >= kEplNmtCsReadyToOperate)) {	// report DLL_CEV_LOSS_OF_PREQ
					DllEvent.m_ulDllErrorEvents |=
					    EPL_DLL_ERR_CN_LOSS_PREQ;
				}
				// enter DLL_CS_WAIT_SOC
				EplDllkInstance_g.m_DllState = kEplDllCsWaitSoc;
				break;

				// DLL_CT7
			case kEplNmtEventDllCeSoc:
			case kEplNmtEventDllCeAsnd:
				// report DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA;

			case kEplNmtEventDllCePres:
			default:
				// remain in this state
				break;
			}
			break;

		case kEplDllCsWaitSoc:
			switch (NmtEvent_p) {
				// DLL_CT1
			case kEplNmtEventDllCeSoc:
				// start of cycle and isochronous phase
				// enter DLL_CS_WAIT_PREQ
				EplDllkInstance_g.m_DllState =
				    kEplDllCsWaitPreq;
				break;

				// DLL_CT4
//                        case kEplNmtEventDllCePres:
			case kEplNmtEventDllCeFrameTimeout:
				if (NmtState_p == kEplNmtCsPreOperational2) {	// ignore frame timeout in PreOp2,
					// because the previously configured cycle len
					// may be wrong.
					// 2008/10/15 d.k. If it would not be ignored,
					// we would go cyclically to PreOp1 and on next
					// SoC back to PreOp2.
					break;
				}
				// fall through

			case kEplNmtEventDllCePreq:
			case kEplNmtEventDllCeSoa:
				// report DLL_CEV_LOSS_SOC
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOC;

			case kEplNmtEventDllCeAsnd:
			default:
				// remain in this state
				break;
			}
			break;

		case kEplDllCsWaitSoa:
			switch (NmtEvent_p) {
			case kEplNmtEventDllCeFrameTimeout:
				// DLL_CT3
				if (NmtState_p == kEplNmtCsPreOperational2) {	// ignore frame timeout in PreOp2,
					// because the previously configured cycle len
					// may be wrong.
					// 2008/10/15 d.k. If it would not be ignored,
					// we would go cyclically to PreOp1 and on next
					// SoC back to PreOp2.
					break;
				}
				// fall through

			case kEplNmtEventDllCePreq:
				// report DLL_CEV_LOSS_SOC and DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA |
				    EPL_DLL_ERR_CN_LOSS_SOC;

			case kEplNmtEventDllCeSoa:
				// enter DLL_CS_WAIT_SOC
				EplDllkInstance_g.m_DllState = kEplDllCsWaitSoc;
				break;

				// DLL_CT9
			case kEplNmtEventDllCeSoc:
				// report DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA;

				// enter DLL_CS_WAIT_PREQ
				EplDllkInstance_g.m_DllState =
				    kEplDllCsWaitPreq;
				break;

				// DLL_CT10
			case kEplNmtEventDllCeAsnd:
				// report DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA;

			case kEplNmtEventDllCePres:
			default:
				// remain in this state
				break;
			}
			break;

		case kEplDllGsInit:
			// enter DLL_CS_WAIT_PREQ
			EplDllkInstance_g.m_DllState = kEplDllCsWaitPreq;
			break;

		default:
			break;
		}
		break;

	case kEplNmtCsStopped:
		// full EPL cycle is active, but without PReq/PRes

		switch (EplDllkInstance_g.m_DllState) {
		case kEplDllCsWaitPreq:
			switch (NmtEvent_p) {
				// DLL_CT2
			case kEplNmtEventDllCePreq:
				// enter DLL_CS_WAIT_SOA
				EplDllkInstance_g.m_DllState = kEplDllCsWaitSoa;
				break;

				// DLL_CT8
			case kEplNmtEventDllCeFrameTimeout:
				// report DLL_CEV_LOSS_SOC and DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA |
				    EPL_DLL_ERR_CN_LOSS_SOC;

			case kEplNmtEventDllCeSoa:
				// NMT_CS_STOPPED active
				// it is Ok if no PReq was received

				// enter DLL_CS_WAIT_SOC
				EplDllkInstance_g.m_DllState = kEplDllCsWaitSoc;
				break;

				// DLL_CT7
			case kEplNmtEventDllCeSoc:
			case kEplNmtEventDllCeAsnd:
				// report DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA;

			case kEplNmtEventDllCePres:
			default:
				// remain in this state
				break;
			}
			break;

		case kEplDllCsWaitSoc:
			switch (NmtEvent_p) {
				// DLL_CT1
			case kEplNmtEventDllCeSoc:
				// start of cycle and isochronous phase
				// enter DLL_CS_WAIT_SOA
				EplDllkInstance_g.m_DllState = kEplDllCsWaitSoa;
				break;

				// DLL_CT4
//                        case kEplNmtEventDllCePres:
			case kEplNmtEventDllCePreq:
			case kEplNmtEventDllCeSoa:
			case kEplNmtEventDllCeFrameTimeout:
				// report DLL_CEV_LOSS_SOC
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOC;

			case kEplNmtEventDllCeAsnd:
			default:
				// remain in this state
				break;
			}
			break;

		case kEplDllCsWaitSoa:
			switch (NmtEvent_p) {
				// DLL_CT3
			case kEplNmtEventDllCeFrameTimeout:
				// report DLL_CEV_LOSS_SOC and DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA |
				    EPL_DLL_ERR_CN_LOSS_SOC;

			case kEplNmtEventDllCeSoa:
				// enter DLL_CS_WAIT_SOC
				EplDllkInstance_g.m_DllState = kEplDllCsWaitSoc;
				break;

				// DLL_CT9
			case kEplNmtEventDllCeSoc:
				// report DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA;
				// remain in DLL_CS_WAIT_SOA
				break;

				// DLL_CT10
			case kEplNmtEventDllCeAsnd:
				// report DLL_CEV_LOSS_SOA
				DllEvent.m_ulDllErrorEvents |=
				    EPL_DLL_ERR_CN_LOSS_SOA;

			case kEplNmtEventDllCePreq:
				// NMT_CS_STOPPED active and we do not expect any PReq
				// so just ignore it
			case kEplNmtEventDllCePres:
			default:
				// remain in this state
				break;
			}
			break;

		case kEplDllGsInit:
		default:
			// enter DLL_CS_WAIT_PREQ
			EplDllkInstance_g.m_DllState = kEplDllCsWaitSoa;
			break;
		}
		break;

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
	case kEplNmtMsNotActive:
	case kEplNmtMsBasicEthernet:
		break;

	case kEplNmtMsPreOperational1:
		// reduced EPL cycle is active
		if (EplDllkInstance_g.m_DllState != kEplDllMsNonCyclic) {	// stop cycle timer
#if EPL_TIMER_USE_HIGHRES != FALSE
			Ret =
			    EplTimerHighReskDeleteTimer(&EplDllkInstance_g.
							m_TimerHdlCycle);
#endif
			EplDllkInstance_g.m_DllState = kEplDllMsNonCyclic;

			// stop further processing,
			// because it will be restarted by NMT MN module
			break;
		}

		switch (NmtEvent_p) {
		case kEplNmtEventDllMeSocTrig:
		case kEplNmtEventDllCeAsnd:
			{	// because of reduced EPL cycle SoA shall be triggered, not SoC
				tEplDllState DummyDllState;

				Ret =
				    EplDllkAsyncFrameNotReceived
				    (EplDllkInstance_g.m_LastReqServiceId,
				     EplDllkInstance_g.m_uiLastTargetNodeId);

				// go ahead and send SoA
				Ret = EplDllkMnSendSoa(NmtState_p,
						       &DummyDllState,
						       (EplDllkInstance_g.
							m_uiCycleCount >=
							EPL_C_DLL_PREOP1_START_CYCLES));
				// increment cycle counter to detect if EPL_C_DLL_PREOP1_START_CYCLES empty cycles are elapsed
				EplDllkInstance_g.m_uiCycleCount++;

				// reprogram timer
#if EPL_TIMER_USE_HIGHRES != FALSE
				if (EplDllkInstance_g.m_DllConfigParam.
				    m_dwAsyncSlotTimeout != 0) {
					Ret =
					    EplTimerHighReskModifyTimerNs
					    (&EplDllkInstance_g.m_TimerHdlCycle,
					     EplDllkInstance_g.m_DllConfigParam.
					     m_dwAsyncSlotTimeout,
					     EplDllkCbMnTimerCycle, 0L, FALSE);
				}
#endif
				break;
			}

		default:
			break;
		}
		break;

	case kEplNmtMsPreOperational2:
	case kEplNmtMsReadyToOperate:
	case kEplNmtMsOperational:
		// full EPL cycle is active
		switch (NmtEvent_p) {
		case kEplNmtEventDllMeSocTrig:
			{
				// update cycle counter
				if (EplDllkInstance_g.m_DllConfigParam.m_uiMultiplCycleCnt > 0) {	// multiplexed cycle active
					EplDllkInstance_g.m_uiCycleCount =
					    (EplDllkInstance_g.m_uiCycleCount +
					     1) %
					    EplDllkInstance_g.m_DllConfigParam.
					    m_uiMultiplCycleCnt;
					// $$$ check multiplexed cycle restart
					//     -> toggle MC flag
					//     -> change node linked list
				} else {	// non-multiplexed cycle active
					// start with first node in isochronous phase
					EplDllkInstance_g.m_pCurNodeInfo = NULL;
				}

				switch (EplDllkInstance_g.m_DllState) {
				case kEplDllMsNonCyclic:
					{	// start continuous cycle timer
#if EPL_TIMER_USE_HIGHRES != FALSE
						Ret =
						    EplTimerHighReskModifyTimerNs
						    (&EplDllkInstance_g.
						     m_TimerHdlCycle,
						     EplDllkInstance_g.
						     m_ullFrameTimeout,
						     EplDllkCbMnTimerCycle, 0L,
						     TRUE);
#endif
						// continue with sending SoC
					}

				case kEplDllMsWaitAsnd:
				case kEplDllMsWaitSocTrig:
					{	// if m_LastReqServiceId is still valid,
						// SoA was not correctly answered
						// and user part has to be informed
						Ret =
						    EplDllkAsyncFrameNotReceived
						    (EplDllkInstance_g.
						     m_LastReqServiceId,
						     EplDllkInstance_g.
						     m_uiLastTargetNodeId);

						// send SoC
						Ret = EplDllkMnSendSoc();

						// new DLL state
						EplDllkInstance_g.m_DllState =
						    kEplDllMsWaitPreqTrig;

						// start WaitSoCPReq Timer
#if EPL_TIMER_USE_HIGHRES != FALSE
						Ret =
						    EplTimerHighReskModifyTimerNs
						    (&EplDllkInstance_g.
						     m_TimerHdlResponse,
						     EplDllkInstance_g.
						     m_DllConfigParam.
						     m_dwWaitSocPreq,
						     EplDllkCbMnTimerResponse,
						     0L, FALSE);
#endif
						break;
					}

				default:
					{	// wrong DLL state / cycle time exceeded
						DllEvent.m_ulDllErrorEvents |=
						    EPL_DLL_ERR_MN_CYCTIMEEXCEED;
						EplDllkInstance_g.m_DllState =
						    kEplDllMsWaitSocTrig;
						break;
					}
				}

				break;
			}

		case kEplNmtEventDllMePresTimeout:
			{

				switch (EplDllkInstance_g.m_DllState) {
				case kEplDllMsWaitPres:
					{	// PRes not received

						if (EplDllkInstance_g.m_pCurNodeInfo->m_fSoftDelete == FALSE) {	// normal isochronous CN
							DllEvent.
							    m_ulDllErrorEvents
							    |=
							    EPL_DLL_ERR_MN_CN_LOSS_PRES;
							DllEvent.m_uiNodeId =
							    EplDllkInstance_g.
							    m_pCurNodeInfo->
							    m_uiNodeId;
						} else {	// CN shall be deleted softly
							Event.m_EventSink =
							    kEplEventSinkDllkCal;
							Event.m_EventType =
							    kEplEventTypeDllkSoftDelNode;
							// $$$ d.k. set Event.m_NetTime to current time
							Event.m_uiSize =
							    sizeof(unsigned
								   int);
							Event.m_pArg =
							    &EplDllkInstance_g.
							    m_pCurNodeInfo->
							    m_uiNodeId;
							Ret =
							    EplEventkPost
							    (&Event);
						}

						// continue with sending next PReq
					}

				case kEplDllMsWaitPreqTrig:
					{
						// send next PReq
						Ret =
						    EplDllkMnSendPreq
						    (NmtState_p,
						     &EplDllkInstance_g.
						     m_DllState);

						break;
					}

				default:
					{	// wrong DLL state
						break;
					}
				}

				break;
			}

		case kEplNmtEventDllCePres:
			{

				switch (EplDllkInstance_g.m_DllState) {
				case kEplDllMsWaitPres:
					{	// PRes received
						// send next PReq
						Ret =
						    EplDllkMnSendPreq
						    (NmtState_p,
						     &EplDllkInstance_g.
						     m_DllState);

						break;
					}

				default:
					{	// wrong DLL state
						break;
					}
				}

				break;
			}

		case kEplNmtEventDllMeSoaTrig:
			{

				switch (EplDllkInstance_g.m_DllState) {
				case kEplDllMsWaitSoaTrig:
					{	// MN PRes sent
						// send SoA
						Ret =
						    EplDllkMnSendSoa(NmtState_p,
								     &EplDllkInstance_g.
								     m_DllState,
								     TRUE);

						break;
					}

				default:
					{	// wrong DLL state
						break;
					}
				}

				break;
			}

		case kEplNmtEventDllCeAsnd:
			{	// ASnd has been received, but it may be not the requested one
/*
                    // report if SoA was correctly answered
                    Ret = EplDllkAsyncFrameNotReceived(EplDllkInstance_g.m_LastReqServiceId,
                                                       EplDllkInstance_g.m_uiLastTargetNodeId);
*/
				if (EplDllkInstance_g.m_DllState ==
				    kEplDllMsWaitAsnd) {
					EplDllkInstance_g.m_DllState =
					    kEplDllMsWaitSocTrig;
				}
				break;
			}

		default:
			break;
		}
		break;
#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)

	default:
		break;
	}

	if (DllEvent.m_ulDllErrorEvents != 0) {	// error event set -> post it to error handler
		Event.m_EventSink = kEplEventSinkErrk;
		Event.m_EventType = kEplEventTypeDllError;
		// $$$ d.k. set Event.m_NetTime to current time
		Event.m_uiSize = sizeof(DllEvent);
		Event.m_pArg = &DllEvent;
		Ret = EplEventkPost(&Event);
	}

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkCbFrameReceived()
//
// Description: called from EdrvInterruptHandler()
//
// Parameters:  pRxBuffer_p             = receive buffer structure
//
// Returns:     (none)
//
//
// State:
//
//---------------------------------------------------------------------------

static void EplDllkCbFrameReceived(tEdrvRxBuffer * pRxBuffer_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplNmtState NmtState;
	tEplNmtEvent NmtEvent = kEplNmtEventNoEvent;
	tEplEvent Event;
	tEplFrame *pFrame;
	tEplFrame *pTxFrame;
	tEdrvTxBuffer *pTxBuffer = NULL;
	tEplFrameInfo FrameInfo;
	tEplMsgType MsgType;
	tEplDllReqServiceId ReqServiceId;
	unsigned int uiAsndServiceId;
	unsigned int uiNodeId;
	BYTE bFlag1;

	BENCHMARK_MOD_02_SET(3);
	NmtState = EplNmtkGetNmtState();

	if (NmtState <= kEplNmtGsResetConfiguration) {
		goto Exit;
	}

	pFrame = (tEplFrame *) pRxBuffer_p->m_pbBuffer;

#if EDRV_EARLY_RX_INT != FALSE
	switch (pRxBuffer_p->m_BufferInFrame) {
	case kEdrvBufferFirstInFrame:
		{
			MsgType =
			    (tEplMsgType) AmiGetByteFromLe(&pFrame->
							   m_le_bMessageType);
			if (MsgType == kEplMsgTypePreq) {
				if (EplDllkInstance_g.m_DllState == kEplDllCsWaitPreq) {	// PReq expected and actually received
					// d.k.: The condition above is sufficent, because EPL cycle is active
					//       and no non-EPL frame shall be received in isochronous phase.
					// start transmission PRes
					// $$$ What if Tx buffer is invalid?
					pTxBuffer =
					    &EplDllkInstance_g.
					    m_pTxBuffer[EPL_DLLK_TXFRAME_PRES];
#if (EPL_DLL_PRES_READY_AFTER_SOA != FALSE) || (EPL_DLL_PRES_READY_AFTER_SOC != FALSE)
					Ret = EdrvTxMsgStart(pTxBuffer);
#else
					pTxFrame =
					    (tEplFrame *) pTxBuffer->m_pbBuffer;
					// update frame (NMT state, RD, RS, PR, MS, EN flags)
					AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.
						       m_le_bNmtStatus,
						       (BYTE) NmtState);
					AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.
						       m_le_bFlag2,
						       EplDllkInstance_g.
						       m_bFlag2);
					if (NmtState != kEplNmtCsOperational) {	// mark PDO as invalid in NMT state Op
						// $$$ reset only RD flag; set other flags appropriately
						AmiSetByteToLe(&pTxFrame->
							       m_Data.m_Pres.
							       m_le_bFlag1, 0);
					}
					// $$$ make function that updates Pres, StatusRes
					// send PRes frame
					Ret = EdrvSendTxMsg(pTxBuffer);
#endif
				}
			}
			goto Exit;
		}

	case kEdrvBufferMiddleInFrame:
		{
			goto Exit;
		}

	case kEdrvBufferLastInFrame:
		{
			break;
		}
	}
#endif

	FrameInfo.m_pFrame = pFrame;
	FrameInfo.m_uiFrameSize = pRxBuffer_p->m_uiRxMsgLen;
	FrameInfo.m_NetTime.m_dwNanoSec = pRxBuffer_p->m_NetTime.m_dwNanoSec;
	FrameInfo.m_NetTime.m_dwSec = pRxBuffer_p->m_NetTime.m_dwSec;

	if (AmiGetWordFromBe(&pFrame->m_be_wEtherType) != EPL_C_DLL_ETHERTYPE_EPL) {	// non-EPL frame
		//TRACE2("EplDllkCbFrameReceived: pfnCbAsync=0x%p SrcMAC=0x%llx\n", EplDllkInstance_g.m_pfnCbAsync, AmiGetQword48FromBe(pFrame->m_be_abSrcMac));
		if (EplDllkInstance_g.m_pfnCbAsync != NULL) {	// handler for async frames is registered
			EplDllkInstance_g.m_pfnCbAsync(&FrameInfo);
		}

		goto Exit;
	}

	MsgType = (tEplMsgType) AmiGetByteFromLe(&pFrame->m_le_bMessageType);
	switch (MsgType) {
	case kEplMsgTypePreq:
		{
			// PReq frame
			// d.k.: (we assume that this PReq frame is intended for us and don't check DstNodeId)
			if (AmiGetByteFromLe(&pFrame->m_le_bDstNodeId) != EplDllkInstance_g.m_DllConfigParam.m_uiNodeId) {	// this PReq is not intended for us
				goto Exit;
			}
			NmtEvent = kEplNmtEventDllCePreq;

			if (NmtState >= kEplNmtMsNotActive) {	// MN is active -> wrong msg type
				break;
			}
#if EDRV_EARLY_RX_INT == FALSE
			if (NmtState >= kEplNmtCsPreOperational2) {	// respond to and process PReq frames only in PreOp2, ReadyToOp and Op
				// Does PRes exist?
				pTxBuffer =
				    &EplDllkInstance_g.
				    m_pTxBuffer[EPL_DLLK_TXFRAME_PRES];
				if (pTxBuffer->m_pbBuffer != NULL) {	// PRes does exist
#if (EPL_DLL_PRES_READY_AFTER_SOA != FALSE) || (EPL_DLL_PRES_READY_AFTER_SOC != FALSE)
					EdrvTxMsgStart(pTxBuffer);
#else
					pTxFrame =
					    (tEplFrame *) pTxBuffer->m_pbBuffer;
					// update frame (NMT state, RD, RS, PR, MS, EN flags)
					AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.
						       m_le_bNmtStatus,
						       (BYTE) NmtState);
					AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.
						       m_le_bFlag2,
						       EplDllkInstance_g.
						       m_bFlag2);
					bFlag1 =
					    AmiGetByteFromLe(&pFrame->m_Data.
							     m_Preq.
							     m_le_bFlag1);
					// save EA flag
					EplDllkInstance_g.m_bMnFlag1 =
					    (EplDllkInstance_g.
					     m_bMnFlag1 & ~EPL_FRAME_FLAG1_EA)
					    | (bFlag1 & EPL_FRAME_FLAG1_EA);
					// preserve MS flag
					bFlag1 &= EPL_FRAME_FLAG1_MS;
					// add EN flag from Error signaling module
					bFlag1 |=
					    EplDllkInstance_g.
					    m_bFlag1 & EPL_FRAME_FLAG1_EN;
					if (NmtState != kEplNmtCsOperational) {	// mark PDO as invalid in NMT state Op
						// reset only RD flag
						AmiSetByteToLe(&pTxFrame->
							       m_Data.m_Pres.
							       m_le_bFlag1,
							       bFlag1);
					} else {	// leave RD flag untouched
						AmiSetByteToLe(&pTxFrame->
							       m_Data.m_Pres.
							       m_le_bFlag1,
							       (AmiGetByteFromLe
								(&pTxFrame->
								 m_Data.m_Pres.
								 m_le_bFlag1) &
								EPL_FRAME_FLAG1_RD)
							       | bFlag1);
					}
					// $$$ update EPL_DLL_PRES_READY_AFTER_* code
					// send PRes frame
					Ret = EdrvSendTxMsg(pTxBuffer);
					if (Ret != kEplSuccessful) {
						goto Exit;
					}
#endif
				}
#endif
				// inform PDO module
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
				if (NmtState >= kEplNmtCsReadyToOperate) {	// inform PDO module only in ReadyToOp and Op
					if (NmtState != kEplNmtCsOperational) {
						// reset RD flag and all other flags, but that does not matter, because they were processed above
						AmiSetByteToLe(&pFrame->m_Data.
							       m_Preq.
							       m_le_bFlag1, 0);
					}
					// compares real frame size and PDO size
					if ((unsigned
					     int)(AmiGetWordFromLe(&pFrame->
								   m_Data.
								   m_Preq.
								   m_le_wSize) +
						  24)
					    > FrameInfo.m_uiFrameSize) {	// format error
						tEplErrorHandlerkEvent DllEvent;

						DllEvent.m_ulDllErrorEvents =
						    EPL_DLL_ERR_INVALID_FORMAT;
						DllEvent.m_uiNodeId =
						    AmiGetByteFromLe(&pFrame->
								     m_le_bSrcNodeId);
						DllEvent.m_NmtState = NmtState;
						Event.m_EventSink =
						    kEplEventSinkErrk;
						Event.m_EventType =
						    kEplEventTypeDllError;
						Event.m_NetTime =
						    FrameInfo.m_NetTime;
						Event.m_uiSize =
						    sizeof(DllEvent);
						Event.m_pArg = &DllEvent;
						Ret = EplEventkPost(&Event);
						break;
					}
					// forward PReq frame as RPDO to PDO module
					Ret = EplPdokCbPdoReceived(&FrameInfo);

				}
#if (EPL_DLL_PRES_READY_AFTER_SOC != FALSE)
				if (pTxBuffer->m_pbBuffer != NULL) {	// PRes does exist
					// inform PDO module about PRes after PReq
					FrameInfo.m_pFrame =
					    (tEplFrame *) pTxBuffer->m_pbBuffer;
					FrameInfo.m_uiFrameSize =
					    pTxBuffer->m_uiMaxBufferLen;
					Ret =
					    EplPdokCbPdoTransmitted(&FrameInfo);
				}
#endif
#endif

#if EDRV_EARLY_RX_INT == FALSE
				// $$$ inform emergency protocol handling (error signaling module) about flags
			}
#endif

			// reset cycle counter
			EplDllkInstance_g.m_uiCycleCount = 0;

			break;
		}

	case kEplMsgTypePres:
		{
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
			tEplDllkNodeInfo *pIntNodeInfo;
			tEplHeartbeatEvent HeartbeatEvent;
#endif

			// PRes frame
			NmtEvent = kEplNmtEventDllCePres;

			uiNodeId = AmiGetByteFromLe(&pFrame->m_le_bSrcNodeId);

			if ((NmtState >= kEplNmtCsPreOperational2)
			    && (NmtState <= kEplNmtCsOperational)) {	// process PRes frames only in PreOp2, ReadyToOp and Op of CN

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
				pIntNodeInfo = EplDllkGetNodeInfo(uiNodeId);
				if (pIntNodeInfo == NULL) {	// no node info structure available
					Ret = kEplDllNoNodeInfo;
					goto Exit;
				}
			} else if (EplDllkInstance_g.m_DllState == kEplDllMsWaitPres) {	// or process PRes frames in MsWaitPres

				pIntNodeInfo = EplDllkInstance_g.m_pCurNodeInfo;
				if ((pIntNodeInfo == NULL) || (pIntNodeInfo->m_uiNodeId != uiNodeId)) {	// ignore PRes, because it is from wrong CN
					// $$$ maybe post event to NmtMn module
					goto Exit;
				}
				// forward Flag2 to asynchronous scheduler
				bFlag1 =
				    AmiGetByteFromLe(&pFrame->m_Data.m_Asnd.
						     m_Payload.m_StatusResponse.
						     m_le_bFlag2);
				Ret =
				    EplDllkCalAsyncSetPendingRequests(uiNodeId,
								      ((tEplDllAsyncReqPriority) ((bFlag1 & EPL_FRAME_FLAG2_PR) >> EPL_FRAME_FLAG2_PR_SHIFT)), (bFlag1 & EPL_FRAME_FLAG2_RS));

#endif
			} else {	// ignore PRes, because it was received in wrong NMT state
				// but execute EplDllkChangeState() and post event to NMT module
				break;
			}

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
			{	// check NMT state of CN
				HeartbeatEvent.m_wErrorCode = EPL_E_NO_ERROR;
				HeartbeatEvent.m_NmtState =
				    (tEplNmtState) (AmiGetByteFromLe
						    (&pFrame->m_Data.m_Pres.
						     m_le_bNmtStatus) |
						    EPL_NMT_TYPE_CS);
				if (pIntNodeInfo->m_NmtState != HeartbeatEvent.m_NmtState) {	// NMT state of CN has changed -> post event to NmtMnu module
					if (pIntNodeInfo->m_fSoftDelete == FALSE) {	// normal isochronous CN
						HeartbeatEvent.m_uiNodeId =
						    uiNodeId;
						Event.m_EventSink =
						    kEplEventSinkNmtMnu;
						Event.m_EventType =
						    kEplEventTypeHeartbeat;
						Event.m_uiSize =
						    sizeof(HeartbeatEvent);
						Event.m_pArg = &HeartbeatEvent;
					} else {	// CN shall be deleted softly
						Event.m_EventSink =
						    kEplEventSinkDllkCal;
						Event.m_EventType =
						    kEplEventTypeDllkSoftDelNode;
						Event.m_uiSize =
						    sizeof(unsigned int);
						Event.m_pArg =
						    &pIntNodeInfo->m_uiNodeId;
					}
					Event.m_NetTime = FrameInfo.m_NetTime;
					Ret = EplEventkPost(&Event);

					// save current NMT state of CN in internal node structure
					pIntNodeInfo->m_NmtState =
					    HeartbeatEvent.m_NmtState;
				}
			}
#endif

			// inform PDO module
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
			if ((NmtState != kEplNmtCsPreOperational2)
			    && (NmtState != kEplNmtMsPreOperational2)) {	// inform PDO module only in ReadyToOp and Op
				// compare real frame size and PDO size?
				if (((unsigned
				      int)(AmiGetWordFromLe(&pFrame->m_Data.
							    m_Pres.m_le_wSize) +
					   24)
				     > FrameInfo.m_uiFrameSize)
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
				    ||
				    (AmiGetWordFromLe
				     (&pFrame->m_Data.m_Pres.m_le_wSize) >
				     pIntNodeInfo->m_wPresPayloadLimit)
#endif
				    ) {	// format error
					tEplErrorHandlerkEvent DllEvent;

					DllEvent.m_ulDllErrorEvents =
					    EPL_DLL_ERR_INVALID_FORMAT;
					DllEvent.m_uiNodeId = uiNodeId;
					DllEvent.m_NmtState = NmtState;
					Event.m_EventSink = kEplEventSinkErrk;
					Event.m_EventType =
					    kEplEventTypeDllError;
					Event.m_NetTime = FrameInfo.m_NetTime;
					Event.m_uiSize = sizeof(DllEvent);
					Event.m_pArg = &DllEvent;
					Ret = EplEventkPost(&Event);
					break;
				}
				if ((NmtState != kEplNmtCsOperational)
				    && (NmtState != kEplNmtMsOperational)) {
					// reset RD flag and all other flags, but that does not matter, because they were processed above
					AmiSetByteToLe(&pFrame->m_Data.m_Pres.
						       m_le_bFlag1, 0);
				}
				Ret = EplPdokCbPdoReceived(&FrameInfo);
			}
#endif

			break;
		}

	case kEplMsgTypeSoc:
		{
			// SoC frame
			NmtEvent = kEplNmtEventDllCeSoc;

			if (NmtState >= kEplNmtMsNotActive) {	// MN is active -> wrong msg type
				break;
			}
#if EPL_DLL_PRES_READY_AFTER_SOC != FALSE
			// post PRes to transmit FIFO of the ethernet controller, but don't start
			// transmission over bus
			pTxBuffer =
			    &EplDllkInstance_g.
			    m_pTxBuffer[EPL_DLLK_TXFRAME_PRES];
			// Does PRes exist?
			if (pTxBuffer->m_pbBuffer != NULL) {	// PRes does exist
				pTxFrame = (tEplFrame *) pTxBuffer->m_pbBuffer;
				// update frame (NMT state, RD, RS, PR, MS, EN flags)
				if (NmtState < kEplNmtCsPreOperational2) {	// NMT state is not PreOp2, ReadyToOp or Op
					// fake NMT state PreOp2, because PRes will be sent only in PreOp2 or greater
					NmtState = kEplNmtCsPreOperational2;
				}
				AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.
					       m_le_bNmtStatus,
					       (BYTE) NmtState);
				AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.
					       m_le_bFlag2,
					       EplDllkInstance_g.m_bFlag2);
				if (NmtState != kEplNmtCsOperational) {	// mark PDO as invalid in NMT state Op
					// $$$ reset only RD flag; set other flags appropriately
					AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.
						       m_le_bFlag1, 0);
				}
				// $$$ make function that updates Pres, StatusRes
				// mark PRes frame as ready for transmission
				Ret = EdrvTxMsgReady(pTxBuffer);
			}
#endif

			if (NmtState >= kEplNmtCsPreOperational2) {	// SoC frames only in PreOp2, ReadyToOp and Op
				// trigger synchronous task
				Event.m_EventSink = kEplEventSinkSync;
				Event.m_EventType = kEplEventTypeSync;
				Event.m_uiSize = 0;
				Ret = EplEventkPost(&Event);

				// update cycle counter
				if (EplDllkInstance_g.m_DllConfigParam.m_uiMultiplCycleCnt > 0) {	// multiplexed cycle active
					EplDllkInstance_g.m_uiCycleCount =
					    (EplDllkInstance_g.m_uiCycleCount +
					     1) %
					    EplDllkInstance_g.m_DllConfigParam.
					    m_uiMultiplCycleCnt;
				}
			}
			// reprogram timer
#if EPL_TIMER_USE_HIGHRES != FALSE
			if (EplDllkInstance_g.m_ullFrameTimeout != 0) {
				Ret =
				    EplTimerHighReskModifyTimerNs
				    (&EplDllkInstance_g.m_TimerHdlCycle,
				     EplDllkInstance_g.m_ullFrameTimeout,
				     EplDllkCbCnTimer, 0L, FALSE);
			}
#endif

			break;
		}

	case kEplMsgTypeSoa:
		{
			// SoA frame
			NmtEvent = kEplNmtEventDllCeSoa;

			if (NmtState >= kEplNmtMsNotActive) {	// MN is active -> wrong msg type
				break;
			}

			pTxFrame = NULL;

			if ((NmtState & EPL_NMT_SUPERSTATE_MASK) != EPL_NMT_CS_EPLMODE) {	// do not respond, if NMT state is < PreOp1 (i.e. not EPL_MODE)
				break;
			}
			// check TargetNodeId
			uiNodeId =
			    AmiGetByteFromLe(&pFrame->m_Data.m_Soa.
					     m_le_bReqServiceTarget);
			if (uiNodeId == EplDllkInstance_g.m_DllConfigParam.m_uiNodeId) {	// local node is the target of the current request

				// check ServiceId
				ReqServiceId =
				    (tEplDllReqServiceId)
				    AmiGetByteFromLe(&pFrame->m_Data.m_Soa.
						     m_le_bReqServiceId);
				if (ReqServiceId == kEplDllReqServiceStatus) {	// StatusRequest
					if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_STATUSRES].m_pbBuffer != NULL) {	// StatusRes does exist

						pTxFrame =
						    (tEplFrame *)
						    EplDllkInstance_g.
						    m_pTxBuffer
						    [EPL_DLLK_TXFRAME_STATUSRES].
						    m_pbBuffer;
						// update StatusRes frame (NMT state, EN, EC, RS, PR flags)
						AmiSetByteToLe(&pTxFrame->
							       m_Data.m_Asnd.
							       m_Payload.
							       m_StatusResponse.
							       m_le_bNmtStatus,
							       (BYTE) NmtState);
						AmiSetByteToLe(&pTxFrame->
							       m_Data.m_Asnd.
							       m_Payload.
							       m_StatusResponse.
							       m_le_bFlag1,
							       EplDllkInstance_g.
							       m_bFlag1);
						AmiSetByteToLe(&pTxFrame->
							       m_Data.m_Asnd.
							       m_Payload.
							       m_StatusResponse.
							       m_le_bFlag2,
							       EplDllkInstance_g.
							       m_bFlag2);
						// send StatusRes
						Ret =
						    EdrvSendTxMsg
						    (&EplDllkInstance_g.
						     m_pTxBuffer
						     [EPL_DLLK_TXFRAME_STATUSRES]);
						if (Ret != kEplSuccessful) {
							goto Exit;
						}
						TGT_DBG_SIGNAL_TRACE_POINT(8);

						// update error signaling
						bFlag1 =
						    AmiGetByteFromLe(&pFrame->
								     m_Data.
								     m_Soa.
								     m_le_bFlag1);
						if (((bFlag1 ^ EplDllkInstance_g.m_bMnFlag1) & EPL_FRAME_FLAG1_ER) != 0) {	// exception reset flag was changed by MN
							// assume same state for EC in next cycle (clear all other bits)
							if ((bFlag1 &
							     EPL_FRAME_FLAG1_ER)
							    != 0) {
								// set EC and reset rest
								EplDllkInstance_g.
								    m_bFlag1 =
								    EPL_FRAME_FLAG1_EC;
							} else {
								// reset complete flag 1 (including EC and EN)
								EplDllkInstance_g.
								    m_bFlag1 =
								    0;
							}
						}
						// save flag 1 from MN for Status request response cycle
						EplDllkInstance_g.m_bMnFlag1 =
						    bFlag1;
					}
				} else if (ReqServiceId == kEplDllReqServiceIdent) {	// IdentRequest
					if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_IDENTRES].m_pbBuffer != NULL) {	// IdentRes does exist
						pTxFrame =
						    (tEplFrame *)
						    EplDllkInstance_g.
						    m_pTxBuffer
						    [EPL_DLLK_TXFRAME_IDENTRES].
						    m_pbBuffer;
						// update IdentRes frame (NMT state, RS, PR flags)
						AmiSetByteToLe(&pTxFrame->
							       m_Data.m_Asnd.
							       m_Payload.
							       m_IdentResponse.
							       m_le_bNmtStatus,
							       (BYTE) NmtState);
						AmiSetByteToLe(&pTxFrame->
							       m_Data.m_Asnd.
							       m_Payload.
							       m_IdentResponse.
							       m_le_bFlag2,
							       EplDllkInstance_g.
							       m_bFlag2);
						// send IdentRes
						Ret =
						    EdrvSendTxMsg
						    (&EplDllkInstance_g.
						     m_pTxBuffer
						     [EPL_DLLK_TXFRAME_IDENTRES]);
						if (Ret != kEplSuccessful) {
							goto Exit;
						}
						TGT_DBG_SIGNAL_TRACE_POINT(7);
					}
				} else if (ReqServiceId == kEplDllReqServiceNmtRequest) {	// NmtRequest
					if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NMTREQ].m_pbBuffer != NULL) {	// NmtRequest does exist
						// check if frame is not empty and not being filled
						if (EplDllkInstance_g.
						    m_pTxBuffer
						    [EPL_DLLK_TXFRAME_NMTREQ].
						    m_uiTxMsgLen >
						    EPL_DLLK_BUFLEN_FILLING) {
							/*if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NMTREQ].m_uiTxMsgLen < EPL_DLLK_BUFLEN_MIN)
							   {   // pad frame
							   EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NMTREQ].m_uiTxMsgLen = EPL_DLLK_BUFLEN_MIN;
							   } */
							// memorize transmission
							pTxFrame =
							    (tEplFrame *) 1;
							// send NmtRequest
							Ret =
							    EdrvSendTxMsg
							    (&EplDllkInstance_g.
							     m_pTxBuffer
							     [EPL_DLLK_TXFRAME_NMTREQ]);
							if (Ret !=
							    kEplSuccessful) {
								goto Exit;
							}

						}
					}

				} else if (ReqServiceId == kEplDllReqServiceUnspecified) {	// unspecified invite
					if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NONEPL].m_pbBuffer != NULL) {	// non-EPL frame does exist
						// check if frame is not empty and not being filled
						if (EplDllkInstance_g.
						    m_pTxBuffer
						    [EPL_DLLK_TXFRAME_NONEPL].
						    m_uiTxMsgLen >
						    EPL_DLLK_BUFLEN_FILLING) {
							/*if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NMTREQ].m_uiTxMsgLen < EPL_DLLK_BUFLEN_MIN)
							   {   // pad frame
							   EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NMTREQ].m_uiTxMsgLen = EPL_DLLK_BUFLEN_MIN;
							   } */
							// memorize transmission
							pTxFrame =
							    (tEplFrame *) 1;
							// send non-EPL frame
							Ret =
							    EdrvSendTxMsg
							    (&EplDllkInstance_g.
							     m_pTxBuffer
							     [EPL_DLLK_TXFRAME_NONEPL]);
							if (Ret !=
							    kEplSuccessful) {
								goto Exit;
							}

						}
					}

				} else if (ReqServiceId == kEplDllReqServiceNo) {	// no async service requested -> do nothing
				}
			}
#if EPL_DLL_PRES_READY_AFTER_SOA != FALSE
			if (pTxFrame == NULL) {	// signal process function readiness of PRes frame
				Event.m_EventSink = kEplEventSinkDllk;
				Event.m_EventType = kEplEventTypeDllkPresReady;
				Event.m_uiSize = 0;
				Event.m_pArg = NULL;
				Ret = EplEventkPost(&Event);
			}
#endif

			// inform PDO module
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0)
//            Ret = EplPdokCbSoa(&FrameInfo);
#endif

			// $$$ put SrcNodeId, NMT state and NetTime as HeartbeatEvent into eventqueue

			// $$$ inform emergency protocol handling about flags
			break;
		}

	case kEplMsgTypeAsnd:
		{
			// ASnd frame
			NmtEvent = kEplNmtEventDllCeAsnd;

			// ASnd service registered?
			uiAsndServiceId =
			    (unsigned int)AmiGetByteFromLe(&pFrame->m_Data.
							   m_Asnd.
							   m_le_bServiceId);

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
			if ((EplDllkInstance_g.m_DllState >= kEplDllMsNonCyclic)
			    &&
			    ((((tEplDllAsndServiceId) uiAsndServiceId) ==
			      kEplDllAsndStatusResponse)
			     || (((tEplDllAsndServiceId) uiAsndServiceId) == kEplDllAsndIdentResponse))) {	// StatusRes or IdentRes received
				uiNodeId =
				    AmiGetByteFromLe(&pFrame->m_le_bSrcNodeId);
				if ((EplDllkInstance_g.m_LastReqServiceId ==
				     ((tEplDllReqServiceId) uiAsndServiceId))
				    && (uiNodeId == EplDllkInstance_g.m_uiLastTargetNodeId)) {	// mark request as responded
					EplDllkInstance_g.m_LastReqServiceId =
					    kEplDllReqServiceNo;
				}
				if (((tEplDllAsndServiceId) uiAsndServiceId) == kEplDllAsndIdentResponse) {	// memorize MAC address of CN for PReq
					tEplDllkNodeInfo *pIntNodeInfo;

					pIntNodeInfo =
					    EplDllkGetNodeInfo(uiNodeId);
					if (pIntNodeInfo == NULL) {	// no node info structure available
						Ret = kEplDllNoNodeInfo;
					} else {
						EPL_MEMCPY(pIntNodeInfo->
							   m_be_abMacAddr,
							   pFrame->
							   m_be_abSrcMac, 6);
					}
				}
				// forward Flag2 to asynchronous scheduler
				bFlag1 =
				    AmiGetByteFromLe(&pFrame->m_Data.m_Asnd.
						     m_Payload.m_StatusResponse.
						     m_le_bFlag2);
				Ret =
				    EplDllkCalAsyncSetPendingRequests(uiNodeId,
								      ((tEplDllAsyncReqPriority) ((bFlag1 & EPL_FRAME_FLAG2_PR) >> EPL_FRAME_FLAG2_PR_SHIFT)), (bFlag1 & EPL_FRAME_FLAG2_RS));
			}
#endif

			if (uiAsndServiceId < EPL_DLL_MAX_ASND_SERVICE_ID) {	// ASnd service ID is valid
				if (EplDllkInstance_g.m_aAsndFilter[uiAsndServiceId] == kEplDllAsndFilterAny) {	// ASnd service ID is registered
					// forward frame via async receive FIFO to userspace
					Ret =
					    EplDllkCalAsyncFrameReceived
					    (&FrameInfo);
				} else if (EplDllkInstance_g.m_aAsndFilter[uiAsndServiceId] == kEplDllAsndFilterLocal) {	// ASnd service ID is registered, but only local node ID or broadcasts
					// shall be forwarded
					uiNodeId =
					    AmiGetByteFromLe(&pFrame->
							     m_le_bDstNodeId);
					if ((uiNodeId ==
					     EplDllkInstance_g.m_DllConfigParam.
					     m_uiNodeId)
					    || (uiNodeId == EPL_C_ADR_BROADCAST)) {	// ASnd frame is intended for us
						// forward frame via async receive FIFO to userspace
						Ret =
						    EplDllkCalAsyncFrameReceived
						    (&FrameInfo);
					}
				}
			}
			break;
		}

	default:
		{
			break;
		}
	}

	if (NmtEvent != kEplNmtEventNoEvent) {	// event for DLL and NMT state machine generated
		Ret = EplDllkChangeState(NmtEvent, NmtState);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}

		if ((NmtEvent != kEplNmtEventDllCeAsnd)
		    && ((NmtState <= kEplNmtCsPreOperational1) || (NmtEvent != kEplNmtEventDllCePres))) {	// NMT state machine is not interested in ASnd frames and PRes frames when not CsNotActive or CsPreOp1
			// inform NMT module
			Event.m_EventSink = kEplEventSinkNmtk;
			Event.m_EventType = kEplEventTypeNmtEvent;
			Event.m_uiSize = sizeof(NmtEvent);
			Event.m_pArg = &NmtEvent;
			Ret = EplEventkPost(&Event);
		}
	}

      Exit:
	if (Ret != kEplSuccessful) {
		DWORD dwArg;

		BENCHMARK_MOD_02_TOGGLE(9);

		dwArg = EplDllkInstance_g.m_DllState | (NmtEvent << 8);

		// Error event for API layer
		Ret = EplEventkPostError(kEplEventSourceDllk,
					 Ret, sizeof(dwArg), &dwArg);
	}
	BENCHMARK_MOD_02_RESET(3);
	return;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkCbFrameTransmitted()
//
// Description: called from EdrvInterruptHandler().
//              It signals
//
// Parameters:  pRxBuffer_p             = receive buffer structure
//
// Returns:     (none)
//
//
// State:
//
//---------------------------------------------------------------------------

static void EplDllkCbFrameTransmitted(tEdrvTxBuffer * pTxBuffer_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplEvent Event;
	tEplDllAsyncReqPriority Priority;
	tEplNmtState NmtState;

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0) \
    && (EPL_DLL_PRES_READY_AFTER_SOC == FALSE)
	tEplFrameInfo FrameInfo;
#endif

	NmtState = EplNmtkGetNmtState();

	if (NmtState <= kEplNmtGsResetConfiguration) {
		goto Exit;
	}

	if ((pTxBuffer_p - EplDllkInstance_g.m_pTxBuffer) == EPL_DLLK_TXFRAME_NMTREQ) {	// frame from NMT request FIFO sent
		// mark Tx-buffer as empty
		pTxBuffer_p->m_uiTxMsgLen = EPL_DLLK_BUFLEN_EMPTY;

		// post event to DLL
		Priority = kEplDllAsyncReqPrioNmt;
		Event.m_EventSink = kEplEventSinkDllk;
		Event.m_EventType = kEplEventTypeDllkFillTx;
		EPL_MEMSET(&Event.m_NetTime, 0x00, sizeof(Event.m_NetTime));
		Event.m_pArg = &Priority;
		Event.m_uiSize = sizeof(Priority);
		Ret = EplEventkPost(&Event);
	} else if ((pTxBuffer_p - EplDllkInstance_g.m_pTxBuffer) == EPL_DLLK_TXFRAME_NONEPL) {	// frame from generic priority FIFO sent
		// mark Tx-buffer as empty
		pTxBuffer_p->m_uiTxMsgLen = EPL_DLLK_BUFLEN_EMPTY;

		// post event to DLL
		Priority = kEplDllAsyncReqPrioGeneric;
		Event.m_EventSink = kEplEventSinkDllk;
		Event.m_EventType = kEplEventTypeDllkFillTx;
		EPL_MEMSET(&Event.m_NetTime, 0x00, sizeof(Event.m_NetTime));
		Event.m_pArg = &Priority;
		Event.m_uiSize = sizeof(Priority);
		Ret = EplEventkPost(&Event);
	}
#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0) \
    && (EPL_DLL_PRES_READY_AFTER_SOC == FALSE)) \
    || (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
	else if ((pTxBuffer_p->m_EplMsgType == kEplMsgTypePreq)
		 || (pTxBuffer_p->m_EplMsgType == kEplMsgTypePres)) {	// PRes resp. PReq frame sent

#if ((((EPL_MODULE_INTEGRATION) & (EPL_MODULE_PDOK)) != 0) \
            && (EPL_DLL_PRES_READY_AFTER_SOC == FALSE))
		{
			// inform PDO module
			FrameInfo.m_pFrame =
			    (tEplFrame *) pTxBuffer_p->m_pbBuffer;
			FrameInfo.m_uiFrameSize = pTxBuffer_p->m_uiMaxBufferLen;
			Ret = EplPdokCbPdoTransmitted(&FrameInfo);
		}
#endif

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
		{
			// if own Pres on MN, trigger SoA
			if ((NmtState >= kEplNmtMsPreOperational2)
			    && (pTxBuffer_p ==
				&EplDllkInstance_g.
				m_pTxBuffer[EPL_DLLK_TXFRAME_PRES])) {
				Ret =
				    EplDllkChangeState(kEplNmtEventDllMeSoaTrig,
						       NmtState);
			}
		}
#endif

#if EPL_DLL_PRES_READY_AFTER_SOA != FALSE
		goto Exit;
#endif
	}
#endif
#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)
	else if (pTxBuffer_p->m_EplMsgType == kEplMsgTypeSoa) {	// SoA frame sent
		tEplNmtEvent NmtEvent = kEplNmtEventDllMeSoaSent;

		// check if we are invited
		if (EplDllkInstance_g.m_uiLastTargetNodeId ==
		    EplDllkInstance_g.m_DllConfigParam.m_uiNodeId) {
			tEplFrame *pTxFrame;

			if (EplDllkInstance_g.m_LastReqServiceId == kEplDllReqServiceStatus) {	// StatusRequest
				if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_STATUSRES].m_pbBuffer != NULL) {	// StatusRes does exist

					pTxFrame =
					    (tEplFrame *) EplDllkInstance_g.
					    m_pTxBuffer
					    [EPL_DLLK_TXFRAME_STATUSRES].
					    m_pbBuffer;
					// update StatusRes frame (NMT state, EN, EC, RS, PR flags)
					AmiSetByteToLe(&pTxFrame->m_Data.m_Asnd.
						       m_Payload.
						       m_StatusResponse.
						       m_le_bNmtStatus,
						       (BYTE) NmtState);
					AmiSetByteToLe(&pTxFrame->m_Data.m_Asnd.
						       m_Payload.
						       m_StatusResponse.
						       m_le_bFlag1,
						       EplDllkInstance_g.
						       m_bFlag1);
					AmiSetByteToLe(&pTxFrame->m_Data.m_Asnd.
						       m_Payload.
						       m_StatusResponse.
						       m_le_bFlag2,
						       EplDllkInstance_g.
						       m_bFlag2);
					// send StatusRes
					Ret =
					    EdrvSendTxMsg(&EplDllkInstance_g.
							  m_pTxBuffer
							  [EPL_DLLK_TXFRAME_STATUSRES]);
					if (Ret != kEplSuccessful) {
						goto Exit;
					}
					TGT_DBG_SIGNAL_TRACE_POINT(8);

				}
			} else if (EplDllkInstance_g.m_LastReqServiceId == kEplDllReqServiceIdent) {	// IdentRequest
				if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_IDENTRES].m_pbBuffer != NULL) {	// IdentRes does exist
					pTxFrame =
					    (tEplFrame *) EplDllkInstance_g.
					    m_pTxBuffer
					    [EPL_DLLK_TXFRAME_IDENTRES].
					    m_pbBuffer;
					// update IdentRes frame (NMT state, RS, PR flags)
					AmiSetByteToLe(&pTxFrame->m_Data.m_Asnd.
						       m_Payload.
						       m_IdentResponse.
						       m_le_bNmtStatus,
						       (BYTE) NmtState);
					AmiSetByteToLe(&pTxFrame->m_Data.m_Asnd.
						       m_Payload.
						       m_IdentResponse.
						       m_le_bFlag2,
						       EplDllkInstance_g.
						       m_bFlag2);
					// send IdentRes
					Ret =
					    EdrvSendTxMsg(&EplDllkInstance_g.
							  m_pTxBuffer
							  [EPL_DLLK_TXFRAME_IDENTRES]);
					if (Ret != kEplSuccessful) {
						goto Exit;
					}
					TGT_DBG_SIGNAL_TRACE_POINT(7);
				}
			} else if (EplDllkInstance_g.m_LastReqServiceId == kEplDllReqServiceNmtRequest) {	// NmtRequest
				if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NMTREQ].m_pbBuffer != NULL) {	// NmtRequest does exist
					// check if frame is not empty and not being filled
					if (EplDllkInstance_g.
					    m_pTxBuffer
					    [EPL_DLLK_TXFRAME_NMTREQ].
					    m_uiTxMsgLen >
					    EPL_DLLK_BUFLEN_FILLING) {
						// check if this frame is a NMT command,
						// then forward this frame back to NmtMnu module,
						// because it needs the time, when this frame is
						// actually sent, to start the timer for monitoring
						// the NMT state change.

						pTxFrame =
						    (tEplFrame *)
						    EplDllkInstance_g.
						    m_pTxBuffer
						    [EPL_DLLK_TXFRAME_NMTREQ].
						    m_pbBuffer;
						if ((AmiGetByteFromLe
						     (&pTxFrame->
						      m_le_bMessageType)
						     == (BYTE) kEplMsgTypeAsnd)
						    &&
						    (AmiGetByteFromLe
						     (&pTxFrame->m_Data.m_Asnd.
						      m_le_bServiceId)
						     == (BYTE) kEplDllAsndNmtCommand)) {	// post event directly to NmtMnu module
							Event.m_EventSink =
							    kEplEventSinkNmtMnu;
							Event.m_EventType =
							    kEplEventTypeNmtMnuNmtCmdSent;
							Event.m_uiSize =
							    EplDllkInstance_g.
							    m_pTxBuffer
							    [EPL_DLLK_TXFRAME_NMTREQ].
							    m_uiTxMsgLen;
							Event.m_pArg = pTxFrame;
							Ret =
							    EplEventkPost
							    (&Event);

						}
						// send NmtRequest
						Ret =
						    EdrvSendTxMsg
						    (&EplDllkInstance_g.
						     m_pTxBuffer
						     [EPL_DLLK_TXFRAME_NMTREQ]);
						if (Ret != kEplSuccessful) {
							goto Exit;
						}

					}
				}

			} else if (EplDllkInstance_g.m_LastReqServiceId == kEplDllReqServiceUnspecified) {	// unspecified invite
				if (EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_NONEPL].m_pbBuffer != NULL) {	// non-EPL frame does exist
					// check if frame is not empty and not being filled
					if (EplDllkInstance_g.
					    m_pTxBuffer
					    [EPL_DLLK_TXFRAME_NONEPL].
					    m_uiTxMsgLen >
					    EPL_DLLK_BUFLEN_FILLING) {
						// send non-EPL frame
						Ret =
						    EdrvSendTxMsg
						    (&EplDllkInstance_g.
						     m_pTxBuffer
						     [EPL_DLLK_TXFRAME_NONEPL]);
						if (Ret != kEplSuccessful) {
							goto Exit;
						}

					}
				}
			}
			// ASnd frame was sent, remove the request
			EplDllkInstance_g.m_LastReqServiceId =
			    kEplDllReqServiceNo;
		}
		// forward event to ErrorHandler and PDO module
		Event.m_EventSink = kEplEventSinkNmtk;
		Event.m_EventType = kEplEventTypeNmtEvent;
		Event.m_uiSize = sizeof(NmtEvent);
		Event.m_pArg = &NmtEvent;
		Ret = EplEventkPost(&Event);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}
	}
#endif

#if EPL_DLL_PRES_READY_AFTER_SOA != FALSE
	else {			// d.k.: Why that else? on CN it is entered on IdentRes and StatusRes
		goto Exit;
	}

	// signal process function readiness of PRes frame
	Event.m_EventSink = kEplEventSinkDllk;
	Event.m_EventType = kEplEventTypeDllkPresReady;
	Event.m_uiSize = 0;
	Event.m_pArg = NULL;
	Ret = EplEventkPost(&Event);

#endif

      Exit:
	if (Ret != kEplSuccessful) {
		DWORD dwArg;

		BENCHMARK_MOD_02_TOGGLE(9);

		dwArg =
		    EplDllkInstance_g.m_DllState | (pTxBuffer_p->
						    m_EplMsgType << 16);

		// Error event for API layer
		Ret = EplEventkPostError(kEplEventSourceDllk,
					 Ret, sizeof(dwArg), &dwArg);
	}

	return;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkCheckFrame()
//
// Description: check frame and set missing information
//
// Parameters:  pFrame_p                = ethernet frame
//              uiFrameSize_p           = size of frame
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplDllkCheckFrame(tEplFrame * pFrame_p,
				    unsigned int uiFrameSize_p)
{
	tEplMsgType MsgType;
	WORD wEtherType;

	// check frame
	if (pFrame_p != NULL) {
		// check SrcMAC
		if (AmiGetQword48FromBe(pFrame_p->m_be_abSrcMac) == 0) {
			// source MAC address
			EPL_MEMCPY(&pFrame_p->m_be_abSrcMac[0],
				   &EplDllkInstance_g.m_be_abSrcMac[0], 6);
		}
		// check ethertype
		wEtherType = AmiGetWordFromBe(&pFrame_p->m_be_wEtherType);
		if (wEtherType == 0) {
			// assume EPL frame
			wEtherType = EPL_C_DLL_ETHERTYPE_EPL;
			AmiSetWordToBe(&pFrame_p->m_be_wEtherType, wEtherType);
		}

		if (wEtherType == EPL_C_DLL_ETHERTYPE_EPL) {
			// source node ID
			AmiSetByteToLe(&pFrame_p->m_le_bSrcNodeId,
				       (BYTE) EplDllkInstance_g.
				       m_DllConfigParam.m_uiNodeId);

			// check message type
			MsgType =
			    AmiGetByteFromLe(&pFrame_p->m_le_bMessageType);
			if (MsgType == 0) {
				MsgType = kEplMsgTypeAsnd;
				AmiSetByteToLe(&pFrame_p->m_le_bMessageType,
					       (BYTE) MsgType);
			}

			if (MsgType == kEplMsgTypeAsnd) {
				// destination MAC address
				AmiSetQword48ToBe(&pFrame_p->m_be_abDstMac[0],
						  EPL_C_DLL_MULTICAST_ASND);
			}

		}
	}

	return kEplSuccessful;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkCbCnTimer()
//
// Description: called by timer module. It monitors the EPL cycle when it is a CN.
//
// Parameters:  pEventArg_p             = timer event argument
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

#if EPL_TIMER_USE_HIGHRES != FALSE
static tEplKernel PUBLIC EplDllkCbCnTimer(tEplTimerEventArg * pEventArg_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplNmtState NmtState;

#if EPL_TIMER_USE_HIGHRES != FALSE
	if (pEventArg_p->m_TimerHdl != EplDllkInstance_g.m_TimerHdlCycle) {	// zombie callback
		// just exit
		goto Exit;
	}
#endif

	NmtState = EplNmtkGetNmtState();

	if (NmtState <= kEplNmtGsResetConfiguration) {
		goto Exit;
	}

	Ret = EplDllkChangeState(kEplNmtEventDllCeFrameTimeout, NmtState);
	if (Ret != kEplSuccessful) {
		goto Exit;
	}
	// 2008/10/15 d.k. reprogramming of timer not necessary,
	// because it will be programmed, when SoC is received.
/*
    // reprogram timer
#if EPL_TIMER_USE_HIGHRES != FALSE
    if ((NmtState > kEplNmtCsPreOperational1)
        && (EplDllkInstance_g.m_ullFrameTimeout != 0))
    {
        Ret = EplTimerHighReskModifyTimerNs(&EplDllkInstance_g.m_TimerHdlCycle, EplDllkInstance_g.m_ullFrameTimeout, EplDllkCbCnTimer, 0L, FALSE);
    }
#endif
*/

      Exit:
	if (Ret != kEplSuccessful) {
		DWORD dwArg;

		BENCHMARK_MOD_02_TOGGLE(9);

		dwArg =
		    EplDllkInstance_g.
		    m_DllState | (kEplNmtEventDllCeFrameTimeout << 8);

		// Error event for API layer
		Ret = EplEventkPostError(kEplEventSourceDllk,
					 Ret, sizeof(dwArg), &dwArg);
	}

	return Ret;
}
#endif

#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)

//---------------------------------------------------------------------------
//
// Function:    EplDllkCbMnTimerCycle()
//
// Description: called by timer module. It triggers the SoC when it is a MN.
//
// Parameters:  pEventArg_p             = timer event argument
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel PUBLIC EplDllkCbMnTimerCycle(tEplTimerEventArg * pEventArg_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplNmtState NmtState;

#if EPL_TIMER_USE_HIGHRES != FALSE
	if (pEventArg_p->m_TimerHdl != EplDllkInstance_g.m_TimerHdlCycle) {	// zombie callback
		// just exit
		goto Exit;
	}
#endif

	NmtState = EplNmtkGetNmtState();

	if (NmtState <= kEplNmtGsResetConfiguration) {
		goto Exit;
	}

	Ret = EplDllkChangeState(kEplNmtEventDllMeSocTrig, NmtState);

      Exit:
	if (Ret != kEplSuccessful) {
		DWORD dwArg;

		BENCHMARK_MOD_02_TOGGLE(9);

		dwArg =
		    EplDllkInstance_g.
		    m_DllState | (kEplNmtEventDllMeSocTrig << 8);

		// Error event for API layer
		Ret = EplEventkPostError(kEplEventSourceDllk,
					 Ret, sizeof(dwArg), &dwArg);
	}

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkCbMnTimerResponse()
//
// Description: called by timer module. It monitors the PRes timeout.
//
// Parameters:  pEventArg_p             = timer event argument
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel PUBLIC EplDllkCbMnTimerResponse(tEplTimerEventArg *
						  pEventArg_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEplNmtState NmtState;

#if EPL_TIMER_USE_HIGHRES != FALSE
	if (pEventArg_p->m_TimerHdl != EplDllkInstance_g.m_TimerHdlResponse) {	// zombie callback
		// just exit
		goto Exit;
	}
#endif

	NmtState = EplNmtkGetNmtState();

	if (NmtState <= kEplNmtGsResetConfiguration) {
		goto Exit;
	}

	Ret = EplDllkChangeState(kEplNmtEventDllMePresTimeout, NmtState);

      Exit:
	if (Ret != kEplSuccessful) {
		DWORD dwArg;

		BENCHMARK_MOD_02_TOGGLE(9);

		dwArg =
		    EplDllkInstance_g.
		    m_DllState | (kEplNmtEventDllMePresTimeout << 8);

		// Error event for API layer
		Ret = EplEventkPostError(kEplEventSourceDllk,
					 Ret, sizeof(dwArg), &dwArg);
	}

	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkGetNodeInfo()
//
// Description: returns node info structure of the specified node.
//
// Parameters:  uiNodeId_p              = node ID
//
// Returns:     tEplDllkNodeInfo*       = pointer to internal node info structure
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplDllkNodeInfo *EplDllkGetNodeInfo(unsigned int uiNodeId_p)
{
	// $$$ d.k.: use hash algorithm to retrieve the appropriate node info structure
	//           if size of array is less than 254.
	uiNodeId_p--;		// node ID starts at 1 but array at 0
	if (uiNodeId_p >= tabentries(EplDllkInstance_g.m_aNodeInfo)) {
		return NULL;
	} else {
		return &EplDllkInstance_g.m_aNodeInfo[uiNodeId_p];
	}
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkMnSendSoa()
//
// Description: it updates and transmits the SoA.
//
// Parameters:  NmtState_p              = current NMT state
//              pDllStateProposed_p     = proposed DLL state
//              fEnableInvitation_p     = enable invitation for asynchronous phase
//                                        it will be disabled for EPL_C_DLL_PREOP1_START_CYCLES SoAs
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplDllkMnSendSoa(tEplNmtState NmtState_p,
				   tEplDllState * pDllStateProposed_p,
				   BOOL fEnableInvitation_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEdrvTxBuffer *pTxBuffer = NULL;
	tEplFrame *pTxFrame;
	tEplDllkNodeInfo *pNodeInfo;

	*pDllStateProposed_p = kEplDllMsNonCyclic;

	pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_SOA];
	if (pTxBuffer->m_pbBuffer != NULL) {	// SoA does exist
		pTxFrame = (tEplFrame *) pTxBuffer->m_pbBuffer;

		if (fEnableInvitation_p != FALSE) {	// fetch target of asynchronous phase
			if (EplDllkInstance_g.m_bFlag2 == 0) {	// own queues are empty
				EplDllkInstance_g.m_LastReqServiceId =
				    kEplDllReqServiceNo;
			} else if (((tEplDllAsyncReqPriority) (EplDllkInstance_g.m_bFlag2 >> EPL_FRAME_FLAG2_PR_SHIFT)) == kEplDllAsyncReqPrioNmt) {	// frames in own NMT request queue available
				EplDllkInstance_g.m_LastReqServiceId =
				    kEplDllReqServiceNmtRequest;
			} else {
				EplDllkInstance_g.m_LastReqServiceId =
				    kEplDllReqServiceUnspecified;
			}
			Ret =
			    EplDllkCalAsyncGetSoaRequest(&EplDllkInstance_g.
							 m_LastReqServiceId,
							 &EplDllkInstance_g.
							 m_uiLastTargetNodeId);
			if (Ret != kEplSuccessful) {
				goto Exit;
			}
			if (EplDllkInstance_g.m_LastReqServiceId != kEplDllReqServiceNo) {	// asynchronous phase will be assigned to one node
				if (EplDllkInstance_g.m_uiLastTargetNodeId == EPL_C_ADR_INVALID) {	// exchange invalid node ID with local node ID
					EplDllkInstance_g.m_uiLastTargetNodeId =
					    EplDllkInstance_g.m_DllConfigParam.
					    m_uiNodeId;
					// d.k. DLL state WaitAsndTrig is not helpful;
					//      so just step over to WaitSocTrig,
					//      because own ASnd is sent automatically in CbFrameTransmitted() after SoA.
					//*pDllStateProposed_p = kEplDllMsWaitAsndTrig;
					*pDllStateProposed_p =
					    kEplDllMsWaitSocTrig;
				} else {	// assignment to CN
					*pDllStateProposed_p =
					    kEplDllMsWaitAsnd;
				}

				pNodeInfo =
				    EplDllkGetNodeInfo(EplDllkInstance_g.
						       m_uiLastTargetNodeId);
				if (pNodeInfo == NULL) {	// no node info structure available
					Ret = kEplDllNoNodeInfo;
					goto Exit;
				}
				// update frame (EA, ER flags)
				AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.
					       m_le_bFlag1,
					       pNodeInfo->
					       m_bSoaFlag1 & (EPL_FRAME_FLAG1_EA
							      |
							      EPL_FRAME_FLAG1_ER));
			} else {	// no assignment of asynchronous phase
				*pDllStateProposed_p = kEplDllMsWaitSocTrig;
				EplDllkInstance_g.m_uiLastTargetNodeId =
				    EPL_C_ADR_INVALID;
			}

			// update frame (target)
			AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.
				       m_le_bReqServiceId,
				       (BYTE) EplDllkInstance_g.
				       m_LastReqServiceId);
			AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.
				       m_le_bReqServiceTarget,
				       (BYTE) EplDllkInstance_g.
				       m_uiLastTargetNodeId);

		} else {	// invite nobody
			// update frame (target)
			AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.
				       m_le_bReqServiceId, (BYTE) 0);
			AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.
				       m_le_bReqServiceTarget, (BYTE) 0);
		}

		// update frame (NMT state)
		AmiSetByteToLe(&pTxFrame->m_Data.m_Soa.m_le_bNmtStatus,
			       (BYTE) NmtState_p);

		// send SoA frame
		Ret = EdrvSendTxMsg(pTxBuffer);
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkMnSendSoc()
//
// Description: it updates and transmits the SoA.
//
// Parameters:  (none)
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplDllkMnSendSoc(void)
{
	tEplKernel Ret = kEplSuccessful;
	tEdrvTxBuffer *pTxBuffer = NULL;
	tEplFrame *pTxFrame;
	tEplEvent Event;

	pTxBuffer = &EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_SOC];
	if (pTxBuffer->m_pbBuffer != NULL) {	// SoC does exist
		pTxFrame = (tEplFrame *) pTxBuffer->m_pbBuffer;

		// $$$ update NetTime

		// send SoC frame
		Ret = EdrvSendTxMsg(pTxBuffer);
		if (Ret != kEplSuccessful) {
			goto Exit;
		}
		// trigger synchronous task
		Event.m_EventSink = kEplEventSinkSync;
		Event.m_EventType = kEplEventTypeSync;
		Event.m_uiSize = 0;
		Ret = EplEventkPost(&Event);
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkMnSendPreq()
//
// Description: it updates and transmits the PReq for the next isochronous CN
//              or own PRes if enabled.
//
// Parameters:  NmtState_p              = current NMT state
//              pDllStateProposed_p     = proposed DLL state
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplDllkMnSendPreq(tEplNmtState NmtState_p,
				    tEplDllState * pDllStateProposed_p)
{
	tEplKernel Ret = kEplSuccessful;
	tEdrvTxBuffer *pTxBuffer = NULL;
	tEplFrame *pTxFrame;
	BYTE bFlag1 = 0;

	if (EplDllkInstance_g.m_pCurNodeInfo == NULL) {	// start with first isochronous CN
		EplDllkInstance_g.m_pCurNodeInfo =
		    EplDllkInstance_g.m_pFirstNodeInfo;
	} else {		// iterate to next isochronous CN
		EplDllkInstance_g.m_pCurNodeInfo =
		    EplDllkInstance_g.m_pCurNodeInfo->m_pNextNodeInfo;
	}

	if (EplDllkInstance_g.m_pCurNodeInfo == NULL) {	// last isochronous CN reached
		Ret = EplDllkMnSendSoa(NmtState_p, pDllStateProposed_p, TRUE);
		goto Exit;
	} else {
		pTxBuffer = EplDllkInstance_g.m_pCurNodeInfo->m_pPreqTxBuffer;
		bFlag1 =
		    EplDllkInstance_g.m_pCurNodeInfo->
		    m_bSoaFlag1 & EPL_FRAME_FLAG1_EA;
		*pDllStateProposed_p = kEplDllMsWaitPres;

		// start PRes Timer
		// $$$ d.k.: maybe move this call to CbFrameTransmitted(), because the time should run from there
#if EPL_TIMER_USE_HIGHRES != FALSE
		Ret =
		    EplTimerHighReskModifyTimerNs(&EplDllkInstance_g.
						  m_TimerHdlResponse,
						  EplDllkInstance_g.
						  m_pCurNodeInfo->
						  m_dwPresTimeout,
						  EplDllkCbMnTimerResponse, 0L,
						  FALSE);
#endif
	}

	if (pTxBuffer == NULL) {	// PReq does not exist
		Ret = kEplDllTxBufNotReady;
		goto Exit;
	}

	pTxFrame = (tEplFrame *) pTxBuffer->m_pbBuffer;

	if (pTxFrame != NULL) {	// PReq does exist
		if (NmtState_p == kEplNmtMsOperational) {	// leave RD flag untouched
			bFlag1 |=
			    AmiGetByteFromLe(&pTxFrame->m_Data.m_Preq.
					     m_le_bFlag1) & EPL_FRAME_FLAG1_RD;
		}

		if (pTxBuffer == &EplDllkInstance_g.m_pTxBuffer[EPL_DLLK_TXFRAME_PRES]) {	// PRes of MN will be sent
			// update NMT state
			AmiSetByteToLe(&pTxFrame->m_Data.m_Pres.m_le_bNmtStatus,
				       (BYTE) NmtState_p);
			*pDllStateProposed_p = kEplDllMsWaitSoaTrig;
		}
		// $$$ d.k. set EPL_FRAME_FLAG1_MS if necessary
		// update frame (Flag1)
		AmiSetByteToLe(&pTxFrame->m_Data.m_Preq.m_le_bFlag1, bFlag1);

		// calculate frame size from payload size
		pTxBuffer->m_uiTxMsgLen =
		    AmiGetWordFromLe(&pTxFrame->m_Data.m_Preq.m_le_wSize) + 24;

		// send PReq frame
		Ret = EdrvSendTxMsg(pTxBuffer);
	} else {
		Ret = kEplDllTxFrameInvalid;
	}

      Exit:
	return Ret;
}

//---------------------------------------------------------------------------
//
// Function:    EplDllkAsyncFrameNotReceived()
//
// Description: passes empty ASnd frame to receive FIFO.
//              It will be called only for frames with registered AsndServiceIds
//              (only kEplDllAsndFilterAny).
//
// Parameters:  none
//
// Returns:     tEplKernel              = error code
//
//
// State:
//
//---------------------------------------------------------------------------

static tEplKernel EplDllkAsyncFrameNotReceived(tEplDllReqServiceId
					       ReqServiceId_p,
					       unsigned int uiNodeId_p)
{
	tEplKernel Ret = kEplSuccessful;
	BYTE abBuffer[18];
	tEplFrame *pFrame = (tEplFrame *) abBuffer;
	tEplFrameInfo FrameInfo;

	// check if previous SoA invitation was not answered
	switch (ReqServiceId_p) {
	case kEplDllReqServiceIdent:
	case kEplDllReqServiceStatus:
		// ASnd service registered?
		if (EplDllkInstance_g.m_aAsndFilter[ReqServiceId_p] == kEplDllAsndFilterAny) {	// ASnd service ID is registered
			AmiSetByteToLe(&pFrame->m_le_bSrcNodeId,
				       (BYTE) uiNodeId_p);
			// EPL MsgType ASnd
			AmiSetByteToLe(&pFrame->m_le_bMessageType,
				       (BYTE) kEplMsgTypeAsnd);
			// ASnd Service ID
			AmiSetByteToLe(&pFrame->m_Data.m_Asnd.m_le_bServiceId,
				       (BYTE) ReqServiceId_p);
			// create frame info structure
			FrameInfo.m_pFrame = pFrame;
			FrameInfo.m_uiFrameSize = 18;	// empty non existing ASnd frame
			// forward frame via async receive FIFO to userspace
			Ret = EplDllkCalAsyncFrameReceived(&FrameInfo);
		}
		break;
	default:
		// no invitation issued or it was successfully answered or it is uninteresting
		break;
	}

	return Ret;
}

#endif //(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_NMT_MN)) != 0)

#endif // #if(((EPL_MODULE_INTEGRATION) & (EPL_MODULE_DLLK)) != 0)
// EOF