summaryrefslogtreecommitdiff
path: root/mbglib/common/gpsdefs.h
blob: c22c137eb4f4e0a6c1bea2694dab84b0a6c59062 (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
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684

/**************************************************************************
 *
 *  $Id: gpsdefs.h 1.124.1.310 2017/04/11 10:30:14 philipp TEST $
 *
 *  Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
 *
 *  Description:
 *    General definitions to be used with Meinberg clocks.
 *    These definitions have initially be used with GPS devices only.
 *    However, more and more Meinberg non-GPS devices also use some of
 *    these definitions.
 *
 * -----------------------------------------------------------------------
 *  $Log: gpsdefs.h $
 *  Revision 1.124.1.310  2017/04/11 10:30:14  philipp
 *  Added USB lock swap macros
 *  Revision 1.124.1.309  2017/04/11 06:42:41  philipp
 *  Renamed MBG_USB_INTR structures to MBG_USB_LOCK
 *  Revision 1.124.1.308  2017/04/11 06:22:29  philipp
 *  Put MBG_USB_INTR_SETTINGS into MBG_USB_INTR_INFO
 *  Revision 1.124.1.307  2017/04/11 05:29:56  philipp
 *  Added commands, structures and defines for feature USB interrupt
 *  Revision 1.124.1.306  2017/04/04 10:57:27  paul.kretz
 *  Added FDM180M and associated definitions
 *  Revision 1.124.1.305  2017/04/04 09:06:40Z  philipp
 *  Added general monitoring and event transactions
 *  Revision 1.124.1.304  2017/04/04 06:20:49  andre.hartmann
 *  xfeature for xhe unit added
 *  Revision 1.124.1.303  2017/03/28 09:38:45Z  paul.kretz
 *  added support for MircoSync power supply module
 *  Revision 1.124.1.302  2017/03/27 10:38:13Z  thomas-b
 *  Renamed PTPv1 common datasets, added swab macros, feature flag and comments
 *  Revision 1.124.1.301  2017/03/24 10:18:56  paul.kretz
 *  removed ENABLE_FLAGS in BUILTIN_FEAT_VSG180
 *  Revision 1.124.1.300  2017/03/23 08:55:57Z  thomas-b
 *  Fixed wrong documentation for MBG_IO_PORT_STATUS_BUFFER
 *  Revision 1.124.1.299  2017/03/22 09:46:28  thomas-b
 *  Added transaction for IO ports
 *  Revision 1.124.1.298  2017/03/22 08:54:45  thomas-b
 *  Fixed string initializer for POUT IO port type
 *  Revision 1.124.1.297  2017/03/22 08:28:21  philipp
 *  Added MBG_IO_PORT_OP_MODE_NONE to enum MBG_IO_PORT_OP_MODE_BITS
 *  Revision 1.124.1.296  2017/03/21 13:32:55  thomas-b
 *  Added relation string variable to MBG_IO_PORT_INFO structure
 *  Revision 1.124.1.295  2017/03/21 08:46:46  thomas-b
 *  Added support for physical and logical IO port groups
 *  Revision 1.124.1.294  2017/03/20 17:10:23  martin
 *  Fixed and added lots of swab..() macros.
 *  Revision 1.124.1.293  2017/03/20 10:10:02  martin
 *  Fixed build without _PRELIMINARY_CODE.
 *  Revision 1.124.1.292  2017/03/17 11:59:47  thomas-b
 *  Added directio in/out and io port positions
 *  Revision 1.124.1.291  2017/03/16 07:47:51  thomas-b
 *  Added several missing IO port conn types
 *  Added new IO port type prog. pulse and appropriate structures
 *  Revision 1.124.1.290  2017/03/15 09:08:12  philipp
 *  Added I/O port types
 *  Revision 1.124.1.289  2017/03/15 09:00:49  gregoire
 *  str initializer for NTP_SYMM_KEY_HASHES added
 *  Revision 1.124.1.288  2017/03/15 06:46:24  thomas-b
 *  Shortened string defines for IO port OP modes
 *  Revision 1.124.1.287  2017/03/14 13:44:41  philipp
 *  Added size initializer for new I/O port type ethernet
 *  Revision 1.124.1.286  2017/03/14 08:55:17  thomas-b
 *  Added IO port type for network
 *  Reworked event info structure
 *  Revision 1.124.1.285  2017/03/13 11:42:13  gregoire.diehl
 *  New PTP preset DOCSIS 3.1 added
 *  Revision 1.124.1.284  2017/03/10 10:36:41Z  paul.kretz
 *  extended MBG_GPIO_VIDEO_TC_MODES enum
 *  Revision 1.124.1.283  2017/03/10 09:03:22Z  philipp
 *  Added event_cfg_counter to MBG_MONITORING_STATUS
 *  Revision 1.124.1.282  2017/03/10 07:23:52  thomas-b
 *  Added define for invalid event sub_idx
 *  Revision 1.124.1.281  2017/03/08 12:44:25  thomas-b
 *  Added mask MBG_TRANSACTION_MSK_SET
 *  Revision 1.124.1.280  2017/03/08 12:35:44  thomas-b
 *  Added macros for transaction type set
 *  Revision 1.124.1.279  2017/03/08 11:42:41  paul.kretz
 *  bugfix in MBG_GPIO_VIDEO_TC_MODE_MASKS
 *  Revision 1.124.1.278  2017/03/07 13:56:35Z  paul.kretz
 *  extended GPIO structs for time code support
 *  Revision 1.124.1.277  2017/03/07 13:46:12Z  thomas-b
 *  Removed builtin feature for ignore lock
 *  Revision 1.124.1.276  2017/03/07 09:08:43  thomas-b
 *  *** empty log message ***
 *  Revision 1.124.1.275  2017/03/07 08:11:01  thomas-b
 *  Added global feature flag for bonding
 *  Revision 1.124.1.274  2017/03/03 07:26:53  thomas-b
 *  Renamed NTP transaction
 *  Revision 1.124.1.273  2017/03/03 06:42:39  thomas-b
 *  Relocated NTP_GLB_INFO, fixed several swab macros of new NTP structures
 *  Revision 1.124.1.272  2017/03/02 14:02:25  gregoire
 *  NTP related structures reworked
 *  MBG_TRANSACTION_TYPE_MONITORING_NTP added
 *  Revision 1.124.1.271  2017/03/01 10:44:26  philipp
 *  Use _PRELIMINARY_CODE macro instead of debug macro
 *  Revision 1.124.1.270  2017/02/28 15:31:08  gregoire
 *  NTP_GLB_INFO: field max_trusted_keys added
 *  NTP_CLNT_MODE_SETTINGS: field num_peers added
 *  NTP_SRV_MODE_SETTINGS: field num_refclks added
 *  NTP_SRV_MODE_INFO: field max_refclks added
 *  Revision 1.124.1.269  2017/02/27 09:20:34  thomas-b
 *  Fixed typo in GNSS_SV_STAT_QUALITY_INDS
 *  Revision 1.124.1.268  2017/02/27 07:44:30  thomas-b
 *  Changed builtin features for GNS181_UC from preset GPS to preset GNSS
 *  Revision 1.124.1.267  2017/02/24 11:00:55  philipp
 *  Moved event type from settings to info
 *  Revision 1.124.1.266  2017/02/24 09:38:25  philipp
 *  Do not use fixed buffers for monitorung event info and status
 *  Revision 1.124.1.265  2017/02/22 12:21:45  thomas-b
 *  Added string initializers for event types and severities
 *  Revision 1.124.1.264  2017/02/22 07:53:35  thomas-b
 *  Added swab macros for monitoring event and status structures
 *  Revision 1.124.1.263  2017/02/21 15:53:47  philipp
 *  Added monitoring event and status structures and defines
 *  Revision 1.124.1.262  2017/02/16 13:00:57  thomas-b
 *  Added MBG_PTP_V2_PORT_DATASET_IDX structure and removed MBG_PTP_V2_COMMON_DATASETS
 *  Revision 1.124.1.261  2017/02/16 09:01:31  martin
 *  New field MBG_GNSS_MODE_INFO::n_sv_status.
 *  Revision 1.124.1.260  2017/02/16 08:13:00  thomas-b
 *  Added structures and supp. flag for PTPv2 common datasets defined in IEEE1588-2008, chapter 8.2
 *  Revision 1.124.1.259  2017/02/15 16:14:47  martin
 *  New GNSS type QZSS.
 *  Renamed GNSS_SV_INFO to GNSS_SV_STATUS.
 *  New flag MBG_GNSS_FLAG_MSK_HAS_SV_STATUS.
 *  Revision 1.124.1.258  2017/02/13 08:32:12  philipp
 *  Fixed GNSS swap macro redefinitions
 *  Revision 1.124.1.257  2017/02/13 08:26:53  philipp
 *  Fixed some typos in SNMP structures
 *  Revision 1.124.1.256  2017/02/10 15:21:11  martin
 *  Added swab macros for new structures.
 *  Revision 1.124.1.255  2017/02/10 14:26:22  martin
 *  New extended feature MBG_XFEATURE_GNSS_SV_INFO
 *  and associated structures.
 *  Revision 1.124.1.254  2017/02/08 13:33:42  philipp
 *  Removed redundant information MBG_SNMP_V12_TRAP_SETTINGS
 *  Revision 1.124.1.253  2017/02/08 12:49:30  thomas-b
 *  Changed all int8_t to char in SNMP structs, fixed typo and added some documentation
 *  Revision 1.124.1.252  2017/02/08 07:04:53  philipp
 *  Added swaP macros for SNMP monitoring structures
 *  Revision 1.124.1.251  2017/02/07 11:46:19  philipp
 *  Fixed duplicate members
 *  Revision 1.124.1.250  2017/02/07 11:39:42  philipp
 *  Added destination port for SNMP trap receivers
 *  Revision 1.124.1.249  2017/02/07 11:34:46  daniel
 *  *** empty log message ***
 *  Revision 1.124.1.248  2017/02/07 10:15:19  daniel
 *  Removed unneccessary xfeature LICENSE_LIMITS
 *  Revision 1.124.1.247  2017/02/06 13:10:25  philipp
 *  Added SNMP monitoring structures and defines
 *  Revision 1.124.1.246  2017/02/06 10:47:49  philipp
 *  Added monitoring XFeature skeleton
 *  Revision 1.124.1.245  2017/02/06 08:57:58  daniel
 *  Added XFEATURE for License Limits
 *  Revision 1.124.1.244  2017/02/01 09:45:25  daniel
 *  Added new TLV License types for PTPv1 and Time Monitor
 *  Revision 1.124.1.243  2017/02/01 09:35:38  martin
 *  Defined DEFAULT_POUT_PULSE_SHIFT_MIN and
 *  DEFAULT_POUT_PULSE_SHIFT_MAX.
 *  Revision 1.124.1.242  2017/01/27 10:24:11  philipp
 *  Fixed missing while in macro
 *  Revision 1.124.1.241  2017/01/27 09:13:15  martin
 *  Fixed macro syntax.
 *  Revision 1.124.1.240  2017/01/26 15:24:36  martin
 *  Support new model RSC180RDU.
 *  Revision 1.124.1.239  2017/01/26 15:13:57  martin
 *  Fixed some macros.
 *  Revision 1.124.1.238  2017/01/25 14:34:12  martin
 *  Added definition POUT_MODES_SUPP_TIMEBASE_UTC.
 *  Updated comments for POUT_SETTINGS_FLAG_BITS.
 *  Revision 1.124.1.237  2017/01/25 13:10:38  martin
 *  Added POUT bit masks definitions indicating which parameter fields
 *  are relevant for which POUT modes.
 *  Fixed macros _mbg_swab_pout_settings_on_get() and
 *  _mbg_swab_pout_settings_on_set().
 *  Updated comments, and fixed some typos in comments.
 *  Revision 1.124.1.236  2017/01/24 14:15:44  daniel
 *  Started to define structures for PTPv1 datasets
 *  Revision 1.124.1.235  2017/01/10 16:17:11  daniel
 *  Added PTPv1 roles
 *  Revision 1.124.1.234  2017/01/06 15:53:20  martin
 *  More POUT pulse shift support.
 *  Revision 1.124.1.233  2017/01/05 14:16:35  martin
 *  Added missing definitions for PSX_4GE.
 *  Revision 1.124.1.232  2017/01/02 10:43:39  andre.hartmann
 *  Added model code for PSX_4GE board.
 *  Revision 1.124.1.231  2016/12/22 11:21:32Z  philipp
 *  Added NTP and PTP hardware timestamping flags to MBG_NET_INTF_LINK_OPTS
 *  Revision 1.124.1.230  2016/12/22 10:19:21  martin
 *  Doxygen fix.
 *  Revision 1.124.1.229  2016/12/21 09:15:23  martin
 *  Added GPS_MODEL_HAS_SV_INFO to the BUILTIN_FEAT_GPS mask.
 *  Support new model GNS180_UC.
 *  Revision 1.124.1.228  2016/12/08 11:44:17  paul.kretz
 *  Updated masks for SCU_STAT_INFO
 *  Revision 1.124.1.227  2016/12/07 14:44:44Z  paul.kretz
 *  Added new masks for SCU_STAT_INFO to support up to 4 power supplies
 *  Revision 1.124.1.226  2016/12/07 09:34:40Z  martin
 *  Removed trailing spaces.
 *  Revision 1.124.1.225  2016/12/06 14:50:15  andre.hartmann
 *  Added model code for GPS165
 *  Revision 1.124.1.224  2016/12/06 09:15:58Z  thomas-b
 *  Added builtin feature HAS_SV_INFO for all GPS (only) receivers
 *  Revision 1.124.1.223  2016/12/01 11:20:08  philipp
 *  Fixed MBG_IO_PORT_INFO_MIN_SIZE
 *  Revision 1.124.1.222  2016/11/30 11:25:07  thomas-b
 *  Added builtin feature for SCU_STAT and added it to RSC180 and MDU180
 *  Revision 1.124.1.221  2016/11/29 14:07:00  philipp
 *  Added MBG_IO_PORT_INFO_IDX_SIZES
 *  Revision 1.124.1.220  2016/11/25 11:32:15  philipp
 *  Finalized I/O port structures, enums, defines
 *  Revision 1.124.1.219  2016/11/24 07:06:34  philipp
 *  Honour big endian system when swapping bytes
 *  Revision 1.124.1.218  2016/11/23 12:41:12  philipp
 *  Fixed GPIO swap macro typos
 *  Revision 1.124.1.217  2016/11/23 09:36:30  paul.kretz
 *  added swab macros for GPIO's
 *  extended MBG_IO_PORT structs
 *  removed unused preprocessor symbol in FPGA_INFO struct
 *  Revision 1.124.1.216  2016/11/22 10:33:16Z  philipp
 *  Implemented I/O ports
 *  Revision 1.124.1.215  2016/11/21 12:22:44  thomas-b
 *  Added enable flags as builtin feature for FDM180
 *  Revision 1.124.1.214  2016/11/16 11:00:36  thomas-b
 *  Added core module type and revision to MBG_EXT_SYS_INFO
 *  Revision 1.124.1.213  2016/11/10 14:08:17  thomas-b
 *  Changed string name for GPS_MODEL_NAME_UNKNOWN
 *  Revision 1.124.1.212  2016/11/08 17:22:11  martin
 *  Doxygen fixes.
 *  Revision 1.124.1.211  2016/11/04 11:48:35  paul.kretz
 *  Support MDU312.
 *  Revision 1.124.1.210  2016/11/04 07:21:26Z  thomas-b
 *  Added flag, mask, and idx for GPIO, which indicates that a GPIO configuration depends on another GPIO
 *  Revision 1.124.1.209  2016/11/02 11:54:57  paul.kretz
 *  added new xfeature MBG_XFEATURE_REQ_TTM
 *  Revision 1.124.1.208  2016/11/01 09:27:49Z  thomas-b
 *  Added builtin feature for TZDL to FDM180
 *  Revision 1.124.1.207  2016/11/01 09:24:12  martin
 *  *** empty log message ***
 *  Revision 1.124.1.206  2016/10/25 13:24:37  martin
 *  *** empty log message ***
 *  Revision 1.124.1.205  2016/10/25 08:56:40  martin
 *  Renamed MSK_ICODE_RX_HAS_SHORT_YEAR to MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P5.
 *  New MSK_ICODE_RX_HAS_ANY_SHORT_YEAR which includes
 *  all codes providing a year number, either after P5 or after P6.
 *  Doxygen fixes.
 *  Changes to builtin feature definitions.
 *  Revision 1.124.1.204  2016/10/24 08:12:04  martin
 *  Support MDU180.
 *  Revision 1.124.1.203  2016/10/20 10:43:20  thomas-b
 *  Added builtin feature GPS_MODEL_IS_BUS_LVL_DEV
 *  Revision 1.124.1.202  2016/10/19 10:19:59  thomas-b
 *  Added define for default user capture network UDP port
 *  Revision 1.124.1.201  2016/10/19 09:07:28  thomas-b
 *  Added supported flags for MBG_UCAP_NET_GLB_INFO
 *  Revision 1.124.1.200  2016/10/13 07:30:10  paul.kretz
 *  Extended sysinfo proc and fpga types by SAM3s, STM32F4, Cyclone4GX15 and Cyclone4CE22
 *  Revision 1.124.1.199  2016/10/10 10:36:35Z  thomas-b
 *  Added transfer protocol for ucap network receivers and added destination port
 *  Revision 1.124.1.198  2016/10/10 10:17:37  thomas-b
 *  Removed _PRELIMINARY_CODE_AUDIO restrictions
 *  Added new extended feature and structure definitions for ucap via network
 *  Revision 1.124.1.197  2016/10/07 11:24:50  thomas-b
 *  Fixed swab makro for addr settings
 *  Revision 1.124.1.196  2016/10/05 08:26:36  andre.hartmann
 *  Revision 1.124.1.195  2016/09/29 11:56:43Z  philipp
 *  Added documentation for MBG_TRANSACTION_TYPE_NETWORK
 *  Revision 1.124.1.194  2016/09/29 10:43:41  thomas-b
 *  Added define for MBG_ARPHRD_ETHER
 *  Revision 1.124.1.193  2016/09/29 06:13:07  philipp
 *  Added support for beginning / ending typed transactions
 *  Revision 1.124.1.192  2016/09/28 13:35:00  philipp
 *  Renamed flag field
 *  Revision 1.124.1.191  2016/09/28 13:29:22  thomas-b
 *  Added feature flags for MBG_NET_GLB_CFG_INFO
 *  Revision 1.124.1.190  2016/09/26 13:04:54  udo
 *  added missing comma in MBG_TLV_FEAT_TYPE_NAMES
 *  Revision 1.124.1.189  2016/09/26 10:08:14  udo
 *  added TLV Feature MBG_TLV_FEAT_TYPE_FILE_REQUEST to request a generic file from HPS
 *  Revision 1.124.1.188  2016/09/23 08:29:09  martin
 *  Fixed missing comma in string table initializer.
 *  Revision 1.124.1.187  2016/09/22 12:12:29  philipp
 *  Split ::MBG_NET_INTF_LINK_OPTS::MBG_NET_INTF_LINK_OPT_CAN_SYNCE up into SyncE In and SyncE Out option
 *  Revision 1.124.1.186  2016/09/15 14:54:30  martin
 *  Support GRC181PEX.
 *  Revision 1.124.1.185  2016/09/12 09:16:49  martin
 *  Fixed cascaded comment characters.
 *  Revision 1.124.1.184  2016/09/08 10:25:03  martin
 *  Fixed build for 16 bit targets.
 *  Revision 1.124.1.183  2016/09/05 13:23:04  paul.kretz
 *  Added ENABLE_FLAGS to BUILTIN_FEAT_VSG180
 *  Revision 1.124.1.182  2016/08/25 14:37:16Z  paul.kretz
 *  added new gpio video type PAL_M
 *  Revision 1.124.1.181  2016/08/23 15:47:04Z  martin
 *  Moved macros _setup_default_receiver_info_dcf() and
 *  _setup_default_receiver_info_gps() here.
 *  Revision 1.124.1.180  2016/08/16 13:01:13  martin
 *  Syntax fix.
 *  Revision 1.124.1.179  2016/08/12 11:05:14  paul.kretz
 *  Added digital audio output as new gpio type which is only included
 *  if symbol _PRELIMINARY_CODE_AUDIO is defined.
 *  Revision 1.124.1.178  2016/08/11 11:34:06Z  martin
 *  Modified MBG_REF_OFFS_NOT_CFGD  to avoid compiler warning.
 *  Revision 1.124.1.177  2016/08/11 11:30:16  martin
 *  Moved time monitoring stuff to new file time_mon.h.
 *  Revision 1.124.1.176  2016/08/11 10:28:09  udo
 *  prepare extended data set for time monitor
 *  Revision 1.124.1.175  2016/08/10 05:17:08  udo
 *  added domain number to Time Monitor Target Settings
 *  Revision 1.124.1.174  2016/08/09 14:48:06  martin
 *  Revision 1.124.1.173  2016/08/03 08:05:11Z  thomas-b
 *  Finished new network structures, definitions and relations
 *  Revision 1.124.1.172  2016/07/29 09:36:21  paul.kretz
 *  Added definitions for N2X180.
 *  Revision 1.124.1.171  2016/07/15 14:08:09Z  martin
 *  Fixed a typo.
 *  Revision 1.124.1.170  2016/07/07 14:17:02  martin
 *  Cleaned up POUT API.
 *  Doxygen fixes.
 *  Revision 1.124.1.169  2016/07/07 09:57:10  andre.hartmann
 *  added mbg_clk_res_info
 *  Revision 1.124.1.168  2016/06/28 15:42:16Z  martin
 *  *** empty log message ***
 *  Revision 1.124.1.167  2016/06/28 15:04:40  martin
 *  Added definitions for GRC181.
 *  Added missing definitions for GPS180CSM.
 *  Revision 1.124.1.166  2016/06/23 09:23:24  thomas-b
 *  Added num_dns_srvr and num_dns_srch_dom to MBG_NET_GLB_CFG_SETTINGS
 *  Revision 1.124.1.165  2016/06/22 06:58:37  udo
 *  added new parameters to MBG_TIME_MON_TARGET_STATUS
 *  Revision 1.124.1.164  2016/06/21 06:34:54  andre
 *  QL alarms now separated for TDEV and MTIE
 *  comment for QL hysteresis added
 *  Revision 1.124.1.163  2016/06/10 07:59:09Z  philipp
 *  Extended sysinfo proc and fpga types by SAM3u and Cyclone5
 *  Revision 1.124.1.162  2016/06/09 09:17:08  thomas-b
 *  Added builtin features TIME and TZDL for TCR cards
 *  Revision 1.124.1.161  2016/06/06 08:59:45  andre
 *  Revision 1.124.1.160  2016/06/02 13:36:11Z  philipp
 *  Extended MBG_EXT_SYS_INFO proc and fpga types
 *  Revision 1.124.1.159  2016/06/02 10:57:51  philipp
 *  Added string initializers for MBG_EXT_SYS_INFO's proc and FPGA types
 *  Revision 1.124.1.158  2016/06/02 10:24:22  philipp
 *  Renaming all revision macros and helper functions
 *  Revision 1.124.1.157  2016/06/02 10:15:35  philipp
 *  Renaming all MBG_EXT_REV_INFO related stuff to MBG_EXT_SYS_INFO.
 *  Revision 1.124.1.156  2016/06/01 10:49:49  andre
 *  Revision 1.124.1.155  2016/06/01 09:51:26Z  philipp
 *  Added structures and definitions for new type MBG_LICENSE to be queried via TLV_API.
 *  Revision 1.124.1.154  2016/06/01 06:59:00  andre
 *  Revision 1.124.1.153  2016/05/31 14:32:27Z  andre
 *  Revision 1.124.1.152  2016/05/31 14:32:02Z  andre
 *  Revision 1.124.1.151  2016/05/30 08:14:09Z  thomas-b
 *  Added builtin feature GPS_MODEL_HAS_TIME to GPS receivers and N2x
 *  Revision 1.124.1.150  2016/05/27 06:32:12  philipp
 *  Changed XMR_HOLDOVER_STATUS_MODE_NAMES
 *  Revision 1.124.1.149  2016/05/26 08:01:16  andre
 *  Revision 1.124.1.148  2016/05/24 14:43:10Z  andre
 *  Revision 1.124.1.147  2016/05/24 13:32:24Z  philipp
 *  Added PTP Statistics
 *  Revision 1.124.1.146  2016/05/20 08:58:52  thomas-b
 *  New BUILTIN_FEATURE GPS_HAS_TZCODE for older PZF cards
 *  Revision 1.124.1.145  2016/05/20 06:41:42  thomas-b
 *  Added TZDL and ENABLE_FLAGS to BUILTIN_FEAT_N2X
 *  Revision 1.124.1.144  2016/05/19 13:12:32  paul
 *  renamed two video HD formats:
 *  1080i29.97Hz to 1080i59.94Hz and 1080i25Hz to 1080i50Hz
 *  Revision 1.124.1.143  2016/05/11 13:20:20Z  thomas-b
 *  Changed several fields and flags in NET_CFG structures
 *  Revision 1.124.1.142  2016/05/09 08:06:53  philipp
 *  New array string initializers for LED modes and colors
 *  Revision 1.124.1.141  2016/05/04 09:57:27  thomas-b
 *  Comment changed
 *  Revision 1.124.1.140  2016/04/26 09:17:41  thomas-b
 *  Changed structure MBG_NET_GLB_CFG_SETTINGS
 *  Revision 1.124.1.139  2016/04/26 08:51:47  philipp
 *  New multi reference input type SyncE
 *  Revision 1.124.1.138  2016/04/26 08:18:58  thomas-b
 *  Added typedefs for interface route structures if _PRELIMINARY_CODE is not defined
 *  Revision 1.124.1.137  2016/04/26 07:39:45  thomas-b
 *  Changed names and descriptions in net_cfg structures
 *  Relocated preliminary code areas in net_cfg and ntp definitions
 *  Revision 1.124.1.136  2016/04/26 06:05:44  philipp
 *  Removed space to fix compiler error on ARM GCC 4.9.3
 *  Revision 1.124.1.135  2016/04/25 15:13:58  martin
 *  *** empty log message ***
 *  Revision 1.124.1.134  2016/04/25 14:34:46  martin
 *  *** empty log message ***
 *  Revision 1.124.1.133  2016/04/25 10:23:22Z  martin
 *  TLV code isn't preliminary anymore.
 *  Enums with more than 16 entries are not supported by 16 bit compilers.
 *  Revision 1.124.1.132  2016/04/22 08:36:27  philipp
 *  Added String initializers for GPIO bit out flags
 *  Revision 1.124.1.131  2016/04/21 10:53:29  philipp
 *  Added GPIO bits format strings.
 *  Added T1 SSM quality levels.
 *  Revision 1.124.1.130  2016/04/20 14:43:29  udo
 *  use NANO_TIME instead of double
 *  Revision 1.124.1.129  2016/04/20 13:16:58  thomas-b
 *  Added typedefs for NTP_SRV_MODE_INFO and NTP_SRV_MODE_SETTINGS
 *  Revision 1.124.1.128  2016/04/20 09:26:05  philipp
 *  Moved all HPS-PTP related structures to gpspriv.h and removed related extended feature bit from gpsdefs.h.
 *  Also removed functions from mbgextio and xdevfeat since HPS-PTP handling needs a redesign concerning structures.
 *  Thus, handle everything explicitly for now!
 *  -> Redesing this A.S.A.P.!!!
 *  Revision 1.124.1.127  2016/04/18 12:37:02  thomas-b
 *  New network structures and definitions for bonding and routing
 *  Revision 1.124.1.126  2016/04/15 13:14:08  daniel
 *  Added PTP profile ITU-T. G. 8275.2
 *  Revision 1.124.1.125  2016/04/15 09:22:16  udo
 *  fixed alignment problem in PTP_DEV_CFG_GLB
 *  Revision 1.124.1.124  2016/04/15 08:17:28  philipp
 *  New feature MBG_XFEATURE_EXT_PTP
 *  Revision 1.124.1.123  2016/04/15 07:31:46  andre
 *  Revision 1.124.1.122  2016/04/08 10:18:02Z  daniel
 *  Fixed MBG_ENCODE_EXT_REV macro
 *  Revision 1.124.1.121  2016/04/08 10:16:29  martin
 *  *** empty log message ***
 *  Revision 1.124.1.120  2016/04/07 13:20:23  philipp
 *  Extended NTP definitions and added new structure MBG_EXT_REV_INFO including enums, masks, etc..
 *  Revision 1.124.1.119  2016/04/05 13:29:25  daniel
 *  Adjust ptp cfg and state structures to take care of unified data type sizes and alignment
 *  Revision 1.124.1.118  2016/04/04 14:46:13  martin
 *  Added TLV feature type names.
 *  Revision 1.124.1.117  2016/03/24 14:08:47  martin
 *  *** empty log message ***
 *  Revision 1.124.1.116  2016/03/24 09:14:52  martin
 *  New extended feature MBG_XFEATURE_PWR_CTL_API.
 *  Revision 1.124.1.115  2016/03/18 11:21:52  martin
 *  *** empty log message ***
 *  Revision 1.124.1.114  2016/03/18 10:32:25  martin
 *  *** empty log message ***
 *  Revision 1.124.1.113  2016/03/17 09:21:01  martin
 *  *** empty log message ***
 *  Revision 1.124.1.112  2016/03/16 15:13:37  martin
 *  *** empty log message ***
 *  Revision 1.124.1.111  2016/03/16 08:29:13  martin
 *  Removed ..._MODEL_HAS_GNSS_MODE definitions, use ..._MODEL_IS_GNSS
 *  instead.
 *  Revision 1.124.1.110  2016/03/15 14:55:04  martin
 *  Modified LNE and LED API.
 *  Revision 1.124.1.109  2016/03/14 11:54:06  martin
 *  Fixed duplicate macro name.
 *  Revision 1.124.1.108  2016/03/11 15:12:08  martin
 *  Started to refactor LED and LNE API.
 *  Revision 1.124.1.107  2016/03/11 11:25:26  martin
 *  Made XMR_STATS::step_det_val a reserved, unused field.
 *  Cleanup.
 *  Revision 1.124.1.106  2016/03/11 10:09:44  andre
 *  Revision 1.124.1.105  2016/03/02 15:03:42Z  daniel
 *  Updates for new PTP Utility profile and PTP statistics
 *  Revision 1.124.1.104  2016/02/29 15:51:31  andre
 *  added estimated holdover var to XMR_HOLDOVER_STATUS
 *  Revision 1.124.1.103  2016/02/25 08:47:32Z  paul
 *  Added definitions for GTS180.
 *  Revision 1.124.1.102  2016/02/24 09:23:55Z  gregoire
 *  change PTP_ANN_RCPT_TIMEOUT_MAX from 255 to 8
 *  Revision 1.124.1.101  2016/02/19 12:11:21Z  udo
 *  added MBG_LNE_INFO_EXT
 *  Revision 1.124.1.100  2016/02/18 14:56:37  daniel
 *  Added TLV FEAT_TYPE LICENSE UPGRADE
 *  Revision 1.124.1.99  2016/02/18 11:27:27  udo
 *  added MBG_LNE_LED_STATUS
 *  Revision 1.124.1.98  2016/02/16 08:38:50  gregoire
 *  added new initializer to MBG_XFEATURE_NAMES
 *  Revision 1.124.1.97  2016/02/11 12:02:39Z  daniel
 *  Added two TLV_FEAT_TYPES
 *  Revision 1.124.1.96  2016/02/10 15:52:36  thomas-b
 *  Added enum MBG_IMS_FDM_FLAGS and appropriate masks enum
 *  Revision 1.124.1.95  2016/02/03 13:27:44  martin
 *  Added definitions for LNE180SFP.
 *  Revision 1.124.1.94  2016/02/03 09:41:32  martin
 *  Fixed build without _PRELIMINARY_CODE.
 *  Revision 1.124.1.93  2016/02/02 15:53:46Z  martin
 *  Added definitions for CSM100.
 *  Revision 1.124.1.92  2016/01/29 09:06:32  udo
 *  Added time-protocol type to Time Monitor Target settings.
 *  Revision 1.124.1.91  2016/01/22 11:34:39  gregoire
 *  Added string initializers for XMR_STATS_FLAGS_BITS.
 *  Revision 1.124.1.90  2016/01/22 08:16:07Z  gregoire
 *  Renamed DEFAULT_MULTI_REF_NAMES_SHORT strings.
 *  Revision 1.124.1.89  2016/01/21 08:59:03Z  andre
 *  Added auto_bis field in XMR_STATS.
 *  Revision 1.124.1.88  2016/01/19 14:11:47Z  udo
 *  Modified time monitor structures.
 *  Revision 1.124.1.87  2016/01/18 08:37:03  udo
 *  Added support for PTP Time Monitoring on TSU/HPS100.
 *  Revision 1.124.1.86  2016/01/15 11:30:14  martin
 *  New field 'timestamp' in XMR_STATS.
 *  Revision 1.124.1.85  2016/01/15 08:52:51  martin
 *  Some flag masks for XMR_STATS.
 *  Revision 1.124.1.84  2016/01/13 15:26:00  martin
 *  Removed obsolete code added in the previous version.
 *  Revision 1.124.1.83  2016/01/13 15:09:17  martin
 *  Support XMR_STATS.
 *  Revision 1.124.1.82  2015/12/14 13:03:09  lars
 *  Fixes / changes in IRIG TX / RX masks.
 *  Revision 1.124.1.81  2015/12/14 11:09:01Z  lars
 *  *** preliminary ***
 *  Revision 1.124.1.80  2015/12/09 17:34:56Z  martin
 *  *** empty log message ***
 *  Revision 1.124.1.79  2015/12/09 10:21:18  martin
 *  *** empty log message ***
 *  Revision 1.124.1.78  2015/12/09 08:28:36  martin
 *  New legacy model codes.
 *  Changed/Added some IRIG enums.
 *  Revision 1.124.1.77  2015/12/07 14:43:04  martin
 *  Doxygen fixes.
 *  Revision 1.124.1.76  2015/12/04 14:20:18  paul
 *  Fixed a typo in comment of video string initialzier.
 *  Added support for configurable epochs for video outputs.
 *  Revision 1.124.1.75  2015/12/02 16:51:19Z  martin
 *  *** empty log message ***
 *  Revision 1.124.1.74  2015/12/02 16:35:32  martin
 *  *** empty log message ***
 *  Revision 1.124.1.73  2015/12/01 11:34:33  martin
 *  *** empty log message ***
 *  Revision 1.124.1.72  2015/11/30 16:51:12  martin
 *  *** empty log message ***
 *  Revision 1.124.1.71  2015/11/30 16:22:30  martin
 *  *** empty log message ***
 *  Revision 1.124.1.70  2015/11/30 09:02:47  philipp
 *  Added TLV feature MBG_TLV_CTX_FLAG_FW_ROLLBACK.
 *  Revision 1.124.1.69  2015/11/30 08:16:57  philipp
 *  Added MBG_TLV_INFO feature macros.
 *  Revision 1.124.1.68  2015/11/26 17:01:08  martin
 *  *** empty log message ***
 *  Revision 1.124.1.67  2015/11/26 08:32:54  martin
 *  *** empty log message ***
 *  Revision 1.124.1.66  2015/11/25 16:55:08  martin
 *  Started to implement extended features.
 *  Revision 1.124.1.65  2015/11/24 13:10:54  philipp
 *  TLV additions / partly redesign and feature inline functions.
 *  Revision 1.124.1.64  2015/11/23 10:23:47  philipp
 *  Added Doxygen documentation for TLV structures, flags and masks.
 *  Revision 1.124.1.63  2015/11/23 10:11:28  martin
 *  *** empty log message ***
 *  Revision 1.124.1.62  2015/11/23 08:27:32  gregoire
 *  Added initializers for MBG_IMS_FDM_LINE_FREQS.
 *  Revision 1.124.1.61  2015/11/20 09:16:39Z  philipp
 *  Fixed macro _mbg_swab_tlv_announce.
 *  Revision 1.124.1.60  2015/11/20 08:14:29  philipp
 *  Added id member to struct MBG_TLV_ANNOUNCE.
 *  Revision 1.124.1.59  2015/11/20 07:26:29  philipp
 *  Moved TLV structures here.
 *  Revision 1.124.1.58  2015/11/18 13:51:50  philipp
 *  Added leapfile to NTP miscellaneous structures.
 *  Revision 1.124.1.57  2015/11/18 13:39:22  philipp
 *  Added NTP miscellaneous structures.
 *  Revision 1.124.1.56  2015/11/06 12:42:08  philipp
 *  Added NTP statistics structures.
 *  Revision 1.124.1.55  2015/11/06 11:25:22  philipp
 *  Removed member symlink in NTP_REFCLK_CFG_SPEC since it is implementation defined.
 *  Revision 1.124.1.54  2015/11/06 11:16:35  philipp
 *  Added NTP symmetric key structures.
 *  Revision 1.124.1.53  2015/11/06 09:17:40  philipp
 *  Added byte swap macros to NTP restriction and NTP refclock configuration structures.
 *  Revision 1.124.1.52  2015/11/05 12:20:12  martin
 *  New define MBG_MAX_HOSTNAME_LEN.
 *  Preliminary fix for TZDL initializers.
 *  Updated some comments.
 *  Revision 1.124.1.51  2015/11/05 09:07:56  philipp
 *  Added structures for NTP restriction and refclock configuration (preliminary code).
 *  Revision 1.124.1.50  2015/10/28 12:09:26  martin
 *  GPIO types for SCG not preliminary anymore.
 *  Added definitions for LUE180.
 *  Revision 1.124.1.49  2015/10/26 11:55:19  daniel
 *  Merged aligned PTP SMPTE and TELECOM PHASE profile structures from previous branch here.
 *  Revision 1.124.1.48  2015/10/26 11:24:04  daniel
 *  Support for PTP Preset 802.1AS
 *  Revision 1.124.1.47  2015/10/26 10:56:42  paul
 *  added a new flag for GPIO studio clock out
 *  Revision 1.124.1.46  2015/10/26 09:47:53Z  paul
 *  added a missing GPIO studio clock scale string initializer
 *  Revision 1.124.1.45  2015/10/23 11:00:27Z  paul
 *  Revision 1.124.1.44  2015/10/22 14:35:51Z  paul
 *  fixed a typo
 *  Revision 1.124.1.43  2015/10/22 14:17:34Z  martin
 *  *** empty log message ***
 *  Revision 1.124.1.42  2015/10/22 14:15:02  paul
 *  some changes in GPIO structs
 *  Revision 1.124.1.41  2015/10/21 14:36:32Z  paul
 *  renamed stud_clk_out in studio_clk_out and vid_sync_out in video_sync_out
 *  Revision 1.124.1.40  2015/10/20 13:38:57Z  paul
 *  renamed HD format in GPIO video type
 *  Revision 1.124.1.39  2015/10/20 12:11:36Z  paul
 *  Revision 1.124.1.38  2015/10/20 10:58:01Z  martin
 *  *** empty log message ***
 *  Revision 1.124.1.37  2015/10/20 10:43:39  paul
 *  Revision 1.124.1.36  2015/10/20 10:15:57Z  paul
 *  added preliminary studio clock structs and defines
 *  Revision 1.124.1.35  2015/10/19 10:48:00Z  gregoire
 *  Revision 1.124.1.34  2015/10/19 10:08:47Z  gregoire
 *  Revision 1.124.1.33  2015/10/16 11:03:06Z  martin
 *  *** empty log message ***
 *  Revision 1.124.1.32  2015/10/15 14:17:22  martin
 *  *** empty log message ***
 *  Revision 1.124.1.31  2015/10/15 08:40:37  paul
 *  added two new HD video formats
 *  Revision 1.124.1.30  2015/10/15 07:38:14Z  gregoire
 *  AES67 Media Profile added
 *  Revision 1.124.1.29  2015/10/13 08:44:08Z  gregoire
 *  smpte_jam_event added to PTP_DEV_CFG_GLB
 *  Revision 1.124.1.28  2015/10/12 10:01:59Z  martin
 *  *** empty log message ***
 *  Revision 1.124.1.27  2015/10/09 11:09:13  martin
 *  *** empty log message ***
 *  Revision 1.124.1.26  2015/10/09 09:03:50  gregoire
 *  Revision 1.124.1.25  2015/10/09 07:18:49Z  gregoire
 *  Builtin feature BUILTIN_FEAT_GNSS set for GRC models.
 *  Revision 1.124.1.24  2015/10/08 13:27:37Z  martin
 *  *** empty log message ***
 *  Revision 1.124.1.23  2015/10/06 10:33:39  paul
 *  Changed GPIO names.
 *  Added two defines for GPIO_TYPE_VIDEO_SYNC.
 *  Revision 1.124.1.22  2015/10/06 07:55:11Z  paul
 *  Changed names of GPIO types and structs.
 *  Revision 1.124.1.21  2015/10/02 13:07:11Z  martin
 *  Doxygen fixes.
 *  Revision 1.124.1.20  2015/10/02 10:33:00  martin
 *  *** empty log message ***
 *  Revision 1.124.1.19  2015/10/01 10:51:32  martin
 *  *** empty log message ***
 *  Revision 1.124.1.18  2015/09/30 08:03:45  paul
 *  Bug fix in some GPIO structs.
 *  Added comments.
 *  Revision 1.124.1.17  2015/09/29 09:55:22Z  paul
 *  added video output and sync output as two new GPIO types
 *  Revision 1.124.1.16  2015/09/28 09:34:56Z  thomas-b
 *  Renamed td_max_limit in MBG_IMS_FDM_LIMITS to td_pos_limit
 *  Revision 1.124.1.15  2015/09/18 13:58:44  martin
 *  *** empty log message ***
 *  Revision 1.124.1.14  2015/09/17 14:56:57  thomas-b
 *  Renamed several variables in MBG_FDM_SETTINGS and MBG_FDM_LIMITS
 *  Revision 1.124.1.13  2015/09/15 13:15:01  martin
 *  Moved definitions for NANO_TIME and NANO_TIME_64 to words.h.
 *  Revision 1.124.1.12  2015/09/15 11:08:22  martin
 *  Support new model TCR180.
 *  Added missing comma in DEFAULT_GPS_MODEL_NAMES.
 *  Revision 1.124.1.11  2015/09/07 09:19:21  martin
 *  Revision 1.124.1.10  2015/09/04 09:19:17  daniel
 *  Moved 2 additional TSU strcutures to PREMINARY_CODE block
 *  Revision 1.124.1.9  2015/09/03 09:17:41  martin
 *  Doxygen fixes.
 *  Revision 1.124.1.8  2015/09/02 16:42:17  martin
 *  Preliminary code which is only included if a preprocessor symbol
 *  _PRELIMINARY_CODE is defined in the project Makefile.
 *  Revision 1.124.1.7  2015/08/25 10:30:13  daniel
 *  Revision 1.124.1.6  2015/08/25 10:02:37  daniel
 *  Revision 1.124.1.5  2015/08/25 09:16:39  daniel
 *  Changed reserved member in PTP_STATE to include tsu_secs
 *  Revision 1.124.1.4  2015/08/10 07:37:09  daniel
 *  Added sync_e byte swab macros
 *  Revision 1.124.1.3  2015/08/07 10:51:10  daniel
 *  Fixed typo in CTC100 declaration
 *  Revision 1.124.1.2  2015/08/07 10:49:40  daniel
 *  RE-added temp. PTP structures PTP_DEV_CFG_GLB and PTP_DEV_CFG_NET
 *  Added new model CTC100
 *  Revision 1.124.1.1  2015/07/29 07:40:55  daniel
 *  Revision 1.124  2015/07/14 14:22:46  martin
 *  Doxygen fix.
 *  Revision 1.123  2015/07/06 13:00:10  martin
 *  Added definitions for VSG180, MSF180, WWVB180, and CPC180.
 *  Added definitions for PZF180.
 *  Definitions for SDI and MDU300 added by stephan.
 *  Definitions for HPS100 added by daniel.
 *  FDM180 and associated definitions added by paul.
 *  Started to support eXtended Binary Protocol (XBP).
 *  Merged daniel and gregoire's changes from the 1.120.2.x branch.
 *  Defines for IPv6 multicast scopes added by gregoire.
 *  XMR_EXT_SRC_INFO and associated XMR_SETTINGS_FLAG_MSKS flags
 *  defined by andre.
 *  Support XMULTI_REF_INFO::n_prio field again.
 *  Fixed _mbg_swab_gpio_cfg_limits() macro.
 *  Added MBG_NET_LINK_OPT_MASK_CAN_SYNCE to MBG_NET_LINK_OPT_MASKS.
 *  New PTP_ROLE_MASKS PTP_ROLE_NTP_SERVER and PTP_ROLE_NTP_CLIENT.
 *  Some PTP profile extensions added by daniel.
 *  Added missing defines for SPT.
 *  Added definitions for REL1000.
 *  Moved structure NANO_TIME_64 here.
 *  Revision 1.122  2014/07/29 08:57:44Z  martin
 *  Updated doxygen comments.
 *  Revision 1.121  2014/07/17 09:41:50  martin
 *  Introduced XMR_HOLDOVER_STATUS, MBG_GPIO_STATUS,
 *  and associated definitions.
 *  Huge update and cleanup on doxygen comments.
 *  Revision 1.120  2014/05/27 08:34:40  martin
 *  Fixed braces in some _mbg_rcvr_is_..() macros.
 *  Definitions used with extended network cfg, VST, and SHS.
 *  Introduced XMR_HOLDOVER_STATUS.
 *  Introduced programmable output mode POUT_GPIO.
 *  Introduced oscillator type OCXO_SQ.
 *  Defined some new baud rates.
 *  Defines for IEEE C37.118.1-2011 CTQ.
 *  Support for new model SCG by paul.
 *  Support new model PPG180.
 *  New SCU control masks.
 *  New GNSS flag MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER.
 *  DEFAULT_MULTI_REF_NAMES_SHORT added by udo.
 *  Definitions used for NTP configuration by thomas-b and marvin.
 *  MBG_NET_ADDR structures changed to MBG_IP_ADDR, and
 *  associated symbols defined by marvin.
 *  Huge rework of comments in doxygen format.
 *  Revision 1.119  2013/12/05 10:13:13  daniel
 *  Support new PTP_CFG_FLAGS for 1-step-L2 and 1-step-P2P support
 *  Revision 1.118  2013/11/19 13:38:35  martin
 *  Added LAN_IF_TYPE_RSC.
 *  Revision 1.117  2013/11/18 14:13:39  martin
 *  Support model LNE_GB.
 *  Revision 1.116  2013/11/11 09:46:11  martin
 *  New PTP configuration flags PTP_CFG_SUPP_MCAST_SLAVE_FLAG and
 *  PTP_CFG_CAN_BE_MULTICAST_SLAVE, plus associated bit masks.
 *  New XMR_INST_FLAGS and XMR_INST_FLAG_MASKS defined by andre.
 *  Fixes for big-endian targets.
 *  Updated doxygen comments.
 *  Revision 1.115  2013/10/02 15:19:28  martin
 *  Changed PTP_CFG_SETTINGS::vlan_cfg back to a reserved field,
 *  and removed associated flag and flag mask.
 *  Revision 1.114  2013/09/25 11:02:10  martin
 *  Support models MRI, BPE, GLN180PEX, N2X, RSC180.
 *  Added feature bit GPS_FEAT_NTP.
 *  Enhanced VLAN configuration structures.
 *  Started to support IPv6.
 *  Renamed PTP_CFG_SETTINGS field "profile" to "selected_presets".
 *  Renamed PTP_CFG_INFO field "supp_profiles" to "supp_opt_ext".
 *  New PTP role PTP_ROLE_BOTH_MASTER.
 *  New PTP flag PTP_FLAG_ONE_STEP.
 *  Added some new PTP_CFG_FLAGS flags.
 *  Added PTP_OPT_EXTS and associated definitions.
 *  Added PTP_PRESETS and associated definitions.
 *  Added "tzdl" field to PTP_POWER_PROFILE_CFG.
 *  Made reserved PTP_CFG_SETTINGS field to "opt_ext" field.
 *  Made reserved PTP_CFG_SETTINGS field to "vlan_cfg" field.
 *  Made reserved PTP_STATE field to "parent_clock_class" and "parent_clock_accuracy".
 *  Definitions for MULTI_REF_EXT_OSC added by Andre.
 *  String initializers for supported HaveQuick formats added by Gregoire.
 *  Lots of doxygen changes.
 *  Revision 1.113  2013/04/04 09:02:01Z  martin
 *  Added definitions to support HaveQuick.
 *  Fixed a typo.
 *  Revision 1.112  2013/02/19 15:39:13  martin
 *  New PTP settings field ann_rcpt_timeout and associated
 *  values PTP_ANN_RCPT_TIMEOUT_LIMITS.
 *  Changed many defines to named enums to simplify references
 *  with doxygen.
 *  Updated doxygen comments.
 *  Revision 1.111  2013/02/01 15:37:36  martin
 *  Added and modified a huge number of doxygen comments.
 *  Revision 1.110  2013/01/16 15:23:25  martin
 *  Fixed 2 comments which were interchanged.
 *  Revision 1.109  2013/01/11 10:39:34  martin
 *  Added definitions for IMS.
 *  Support XMR_HOLDOVER_INTV.
 *  New XMRS status bit XMRS_BIT_LOW_JITTER / XMRS_MSK_LOW_JITTER.
 *  Added framing type 8E2, though most UARTs don't support this.
 *  Added enum names and updated comments for doxygen.
 *  Revision 1.108  2012/10/30 11:31:16  martin
 *  Defined PTP_UC_MSG_DURATION_MIN and PTP_UC_MSG_DURATION_MAX.
 *  Fixed some doxygen comments.
 *  Changes by andre: changed reserved field to ssm and boc in BITS_OUT settings.
 *  Revision 1.107  2012/10/12 07:40:12  martin
 *  New PTP state flags PTP_FLAG_MSK_UTC_VALID and
 *  PTP_CFG_MSK_SUPP_UTC_VALID.
 *  Revision 1.106  2012/10/02 18:22:10  martin
 *  Added default baud rate and framing for binary protocol.
 *  Added definitions for IRIG codes E002/E112 and NASA36.
 *  Reworked GPIO structures.
 *  Added definitions for GRC, LIU, DCF600RS, and DCF600HS.
 *  New flag POUT_FIXED_PULSE_LEN.
 *  New flag POUT_NOT_INVERTIBLE.
 *  Unified capitalization in MBG_XMRS_STATUS_STRS.
 *  Revision 1.105  2012/06/01 16:31:16  martin
 *  Some TIME_SLOT definitions added by marvin.
 *  Moved some PTP configuration defaults and limits to ptpdflts.h.
 *  Revision 1.104  2012/04/11 16:02:55Z  martin
 *  Fixed some doxygen comments.
 *  Revision 1.103  2012/04/02 11:08:57Z  martin
 *  Extended description of GPS UTC/leap second data.
 *  Revision 1.102  2012/03/16 11:43:31  martin
 *  Fixed a potential compiler warning.
 *  Revision 1.101  2012/03/06 16:56:01Z  martin
 *  Added support for PTP multicast auto role.
 *  Merged Daniel's definitions for PTP profile support.
 *  Support time slot mode for programmable pulse outputs.
 *  Support LNO180.
 *  Moved definition of MBG_MAC_ADDR here.
 *  Use MBG_MAC_ADDR in definition of LAN_IF_INFO.
 *  Revision 1.100  2012/01/17 13:33:55  martin
 *  Added new IRIG RX delay compensation code groups for G0xx and G1xx codes.
 *  As a consequence the value of N_IRIG_RX_COMP has changed.
 *  Added definition of IRIG_RX_COMP_MAX.
 *  Updated IRIG code classification macros.
 *  Removed obsolete/unused definition of CAL_REC_INFO.
 *  Added some comments.
 *  Revision 1.99  2011/12/09 09:22:03  martin
 *  Fixed a typo.
 *  Revision 1.98  2011/11/25 14:58:34  martin
 *  Renamed some evt_log definitions.
 *  Revision 1.97  2011/11/25 10:11:17  martin
 *  Initializers for XMRS status bit strings added by gregoire.
 *  New feature GPS_FEAT_EVT_LOG.
 *  Added definitions used with event logs.
 *  Moved cal_reg and gen_io stuff here.
 *  Added macro _mbg_swab_debug_status().
 *  Updated some comments.
 *  Revision 1.96  2011/10/11 13:40:46Z  andre
 *  changed reserved field into slot_id in XMULTI_REF_INSTANCES
 *  Revision 1.95.1.1  2011/10/07 09:31:58Z  andre
 *  Revision 1.95  2011/10/04 09:35:41Z  martin
 *  Added support for ESI180.
 *  Changed RECEIVER_INFO::flags bit GPS_10MHZ_DISBD to a RECEIVER_INFO::features bit.
 *  Support MULTI_REF_INTERNAL, MULTI_REF_LWR and MULTI_REF_PZF.
 *  Added MBG_GPIO_BITS structure and associated definitions.
 *  Revision 1.94  2011/08/25 07:42:43Z  martin
 *  Fixed a bug  in macro _mbg_swab_pout_settings() where the 16 bit timeout
 *  field was swapped using a macro for 32 bit types.
 *  Use shorter names for some PTP unicast master default values.
 *  Revision 1.93  2011/08/10 08:19:38Z  martin
 *  New PORT_INFO and PORT_SETTINGS flag PORT_FLAG_PORT_INVISIBLE.
 *  Revision 1.92  2011/07/29 09:49:35  martin
 *  Support PZF180PEX, MGR180, MSF600, WWVB600, JJY600,
 *  GPS180HS, and GPS180AMC.
 *  Added receiver info features GPS_FEAT_PTP_UNICAST
 *  and GPS_FEAT_XMRS_MULT_INSTC.
 *  Added receiver info flag bit GPS_10MHZ_DISBD.
 *  Added initializers for PTP timescale names.
 *  New PTP_STATE flags bit PTP_FLAG_MSK_IS_UNICAST.
 *  Made unused PTP_STATE fields num_clients and num_masters reserved.
 *  Account for different PTP roles.
 *  Added / renamed some definitions for PTP.
 *  Modified default string for PTP layer 2 protocol.
 *  Support PTP unicast configuration.
 *  Support GPIO configuration.
 *  Introduced XMULTI_REF_INSTANCES.
 *  Moved flags XMRS_..._IS_EXTERNAL and XMRS_..._INSTC_EXCEEDED
 *  to definitions for XMULTI_REF_STATUS::status.
 *  Some comments added, updated, and converted to doxygen style.
 *  Cleaned up handling of pragma pack().
 *  Removed trailing whitespace and hard tabs.
 *  Revision 1.91  2011/01/31 11:23:56Z  martin
 *  Added model type name definitions for GPS180PEX and TCR180PEX.
 *  Introduced synthesizer mode for programmable outputs.
 *  Added IRIG-RX code TXC-101 DTR-6.
 *  Fixed missing comma bugs in DEFAULT_GPS_MODEL_NAMES.
 *  Fixed missing comma bugs in some IRIG string initializers.
 *  Fixed AFNOR notation.
 *  Modified some comments for doxygen.
 *  Revision 1.90  2010/10/15 11:47:53  martin
 *  Added definitions POUT_TIMEBASE_UTC and POUT_SUPP_DCF77_UTC.
 *  Added receiver info feature GPS_FEAT_RAW_IRIG_TIME.
 *  Support IRIG format C37.118.
 *  Added initializers for short IRIG code names.
 *  Cleaned up IRIG definitions and comments.
 *  Revision 1.89  2010/09/06 07:40:02Z  martin
 *  Picked up Daniel's definitions for multi GNSS support.
 *  Moved MBG_IRIG_CTRL_BITS, MBG_RAW_IRIG_DATA and related definitions
 *  from pcpsdefs.h here.
 *  Added macros _pcps_tfom_from_irig_ctrl_bits()
 *  and _pcps_tfom_from_raw_irig_data().
 *  Added RI_FEATURES type.
 *  Revision 1.88  2010/04/21 13:47:54  daniel
 *  Added support for new model GLN170.
 *  Revision 1.87  2010/03/10 11:29:37Z  martin
 *  Added definitions for GPS180.
 *  Added multi ref source 1 PPS plus associated string.
 *  Revision 1.86  2010/02/17 14:16:42  martin
 *  Added definitions for PZF600 and TCR600.
 *  Revision 1.85  2010/02/15 11:34:36  martin
 *  Changed definition of PTP_TABLE::name to const char *.
 *  Added definitions to support new model JJY511.
 *  Revision 1.84  2010/02/01 13:20:50  martin
 *  Support programmable outputs being disabled when sync. is lost.
 *  Revision 1.83  2010/01/28 09:15:50  martin
 *  Added new POUT mode DCF77_M59 and associated definitions.
 *  Revision 1.82  2010/01/07 09:04:55  martin
 *  Added XMR status bit XMRS_BIT_NOT_PHASE_LOCKED.
 *  Revision 1.81  2009/11/09 09:08:24  martin
 *  New TM_GPS status bit TM_INVT.
 *  Added definitions to support VLAN.
 *  Changed DEFAULT_PTP_DELAY_MECH_MASK to include also
 *  PTP_DELAY_MECH_MSK_P2P.
 *  There is now only one type of  TCXO supported which matches the former
 *  TCXO HQ, so the default name for TCXO HQ has been changed to TCXO.
 *  TCXO LQ and MQ names are still supported for backward compatibility.
 *  Revision 1.80  2009/09/28 14:55:53  martin
 *  Support IRIG formats G002/G142 and G006/G146.
 *  Modified IRIG format description strings.
 *  Revision 1.79  2009/08/12 14:12:38  daniel
 *  Added definitions to support new model MGR170.
 *  Added definitions and commands to support configuration
 *  of navigation engine (currently supported by u-blox
 *  receivers only).
 *  Renamed simulation values in PTP_SETTINGS to reserved.
 *  Added "UNINITIALIZED" to PTP port state.
 *  Removed obsolete braces in initializer.
 *  Revision 1.78  2009/06/25 15:49:05Z  martin
 *  Added macro _nano_time_negative().
 *  Revision 1.77  2009/06/08 19:22:32Z  daniel
 *  Added feature GPS_HAS_PTP.
 *  Added preliminary structures and definitions for PTP
 *  configuration and state.
 *  Added IP4_ADDR type.
 *  Added Bitmask IP4_MSK_DHCP.
 *  Added byte swapper macros for LAN and PTP structures.
 *  Moved LAN interface configuration definitions here.
 *  Moved DAC_VAL definition here.
 *  Changed type iof FPGA_INFO::start_addr for non-firmware applications.
 *  Revision 1.76  2009/04/08 08:26:56  daniel
 *  Added feature GPS_FEAT_IRIG_CTRL_BITS.
 *  Revision 1.75  2009/03/19 14:06:39Z  martin
 *  Modified string initializer for unknown oscillator type.
 *  Revision 1.74  2009/03/18 13:45:53  daniel
 *  Added missing commas in
 *  MBG_DEBUG_STATUS_STRS initializer.
 *  Adjusted some comments for doxygen parser.
 *  Revision 1.73  2009/03/10 16:55:33Z  martin
 *  Support configurable time scales GPS and TAI.
 *  Defined extended TM status type and associated flags.
 *  Added definition TM_MSK_TIME_VALID.
 *  Added some macros to swap endianess of structures.
 *  Revision 1.72  2008/11/28 09:26:21Z  daniel
 *  Added definitions to support WWVB511
 *  Revision 1.71  2008/10/31 14:31:44Z  martin
 *  Added definitions for TCR170PEX.
 *  Revision 1.70  2008/09/18 11:14:39  martin
 *  Added definitions to support GEN170.
 *  Revision 1.69  2008/09/15 14:16:17  martin
 *  Added more macros to convert the endianess of structures.
 *  Added N_COM_HS to the enumeration of handshake modes.
 *  Added MBG_PS_... codes.
 *  Revision 1.68  2008/08/25 10:51:13  martin
 *  Added definitions for PTP270PEX and FRC511PEX.
 *  Revision 1.67  2008/07/17 08:54:52Z  martin
 *  Added macros to convert the endianess of structures.
 *  Added multi ref fixed frequency source.
 *  Revision 1.66  2008/05/19 14:49:07  daniel
 *  Renamed s_addr to start_addr in FPGA_INFO.
 *  Revision 1.65  2008/05/19 09:00:01Z  martin
 *  Added definitions for GPS162.
 *  Added FPGA_INFO and GPS_HAS_FPGA.
 *  Added FPGA_START_INFO and associated definitions.
 *  Added new XMRS status XMRS_..._NOT_SETTLED.
 *  Added initializer XMULTI_REF_STATUS_INVALID.
 *  Revision 1.64  2008/01/17 11:50:33Z  daniel
 *  Made IGNORE_LOCK bit maskable.
 *  Revision 1.63  2008/01/17 11:42:09Z  daniel
 *  Made comments compatible for Doxygen parser.
 *  No sourcecode changes.
 *  Revision 1.62  2007/11/15 13:23:33Z  martin
 *  Decide whether other Meinberg headers are to be included depending on whether
 *  CLOCK_MEINBERG is defined (as with NTP) or not. Previous  versions checked
 *  for "PACKAGE" which is also defined by the Borland C++ build environment, though.
 *  Revision 1.61  2007/11/13 13:28:54  daniel
 *  Added definitions to support GPS170PEX.
 *  Revision 1.60  2007/09/13 12:37:35Z  martin
 *  Modified and added initializers for TZDL.
 *  Added multi ref source PTP over E1.
 *  Added codes for MSF511 and GRC170 devices.
 *  Modified XMULTI_REF_SETTINGS and XMULTI_REF_STATUS structures.
 *  Avoid inclusion of other Meinberg headers in non-Meinberg projects.
 *  Added device classification macros _mbg_rcvr_is_...().
 *  Modified feature name string initializer for non-GPS devices.
 *  Updated some comments.
 *  Removed some obsolete comments.
 *  Revision 1.59  2007/07/19 07:41:56Z  martin
 *  Added symbol MBG_REF_OFFS_NOT_CFGD.
 *  Revision 1.58  2007/05/21 15:46:44Z  martin
 *  Fixed a typo.
 *  Revision 1.57  2007/03/29 12:20:43  martin
 *  Fixed some TZDL initializers.
 *  Revision 1.56  2007/02/14 14:17:10Z  andre
 *  bug fixed in mask XMRS_MSK_NO_CONN
 *  Revision 1.55  2007/02/06 16:23:18Z  martin
 *  Added definitions for AM511.
 *  Made SVNO unsigned.
 *  Added support for OPT_SETTINGS.
 *  Added XMULTI_REF_... definitions.
 *  Added string initializer DEFAULT_FREQ_RANGES.
 *  Revision 1.54  2007/01/04 11:39:39Z  martin
 *  Added definitions for TCR511.
 *  Added definition GPS_FEAT_5_MHZ.
 *  Updated some comments related to duplicate features/options
 *  IGNORE_LOCK and EMU_SYNC.
 *  Revision 1.53  2006/12/13 09:31:49  martin
 *  Added feature flag for ignore_lock.
 *  Revision 1.52  2006/12/12 15:47:18  martin
 *  Added MBG_DEBUG_STATUS type and associated definitions.
 *  Added definition GPS_HAS_REF_OFFS.
 *  Moved PCPS_REF_OFFS and associated definitions from pcpsdefs.h here
 *  and renamed them to MBG_REF_OFFS, etc.
 *  Revision 1.51  2006/10/23 15:31:27  martin
 *  Added definitions for GPS170.
 *  Added definitions for new multi_ref sources IRIG, NTP, and PTP.
 *  Added some definitions useful when editing synth frequency.
 *  Revision 1.50  2006/08/25 09:29:28Z  martin
 *  Added structure NANO_TIME.
 *  Revision 1.49  2006/08/09 07:06:42Z  martin
 *  New TM_GPS status flag TM_EXT_SYNC.
 *  Revision 1.48  2006/08/08 12:51:20Z  martin
 *  Added definitions for IRIG codes B006/B126 and B007/B127.
 *  Revision 1.47  2006/07/06 08:41:45Z  martin
 *  Added definition of MEINBERG_MAGIC.
 *  Revision 1.46  2006/06/21 14:08:53Z  martin
 *  Added masks of IRIG codes which contain time zone information.
 *  Revision 1.45  2006/06/15 12:13:32Z  martin
 *  Added MULTI_REF_STATUS and associated flags.
 *  Added ROM_CSUM, RCV_TIMEOUT, and IGNORE_LOCK types.
 *  Revision 1.44  2006/05/18 09:34:41Z  martin
 *  Added definitions for POUT max. pulse_len and max timeout.
 *  Changed comment for POUT_SETTINGS::timeout.
 *  Units are minutes, not seconds.
 *  Added definition for MAX_POUT_TIME_STR_PORTS.
 *  Added definitions for POUT mode 10MHz.
 *  Added hint strings for POUT modes.
 *  Added definitions for PZF511.
 *  Revision 1.43  2006/01/24 07:53:29Z  martin
 *  New TM_GPS status flag TM_HOLDOVER.
 *  Revision 1.42  2005/11/24 14:53:22Z  martin
 *  Added definitions for manchester encoded DC IRIG frames.
 *  Added POUT_TIMESTR and related definitions.
 *  Revision 1.41  2005/11/03 15:06:59Z  martin
 *  Added definitions to support GPS170PCI.
 *  Revision 1.40  2005/10/28 08:58:29Z  martin
 *  Added definitions for OCXO_DHQ.
 *  Revision 1.39  2005/09/08 14:06:00Z  martin
 *  Added definition SYNTH_PHASE_SYNC_LIMIT.
 *  Revision 1.38  2005/08/18 10:27:35  andre
 *  added definitions for GPS164,
 *  added POUT_TIMECODE,
 *  struct SCU_STAT changed,
 *  ulong flags changed into two byte clk_info and ushort flags
 *  Revision 1.37  2005/05/02 14:44:55Z  martin
 *  Added structure SYNTH_STATE and associated definitions.
 *  Revision 1.36  2005/03/29 12:44:07Z  martin
 *  New RECEIVER_INFO::flags code: GPS_IRIG_FO_IN
 *  Revision 1.35  2004/12/09 14:04:38Z  martin
 *  Changed max synth freq from 12 MHz to 10 MHz.
 *  Revision 1.34  2004/11/23 16:20:09Z  martin
 *  Added bit definitions for the existing TTM status bit masks.
 *  Revision 1.33  2004/11/09 12:39:59Z  martin
 *  Redefined interface data types using C99 fixed-size definitions.
 *  Added model code and name for TCR167PCI.
 *  New type GPS_CMD.
 *  Defined type BVAR_STAT and associated flags.
 *  Revision 1.32  2004/09/20 12:46:25  andre
 *  Added structures and definitions for SCU board.
 *  Revision 1.31  2004/07/08 08:30:36Z  martin
 *  Added feature GPS_FEAT_RCV_TIMEOUT.
 *  Revision 1.30  2004/06/21 13:38:42  martin
 *  New flag MBG_OPT_BIT_EMU_SYNC/MBG_OPT_FLAG_EMU_SYNC
 *  lets the receicer emulate/pretend to be always synchronized.
 *  Revision 1.30  2004/06/21 13:35:46Z  martin
 *  Revision 1.29  2004/06/16 12:47:53Z  martin
 *  Moved OPT_SETTINGS related definitions from pcpsdefs.h
 *  here and renamed symbols from PCPS_.. to to MBG_...
 *  Revision 1.28  2004/03/26 10:37:00Z  martin
 *  Added definitions to support multiple ref sources.
 *  Added definitions OSC_DAC_RANGE, OSC_DAC_BIAS.
 *  Revision 1.27  2004/03/08 14:06:45Z  martin
 *  New model code and name for GPS169PCI.
 *  Existing feature GPS_FEAT_IRIG has been
 *  renamed to GPS_FEAT_IRIG_TX.
 *  Added feature GPS_FEAT_IRIG_RX.
 *  Added IPv4 LAN interface feature flags.
 *  Renamed IFLAGS_IGNORE_TFOM to IFLAGS_DISABLE_TFOM.
 *  Revision 1.26  2003/12/05 12:28:20Z  martin
 *  Added some codes used with IRIG cfg.
 *  Revision 1.25  2003/10/29 16:18:14Z  martin
 *  Added 7N2 to DEFAULT_GPS_FRAMINGS_GP2021.
 *  Revision 1.24  2003/09/30 08:49:48Z  martin
 *  New flag TM_LS_ANN_NEG which is set in addition to
 *  TM_LS_ANN if next leap second is negative.
 *  Revision 1.23  2003/08/26 14:32:33Z  martin
 *  Added some initializers for commonly used
 *  TZDL configurations.
 *  Revision 1.22  2003/04/25 10:18:11  martin
 *  Fixed typo inside an IRIG name string initializer.
 *  Revision 1.21  2003/04/15 09:18:48  martin
 *  New typedef ANT_CABLE_LEN.
 *  Revision 1.20  2003/04/03 11:03:44Z  martin
 *  Extended definitions for IRIG support.
 *  Revision 1.19  2003/01/31 13:38:20  MARTIN
 *  Modified type of RECEIVER_INFO::fixed_freq field.
 *  Revision 1.18  2002/10/28 09:24:07  MARTIN
 *  Added/renamed some POUT related symbols.
 *  Revision 1.17  2002/09/05 10:58:39  MARTIN
 *  Renamed some symbols related to programmable outputs.
 *  Revision 1.16  2002/08/29 08:04:47  martin
 *  Renamed structure POUT_PROG to POUT_SETTINGS.
 *  New structures POUT_SETTINGS_IDX, POUT_INFO,
 *  POUT_INFO_IDX and associated definitions.
 *  Updated some comments.
 *  Revision 1.15  2002/07/17 07:39:39Z  Andre
 *  comma added in definition DEFAULT_GPS_OSC_NAMES
 *  Revision 1.14  2002/06/27 12:17:29Z  MARTIN
 *  Added new oscillator code TCXO_MQ.
 *  Added initializer for oscillator names.
 *  Added initializer for oscillator list ordered by quality.
 *  Revision 1.13  2002/05/08 08:16:03  MARTIN
 *  Added GPS_OSC_CFG_SUPP for RECEIVER_INFO::flags.
 *  Fixed some comments.
 *  Revision 1.12  2002/03/14 13:45:56  MARTIN
 *  Changed type CSUM from short to ushort.
 *  Revision 1.11  2002/03/01 12:29:30  Andre
 *  Added GPS_MODEL_GPS161 and GPS_MODEL_NAME_GPS161.
 *  Revision 1.10  2002/02/25 08:02:33Z  MARTIN
 *  Added array of chars to union IDENT.
 *  Revision 1.9  2002/01/29 15:21:46  MARTIN
 *  Added new field "reserved" to struct SW_REV to fix C166 data
 *  alignment/structure size. Converted structure IDENT to a union.
 *  The changes above should not affect existing monitoring programs.
 *  New status flag TM_ANT_SHORT.
 *  New structure RECEIVER_INFO and associated definitions to
 *  enhance control from monitoring programs.
 *  New structures PORT_INFO, STR_TYPE_INFO, and associated
 *  definitions to simplify and unify configuration from external programs.
 *  New structures IRIG_INFO and POUT_PROG_IDX to configure an
 *  optional IRIG interface and programmable pulse outputs.
 *  Modified some comments.
 *  Revision 1.8  2001/03/30 11:44:11  MARTIN
 *  Control alignment of structures from new file use_pack.h.
 *  Defined initializers with valid baud rate and framing parameters.
 *  Modified some comments.
 *  Revision 1.7  2001/03/01 08:09:22  MARTIN
 *  Modified preprocessor syntax.
 *  Revision 1.6  2000/07/21 14:04:33  MARTIN
 *  Added som #if directives to protect structures against being multiply
 *  defined.
 *  Modified some comments.
 *  Comments using characters for +/- and degree now include ASCII
 *  characters only.
 *
 **************************************************************************/

#ifndef _GPSDEFS_H
#define _GPSDEFS_H


/* Other headers to be included */

#if defined( HAVE_CONFIG_H )
  // this is mainly to simplify usage in non-Meinberg projects
  #include <config.h>
#endif

// CLOCK_MEINBERG is defined in NTP's config.h if configured
// to support Meinberg clocks.
#if !defined( CLOCK_MEINBERG )
  // avoid having to use these headers in non-Meinberg projects
  #include <words.h>
  #include <use_pack.h>
#endif



/* Start of header body */

#if defined( _USE_PACK )
  #pragma pack( 1 )      // set byte alignment
  #define _USING_BYTE_ALIGNMENT
#endif



/* "magic" number */
#define MEINBERG_MAGIC 0x6AAC

/**
 * @brief GNSS satellite numbers
 *
 * @todo: Check if MAX_SVNO_GLN is 94 instead of 95, and thus
 *        N_SVNO_GLN is 30 instead of 31, as reported by Wikipedia.
 */
enum GNSS_SVNOS
{
  MIN_SVNO_GPS = 1,       ///< min. GPS satellite PRN number
  MAX_SVNO_GPS = 32,      ///< max. GPS satellite PRN number
  N_SVNO_GPS = 32,        ///< max. number of active GPS satellites

  MIN_SVNO_WAAS = 33,     ///< min. WAAS satellite number
  MAX_SVNO_WAAS = 64,     ///< max. WAAS satellite number
  N_SVNO_WAAS = 32,       ///< max. number of active WAAS satellites

  MIN_SVNO_GLONASS = 65,  ///< min. Glonass satellite number (64 + sat slot ID)
  MAX_SVNO_GLONASS = 95,  ///< max. Glonass satellite number (64 + sat slot ID)
  N_SVNO_GLONASS = 31     ///< max. number of active Glonass satellites
};

// for compatibility with GPS-only software:
#define MIN_SVNO   MIN_SVNO_GPS   ///< min. SV number
#define MAX_SVNO   MAX_SVNO_GPS   ///< max. SV number
#define N_SVNO     N_SVNO_GPS     ///< number of possibly active SVs



#define GPS_ID_STR_LEN      16
#define GPS_ID_STR_SIZE     ( GPS_ID_STR_LEN + 1 )

#define GPS_EPLD_STR_LEN    8
#define GPS_EPLD_STR_SIZE   ( GPS_EPLD_STR_LEN + 1 )


#define DEFAULT_GPS_TICKS_PER_SEC   10000000L  ///< system time base, see ::GPS_TICKS_PER_SEC

#if !defined( GPS_TICKS_PER_SEC )
  /*
   * The actual ticks per seconds may vary for different
   * GPS receiver models. If this is the case, the receiver
   * model support the ::RECEIVER_INFO structure which contains
   * the actual value.
   */
  #define GPS_TICKS_PER_SEC   DEFAULT_GPS_TICKS_PER_SEC  ///< see ::DEFAULT_GPS_TICKS_PER_SEC

#endif


typedef uint16_t SVNO;    ///< the number of an SV (Space Vehicle, i.e. satellite)
typedef uint16_t HEALTH;  ///< an SV's 6 bit health code
typedef uint16_t CFG;     ///< an SV's 4 bit configuration code
typedef uint16_t IOD;     ///< Issue-Of-Data code


/* the type of various checksums */

#ifndef _CSUM_DEFINED
  typedef uint16_t CSUM;  ///< checksum used by some structures stored in non-volatile memory
  #define _CSUM_DEFINED
#endif

#define _mbg_swab_csum( _p )    _mbg_swab16( _p )



/**
 * @brief The type of a GPS command code
 *
 * @see ::GPS_CMD_CODES
 * @see ::PC_GPS_CMD_CODES
 */
typedef uint16_t GPS_CMD;

#define _mbg_swab_gps_cmd( _p )    _mbg_swab16( _p )


/**
 * @brief Software revision information
 *
 * Contains a software revision code, plus an optional
 * identifier for a customized version.
 *
 * @see @ref group_ext_sys_info
 */
typedef struct
{
  uint16_t code;               ///< Version number, e.g. 0x0120 means v1.20
  char name[GPS_ID_STR_SIZE];  ///< Optional string identifying a customized firmware version, should be empty in standard versions
  uint8_t reserved;            ///< Reserved field to yield even structure size

} SW_REV;

#define _mbg_swab_sw_rev( _p )  \
do                              \
{                               \
  _mbg_swab16( &(_p)->code );   \
} while ( 0 )



/**
 * @defgroup group_bvar_stat Status of buffered (non-volatile) data
 *
 * Status word, associated bit numbers and bit masks indicating
 * whether certain data from the GPS satellites are
 * available and valid.
 *
 * These bits defined are set in ::BVAR_STAT if the corresponding
 * parameters are NOT valid and complete.
 *
 * @{ */

/**
 * @brief Status flags of battery buffered data
 *
 * Related to data received from the satellites, or data derived thereof.
 *
 * All '0' means OK, single bits set to '1' indicate
 * the associated type of GPS data is not available.
 *
 * @see ::BVAR_FLAGS
 */
typedef uint16_t BVAR_STAT;

#define _mbg_swab_bvar_stat( _p )  _mbg_swab16( (_p) )


/**
 * @brief Enumeration of flag bits used to define ::BVAR_FLAGS
 *
 * For each bit which is set this means the associated data set in
 * non-volatile memory is not available, or incomplete.
 * Most data sets will just be re-collected from the data streams sent
 * by the satellites. However, the receiver position has usually been
 * computed earlier during normal operation, and will be re-computed
 * when a sufficient number of satellites can be received.
 *
 * @see ::BVAR_STAT
 * @see ::BVAR_FLAGS
 * @see ::BVAR_FLAG_NAMES
 */
enum BVAR_FLAG_BITS
{
  BVAR_BIT_CFGH_INVALID,      ///< Satellite configuration and health parameters incomplete
  BVAR_BIT_ALM_NOT_COMPLETE,  ///< Almanac parameters incomplete
  BVAR_BIT_UTC_INVALID,       ///< %UTC offset parameters incomplete
  BVAR_BIT_IONO_INVALID,      ///< Ionospheric correction parameters incomplete
  BVAR_BIT_RCVR_POS_INVALID,  ///< No valid receiver position available
  N_BVAR_BIT                  ///< number of defined ::BVAR_STAT bits
};


/**
 * @brief Bit masks associated with ::BVAR_FLAG_BITS
 *
 * Used with ::BVAR_STAT.
 *
 * @see ::BVAR_STAT
 * @see ::BVAR_FLAG_BITS
 * @see ::BVAR_FLAG_NAMES
 */
enum BVAR_FLAGS
{
  BVAR_CFGH_INVALID     = ( 1UL << BVAR_BIT_CFGH_INVALID ),      ///< see ::BVAR_BIT_CFGH_INVALID
  BVAR_ALM_NOT_COMPLETE = ( 1UL << BVAR_BIT_ALM_NOT_COMPLETE ),  ///< see ::BVAR_BIT_ALM_NOT_COMPLETE
  BVAR_UTC_INVALID      = ( 1UL << BVAR_BIT_UTC_INVALID ),       ///< see ::BVAR_BIT_UTC_INVALID
  BVAR_IONO_INVALID     = ( 1UL << BVAR_BIT_IONO_INVALID ),      ///< see ::BVAR_BIT_IONO_INVALID
  BVAR_RCVR_POS_INVALID = ( 1UL << BVAR_BIT_RCVR_POS_INVALID ),  ///< see ::BVAR_BIT_RCVR_POS_INVALID
};

#define BVAR_MASK  ( ( 1UL << N_BVAR_BIT ) - 1 )       ///< Bit mask for all defined bits


/**
 * @brief String initializer for ::BVAR_STAT flag names
 *
 * @see ::BVAR_STAT
 * @see ::BVAR_FLAG_BITS
 * @see ::BVAR_FLAGS
 */
#define BVAR_FLAG_NAMES      \
{                            \
  "Sat. config and health",  \
  "Almanac",                 \
  "UTC offset",              \
  "Ionospheric correction",  \
  "Receiver position"        \
}

/** @} defgroup group_bvar_stat */



/**
 * @brief A structure used to hold a fixed frequency value
 *
 * @note frequ[kHz] = khz_val * 10^range
 */
typedef struct
{
  uint16_t khz_val;     ///< the base frequency in [kHz]
  int16_t range;        ///< an optional base 10 exponent

} FIXED_FREQ_INFO;

#define _mbg_swab_fixed_freq_info( _p )  \
do                                       \
{                                        \
  _mbg_swab16( &(_p)->khz_val );         \
  _mbg_swab16( &(_p)->range );           \
} while ( 0 )


/**
 * @brief A data type to specify feature flags within ::RECEIVER_INFO
 */
typedef uint32_t RI_FEATURES;     ///< see @ref GPS_FEATURE_MASKS



/**
 * @brief A structure used to identify a device type and supported features
 *
 * @note This may not be supported by some very old devices.
 */
typedef struct
{
  uint16_t model_code;               ///< identifier for receiver model, see ::GPS_MODEL_CODES
  SW_REV sw_rev;                     ///< software revision and ID
  char model_name[GPS_ID_STR_SIZE];  ///< ASCIIZ, name of receiver model
  char sernum[GPS_ID_STR_SIZE];      ///< ASCIIZ, serial number
  char epld_name[GPS_EPLD_STR_SIZE]; ///< ASCIIZ, file name of EPLD image (optional)
  uint8_t n_channels;                ///< number of satellites which can be tracked simultaneously
  uint32_t ticks_per_sec;            ///< resolution of fractions of seconds, see ::GPS_TICKS_PER_SEC
  RI_FEATURES features;              ///< optional features, see @ref GPS_FEATURE_MASKS
  FIXED_FREQ_INFO fixed_freq;        ///< optional non-standard fixed frequency, may be 0 if not supported
  uint8_t osc_type;                  ///< type of installed oscillator, see ::GPS_OSC_TYPES
  uint8_t osc_flags;                 ///< oscillator flags, actually not used and always 0
  uint8_t n_ucaps;                   ///< number of user time capture inputs
  uint8_t n_com_ports;               ///< number of on-board serial ports
  uint8_t n_str_type;                ///< max num of string types supported by any port
  uint8_t n_prg_out;                 ///< number of programmable pulse outputs
  uint16_t flags;                    ///< additional information, see ::RECEIVER_INFO_FLAG_MASKS

} RECEIVER_INFO;

#define _mbg_swab_receiver_info( _p )              \
do                                                 \
{                                                  \
  _mbg_swab16( &(_p)->model_code );                \
  _mbg_swab_sw_rev( &(_p)->sw_rev );               \
  _mbg_swab16( &(_p)->ticks_per_sec );             \
  _mbg_swab32( &(_p)->features );                  \
  _mbg_swab_fixed_freq_info( &(_p)->fixed_freq );  \
  _mbg_swab16( &(_p)->flags );                     \
} while ( 0 )


/**
 * @brief Known device ID codes for ::RECEIVER_INFO::model_code
 *
 * @see @ref GPS_MODEL_NAMES
 * @see ::DEFAULT_GPS_MODEL_NAMES
 */
enum GPS_MODEL_CODES
{
  GPS_MODEL_UNKNOWN,
  GPS_MODEL_GPS166,
  GPS_MODEL_GPS167,
  GPS_MODEL_GPS167SV,
  GPS_MODEL_GPS167PC,
  GPS_MODEL_GPS167PCI,
  GPS_MODEL_GPS163,
  GPS_MODEL_GPS168PCI,
  GPS_MODEL_GPS161,
  GPS_MODEL_GPS169PCI,
  GPS_MODEL_TCR167PCI,
  GPS_MODEL_GPS164,
  GPS_MODEL_GPS170PCI,
  GPS_MODEL_PZF511,
  GPS_MODEL_GPS170,
  GPS_MODEL_TCR511,
  GPS_MODEL_AM511,
  GPS_MODEL_MSF511,
  GPS_MODEL_GRC170,
  GPS_MODEL_GPS170PEX,
  GPS_MODEL_GPS162,
  GPS_MODEL_PTP270PEX,
  GPS_MODEL_FRC511PEX,
  GPS_MODEL_GEN170,
  GPS_MODEL_TCR170PEX,
  GPS_MODEL_WWVB511,
  GPS_MODEL_MGR170,
  GPS_MODEL_JJY511,
  GPS_MODEL_PZF600,
  GPS_MODEL_TCR600,
  GPS_MODEL_GPS180,
  GPS_MODEL_GLN170,
  GPS_MODEL_GPS180PEX,
  GPS_MODEL_TCR180PEX,
  GPS_MODEL_PZF180PEX,
  GPS_MODEL_MGR180,
  GPS_MODEL_MSF600,
  GPS_MODEL_WWVB600,
  GPS_MODEL_JJY600,
  GPS_MODEL_GPS180HS,
  GPS_MODEL_GPS180AMC,
  GPS_MODEL_ESI180,
  GPS_MODEL_CPE180,
  GPS_MODEL_LNO180,
  GPS_MODEL_GRC180,
  GPS_MODEL_LIU,
  GPS_MODEL_DCF600HS,
  GPS_MODEL_DCF600RS,
  GPS_MODEL_MRI,
  GPS_MODEL_BPE,
  GPS_MODEL_GLN180PEX,
  GPS_MODEL_N2X,
  GPS_MODEL_RSC180,
  GPS_MODEL_LNE_GB,
  GPS_MODEL_PPG180,
  GPS_MODEL_SCG,
  GPS_MODEL_MDU300,
  GPS_MODEL_SDI,
  GPS_MODEL_FDM180,
  GPS_MODEL_SPT,
  GPS_MODEL_PZF180,
  GPS_MODEL_REL1000,
  GPS_MODEL_HPS100,
  GPS_MODEL_VSG180,
  GPS_MODEL_MSF180,
  GPS_MODEL_WWVB180,
  GPS_MODEL_CPC180,
  GPS_MODEL_CTC100,
  GPS_MODEL_TCR180,
  GPS_MODEL_LUE180,
  GPS_MODEL_CPC_01,
  GPS_MODEL_TSU_01,
  GPS_MODEL_CMC_01,
  GPS_MODEL_SCU_01,
  GPS_MODEL_FCU_01,
  GPS_MODEL_CSM100,
  GPS_MODEL_LNE180SFP,
  GPS_MODEL_GTS180,
  GPS_MODEL_GPS180CSM,
  GPS_MODEL_GRC181,
  GPS_MODEL_N2X180,
  GPS_MODEL_GRC181PEX,
  GPS_MODEL_MDU180,
  GPS_MODEL_MDU312,
  GPS_MODEL_GPS165,
  GPS_MODEL_GNS181_UC,
  GPS_MODEL_PSX_4GE,
  GPS_MODEL_RSC180RDU,
  GPS_MODEL_USYNCPWR,
  GPS_MODEL_FDM180M,
  N_GPS_MODEL
  /* If new model codes are added then care must be taken
   * to update the associated string initializers GPS_MODEL_NAMES
   * and GPS_MODEL_NAME_TABLE accordingly, and to check whether
   * the classification macros also cover the new model names.
   */
};



/**
 * @brief Model name strings used with Meinberg devices
 *
 * String initializers for each of the device models
 * enumerated in ::GPS_MODEL_CODES.
 *
 * @see ::GPS_MODEL_CODES
 * @see ::DEFAULT_GPS_MODEL_NAMES
 *
 * @anchor GPS_MODEL_NAMES @{ */

#define GPS_MODEL_NAME_UNKNOWN   "Unknown"
#define GPS_MODEL_NAME_GPS166    "GPS166"
#define GPS_MODEL_NAME_GPS167    "GPS167"
#define GPS_MODEL_NAME_GPS167SV  "GPS167SV"
#define GPS_MODEL_NAME_GPS167PC  "GPS167PC"
#define GPS_MODEL_NAME_GPS167PCI "GPS167PCI"
#define GPS_MODEL_NAME_GPS163    "GPS163"
#define GPS_MODEL_NAME_GPS168PCI "GPS168PCI"
#define GPS_MODEL_NAME_GPS161    "GPS161"
#define GPS_MODEL_NAME_GPS169PCI "GPS169PCI"
#define GPS_MODEL_NAME_TCR167PCI "TCR167PCI"
#define GPS_MODEL_NAME_GPS164    "GPS164"
#define GPS_MODEL_NAME_GPS170PCI "GPS170PCI"
#define GPS_MODEL_NAME_PZF511    "PZF511"
#define GPS_MODEL_NAME_GPS170    "GPS170"
#define GPS_MODEL_NAME_TCR511    "TCR511"
#define GPS_MODEL_NAME_AM511     "AM511"
#define GPS_MODEL_NAME_MSF511    "MSF511"
#define GPS_MODEL_NAME_GRC170    "GRC170"
#define GPS_MODEL_NAME_GPS170PEX "GPS170PEX"
#define GPS_MODEL_NAME_GPS162    "GPS162"
#define GPS_MODEL_NAME_PTP270PEX "PTP270PEX"
#define GPS_MODEL_NAME_FRC511PEX "FRC511PEX"
#define GPS_MODEL_NAME_GEN170    "GEN170"
#define GPS_MODEL_NAME_TCR170PEX "TCR170PEX"
#define GPS_MODEL_NAME_WWVB511   "WWVB511"
#define GPS_MODEL_NAME_MGR170    "MGR170"
#define GPS_MODEL_NAME_JJY511    "JJY511"
#define GPS_MODEL_NAME_PZF600    "PZF600"
#define GPS_MODEL_NAME_TCR600    "TCR600"
#define GPS_MODEL_NAME_GPS180    "GPS180"
#define GPS_MODEL_NAME_GLN170    "GLN170"
#define GPS_MODEL_NAME_GPS180PEX "GPS180PEX"
#define GPS_MODEL_NAME_TCR180PEX "TCR180PEX"
#define GPS_MODEL_NAME_PZF180PEX "PZF180PEX"
#define GPS_MODEL_NAME_MGR180    "MGR180"
#define GPS_MODEL_NAME_MSF600    "MSF600"
#define GPS_MODEL_NAME_WWVB600   "WWVB600"
#define GPS_MODEL_NAME_JJY600    "JJY600"
#define GPS_MODEL_NAME_GPS180HS  "GPS180HS"
#define GPS_MODEL_NAME_GPS180AMC "GPS180AMC"
#define GPS_MODEL_NAME_ESI180    "ESI180"
#define GPS_MODEL_NAME_CPE180    "CPE180"
#define GPS_MODEL_NAME_LNO180    "LNO180"
#define GPS_MODEL_NAME_GRC180    "GRC180"
#define GPS_MODEL_NAME_LIU       "LIU"
#define GPS_MODEL_NAME_DCF600HS  "DCF600HS"
#define GPS_MODEL_NAME_DCF600RS  "DCF600RS"
#define GPS_MODEL_NAME_MRI       "MRI"
#define GPS_MODEL_NAME_BPE       "BPE"
#define GPS_MODEL_NAME_GLN180PEX "GLN180PEX"
#define GPS_MODEL_NAME_N2X       "N2X"
#define GPS_MODEL_NAME_RSC180    "RSC180"
#define GPS_MODEL_NAME_LNE_GB    "LNE_GB"
#define GPS_MODEL_NAME_PPG180    "PPG180"
#define GPS_MODEL_NAME_SCG       "SCG"
#define GPS_MODEL_NAME_MDU300    "MDU300"
#define GPS_MODEL_NAME_SDI       "SDI"
#define GPS_MODEL_NAME_FDM180    "FDM180"
#define GPS_MODEL_NAME_SPT       "SPT"
#define GPS_MODEL_NAME_PZF180    "PZF180"
#define GPS_MODEL_NAME_REL1000   "REL1000"
#define GPS_MODEL_NAME_HPS100    "HPS100"
#define GPS_MODEL_NAME_VSG180    "VSG180"
#define GPS_MODEL_NAME_MSF180    "MSF180"
#define GPS_MODEL_NAME_WWVB180   "WWVB180"
#define GPS_MODEL_NAME_CPC180    "CPC180"
#define GPS_MODEL_NAME_CTC100    "CTC100"
#define GPS_MODEL_NAME_TCR180    "TCR180"
#define GPS_MODEL_NAME_LUE180    "LUE180"
#define GPS_MODEL_NAME_CPC_01    "CPC_01"
#define GPS_MODEL_NAME_TSU_01    "TSU_01"
#define GPS_MODEL_NAME_CMC_01    "CMC_01"
#define GPS_MODEL_NAME_SCU_01    "SCU_01"
#define GPS_MODEL_NAME_FCU_01    "FCU_01"
#define GPS_MODEL_NAME_CSM100    "CSM100"
#define GPS_MODEL_NAME_LNE180SFP "LNE180SFP"
#define GPS_MODEL_NAME_GTS180    "GTS180"
#define GPS_MODEL_NAME_GPS180CSM "GPS180CSM"
#define GPS_MODEL_NAME_GRC181    "GRC181"
#define GPS_MODEL_NAME_N2X180    "N2X180"
#define GPS_MODEL_NAME_GRC181PEX "GRC181PEX"
#define GPS_MODEL_NAME_MDU180    "MDU180"
#define GPS_MODEL_NAME_MDU312    "MDU312"
#define GPS_MODEL_NAME_GPS165    "GPS165"
#define GPS_MODEL_NAME_GNS181_UC "GNS181_UC"
#define GPS_MODEL_NAME_PSX_4GE   "PSX_4GE"
#define GPS_MODEL_NAME_RSC180RDU "RSC180RDU"
#define GPS_MODEL_NAME_USYNCPWR  "MICROSYNC-PWR"
#define GPS_MODEL_NAME_FDM180M   "FDM180M"

/** @} anchor GPS_MODEL_NAMES */



/**
 * @brief An initializer for a table of device names
 *
 * Can be used to initialize an array of ::N_GPS_MODEL
 * type name strings.
 *
 * @note Including the trailing 0, each name must not
 * exceed ::GPS_ID_STR_SIZE chars.
 *
 * @see ::GPS_MODEL_CODES
 * @see @ref GPS_MODEL_NAMES
 */
#define DEFAULT_GPS_MODEL_NAMES \
{                               \
  GPS_MODEL_NAME_UNKNOWN,       \
  GPS_MODEL_NAME_GPS166,        \
  GPS_MODEL_NAME_GPS167,        \
  GPS_MODEL_NAME_GPS167SV,      \
  GPS_MODEL_NAME_GPS167PC,      \
  GPS_MODEL_NAME_GPS167PCI,     \
  GPS_MODEL_NAME_GPS163,        \
  GPS_MODEL_NAME_GPS168PCI,     \
  GPS_MODEL_NAME_GPS161,        \
  GPS_MODEL_NAME_GPS169PCI,     \
  GPS_MODEL_NAME_TCR167PCI,     \
  GPS_MODEL_NAME_GPS164,        \
  GPS_MODEL_NAME_GPS170PCI,     \
  GPS_MODEL_NAME_PZF511,        \
  GPS_MODEL_NAME_GPS170,        \
  GPS_MODEL_NAME_TCR511,        \
  GPS_MODEL_NAME_AM511,         \
  GPS_MODEL_NAME_MSF511,        \
  GPS_MODEL_NAME_GRC170,        \
  GPS_MODEL_NAME_GPS170PEX,     \
  GPS_MODEL_NAME_GPS162,        \
  GPS_MODEL_NAME_PTP270PEX,     \
  GPS_MODEL_NAME_FRC511PEX,     \
  GPS_MODEL_NAME_GEN170,        \
  GPS_MODEL_NAME_TCR170PEX,     \
  GPS_MODEL_NAME_WWVB511,       \
  GPS_MODEL_NAME_MGR170,        \
  GPS_MODEL_NAME_JJY511,        \
  GPS_MODEL_NAME_PZF600,        \
  GPS_MODEL_NAME_TCR600,        \
  GPS_MODEL_NAME_GPS180,        \
  GPS_MODEL_NAME_GLN170,        \
  GPS_MODEL_NAME_GPS180PEX,     \
  GPS_MODEL_NAME_TCR180PEX,     \
  GPS_MODEL_NAME_PZF180PEX,     \
  GPS_MODEL_NAME_MGR180,        \
  GPS_MODEL_NAME_MSF600,        \
  GPS_MODEL_NAME_WWVB600,       \
  GPS_MODEL_NAME_JJY600,        \
  GPS_MODEL_NAME_GPS180HS,      \
  GPS_MODEL_NAME_GPS180AMC,     \
  GPS_MODEL_NAME_ESI180,        \
  GPS_MODEL_NAME_CPE180,        \
  GPS_MODEL_NAME_LNO180,        \
  GPS_MODEL_NAME_GRC180,        \
  GPS_MODEL_NAME_LIU,           \
  GPS_MODEL_NAME_DCF600HS,      \
  GPS_MODEL_NAME_DCF600RS,      \
  GPS_MODEL_NAME_MRI,           \
  GPS_MODEL_NAME_BPE,           \
  GPS_MODEL_NAME_GLN180PEX,     \
  GPS_MODEL_NAME_N2X,           \
  GPS_MODEL_NAME_RSC180,        \
  GPS_MODEL_NAME_LNE_GB,        \
  GPS_MODEL_NAME_PPG180,        \
  GPS_MODEL_NAME_SCG,           \
  GPS_MODEL_NAME_MDU300,        \
  GPS_MODEL_NAME_SDI,           \
  GPS_MODEL_NAME_FDM180,        \
  GPS_MODEL_NAME_SPT,           \
  GPS_MODEL_NAME_PZF180,        \
  GPS_MODEL_NAME_REL1000,       \
  GPS_MODEL_NAME_HPS100,        \
  GPS_MODEL_NAME_VSG180,        \
  GPS_MODEL_NAME_MSF180,        \
  GPS_MODEL_NAME_WWVB180,       \
  GPS_MODEL_NAME_CPC180,        \
  GPS_MODEL_NAME_CTC100,        \
  GPS_MODEL_NAME_TCR180,        \
  GPS_MODEL_NAME_LUE180,        \
  GPS_MODEL_NAME_CPC_01,        \
  GPS_MODEL_NAME_TSU_01,        \
  GPS_MODEL_NAME_CMC_01,        \
  GPS_MODEL_NAME_SCU_01,        \
  GPS_MODEL_NAME_FCU_01,        \
  GPS_MODEL_NAME_CSM100,        \
  GPS_MODEL_NAME_LNE180SFP,     \
  GPS_MODEL_NAME_GTS180,        \
  GPS_MODEL_NAME_GPS180CSM,     \
  GPS_MODEL_NAME_GRC181,        \
  GPS_MODEL_NAME_N2X180,        \
  GPS_MODEL_NAME_GRC181PEX,     \
  GPS_MODEL_NAME_MDU180,        \
  GPS_MODEL_NAME_MDU312,        \
  GPS_MODEL_NAME_GPS165,        \
  GPS_MODEL_NAME_GNS181_UC,     \
  GPS_MODEL_NAME_PSX_4GE,       \
  GPS_MODEL_NAME_RSC180RDU,     \
  GPS_MODEL_NAME_USYNCPWR,      \
  GPS_MODEL_NAME_FDM180M        \
}



/**
 * @brief Definitions used to classify devices and built-in features
 *
 * @see ::GPS_MODEL_CODES
 * @see ::GPS_BUILTIN_FEATURE_BITS
 * @see @ref GPS_BUILTIN_FEATURE_MASKS
 *
 * @anchor GPS_BUILTIN_FEATURE_DEFS @{ */


/**
 * @brief Enumeration of classifiers and built-in features
 *
 * @see ::GPS_MODEL_CODES
 * @see @ref GPS_BUILTIN_FEATURE_MASKS
 */
enum GPS_BUILTIN_FEATURE_BITS
{
  GPS_BIT_MODEL_IS_GPS,
  GPS_BIT_MODEL_IS_GNSS,
  GPS_BIT_MODEL_IS_TCR,
  GPS_BIT_MODEL_IS_DCF_AM,
  GPS_BIT_MODEL_IS_DCF_PZF,
  GPS_BIT_MODEL_IS_MSF,
  GPS_BIT_MODEL_IS_JJY,
  GPS_BIT_MODEL_IS_WWVB,

  GPS_BIT_MODEL_IS_BUS_LVL_DEV,
  GPS_BIT_MODEL_HAS_BVAR_STAT,
  GPS_BIT_MODEL_HAS_POS_XYZ,
  GPS_BIT_MODEL_HAS_POS_LLA,
  GPS_BIT_MODEL_HAS_TIME_TTM,
  GPS_BIT_MODEL_HAS_TZDL,
  GPS_BIT_MODEL_HAS_TZCODE,
  GPS_BIT_MODEL_HAS_ANT_INFO,

  GPS_BIT_MODEL_HAS_ENABLE_FLAGS,
  GPS_BIT_MODEL_HAS_STAT_INFO,
  GPS_BIT_MODEL_HAS_ANT_CABLE_LEN,
  GPS_BIT_MODEL_HAS_SCU_STAT,
  GPS_BIT_MODEL_HAS_SV_INFO,

  GPS_BIT_MODEL_HAS_XMR_HOLDOVER_INTV,

#if 0  //### TODO This has to be discussed
  GPS_BIT_MODEL_IS_LNO,
  GPS_BIT_MODEL_IS_SCU,
#endif

  N_GPS_BUILTIN_FEATURE_BITS
};



/**
 * @brief Bit masks associated with classifiers and built-in features
 *
 * @see ::GPS_MODEL_CODES
 * @see ::GPS_BUILTIN_FEATURE_BITS
 *
 * @anchor GPS_BUILTIN_FEATURE_MASKS @{ */

#define GPS_MODEL_IS_GPS                  ( 1UL << GPS_BIT_MODEL_IS_GPS )                 ///< see ::GPS_BIT_MODEL_IS_GPS
#define GPS_MODEL_IS_GNSS                 ( 1UL << GPS_BIT_MODEL_IS_GNSS )                ///< see ::GPS_BIT_MODEL_IS_GNSS
#define GPS_MODEL_IS_TCR                  ( 1UL << GPS_BIT_MODEL_IS_TCR )                 ///< see ::GPS_BIT_MODEL_IS_TCR
#define GPS_MODEL_IS_DCF_AM               ( 1UL << GPS_BIT_MODEL_IS_DCF_AM )              ///< see ::GPS_BIT_MODEL_IS_DCF_AM
#define GPS_MODEL_IS_DCF_PZF              ( 1UL << GPS_BIT_MODEL_IS_DCF_PZF )             ///< see ::GPS_BIT_MODEL_IS_DCF_PZF
#define GPS_MODEL_IS_MSF                  ( 1UL << GPS_BIT_MODEL_IS_MSF )                 ///< see ::GPS_BIT_MODEL_IS_MSF
#define GPS_MODEL_IS_JJY                  ( 1UL << GPS_BIT_MODEL_IS_JJY )                 ///< see ::GPS_BIT_MODEL_IS_JJY
#define GPS_MODEL_IS_WWVB                 ( 1UL << GPS_BIT_MODEL_IS_WWVB )                ///< see ::GPS_BIT_MODEL_IS_WWVB

#define GPS_MODEL_IS_BUS_LVL_DEV          ( 1UL << GPS_BIT_MODEL_IS_BUS_LVL_DEV )         ///< see ::GPS_BIT_MODEL_IS_BUS_LVL_DEV
#define GPS_MODEL_HAS_BVAR_STAT           ( 1UL << GPS_BIT_MODEL_HAS_BVAR_STAT )          ///< see ::GPS_BIT_MODEL_HAS_BVAR_STAT
#define GPS_MODEL_HAS_POS_XYZ             ( 1UL << GPS_BIT_MODEL_HAS_POS_XYZ )            ///< see ::GPS_BIT_MODEL_HAS_POS_XYZ
#define GPS_MODEL_HAS_POS_LLA             ( 1UL << GPS_BIT_MODEL_HAS_POS_LLA )            ///< see ::GPS_BIT_MODEL_HAS_POS_LLA
#define GPS_MODEL_HAS_TIME_TTM            ( 1UL << GPS_BIT_MODEL_HAS_TIME_TTM )           ///< see ::GPS_BIT_MODEL_HAS_TIME_TTM
#define GPS_MODEL_HAS_TZDL                ( 1UL << GPS_BIT_MODEL_HAS_TZDL )               ///< see ::GPS_BIT_MODEL_HAS_TZDL
#define GPS_MODEL_HAS_TZCODE              ( 1UL << GPS_BIT_MODEL_HAS_TZCODE )             ///< see ::GPS_BIT_MODEL_HAS_TZCODE
#define GPS_MODEL_HAS_ANT_INFO            ( 1UL << GPS_BIT_MODEL_HAS_ANT_INFO )           ///< see ::GPS_BIT_MODEL_HAS_ANT_INFO

#define GPS_MODEL_HAS_ENABLE_FLAGS        ( 1UL << GPS_BIT_MODEL_HAS_ENABLE_FLAGS )       ///< see ::GPS_BIT_MODEL_HAS_ENABLE_FLAGS
#define GPS_MODEL_HAS_STAT_INFO           ( 1UL << GPS_BIT_MODEL_HAS_STAT_INFO )          ///< see ::GPS_BIT_MODEL_HAS_STAT_INFO
#define GPS_MODEL_HAS_ANT_CABLE_LEN       ( 1UL << GPS_BIT_MODEL_HAS_ANT_CABLE_LEN )      ///< see ::GPS_BIT_MODEL_HAS_ANT_CABLE_LEN
#define GPS_MODEL_HAS_SCU_STAT            ( 1UL << GPS_BIT_MODEL_HAS_SCU_STAT )           ///< see ::GPS_BIT_MODEL_HAS_SCU_STAT
#define GPS_MODEL_HAS_SV_INFO             ( 1UL << GPS_BIT_MODEL_HAS_SV_INFO )            ///< see ::GPS_BIT_MODEL_HAS_SV_INFO

#if 0  // ### TODO This has to be discussed
  #define GPS_MODEL_IS_LNO                  ( 1UL << GPS_BIT_MODEL_IS_LNO )                 ///< see ::GPS_BIT_MODEL_IS_LNO
  #define GPS_MODEL_IS_SCU                  ( 1UL << GPS_BIT_MODEL_IS_SCU )                 ///< see ::GPS_BIT_MODEL_IS_SCU
#endif

// ### TODO do we need the next one?
#define GPS_MODEL_HAS_XMR_HOLDOVER_INTV   ( 1UL << GPS_BIT_MODEL_HAS_XMR_HOLDOVER_INTV )  ///< see ::GPS_BIT_MODEL_HAS_XMR_HOLDOVER_INTV

//### TODO: should we use an extra flag?
#define GPS_MODEL_HAS_POS ( GPS_MODEL_HAS_POS_XYZ | GPS_MODEL_HAS_POS_LLA )

/** @} anchor GPS_BUILTIN_FEATURE_MASKS */


#if 0  //##++ more potential builtin features and classifiers

  GPS_MODEL_HAS_CFGH |    \
  GPS_MODEL_HAS_ALM  |    \
  GPS_MODEL_HAS_EPH  |    \
  GPS_MODEL_HAS_UTC  |    \
  GPS_MODEL_HAS_IONO      \

#define GPS_MODEL_HAS_AUTO_ON                   // --
#define GPS_MODEL_HAS_AUTO_OFF                  // --
#define GPS_MODEL_HAS_SW_REV                    // deprecated, use only if ri not supported
#define GPS_MODEL_HAS_BVAR_STAT                 // req
#define GPS_MODEL_HAS_POS_XYZ                   // GPS_MODEL_IS_GPS, GPS_MODEL_HAS_POS, GPS_MODEL_HAS_POS_XYZ ?
#define GPS_MODEL_HAS_POS_LLA                   // GPS_MODEL_IS_GPS, GPS_MODEL_HAS_POS, GPS_MODEL_HAS_POS_LLA ?
#define GPS_MODEL_HAS_TZDL                      // req
#define GPS_MODEL_HAS_PORT_PARM                 // deprecated, use only if ri not supported
#define GPS_MODEL_HAS_SYNTH                     // ri GPS_HAS_SYNTH
#define GPS_MODEL_HAS_ANT_INFO                  // GPS_MODEL_IS_GPS, also GNSS, or req?
#define GPS_MODEL_HAS_UCAP                      // ri n_ucap
#define GPS_MODEL_HAS_ENABLE_FLAGS              // req
#define GPS_MODEL_HAS_STAT_INFO                 // req
#define GPS_MODEL_HAS_SWITCH_PARMS              // deprecated, use ...
#define GPS_MODEL_HAS_STRING_PARMS              // deprecated, use ...
#define GPS_MODEL_HAS_ANT_CABLE_LEN             // GPS_MODEL_IS_GPS, also GNSS, or req?
#define GPS_MODEL_HAS_SYNC_OUTAGE_DELAY         // custom
#define GPS_MODEL_HAS_PULSE_INFO                // custom
#define GPS_MODEL_HAS_OPT_FEATURES              // deprecated, use ri
#define GPS_MODEL_HAS_IRIG_TX_SETTINGS          // ri GPS_HAS_IRIG_TX
#define GPS_MODEL_HAS_RECEIVER_INFO             // --
#define GPS_MODEL_HAS_STR_TYPE_INFO_IDX         // ri n_str_type
#define GPS_MODEL_HAS_PORT_INFO_IDX             // ri n_com
#define GPS_MODEL_HAS_PORT_SETTINGS_IDX         // ri n_com
#define GPS_MODEL_HAS_POUT_INFO_IDX             // ri n_pout
#define GPS_MODEL_HAS_POUT_SETTINGS_IDX         // ri n_pout
#define GPS_MODEL_HAS_IRIG_TX_INFO              // ri GPS_HAS_IRIG_TX
#define GPS_MODEL_HAS_MULTI_REF_SETTINGS        // ri GPS_HAS_MULTI_REF
#define GPS_MODEL_HAS_MULTI_REF_INFO            // ri GPS_HAS_MULTI_REF
#define GPS_MODEL_HAS_ROM_CSUM                  // ?
#define GPS_MODEL_HAS_MULTI_REF_STATUS          // ri ...
#define GPS_MODEL_HAS_RCV_TIMEOUT               // ri ...
#define GPS_MODEL_HAS_IRIG_RX_SETTINGS          // ri ...
#define GPS_MODEL_HAS_IRIG_RX_INFO              // ri ...
#define GPS_MODEL_HAS_REF_OFFS                  // ri ...
#define GPS_MODEL_HAS_DEBUG_STATUS              //
#define GPS_MODEL_HAS_XMR_SETTINGS_IDX          //
#define GPS_MODEL_HAS_XMR_INFO_IDX              //
#define GPS_MODEL_HAS_XMR_STATUS_IDX            //
#define GPS_MODEL_HAS_OPT_SETTINGS              //
#define GPS_MODEL_HAS_OPT_INFO                  //
#define GPS_MODEL_HAS_CLR_UCAP_BUFF             //
#define GPS_MODEL_HAS_TIME_SCALE                //
#define GPS_MODEL_HAS_NAV_ENG_SETTINGS          //
#define GPS_MODEL_HAS_RAW_IRIG_DATA             //
#define GPS_MODEL_HAS_GPIO_CFG_LIMITS           //
#define GPS_MODEL_HAS_GPIO_INFO_IDX             //
#define GPS_MODEL_HAS_GPIO_SETTINGS_IDX         //
#define GPS_MODEL_HAS_XMR_INSTANCES             //
#define GPS_MODEL_HAS_CLR_EVT_LOG               //
#define GPS_MODEL_HAS_NUM_EVT_LOG_ENTRIES       //
#define GPS_MODEL_HAS_FIRST_EVT_LOG_ENTRY       //
#define GPS_MODEL_HAS_NEXT_EVT_LOG_ENTRY        //
#define GPS_MODEL_HAS_LNO_STATUS                //
#define GPS_MODEL_HAS_IMS_STATE                 //
#define GPS_MODEL_HAS_IMS_SENSOR_STATE_IDX      //
#define GPS_MODEL_HAS_XMR_HOLDOVER_INTV         //
#define GPS_MODEL_HAS_HAVEQUICK_RX_SETTINGS     //
#define GPS_MODEL_HAS_HAVEQUICK_RX_INFO         //
#define GPS_MODEL_HAS_HAVEQUICK_TX_SETTINGS     //
#define GPS_MODEL_HAS_HAVEQUICK_TX_INFO         //
#define GPS_MODEL_HAS_PTP_CFG                   //
#define GPS_MODEL_HAS_PTP_STATE                 //
#define GPS_MODEL_HAS_PTP_UC_MASTER_CFG_LIMITS  //
#define GPS_MODEL_HAS_PTP_UC_MASTER_CFG         //
#define GPS_MODEL_HAS_NTP_GLB_CFG               //
#define GPS_MODEL_HAS_NTP_CLNT_MODE_CFG         //
#define GPS_MODEL_HAS_NTP_SRV_MODE_CFG          //
#define GPS_MODEL_HAS_NTP_PEER_SETTINGS_IDX     //
#define GPS_MODEL_HAS_NTP_SYS_STATE             //
#define GPS_MODEL_HAS_NTP_PEER_STATE_IDX        //
#define GPS_MODEL_HAS_SHS                       //
#define GPS_MODEL_HAS_SHS_STATUS                //
#define GPS_MODEL_HAS_NET_GLB_CFG               //
#define GPS_MODEL_HAS_NET_DNS_SRVR              //
#define GPS_MODEL_HAS_NET_DNS_SRCH_DOM          //
#define GPS_MODEL_HAS_NET_STAT_DNS_SRVR         //
#define GPS_MODEL_HAS_NET_STAT_DNS_SRCH_DOM     //
#define GPS_MODEL_HAS_GNSS_SAT_INFO_IDX         //

#define GPS_MODEL_HAS_CFGH                      //
#define GPS_MODEL_HAS_ALM                       //
#define GPS_MODEL_HAS_EPH                       //
#define GPS_MODEL_HAS_UTC                       //
#define GPS_MODEL_HAS_IONO                      //
#define GPS_MODEL_HAS_ASCII_MSG                 //

#define GPS_MODEL_HAS_GLNS_ALM                  //
#define GPS_MODEL_HAS_GNSS_SAT_INFO             //
//#define GPS_MODEL_HAS_GNSS_MODE                 //

#define GPS_MODEL_HAS_IP4_SETTINGS              //
#define GPS_MODEL_HAS_LAN_IF_INFO               //
#define GPS_MODEL_HAS_IP4_STATE                 //

#define GPS_MODEL_HAS_CRYPTED_PACKET            //
#define GPS_MODEL_HAS_CRYPTED_RAW_PACKET        //

#define GPS_MODEL_HAS_SECU_INFO                 //
#define GPS_MODEL_HAS_SECU_SETTINGS             //
#define GPS_MODEL_HAS_SECU_PUBLIC_KEY           //

#endif  //##++ more potential builtin features and classifiers



/**
 * @brief Common builtin features of all GPS receivers
 *
 * @see ::BUILTIN_FEAT_GPS_BUS_LVL
 * @see ::BUILTIN_FEAT_GNSS
 */
#define BUILTIN_FEAT_GPS           \
(                                  \
  GPS_MODEL_IS_GPS               | \
  GPS_MODEL_HAS_BVAR_STAT        | \
  GPS_MODEL_HAS_POS_XYZ          | \
  GPS_MODEL_HAS_POS_LLA          | \
  GPS_MODEL_HAS_TIME_TTM         | \
  GPS_MODEL_HAS_TZDL             | \
  GPS_MODEL_HAS_ANT_INFO         | \
  GPS_MODEL_HAS_ENABLE_FLAGS     | \
  GPS_MODEL_HAS_STAT_INFO        | \
  GPS_MODEL_HAS_ANT_CABLE_LEN    | \
  GPS_MODEL_HAS_SV_INFO            \
)


/**
 * @brief Common builtin features of all GNSS receivers
 *
 * GNSS includes GPS but optionally other satellite systems,
 * and the associated API.
 *
 * @see ::BUILTIN_FEAT_GNSS_BUS_LVL
 * @see ::BUILTIN_FEAT_GPS
 */
#define BUILTIN_FEAT_GNSS   \
(                           \
  BUILTIN_FEAT_GPS        | \
  GPS_MODEL_IS_GNSS         \
)



/**
 * @brief Common builtin features of all simple TCR devices
 */
#define BUILTIN_FEAT_TCR_1  \
(                           \
  GPS_MODEL_IS_TCR          \
)


/**
 * @brief Common builtin features of all enhanced TCR devices
 */
#define BUILTIN_FEAT_TCR_2      \
(                               \
  GPS_MODEL_IS_TCR            | \
  GPS_MODEL_HAS_TIME_TTM      | \
  GPS_MODEL_HAS_TZDL          | \
  GPS_MODEL_HAS_ANT_INFO      | \
  GPS_MODEL_HAS_ENABLE_FLAGS    \
)



/**
 * @brief Common builtin features of all simple DCF77 AM receivers
 */
#define BUILTIN_FEAT_DCF_1  \
(                           \
  GPS_MODEL_IS_DCF_AM     | \
  GPS_MODEL_HAS_TZCODE      \
)


/**
 * @brief Common builtin features of all enhanced DCF77 AM receivers
 */
#define BUILTIN_FEAT_DCF_2      \
(                               \
  GPS_MODEL_IS_DCF_AM         | \
  GPS_MODEL_HAS_TIME_TTM      | \
  GPS_MODEL_HAS_TZDL          | \
  GPS_MODEL_HAS_ANT_INFO      | \
  GPS_MODEL_HAS_ENABLE_FLAGS    \
)


/**
 * @brief Common builtin features of all simple DCF77 PZF receivers
 */
#define BUILTIN_FEAT_DCF_PZF_1  \
(                               \
  GPS_MODEL_IS_DCF_PZF        | \
  GPS_MODEL_HAS_TZCODE          \
)


/**
 * @brief Common builtin features of all enhanced DCF77 PZF receivers
 */
#define BUILTIN_FEAT_DCF_PZF_2  \
(                               \
  GPS_MODEL_IS_DCF_PZF        | \
  GPS_MODEL_HAS_TIME_TTM      | \
  GPS_MODEL_HAS_TZDL          | \
  GPS_MODEL_HAS_ANT_INFO      | \
  GPS_MODEL_HAS_ENABLE_FLAGS    \
)



/**
 * @brief Common builtin features of all simple MSF receivers
 */
#define BUILTIN_FEAT_MSF_1  \
(                           \
  GPS_MODEL_IS_MSF        | \
  GPS_MODEL_HAS_TZCODE      \
)


/**
 * @brief Common builtin features of all enhanced MSF receivers
 */
#define BUILTIN_FEAT_MSF_2      \
(                               \
  GPS_MODEL_IS_MSF            | \
  GPS_MODEL_HAS_TIME_TTM      | \
  GPS_MODEL_HAS_TZDL          | \
  GPS_MODEL_HAS_ANT_INFO      | \
  GPS_MODEL_HAS_ENABLE_FLAGS    \
)



/**
 * @brief Common builtin features of all simple WWVB receivers
 */
#define BUILTIN_FEAT_WVB_1  \
(                           \
  GPS_MODEL_IS_WWVB       | \
  GPS_MODEL_HAS_TZCODE      \
)


/**
 * @brief Common builtin features of all enhanced WWVB receivers
 */
#define BUILTIN_FEAT_WVB_2  \
(                           \
  GPS_MODEL_IS_WWVB       | \
  GPS_MODEL_HAS_TZDL        \
)



/**
 * @brief Common builtin features of all simple JJY receivers
 */
#define BUILTIN_FEAT_JJY_1  \
(                           \
  GPS_MODEL_IS_JJY        | \
  GPS_MODEL_HAS_TZCODE      \
)



/**
 * @brief Common builtin features of all N2X devices
 */
#define BUILTIN_FEAT_COMM_N2X   \
(                               \
  GPS_MODEL_HAS_TIME_TTM      | \
  GPS_MODEL_HAS_TZDL          | \
  GPS_MODEL_HAS_ENABLE_FLAGS    \
)



/**
 * @brief Common builtin features of all bus-level GPS receivers
 */
#define BUILTIN_FEAT_GPS_BUS_LVL  ( BUILTIN_FEAT_GPS | GPS_MODEL_IS_BUS_LVL_DEV )


/**
 * @brief Common builtin features of all bus-level GNSS receivers
 */
#define BUILTIN_FEAT_GNSS_BUS_LVL  ( BUILTIN_FEAT_GNSS | GPS_MODEL_IS_BUS_LVL_DEV )


/**
 * @brief Common builtin features of all simple, bus-level TCR devices
 */
#define BUILTIN_FEAT_TCR_1_BUS_LVL  ( BUILTIN_FEAT_TCR_1 | GPS_MODEL_IS_BUS_LVL_DEV )

/**
 * @brief Common builtin features of all enhanced, bus-level TCR devices
 */
#define BUILTIN_FEAT_TCR_2_BUS_LVL  ( BUILTIN_FEAT_TCR_2 | GPS_MODEL_IS_BUS_LVL_DEV )


/**
 * @brief Common builtin features of all simple, bus-level DCF77 AM receivers
 */
#define BUILTIN_FEAT_DCF_1_BUS_LVL  ( BUILTIN_FEAT_DCF_1 | GPS_MODEL_IS_BUS_LVL_DEV )

/**
 * @brief Common builtin features of all enhanced, bus-level DCF77 AM receivers
 */
#define BUILTIN_FEAT_DCF_2_BUS_LVL  ( BUILTIN_FEAT_DCF_2 | GPS_MODEL_IS_BUS_LVL_DEV )

/**
 * @brief Common builtin features of all enhanced, bus-level DCF77 PZF receivers
 */
#define BUILTIN_FEAT_DCF_PZF_2_BUS_LVL  ( BUILTIN_FEAT_DCF_PZF_2 | GPS_MODEL_IS_BUS_LVL_DEV )



/**
 * @brief Definitions of builtin features per device type
 *
 * @see ::GPS_MODEL_CODES
 * @see @ref GPS_MODEL_BUILTIN_FEATURES
 *
 * @anchor GPS_MODEL_BUILTIN_FEATURE_MASKS @{ */

#define BUILTIN_FEAT_GPS166     ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GPS167     ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GPS167SV   ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GPS167PC   ( BUILTIN_FEAT_GPS_BUS_LVL )
#define BUILTIN_FEAT_GPS167PCI  ( BUILTIN_FEAT_GPS_BUS_LVL )
#define BUILTIN_FEAT_GPS163     ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GPS168PCI  ( BUILTIN_FEAT_GPS_BUS_LVL )
#define BUILTIN_FEAT_GPS161     ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GPS169PCI  ( BUILTIN_FEAT_GPS_BUS_LVL )
#define BUILTIN_FEAT_TCR167PCI  ( BUILTIN_FEAT_TCR_2_BUS_LVL )
#define BUILTIN_FEAT_GPS164     ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GPS170PCI  ( BUILTIN_FEAT_GPS_BUS_LVL )
#define BUILTIN_FEAT_PZF511     ( BUILTIN_FEAT_DCF_PZF_1 )
#define BUILTIN_FEAT_GPS170     ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_TCR511     ( BUILTIN_FEAT_TCR_1_BUS_LVL | GPS_MODEL_HAS_TIME_TTM )  //### TODO Or full TCR_2?
#define BUILTIN_FEAT_AM511      ( BUILTIN_FEAT_DCF_1 )
#define BUILTIN_FEAT_MSF511     ( BUILTIN_FEAT_MSF_1 )
#define BUILTIN_FEAT_GRC170     ( BUILTIN_FEAT_GNSS )
#define BUILTIN_FEAT_GPS170PEX  ( BUILTIN_FEAT_GPS_BUS_LVL )
#define BUILTIN_FEAT_GPS162     ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_PTP270PEX  ( GPS_MODEL_IS_BUS_LVL_DEV )
#define BUILTIN_FEAT_FRC511PEX  ( GPS_MODEL_IS_BUS_LVL_DEV )
#define BUILTIN_FEAT_GEN170     ( 0 )
#define BUILTIN_FEAT_TCR170PEX  ( BUILTIN_FEAT_TCR_2_BUS_LVL )
#define BUILTIN_FEAT_WWVB511    ( BUILTIN_FEAT_WVB_1 )
#define BUILTIN_FEAT_MGR170     ( 0 )
#define BUILTIN_FEAT_JJY511     ( BUILTIN_FEAT_JJY_1 )
#define BUILTIN_FEAT_PZF600     ( BUILTIN_FEAT_DCF_PZF_1 )                       //### TODO Or full PZF_2?
#define BUILTIN_FEAT_TCR600     ( BUILTIN_FEAT_TCR_1 | GPS_MODEL_HAS_TIME_TTM )  //### TODO Or full TCR_2?
#define BUILTIN_FEAT_GPS180     ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GLN170     ( BUILTIN_FEAT_GNSS)
#define BUILTIN_FEAT_GPS180PEX  ( BUILTIN_FEAT_GPS_BUS_LVL )
#define BUILTIN_FEAT_TCR180PEX  ( BUILTIN_FEAT_TCR_2_BUS_LVL )
#define BUILTIN_FEAT_PZF180PEX  ( BUILTIN_FEAT_DCF_PZF_2_BUS_LVL )
#define BUILTIN_FEAT_MGR180     ( 0 )
#define BUILTIN_FEAT_MSF600     ( BUILTIN_FEAT_MSF_1 )                           //### TODO Or full MSF_2?
#define BUILTIN_FEAT_WWVB600    ( BUILTIN_FEAT_WVB_1 )                           //### TODO Or full WVB_2?
#define BUILTIN_FEAT_JJY600     ( BUILTIN_FEAT_JJY_1 )                           //### TODO Or full JJY_2?
#define BUILTIN_FEAT_GPS180HS   ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GPS180AMC  ( BUILTIN_FEAT_GPS_BUS_LVL )
#define BUILTIN_FEAT_ESI180     ( 0 )
#define BUILTIN_FEAT_CPE180     ( 0 )
#define BUILTIN_FEAT_LNO180     ( 0 )
#define BUILTIN_FEAT_GRC180     ( BUILTIN_FEAT_GNSS )
#define BUILTIN_FEAT_LIU        ( 0 )
#define BUILTIN_FEAT_DCF600HS   ( BUILTIN_FEAT_DCF_2 )   //### TODO
#define BUILTIN_FEAT_DCF600RS   ( BUILTIN_FEAT_DCF_2 )   //### TODO
#define BUILTIN_FEAT_MRI        ( 0 )
#define BUILTIN_FEAT_BPE        ( 0 )
#define BUILTIN_FEAT_GLN180PEX  ( BUILTIN_FEAT_GNSS_BUS_LVL )
#define BUILTIN_FEAT_N2X        ( BUILTIN_FEAT_COMM_N2X )
#define BUILTIN_FEAT_RSC180     ( GPS_MODEL_HAS_SCU_STAT )
#define BUILTIN_FEAT_LNE_GB     ( 0 )
#define BUILTIN_FEAT_PPG180     ( 0 )
#define BUILTIN_FEAT_SCG        ( 0 )
#define BUILTIN_FEAT_MDU300     ( 0 )
#define BUILTIN_FEAT_SDI        ( 0 )
#define BUILTIN_FEAT_FDM180     ( GPS_MODEL_HAS_TZDL | GPS_MODEL_HAS_ENABLE_FLAGS )
#define BUILTIN_FEAT_SPT        ( 0 )
#define BUILTIN_FEAT_PZF180     ( BUILTIN_FEAT_DCF_PZF_2 )
#define BUILTIN_FEAT_REL1000    ( 0 )
#define BUILTIN_FEAT_HPS100     ( 0 )
#define BUILTIN_FEAT_VSG180     ( 0 )
#define BUILTIN_FEAT_MSF180     ( BUILTIN_FEAT_MSF_2 )
#define BUILTIN_FEAT_WWVB180    ( BUILTIN_FEAT_WVB_2 )
#define BUILTIN_FEAT_CPC180     ( 0 )
#define BUILTIN_FEAT_CTC100     ( 0 )
#define BUILTIN_FEAT_TCR180     ( BUILTIN_FEAT_TCR_2 )
#define BUILTIN_FEAT_LUE180     ( 0 )
#define BUILTIN_FEAT_CPC_01     ( 0 )
#define BUILTIN_FEAT_TSU_01     ( 0 )
#define BUILTIN_FEAT_CMC_01     ( 0 )
#define BUILTIN_FEAT_SCU_01     ( 0 )
#define BUILTIN_FEAT_FCU_01     ( 0 )
#define BUILTIN_FEAT_CSM100     ( 0 )
#define BUILTIN_FEAT_LNE180SFP  ( 0 )
#define BUILTIN_FEAT_GTS180     ( 0 )
#define BUILTIN_FEAT_GPS180CSM  ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GRC181     ( BUILTIN_FEAT_GNSS )
#define BUILTIN_FEAT_N2X180     ( BUILTIN_FEAT_COMM_N2X )
#define BUILTIN_FEAT_GRC181PEX  ( BUILTIN_FEAT_GNSS_BUS_LVL )
#define BUILTIN_FEAT_MDU180     ( GPS_MODEL_HAS_SCU_STAT )
#define BUILTIN_FEAT_MDU312     ( 0 )
#define BUILTIN_FEAT_GPS165     ( BUILTIN_FEAT_GPS )
#define BUILTIN_FEAT_GNS181_UC  ( BUILTIN_FEAT_GNSS )
#define BUILTIN_FEAT_PSX_4GE    ( 0 )
#define BUILTIN_FEAT_RSC180RDU  ( GPS_MODEL_HAS_SCU_STAT )
#define BUILTIN_FEAT_USYNCPWR   ( 0 )
#define BUILTIN_FEAT_FDM180M    ( GPS_MODEL_HAS_TZDL | GPS_MODEL_HAS_ENABLE_FLAGS )

/** @} anchor GPS_MODEL_BUILTIN_FEATURE_MASKS */



/**
 * @brief Initializer for a table of built-in features per device
 *
 * Last entry is all zero to indicated end of table.
 *
 * @see ::GPS_MODEL_CODES
 * @see @ref GPS_MODEL_BUILTIN_FEATURE_MASKS
 */
#define GPS_MODEL_BUILTIN_FEATURES                   \
{                                                    \
  {  GPS_MODEL_GPS166,    BUILTIN_FEAT_GPS166 },     \
  {  GPS_MODEL_GPS167,    BUILTIN_FEAT_GPS167 },     \
  {  GPS_MODEL_GPS167SV,  BUILTIN_FEAT_GPS167SV },   \
  {  GPS_MODEL_GPS167PC,  BUILTIN_FEAT_GPS167PC },   \
  {  GPS_MODEL_GPS167PCI, BUILTIN_FEAT_GPS167PCI },  \
  {  GPS_MODEL_GPS163,    BUILTIN_FEAT_GPS163 },     \
  {  GPS_MODEL_GPS168PCI, BUILTIN_FEAT_GPS168PCI },  \
  {  GPS_MODEL_GPS161,    BUILTIN_FEAT_GPS161 },     \
  {  GPS_MODEL_GPS169PCI, BUILTIN_FEAT_GPS169PCI },  \
  {  GPS_MODEL_TCR167PCI, BUILTIN_FEAT_TCR167PCI },  \
  {  GPS_MODEL_GPS164,    BUILTIN_FEAT_GPS164 },     \
  {  GPS_MODEL_GPS170PCI, BUILTIN_FEAT_GPS170PCI },  \
  {  GPS_MODEL_PZF511,    BUILTIN_FEAT_PZF511 },     \
  {  GPS_MODEL_GPS170,    BUILTIN_FEAT_GPS170 },     \
  {  GPS_MODEL_TCR511,    BUILTIN_FEAT_TCR511 },     \
  {  GPS_MODEL_AM511,     BUILTIN_FEAT_AM511 },      \
  {  GPS_MODEL_MSF511,    BUILTIN_FEAT_MSF511 },     \
  {  GPS_MODEL_GRC170,    BUILTIN_FEAT_GRC170 },     \
  {  GPS_MODEL_GPS170PEX, BUILTIN_FEAT_GPS170PEX },  \
  {  GPS_MODEL_GPS162,    BUILTIN_FEAT_GPS162 },     \
  {  GPS_MODEL_PTP270PEX, BUILTIN_FEAT_PTP270PEX },  \
  {  GPS_MODEL_FRC511PEX, BUILTIN_FEAT_FRC511PEX },  \
  {  GPS_MODEL_GEN170,    BUILTIN_FEAT_GEN170 },     \
  {  GPS_MODEL_TCR170PEX, BUILTIN_FEAT_TCR170PEX },  \
  {  GPS_MODEL_WWVB511,   BUILTIN_FEAT_WWVB511 },    \
  {  GPS_MODEL_MGR170,    BUILTIN_FEAT_MGR170 },     \
  {  GPS_MODEL_JJY511,    BUILTIN_FEAT_JJY511 },     \
  {  GPS_MODEL_PZF600,    BUILTIN_FEAT_PZF600 },     \
  {  GPS_MODEL_TCR600,    BUILTIN_FEAT_TCR600 },     \
  {  GPS_MODEL_GPS180,    BUILTIN_FEAT_GPS180 },     \
  {  GPS_MODEL_GLN170,    BUILTIN_FEAT_GLN170 },     \
  {  GPS_MODEL_GPS180PEX, BUILTIN_FEAT_GPS180PEX },  \
  {  GPS_MODEL_TCR180PEX, BUILTIN_FEAT_TCR180PEX },  \
  {  GPS_MODEL_PZF180PEX, BUILTIN_FEAT_PZF180PEX },  \
  {  GPS_MODEL_MGR180,    BUILTIN_FEAT_MGR180 },     \
  {  GPS_MODEL_MSF600,    BUILTIN_FEAT_MSF600 },     \
  {  GPS_MODEL_WWVB600,   BUILTIN_FEAT_WWVB600 },    \
  {  GPS_MODEL_JJY600,    BUILTIN_FEAT_JJY600 },     \
  {  GPS_MODEL_GPS180HS,  BUILTIN_FEAT_GPS180HS },   \
  {  GPS_MODEL_GPS180AMC, BUILTIN_FEAT_GPS180AMC },  \
  {  GPS_MODEL_ESI180,    BUILTIN_FEAT_ESI180 },     \
  {  GPS_MODEL_CPE180,    BUILTIN_FEAT_CPE180 },     \
  {  GPS_MODEL_LNO180,    BUILTIN_FEAT_LNO180 },     \
  {  GPS_MODEL_GRC180,    BUILTIN_FEAT_GRC180 },     \
  {  GPS_MODEL_LIU,       BUILTIN_FEAT_LIU },        \
  {  GPS_MODEL_DCF600HS,  BUILTIN_FEAT_DCF600HS },   \
  {  GPS_MODEL_DCF600RS,  BUILTIN_FEAT_DCF600RS },   \
  {  GPS_MODEL_MRI,       BUILTIN_FEAT_MRI },        \
  {  GPS_MODEL_BPE,       BUILTIN_FEAT_BPE },        \
  {  GPS_MODEL_GLN180PEX, BUILTIN_FEAT_GLN180PEX },  \
  {  GPS_MODEL_N2X,       BUILTIN_FEAT_N2X },        \
  {  GPS_MODEL_RSC180,    BUILTIN_FEAT_RSC180 },     \
  {  GPS_MODEL_LNE_GB,    BUILTIN_FEAT_LNE_GB },     \
  {  GPS_MODEL_PPG180,    BUILTIN_FEAT_PPG180 },     \
  {  GPS_MODEL_SCG,       BUILTIN_FEAT_SCG },        \
  {  GPS_MODEL_MDU300,    BUILTIN_FEAT_MDU300 },     \
  {  GPS_MODEL_SDI,       BUILTIN_FEAT_SDI },        \
  {  GPS_MODEL_FDM180,    BUILTIN_FEAT_FDM180 },     \
  {  GPS_MODEL_SPT,       BUILTIN_FEAT_SPT },        \
  {  GPS_MODEL_PZF180,    BUILTIN_FEAT_PZF180 },     \
  {  GPS_MODEL_REL1000,   BUILTIN_FEAT_REL1000 },    \
  {  GPS_MODEL_HPS100,    BUILTIN_FEAT_HPS100 },     \
  {  GPS_MODEL_VSG180,    BUILTIN_FEAT_VSG180 },     \
  {  GPS_MODEL_MSF180,    BUILTIN_FEAT_MSF180 },     \
  {  GPS_MODEL_WWVB180,   BUILTIN_FEAT_WWVB180 },    \
  {  GPS_MODEL_CPC180,    BUILTIN_FEAT_CPC180 },     \
  {  GPS_MODEL_CTC100,    BUILTIN_FEAT_CTC100 },     \
  {  GPS_MODEL_TCR180,    BUILTIN_FEAT_TCR180 },     \
  {  GPS_MODEL_LUE180,    BUILTIN_FEAT_LUE180 },     \
  {  GPS_MODEL_CPC_01,    BUILTIN_FEAT_CPC_01 },     \
  {  GPS_MODEL_TSU_01,    BUILTIN_FEAT_TSU_01 },     \
  {  GPS_MODEL_CMC_01,    BUILTIN_FEAT_CMC_01 },     \
  {  GPS_MODEL_SCU_01,    BUILTIN_FEAT_SCU_01 },     \
  {  GPS_MODEL_FCU_01,    BUILTIN_FEAT_FCU_01 },     \
  {  GPS_MODEL_CSM100,    BUILTIN_FEAT_CSM100 },     \
  {  GPS_MODEL_LNE180SFP, BUILTIN_FEAT_LNE180SFP },  \
  {  GPS_MODEL_GTS180,    BUILTIN_FEAT_GTS180 },     \
  {  GPS_MODEL_GPS180CSM, BUILTIN_FEAT_GPS180CSM },  \
  {  GPS_MODEL_GRC181,    BUILTIN_FEAT_GRC181 },     \
  {  GPS_MODEL_N2X180,    BUILTIN_FEAT_N2X180 },     \
  {  GPS_MODEL_GRC181PEX, BUILTIN_FEAT_GRC181PEX },  \
  {  GPS_MODEL_MDU180,    BUILTIN_FEAT_MDU180 },     \
  {  GPS_MODEL_MDU312,    BUILTIN_FEAT_MDU312 },     \
  {  GPS_MODEL_GPS165,    BUILTIN_FEAT_GPS165 },     \
  {  GPS_MODEL_GNS181_UC, BUILTIN_FEAT_GNS181_UC },  \
  {  GPS_MODEL_PSX_4GE,   BUILTIN_FEAT_PSX_4GE },    \
  {  GPS_MODEL_RSC180RDU, BUILTIN_FEAT_RSC180RDU },  \
  {  GPS_MODEL_USYNCPWR,  BUILTIN_FEAT_USYNCPWR },   \
  {  GPS_MODEL_FDM180M,   BUILTIN_FEAT_FDM180M },    \
  {  0, 0 }                                          \
}

/** @} anchor GPS_BUILTIN_FEATURE_DEFS */



/**
 * @brief Initialize a ::RECEIVER_INFO structure for legacy DCF77 receivers
 *
 * Legacy DCF77 receivers may not provide a ::RECEIVER_INFO structure,
 * but have well-known properties which can be used to set up a
 * default ::RECEIVER_INFO.
 *
 * @param[in,out] _p     Pointer to a ::RECEIVER_INFO STRUCTURE to be set up
 * @param[in]     _pdev  Pointer to a ::PCPS_DEV structure read before
 *
 * @see ::_setup_default_receiver_info_gps
 */
#define _setup_default_receiver_info_dcf( _p, _pdev )    \
do                                                       \
{                                                        \
  memset( (_p), 0, sizeof( *(_p) ) );                    \
                                                         \
  (_p)->ticks_per_sec = DEFAULT_GPS_TICKS_PER_SEC;       \
  (_p)->n_ucaps = 0;                                     \
  (_p)->n_com_ports = _pcps_has_serial( _pdev ) ? 1 : 0; \
  (_p)->n_str_type = ( (_p)->n_com_ports != 0 ) ?        \
                     DEFAULT_N_STR_TYPE_DCF : 0;         \
} while ( 0 )



/**
 * @brief Initialize a ::RECEIVER_INFO structure for legacy GPS receivers
 *
 * Legacy GPS receivers may not provide a ::RECEIVER_INFO structure,
 * but have well-known properties which can be used to set up a
 * default ::RECEIVER_INFO.
 *
 * @param[in,out] _p      Pointer to a ::RECEIVER_INFO STRUCTURE to be set up
 *
 * @see ::_setup_default_receiver_info_dcf
 */
#define _setup_default_receiver_info_gps( _p )      \
do                                                  \
{                                                   \
  memset( (_p), 0, sizeof( *(_p) ) );               \
                                                    \
  (_p)->ticks_per_sec = DEFAULT_GPS_TICKS_PER_SEC;  \
  (_p)->n_ucaps = 2;                                \
  (_p)->n_com_ports = DEFAULT_N_COM;                \
  (_p)->n_str_type = DEFAULT_N_STR_TYPE_GPS;        \
} while ( 0 )



/*
 * The macros below can be used to classify a receiver,
 * e.g. depending on the time source and/or depending on
 * whether it's a plug-in card or an external device.
 */

#define _mbg_rcvr_is_plug_in( _p_ri )      \
  ( strstr( (_p_ri)->model_name, "PC" ) || \
    strstr( (_p_ri)->model_name, "PEX" ) )

#define _mbg_rcvr_is_gps( _p_ri ) \
  ( strstr( (_p_ri)->model_name, "GPS" ) || \
    strstr( (_p_ri)->model_name, "MGR" ) )

#define _mbg_rcvr_is_mobile_gps( _p_ri ) \
  ( strstr( (_p_ri)->model_name, "MGR" ) )

#define _mbg_rcvr_is_gps_plug_in( _p_ri ) \
  ( _mbg_rcvr_is_gps( _p_ri ) &&          \
    _mbg_rcvr_is_plug_in( _p_ri ) )

#define _mbg_rcvr_is_irig( _p_ri ) \
  ( strstr( (_p_ri)->model_name, "TCR" ) )

#define _mbg_rcvr_is_irig_plug_in( _p_ri ) \
  ( _mbg_rcvr_is_irig( _p_ri ) &&          \
    _mbg_rcvr_is_plug_in( _p_ri ) )

#define _mbg_rcvr_is_dcf77_am( _p_ri ) \
  ( strstr( (_p_ri)->model_name, "AM" ) )

#define _mbg_rcvr_is_dcf77_am_plug_in( _p_ri ) \
  ( _mbg_rcvr_is_dcf77_am( _p_ri ) &&          \
    _mbg_rcvr_is_plug_in( _p_ri ) )

#define _mbg_rcvr_is_dcf77_pzf( _p_ri )  \
  ( strstr( (_p_ri)->model_name, "PZF" ) )

#define _mbg_rcvr_is_dcf77_pzf_plug_in( _p_ri ) \
  ( _mbg_rcvr_is_dcf77_pzf( _p_ri ) &&          \
    _mbg_rcvr_is_plug_in( _p_ri ) )

#define _mbg_rcvr_is_any_dcf77( _p_ri )   \
  ( _mbg_rcvr_is_dcf77_am( _p_ri ) ||     \
    _mbg_rcvr_is_dcf77_pzf( _p_ri ) )

#define _mbg_rcvr_is_any_dcf77_plug_in( _p_ri ) \
  ( _mbg_rcvr_is_any_dcf77( _p_ri ) &&          \
    _mbg_rcvr_is_plug_in( _p_ri ) )

#define _mbg_rcvr_is_msf( _p_ri ) \
  ( strstr( (_p_ri)->model_name, "MSF" ) )

#define _mbg_rcvr_is_jjy( _p_ri ) \
  ( strstr( (_p_ri)->model_name, "JJY" ) )

#define _mbg_rcvr_is_msf_plug_in( _p_ri ) \
  ( _mbg_rcvr_is_msf( _p_ri ) &&          \
    _mbg_rcvr_is_plug_in( _p_ri ) )

#define _mbg_rcvr_is_glonass( _p_ri ) \
  ( strstr( (_p_ri)->model_name, "GRC" ) || \
    strstr( (_p_ri)->model_name, "GLN" ) )

#define _mbg_rcvr_is_glonass_plug_in( _p_ri ) \
  ( _mbg_rcvr_is_glonass( _p_ri ) &&          \
    _mbg_rcvr_is_plug_in( _p_ri ) )

#define _mbg_rcvr_is_wwvb( _p_ri ) \
  ( strstr( (_p_ri)->model_name, "WWVB" ) )

#define _mbg_rcvr_is_wwvb_plug_in( _p_ri ) \
  ( _mbg_rcvr_is_wwvb( _p_ri ) &&          \
    _mbg_rcvr_is_plug_in( _p_ri ) )



/**
 * @brief Known oscillator types used with ::RECEIVER_INFO::osc_type
 *
 * The sequence of codes does NOT reflect the order of quality.
 * New oscillator type codes will just be appended to the enumeration.
 *
 * @see ::DEFAULT_GPS_OSC_NAMES
 * @see ::DEFAULT_GPS_OSC_QUALITY_IDX
 */
enum GPS_OSC_TYPES
{
  GPS_OSC_UNKNOWN,
  GPS_OSC_TCXO_LQ,
  GPS_OSC_TCXO_HQ,
  GPS_OSC_OCXO_LQ,
  GPS_OSC_OCXO_MQ,
  GPS_OSC_OCXO_HQ,
  GPS_OSC_OCXO_XHQ,
  GPS_OSC_RUBIDIUM,
  GPS_OSC_TCXO_MQ,
  GPS_OSC_OCXO_DHQ,
  GPS_OSC_OCXO_SQ,
  N_GPS_OSC
};


/**
 * @brief Oscillator type name string initializer
 *
 * The sequence and number of oscillator names has to
 * correspond to the enumeration in ::GPS_OSC_TYPES
 *
 * @see ::GPS_OSC_TYPES
 * @see ::DEFAULT_GPS_OSC_QUALITY_IDX
 */
#define DEFAULT_GPS_OSC_NAMES \
{                             \
  "[unknown]",                \
  "TCXO LQ",                  \
  "TCXO",                     \
  "OCXO LQ",                  \
  "OCXO MQ",                  \
  "OCXO HQ",                  \
  "OCXO XHQ",                 \
  "RUBIDIUM",                 \
  "TCXO MQ",                  \
  "OCXO DHQ",                 \
  "OCXO SQ"                   \
}


/**
 * @brief Oscillator quality index
 *
 * Can be used to initialize a index array
 * (e.g. "int osc_quality_idx[N_GPS_OSC];")
 * allowing to display the oscillator types
 * ordered by quality
 *
 * @see ::GPS_OSC_TYPES
 * @see ::DEFAULT_GPS_OSC_NAMES
 */
#define DEFAULT_GPS_OSC_QUALITY_IDX \
{                                   \
  GPS_OSC_UNKNOWN,                  \
  GPS_OSC_TCXO_LQ,                  \
  GPS_OSC_TCXO_MQ,                  \
  GPS_OSC_TCXO_HQ,                  \
  GPS_OSC_OCXO_LQ,                  \
  GPS_OSC_OCXO_SQ,                  \
  GPS_OSC_OCXO_MQ,                  \
  GPS_OSC_OCXO_HQ,                  \
  GPS_OSC_OCXO_DHQ,                 \
  GPS_OSC_OCXO_XHQ,                 \
  GPS_OSC_RUBIDIUM                  \
}



/**
 * @brief Enumeration of device features flags reported in ::RI_FEATURES
 *
 * Used with ::RECEIVER_INFO::features. Each flags indicates if a device
 * supports the associated feature, but due to the limited bit size of
 * the ::RI_FEATURES type the number of these features is limited to 32.
 *
 * To extend the number of possible features the ::MBG_XFEATURE_BITS, the
 * ::MBG_XFEATURE_BUFFER structure and associated definitions have been
 * introduced, which are supported by devices which have ::GPS_HAS_XFEATURE
 * set in ::RI_FEATURES.
 *
 * @see ::RI_FEATURES
 * @see ::MBG_XFEATURE_BITS
 * @see ::MBG_XFEATURE_BUFFER
 */
enum GPS_FEATURE_BITS
{
  GPS_FEAT_PPS,                 ///< has pulse per second output
  GPS_FEAT_PPM,                 ///< has pulse per minute output
  GPS_FEAT_SYNTH,               ///< has programmable synthesizer output
  GPS_FEAT_DCFMARKS,            ///< has DCF77 compatible time mark output
  GPS_FEAT_IRIG_TX,             ///< has on-board IRIG output
  GPS_FEAT_IRIG_RX,             ///< has on-board IRIG input
  GPS_FEAT_LAN_IP4,             ///< has simple LAN IPv4 interface, superseded by ::GPS_FEAT_NET_CFG
  GPS_FEAT_MULTI_REF,           ///< has multiple input sources with priorities, superseded by ::GPS_FEAT_XMULTI_REF

  GPS_FEAT_RCV_TIMEOUT,         ///< timeout after GPS reception has stopped
  GPS_FEAT_IGNORE_LOCK,         ///< supports "ignore lock", ::MBG_OPT_BIT_EMU_SYNC can be set alternatively
  GPS_FEAT_5_MHZ,               ///< output 5 MHz rather than 100 kHz
  GPS_FEAT_XMULTI_REF,          ///< has extended multiple input source configuration, supersedes ::GPS_FEAT_MULTI_REF
  GPS_FEAT_OPT_SETTINGS,        ///< supports ::MBG_OPT_SETTINGS
  GPS_FEAT_TIME_SCALE,          ///< supports configurable time scale (%UTC, TAI, GPS, ...)
  GPS_FEAT_IRIG_CTRL_BITS,      ///< supports IRIG control bits (::MBG_IRIG_CTRL_BITS)
  GPS_FEAT_PTP,                 ///< has PTP support

  GPS_FEAT_NAV_ENGINE_SETTINGS, ///< supports navigation engine configuration
  GPS_FEAT_RAW_IRIG_DATA,       ///< supports reading raw IRIG input data (::MBG_RAW_IRIG_DATA)
  GPS_FEAT_RAW_IRIG_TIME,       ///< supports reading decoded IRIG time (::PCPS_IRIG_TIME)
  GPS_FEAT_PTP_UNICAST,         ///< has PTP Unicast support
  GPS_FEAT_GPIO,                ///< has general purpose inputs/outputs
  GPS_FEAT_XMRS_MULT_INSTC,     ///< multiple XMRS instances of the same ref type supported (::XMULTI_REF_INSTANCES)
  GPS_FEAT_10MHZ_DISBD,         ///< 10 MHz output is always disabled
  GPS_FEAT_EVT_LOG,             ///< Event logging supported

  GPS_FEAT_IMS,                 ///< supports IMS data structures
  GPS_FEAT_HAVEQUICK,           ///< supports HaveQuick structures
  GPS_FEAT_NTP,                 ///< supports NTP structures
  GPS_FEAT_NET_CFG,             ///< supports extended network interface configuration, supersedes ::GPS_FEAT_LAN_IP4
  GPS_FEAT_VST,                 ///< supports VST (Versatile Storage) API and structures
  GPS_FEAT_SHS,                 ///< supports SHS (Secure Hybrid System) API and structures
  GPS_FEAT_XBP,                 ///< supports XBP (eXtended Binary Protocol) API and structures, see @ref group_xbp
  GPS_FEAT_XFEATURE,            ///< support eXtended features, see @ref group_xfeature
  N_GPS_FEATURE                 ///< the number of known ::GPS_FEATURE_BITS, should now be at its limit, i.e. 32.

  // WARNING: There are no more unassigned feature bits available here.
  // New features have to be defined using the ::MBG_XFEATURE_BITS
};


/**
 * @brief Names of device features
 *
 * @see ::GPS_FEATURE_BITS
 */
#define DEFAULT_GPS_FEATURE_NAMES \
{                                 \
  "Pulse Per Second",             \
  "Pulse Per Minute",             \
  "Programmable Synth.",          \
  "DCF77 Time Marks",             \
  "IRIG Out",                     \
  "IRIG In",                      \
  "IPv4 LAN Interface",           \
  "Multiple Ref. Sources",        \
  "Receive Timeout",              \
  "Ignore Lock",                  \
  "5 MHz Output",                 \
  "Ext. Multiple Ref. Src. Cfg.", \
  "Optional Settings",            \
  "Configurable Time Scale",      \
  "IRIG Control Bits",            \
  "PTP/IEEE1588",                 \
  "Nav. Engine Settings",         \
  "Raw IRIG Data",                \
  "Raw IRIG Time",                \
  "PTP/IEEE1588 Unicast",         \
  "General Purpose I/O",          \
  "Multiple XMRS Instances",      \
  "10 MHz Output Disabled",       \
  "Event Logging",                \
  "IMS data",                     \
  "HaveQuick",                    \
  "NTP",                          \
  "Ext. Network Config",          \
  "Versatile Storage",            \
  "SHS",                          \
  "Extended Binary Protocol",     \
  "Extended Features"             \
}


/**
 * @brief Bit masks used with ::RECEIVER_INFO::features
 *
 * @see ::GPS_FEATURE_BITS
 *
 * @anchor GPS_FEATURE_MASKS @{ */

#define GPS_HAS_PPS                  ( 1UL << GPS_FEAT_PPS )                  ///< see ::GPS_FEAT_PPS
#define GPS_HAS_PPM                  ( 1UL << GPS_FEAT_PPM )                  ///< see ::GPS_FEAT_PPM
#define GPS_HAS_SYNTH                ( 1UL << GPS_FEAT_SYNTH )                ///< see ::GPS_FEAT_SYNTH
#define GPS_HAS_DCFMARKS             ( 1UL << GPS_FEAT_DCFMARKS )             ///< see ::GPS_FEAT_DCFMARKS
#define GPS_HAS_IRIG_TX              ( 1UL << GPS_FEAT_IRIG_TX )              ///< see ::GPS_FEAT_IRIG_TX
#define GPS_HAS_IRIG_RX              ( 1UL << GPS_FEAT_IRIG_RX )              ///< see ::GPS_FEAT_IRIG_RX
#define GPS_HAS_LAN_IP4              ( 1UL << GPS_FEAT_LAN_IP4 )              ///< see ::GPS_FEAT_LAN_IP4
#define GPS_HAS_MULTI_REF            ( 1UL << GPS_FEAT_MULTI_REF )            ///< see ::GPS_FEAT_MULTI_REF

#define GPS_HAS_RCV_TIMEOUT          ( 1UL << GPS_FEAT_RCV_TIMEOUT )          ///< see ::GPS_FEAT_RCV_TIMEOUT
#define GPS_HAS_IGNORE_LOCK          ( 1UL << GPS_FEAT_IGNORE_LOCK )          ///< see ::GPS_FEAT_IGNORE_LOCK
#define GPS_HAS_5_MHZ                ( 1UL << GPS_FEAT_5_MHZ )                ///< see ::GPS_FEAT_5_MHZ
#define GPS_HAS_XMULTI_REF           ( 1UL << GPS_FEAT_XMULTI_REF )           ///< see ::GPS_FEAT_XMULTI_REF
#define GPS_HAS_OPT_SETTINGS         ( 1UL << GPS_FEAT_OPT_SETTINGS )         ///< see ::GPS_FEAT_OPT_SETTINGS
#define GPS_HAS_TIME_SCALE           ( 1UL << GPS_FEAT_TIME_SCALE )           ///< see ::GPS_FEAT_TIME_SCALE
#define GPS_HAS_IRIG_CTRL_BITS       ( 1UL << GPS_FEAT_IRIG_CTRL_BITS )       ///< see ::GPS_FEAT_IRIG_CTRL_BITS
#define GPS_HAS_PTP                  ( 1UL << GPS_FEAT_PTP )                  ///< see ::GPS_FEAT_PTP

#define GPS_HAS_NAV_ENGINE_SETTINGS  ( 1UL << GPS_FEAT_NAV_ENGINE_SETTINGS )  ///< see ::GPS_FEAT_NAV_ENGINE_SETTINGS
#define GPS_HAS_RAW_IRIG_DATA        ( 1UL << GPS_FEAT_RAW_IRIG_DATA )        ///< see ::GPS_FEAT_RAW_IRIG_DATA
#define GPS_HAS_RAW_IRIG_TIME        ( 1UL << GPS_FEAT_RAW_IRIG_TIME )        ///< see ::GPS_FEAT_RAW_IRIG_TIME
#define GPS_HAS_PTP_UNICAST          ( 1UL << GPS_FEAT_PTP_UNICAST )          ///< see ::GPS_FEAT_PTP_UNICAST
#define GPS_HAS_GPIO                 ( 1UL << GPS_FEAT_GPIO )                 ///< see ::GPS_FEAT_GPIO
#define GPS_HAS_XMRS_MULT_INSTC      ( 1UL << GPS_FEAT_XMRS_MULT_INSTC )      ///< see ::GPS_FEAT_XMRS_MULT_INSTC
#define GPS_HAS_10MHZ_DISBD          ( 1UL << GPS_FEAT_10MHZ_DISBD )          ///< see ::GPS_FEAT_10MHZ_DISBD
#define GPS_HAS_EVT_LOG              ( 1UL << GPS_FEAT_EVT_LOG )              ///< see ::GPS_FEAT_EVT_LOG

#define GPS_HAS_IMS                  ( 1UL << GPS_FEAT_IMS )                  ///< see ::GPS_FEAT_IMS
#define GPS_HAS_HAVEQUICK            ( 1UL << GPS_FEAT_HAVEQUICK )            ///< see ::GPS_FEAT_HAVEQUICK
#define GPS_HAS_NTP                  ( 1UL << GPS_FEAT_NTP )                  ///< see ::GPS_FEAT_NTP
#define GPS_HAS_NET_CFG              ( 1UL << GPS_FEAT_NET_CFG )              ///< see ::GPS_FEAT_NET_CFG
#define GPS_HAS_VST                  ( 1UL << GPS_FEAT_VST )                  ///< see ::GPS_FEAT_VST
#define GPS_HAS_SHS                  ( 1UL << GPS_FEAT_SHS )                  ///< see ::GPS_FEAT_SHS
#define GPS_HAS_XBP                  ( 1UL << GPS_FEAT_XBP )                  ///< see ::GPS_FEAT_XBP
#define GPS_HAS_XFEATURE             ( 1UL << GPS_FEAT_XFEATURE )             ///< see ::GPS_FEAT_XFEATURE

// the next ones are special since they just shadow another flag:
#define GPS_HAS_REF_OFFS      GPS_HAS_IRIG_RX   ///< always supported with IRIG inputs, see ::GPS_HAS_IRIG_RX
#define GPS_HAS_DEBUG_STATUS  GPS_HAS_IRIG_RX   ///< always supported with IRIG inputs, see ::GPS_HAS_IRIG_RX

/** @} anchor GPS_FEATURE_MASKS */


/**
 * @defgroup group_xfeature Extended feature definitions
 *
 * @note These structures and definitions are only supported by a device
 * if ::GPS_HAS_XFEATURE is set in ::RECEIVER_INFO::features.
 *
 * @{ */


/**
 * @brief The maximum number of feature bits supported by the MBG_XFEATURE API.
 *
 * Warning: Changing this number breaks API compatibility!
 *
 * @see ::MBG_XFEATURE_BITS
 */
#define MAX_XFEATURE_BITS    1024



/**
 * @brief Enumeration of defined extended features.
 *
 * @see ::MBG_XFEATURE_NAMES
 * @see ::MBG_XFEATURE_BUFFER
 */
enum MBG_XFEATURE_BITS
{
  MBG_XFEATURE_TLV_API,      ///< Supports generic TLV API, see @ref group_tlv_api
  MBG_XFEATURE_SAVE_CFG,     ///< Supports the ::GPS_SAVE_CFG command
  MBG_XFEATURE_LED_API,      ///< Supports programmable LED API, see @ref group_led_api
  MBG_XFEATURE_LNE_API,      ///< Supports specific LNE API, see @ref group_lne_api
  MBG_XFEATURE_PWR_CTL_API,  ///< Supports power control, see @ref group_pwr_ctl_api
  MBG_XFEATURE_EXT_SYS_INFO, ///< Supports extended revision information, see @ref group_ext_sys_info
  MBG_XFEATURE_TRANSACTIONS, ///< Supports the ::GPS_BEGIN_TRANSACTION and ::GPS_END_TRANSACTION commands, see also ::MBG_TRANSACTION_TYPES
  MBG_XFEATURE_REBOOT,       ///< Supports the ::GPS_REBOOT command
  MBG_XFEATURE_CLK_RES_INFO, ///< Supports the ::GPS_CLK_RES_INFO command, see @ref group_clk_res_info
  MBG_XFEATURE_UCAP_NET,     ///< Supports the ::GPS_UCAP_NET_GLB_INFO and ::GPS_UCAP_NET_RECV_INFO_IDX commands, see @ref group_ucap_net
  MBG_XFEATURE_REQ_TTM,      ///< Supports TTM requests via GPS_TIME command
  MBG_XFEATURE_IO_PORTS,     ///< Supports I/O port structures, see @ref group_io_ports
  MBG_XFEATURE_MONITORING,   ///< Supports monitoring / notifications, see @ref group_monitoring
  MBG_XFEATURE_XHE,          ///< Supports XHE external rubidium unit I/O commands
  MBG_XFEATURE_USB_LOCK,     ///< Supports USB interrupt structures, see @ref group_usb_lock
  N_MBG_XFEATURE             ///< Number of defined extended features
  // NOTE If new features are appended here then an appropriate feature
  // name string has to be appended to ::MBG_XFEATURE_NAMES, and care must
  // be taken that ::N_MBG_XFEATURE doesn't exceed ::MAX_XFEATURE_BITS.
};



/**
 * @brief Names of extended device features
 *
 * Can be used to initialize a string array of ::N_MBG_XFEATURE entries,
 * so the number of strings must correspond to ::N_MBG_XFEATURE.
 *
 * @see ::MBG_XFEATURE_BITS
 */
#define MBG_XFEATURE_NAMES  \
{                           \
  "Generic TLV API",        \
  "Save Config On Card",    \
  "Programmable LED API",   \
  "LNE API",                \
  "Power Control API",      \
  "Extended Revision Info", \
  "Transaction commands",   \
  "Reboot command",         \
  "Clock Resolution Info",  \
  "Extended User Captures", \
  "Request TTM",            \
  "I/O Ports",              \
  "Monitoring",             \
  "XHE unit",               \
  "USB lock"                \
}



/**
 * @brief Array size required to store all extended features
 *
 * The number of bytes required to store up to ::MAX_XFEATURE_BITS
 * feature bits in a byte array.
 */
#define MAX_XFEATURE_BYTES   ( MAX_XFEATURE_BITS / 8 )



/**
 * @brief A structure used to store extended device features.
 *
 * Up to ::MAX_XFEATURE_BITS totally can be stored, but only
 * ::N_MBG_XFEATURE extended features are currently defined.
 * The ::_set_xfeature_bit macro should be used by the firmware
 * to set a feature bit in the buffer, and the ::check_xfeature
 * function should be used to implement API calls which test if an
 * extended feature is supported.
 *
 * @see ::_set_xfeature_bit
 * @see ::check_xfeature
 */
typedef struct
{
  uint8_t b[MAX_XFEATURE_BYTES];

} MBG_XFEATURE_BUFFER;



/**
 * @brief Set an extended feature bit in a ::MBG_XFEATURE_BUFFER
 *
 * Should be used by the firmware only to set one of the ::MBG_XFEATURE_BITS
 * in an ::MBG_XFEATURE_BUFFER after power-up.
 *
 * @param[in]  _xf_bit    One of the ::MBG_XFEATURE_BITS
 * @param[in]  _xf_buffp  Pointer to an ::MBG_XFEATURE_BUFFER
 */
#define _set_xfeature_bit( _xf_bit, _xf_buffp ) \
  _set_array_bit( _xf_bit, (_xf_buffp)->b, MAX_XFEATURE_BYTES )


/** @} defgroup group_xfeature */



/*
 * The features below are supported by default by older
 * C166 based GPS receivers:
 */
#define DEFAULT_GPS_FEATURES_C166 \
{                                 \
  GPS_HAS_PPS |                   \
  GPS_HAS_PPM |                   \
  GPS_HAS_SYNTH |                 \
  GPS_HAS_DCFMARKS                \
}


/**
 * @brief Bits used to define ::RECEIVER_INFO_FLAG_MASKS
 */
enum RECEIVER_INFO_FLAG_BITS
{
  GPS_BIT_OSC_CFG_SUPP,      ///< oscillator cfg is supported, see ::RECEIVER_INFO::osc_type
  GPS_BIT_IRIG_FO_IN,        ///< IRIG input via fiber optics
  GPS_BIT_HAS_FPGA,          ///< device provides on-board FPGA
  N_RECEIVER_INFO_FLAG_BITS  ///< number of known bits
};


/**
 * @brief Bit masks to be used with ::RECEIVER_INFO::flags
 */
enum RECEIVER_INFO_FLAG_MASKS
{
  GPS_OSC_CFG_SUPP = ( 1UL << GPS_BIT_OSC_CFG_SUPP ),  ///< see ::GPS_BIT_OSC_CFG_SUPP
  GPS_IRIG_FO_IN   = ( 1UL << GPS_BIT_IRIG_FO_IN ),    ///< see ::GPS_BIT_IRIG_FO_IN
  GPS_HAS_FPGA     = ( 1UL << GPS_BIT_HAS_FPGA )       ///< see ::GPS_BIT_HAS_FPGA
};



/*
 * If the ::GPS_HAS_FPGA flag is set in ::RECEIVER_INFO::flags then the card
 * provides an FPGA and the following information about the FPGA is available:
 */
#define FPGA_NAME_LEN    31                     // max name length
#define FPGA_NAME_SIZE   ( FPGA_NAME_LEN + 1 )  // size including trailing 0

#define FPGA_INFO_SIZE   128

typedef union
{
  struct
  {
    CSUM csum;
    uint32_t fsize;
    uint32_t start_addr;
    char name[FPGA_NAME_SIZE];
  } hdr;

  char b[FPGA_INFO_SIZE];

} FPGA_INFO;



/*
 * The definitions below are used to specify where a FPGA image is located
 * in the flash memory:
 */
typedef struct
{
  CSUM csum;
  uint16_t fpga_start_seg;   // Number of the 4k block where an FPGA image is located

} FPGA_START_INFO;

#define DEFAULT_FPGA_START_SEG     0x60

#define DEFAULT_FPGA_START_INFO    \
{                                  \
  0x1234 + DEFAULT_FPGA_START_SEG, \
  DEFAULT_FPGA_START_SEG           \
}



/**
 * @brief A structure used to hold time in GPS format
 *
 * Date and time refer to the linear time scale defined by GPS, with
 * the epoch starting at %UTC midnight at the beginning of January 6, 1980.
 *
 * GPS time is counted by the week numbers since the epoch, plus second
 * of the week, plus fraction of the second. The week number transmitted
 * by the satellites rolls over from 1023 to 0, but Meinberg devices
 * just continue to count the weeks beyond the 1024 week limit to keep
 * the receiver's internal time.
 *
 * %UTC time differs from GPS time since a number of leap seconds have
 * been inserted in the %UTC time scale after the GPS epoch. The number
 * of leap seconds is disseminated by the satellites using the ::UTC
 * parameter set, which also provides info on pending leap seconds.
 */
typedef struct
{
  uint16_t wn;     ///< the week number since the GPS system has been put into operation
  uint32_t sec;    ///< the second of that week
  uint32_t tick;   ///< fractions of a second, 1/::RECEIVER_INFO::ticks_per_sec units

} T_GPS;

#define _mbg_swab_t_gps( _p )  \
do                             \
{                              \
  _mbg_swab16( &(_p)->wn );    \
  _mbg_swab32( &(_p)->sec );   \
  _mbg_swab32( &(_p)->tick );  \
} while ( 0 )


/**
 * @brief Local date and time computed from GPS time
 *
 * The current number of leap seconds have to be added to get %UTC
 * from GPS time. Additional corrections could have been made according
 * to the time zone/daylight saving parameters ::TZDL defined by the user.
 * The status field can be checked to see which corrections
 * have actually been applied.
 *
 * @note Conversion from GPS time to %UTC and/or local time can only be
 * done if some valid ::UTC correction parameters are available in the
 * receiver's non-volatile memory.
 */
typedef struct
{
  int16_t year;           ///< year number, 0..9999
  int8_t month;           ///< month, 1..12
  int8_t mday;            ///< day of month, 1..31
  int16_t yday;           ///< day of year, 1..365, or 366 in case of leap year
  int8_t wday;            ///< day of week, 0..6 == Sun..Sat
  int8_t hour;            ///< hours, 0..23
  int8_t min;             ///< minutes, 0..59
  int8_t sec;             ///< seconds, 0..59, or 60 in case of inserted leap second
  int32_t frac;           ///< fractions of a second, 1/::RECEIVER_INFO::ticks_per_sec units
  int32_t offs_from_utc;  ///< local time offset from %UTC [sec]
  uint16_t status;        ///< status flags, see ::TM_GPS_STATUS_BIT_MASKS

} TM_GPS;

#define _mbg_swab_tm_gps( _p )          \
do                                      \
{                                       \
  _mbg_swab16( &(_p)->year );           \
  _mbg_swab16( &(_p)->yday );           \
  _mbg_swab32( &(_p)->frac );           \
  _mbg_swab32( &(_p)->offs_from_utc );  \
  _mbg_swab16( &(_p)->status );         \
} while ( 0 )


/**
 * @brief Status flag bits used to define ::TM_GPS_STATUS_BIT_MASKS
 *
 * These bits report info on the time conversion from GPS time to %UTC
 * and/or local time as well as device status info.
 *
 * @see ::TM_GPS_STATUS_BIT_MASKS
 */
enum TM_GPS_STATUS_BITS
{
  TM_BIT_UTC,          ///< %UTC correction has been made
  TM_BIT_LOCAL,        ///< %UTC has been converted to local time according to ::TZDL settings
  TM_BIT_DL_ANN,       ///< state of daylight saving is going to change
  TM_BIT_DL_ENB,       ///< daylight saving is in effect
  TM_BIT_LS_ANN,       ///< leap second pending
  TM_BIT_LS_ENB,       ///< current second is leap second
  TM_BIT_LS_ANN_NEG,   ///< set in addition to ::TM_BIT_LS_ANN if leap sec is negative
  TM_BIT_INVT,         ///< invalid time, e.g. if RTC battery bas been empty

  TM_BIT_EXT_SYNC,     ///< synchronized externally
  TM_BIT_HOLDOVER,     ///< in holdover mode after previous synchronization
  TM_BIT_ANT_SHORT,    ///< antenna cable short circuited
  TM_BIT_NO_WARM,      ///< oscillator control loop not settled
  TM_BIT_ANT_DISCONN,  ///< antenna currently disconnected
  TM_BIT_SYN_FLAG,     ///< clock not synchronized, reflects the state of the "time sync error" output pin
  TM_BIT_NO_SYNC,      ///< time sync actually not verified
  TM_BIT_NO_POS        ///< position actually not verified, LOCK LED off
};


/**
 * @brief Status flag masks used with ::TM_GPS::status
 *
 * These bits report info on the time conversion from GPS time to %UTC
 * and/or local time as well as device status info.
 *
 * @see ::TM_GPS_STATUS_BITS
 */
enum TM_GPS_STATUS_BIT_MASKS
{
  TM_UTC         = ( 1UL << TM_BIT_UTC ),          ///< see ::TM_BIT_UTC
  TM_LOCAL       = ( 1UL << TM_BIT_LOCAL ),        ///< see ::TM_BIT_LOCAL
  TM_DL_ANN      = ( 1UL << TM_BIT_DL_ANN ),       ///< see ::TM_BIT_DL_ANN
  TM_DL_ENB      = ( 1UL << TM_BIT_DL_ENB ),       ///< see ::TM_BIT_DL_ENB
  TM_LS_ANN      = ( 1UL << TM_BIT_LS_ANN ),       ///< see ::TM_BIT_LS_ANN
  TM_LS_ENB      = ( 1UL << TM_BIT_LS_ENB ),       ///< see ::TM_BIT_LS_ENB
  TM_LS_ANN_NEG  = ( 1UL << TM_BIT_LS_ANN_NEG ),   ///< see ::TM_BIT_LS_ANN_NEG
  TM_INVT        = ( 1UL << TM_BIT_INVT ),         ///< see ::TM_BIT_INVT

  TM_EXT_SYNC    = ( 1UL << TM_BIT_EXT_SYNC ),     ///< see ::TM_BIT_EXT_SYNC
  TM_HOLDOVER    = ( 1UL << TM_BIT_HOLDOVER ),     ///< see ::TM_BIT_HOLDOVER
  TM_ANT_SHORT   = ( 1UL << TM_BIT_ANT_SHORT ),    ///< see ::TM_BIT_ANT_SHORT
  TM_NO_WARM     = ( 1UL << TM_BIT_NO_WARM ),      ///< see ::TM_BIT_NO_WARM
  TM_ANT_DISCONN = ( 1UL << TM_BIT_ANT_DISCONN ),  ///< see ::TM_BIT_ANT_DISCONN
  TM_SYN_FLAG    = ( 1UL << TM_BIT_SYN_FLAG ),     ///< see ::TM_BIT_SYN_FLAG
  TM_NO_SYNC     = ( 1UL << TM_BIT_NO_SYNC ),      ///< see ::TM_BIT_NO_SYNC
  TM_NO_POS      = ( 1UL << TM_BIT_NO_POS )        ///< see ::TM_BIT_NO_POS
};



/**
 * @brief Type of an extended TM status which is mainly used inside the firmware
 */
typedef uint32_t TM_STATUS_EXT;

/**
 * @brief Enumeration of extended status bits used with ::TM_STATUS_EXT
 *
 * @note The lower 16 bits correspond to ::TM_GPS_STATUS_BITS
 */
enum TM_GPS_STATUS_BITS_EX
{
  TM_BIT_SCALE_GPS = 16,  ///< time scale configured to return GPS time
  TM_BIT_SCALE_TAI        ///< time scale configured to return TAI
  // the remaining bits are reserved
};

// The following bits are only used with the ::TM_STATUS_X type:
#define TM_SCALE_GPS    ( 1UL << TM_BIT_SCALE_GPS )
#define TM_SCALE_TAI    ( 1UL << TM_BIT_SCALE_TAI )

#define TM_MSK_TIME_VALID  ( TM_UTC | TM_SCALE_GPS | TM_SCALE_TAI )


/**
 * @brief A structure used to transmit information on date and time
 *
 * This structure can be used to transfer the current time, in which
 * case the channel field has to be set to -1, or an event capture time
 * retrieved from the on-board FIFO, in which case the channel field
 * contains the index of the time capture input, e.g. 0 or 1.
 */
typedef struct
{
  int16_t channel;  ///< -1: the current on-board time; >= 0 the capture channel number
  T_GPS t;          ///< time in GPS scale and format
  TM_GPS tm;        ///< time converted to %UTC and/or local time according to ::TZDL settings

} TTM;

#define _mbg_swab_ttm( _p )       \
do                                \
{                                 \
  _mbg_swab16( &(_p)->channel );  \
  _mbg_swab_t_gps( &(_p)->t );    \
  _mbg_swab_tm_gps( &(_p)->tm );  \
} while ( 0 )



#ifndef _XYZ_DEFINED
  /**
   * @brief Sequence and number of components of a cartesian position
   */
  enum XYZ_FIELDS { XP, YP, ZP, N_XYZ };  // x, y, z

  /**
   * @brief A position in cartesian coordinates
   *
   * Usually earth centered, earth fixed (ECEF) coordinates.
   */
  typedef double XYZ[N_XYZ];      ///< values are in [m], see ::XYZ_FIELDS

  #define _XYZ_DEFINED
#endif

#define _mbg_swab_xyz( _p )  _mbg_swab_doubles( _p, N_XYZ )


#ifndef _LLA_DEFINED
  /**
   * @brief Sequence and number of components of a geographic position
   */
  enum LLA_FIELDS { LAT, LON, ALT, N_LLA };  /* latitude, longitude, altitude */

  /**
   * @brief A geographic position based on latitude, longitude, and altitude
   *
   * The geographic position associated to specific cartesian coordinates
   * depends on the characteristics of the ellipsoid used for the computation,
   * the so-called geographic datum. GPS uses the WGS84 (World Geodetic System
   * from 1984) ellipsoid by default.
   */
  typedef double LLA[N_LLA];      ///< lon, lat in [rad], alt in [m], see ::LLA_FIELDS

  #define _LLA_DEFINED
#endif

#define _mbg_swab_lla( _p )  _mbg_swab_doubles( _p, N_LLA )


/**
 * @defgroup group_synth Synthesizer parameters
 *
 * Synthesizer frequency is expressed as a
 * four digit decimal number (freq) to be multiplied by 0.1 Hz and an
 * base 10 exponent (range). If the effective frequency is less than
 * 10 kHz its phase is synchronized corresponding to the variable phase.
 * Phase may be in a range from -360 deg to +360 deg with a resolution
 * of 0.1 deg, so the resulting numbers to be stored are in a range of
 * -3600 to +3600.
 *
 * Example:<br>
 * Assume the value of freq is 2345 (decimal) and the value of phase is 900.
 * If range == 0 the effective frequency is 234.5 Hz with a phase of +90 deg.
 * If range == 1 the synthesizer will generate a 2345 Hz output frequency
 * and so on.
 *
 * Limitations:<br>
 * If freq == 0 the synthesizer is disabled. If range == 0 the least
 * significant digit of freq is limited to 0, 3, 5 or 6. The resulting
 * frequency is shown in the examples below:
 *    - freq == 1230  -->  123.0 Hz
 *    - freq == 1233  -->  123 1/3 Hz (real 1/3 Hz, NOT 123.3 Hz)
 *    - freq == 1235  -->  123.5 Hz
 *    - freq == 1236  -->  123 2/3 Hz (real 2/3 Hz, NOT 123.6 Hz)
 *
 * If range == ::MAX_SYNTH_RANGE the value of freq must not exceed 1000, so
 * the output frequency is limited to 10 MHz (see ::MAX_SYNTH_FREQ_VAL).
 *
 * @{ */

#define N_SYNTH_FREQ_DIGIT  4    ///< number of digits to edit
#define MAX_SYNTH_FREQ   1000    ///< if range == ::MAX_SYNTH_RANGE

#define MIN_SYNTH_RANGE     0
#define MAX_SYNTH_RANGE     5
#define N_SYNTH_RANGE       ( MAX_SYNTH_RANGE - MIN_SYNTH_RANGE + 1 )

#define N_SYNTH_PHASE_DIGIT  4
#define MAX_SYNTH_PHASE      3600


#define MAX_SYNTH_FREQ_EDIT  9999  ///< max sequence of digits when editing


/**
 * @brief The maximum frequency that can be configured for the synthesizer
 */
#define MAX_SYNTH_FREQ_VAL   10000000UL     ///< 10 MHz
/*   == MAX_SYNTH_FREQ * 10^(MAX_SYNTH_RANGE-1) */

/**
 * @brief The synthesizer's phase is only be synchronized if the frequency is below this limit
 */
#define SYNTH_PHASE_SYNC_LIMIT   10000UL    ///< 10 kHz

/**
 * A Macro used to determine the position of the decimal point
 * when printing the synthesizer frequency as 4 digit value
 */
#define _synth_dp_pos_from_range( _r ) \
  ( ( ( N_SYNTH_RANGE - (_r) ) % ( N_SYNTH_FREQ_DIGIT - 1 ) ) + 1 )

/**
 * @brief Synthesizer frequency units
 *
 * An initializer for commonly displayed synthesizer frequency units
 * (::N_SYNTH_RANGE strings)
 */
#define DEFAULT_FREQ_RANGES \
{                           \
  "Hz",                     \
  "kHz",                    \
  "kHz",                    \
  "kHz",                    \
  "MHz",                    \
  "MHz",                    \
}



/**
 * @brief Synthesizer configuration parameters
 */
typedef struct
{
  int16_t freq;    ///< four digits used; scale: 0.1 Hz; e.g. 1234 -> 123.4 Hz
  int16_t range;   ///< scale factor for freq; 0..::MAX_SYNTH_RANGE
  int16_t phase;   ///< -::MAX_SYNTH_PHASE..+::MAX_SYNTH_PHASE; >0 -> pulses later

} SYNTH;

#define _mbg_swab_synth( _p )   \
do                              \
{                               \
  _mbg_swab16( &(_p)->freq );   \
  _mbg_swab16( &(_p)->range );  \
  _mbg_swab16( &(_p)->phase );  \
} while ( 0 )


/**
 * @brief Enumeration of synthesizer states
 */
enum SYNTH_STATES
{
  SYNTH_DISABLED,   ///< disbled by cfg, i.e. freq == 0.0
  SYNTH_OFF,        ///< not enabled after power-up
  SYNTH_FREE,       ///< enabled, but not synchronized
  SYNTH_DRIFTING,   ///< has initially been sync'd, but now running free
  SYNTH_SYNC,       ///< fully synchronized
  N_SYNTH_STATE     ///< the number of known states
};


/**
 * @brief A structure used to report the synthesizer state
 */
typedef struct
{
  uint8_t state;     ///< state code as enumerated in ::SYNTH_STATES
  uint8_t flags;     ///< reserved, currently always 0

} SYNTH_STATE;

#define _mbg_swab_synth_state( _p )  _nop_macro_fnc()

#define SYNTH_FLAG_PHASE_IGNORED  0x01

/** @} defgroup group_synth */



/**
 * @defgroup group_tzdl Time zone / daylight saving parameters
 *
 * Example: <br>
 * For automatic daylight saving enable/disable in Central Europe,
 * the variables are to be set as shown below: <br>
 *   - offs = 3600L           one hour from %UTC
 *   - offs_dl = 3600L        one additional hour if daylight saving enabled
 *   - tm_on = first Sunday from March 25, 02:00:00h ( year |= ::DL_AUTO_FLAG )
 *   - tm_off = first Sunday from October 25, 03:00:00h ( year |= ::DL_AUTO_FLAG )
 *   - name[0] == "CET  "     name if daylight saving not enabled
 *   - name[1] == "CEST "     name if daylight saving is enabled
 *
 * @{ */

/**
 * @brief The name of a time zone
 *
 * @note Up to 5 printable characters, plus trailing zero
 */
typedef char TZ_NAME[6];

/**
 * @brief Time zone / daylight saving parameters
 *
 * This structure is used to specify how a device converts on-board %UTC
 * to local time, including computation of beginning and end of daylight
 * saving time (DST), if required.
 *
 * @note The ::TZDL structure contains members of type ::TM_GPS to specify
 * the times for beginning and end of DST. However, the ::TM_GPS::frac,
 * ::TM_GPS::offs_from_utc, and ::TM_GPS::status fields of these ::TZDL::tm_on
 * and ::TZDL::tm_off members are ignored for the conversion to local time,
 * and thus should be 0.
 */
typedef struct
{
  int32_t offs;      ///< standard offset from %UTC to local time [sec]
  int32_t offs_dl;   ///< additional offset if daylight saving enabled [sec]
  TM_GPS tm_on;      ///< date/time when daylight saving starts
  TM_GPS tm_off;     ///< date/time when daylight saving ends
  TZ_NAME name[2];   ///< names without and with daylight saving enabled

} TZDL;

#define _mbg_swab_tzdl( _p )          \
do                                    \
{                                     \
  _mbg_swab32( &(_p)->offs );         \
  _mbg_swab32( &(_p)->offs_dl );      \
  _mbg_swab_tm_gps( &(_p)->tm_on );   \
  _mbg_swab_tm_gps( &(_p)->tm_off );  \
} while ( 0 )


/**
 * @brief A flag indicating automatic computation of DST
 *
 * If this flag is or'ed to the year numbers in ::TZDL::tm_on and ::TZDL::tm_off
 * then daylight saving is computed automatically year by year.
 */
#define DL_AUTO_FLAG  0x8000



// Below there are some initializers for commonly used TZDL configurations:

#define DEFAULT_TZDL_AUTO_YEAR   ( (int16_t) ( 2007L | DL_AUTO_FLAG ) )

#define DEFAULt_TZDL_OFFS_DL     3600L  ///< usually DST is +1 hour


/**
 * An initializer for ::TZDL::tm_on and ::TZDL::tm_off for time zones
 * which do not observe DST.
 */
#define DEFAULT_TZDL_TM_ON_OFF_NO_DST \
  { DEFAULT_TZDL_AUTO_YEAR, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }


// Settings used with %UTC:

#define TZ_INFO_UTC  "UTC (Universal Time, Coordinated)"

#define DEFAULT_TZDL_NAMES_UTC    { "UTC  ", "UTC  " }

#define DEFAULT_TZDL_UTC                        \
{                                               \
  0L,                             /* offs */    \
  0L,                             /* offs_dl */ \
  DEFAULT_TZDL_TM_ON_OFF_NO_DST,  /* tm_on */   \
  DEFAULT_TZDL_TM_ON_OFF_NO_DST,  /* tm_off */  \
  DEFAULT_TZDL_NAMES_UTC          /* name */    \
}


/**
 * @brief An initializer for ::TZDL::tm_on according to the rules for Central Europe
 */
#define DEFAULT_TZDL_TM_ON_CET_CEST \
  { DEFAULT_TZDL_AUTO_YEAR, 3, 25, 0, 0, 2, 0, 0, 0L, 0L, 0 }

/**
 * @brief An initializer for ::TZDL::tm_off according to the rules for Central Europe
 */
#define DEFAULT_TZDL_TM_OFF_CET_CEST \
  { DEFAULT_TZDL_AUTO_YEAR, 10, 25, 0, 0, 3, 0, 0, 0L, 0L, 0 }


// Settings used with Central European Time:

#define TZ_INFO_CET_CEST_EN  "CET/CEST (Central Europe)"
#define TZ_INFO_CET_CEST_DE  "MEZ/MESZ (Mitteleuropa)"

#define DEFAULT_TZDL_NAMES_CET_CEST_EN  { "CET  ", "CEST " }
#define DEFAULT_TZDL_NAMES_CET_CEST_DE  { "MEZ  ", "MESZ " }

#define DEFAULT_TZDL_OFFS_CET  3600L

#define DEFAULT_TZDL_CET_CEST_EN                \
{                                               \
  DEFAULT_TZDL_OFFS_CET,          /* offs */    \
  DEFAULt_TZDL_OFFS_DL,           /* offs_dl */ \
  DEFAULT_TZDL_TM_ON_CET_CEST,    /* tm_on */   \
  DEFAULT_TZDL_TM_OFF_CET_CEST,   /* tm_off */  \
  DEFAULT_TZDL_NAMES_CET_CEST_EN  /* name */    \
}

#define DEFAULT_TZDL_CET_CEST_DE                \
{                                               \
  DEFAULT_TZDL_OFFS_CET,          /* offs */    \
  DEFAULt_TZDL_OFFS_DL,           /* offs_dl */ \
  DEFAULT_TZDL_TM_ON_CET_CEST,    /* tm_on */   \
  DEFAULT_TZDL_TM_OFF_CET_CEST,   /* tm_off */  \
  DEFAULT_TZDL_NAMES_CET_CEST_DE  /* name */    \
}


// The symbols below specify beginning and end of DST for
// Easter Europe, as constituted by the European Parliament:

#define DEFAULT_TZDL_TM_ON_EET_EEST \
  { DEFAULT_TZDL_AUTO_YEAR, 3, 25, 0, 0, 3, 0, 0, 0L, 0L, 0 }

#define DEFAULT_TZDL_TM_OFF_EET_EEST \
  { DEFAULT_TZDL_AUTO_YEAR, 10, 25, 0, 0, 4, 0, 0, 0L, 0L, 0 }


// Settings used with Eastern European Time:

#define TZ_INFO_EET_EEST_EN  "EET/EEST (East Europe)"
#define TZ_INFO_EET_EEST_DE  "OEZ/OEST (Osteuropa)"

#define DEFAULT_TZDL_NAMES_EET_EEST_EN  { "EET  ", "EEST " }
#define DEFAULT_TZDL_NAMES_EET_EEST_DE  { "OEZ  ", "OESZ " }

#define DEFAULT_TZDL_OFFS_EET  7200L

#define DEFAULT_TZDL_EET_EEST_EN                \
{                                               \
  DEFAULT_TZDL_OFFS_EET,          /* offs */    \
  DEFAULt_TZDL_OFFS_DL,           /* offs_dl */ \
  DEFAULT_TZDL_TM_ON_EET_EEST,    /* tm_on */   \
  DEFAULT_TZDL_TM_OFF_EET_EEST,   /* tm_off */  \
  DEFAULT_TZDL_NAMES_EET_EEST_EN  /* name */    \
}

#define DEFAULT_TZDL_EET_EEST_DE                \
{                                               \
  DEFAULT_TZDL_OFFS_EET,          /* offs */    \
  DEFAULt_TZDL_OFFS_DL,           /* offs_dl */ \
  DEFAULT_TZDL_TM_ON_EET_EEST,    /* tm_on */   \
  DEFAULT_TZDL_TM_OFF_EET_EEST,   /* tm_off */  \
  DEFAULT_TZDL_NAMES_EET_EEST_DE  /* name */    \
}

/** @} defgroup group_tzdl */



/**
 * @brief Antenna status and error at reconnect information
 *
 * The structure below reflects the status of the antenna,
 * the times of last disconnect/reconnect, and the board's
 * clock offset when it has synchronized again after the
 * disconnection interval.
 *
 * @note ::ANT_INFO::status changes back to ::ANT_RECONN only
 * after the antenna has been reconnected <b>and</b> the
 * receiver has re-synchronized to the satellite signal.
 * In this case ::ANT_INFO::delta_t reports the time offset
 * before resynchronization, i.e. how much the internal
 * time has drifted while the antenna was disconnected.
 */
typedef struct
{
  int16_t status;      ///< current status of antenna, see ::ANT_STATUS_CODES
  TM_GPS tm_disconn;   ///< time of antenna disconnect
  TM_GPS tm_reconn;    ///< time of antenna reconnect
  int32_t delta_t;     ///< clock offs at reconn. time in 1/::RECEIVER_INFO::ticks_per_sec units

} ANT_INFO;

#define _mbg_swab_ant_info( _p )          \
do                                        \
{                                         \
  _mbg_swab16( &(_p)->status );           \
  _mbg_swab_tm_gps( &(_p)->tm_disconn );  \
  _mbg_swab_tm_gps( &(_p)->tm_reconn );   \
  _mbg_swab32( &(_p)->delta_t );          \
} while ( 0 )


/**
 * @brief Status code used with ::ANT_INFO::status
 */
enum ANT_STATUS_CODES
{
  ANT_INVALID,   ///< No other fields valid since antenna has not yet been disconnected
  ANT_DISCONN,   ///< Antenna is disconnected, tm_reconn and delta_t not yet set
  ANT_RECONN,    ///< Antenna has been disconnect, and receiver sync. after reconnect, so all fields valid
  N_ANT_STATUS_CODES  ///< the number of known status codes
};



/**
 * @brief A structure controlling when output signals are enabled
 *
 * The structure holds some flags which let the corresponding outputs
 * be disabled after power-up until the receiver has synchronized
 * (flags == ::EF_OFF, the default) or force the outputs to be enabled
 * immediately after power-up. The fixed frequency output is hard-wired
 * to be enabled immediately after power-up, so ::ENABLE_FLAGS::freq must
 * always be set to ::EF_FREQ_ALL.
 */
typedef struct
{
  uint16_t serial;   ///< ::EF_OFF or ::EF_SERIAL_BOTH
  uint16_t pulses;   ///< ::EF_OFF or ::EF_PULSES_BOTH
  uint16_t freq;     ///< always ::EF_FREQ_ALL
  uint16_t synth;    ///< ::EF_OFF or ::EF_SYNTH

} ENABLE_FLAGS;

#define _mbg_swab_enable_flags( _p )  \
do                                    \
{                                     \
  _mbg_swab16( &(_p)->serial );       \
  _mbg_swab16( &(_p)->pulses );       \
  _mbg_swab16( &(_p)->freq );         \
  _mbg_swab16( &(_p)->synth );        \
} while ( 0 )


/**
 * @brief Codes used with ::ENABLE_FLAGS
 **/
enum ENABLE_FLAGS_CODES
{
  EF_OFF          =  0x00,   ///< associated outputs off until synchronized

  EF_SERIAL_BOTH  =  0x03,   ///< both serial ports on, use with ::ENABLE_FLAGS::serial
  EF_PULSES_BOTH  =  0x03,   ///< both pulses P_SEC and P_MIN on, use with ::ENABLE_FLAGS::pulses
  EF_FREQ_ALL     =  0x07,   ///< all fixed freq. outputs on, use with ::ENABLE_FLAGS::freq
  EF_SYNTH        =  0x01    ///< synthesizer on, use with ::ENABLE_FLAGS::synth
};



#ifndef _COM_HS_DEFINED
  /**
   * @brief Enumeration of handshake modes
   */
  enum COM_HANSHAKE_MODES { HS_NONE, HS_XONXOFF, HS_RTSCTS, N_COM_HS };
  #define _COM_HS_DEFINED
#endif

#ifndef _COM_PARM_DEFINED
  /**
   * @brief A data type to configure a serial port's baud rate
   *
   * @see ::MBG_BAUD_RATES
   */
  typedef int32_t BAUD_RATE;

  /**
   * @brief Indices used to identify a parameter in the framing string
   *
   * @see ::MBG_FRAMING_STRS
   */
  enum MBG_FRAMING_STR_IDXS { F_DBITS, F_PRTY, F_STBITS };

  /**
   * @brief A structure to store the configuration of a serial port
   */
  typedef struct
  {
    BAUD_RATE baud_rate;  ///< transmission speed, e.g. 19200L, see ::MBG_BAUD_RATES
    char framing[4];      ///< ASCIIZ framing string, e.g. "8N1" or "7E2", see ::MBG_FRAMING_STRS
    int16_t handshake;    ///< handshake mode, yet only ::HS_NONE supported

  } COM_PARM;

  #define _COM_PARM_DEFINED
#endif

#define _mbg_swab_baud_rate( _p )   _mbg_swab32( _p )

#define _mbg_swab_com_parm( _p )            \
do                                          \
{                                           \
  _mbg_swab_baud_rate( &(_p)->baud_rate );  \
  _mbg_swab16( &(_p)->handshake );          \
} while ( 0 )


/**
 * @brief Enumeration of serial port baud rates
 *
 * @note Most clock models and/or serial ports don't support all defined baud rates.
 *
 * @see ::MBG_BAUD_RATES
 * @see ::MBG_BAUD_RATE_MASKS
 */
enum MBG_BAUD_RATE_CODES
{
  MBG_BAUD_RATE_300,
  MBG_BAUD_RATE_600,
  MBG_BAUD_RATE_1200,
  MBG_BAUD_RATE_2400,
  MBG_BAUD_RATE_4800,
  MBG_BAUD_RATE_9600,
  MBG_BAUD_RATE_19200,
  MBG_BAUD_RATE_38400,
  MBG_BAUD_RATE_57600,
  MBG_BAUD_RATE_115200,
  MBG_BAUD_RATE_230400,
  MBG_BAUD_RATE_460800,
  MBG_BAUD_RATE_921600,
  N_MBG_BAUD_RATES     ///< the number of known baud rates
};

/**
 * @brief An initializer for a table of baud rate values
 *
 * These values can be used with ::COM_PARM::baud_rate, if the device
 * supports the particular baud rate.
 *
 * The values must correspond to the enumeration ::MBG_BAUD_RATE_CODES
 *
 * @see ::MBG_BAUD_RATE_CODES
 */
#define MBG_BAUD_RATES \
{                      \
  300L,                \
  600L,                \
  1200L,               \
  2400L,               \
  4800L,               \
  9600L,               \
  19200L,              \
  38400L,              \
  57600L,              \
  115200L,             \
  230400L,             \
  460800L,             \
  921600L              \
}

/**
 * @brief An initializer for a table of baud rate strings
 *
 * The values must correspond to the enumeration ::MBG_BAUD_RATE_CODES
 *
 * @see ::MBG_BAUD_RATE_CODES
 */
#define MBG_BAUD_STRS \
{                     \
  "300",              \
  "600",              \
  "1200",             \
  "2400",             \
  "4800",             \
  "9600",             \
  "19200",            \
  "38400",            \
  "57600",            \
  "115200",           \
  "230400",           \
  "460800",           \
  "921600"            \
}

/**
 * @brief Bit masks associated with baud rates enumerated in ::MBG_BAUD_RATE_CODES
 *
 * These bit masks are used e.g. with ::PORT_INFO::supp_baud_rates to
 * determine which baud rates are supported by a particular serial port.
 *
 * @see ::MBG_BAUD_RATE_CODES
 * @see ::MBG_FRAMING_MASKS
 */
enum MBG_BAUD_RATE_MASKS
{
  MBG_PORT_HAS_300     = ( 1UL << MBG_BAUD_RATE_300 ),      ///< see ::MBG_BAUD_RATE_300
  MBG_PORT_HAS_600     = ( 1UL << MBG_BAUD_RATE_600 ),      ///< see ::MBG_BAUD_RATE_600
  MBG_PORT_HAS_1200    = ( 1UL << MBG_BAUD_RATE_1200 ),     ///< see ::MBG_BAUD_RATE_1200
  MBG_PORT_HAS_2400    = ( 1UL << MBG_BAUD_RATE_2400 ),     ///< see ::MBG_BAUD_RATE_2400
  MBG_PORT_HAS_4800    = ( 1UL << MBG_BAUD_RATE_4800 ),     ///< see ::MBG_BAUD_RATE_4800
  MBG_PORT_HAS_9600    = ( 1UL << MBG_BAUD_RATE_9600 ),     ///< see ::MBG_BAUD_RATE_9600
  MBG_PORT_HAS_19200   = ( 1UL << MBG_BAUD_RATE_19200 ),    ///< see ::MBG_BAUD_RATE_19200
  MBG_PORT_HAS_38400   = ( 1UL << MBG_BAUD_RATE_38400 ),    ///< see ::MBG_BAUD_RATE_38400
  MBG_PORT_HAS_57600   = ( 1UL << MBG_BAUD_RATE_57600 ),    ///< see ::MBG_BAUD_RATE_57600
  MBG_PORT_HAS_115200  = ( 1UL << MBG_BAUD_RATE_115200 ),   ///< see ::MBG_BAUD_RATE_115200
  MBG_PORT_HAS_230400  = ( 1UL << MBG_BAUD_RATE_230400 ),   ///< see ::MBG_BAUD_RATE_230400
  MBG_PORT_HAS_460800  = ( 1UL << MBG_BAUD_RATE_460800 ),   ///< see ::MBG_BAUD_RATE_460800
  MBG_PORT_HAS_921600  = ( 1UL << MBG_BAUD_RATE_921600 )    ///< see ::MBG_BAUD_RATE_921600
};


/**
 * @brief Enumeration of all known serial port framings
 *
 * @note Most clock models and/or serial ports don't support all defined framing types.
 *
 * @see ::MBG_FRAMING_STRS
 */
enum MBG_FRAMING_CODES
{
  MBG_FRAMING_7N2,
  MBG_FRAMING_7E1,
  MBG_FRAMING_7E2,
  MBG_FRAMING_8N1,
  MBG_FRAMING_8N2,
  MBG_FRAMING_8E1,
  MBG_FRAMING_7O1,
  MBG_FRAMING_7O2,
  MBG_FRAMING_8O1,
  MBG_FRAMING_8E2,  ///< Note: most serial ports don't support this!
  N_MBG_FRAMINGS    ///< the number of known framings
};

/**
 * @brief An initializer for a table of known framing strings
 *
 * These values can be used with ::COM_PARM::framing, if the device
 * supports the particular framing.
 *
 * The values must correspond to the enumeration ::MBG_FRAMING_CODES
 *
 * @see ::MBG_FRAMING_CODES
 * @see ::MBG_FRAMING_MASKS
 * @see ::MBG_FRAMING_STR_IDXS
 */
#define MBG_FRAMING_STRS \
{                        \
  "7N2",                 \
  "7E1",                 \
  "7E2",                 \
  "8N1",                 \
  "8N2",                 \
  "8E1",                 \
  "7O1",                 \
  "7O2",                 \
  "8O1",                 \
  "8E2"                  \
}

/**
 * @brief Bit masks associated with framings enumerated in ::MBG_FRAMING_CODES
 *
 * These bit masks are used e.g. with ::PORT_INFO::supp_framings to
 * determine which framings are supported by a particular serial port.
 *
 * @see ::MBG_FRAMING_CODES
 * @see ::MBG_FRAMING_STRS
 */
enum MBG_FRAMING_MASKS
{
  MBG_PORT_HAS_7N2 = ( 1UL << MBG_FRAMING_7N2 ),   ///< see ::MBG_FRAMING_7N2
  MBG_PORT_HAS_7E1 = ( 1UL << MBG_FRAMING_7E1 ),   ///< see ::MBG_FRAMING_7E1
  MBG_PORT_HAS_7E2 = ( 1UL << MBG_FRAMING_7E2 ),   ///< see ::MBG_FRAMING_7E2
  MBG_PORT_HAS_8N1 = ( 1UL << MBG_FRAMING_8N1 ),   ///< see ::MBG_FRAMING_8N1
  MBG_PORT_HAS_8N2 = ( 1UL << MBG_FRAMING_8N2 ),   ///< see ::MBG_FRAMING_8N2
  MBG_PORT_HAS_8E1 = ( 1UL << MBG_FRAMING_8E1 ),   ///< see ::MBG_FRAMING_8E1
  MBG_PORT_HAS_7O1 = ( 1UL << MBG_FRAMING_7O1 ),   ///< see ::MBG_FRAMING_7O1
  MBG_PORT_HAS_7O2 = ( 1UL << MBG_FRAMING_7O2 ),   ///< see ::MBG_FRAMING_7O2
  MBG_PORT_HAS_8O1 = ( 1UL << MBG_FRAMING_8O1 ),   ///< see ::MBG_FRAMING_8O1
  MBG_PORT_HAS_8E2 = ( 1UL << MBG_FRAMING_8E2 )    ///< see ::MBG_FRAMING_8E2
};



/**
 * @brief Definitions used with the Meinberg binary protocol
 *
 * @anchor GPS_BIN_PROT_DEFS @{ */

/**
 * @brief Framing used with the binary protocol
 *
 * Different data length, or parity settings would corrupt
 * the binary data.
 */
#define MBG_DEFAULT_FRAMING      "8N1"

/**
 * @brief The standard baud rate used for the binary protocol
 *
 * This is supported by most devices. Some new devices may also
 * support ::MBG_DEFAULT_BAUDRATE_HS
 */
#define MBG_DEFAULT_BAUDRATE     19200L

/**
 * @brief The high speed baud rate used for the binary protocol
 *
 * This is not supported by older devices which work
 * with ::MBG_DEFAULT_BAUDRATE only.
 */
#define MBG_DEFAULT_BAUDRATE_HS  115200L


/**
 * @brief Strings used to force connection settings for the binary protocol
 *
 * If a device supports this and receives one of these ASCII strings
 * then it temporarily switches the serial port to some well-known
 * baud rate and framing appropriate for the binary protocol.
 *
 * @anchor GPS_BIN_PROT_CMD_STRS @{ */

#define MBG_FORCE_CONN_CMD_STR     "\nDFC\n"    ///< switch to ::MBG_DEFAULT_BAUDRATE
#define MBG_FORCE_CONN_HS_CMD_STR  "\nDFCHS\n"  ///< switch to ::MBG_DEFAULT_BAUDRATE_HS

/** @} anchor GPS_BIN_PROT_CMD_STRS */

/** @} anchor GPS_BIN_PROT_DEFS */



/*
 * By default, the baud rates and framings below
 * are supported by the UARTs integrated into
 * the C166 microcontroller:
 */
#define DEFAULT_GPS_BAUD_RATES_C166 \
(                                   \
  MBG_PORT_HAS_300   |              \
  MBG_PORT_HAS_600   |              \
  MBG_PORT_HAS_1200  |              \
  MBG_PORT_HAS_2400  |              \
  MBG_PORT_HAS_4800  |              \
  MBG_PORT_HAS_9600  |              \
  MBG_PORT_HAS_19200                \
)

#define DEFAULT_GPS_FRAMINGS_C166   \
(                                   \
  MBG_PORT_HAS_7N2 |                \
  MBG_PORT_HAS_7E1 |                \
  MBG_PORT_HAS_7E2 |                \
  MBG_PORT_HAS_8N1 |                \
  MBG_PORT_HAS_8N2 |                \
  MBG_PORT_HAS_8E1                  \
)


/*
 * By default, the baud rates and framings below
 * are supported by the UARTs integrated into
 * the GP2021 chipset:
 */
#define DEFAULT_GPS_BAUD_RATES_GP2021 \
(                                     \
  MBG_PORT_HAS_300   |                \
  MBG_PORT_HAS_600   |                \
  MBG_PORT_HAS_1200  |                \
  MBG_PORT_HAS_2400  |                \
  MBG_PORT_HAS_4800  |                \
  MBG_PORT_HAS_9600  |                \
  MBG_PORT_HAS_19200                  \
)

#define DEFAULT_GPS_FRAMINGS_GP2021   \
(                                     \
  MBG_PORT_HAS_7N2 |                  \
  MBG_PORT_HAS_7E2 |                  \
  MBG_PORT_HAS_8N1 |                  \
  MBG_PORT_HAS_8E1 |                  \
  MBG_PORT_HAS_8O1                    \
)


/**
 * @brief Configuration settings of a serial port
 *
 * @note This should be used preferably instead of
 * ::PORT_PARM, which is deprecated.
 */
typedef struct
{
  COM_PARM parm;        ///< transmission speed, framing, etc.
  uint8_t mode;         ///< string mode, see ::STR_MODES
  uint8_t str_type;     ///< index of the supported time string formats, see ::STR_TYPE_INFO_IDX
  uint32_t flags;       ///< reserved, don't use, currently 0

} PORT_SETTINGS;

#define _mbg_swab_port_settings( _p )  \
do                                     \
{                                      \
  _mbg_swab_com_parm( &(_p)->parm );   \
  _mbg_swab32( &(_p)->flags );         \
} while ( 0 )


/**
 * @brief Flag bits used to mark individual ::PORT_SETTINGS fields
 *
 * These definitions can be used to mark specific fields of a
 * ::PORT_SETTINGS structure, e.g. which fields have changed when
 * editing, or which fields have settings which are not valid.
 */
enum MBG_COM_CFG_STATUS_BITS
{
  MBG_PS_BIT_BAUD_RATE_OVR_SW,   ///< Baud rate index exceeds num supp by driver SW
  MBG_PS_BIT_BAUD_RATE_OVR_DEV,  ///< Baud rate index exceeds num supp by device
  MBG_PS_BIT_BAUD_RATE,          ///< Baud rate not supp by given port
  MBG_PS_BIT_FRAMING_OVR_SW,     ///< Framing index exceeds num supp by driver SW
  MBG_PS_BIT_FRAMING_OVR_DEV,    ///< Framing index exceeds num supp by device
  MBG_PS_BIT_FRAMING,            ///< Framing not supp by given port
  MBG_PS_BIT_HS_OVR_SW,          ///< Handshake index exceeds num supp by driver SW
  MBG_PS_BIT_HS,                 ///< Handshake mode not supp by given port
  MBG_PS_BIT_STR_TYPE_OVR_SW,    ///< String type index exceeds num supp by driver SW
  MBG_PS_BIT_STR_TYPE_OVR_DEV,   ///< String type index exceeds num supp by device
  MBG_PS_BIT_STR_TYPE,           ///< String type not supp by given port
  MBG_PS_BIT_STR_MODE_OVR_SW,    ///< String mode index exceeds num supp by driver SW
  MBG_PS_BIT_STR_MODE_OVR_DEV,   ///< String mode index exceeds num supp by device
  MBG_PS_BIT_STR_MODE,           ///< String mode not supp by given port and string type
  MBG_PS_BIT_FLAGS_OVR_SW,       ///< Flags not supp by driver SW
  MBG_PS_BIT_FLAGS,              ///< Flags not supp by device
  N_MBG_PS_BIT
};

/**
 * @brief Flag bit masks associated with ::MBG_COM_CFG_STATUS_BITS
 *
 * These definitions can be used to mark specific fields of a
 * ::PORT_SETTINGS structure, e.g. which fields have changed when
 * editing, or which fields have settings which are not valid.
 *
 * @anchor MBG_COM_CFG_STATUS_MASKS @{ */

#define MBG_PS_MSK_BAUD_RATE_OVR_SW   ( 1UL << MBG_PS_BIT_BAUD_RATE_OVR_SW )   ///< see ::MBG_PS_BIT_BAUD_RATE_OVR_SW
#define MBG_PS_MSK_BAUD_RATE_OVR_DEV  ( 1UL << MBG_PS_BIT_BAUD_RATE_OVR_DEV )  ///< see ::MBG_PS_BIT_BAUD_RATE_OVR_DEV
#define MBG_PS_MSK_BAUD_RATE          ( 1UL << MBG_PS_BIT_BAUD_RATE )          ///< see ::MBG_PS_BIT_BAUD_RATE
#define MBG_PS_MSK_FRAMING_OVR_SW     ( 1UL << MBG_PS_BIT_FRAMING_OVR_SW )     ///< see ::MBG_PS_BIT_FRAMING_OVR_SW
#define MBG_PS_MSK_FRAMING_OVR_DEV    ( 1UL << MBG_PS_BIT_FRAMING_OVR_DEV )    ///< see ::MBG_PS_BIT_FRAMING_OVR_DEV
#define MBG_PS_MSK_FRAMING            ( 1UL << MBG_PS_BIT_FRAMING )            ///< see ::MBG_PS_BIT_FRAMING
#define MBG_PS_MSK_HS_OVR_SW          ( 1UL << MBG_PS_BIT_HS_OVR_SW )          ///< see ::MBG_PS_BIT_HS_OVR_SW
#define MBG_PS_MSK_HS                 ( 1UL << MBG_PS_BIT_HS )                 ///< see ::MBG_PS_BIT_HS
#define MBG_PS_MSK_STR_TYPE_OVR_SW    ( 1UL << MBG_PS_BIT_STR_TYPE_OVR_SW )    ///< see ::MBG_PS_BIT_STR_TYPE_OVR_SW
#define MBG_PS_MSK_STR_TYPE_OVR_DEV   ( 1UL << MBG_PS_BIT_STR_TYPE_OVR_DEV )   ///< see ::MBG_PS_BIT_STR_TYPE_OVR_DEV
#define MBG_PS_MSK_STR_TYPE           ( 1UL << MBG_PS_BIT_STR_TYPE )           ///< see ::MBG_PS_BIT_STR_TYPE
#define MBG_PS_MSK_STR_MODE_OVR_SW    ( 1UL << MBG_PS_BIT_STR_MODE_OVR_SW )    ///< see ::MBG_PS_BIT_STR_MODE_OVR_SW
#define MBG_PS_MSK_STR_MODE_OVR_DEV   ( 1UL << MBG_PS_BIT_STR_MODE_OVR_DEV )   ///< see ::MBG_PS_BIT_STR_MODE_OVR_DEV
#define MBG_PS_MSK_STR_MODE           ( 1UL << MBG_PS_BIT_STR_MODE )           ///< see ::MBG_PS_BIT_STR_MODE
#define MBG_PS_MSK_FLAGS_OVR_SW       ( 1UL << MBG_PS_BIT_FLAGS_OVR_SW )       ///< see ::MBG_PS_BIT_FLAGS_OVR_SW
#define MBG_PS_MSK_FLAGS              ( 1UL << MBG_PS_BIT_FLAGS )              ///< see ::MBG_PS_BIT_FLAGS

/** @} anchor MBG_COM_CFG_STATUS_MASKS */



/**
 * @brief Configuration settings of a specific serial port
 *
 * This structure should be sent to a device to configure
 * a specific serial port. The number of supported ports
 * is ::RECEIVER_INFO::n_com_ports.
 *
 * @note The ::PORT_INFO_IDX structure should be read from
 * a device to retrieve the current settings and capabilities.
 *
 * @see ::STR_TYPE_INFO
 */
typedef struct
{
  uint16_t idx;         ///< port index, 0..::RECEIVER_INFO::n_com_ports-1
  PORT_SETTINGS port_settings;

} PORT_SETTINGS_IDX;

#define _mbg_swab_port_settings_idx( _p )           \
do                                                  \
{                                                   \
  _mbg_swab16( &(_p)->idx );                        \
  _mbg_swab_port_settings( &(_p)->port_settings );  \
} while ( 0 )


/**
 * @brief Current settings and general capabilities of a serial port
 *
 * @note This structure should be read from a device to retrieve
 * the current settings of a serial port plus its capabilities,
 * e.g. supported baud rates, supported string formats, etc.
 *
 * @see ::STR_TYPE_INFO
 */
typedef struct
{
  PORT_SETTINGS port_settings;  ///< current configuration of the port
  uint32_t supp_baud_rates;     ///< bit mask of baud rates supp. by this port, see ::MBG_BAUD_RATE_MASKS
  uint32_t supp_framings;       ///< bit mask of framings supp. by this port, see ::MBG_FRAMING_MASKS
  uint32_t supp_str_types;      ///< bit mask of string types supp. by this port, i.e. bit 0 set if str_type[0] is supp.
  uint32_t reserved;            ///< reserved for future use, currently always 0
  uint32_t flags;               ///< see ::PORT_INFO_FLAGS

} PORT_INFO;

#define _mbg_swab_port_info( _p )                   \
do                                                  \
{                                                   \
  _mbg_swab_port_settings( &(_p)->port_settings );  \
  _mbg_swab32( &(_p)->supp_baud_rates );            \
  _mbg_swab32( &(_p)->supp_framings );              \
  _mbg_swab32( &(_p)->supp_str_types );             \
  _mbg_swab32( &(_p)->reserved );                   \
  _mbg_swab32( &(_p)->flags );                      \
} while ( 0 )


/**
 * @brief Flags bits used to define ::PORT_INFO_FLAGS
 *
 * @see ::PORT_INFO_FLAGS
 */
enum PORT_INFO_FLAG_BITS
{
  PORT_INFO_FLAG_BIT_PORT_INVISIBLE,  ///< port is used internally and should not be displayed by config apps
  PORT_INFO_FLAG_BIT_BIN_PROT_HS,     ///< port supports binary protocol at high speed, see ::MBG_DEFAULT_BAUDRATE_HS
  N_PORT_INFO_FLAG_BITS               ///< the number of defined bits
};


/**
 * @brief Bit masks used with ::PORT_INFO::flags
 *
 * @see ::PORT_INFO_FLAG_BITS
 */
enum PORT_INFO_FLAGS
{
  PORT_INFO_FLAG_PORT_INVISIBLE = ( 1UL << PORT_INFO_FLAG_BIT_PORT_INVISIBLE ),  ///< see ::PORT_INFO_FLAG_BIT_PORT_INVISIBLE
  PORT_INFO_FLAG_BIN_PROT_HS    = ( 1UL << PORT_INFO_FLAG_BIT_BIN_PROT_HS )      ///< see ::PORT_INFO_FLAG_BIT_BIN_PROT_HS
};


/**
 * @brief Current settings and general capabilities of a specific serial port
 *
 * This structure should be read from the device to retrieve the
 * current settings of a specific serial port plus its capabilities,
 * e.g. supported baud rates, supported string formats, etc.
 * The number of supported ports is ::RECEIVER_INFO::n_com_ports.
 *
 * @note The ::PORT_SETTINGS_IDX structure should be send back to
 * the device to configure the specified serial port.
 */
typedef struct
{
  uint16_t idx;         ///< port index, 0..::RECEIVER_INFO::n_com_ports-1
  PORT_INFO port_info;

} PORT_INFO_IDX;

#define _mbg_swab_port_info_idx( _p )       \
do                                          \
{                                           \
  _mbg_swab16( &(_p)->idx );                \
  _mbg_swab_port_info( &(_p)->port_info );  \
} while ( 0 )


/**
 * @brief Information on a supported string format
 *
 * Information includes the name of the string format, which
 * transmission modes are supported, etc.
 *
 * The number of string types, and which string types are supported
 * depends on the device type and firmware version.
 *
 * @note Multiple structures ::STR_TYPE_INFO_IDX should be read
 * to retrieve all supported string types.
 */
typedef struct
{
  uint32_t supp_modes;  ///< bit mask of modes supp. for this string type, see ::STR_MODE_MASKS
  char long_name[23];   ///< long name of the string format
  char short_name[11];  ///< short name of the string format
  uint16_t flags;       ///< reserved, currently always 0

} STR_TYPE_INFO;

#define _mbg_swab_str_type_info( _p )  \
do                                     \
{                                      \
  _mbg_swab32( &(_p)->supp_modes );    \
  _mbg_swab16( &(_p)->flags );         \
} while ( 0 )



/**
 * @brief Information on a specific supported string format
 *
 * This structure should be read from a device to retrieve information
 * on a specific supported time string type from an array of supported
 * string types. The number of supported string types is returned
 * in ::RECEIVER_INFO::n_str_type.
 *
 * A selected index number can be saved in ::PORT_SETTINGS::str_type to
 * configure the selected string type for the specific serial port.
 */
typedef struct
{
  uint16_t idx;          ///< string type index, 0..::RECEIVER_INFO::n_str_type-1
  STR_TYPE_INFO str_type_info;

} STR_TYPE_INFO_IDX;

#define _mbg_swab_str_type_info_idx( _p )           \
do                                                  \
{                                                   \
  _mbg_swab16( &(_p)->idx );                        \
  _mbg_swab_str_type_info( &(_p)->str_type_info );  \
} while ( 0 )


/**
 * @brief Enumeration of modes supported for time string transmission
 *
 * This determines e.g. at which point in time a string starts
 * to be transmitted via the serial port.
 * Used with ::PORT_SETTINGS::mode.
 *
 * @see ::STR_MODE_MASKS
 */
enum STR_MODES
{
  STR_ON_REQ,     ///< transmission on request by received '?' character only
  STR_PER_SEC,    ///< transmission automatically if second changes
  STR_PER_MIN,    ///< transmission automatically if minute changes
  STR_AUTO,       ///< transmission automatically if required, e.g. on capture event
  STR_ON_REQ_SEC, ///< transmission if second changes and a request has been received before
  N_STR_MODE      ///< the number of known modes
};


/**
 * @brief Bit masks associated with ::STR_MODES
 *
 * Used with ::STR_TYPE_INFO::supp_modes to indicate which
 * transmission modes are supported by the particular string type.
 *
 * @see ::STR_MODES
 */
enum STR_MODE_MASKS
{
  MSK_STR_ON_REQ     = ( 1UL << STR_ON_REQ ),      ///< see ::STR_ON_REQ
  MSK_STR_PER_SEC    = ( 1UL << STR_PER_SEC ),     ///< see ::STR_PER_SEC
  MSK_STR_PER_MIN    = ( 1UL << STR_PER_MIN ),     ///< see ::STR_PER_MIN
  MSK_STR_AUTO       = ( 1UL << STR_AUTO ),        ///< see ::STR_AUTO
  MSK_STR_ON_REQ_SEC = ( 1UL << STR_ON_REQ_SEC )   ///< see ::STR_ON_REQ_SEC
};


/**
 * @brief Initializer for short name strings associated with ::STR_MODES
 *
 * @see ::STR_MODES
 */
#define DEFAULT_SHORT_MODE_NAMES \
{                                \
  "'?'",                         \
  "1 sec",                       \
  "1 min",                       \
  "auto",                        \
  "'?' sec"                      \
}


/**
 * @brief Default initializers for English mode name strings
 *
 * Initializers for multi-language strings can be found in pcpslstr.h.
 *
 * @see ::STR_MODES
 */
#define ENG_MODE_NAME_STR_ON_REQ       "on request '?' only"
#define ENG_MODE_NAME_STR_PER_SEC      "per second"
#define ENG_MODE_NAME_STR_PER_MIN      "per minute"
#define ENG_MODE_NAME_STR_AUTO         "automatically"
#define ENG_MODE_NAME_STR_ON_REQ_SEC   "sec after request"


/**
 * @brief Initializer for an English mode name string table
 *
 * Initializers for multi-language strings can be found in pcpslstr.h.
 *
 * @see ::STR_MODES
 */
#define DEFAULT_ENG_MODE_NAMES   \
{                                \
  ENG_MODE_NAME_STR_ON_REQ,      \
  ENG_MODE_NAME_STR_PER_SEC,     \
  ENG_MODE_NAME_STR_PER_MIN,     \
  ENG_MODE_NAME_STR_AUTO,        \
  ENG_MODE_NAME_STR_ON_REQ_SEC   \
}


/*
 *  The modes below are supported by most string types:
 */
#define DEFAULT_STR_MODES \
(                         \
  MSK_STR_ON_REQ |        \
  MSK_STR_PER_SEC |       \
  MSK_STR_PER_MIN         \
)


/*
 *  The modes below can be used with the capture string:
 */
#define DEFAULT_STR_MODES_UCAP \
(                              \
  MSK_STR_ON_REQ |             \
  MSK_STR_AUTO                 \
)



/**
 * @brief The number of string types supported by legacy DCF77 receivers
 *
 * For receivers supporting a ::RECEIVER_INFO this should be determined
 * from ::RECEIVER_INFO::n_str_type.
 *
 * @see ::DEFAULT_SUPP_STR_TYPES_DCF
 */
#define DEFAULT_N_STR_TYPE_DCF  1

/**
 * @brief Bit mask of string types supported by legacy DCF77 receivers
 *
 * For receivers supporting a ::RECEIVER_INFO this should be determined
 * from ::PORT_INFO::supp_str_types.
 *
 * @see ::DEFAULT_N_STR_TYPE_DCF
 */
#define DEFAULT_SUPP_STR_TYPES_DCF \
  ( ( 1UL << DEFAULT_N_STR_TYPE_DCF ) - 1 )



/**
 * @brief The number of string types supported by legacy GPS receivers
 *
 * For receivers supporting a ::RECEIVER_INFO this should be determined
 * from ::RECEIVER_INFO::n_str_type.
 *
 * @see ::DEFAULT_SUPP_STR_TYPES_GPS
 */
#define DEFAULT_N_STR_TYPE_GPS  2

/**
 * @brief Bit mask of string types supported by legacy GPS receivers
 *
 * For receivers supporting a ::RECEIVER_INFO this should be determined
 * from ::PORT_INFO::supp_str_types.
 *
 * @see ::DEFAULT_N_STR_TYPE_GPS
 */
#define DEFAULT_SUPP_STR_TYPES_GPS  \
  ( ( 1UL << DEFAULT_N_STR_TYPE_GPS ) - 1 )



/*
 * The number of serial ports which are at least available
 * even with very old GPS receiver models. For devices providing
 * a ::RECEIVER_INFO structure the number of provided COM ports
 * is available in ::RECEIVER_INFO::n_com_ports.
 */
#define DEFAULT_N_COM   2

/*
 * By default that's also the number of ports
 * currently available:
 */
#ifndef N_COM
  #define N_COM     DEFAULT_N_COM
#endif

/**
 * @brief A The structure used to store the configuration of two serial ports
 *
 * @deprecated This structure is deprecated, ::PORT_SETTINGS and related structures
 * should be used instead, if supported by the device.
 */
typedef struct
{
  COM_PARM com[DEFAULT_N_COM];    ///< COM0 and COM1 settings
  uint8_t mode[DEFAULT_N_COM];    ///< COM0 and COM1 output mode

} PORT_PARM;

#define _mbg_swab_port_parm( _p )         \
do                                        \
{                                         \
  int i;                                  \
  for ( i = 0; i < DEFAULT_N_COM; i++ )   \
  {                                       \
    _mbg_swab_com_parm( &(_p)->com[i] );  \
    /* no need to swap mode byte */       \
  }                                       \
} while ( 0 )


/**
 * @brief Deprecated codes for mode of operation
 *
 * @deprecated These codes have been used with the
 * deprecated ::PORT_PARM::mode. They are only still
 * defined for compatibility with older devices.
 *
 * @see ::STR_MODES
 */
enum
{
  /* STR_ON_REQ,   defined above */
  /* STR_PER_SEC,  defined above */
  /* STR_PER_MIN,  defined above */
  N_STR_MODE_0 = STR_AUTO,   /* COM0 and COM1 */
  STR_UCAP = N_STR_MODE_0,
  STR_UCAP_REQ,
  N_STR_MODE_1               /* COM1 only */
};



/**
 * @defgroup group_icode IRIG time codes
 *
 * The following definitions are used to configure an optional
 * on-board IRIG input or output. Which frame types are supported
 * by a device depends on the device type, and may eventually
 * depend on the device's firmware version.
 *
 * All IRIG frames transport the day-of-year number plus the time-of-day,
 * and include a control field segment which can transport user defined
 * information.
 *
 * Some newer IRIG frames are compatible with older frame types but support
 * well defined extensions like the year number, local time offset, DST status,
 * etc., in the control fields:
 *
 * The following specification can be found in IRIG Standard 200-04 (September 2004):
 *
 * Format A: 1k pps
 * Format B: 100 pps
 * Format D: 1 ppm
 * Format E: 10 pps
 * Format G: 10k pps
 * Format H: 1 pps
 *
 * 1st digit: Modulation Frequency
 *   0 Pulse width code
 *   1 Sine wave, amplitude modulated
 *   2 Manchester modulated
 *
 * 2nd digit: Frequency / Resolution
 *   0: No carrier / index count interval
 *   1: 100 Hz / 10 ms
 *   2: 1 kHz / 1 ms
 *   3: 10 kHz / 0.1 ms
 *   4: 100 kHz / 10 ms
 *   5: 1 MHz / 1 ms
 *
 * 3rd digit: Coded expressions
 *   0: DOY+TOD, CF, SBS
 *   1: DOY+TOD, CF
 *   2: DOY+TOD
 *   3: DOY+TOD, SBS
 *   4: DOY+TOD, Year, CF, SBS
 *   5: DOY+TOD, Year, CF
 *   6: DOY+TOD, Year
 *   7: DOY+TOD, Year, SBS
 *
 *
 * Table of Permissible Code Formats
 *
 * Letter 1st digit  2nd digit    3rd digit
 * ----------------------------------------------
 *   A      0,1,2    0,3,4,5      0,1,2,3,4,5,6,7
 *   B      0,1,2    0,2,3,4,5    0,1,2,3,4,5,6,7
 *   D      0,1      0,1,2        1,2
 *   E      0,1      0,1,2        1,2,5,6
 *   G      0,1,2    0,4,5        1,2,5,6
 *   H      0,1      0,1,2        1,2
 *
 * - Known IRIG signal code types:
 *  - \b  A002:             1000 bps, DCLS, time-of-year
 *  - \b  A003:             1000 bps, DCLS, time-of-year, SBS
 *  - \b  A132:             1000 bps, 10 kHz carrier, time-of-year
 *  - \b  A133:             1000 bps, 10 kHz carrier, time-of-year, SBS
 *  - \b  B002:             100 bps, DCLS, time-of-year
 *  - \b  B003:             100 bps, DCLS, time-of-year, SBS
 *  - \b  B122:             100 bps, 1 kHz carrier, time-of-year
 *  - \b  B123:             100 bps, 1 kHz carrier, time-of-year, SBS
 *  - \b  B006:             100 bps, DCLS, complete date
 *  - \b  B007:             100 bps, DCLS, complete date, SBS
 *  - \b  B126:             100 bps, 1 kHz carrier, complete date
 *  - \b  B127:             100 bps, 1 kHz carrier, complete date, SBS
 *  - \b  B220/1344:        100 bps, DCLS, manchester encoded, IEEE1344 extensions
 *  - \b  B222:             100 bps, DCLS, manchester encoded, time-of-year
 *  - \b  B223:             100 bps, DCLS, manchester encoded, time-of-year, SBS
 *  - \b  G002:             10 kbps, DCLS, time-of-year
 *  - \b  G142:             10 kbps, 100 kHz carrier, time-of-year
 *  - \b  G006:             10 kbps, DCLS, complete date
 *  - \b  G146:             10 kbps, 100 kHz carrier, complete date
 *  - \b  AFNOR:            100 bps, 1 kHz carrier, SBS, complete date
 *  - \b  AFNOR DC:         100 bps, DCLS, SBS, complete date
 *  - \b  IEEE1344:         100 bps, 1 kHz carrier, time-of-year, SBS, IEEE 1344 extensions (B120)
 *  - \b  IEEE1344 DC:      100 bps, DCLS, time-of-year, SBS, IEEE 1344 extensions (B000)
 *  - \b  C37.118:          like IEEE 1344, but %UTC offset applied with reversed sign
 *  - \b  C37.118 DC:       like IEEE 1344 DC, but %UTC offset applied with reversed sign
 *
 * - time-of-year: day-of-year, hours, minutes, seconds
 * - complete date: time-of-year plus year number
 * - SBS: straight binary seconds, second-of-day
 *
 * AFNOR codes are based on the french standard AFNOR NF S87-500
 *
 * IEEE 1344 codes are defined in IEEE standard 1344-1995. The code frame is compatible
 * with B002/B122 but provides some well defined extensions in the control field which
 * include a quality indicator (time figure of merit, TFOM), year number, DST and leap
 * second status, and local time offset from %UTC.
 *
 * IEEE C37.118 codes are defined in IEEE standard C37.118-2005 which includes a revised version
 * of the IEEE 1344 standard from 1995. These codes provide the same extensions as IEEE 1344
 * but unfortunately determine that the %UTC offset has to be applied with reversed sign.
 *
 * For example, if a -6 hours UTC offset is transmitted in the time code:<br>
 * IEEE 1344:    (IRIG time 14:43:27 h) - (offs -6 h) = (UTC 20:43:27)<br>
 * IEEE C37.118: (IRIG time 14:43:27 h) + (offs -6 h) = (UTC 08:43:27)<br>
 *
 * @see @ref MSK_ICODE_RX_UTC_OFFS_ADD and @ref MSK_ICODE_RX_UTC_OFFS_SUB
 *
 * @note There are 3rd party IRIG devices out there which apply the %UTC offset as specified
 * in IEEE C37.118-2005, but claim to be compatible with IEEE 1344. So if local time is transmitted
 * by the timecode then care must be taken that the %UTC offset is evaluated by the timecode
 * receiver in the same way as computed by the timecode generator. Otherwise the %UTC
 * time computed by the receiver may be <b>wrong</b>.
 *
 * @{ */

/**
 * @brief Known IRIG TX code formats
 *
 * Used with ::IRIG_SETTINGS::icode for IRIG transmitters.
 * For IRIG receivers see ::ICODE_RX_CODES.
 *
 * Meinberg timecode transmitters always generate the unmodulated (DCLS)
 * and usually the modulated timecode signals internally at the same time,
 * so the code definitions always refer to both.
 *
 * @note Not all device may provide both the modulated and unmodulated
 * signal externally.
 */
enum ICODE_TX_CODES
{
  ICODE_TX_B002_B122,
  ICODE_TX_B003_B123,
  ICODE_TX_A002_A132,
  ICODE_TX_A003_A133,
  ICODE_TX_AFNOR,
  ICODE_TX_IEEE1344,
  ICODE_TX_B2201344,   ///< DCLS only
  ICODE_TX_B222,       ///< DCLS only
  ICODE_TX_B223,       ///< DCLS only
  ICODE_TX_B006_B126,
  ICODE_TX_B007_B127,
  ICODE_TX_G002_G142,
  ICODE_TX_G006_G146,
  ICODE_TX_C37118,
  ICODE_TX_TXC101,
  ICODE_TX_E002_E112,
  ICODE_TX_NASA36,
  ICODE_TX_A006_A136,
  ICODE_TX_A007_A137,
  N_ICODE_TX           ///< number of known codes
};


/**
 * @brief Initializers for TX timecode format name strings
 *
 * @see ::ICODE_TX_CODES
 */
#define DEFAULT_ICODE_TX_NAMES          \
{                                       \
  /* B002_B122 */  "B002+B122",         \
  /* B003_B123 */  "B003+B123",         \
  /* A002_A132 */  "A002+A132",         \
  /* A003_A133 */  "A003+A133",         \
  /* AFNOR     */  "AFNOR NF S87-500",  \
  /* IEEE1344  */  "IEEE 1344",         \
  /* B2201344  */  "B220(1344) DCLS",   \
  /* B222      */  "B222 DCLS",         \
  /* B223      */  "B223 DCLS",         \
  /* B006_B126 */  "B006+B126",         \
  /* B007_B127 */  "B007+B127",         \
  /* G002_G142 */  "G002+G142",         \
  /* G006_G146 */  "G006+G146",         \
  /* C37118    */  "IEEE C37.118",      \
  /* TXC101    */  "TXC-101 DTR-6",     \
  /* E002_E112 */  "E002+E112",         \
  /* NASA36    */  "NASA 36",           \
  /* A006_A136 */  "A006+A136",         \
  /* A007_A137 */  "A007+A137"          \
}

/**
 * @brief Initializers for short TX timecode format name strings
 *
 * @note Must not be longer than 10 printable characters
 *
 * @see ::ICODE_TX_CODES
 */
#define DEFAULT_ICODE_TX_NAMES_SHORT \
{                                    \
  /* B002_B122 */  "B002+B122",      \
  /* B003_B123 */  "B003+B123",      \
  /* A002_A132 */  "A002+A132",      \
  /* A003_A133 */  "A003+A133",      \
  /* AFNOR     */  "AFNOR NF S",     \
  /* IEEE1344  */  "IEEE 1344",      \
  /* B2201344  */  "B220/1344",      \
  /* B222      */  "B222 DC",        \
  /* B223      */  "B223 DC",        \
  /* B006_B126 */  "B006+B126",      \
  /* B007_B127 */  "B007+B127",      \
  /* G002_G142 */  "G002+G142",      \
  /* G006_G146 */  "G006+G146",      \
  /* C37118    */  "C37.118",        \
  /* TXC101    */  "TXC-101",        \
  /* E002_E112 */  "E002+E112",      \
  /* NASA36    */  "NASA 36",        \
  /* A006_A136 */  "A006+A136",      \
  /* A007_A137 */  "A007+A137"       \
}


/**
 * @brief Initializers for English TX format description strings
 *
 * @see ::ICODE_TX_CODES
 */
#define DEFAULT_ICODE_TX_DESCRIPTIONS_ENG                                                                                       \
{                                                                                                                               \
  /* B002_B122 */  "100 bps, DCLS or 1 kHz carrier",                                                                            \
  /* B003_B123 */  "100 bps, DCLS or 1 kHz carrier, SBS",                                                                       \
  /* A002_A132 */  "1000 bps, DCLS or 10 kHz carrier",                                                                          \
  /* A003_A133 */  "1000 bps, DCLS or 10 kHz carrier, SBS",                                                                     \
  /* AFNOR     */  "100 bps, DCLS or 1 kHz carrier, complete date, SBS",                                                        \
  /* IEEE1344  */  "100 bps, DCLS or 1 kHz carrier, 2 digit year number, SBS, UTC offset, DST and Leap sec status",             \
  /* B2201344  */  "100 bps, Manchester enc., DCLS only, 2 digit year number, SBS, UTC offset, DST and Leap sec status",        \
  /* B222      */  "100 bps, Manchester enc., DCLS only",                                                                       \
  /* B223      */  "100 bps, Manchester enc., DCLS only, SBS",                                                                  \
  /* B006_B126 */  "100 bps, DCLS or 1 kHz carrier, 2 digit year number",                                                       \
  /* B007_B127 */  "100 bps, DCLS or 1 kHz carrier, 2 digit year number, SBS",                                                  \
  /* G002_G142 */  "10 kbps, DCLS or 100 kHz carrier",                                                                          \
  /* G006_G146 */  "10 kbps, DCLS or 100 kHz carrier, 2 digit year number",                                                     \
  /* C37118    */  "100 bps, DCLS or 1 kHz carrier, 2 digit year number, SBS, UTC offs. reverse to 1344, DST/Leap sec status",  \
  /* TXC101    */  "code from TV time sync device TXC-101 DTR-6",                                                               \
  /* E002_E112 */  "10 bps, DCLS or 100 Hz carrier",                                                                            \
  /* NASA36    */  "100 bps, DCLS or 1 kHz carrier",                                                                            \
  /* A006_A136 */  "1000 bps, DCLS or 10 kHz carrier, 2 digit year number",                                                     \
  /* A007_A137 */  "1000 bps, DCLS or 10 kHz carrier, 2 digit year number, SBS"                                                 \
}


/**
 * @brief Bit masks used with ::IRIG_INFO::supp_codes for TX
 *
 * These bit masks are used with timecode receivers only
 *
 * @see @ref ICODE_TX_CODES
 * @see @ref ICODE_RX_CODES
 * @see @ref ICODE_RX_MASKS
 *
 * @anchor ICODE_TX_MASKS @{ */

#define MSK_ICODE_TX_B002_B122    ( 1UL << ICODE_TX_B002_B122 )
#define MSK_ICODE_TX_B003_B123    ( 1UL << ICODE_TX_B003_B123 )
#define MSK_ICODE_TX_A002_A132    ( 1UL << ICODE_TX_A002_A132 )
#define MSK_ICODE_TX_A003_A133    ( 1UL << ICODE_TX_A003_A133 )
#define MSK_ICODE_TX_AFNOR        ( 1UL << ICODE_TX_AFNOR )
#define MSK_ICODE_TX_IEEE1344     ( 1UL << ICODE_TX_IEEE1344 )
#define MSK_ICODE_TX_B2201344     ( 1UL << ICODE_TX_B2201344 )
#define MSK_ICODE_TX_B222         ( 1UL << ICODE_TX_B222 )
#define MSK_ICODE_TX_B223         ( 1UL << ICODE_TX_B223 )
#define MSK_ICODE_TX_B006_B126    ( 1UL << ICODE_TX_B006_B126 )
#define MSK_ICODE_TX_B007_B127    ( 1UL << ICODE_TX_B007_B127 )
#define MSK_ICODE_TX_G002_G142    ( 1UL << ICODE_TX_G002_G142 )
#define MSK_ICODE_TX_G006_G146    ( 1UL << ICODE_TX_G006_G146 )
#define MSK_ICODE_TX_C37118       ( 1UL << ICODE_TX_C37118 )
#define MSK_ICODE_TX_TXC101       ( 1UL << ICODE_TX_TXC101 )
#define MSK_ICODE_TX_E002_E112    ( 1UL << ICODE_TX_E002_E112 )
#define MSK_ICODE_TX_NASA36       ( 1UL << ICODE_TX_NASA36 )
#define MSK_ICODE_TX_A006_A136    ( 1UL << ICODE_TX_A006_A136 )
#define MSK_ICODE_TX_A007_A137    ( 1UL << ICODE_TX_A007_A137 )

/** @} anchor ICODE_TX_MASKS */


/**
 * @brief A mask of IRIG TX formats with manchester encoded DC output
 */
#define MSK_ICODE_TX_DC_MANCH \
(                             \
  MSK_ICODE_TX_B2201344     | \
  MSK_ICODE_TX_B222         | \
  MSK_ICODE_TX_B223           \
)

/**
 * @brief A mask of IRIG TX formats with 100 Hz carrier
 */
#define MSK_ICODE_TX_100HZ  \
(                           \
  MSK_ICODE_TX_E002_E112    \
)

/**
 * @brief A mask of IRIG TX formats with 1 kHz carrier
 */
#define MSK_ICODE_TX_1KHZ  \
(                          \
  MSK_ICODE_TX_B002_B122 | \
  MSK_ICODE_TX_B003_B123 | \
  MSK_ICODE_TX_AFNOR     | \
  MSK_ICODE_TX_IEEE1344  | \
  MSK_ICODE_TX_B2201344  | \
  MSK_ICODE_TX_B222      | \
  MSK_ICODE_TX_B223      | \
  MSK_ICODE_TX_B006_B126 | \
  MSK_ICODE_TX_B007_B127 | \
  MSK_ICODE_TX_C37118    | \
  MSK_ICODE_TX_NASA36      \
)

/**
 * @brief A mask of IRIG TX formats with 10 kHz carrier
 */
#define MSK_ICODE_TX_10KHZ \
(                          \
  MSK_ICODE_TX_A002_A132 | \
  MSK_ICODE_TX_A003_A133 | \
  MSK_ICODE_TX_A006_A136 | \
  MSK_ICODE_TX_A007_A137   \
)

/**
 * @brief A mask of IRIG TX formats with 100 kHz carrier
 */
#define MSK_ICODE_TX_100KHZ \
(                           \
  MSK_ICODE_TX_G002_G142  | \
  MSK_ICODE_TX_G006_G146    \
)

/**
 * @brief A mask of IRIG TX formats with 10 bps data rate
 */
#define MSK_ICODE_TX_10BPS  \
(                           \
  MSK_ICODE_TX_E002_E112    \
)

/**
 * @brief A mask of IRIG TX formats with 100 bps data rate
 */
#define MSK_ICODE_TX_100BPS \
(                           \
  MSK_ICODE_TX_B002_B122  | \
  MSK_ICODE_TX_B003_B123  | \
  MSK_ICODE_TX_AFNOR      | \
  MSK_ICODE_TX_IEEE1344   | \
  MSK_ICODE_TX_B006_B126  | \
  MSK_ICODE_TX_B007_B127  | \
  MSK_ICODE_TX_C37118       \
)

/**
 * @brief A mask of IRIG TX formats with 1000 bps data rate
 */
#define MSK_ICODE_TX_1000BPS \
(                            \
  MSK_ICODE_TX_A002_A132   | \
  MSK_ICODE_TX_A003_A133   | \
  MSK_ICODE_TX_A006_A136   | \
  MSK_ICODE_TX_A007_A137     \
)

/**
 * @brief A mask of IRIG TX formats with 10 kbps data rate
 */
#define MSK_ICODE_TX_10000BPS \
(                             \
  MSK_ICODE_TX_G002_G142    | \
  MSK_ICODE_TX_G006_G146      \
)

/**
 * @brief A mask of IRIG TX formats supporting 10ths of seconds
 */
#define MSK_ICODE_TX_HAS_SEC10THS \
(                                 \
  MSK_ICODE_TX_A002_A132        | \
  MSK_ICODE_TX_A003_A133        | \
  MSK_ICODE_TX_G002_G142        | \
  MSK_ICODE_TX_G006_G146        | \
  MSK_ICODE_TX_A006_A136        | \
  MSK_ICODE_TX_A007_A137          \
)

/**
 * @brief A mask of IRIG TX formats supporting 100ths of seconds
 */
#define MSK_ICODE_TX_HAS_SEC100THS \
(                                  \
  MSK_ICODE_TX_G002_G142         | \
  MSK_ICODE_TX_G006_G146           \
)

/**
 * @brief A mask of IRIG TX formats supporting a 2 digit year number
 */
#define MSK_ICODE_TX_HAS_SHORT_YEAR \
(                                   \
  MSK_ICODE_TX_AFNOR              | \
  MSK_ICODE_TX_IEEE1344           | \
  MSK_ICODE_TX_B2201344           | \
  MSK_ICODE_TX_B006_B126          | \
  MSK_ICODE_TX_B007_B127          | \
  MSK_ICODE_TX_G006_G146          | \
  MSK_ICODE_TX_C37118             | \
  MSK_ICODE_TX_A006_A136          | \
  MSK_ICODE_TX_A007_A137            \
)

/**
 * @brief A mask of IRIG TX formats supporting a 2 digit year number
 *
 * This is after the P6 identifier.
 */
 #define MSK_ICODE_TX_HAS_SHORT_YEAR_AFTER_P6   \
(                                               \
  MSK_ICODE_TX_G006_G146                        \
)

/**
 * @brief A mask of IRIG TX formats supporting TFOM
 */
#define MSK_ICODE_TX_HAS_TFOM \
(                             \
  MSK_ICODE_TX_IEEE1344     | \
  MSK_ICODE_TX_C37118         \
)

/**
 * @brief A mask of IRIG TX formats supporting CTQ continuous time quality
 *
 * This has been introduced in IEEE C37.118.1-2011
 */
#define MSK_ICODE_TX_HAS_CTQ  \
(                             \
  MSK_ICODE_TX_IEEE1344     | \
  MSK_ICODE_TX_C37118         \
)

/**
 * @brief A mask of IRIG TX formats supporting time zone information
 */
#define MSK_ICODE_TX_HAS_TZI \
(                            \
  MSK_ICODE_TX_IEEE1344    | \
  MSK_ICODE_TX_C37118        \
)

/**
 * @brief IRIG TX formats where UTC offset must be subtracted to yield UTC
 *
 * A mask of IRIG formats where the decoded UTC offset must be
 * subtracted from the time decoded from the IRIG signal to yield UTC, e.g.:<br>
 * (IRIG time 14:43:27 h) - (offs -6 h) = (UTC 20:43:27)
 */
#define MSK_ICODE_TX_UTC_OFFS_SUB \
(                                 \
  MSK_ICODE_TX_IEEE1344           \
)

/**
 * @brief IRIG TX formats where UTC offset must be added to yield UTC
 *
 * A mask of IRIG formats where the decoded UTC offset must be
 * added to the time decoded from the IRIG signal to yield UTC, e.g.:<br>
 * (IRIG time 14:43:27 h) + (offs -6 h) = (UTC 08:43:27)
 */
#define MSK_ICODE_TX_UTC_OFFS_ADD \
(                                 \
  MSK_ICODE_TX_C37118             \
)

/**
 * @brief A mask of IRIG TX formats supporting a day of week number
 */
#define MSK_ICODE_TX_HAS_AFNOR_WDAY \
(                                   \
  MSK_ICODE_TX_AFNOR              | \
  MSK_ICODE_TX_AFNOR_DC             \
)

/**
 * @brief A mask of IRIG TX formats supporting a date (day-of-month, month)
 */
#define MSK_ICODE_TX_HAS_AFNOR_DATE \
(                                   \
  MSK_ICODE_TX_AFNOR              | \
  MSK_ICODE_TX_AFNOR_DC             \
)


/**
 * @brief The default mask of IRIG TX formats supported by IRIG transmitters
 *
 * @note The formats which are actually supported should be retrieved
 * from the device
 */
#if !defined( SUPP_MSK_ICODE_TX )
  #define SUPP_MSK_ICODE_TX  \
  (                          \
    MSK_ICODE_TX_B002_B122 | \
    MSK_ICODE_TX_B003_B123 | \
    MSK_ICODE_TX_A002_A132 | \
    MSK_ICODE_TX_A003_A133 | \
    MSK_ICODE_TX_AFNOR       \
  )
#endif



/**
 * @brief Known IRIG RX code formats
 *
 * Used with ::IRIG_SETTINGS::icode for IRIG receivers.
 * For IRIG transmitters see ::ICODE_TX_CODES.
 *
 * The SBS value is redundant and can easily by computed
 * from the time-of-day, so Meinberg time code receivers
 * usually don't evaluate the SBS field anyway, and thus
 * it makes no difference if a code with or withour SBS
 * is supplied.
 */
enum ICODE_RX_CODES
{
  ICODE_RX_B122_B123,    ///< modulated
  ICODE_RX_A132_A133,    ///< modulated
  ICODE_RX_B002_B003,    ///< DCLS
  ICODE_RX_A002_A003,    ///< DCLS
  ICODE_RX_AFNOR,        ///< modulated
  ICODE_RX_AFNOR_DC,     ///< DCLS
  ICODE_RX_IEEE1344,     ///< modulated
  ICODE_RX_IEEE1344_DC,  ///< DCLS
  ICODE_RX_B126_B127,    ///< modulated
  ICODE_RX_B006_B007,    ///< DCLS
  ICODE_RX_G142,         ///< modulated (G143 is undefined, SBS not supported with Gxxx)
  ICODE_RX_G002,         ///< DCLS (G003 is undefined, SBS not supported with Gxxx)
  ICODE_RX_C37118,       ///< modulated
  ICODE_RX_C37118_DC,    ///< DCLS
  ICODE_RX_TXC101,       ///< modulated
  ICODE_RX_TXC101_DC,    ///< DCLS
  ICODE_RX_E112,         ///< modulated
  ICODE_RX_E002,         ///< DCLS
  ICODE_RX_NASA36,       ///< modulated
  ICODE_RX_NASA36_DC,    ///< DCLS
  ICODE_RX_A136_A137,    ///< modulated
  ICODE_RX_A006_A007,    ///< DCLS
  ICODE_RX_G146,         ///< modulated (G147 is undefined, SBS not supported with Gxxx)
  ICODE_RX_G006,         ///< DCLS (G007 is undefined, SBS not supported with Gxxx)
  N_ICODE_RX             ///< the number of known codes
};

/**
 * @brief Initializers for RX timecode format name strings
 *
 * @see ::ICODE_RX_CODES
 */
#define DEFAULT_ICODE_RX_NAMES \
{                              \
  /* B122_B123   */  "B122/B123",                 \
  /* A132_A133   */  "A132/A133",                 \
  /* B002_B003   */  "B002/B003 (DCLS)",          \
  /* A002_A003   */  "A002/A003 (DCLS)",          \
  /* AFNOR       */  "AFNOR NF S87-500",          \
  /* AFNOR_DC    */  "AFNOR NF S87-500 (DCLS)",   \
  /* IEEE1344    */  "IEEE1344",                  \
  /* IEEE1344_DC */  "IEEE1344 (DCLS)",           \
  /* B126_B127   */  "B126/B127",                 \
  /* B006_B007   */  "B006/B007 (DCLS)",          \
  /* G142        */  "G142",                 \
  /* G002        */  "G002 (DCLS)",          \
  /* C37118      */  "C37.118",                   \
  /* C37118_DC   */  "C37.118 (DCLS)",            \
  /* TXC101      */  "TXC-101 DTR-6",             \
  /* TXC101_DC   */  "TXC-101 DTR-6 (DCLS)",      \
  /* E112        */  "E112",                      \
  /* E002        */  "E002 (DCLS)",               \
  /* NASA36      */  "NASA-36",                   \
  /* NASA36_DC   */  "NASA-36 (DCLS)",            \
  /* A136_A137   */  "A136/A137",                 \
  /* A006_A007   */  "A006/A007 (DCLS)",          \
  /* G146        */  "G146",                      \
  /* G006        */  "G006 (DCLS)"                \
}

/**
 * @brief Initializers for short RX timecode format name strings
 *
 * @note Must not be longer than 11 printable characters
 *
 * @see ::ICODE_RX_CODES
 */
#define DEFAULT_ICODE_RX_NAMES_SHORT    \
{                                       \
  /* B122_B123   */  "B122/B123",       \
  /* A132_A133   */  "A132/A133",       \
  /* B002_B003   */  "B002/B003",       \
  /* A002_A003   */  "A002/A003",       \
  /* AFNOR       */  "AFNOR NF S",      \
  /* AFNOR_DC    */  "AFNOR DC",        \
  /* IEEE1344    */  "IEEE1344",        \
  /* IEEE1344_DC */  "IEEE1344 DC",     \
  /* B126_B127   */  "B126/B127",       \
  /* B006_B007   */  "B006/B007",       \
  /* G142        */  "G142",            \
  /* G002        */  "G002 DC",            \
  /* C37118      */  "C37.118",         \
  /* C37118_DC   */  "C37.118 DC",      \
  /* TXC101      */  "TXC-101",         \
  /* TXC101_DC   */  "TXC-101 DC",      \
  /* E112        */  "E112",            \
  /* E002        */  "E002 DC",         \
  /* NASA36      */  "NASA-36",         \
  /* NASA36_DC   */  "NASA-36 DC",      \
  /* A136_A137   */  "A136/A137",       \
  /* A006_A007   */  "A006/A007",       \
  /* G146        */  "G146",            \
  /* G006        */  "G006 DC"          \
}


/**
 * @brief Initializers for English RX format description strings
 *
 * @see ::ICODE_RX_CODES
 */
#define DEFAULT_ICODE_RX_DESCRIPTIONS_ENG                                             \
{                                                                                     \
  /* B122_B123   */  "100 bps, 1 kHz carrier, SBS optionally",                        \
  /* A132_A133   */  "1000 bps, 10 kHz carrier, SBS optionally",                      \
  /* B002_B003   */  "100 bps, DCLS, SBS optionally",                                 \
  /* A002_A003   */  "1000 bps, DCLS, SBS optionally",                                \
  /* AFNOR       */  "100 bps, 1 kHz carrier, complete date, SBS",                    \
  /* AFNOR_DC    */  "100 bps, DCLS, complete date, SBS",                             \
  /* IEEE1344    */  "100 bps, 1 kHz carrier, SBS, time zone info",                   \
  /* IEEE1344_DC */  "100 bps, DCLS, SBS, time zone info",                            \
  /* B126_B127   */  "100 bps, 1 kHz carrier, 2 digit year number, SBS optionally",   \
  /* B006_B007   */  "100 bps, DCLS, 2 digit year number, SBS optionally",            \
  /* G142        */  "10 kbps, 100 kHz carrier",                                      \
  /* G002        */  "10 kbps, DCLS",                                                 \
  /* C37118      */  "like IEEE1344, but UTC offset with reversed sign",              \
  /* C37118_DC   */  "like IEEE1344 DC, but UTC offset with reversed sign",           \
  /* TXC101      */  "code from TV time sync device TXC-101 DTR-6",                   \
  /* TXC101_DC   */  "DC code from TV time sync device TXC-101 DTR-6",                \
  /* E112        */  "10 bps, 100 Hz carrier",                                        \
  /* E002        */  "10 bps, DCLS",                                                  \
  /* NASA36      */  "100 bps, 1 kHz carrier",                                        \
  /* NASA36_DC   */  "100 bps, DCLS",                                                 \
  /* A136_A137   */  "1000 bps, 10 kHz carrier, 2 digit year number, SBS optionally", \
  /* A006_A007   */  "1000 bps, DCLS, 2 digit year number, SBS optionally",           \
  /* G146        */  "10 kbps, 100 kHz carrier, 2 digit year number",                 \
  /* G006        */  "10 kbps, DCLS, 2 digit year number"                             \
}

/**
 * @brief Bit masks used with ::IRIG_INFO::supp_codes for RX
 *
 * These bit masks are used with timecode receivers only
 *
 * @see @ref ICODE_RX_CODES
 * @see @ref ICODE_TX_CODES
 * @see @ref ICODE_TX_MASKS
 *
 * @anchor ICODE_RX_MASKS @{ */

#define MSK_ICODE_RX_B122_B123       ( 1UL << ICODE_RX_B122_B123 )
#define MSK_ICODE_RX_A132_A133       ( 1UL << ICODE_RX_A132_A133 )
#define MSK_ICODE_RX_B002_B003       ( 1UL << ICODE_RX_B002_B003 )
#define MSK_ICODE_RX_A002_A003       ( 1UL << ICODE_RX_A002_A003 )
#define MSK_ICODE_RX_AFNOR           ( 1UL << ICODE_RX_AFNOR )
#define MSK_ICODE_RX_AFNOR_DC        ( 1UL << ICODE_RX_AFNOR_DC )
#define MSK_ICODE_RX_IEEE1344        ( 1UL << ICODE_RX_IEEE1344 )
#define MSK_ICODE_RX_IEEE1344_DC     ( 1UL << ICODE_RX_IEEE1344_DC )
#define MSK_ICODE_RX_B126_B127       ( 1UL << ICODE_RX_B126_B127 )
#define MSK_ICODE_RX_B006_B007       ( 1UL << ICODE_RX_B006_B007 )
#define MSK_ICODE_RX_G142            ( 1UL << ICODE_RX_G142 )
#define MSK_ICODE_RX_G002            ( 1UL << ICODE_RX_G002 )
#define MSK_ICODE_RX_C37118          ( 1UL << ICODE_RX_C37118 )
#define MSK_ICODE_RX_C37118_DC       ( 1UL << ICODE_RX_C37118_DC )
#define MSK_ICODE_RX_TXC101          ( 1UL << ICODE_RX_TXC101 )
#define MSK_ICODE_RX_TXC101_DC       ( 1UL << ICODE_RX_TXC101_DC )
#define MSK_ICODE_RX_E112            ( 1UL << ICODE_RX_E112 )
#define MSK_ICODE_RX_E002            ( 1UL << ICODE_RX_E002 )
#define MSK_ICODE_RX_NASA36          ( 1UL << ICODE_RX_NASA36 )
#define MSK_ICODE_RX_NASA36_DC       ( 1UL << ICODE_RX_NASA36_DC )
#define MSK_ICODE_RX_A136_A137       ( 1UL << ICODE_RX_A136_A137 )
#define MSK_ICODE_RX_A006_A007       ( 1UL << ICODE_RX_A006_A007 )
#define MSK_ICODE_RX_G146            ( 1UL << ICODE_RX_G146 )
#define MSK_ICODE_RX_G006            ( 1UL << ICODE_RX_G006 )

/** @} anchor ICODE_RX_MASKS */


/**
 * @brief A mask of IRIG RX DCLS formats
 */
#define MSK_ICODE_RX_DC       \
(                             \
  MSK_ICODE_RX_B002_B003    | \
  MSK_ICODE_RX_A002_A003    | \
  MSK_ICODE_RX_AFNOR_DC     | \
  MSK_ICODE_RX_IEEE1344_DC  | \
  MSK_ICODE_RX_B006_B007    | \
  MSK_ICODE_RX_G002         | \
  MSK_ICODE_RX_C37118_DC    | \
  MSK_ICODE_RX_TXC101_DC    | \
  MSK_ICODE_RX_E002         | \
  MSK_ICODE_RX_NASA36_DC    | \
  MSK_ICODE_RX_A006_A007    | \
  MSK_ICODE_RX_G006           \
)

/**
 * @brief A mask of IRIG RX formats with 100 Hz carrier
 */
#define MSK_ICODE_RX_100HZ \
(                          \
  MSK_ICODE_RX_E112        \
)

/**
 * @brief A mask of IRIG RX formats with 1 kHz carrier
 */
#define MSK_ICODE_RX_1KHZ  \
(                          \
  MSK_ICODE_RX_B122_B123 | \
  MSK_ICODE_RX_AFNOR     | \
  MSK_ICODE_RX_IEEE1344  | \
  MSK_ICODE_RX_B126_B127 | \
  MSK_ICODE_RX_C37118    | \
  MSK_ICODE_RX_TXC101    | \
  MSK_ICODE_RX_NASA36      \
)

/**
 * @brief A mask of IRIG RX formats with 10 kHz carrier
 */
#define MSK_ICODE_RX_10KHZ \
(                          \
  MSK_ICODE_RX_A132_A133 | \
  MSK_ICODE_RX_A136_A137   \
)

/**
 * @brief A mask of IRIG RX formats with 100 kHz carrier
 */
#define MSK_ICODE_RX_100KHZ \
(                           \
  MSK_ICODE_RX_G142       | \
  MSK_ICODE_RX_G146         \
)

/**
 * @brief A mask of IRIG RX formats with 10 bps data rate
 */
#define MSK_ICODE_RX_10BPS  \
(                           \
  MSK_ICODE_RX_E002_E112  | \
  MSK_ICODE_RX_E002_E002    \
)

/**
 * @brief A mask of IRIG RX formats with 100 bps data rate
 */
#define MSK_ICODE_RX_100BPS   \
(                             \
  MSK_ICODE_RX_B122_B123    | \
  MSK_ICODE_RX_B002_B003    | \
  MSK_ICODE_RX_AFNOR        | \
  MSK_ICODE_RX_AFNOR_DC     | \
  MSK_ICODE_RX_IEEE1344     | \
  MSK_ICODE_RX_IEEE1344_DC  | \
  MSK_ICODE_RX_B126_B127    | \
  MSK_ICODE_RX_B006_B007    | \
  MSK_ICODE_RX_C37118       | \
  MSK_ICODE_RX_C37118_DC    | \
  MSK_ICODE_RX_TXC101       | \
  MSK_ICODE_RX_TXC101_DC    | \
  MSK_ICODE_RX_NASA36       | \
  MSK_ICODE_RX_NASA36_DC      \
)

/**
 * @brief A mask of IRIG RX formats with 1000 bps data rate
 */
#define MSK_ICODE_RX_1000BPS \
(                            \
  MSK_ICODE_RX_A132_A133   | \
  MSK_ICODE_RX_A002_A003   | \
  MSK_ICODE_RX_A136_A137   | \
  MSK_ICODE_RX_A006_A007     \
)

/**
 * @brief A mask of IRIG RX formats with 10 kbps data rate
 */
#define MSK_ICODE_RX_10000BPS \
(                             \
  MSK_ICODE_RX_G142         | \
  MSK_ICODE_RX_G002         | \
  MSK_ICODE_RX_G146         | \
  MSK_ICODE_RX_G006           \
)

/**
 * @brief A mask of IRIG RX formats supporting 10ths of seconds
 */
#define MSK_ICODE_RX_HAS_SEC10THS \
(                                 \
  MSK_ICODE_RX_A132_A133        | \
  MSK_ICODE_RX_A002_A003        | \
  MSK_ICODE_RX_G142             | \
  MSK_ICODE_RX_G002             | \
  MSK_ICODE_RX_A136_A137        | \
  MSK_ICODE_RX_A006_A007        | \
  MSK_ICODE_RX_G146             | \
  MSK_ICODE_RX_G006               \
)

/**
 * @brief A mask of IRIG RX formats which support 100ths of seconds
 */
#define MSK_ICODE_RX_HAS_SEC100THS \
(                                  \
  MSK_ICODE_RX_G142              | \
  MSK_ICODE_RX_G002              | \
  MSK_ICODE_RX_G146              | \
  MSK_ICODE_RX_G006                \
)

/**
 * @brief A mask of IRIG RX formats supporting a 2 digit year number after P5
 *
 * Note: This macro specifies ONLY the codes where the year number
 * is transmitted after position identifier P5.
 *
 * @see ::MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P6
 * @see ::MSK_ICODE_RX_HAS_ANY_SHORT_YEAR
 */
#define MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P5 \
(                                            \
  MSK_ICODE_RX_AFNOR                       | \
  MSK_ICODE_RX_AFNOR_DC                    | \
  MSK_ICODE_RX_IEEE1344                    | \
  MSK_ICODE_RX_IEEE1344_DC                 | \
  MSK_ICODE_RX_B126_B127                   | \
  MSK_ICODE_RX_B006_B007                   | \
  MSK_ICODE_RX_C37118                      | \
  MSK_ICODE_RX_C37118_DC                   | \
  MSK_ICODE_RX_A136_A137                   | \
  MSK_ICODE_RX_A006_A007                     \
)

/**
 * @brief A mask of IRIG RX formats supporting a 2 digit year number after P6
 *
 * Note: This macro specifies ONLY the codes where the year number
 * is transmitted after position identifier P6.
 *
 * @see ::MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P5
 * @see ::MSK_ICODE_RX_HAS_ANY_SHORT_YEAR
 */
#define MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P6 \
(                                            \
  MSK_ICODE_RX_G146                        | \
  MSK_ICODE_RX_G006                          \
)

/**
 * @brief A mask of IRIG RX formats providing any 2 digit year number
 *
 * Note: Different sets of code frames may provide a year number
 * in different locations of the transmitted code.
 *
 * @see ::MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P5
 * @see ::MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P6
 */
#define MSK_ICODE_RX_HAS_ANY_SHORT_YEAR  \
(                                        \
  MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P5 | \
  MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P6   \
)



/**
 * @brief A mask of IRIG RX formats supporting TFOM time quality indicator
 */
#define MSK_ICODE_RX_HAS_TFOM \
(                             \
  MSK_ICODE_RX_IEEE1344     | \
  MSK_ICODE_RX_IEEE1344_DC  | \
  MSK_ICODE_RX_C37118       | \
  MSK_ICODE_RX_C37118_DC      \
)

/**
 * @brief A mask of IRIG RX formats supporting CTQ continuous time quality
 *
 * This has been introduced in IEEE C37.118.1-2011
 */
#define MSK_ICODE_RX_HAS_CTQ  \
(                             \
  MSK_ICODE_RX_IEEE1344     | \
  MSK_ICODE_RX_IEEE1344_DC  | \
  MSK_ICODE_RX_C37118       | \
  MSK_ICODE_RX_C37118_DC      \
)

/**
 * @brief A mask of IRIG RX formats supporting time zone information
 */
#define MSK_ICODE_RX_HAS_TZI  \
(                             \
  MSK_ICODE_RX_IEEE1344     | \
  MSK_ICODE_RX_IEEE1344_DC  | \
  MSK_ICODE_RX_C37118       | \
  MSK_ICODE_RX_C37118_DC      \
)

/**
 * @brief IRIG RX formats where UTC offset must be subtracted to yield UTC
 *
 * A mask of IRIG formats where the decoded UTC offset must be
 * subtracted from the time decoded from the IRIG signal to yield UTC, e.g.:<br>
 * (IRIG time 14:43:27 h) - (offs -6 h) = (UTC 20:43:27)
 */
#define MSK_ICODE_RX_UTC_OFFS_SUB \
(                                 \
  MSK_ICODE_RX_IEEE1344         | \
  MSK_ICODE_RX_IEEE1344_DC        \
)

/**
 * @brief IRIG RX formats where UTC offset must be added to yield UTC
 *
 * A mask of IRIG formats where the decoded UTC offset must be
 * added to the time decoded from the IRIG signal to yield UTC, e.g.:<br>
 * (IRIG time 14:43:27 h) + (offs -6 h) = (UTC 08:43:27)
 */
#define MSK_ICODE_RX_UTC_OFFS_ADD \
(                                 \
  MSK_ICODE_RX_C37118           | \
  MSK_ICODE_RX_C37118_DC          \
)

/**
 * @brief A mask of IRIG RX formats supporting a day of week number
 */
#define MSK_ICODE_RX_HAS_AFNOR_WDAY \
(                                   \
  MSK_ICODE_RX_AFNOR              | \
  MSK_ICODE_RX_AFNOR_DC             \
)

/**
 * @brief A mask of IRIG RX formats supporting a date (day-of-month, month)
 */
#define MSK_ICODE_RX_HAS_AFNOR_DATE \
(                                   \
  MSK_ICODE_RX_AFNOR              | \
  MSK_ICODE_RX_AFNOR_DC             \
)


/**
 * @brief The default mask of IRIG RX formats supported by IRIG receivers
 *
 * @note The formats which are actually supported should be retrieved
 * from the device
 */
#if !defined( SUPP_MSK_ICODE_RX )
  #define SUPP_MSK_ICODE_RX  \
  (                          \
    MSK_ICODE_RX_B122_B123 | \
    MSK_ICODE_RX_A132_A133 | \
    MSK_ICODE_RX_B002_B003 | \
    MSK_ICODE_RX_A002_A003 | \
    MSK_ICODE_RX_AFNOR     | \
    MSK_ICODE_RX_AFNOR_DC    \
  )
#endif

/** @} defgroup group_icode */



/**
 * @brief Configuration settings of an IRIG input or output
 *
 * @see @ref group_icode
 */
typedef struct
{
  uint16_t icode;   ///< IRIG signal code, see ::ICODE_RX_CODES and ::ICODE_TX_CODES
  uint16_t flags;   ///< see ::IFLAGS_BIT_MASKS

} IRIG_SETTINGS;

#define _mbg_swab_irig_settings( _p )  \
do                                     \
{                                      \
  _mbg_swab16( &(_p)->icode );         \
  _mbg_swab16( &(_p)->flags );         \
} while ( 0 )



/**
 * @brief Flag bits used to define ::IFLAGS_BIT_MASKS
 *
 * @see ::IFLAGS_BIT_MASKS
 */
enum IFLAGS_BITS
{
  IFLAGS_BIT_DISABLE_TFOM,        ///< for RX ignore, for TX don't generate TFOM flag
  IFLAGS_BIT_TX_GEN_LOCAL_TIME,   ///< TX output local time instead of %UTC
  N_IFLAGS_BITS                   ///< number of known bits
};


/**
 * @brief Bit masks used with ::IRIG_SETTINGS::flags
 *
 * @note The presence or absence of the ::IFLAGS_DISABLE_TFOM flag for the IRIG RX
 * settings of some PCI cards may not be evaluated correctly by some firmware
 * versions for those cards, even if an IRIG code has been configured which supports
 * this flag. See the comments near the declaration of the ::_pcps_incoming_tfom_ignored
 * macro in pcpsdev.h for details.
 *
 * @see ::IFLAGS_BITS
 */
enum IFLAGS_BIT_MASKS
{
  IFLAGS_DISABLE_TFOM      = ( 1UL << IFLAGS_BIT_DISABLE_TFOM ),       ///< see ::IFLAGS_BIT_DISABLE_TFOM
  IFLAGS_TX_GEN_LOCAL_TIME = ( 1UL << IFLAGS_BIT_TX_GEN_LOCAL_TIME ),  ///< see ::IFLAGS_BIT_TX_GEN_LOCAL_TIME

  IFLAGS_MASK              = ( ( 1UL << N_IFLAGS_BITS ) - 1 )          ///< mask of all known flags
};


/**
 * @brief Current IRIG settings and supported codes
 *
 * Used to query the current IRIG settings
 * plus a mask of supported codes.
 */
typedef struct
{
  IRIG_SETTINGS settings;  ///< current settings
  uint32_t supp_codes;     ///< see @ref ICODE_TX_MASKS and @ref ICODE_RX_MASKS

} IRIG_INFO;

#define _mbg_swab_irig_info( _p )              \
do                                             \
{                                              \
  _mbg_swab_irig_settings( &(_p)->settings );  \
  _mbg_swab32( &(_p)->supp_codes );            \
} while ( 0 )


/**
 * @defgroup group_irig_comp IRIG input delay compensation
 *
 * These definitions are used with IRIG RX delay compensation
 * which is supported by some IRIG receivers. Delay compensation
 * depends on the basic frame type, so there are different records
 * required for the different frame type groups.
 *
 * @{ */

/**
 * The number of coefficients of a compensation record
 * for a single frame type group, and the structure
 * which contains those coefficients.
 */
#define N_IRIG_RX_COMP_VAL  4

/**
 * @brief A structure used to store compensation values
 */
typedef struct
{
  /**
   * @brief Delay compensation values [100 ns units]
   *
   * @note Only the first value is actually used to compensate
   * a delay, so the remaining values should be 0.
   */
  int16_t c[N_IRIG_RX_COMP_VAL];

} IRIG_RX_COMP;

#define _mbg_swab_irig_rx_comp( _p )          \
do                                            \
{                                             \
  int i;                                      \
  for ( i = 0; i < N_IRIG_RX_COMP_VAL; i++ )  \
    _mbg_swab16( &(_p)->c[i] );               \
} while ( 0 )


/** The absolute value of the maximum compensation value accepted by a device */
#define IRIG_RX_COMP_MAX   999  // [100 ns units], i.e. valid range is +/-99.9 us



/**
 * @brief Structure used to retrieve the number of records for a given type
 */
typedef struct
{
  uint16_t type;    ///< record type, see ::CAL_REC_TYPES
  uint16_t idx;     ///< index if several records of same type are supported, see ::IRIG_RX_COMP_GROUPS

} CAL_REC_HDR;

#define _mbg_swab_cal_rec_hdr( _p )  \
do                                   \
{                                    \
  _mbg_swab16( &(_p)->type );        \
  _mbg_swab16( &(_p)->idx );         \
} while ( 0 )


/**
 * @brief Types to be used with ::CAL_REC_HDR::type
 */
enum CAL_REC_TYPES
{
  CAL_REC_TYPE_UNDEF,          ///< undefined type
  CAL_REC_TYPE_IRIG_RX_COMP,   ///< IRIG receiver delay compensation
  N_CAL_REC_TYPE               ///< number of known types
};


/**
 * @brief Types to be used with ::CAL_REC_HDR::idx
 *
 * IRIG frame type groups to be distinguished for delay compensation.
 */
enum IRIG_RX_COMP_GROUPS
{
  IRIG_RX_COMP_B1,  ///< codes B1xx, AFNOR, IEEE1344
  IRIG_RX_COMP_A1,  ///< code A1xx
  IRIG_RX_COMP_B0,  ///< codes B0xx, AFNOR DC, IEEE1344 DC
  IRIG_RX_COMP_A0,  ///< code A0xx
  IRIG_RX_COMP_G1,  ///< code G14x
  IRIG_RX_COMP_G0,  ///< code G00x
  N_IRIG_RX_COMP    ///< number of compensation values
};


/**
 * @brief Initializers for format name strings
 */
#define DEFAULT_IRIG_RX_COMP_NAMES \
{                                  \
  "B1xx/AFNOR/IEEE1344",           \
  "A1xx",                          \
  "B0xx/AFNOR DC/IEEE1344 DC",     \
  "A0xx",                          \
  "G14X",                          \
  "G00X",                          \
}



/**
 * @brief Structure used to transfer calibration records
 */
typedef struct
{
  CAL_REC_HDR hdr;          ///< data header
  IRIG_RX_COMP comp_data;   ///< IRIG receiver delay compensation

} CAL_REC_IRIG_RX_COMP;

#define _mbg_swab_cal_rec_irig_rx_comp( _p )    \
do                                              \
{                                               \
  _mbg_swab_cal_rec_hdr( &(_p)->hdr );          \
  _mbg_swab_irig_rx_comp( &(_p)->comp_data );   \
} while ( 0 )

/** @} defgroup group_irig_comp */



/**
 * @brief A data type used to read the board's debug status
 *
 * @note This also includes IRIG decoder status.
 *
 * @see @ref MBG_DEBUG_STATUS_BIT_MASKS
 */
typedef uint32_t MBG_DEBUG_STATUS;

#define _mbg_swab_debug_status( _p ) \
  _mbg_swab32( _p )



/**
 * @brief Enumeration of flag bits used for debug status
 *
 * @see @ref MBG_DEBUG_STATUS_BIT_MASKS
 */
enum MBG_DEBUG_STATUS_BITS
{
  MBG_IRIG_BIT_WARMED_UP,          ///< Osc has warmed up
  MBG_IRIG_BIT_PPS_ACTIVE,         ///< PPS output is active
  MBG_IRIG_BIT_INV_CONFIG,         ///< Invalid config, e.g. data csum error
  MBG_IRIG_BIT_MSG_DECODED,        ///< IRIG msg could be decoded
  MBG_IRIG_BIT_MSG_INCONSISTENT,   ///< IRIG msg contains inconsistent data
  MBG_IRIG_BIT_LOOP_LOCKED,        ///< Decoder control loop is locked
  MBG_IRIG_BIT_JITTER_TOO_LARGE,   ///< Phase jitter too large
  MBG_IRIG_BIT_INV_REF_OFFS,       ///< %UTC ref offset not configured

  MBG_SYS_BIT_INV_TIME,            ///< Internal time not valid/set
  MBG_SYS_BIT_TIME_SET_VIA_API,    ///< On board time set externally
  MBG_SYS_BIT_INV_RTC,             ///< On board RTC invalid
  MBG_SYS_BIT_CPU_PLL_FAILED,      ///< The CPU's PLL watchdog

  N_MBG_DEBUG_BIT                  ///< The number of known bits
};

/**
 * @brief Initializers for debug status bit strings
 *
 * @see ::MBG_DEBUG_STATUS_BITS
 */
#define MBG_DEBUG_STATUS_STRS      \
{                                  \
  "Osc has warmed up",             \
  "PPS output is active",          \
  "Config set to default",         \
  "IRIG msg decoded",              \
  "IRIG msg not consistent",       \
  "Decoder control loop locked",   \
  "Phase jitter too large",        \
  "Invalid ref offset",            \
                                   \
  "Internal time not valid",       \
  "On board time set via API",     \
  "On board RTC invalid",          \
  "CPU PLL failure, needs restart" \
}


/**
 * @brief Bit masks used with ::MBG_DEBUG_STATUS
 *
 * @see ::MBG_DEBUG_STATUS_BITS
 *
 * @anchor MBG_DEBUG_STATUS_BIT_MASKS @{ */

#define MBG_IRIG_MSK_WARMED_UP        ( 1UL << MBG_IRIG_BIT_WARMED_UP )
#define MBG_IRIG_MSK_PPS_ACTIVE       ( 1UL << MBG_IRIG_BIT_PPS_ACTIVE )
#define MBG_IRIG_MSK_INV_CONFIG       ( 1UL << MBG_IRIG_BIT_INV_CONFIG )
#define MBG_IRIG_MSK_MSG_DECODED      ( 1UL << MBG_IRIG_BIT_MSG_DECODED )
#define MBG_IRIG_MSK_MSG_INCONSISTENT ( 1UL << MBG_IRIG_BIT_MSG_INCONSISTENT )
#define MBG_IRIG_MSK_LOOP_LOCKED      ( 1UL << MBG_IRIG_BIT_LOOP_LOCKED )
#define MBG_IRIG_MSK_JITTER_TOO_LARGE ( 1UL << MBG_IRIG_BIT_JITTER_TOO_LARGE )
#define MBG_IRIG_MSK_INV_REF_OFFS     ( 1UL << MBG_IRIG_BIT_INV_REF_OFFS )

#define MBG_SYS_MSK_INV_TIME          ( 1UL << MBG_SYS_BIT_INV_TIME )
#define MBG_SYS_MSK_TIME_SET_VIA_API  ( 1UL << MBG_SYS_BIT_TIME_SET_VIA_API )
#define MBG_SYS_MSK_INV_RTC           ( 1UL << MBG_SYS_BIT_INV_RTC )
#define MBG_SYS_MSK_CPU_PLL_FAILED    ( 1UL << MBG_SYS_BIT_CPU_PLL_FAILED )

/** @} anchor MBG_DEBUG_STATUS_BIT_MASKS */


/**
 * @brief A data type used to configure the ref offset
 *
 * The ref offset if the offset of the incoming reference time from %UTC.
 * For some types of signal (e.g. most IRIG frame formats) this can't be
 * determined automatically.
 *
 * Valid range: -::MBG_REF_OFFS_MAX..::MBG_REF_OFFS_MAX, or ::MBG_REF_OFFS_NOT_CFGD
 *
 * @note There's a special flag ::MBG_REF_OFFS_NOT_CFGD indicating that
 * this parameter is unconfigured, in which case a Meinberg time code
 * receiver refuses to synchronize to the time code signal unless a time
 * code frame has been configured which provides the UTC offset (namely
 * IEEE 1344 or IEEE C37.118).
 */
typedef int16_t MBG_REF_OFFS;

#define _mbg_swab_mbg_ref_offs( _p )  _mbg_swab16( (_p) )


/**
 * @brief The maximum allowed positive / negative ref offset
 */
#define MBG_REF_OFFS_MAX   ( ( 12L * 60 ) + 30 )  // [minutes]

/**
 * @brief A flag indicating that the ref offset has not yet been configured
 *
 * If this flag is set in ::MBG_REF_OFFS this means the ref offset
 * (time offset from %UTC) has not yet been configured. This is usually
 * the case for IRIG receiver devices right after they have been shipped.
 */
#define MBG_REF_OFFS_NOT_CFGD  ( (MBG_REF_OFFS) 0x8000 )



/**
 * @brief A structure used to configure optional settings
 *
 * Optional settings are a generic way to configure some extended settings.
 */
typedef struct
{
  uint32_t flags;   ///< @see ::MBG_OPT_FLAGS

} MBG_OPT_SETTINGS;

#define _mbg_swab_mbg_opt_settings( _p )  \
do                                        \
{                                         \
  _mbg_swab32( &(_p)->flags );            \
} while ( 0 )


/**
 * @brief A structure used to configure optional settings
 *
 * This structure includes the current settings, and a bit mask
 * indicating which flags are supported.
 */
typedef struct
{
  MBG_OPT_SETTINGS settings;  ///< current settings
  uint32_t supp_flags;        ///< bit mask of supported flags, see ::MBG_OPT_FLAGS

} MBG_OPT_INFO;

#define _mbg_swab_mbg_opt_info( _p )              \
do                                                \
{                                                 \
  _mbg_swab_mbg_opt_settings( &(_p)->settings );  \
  _mbg_swab32( &(_p)->supp_flags );               \
} while ( 0 )


/**
 * @brief Enumeration of flag bits used to define ::MBG_OPT_FLAGS
 */
enum MBG_OPT_BITS
{
  MBG_OPT_BIT_STR_UTC,   ///< serial time string contains %UTC time
  MBG_OPT_BIT_EMU_SYNC,  ///< always pretend to be synchronized, alternatively ::GPS_FEAT_IGNORE_LOCK may be supported
  N_MBG_OPT_BIT
};


/**
 * @brief Bit masks according to ::MBG_OPT_BITS
 *
 * Used with ::MBG_OPT_SETTINGS::flags and ::MBG_OPT_INFO::supp_flags.
 */
enum MBG_OPT_FLAGS
{
  MBG_OPT_FLAG_STR_UTC  = ( 1UL << MBG_OPT_BIT_STR_UTC ),  ///< see ::MBG_OPT_BIT_STR_UTC
  MBG_OPT_FLAG_EMU_SYNC = ( 1UL << MBG_OPT_BIT_EMU_SYNC )  ///< see ::MBG_OPT_BIT_EMU_SYNC
};



/**
 * @brief Bit coded return type for ::PCPS_GET_IRIG_CTRL_BITS
 *
 * The control bits a time code receiver has decoded from
 * the incoming time code signal.
 *
 * @note ::MBG_RAW_IRIG_DATA is more versatile and should
 * be used preferably, if supported.
 *
 * @see ::MBG_RAW_IRIG_DATA
 */
typedef uint32_t MBG_IRIG_CTRL_BITS;

#define _mbg_swab_irig_ctrl_bits( _p )  _mbg_swab32( _p )


/**
 * @brief Extract the TFOM code from ::MBG_IRIG_CTRL_BITS
 *
 * The resulting code is only valid if the configured IRIG code frame format
 * supports this. See @ref MSK_ICODE_TX_HAS_TFOM and @ref MSK_ICODE_RX_HAS_TFOM
 *
 * As specified in the IEEE 1344 standard as "Time Quality", the TFOM code is
 * the range 0x0 (locked, maximum accuracy) to 0xF (failed, data unreliable).
 */
#define _pcps_tfom_from_irig_ctrl_bits( _p ) \
        ( ( ( *(_p) ) >> 24 ) & 0x0F )



#define RAW_IRIG_SIZE    16

/**
 * @brief A buffer used to read raw IRIG data bits from an IRIG receiver
 *
 * Used to get the raw data bits from the IRIG decoder. A maximum number
 * of ::RAW_IRIG_SIZE bytes can be filled up, depending on the IRIG code.
 * If less bytes are used then the rest of the bytes are filled with zeros.
 *
 * @note The first IRIG bit received from the transmitter is saved
 * in the MSB (bit 7) of data_bytes[0], etc.
 */
typedef struct
{
  uint8_t data_bytes[RAW_IRIG_SIZE];

} MBG_RAW_IRIG_DATA;

#define _mbg_swab_mbg_raw_irig_data( _p )  _nop_macro_fnc()

/**
 * @brief Extract the TFOM code from ::MBG_RAW_IRIG_DATA
 *
 * The resulting code is only valid if the configured IRIG code frame format
 * supports this. See @ref MSK_ICODE_TX_HAS_TFOM and @ref MSK_ICODE_RX_HAS_TFOM
 *
 * As specified in the IEEE 1344 standard as "Time Quality", the TFOM code is
 * the range 0x0 (locked, maximum accuracy) to 0xF (failed, data unreliable).
 */
#define _pcps_tfom_from_raw_irig_data( _p )  \
  ( ( ( (_p)->data_bytes[9] >> 2 ) & 0x08 )  \
  | ( ( (_p)->data_bytes[9] >> 4 ) & 0x04 )  \
  | ( ( (_p)->data_bytes[9] >> 6 ) & 0x02 )  \
  | ( ( (_p)->data_bytes[8] & 0x01 ) ) )



/**
 * @defgroup group_time_scale Time Scale Configuration
 *
 * Used to configure the GPS receiver's basic time scale.
 * By default this is %UTC which can optionally be converted
 * to some local time. However, some applications prefer
 * TAI or pure GPS time. This can be configured using the
 * structures below if the ::GPS_HAS_TIME_SCALE flag is set
 * in ::RECEIVER_INFO::features.
 *
 * @{ */

/**
 * @brief Known time scales
 *
 * @see ::MBG_TIME_SCALE_MASKS
 * @see ::TM_SCALE_GPS
 * @see ::TM_SCALE_TAI
 */
enum MBG_TIME_SCALES
{
  MBG_TIME_SCALE_DEFAULT,   ///< %UTC or local time according to ::UTC parameters and ::TZDL configuration
  MBG_TIME_SCALE_GPS,       ///< GPS time as sent by the satellites, monotonical
  MBG_TIME_SCALE_TAI,       ///< TAI, i.e. GPS time plus constant offset (see ::GPS_TAI_OFFSET)
  N_MBG_TIME_SCALE
};

/**
 * @brief Bit masks for known time scales
 *
 * @see ::MBG_TIME_SCALES
 */
enum MBG_TIME_SCALE_MASKS
{
  MBG_TIME_SCALE_MSK_DEFAULT = ( 1UL << MBG_TIME_SCALE_DEFAULT ),  ///< see ::MBG_TIME_SCALE_DEFAULT
  MBG_TIME_SCALE_MSK_GPS     = ( 1UL << MBG_TIME_SCALE_GPS ),      ///< see ::MBG_TIME_SCALE_GPS
  MBG_TIME_SCALE_MSK_TAI     = ( 1UL << MBG_TIME_SCALE_TAI )       ///< see ::MBG_TIME_SCALE_TAI
};

#define MBG_TIME_SCALE_STRS \
{                           \
  "UTC/local",              \
  "GPS",                    \
  "TAI"                     \
}



/**
 * @brief The constant time offset between the GPS and TAI time scales, in seconds
 */
#define GPS_TAI_OFFSET   19   ///< [s], TAI = GPS + GPS_TAI_OFFSET


/**
 * @brief Time scale configuration settings
 */
typedef struct
{
  uint8_t scale;  ///< current time scale code, see ::MBG_TIME_SCALES
  uint8_t flags;  ///< reserved, don't use, currently always 0

} MBG_TIME_SCALE_SETTINGS;

#define _mbg_swab_mbg_time_scale_settings( _p )  \
  _nop_macro_fnc()


/**
 * @brief Time scale configuration settings plus capabilities
 */
typedef struct
{
  MBG_TIME_SCALE_SETTINGS settings;      ///< current settings
  MBG_TIME_SCALE_SETTINGS max_settings;  ///< number of scales, all supported flags
  uint32_t supp_scales;                  ///< bit masks of supported scales, see ::MBG_TIME_SCALE_MASKS

} MBG_TIME_SCALE_INFO;

#define _mbg_swab_mbg_time_scale_info( _p )                 \
do                                                          \
{                                                           \
  _mbg_swab_mbg_time_scale_settings( &(_p)->settings );     \
  _mbg_swab_mbg_time_scale_settings( &(_p)->max_settings ); \
  _mbg_swab32( &(_p)->supp_scales );                        \
} while ( 0 )

/** @} defgroup group_time_scale */



/**
 * @defgroup group_pout_api Programmable Output API
 *
 * These structures below are used to configure the programmable
 * pulse outputs which are provided by some GPS receivers.
 * The number of programmable pulse outputs supported by a GPS
 * receiver is reported in the RECEIVER_INFO::n_prg_out field.
 *
 * @{ */


/**
 * @brief A calendar date including full year number
 */
typedef struct
{
  uint8_t mday;    ///< 1..28,29,30,31
  uint8_t month;   ///< 1..12
  uint16_t year;   ///< including century

} MBG_DATE;

#define _mbg_swab_mbg_date( _p ) \
do                               \
{                                \
  _mbg_swab16( &(_p)->year );    \
} while ( 0 )


/**
 * @brief The time of day including hundredths of seconds
 */
typedef struct
{
  uint8_t hour;    ///< 0..23
  uint8_t min;     ///< 0..59
  uint8_t sec;     ///< 0..59,60
  uint8_t sec100;  ///< 100ths of seconds

} MBG_TIME;

#define _mbg_swab_mbg_time( _p ) \
  _nop_macro_fnc()    // nothing to swap


/**
 * @brief Date and time specification for switching operations
 */
typedef struct
{
  MBG_DATE d;     ///< date to switch
  MBG_TIME t;     ///< time to switch
  uint8_t wday;   ///< reserved, currently always 0
  uint8_t flags;  ///< reserved, currently 0

} MBG_DATE_TIME;

#define _mbg_swab_mbg_date_time( _p ) \
do                                    \
{                                     \
  _mbg_swab_mbg_date( &(_p)->d );     \
  _mbg_swab_mbg_time( &(_p)->t );     \
} while ( 0 )


/**
 * @brief A structure to define on/off cycle times
 *
 * @note The ::MBG_TIME::sec100 field in ::POUT_TIME:on and
 * ::POUT_TIME:off is not evaluated by the firmware and thus
 * should always be set to 0.
 */
typedef struct
{
  MBG_DATE_TIME on;   ///< date and time to switch on
  MBG_DATE_TIME off;  ///< date and time to switch off

} POUT_TIME;

#define _mbg_swab_pout_time( _p )        \
do                                       \
{                                        \
  _mbg_swab_mbg_date_time( &(_p)->on );  \
  _mbg_swab_mbg_date_time( &(_p)->off ); \
} while ( 0 )



/**
 * @brief The number of ::POUT_TIME settings for each programmable pulse output
 *
 * @note This can't be changed without breaking compatibility of the API
 */
#define N_POUT_TIMES   3

/**
 * @brief A Generic data field for programmable output settings
 */
typedef union
{
  /// Switching times. See ::POUT_MODES_DATA_TM, ::POUT_MODES_DATA_TM_0
  POUT_TIME tm[N_POUT_TIMES];

  uint8_t b[N_POUT_TIMES * sizeof( POUT_TIME )];

  /// Only if ::POUT_SUPP_PULSE_SHIFT is set, this field can be used to
  /// configure the time interval in [ns] by which output pulse slopes are
  /// to be shifted. The configured pulse shift must be in the range
  /// ::DEFAULT_POUT_PULSE_SHIFT_MIN through ::DEFAULT_POUT_PULSE_SHIFT_MAX.
  /// The resolution / steps at which the pulse shift interval can be configured
  /// is returned in ::POUT_INFO::pulse_shift_res.
  /// @see ::POUT_MODES_DATA_PULSE_SHIFT
  int32_t pulse_shift;

} POUT_DATA;

#define DEFAULT_POUT_PULSE_SHIFT_MIN  -500000000L   ///< Default minimum value for ::POUT_DATA::pulse_shift, in [ns]
#define DEFAULT_POUT_PULSE_SHIFT_MAX   499000000L   ///< Default maximum value for ::POUT_DATA::pulse_shift, in [ns]


/**
 * @brief Convert ::POUT_DATA endianess depending on the mode
 *
 * Assuming the mode is passed to the macro with correct endianess.
 */
#define _mbg_swab_pout_data( _p, _mode )                         \
do                                                               \
{                                                                \
  uint32_t mode_mask = 1UL << _mode;                             \
                                                                 \
  if ( mode_mask & POUT_MODES_DATA_TM )                          \
  {                                                              \
    int i;                                                       \
                                                                 \
    for ( i = 0; i < N_POUT_TIMES; i++ )                         \
      _mbg_swab_pout_time( &(_p)->tm[i] );                       \
  }                                                              \
  else                                                           \
  {                                                              \
    if ( mode_mask & POUT_MODES_DATA_TM_0 )                      \
      _mbg_swab_pout_time( &(_p)->tm[0] );                       \
    else                                                         \
      if ( mode_mask & POUT_MODES_DATA_PULSE_SHIFT )             \
        _mbg_swab32( &(_p)->pulse_shift );                       \
  }                                                              \
                                                                 \
} while ( 0 )



/**
 * @brief Configuration settings for a single programmable pulse output
 */
typedef struct
{
  uint16_t mode;        ///< Mode of operation, see ::POUT_MODES
  uint16_t mode_param;  ///< Optional parameter depending on the mode, see @ref POUT_MODES_PARAM_MASKS

  /// Timeout [min] which can be specified for some modes, see ::POUT_MODES_TIMEOUT, ::MAX_POUT_DCF_TIMOUT.
  ///
  /// If the clock looses synchronization then the output
  ///  - is disabled **immediately** if ::POUT_IF_SYNC_ONLY is set in ::POUT_SETTINGS::flags
  ///  - is disabled after ::POUT_SETTINGS::timeout, if timeout is not 0 (see ::MAX_POUT_DCF_TIMOUT)
  ///  - stays enabled if timeout is 0 **and** ::POUT_IF_SYNC_ONLY is **not** set
  uint16_t timeout;

  uint16_t flags;       ///< @see ::POUT_SETTINGS_FLAGS
  POUT_DATA pout_data;  ///< Additional configuration data, see ::POUT_DATA

} POUT_SETTINGS;

/**
 * @brief Convert ::POUT_SETTINGS endianess after reading from a device
 */
#define _mbg_swab_pout_settings_on_get( _p )           \
do                                                     \
{                                                      \
  _mbg_swab16( &(_p)->mode );                          \
  _mbg_swab16( &(_p)->mode_param );                    \
  _mbg_swab16( &(_p)->timeout );                       \
  _mbg_swab16( &(_p)->flags );                         \
  _mbg_swab_pout_data( &(_p)->pout_data, (_p)->mode ); \
} while ( 0 )

/**
 * @brief Convert ::POUT_SETTINGS endianess before writing to a device
 */
#define _mbg_swab_pout_settings_on_set( _p )           \
do                                                     \
{                                                      \
  _mbg_swab_pout_data( &(_p)->pout_data, (_p)->mode ); \
  _mbg_swab16( &(_p)->mode );                          \
  _mbg_swab16( &(_p)->mode_param );                    \
  _mbg_swab16( &(_p)->timeout );                       \
  _mbg_swab16( &(_p)->flags );                         \
} while ( 0 )



/**
 * @brief Definitions used with ::POUT_TIME_SLOTS mode
 *
 * If ::POUT_SETTINGS::mode is set to ::POUT_TIME_SLOTS then the number
 * of time slots per minute is stored in ::POUT_SETTINGS::mode_param.
 * Valid numbers are all numbers n in the range ::MIN_TIME_SLOTS_PER_MINUTE
 * to ::MAX_TIME_SLOTS_PER_MINUTE for which the remainder of 60 / n is 0.
 * @see ::POUT_MODES_MODE_PARAM_AS_SLOTS_PER_MIN
 *
 * @anchor POUT_TIME_SLOTS_MODE_DEFS @{ */

#define MIN_TIME_SLOTS_PER_MINUTE  1
#define MAX_TIME_SLOTS_PER_MINUTE  60
#define TIME_SLOT_REGISTER_IN_SEC  60

#define TIMEOUT_DIVIDED_BY 10
#define TIME_SLOT_SWITCH_OFF_BUFFER_MIN 50 / TIMEOUT_DIVIDED_BY
#define TIME_SLOT_SWITCH_OFF_BUFFER_MAX 500 / TIMEOUT_DIVIDED_BY
#define TIME_SLOT_SWITCH_OFF_BUFFER_STD 500 / TIMEOUT_DIVIDED_BY
#define TIME_SLOT_SWITCH_OFF_BUFFER_STEP_SIZE 50 / TIMEOUT_DIVIDED_BY

#define _valid_time_slots_per_minute( _n )   \
  ( ( (_n) >= MIN_TIME_SLOTS_PER_MINUTE ) && \
    ( (_n) <= MAX_TIME_SLOTS_PER_MINUTE ) && \
    ( ( 60 % (_n) ) == 0 )                   \
  )

/** @} anchor POUT_TIME_SLOTS_MODE_DEFS */



#define MAX_POUT_PULSE_LEN    1000         ///< 10 secs, in 10 msec units
#define MAX_POUT_DCF_TIMOUT   ( 48 * 60 )  ///< 48 hours, in minutes



/**
 * @brief Enumeration of known operation modes for programmable pulse outputs
 *
 * These codes are used with ::POUT_SETTINGS::mode. One or more of
 * the remaining fields in ::POUT_SETTINGS are evaluated depending
 * on the selected mode. Unused fields should be set to 0.
 *
 * Unless ::POUT_NOT_INVERTIBLE is set in ::POUT_INFO::flags
 * the output signal level can be inverted if ::POUT_INVERTED
 * is set in ::POUT_SETTINGS::flags.
 *
 * @note Not every programmable pulse output supports all modes.
 *
 * @see @ref POUT_MODE_MASKS
 * @see @ref POUT_MODES_PARAM_MASKS
 * @see @ref ENG_POUT_NAMES
 * @see @ref ENG_POUT_HINTS
 */
enum POUT_MODES
{
  /// Output is normally always 'off', or always 'on', if flag ::POUT_INVERTED is set.
  POUT_IDLE,

  /// Switch 'on' or 'off' at the times specified in ::POUT_DATA::tm.
  POUT_TIMER,

  /// Generate a pulse at the time specified in ::POUT_SETTINGS::POUT_DATA::tm[0]::on.
  /// Pulse length according to ::POUT_SETTINGS::mode_param, in [10 ms] units.
  /// See ::MAX_POUT_PULSE_LEN.
  POUT_SINGLE_SHOT,

  /// Generate a cyclic pulse at the interval specified in ::POUT_SETTINGS::POUT_DATA::tm[0]:on::t.
  /// Pulse length according to ::POUT_SETTINGS::mode_param, in [10 ms] units.
  /// See ::MAX_POUT_PULSE_LEN.
  POUT_CYCLIC_PULSE,

  /// Generate a pulse whenever the second changes.
  /// Pulse length according to ::POUT_SETTINGS::mode_param, in [10 ms] units.
  /// See ::MAX_POUT_PULSE_LEN.
  POUT_PER_SEC,

  /// Generate a pulse whenever the minute changes.
  /// Pulse length according to ::POUT_SETTINGS::mode_param, in [10 ms] units.
  /// See ::MAX_POUT_PULSE_LEN.
  POUT_PER_MIN,

  /// Generate a pulse whenever the hour changes.
  /// Pulse length according to ::POUT_SETTINGS::mode_param, in [10 ms] units.
  /// See ::MAX_POUT_PULSE_LEN.
  POUT_PER_HOUR,

  /// Generate DCF77-compatible second marks.
  /// See ::POUT_DCF77_M59, ::POUT_SETTINGS::timeout and ::MAX_POUT_DCF_TIMOUT.
  POUT_DCF77,

  /// Output switched on if receiver position verified (condition nav_solved).
  POUT_POS_OK,

  /// Output switched on if time synchronized (condition time_syn).
  POUT_TIME_SYNC,

  /// Output switched on if both position verified and time synchronized.
  POUT_ALL_SYNC,

  /// IRIG/AFNOR DCLS time code signal mapped to this output.
  POUT_TIMECODE,

  /// Serial time string of one one of the serial ports mapped to this output.
  /// ::POUT_SETTINGS::mode_param contains the number of the COM port.
  /// See ::MAX_POUT_TIMESTR_PORTS.
  POUT_TIMESTR,

  /// 10 MHz fixed frequency output.
  POUT_10MHZ,

  /// DCF77-like signal with extra 500 ms pulse in the 59th second
  /// (the original DCF77 signal has no such pulse). See ::POUT_DCF77,
  /// ::POUT_SETTINGS::timeout and ::MAX_POUT_DCF_TIMOUT.
  POUT_DCF77_M59,

  /// Output signal generated by the programmable frequency synthesizer.
  POUT_SYNTH,

  /// Programmable time slots during each minute.
  /// ::POUT_SETTINGS::mode_param specifies the time slots per minute.
  /// Uses ::POUT_DATA. ::TODO
  POUT_TIME_SLOTS,

  /// A GPIO input or output signal is reflected at this pulse output.
  /// ::POUT_SETTINGS::mode_param specifies the GPIO number which must
  /// be in the range 0..::MBG_GPIO_CFG_LIMITS::num_io.
  POUT_GPIO,

  /// A 1PPS signal with a fixed 20us pulse length
  POUT_PTTI_PPS,

  /// A HaveQuick signal as configured in ::HAVEQUICK_SETTINGS::format
  POUT_HAVEQUICK,

  // New modes have to be added here at the end of the enumeration, and the
  // POUT_MODE_MASKS, the POUT_MODES_PARAM_MASKS as well as string initializers
  // (also in pcpslstr.h) have to be updated accordingly.
  N_POUT_MODES        ///< the number of known modes
};


/**
 * @brief Bit masks associated with ::POUT_MODES
 *
 * Used with ::POUT_INFO::supp_modes to specify which ::POUT_MODES
 * are supported for a particular programmable output.
 *
 * @see ::POUT_MODES
 *
 * @anchor POUT_MODE_MASKS @{ */

#define MSK_POUT_IDLE          ( 1UL << POUT_IDLE )          ///< see ::POUT_IDLE
#define MSK_POUT_TIMER         ( 1UL << POUT_TIMER )         ///< see ::POUT_TIMER
#define MSK_POUT_SINGLE_SHOT   ( 1UL << POUT_SINGLE_SHOT )   ///< see ::POUT_SINGLE_SHOT
#define MSK_POUT_CYCLIC_PULSE  ( 1UL << POUT_CYCLIC_PULSE )  ///< see ::POUT_CYCLIC_PULSE
#define MSK_POUT_PER_SEC       ( 1UL << POUT_PER_SEC )       ///< see ::POUT_PER_SEC
#define MSK_POUT_PER_MIN       ( 1UL << POUT_PER_MIN )       ///< see ::POUT_PER_MIN
#define MSK_POUT_PER_HOUR      ( 1UL << POUT_PER_HOUR )      ///< see ::POUT_PER_HOUR
#define MSK_POUT_DCF77         ( 1UL << POUT_DCF77 )         ///< see ::POUT_DCF77
#define MSK_POUT_POS_OK        ( 1UL << POUT_POS_OK )        ///< see ::POUT_POS_OK
#define MSK_POUT_TIME_SYNC     ( 1UL << POUT_TIME_SYNC )     ///< see ::POUT_TIME_SYNC
#define MSK_POUT_ALL_SYNC      ( 1UL << POUT_ALL_SYNC )      ///< see ::POUT_ALL_SYNC
#define MSK_POUT_TIMECODE      ( 1UL << POUT_TIMECODE )      ///< see ::POUT_TIMECODE
#define MSK_POUT_TIMESTR       ( 1UL << POUT_TIMESTR )       ///< see ::POUT_TIMESTR
#define MSK_POUT_10MHZ         ( 1UL << POUT_10MHZ )         ///< see ::POUT_10MHZ
#define MSK_POUT_DCF77_M59     ( 1UL << POUT_DCF77_M59 )     ///< see ::POUT_DCF77_M59
#define MSK_POUT_SYNTH         ( 1UL << POUT_SYNTH )         ///< see ::POUT_SYNTH
#define MSK_POUT_TIME_SLOTS    ( 1UL << POUT_TIME_SLOTS )    ///< see ::POUT_TIME_SLOTS
#define MSK_POUT_GPIO          ( 1UL << POUT_GPIO )          ///< see ::POUT_GPIO
#define MSK_POUT_PTTI_PPS      ( 1UL << POUT_PTTI_PPS )      ///< see ::POUT_PTTI_PPS
#define MSK_POUT_HAVEQUICK     ( 1UL << POUT_HAVEQUICK )     ///< see ::POUT_HAVEQUICK

/** @} anchor POUT_MODE_MASKS */



/**
 * @brief Bit masks indicating which parameters relevant for which ::POUT_MODES
 *
 * @see ::POUT_MODES
 * @see @ref POUT_MODE_MASKS
 *
 * @anchor POUT_MODES_PARAM_MASKS @{ */


/**
 * @brief POUT modes which use the full ::POUT_DATA::tm array as parameter
 */
#define POUT_MODES_DATA_TM  \
(                           \
  MSK_POUT_TIMER            \
)


/**
 * @brief POUT modes which use only ::POUT_DATA::tm[0] as parameter
 */
#define POUT_MODES_DATA_TM_0  \
(                             \
  MSK_POUT_SINGLE_SHOT      | \
  MSK_POUT_CYCLIC_PULSE       \
)


/**
 * @brief POUT modes which use ::POUT_SETTINGS::mode_param as pulse length
 *
 * @see ::MAX_POUT_PULSE_LEN
 */
#define POUT_MODES_MODE_PARAM_AS_PULSE_LEN  \
(                                           \
  MSK_POUT_SINGLE_SHOT                    | \
  MSK_POUT_CYCLIC_PULSE                   | \
  MSK_POUT_PER_SEC                        | \
  MSK_POUT_PER_MIN                        | \
  MSK_POUT_PER_HOUR                         \
)


/**
 * @brief POUT modes which use ::POUT_SETTINGS::mode_param as COM port index number
 */
#define POUT_MODES_MODE_PARAM_AS_COM_IDX  \
(                                         \
  MSK_POUT_TIMESTR                        \
)


/**
 * @brief POUT modes which use ::POUT_SETTINGS::mode_param as time slots per minute
 *
 * @see @ref POUT_TIME_SLOTS_MODE_DEFS
 */
#define POUT_MODES_MODE_PARAM_AS_SLOTS_PER_MIN  \
(                                               \
  MSK_POUT_TIME_SLOTS                           \
)


/**
 * @brief POUT modes which use ::POUT_SETTINGS::mode_param as GPIO index number
 */
#define POUT_MODES_MODE_PARAM_AS_GPIO_IDX   \
(                                           \
  MSK_POUT_GPIO                             \
)


/**
 * @brief POUT modes which use ::POUT_SETTINGS::timeout
 */
#define POUT_MODES_TIMEOUT  \
(                           \
  MSK_POUT_DCF77          | \
  MSK_POUT_DCF77_M59        \
)


/**
 * @brief POUT modes which which support ::POUT_TIMEBASE_UTC
 */
#define POUT_MODES_SUPP_TIMEBASE_UTC  \
(                                     \
  MSK_POUT_DCF77                    | \
  MSK_POUT_DCF77_M59                  \
)


/**
 * @brief POUT modes which use ::POUT_DATA::pulse_shift
 *
 * @note: Supported only if ::POUT_SUPP_PULSE_SHIFT is set
 */
#define POUT_MODES_DATA_PULSE_SHIFT  \
(                                    \
  MSK_POUT_PER_SEC                 | \
  MSK_POUT_PER_MIN                 | \
  MSK_POUT_PER_HOUR                  \
)


/**
 * @brief POUT modes which support ::POUT_SUPP_IF_SYNC_ONLY
 *
 * Even if ::POUT_SUPP_IF_SYNC_ONLY is set in ::POUT_INFO::flags
 * the associated flag ::POUT_IF_SYNC_ONLY in ::POUT_SETTINGS::flags
 * may be evaluated depending on the mode.
 *
 * Modes ::POUT_POS_OK, ::POUT_TIME_SYNC, and ::MSK_POUT_ALL_SYNC
 * are explicitly excluded.
 *
 * For modes ::MSK_POUT_DCF77 and ::MSK_POUT_DCF77_M59 see also
 * ::POUT_SETTINGS::timeout.
 */
#define POUT_MODES_SUPP_IF_SYNC_ONLY  \
(                                     \
  MSK_POUT_IDLE                     | \
  MSK_POUT_TIMER                    | \
  MSK_POUT_SINGLE_SHOT              | \
  MSK_POUT_CYCLIC_PULSE             | \
  MSK_POUT_PER_SEC                  | \
  MSK_POUT_PER_MIN                  | \
  MSK_POUT_PER_HOUR                 | \
  MSK_POUT_DCF77                    | \
  MSK_POUT_TIMECODE                 | \
  MSK_POUT_TIMESTR                  | \
  MSK_POUT_10MHZ                    | \
  MSK_POUT_DCF77_M59                | \
  MSK_POUT_SYNTH                    | \
  MSK_POUT_TIME_SLOTS               | \
  MSK_POUT_GPIO                     | \
  MSK_POUT_PTTI_PPS                 | \
  MSK_POUT_HAVEQUICK                  \
)


/** @} anchor POUT_MODES_PARAM_MASKS */



/**
 * @brief Name strings associated with ::POUT_MODES
 *
 * Default initializers for English programmable output mode names.
 * Initializers for multi-language strings can be found in pcpslstr.h.
 *
 * @see ::POUT_MODES
 * @see ::DEFAULT_ENG_POUT_NAMES
 *
 * @anchor ENG_POUT_NAMES @{ */

#define ENG_POUT_NAME_IDLE            "Idle"
#define ENG_POUT_NAME_TIMER           "Timer"
#define ENG_POUT_NAME_SINGLE_SHOT     "Single Shot"
#define ENG_POUT_NAME_CYCLIC_PULSE    "Cyclic Pulse"
#define ENG_POUT_NAME_PER_SEC         "Pulse Per Second"
#define ENG_POUT_NAME_PER_MIN         "Pulse Per Min"
#define ENG_POUT_NAME_PER_HOUR        "Pulse Per Hour"
#define ENG_POUT_NAME_DCF77           "DCF77 Marks"
#define ENG_POUT_NAME_POS_OK          "Position OK"
#define ENG_POUT_NAME_TIME_SYNC       "Time Sync"
#define ENG_POUT_NAME_ALL_SYNC        "All Sync"
#define ENG_POUT_NAME_TIMECODE        "DCLS Time Code"
#define ENG_POUT_NAME_TIMESTR         "Serial Time String"
#define ENG_POUT_NAME_10MHZ           "10 MHz Frequency"
#define ENG_POUT_NAME_DCF77_M59       "DCF77-like M59"
#define ENG_POUT_NAME_SYNTH           "Synthesizer Frequency"
#define ENG_POUT_NAME_TIME_SLOTS      "Time Slots per Minute"
#define ENG_POUT_NAME_GPIO            "GPIO Signal"
#define ENG_POUT_PTTI_PPS             "PTTI 1PPS"
#define ENG_POUT_HAVEQUICK            "HaveQuick"

/** @} anchor ENG_POUT_NAMES */



/**
 * @brief An initializer for a table of English POUT name strings
 *
 * @see @ref ENG_POUT_NAMES
 */
#define DEFAULT_ENG_POUT_NAMES \
{                              \
  ENG_POUT_NAME_IDLE,          \
  ENG_POUT_NAME_TIMER,         \
  ENG_POUT_NAME_SINGLE_SHOT,   \
  ENG_POUT_NAME_CYCLIC_PULSE,  \
  ENG_POUT_NAME_PER_SEC,       \
  ENG_POUT_NAME_PER_MIN,       \
  ENG_POUT_NAME_PER_HOUR,      \
  ENG_POUT_NAME_DCF77,         \
  ENG_POUT_NAME_POS_OK,        \
  ENG_POUT_NAME_TIME_SYNC,     \
  ENG_POUT_NAME_ALL_SYNC,      \
  ENG_POUT_NAME_TIMECODE,      \
  ENG_POUT_NAME_TIMESTR,       \
  ENG_POUT_NAME_10MHZ,         \
  ENG_POUT_NAME_DCF77_M59,     \
  ENG_POUT_NAME_SYNTH,         \
  ENG_POUT_NAME_TIME_SLOTS,    \
  ENG_POUT_NAME_GPIO,          \
  ENG_POUT_PTTI_PPS,           \
  ENG_POUT_HAVEQUICK           \
}


/**
 * @brief Hint strings associated with ::POUT_MODES
 *
 * Default initializers for English programmable output mode hints.
 * Initializers for multi-language strings can be found in pcpslstr.h.
 *
 * @see ::POUT_MODES
 * @see ::DEFAULT_ENG_POUT_HINTS
 *
 * @anchor ENG_POUT_HINTS @{ */

#define ENG_POUT_HINT_IDLE            "Constant output level"
#define ENG_POUT_HINT_TIMER           "Switch based on configured on/off times"
#define ENG_POUT_HINT_SINGLE_SHOT     "Generate a single pulse of determined length"
#define ENG_POUT_HINT_CYCLIC_PULSE    "Generate cyclic pulses of determined length"
#define ENG_POUT_HINT_PER_SEC         "Generate pulse at beginning of new second"
#define ENG_POUT_HINT_PER_MIN         "Generate pulse at beginning of new minute"
#define ENG_POUT_HINT_PER_HOUR        "Generate pulse at beginning of new hour"
#define ENG_POUT_HINT_DCF77           "DCF77 compatible time marks"
#define ENG_POUT_HINT_POS_OK          "Switch if receiver position has been verified"
#define ENG_POUT_HINT_TIME_SYNC       "Switch if time is synchronized"
#define ENG_POUT_HINT_ALL_SYNC        "Switch if full sync"
#define ENG_POUT_HINT_TIMECODE        "Duplicate IRIG time code signal"
#define ENG_POUT_HINT_TIMESTR         "Duplicate serial time string of specified port"
#define ENG_POUT_HINT_10MHZ           "10 MHz fixed output frequency"
#define ENG_POUT_HINT_DCF77_M59       "DCF77 time marks with 500 ms pulse in 59th second"
#define ENG_POUT_HINT_SYNTH           "Frequency generated by programmable synthesizer"
#define ENG_POUT_HINT_TIME_SLOTS      "Output enabled during specified time slots per minute"
#define ENG_POUT_HINT_GPIO            "Duplicated signal of the specified GPIO input or output"
#define ENG_POUT_HINT_PTTI_PPS        "Generate 20us Pulse at beginning of the second"
#define ENG_POUT_HINT_HAVEQUICK       "Duplicated HaveQuick Signal"

/** @} anchor ENG_POUT_HINTS */


/**
 * @brief An initializer for a table of English POUT hint strings
 *
 * @see @ref ENG_POUT_HINTS
 */
#define DEFAULT_ENG_POUT_HINTS \
{                              \
  ENG_POUT_HINT_IDLE,          \
  ENG_POUT_HINT_TIMER,         \
  ENG_POUT_HINT_SINGLE_SHOT,   \
  ENG_POUT_HINT_CYCLIC_PULSE,  \
  ENG_POUT_HINT_PER_SEC,       \
  ENG_POUT_HINT_PER_MIN,       \
  ENG_POUT_HINT_PER_HOUR,      \
  ENG_POUT_HINT_DCF77,         \
  ENG_POUT_HINT_POS_OK,        \
  ENG_POUT_HINT_TIME_SYNC,     \
  ENG_POUT_HINT_ALL_SYNC,      \
  ENG_POUT_HINT_TIMECODE,      \
  ENG_POUT_HINT_TIMESTR,       \
  ENG_POUT_HINT_10MHZ,         \
  ENG_POUT_HINT_DCF77_M59,     \
  ENG_POUT_HINT_SYNTH,         \
  ENG_POUT_HINT_TIME_SLOTS,    \
  ENG_POUT_HINT_GPIO,          \
  ENG_POUT_HINT_PTTI_PPS,      \
  ENG_POUT_HINT_HAVEQUICK      \
}



/**
 * @brief Flag bits used to define ::POUT_SETTINGS_FLAGS
 *
 * @see ::POUT_SETTINGS_FLAGS
 */
enum POUT_SETTINGS_FLAG_BITS
{
  /// Output level is to be inverted. Can only be used
  /// if ::POUT_NOT_INVERTIBLE is **not** set, but is
  /// supported by all ::POUT_MODES.
  POUT_BIT_INVERTED,

  /// Enable output **only** while synchronized. This even overrides
  /// the settings in ::ENABLE_FLAGS::pulses, so if this flag is set
  /// the output is only enabled if the clock is synchronized, and is
  /// disabled when synchronization is lost, i.e. the device enters
  /// holdover mode.
  /// This flag can only be used with outputs that have ::POUT_SUPP_IF_SYNC_ONLY
  /// set, and is only supported for the ::POUT_MODES specified in
  /// ::POUT_MODES_SUPP_IF_SYNC_ONLY.
  POUT_BIT_IF_SYNC_ONLY,

  /// Output %UTC time instead of local time for DCF77 emulation.
  /// This flag can only be used with outputs that have ::POUT_SUPP_DCF77_UTC
  /// set, and is only supported for the ::POUT_MODES specified in
  /// ::POUT_MODES_SUPP_TIMEBASE_UTC (e.g. ::POUT_DCF77 or ::POUT_DCF77_M59).
  POUT_BIT_TIMEBASE_UTC,

  N_POUT_SETTINGS_FLAG_BITS  ///< Number of known flag bits
};


/**
 * @brief Flag bit masks used with ::POUT_SETTINGS::flags
 *
 * @see ::POUT_SETTINGS_FLAG_BITS
 */
enum POUT_SETTINGS_FLAGS
{
  POUT_INVERTED     = ( 1UL << POUT_BIT_INVERTED ),      ///< see ::POUT_BIT_INVERTED, ::POUT_NOT_INVERTIBLE
  POUT_IF_SYNC_ONLY = ( 1UL << POUT_BIT_IF_SYNC_ONLY ),  ///< see ::POUT_BIT_IF_SYNC_ONLY, ::POUT_SUPP_IF_SYNC_ONLY
  POUT_TIMEBASE_UTC = ( 1UL << POUT_BIT_TIMEBASE_UTC )   ///< see ::POUT_BIT_TIMEBASE_UTC, ::POUT_SUPP_DCF77_UTC
};



/**
 * @brief Configuration settings for a specific programmable pulse output
 *
 * This structure can be used to send configuration settings for a specific
 * programmable output to a device.
 * The number of supported outputs is RECEIVER_INFO::n_prg_out.
 *
 * @note The ::POUT_INFO_IDX structure should be read from
 * a device to retrieve the current settings and capabilities.
 */
typedef struct
{
  uint16_t idx;                 ///< 0..::RECEIVER_INFO::n_prg_out-1
  POUT_SETTINGS pout_settings;

} POUT_SETTINGS_IDX;

#define _mbg_swab_pout_settings_idx_on_set( _p )          \
do                                                        \
{                                                         \
  _mbg_swab16( &(_p)->idx );                              \
  _mbg_swab_pout_settings_on_set( &(_p)->pout_settings ); \
} while ( 0 )

#define _mbg_swab_pout_settings_idx_on_get( _p )          \
do                                                        \
{                                                         \
  _mbg_swab16( &(_p)->idx );                              \
  _mbg_swab_pout_settings_on_get( &(_p)->pout_settings ); \
} while ( 0 )


/**
 * @brief Current settings and general capabilities of a programmable pulse output
 *
 * This structure should be read from the device to retrieve the
 * current settings of a programmable pulse output plus its capabilities,
 * e.g. the supported output modes, etc.
 *
 * @note The ::POUT_INFO_IDX structure should be used to read
 * current settings and capabilities of a specific output.
 */
typedef struct
{
  POUT_SETTINGS pout_settings;
  uint32_t supp_modes;      ///< bit mask of modes supp. by this output, see @ref POUT_MODE_MASKS
  uint8_t timestr_ports;    ///< bit mask of COM ports supported for mode ::POUT_TIMESTR, see ::MAX_POUT_TIMESTR_PORTS
  uint8_t pulse_shift_res;  ///< pulse shift resolution, in [ns], only if ::POUT_SUPP_PULSE_SHIFT, see ::POUT_DATA::pulse_shift
  uint16_t reserved_1;      ///< reserved for future use, currently unused and always 0
  uint32_t flags;           ///< @see ::POUT_INFO_FLAG_MASKS

} POUT_INFO;

#define _mbg_swab_pout_info_on_get( _p )                   \
do                                                         \
{                                                          \
  _mbg_swab_pout_settings_on_get( &(_p)->pout_settings );  \
  _mbg_swab32( &(_p)->supp_modes );                        \
  _mbg_swab8( &(_p)->timestr_ports );                      \
  _mbg_swab8( &(_p)->pulse_shift_res );                    \
  _mbg_swab16( &(_p)->reserved_1 );                        \
  _mbg_swab32( &(_p)->flags );                             \
} while ( 0 )


#define MAX_POUT_TIMESTR_PORTS  8   ///< The max number of COM ports that can be handled by ::POUT_INFO::timestr_ports



/**
 * @brief Flag bits used to define ::POUT_INFO_FLAG_MASKS
 *
 * @see ::POUT_INFO_FLAG_MASKS
 */
enum POUT_INFO_FLAG_BITS
{
  POUT_BIT_SUPP_IF_SYNC_ONLY,  ///< ::POUT_IF_SYNC_ONLY is supported for this output
  POUT_BIT_SUPP_DCF77_UTC,     ///< ::POUT_SUPP_DCF77_UTC is supported for this output
  POUT_BIT_FIXED_PULSE_LEN,    ///< pulse length is limited to the value ::POUT_SETTINGS::mode_param
  POUT_BIT_NOT_INVERTIBLE,     ///< output level can't be inverted, thus ::POUT_INVERTED is not supported for this output
  POUT_BIT_SUPP_PULSE_SHIFT,   ///< output slopes can be shifted, see ::POUT_DATA::pulse_shift
  N_POUT_INFO_FLAG_BITS        ///< number of known flag bits
};


/**
 * @brief Flag bit masks used with ::POUT_INFO::flags
 *
 * @see ::POUT_INFO_FLAG_BITS
 */
enum POUT_INFO_FLAG_MASKS
{
  POUT_SUPP_IF_SYNC_ONLY = ( 1UL << POUT_BIT_SUPP_IF_SYNC_ONLY ),  ///< see ::POUT_BIT_SUPP_IF_SYNC_ONLY, ::POUT_IF_SYNC_ONLY
  POUT_SUPP_DCF77_UTC    = ( 1UL << POUT_BIT_SUPP_DCF77_UTC ),     ///< see ::POUT_BIT_SUPP_DCF77_UTC, ::POUT_SUPP_DCF77_UTC
  POUT_FIXED_PULSE_LEN   = ( 1UL << POUT_BIT_FIXED_PULSE_LEN ),    ///< see ::POUT_BIT_FIXED_PULSE_LEN
  POUT_NOT_INVERTIBLE    = ( 1UL << POUT_BIT_NOT_INVERTIBLE ),     ///< see ::POUT_BIT_NOT_INVERTIBLE, ::POUT_INVERTED
  POUT_SUPP_PULSE_SHIFT  = ( 1UL << POUT_BIT_SUPP_PULSE_SHIFT )    ///< see ::POUT_BIT_SUPP_PULSE_SHIFT, ::POUT_DATA::pulse_shift
};



/**
 * @brief Current settings and general capabilities of a specific programmable pulse output
 *
 * This structure should be read from the device to retrieve the
 * current settings of a specific programmable output plus its capabilities,
 * e.g. supported modes of operation, etc.
 * The number of supported ports is RECEIVER_INFO::n_prg_out.
 *
 * @note The ::POUT_SETTINGS_IDX structure should be send back to
 * the device to configure the specified programmable pulse output.
 */
typedef struct
{
  uint16_t idx;          ///< 0..::RECEIVER_INFO::n_prg_out-1
  POUT_INFO pout_info;

} POUT_INFO_IDX;

#define _mbg_swab_pout_info_idx_on_get( _p )      \
do                                                \
{                                                 \
  _mbg_swab16( &(_p)->idx );                      \
  _mbg_swab_pout_info_on_get( &(_p)->pout_info ); \
} while ( 0 )

/** @} defgroup group_pout_api */



/**
 * @defgroup group_multi_ref_all Support for multiple reference time sources
 *
 * Some devices can evaluate and synchronize to several different types
 * of input signal, and eventually even several signals of the same type,
 * e.g. several 1 PPS input signals.
 *
 * There are two different ways to configure multi ref devices.
 *
 * Newer devices which have the ::GPS_HAS_XMULTI_REF flag set in
 * ::RECEIVER_INFO::features support the newer XMULTI_REF_... structures
 * which provide a more flexible API, see @ref group_multi_ref_ext
 *
 * Older devices may have the ::GPS_FEAT_MULTI_REF flag set in which
 * case an older API is supported, see @ref group_multi_ref_old
 *
 * Symbols defined in @ref group_multi_ref_common can be used
 * with both APIs.
 *
 * @see @ref group_multi_ref_common
 * @see @ref group_multi_ref_old
 * @see @ref group_multi_ref_ext
 * @{ */

/**
 * @defgroup group_multi_ref_common Common multi ref definitions
 *
 * Common definitions used with both the old and the extended
 * multi ref API.
 *
 * @{ */

/**
 * @brief Enumeration of all known types of reference time source
 *
 * All known types of input signal which may possibly be supported
 * by devices which support several different input signals, i.e.
 * have the ::GPS_HAS_MULTI_REF or ::GPS_HAS_XMULTI_REF bit set
 * in ::RECEIVER_INFO::features. Not all devices support each known
 * type of input signal.
 *
 * @see @ref group_multi_ref_all
 * @see ::DEFAULT_MULTI_REF_NAMES
 * @see ::DEFAULT_MULTI_REF_NAMES_SHORT
 * @see @ref MULTI_REF_TYPE_MASKS
 */
enum MULTI_REF_TYPES
{
  /// This ref type must not be used as index, but marks particular
  /// ::XMULTI_REF_SETTINGS structures as "unused". It is only
  /// supported if bit ::XMRIF_BIT_MRF_NONE_SUPP is set.
  MULTI_REF_NONE = -1,

  MULTI_REF_GPS = 0,     ///< standard GPS
  MULTI_REF_10MHZ,       ///< 10 MHz input frequency
  MULTI_REF_PPS,         ///< 1 PPS input signal
  MULTI_REF_10MHZ_PPS,   ///< combined 10 MHz plus PPS
  MULTI_REF_IRIG,        ///< IRIG input
  MULTI_REF_NTP,         ///< Network Time Protocol (NTP)
  MULTI_REF_PTP,         ///< Precision Time Protocol (PTP/IEEE1588)
  MULTI_REF_PTP_E1,      ///< PTP over E1
  MULTI_REF_FREQ,        ///< fixed frequency
  MULTI_REF_PPS_STRING,  ///< 1 PPS in addition to time string
  MULTI_REF_GPIO,        ///< variable input signal via GPIO
  MULTI_REF_INTERNAL,    ///< reserved, used internally by firmware only
  MULTI_REF_PZF,         ///< DCF77 PZF providing much more accuracy than a standard LWR
  MULTI_REF_LWR,         ///< long wave receiver. e.g. DCF77 AM, WWVB, MSF, JJY
  MULTI_REF_GRC,         ///< Glonass / GPS receiver
  MULTI_REF_HAVEQUICK,   ///< HaveQuick input
  MULTI_REF_EXT_OSC,     ///< external oscillator disciplined and looped back via 1 PPS I/O
  MULTI_REF_SYNCE,       ///< Synchronous Ethernet, needs (external) ethernet interface
  N_MULTI_REF            ///< the number of defined sources, must not exceed ::MAX_N_MULTI_REF_TYPES
};

/**
 * @brief Theoretical maximum number of multi ref input signal types
 *
 * Actually only ::N_MULTI_REF types have been defined, but ::N_MULTI_REF
 * must not exceed the number of bits which can be hold by a uint32_t type.
 */
#define MAX_N_MULTI_REF_TYPES    32


/**
 * @brief Names of known ref time sources
 *
 * @see ::MULTI_REF_TYPES
 */
#define DEFAULT_MULTI_REF_NAMES \
{                               \
  "GPS",                        \
  "10 MHz freq in",             \
  "PPS in",                     \
  "10 MHz + PPS in",            \
  "IRIG",                       \
  "NTP",                        \
  "PTP (IEEE1588)",             \
  "PTP over E1",                \
  "Fixed Freq. in",             \
  "PPS plus string",            \
  "Var. freq. via GPIO",        \
  "(reserved)",                 \
  "DCF77 PZF Receiver",         \
  "Long Wave Receiver",         \
  "GLONASS/GPS Receiver",       \
  "HaveQuick Input",            \
  "ext. Osc.",                  \
  "Synchronous Ethernet"        \
}

/**
 * @brief Short names of supported ref time sources
 *
 * Used e.g. to configure a particular input signal type
 *
 * @see ::MULTI_REF_TYPES
 */
#define DEFAULT_MULTI_REF_NAMES_SHORT \
{                \
  "GPS",         \
  "FRQ",         \
  "PPS",         \
  "10MHZ+PPS",   \
  "TCR",         \
  "NTP",         \
  "PTP",         \
  "PTP_E1",      \
  "FIXED_FREQ",  \
  "STRING+PPS",  \
  "GPIO",        \
  "(reserved)",  \
  "PZF",         \
  "LWR",         \
  "GGR",         \
  "HQI",         \
  "EXT",         \
  "SYNCE"        \
}


/**
 * @brief Bit masks associated with multi ref types
 *
 * Used to indicate which multi ref types are supported, e.g.
 * in ::XMULTI_REF_INFO::supp_ref or ::MULTI_REF_INFO::supp_ref.
 *
 * @see ::MULTI_REF_TYPES
 *
 * @anchor MULTI_REF_TYPE_MASKS @{ */

#define HAS_MULTI_REF_GPS        ( 1UL << MULTI_REF_GPS )         ///< see ::MULTI_REF_GPS
#define HAS_MULTI_REF_10MHZ      ( 1UL << MULTI_REF_10MHZ )       ///< see ::MULTI_REF_10MHZ
#define HAS_MULTI_REF_PPS        ( 1UL << MULTI_REF_PPS )         ///< see ::MULTI_REF_PPS
#define HAS_MULTI_REF_10MHZ_PPS  ( 1UL << MULTI_REF_10MHZ_PPS )   ///< see ::MULTI_REF_10MHZ_PPS
#define HAS_MULTI_REF_IRIG       ( 1UL << MULTI_REF_IRIG )        ///< see ::MULTI_REF_IRIG
#define HAS_MULTI_REF_NTP        ( 1UL << MULTI_REF_NTP )         ///< see ::MULTI_REF_NTP
#define HAS_MULTI_REF_PTP        ( 1UL << MULTI_REF_PTP )         ///< see ::MULTI_REF_PTP
#define HAS_MULTI_REF_PTP_E1     ( 1UL << MULTI_REF_PTP_E1 )      ///< see ::MULTI_REF_PTP_E1

#define HAS_MULTI_REF_FREQ       ( 1UL << MULTI_REF_FREQ )        ///< see ::MULTI_REF_FREQ
#define HAS_MULTI_REF_PPS_STRING ( 1UL << MULTI_REF_PPS_STRING )  ///< see ::MULTI_REF_PPS_STRING
#define HAS_MULTI_REF_GPIO       ( 1UL << MULTI_REF_GPIO )        ///< see ::MULTI_REF_GPIO
#define HAS_MULTI_REF_INTERNAL   ( 1UL << MULTI_REF_INTERNAL )    ///< see ::MULTI_REF_INTERNAL
#define HAS_MULTI_REF_PZF        ( 1UL << MULTI_REF_PZF )         ///< see ::MULTI_REF_PZF
#define HAS_MULTI_REF_LWR        ( 1UL << MULTI_REF_LWR )         ///< see ::MULTI_REF_LWR
#define HAS_MULTI_REF_GRC        ( 1UL << MULTI_REF_GRC )         ///< see ::MULTI_REF_GRC
#define HAS_MULTI_REF_HAVEQUICK  ( 1UL << MULTI_REF_HAVEQUICK )   ///< see ::MULTI_REF_HAVEQUICK

#define HAS_MULTI_REF_EXT_OSC    ( 1UL << MULTI_REF_EXT_OSC )     ///< see ::MULTI_REF_EXT_OSC
#define HAS_MULTI_REF_SYNCE      ( 1UL << MULTI_REF_SYNCE )       ///< see ::MULTI_REF_SYNCE

/** @} anchor MULTI_REF_TYPE_MASKS */

/** @} defgroup group_multi_ref_common */



/**
 * @defgroup group_multi_ref_old Definitions used with the old multi ref API
 *
 * This API has been deprecated by a newer one which should be used preferably.
 *
 * @see @ref group_multi_ref_ext
 *
 * @{ */

/**
 * @brief Maximum number of input sources
 *
 * The number of supported input sources and priorities is
 * limited to this value if the old API is used, i.e. if only
 * the ::GPS_FEAT_MULTI_REF flag is set.
 */
#define N_MULTI_REF_PRIO   4


/**
 * @brief A structure used to configure the priority of the supported ref sources
 *
 * The number stored in prio[0] of the array indicates the ref time
 * source with highest priority. If that source fails, the device
 * falls back to the source indicated by prio[1]. Each field of
 * the prio[] array has to be set to one of the values 0..::N_MULTI_REF-1,
 * or to ::MULTI_REF_NONE if no time source is specified.
 */
typedef struct
{
  uint8_t prio[N_MULTI_REF_PRIO];

} MULTI_REF_SETTINGS;


/**
 * @brief A structure used to query MULTI_REF configuration parameters
 *
 * This also includes a bit mask of supported ref sources.
 */
typedef struct
{
  MULTI_REF_SETTINGS settings;    ///< current settings
  uint32_t supp_ref;              ///< bit mask of supported sources, see @ref MULTI_REF_TYPE_MASKS
  uint16_t n_levels;              ///< supported priority levels, 0..::N_MULTI_REF_PRIO-1
  uint16_t flags;                 ///< reserved, currently always 0

} MULTI_REF_INFO;


/**
 * @brief A data type used to query MULTI_REF status information
 *
 * @see ::MULTI_REF_STATUS_BIT_MASKS
 */
typedef uint16_t MULTI_REF_STATUS;


/**
 * @brief Enumeration of multi ref status bits
 *
 * @see ::MULTI_REF_STATUS_BIT_MASKS
 */
enum MULTI_REF_STATUS_BITS
{
  WRN_MODULE_MODE,         ///< selected input mode was invalid, set to default
  WRN_COLD_BOOT,           ///< GPS is in cold boot mode
  WRN_WARM_BOOT,           ///< GPS is in warm boot mode
  WRN_ANT_DISCONN,         ///< antenna is disconnected
  WRN_10MHZ_UNLOCK,        ///< impossible to lock to external 10 MHz reference
  WRN_1PPS_UNLOCK,         ///< impossible to lock to external 1 PPS reference
  WRN_GPS_UNLOCK,          ///< impossible to lock to GPS
  WRN_10MHZ_MISSING,       ///< external 10 MHz signal not available
  WRN_1PPS_MISSING,        ///< external 1 PPS signal not available
  N_MULTI_REF_STATUS_BITS  ///< the number of known bits
};


/**
 * @brief Bit masks associated with ::MULTI_REF_STATUS_BITS
 *
 * Used with ::MULTI_REF_STATUS.
 *
 * @see ::MULTI_REF_STATUS_BITS
 */
enum MULTI_REF_STATUS_BIT_MASKS
{
  MSK_WRN_COLD_BOOT     = ( 1UL << WRN_COLD_BOOT ),      ///< see ::WRN_COLD_BOOT
  MSK_WRN_WARM_BOOT     = ( 1UL << WRN_WARM_BOOT ),      ///< see ::WRN_WARM_BOOT
  MSK_WRN_ANT_DISCONN   = ( 1UL << WRN_ANT_DISCONN ),    ///< see ::WRN_ANT_DISCONN
  MSK_WRN_10MHZ_UNLOCK  = ( 1UL << WRN_10MHZ_UNLOCK ),   ///< see ::WRN_10MHZ_UNLOCK
  MSK_WRN_1PPS_UNLOCK   = ( 1UL << WRN_1PPS_UNLOCK ),    ///< see ::WRN_1PPS_UNLOCK
  MSK_WRN_GPS_UNLOCK    = ( 1UL << WRN_GPS_UNLOCK ),     ///< see ::WRN_GPS_UNLOCK
  MSK_WRN_10MHZ_MISSING = ( 1UL << WRN_10MHZ_MISSING ),  ///< see ::WRN_10MHZ_MISSING
  MSK_WRN_1PPS_MISSING  = ( 1UL << WRN_1PPS_MISSING ),   ///< see ::WRN_1PPS_MISSING
  MSK_WRN_MODULE_MODE   = ( 1UL << WRN_MODULE_MODE )     ///< see ::WRN_MODULE_MODE
};

/** @} defgroup group_multi_ref_old */



/**
 * @defgroup group_multi_ref_ext Extended multi ref definitions
 *
 * If the ::GPS_HAS_XMULTI_REF feature is set in ::RECEIVER_INFO::features then
 * the XMULTI_REF (extended multi ref, XMR) feature and API are supported and
 * have to be used in favor of the older multi ref API (see @ref group_multi_ref_old).
 *
 * Devices supporting the XMULTI_REF feature provide a number of
 * priority levels addressed by the priority index, starting at 0
 * for highest priority. A single reference time source from the set
 * of supported sources can be assigned to each priority level.
 *
 * These structures are used to configure the individual time source for each
 * priority level, and retrieve the status of the time source at each priority level.
 *
 * If ::GPS_HAS_XMRS_MULT_INSTC is also set in ::RECEIVER_INFO::features then
 * ::XMULTI_REF_INSTANCES can be used to find out which types of input source
 * are supported (::XMULTI_REF_INSTANCES::n_inst array entries != 0), and
 * how many priority levels are supported to which an input source can be
 * assigned (::XMULTI_REF_INSTANCES::n_xmr_settings).
 *
 * If ::XMRIF_MSK_HOLDOVER_STATUS_SUPP is set in ::XMULTI_REF_INSTANCES::flags
 * then ::XMR_HOLDOVER_STATUS can be used to monitor the switching between
 * different time sources when they become available or unavailable.
 *
 * If an XMR time source at a high priority level becomes unavailable the
 * XMR control function tries to find and switch to a different time source
 * at a lower level of the priority list, which is still available.
 *
 * On the other hand, if a time source at a higher priority level becomes
 * available again, the XMR control function switches over to the time source
 * at the higher priority even if the current time source is still available.
 *
 * If the accuracy of the time source at the next priority level is better than
 * the accuracy of the time source at the current priority level then switching
 * can be done immediately. However, if the next time source is worse than
 * the current one it makes more sense to switch only after a certain holdover
 * interval.
 *
 * The holdover interval is computed so that the time error due to the expected
 * drift of the previously disciplined time base grows until it reaches the
 * accuracy level of the next available reference time source.
 *
 * Only if the time source at the current priority level is still unavailable
 * when the holdover interval expires the reference time source is switched
 * to the time source at the next available priority level.
 *
 * @{ */


/**
 * @brief Identifier for a reference source
 */
typedef struct
{
  uint8_t type;      ///< see ::MULTI_REF_TYPES, and note for ::XMRIF_BIT_MRF_NONE_SUPP
  uint8_t instance;  ///< instance number, if multiple instances are supported, else 0

} XMULTI_REF_ID;

#define _mbg_swab_xmulti_ref_id( _p )  \
do                                     \
{                                      \
  _mbg_swab8( &(_p)->type );           \
  _mbg_swab8( &(_p)->instance );       \
} while ( 0 )



/**
 * @brief Reference source configuration settings
 */
typedef struct
{
  XMULTI_REF_ID id;     ///< reference time source identifier
  uint16_t flags;       ///< see ::XMR_SETTINGS_FLAG_MSKS and ::XMR_EXT_SRC_INFO::supp_flags
  NANO_TIME bias;       ///< time bias, e.g. path delay @todo specify sign vs. earlier/later
  NANO_TIME precision;  ///< precision of the time source
  uint32_t reserved;    ///< reserved, currently always 0

} XMULTI_REF_SETTINGS;

#define _mbg_swab_xmulti_ref_settings( _p )  \
do                                           \
{                                            \
  _mbg_swab_xmulti_ref_id( &(_p)->id );      \
  _mbg_swab16( &(_p)->flags );               \
  _mbg_swab_nano_time( &(_p)->bias );        \
  _mbg_swab_nano_time( &(_p)->precision );   \
  _mbg_swab32( &(_p)->reserved );            \
} while ( 0 )



/**
 * @brief Reference source configuration for a specific priority level
 *
 * @note After all other ::XMULTI_REF_SETTINGS_IDX configuration structures
 * have been sent to a device, an additional structure with idx == -1 (0xFFFF)
 * has to be sent to let the new settings come into effect.
 */
typedef struct
{
  uint16_t idx;                  ///< the priority level index (highest == 0), 0..::XMULTI_REF_INSTANCES::n_xmr_settings-1
  XMULTI_REF_SETTINGS settings;  ///< the settings configured for this level

} XMULTI_REF_SETTINGS_IDX;

#define _mbg_swab_xmulti_ref_settings_idx( _p )      \
do                                                   \
{                                                    \
  _mbg_swab16( &(_p)->idx );                         \
  _mbg_swab_xmulti_ref_settings( &(_p)->settings );  \
} while ( 0 )



/**
 * @brief Bit masks used to define ::XMR_SETTINGS_FLAG_MSKS
 */
enum XMR_SETTINGS_FLAG_BITS
{
  XMRSF_BIT_AUTO_BIAS_MASTER,          ///< src is allowed to operate as zero asymmetry master
  XMRSF_BIT_AUTO_BIAS_SLAVE,           ///< accept static bias correction from zero asymmetry master
  XMRSF_BIT_ASYMMETRY_STEP_DETECTION,  ///< static bias auto correction in case of step
  N_XMRSF_BITS                         ///< number of known flag bits
};


/**
 * @brief Bit masks used with ::XMULTI_REF_SETTINGS::flags and ::XMR_EXT_SRC_INFO::supp_flags
 */
enum XMR_SETTINGS_FLAG_MSKS
{
  XMRSF_MSK_AUTO_BIAS_MASTER         = ( 1UL << XMRSF_BIT_AUTO_BIAS_MASTER ),         ///< see ::XMRSF_BIT_AUTO_BIAS_MASTER
  XMRSF_MSK_AUTO_BIAS_SLAVE          = ( 1UL << XMRSF_BIT_AUTO_BIAS_SLAVE ),          ///< see ::XMRSF_BIT_AUTO_BIAS_SLAVE
  XMRSF_MSK_ASYMMETRY_STEP_DETECTION = ( 1UL << XMRSF_BIT_ASYMMETRY_STEP_DETECTION )  ///< see ::XMRSF_BIT_ASYMMETRY_STEP_DETECTION
};



/**
 * @brief Reference source capabilities and current configuration
 */
typedef struct
{
  XMULTI_REF_SETTINGS settings;  ///< current settings

  /**
   * @deprecated Deprecated by ::XMULTI_REF_INSTANCES::n_inst.
   * If ::GPS_HAS_XMRS_MULT_INSTC is *not* set then this field provides
   * a bit mask of supported sources (see @ref MULTI_REF_TYPE_MASKS),
   * and only a single instance of each source signal type is supported.
   */
  uint32_t supp_ref;

  /**
   * @deprecated Deprecated by ::XMULTI_REF_INSTANCES::n_xmr_settings.
   * If ::GPS_HAS_XMRS_MULT_INSTC is *not* set then this field
   * reports the number of priority levels supported by the device.
   */
  uint8_t n_supp_ref;

  uint8_t n_prio;   ///< reserved, don't use, currently always 0 //##++++ TODO: check which devices support/use this field
  uint16_t flags;   ///< reserved, don't use, currently always 0

} XMULTI_REF_INFO;

#define _mbg_swab_xmulti_ref_info( _p )              \
do                                                   \
{                                                    \
  _mbg_swab_xmulti_ref_settings( &(_p)->settings );  \
  _mbg_swab32( &(_p)->supp_ref );                    \
  _mbg_swab8( &(_p)->n_supp_ref );                   \
  _mbg_swab8( &(_p)->n_prio );                       \
  _mbg_swab16( &(_p)->flags );                       \
} while ( 0 )



/**
 * @brief Reference source capabilities and current configuration for a specific priority level
 */
typedef struct
{
  uint16_t idx;          ///< the priority level index (highest == 0), 0..::XMULTI_REF_INSTANCES::n_xmr_settings-1
  XMULTI_REF_INFO info;  ///< ref source configuration and capabilities

} XMULTI_REF_INFO_IDX;

#define _mbg_swab_xmulti_ref_info_idx( _p )  \
do                                           \
{                                            \
  _mbg_swab16( &(_p)->idx );                 \
  _mbg_swab_xmulti_ref_info( &(_p)->info );  \
} while ( 0 )



/**
 * @brief Status information on a single ref time source
 */
typedef struct
{
  XMULTI_REF_ID id;  ///< time source identifier
  uint16_t status;   ///< status bits, see @ref XMR_REF_STATUS_BIT_MASKS
  NANO_TIME offset;  ///< time offset from main time base @todo specify sign vs. earlier/later
  uint16_t flags;    ///< flags, see ::XMR_QL  // TODO ###
  uint8_t ssm;       ///< synchronization status message, if supported by signal source
  uint8_t soc;       ///< signal outage counter, incremented on loss of signal

} XMULTI_REF_STATUS;

#define _mbg_swab_xmulti_ref_status( _p )  \
do                                         \
{                                          \
  _mbg_swab_xmulti_ref_id( &(_p)->id );    \
  _mbg_swab16( &(_p)->status );            \
  _mbg_swab_nano_time( &(_p)->offset );    \
  _mbg_swab16( &(_p)->flags );             \
  _mbg_swab8( &(_p)->ssm );                \
  _mbg_swab8( &(_p)->soc );                \
} while ( 0 )



/**
 * @brief Status information on a ref time source at a specific priority level
 */
typedef struct
{
  uint16_t idx;              ///< the priority level index (highest == 0), 0..::XMULTI_REF_INSTANCES::n_xmr_settings-1
  XMULTI_REF_STATUS status;  ///< status information

} XMULTI_REF_STATUS_IDX;

#define _mbg_swab_xmulti_ref_status_idx( _p )    \
do                                               \
{                                                \
  _mbg_swab16( &(_p)->idx );                     \
  _mbg_swab_xmulti_ref_status( &(_p)->status );  \
} while ( 0 )



/**
 * @brief ::TODO
 *
 * Used with the ::... field of ::XMULTI_REF_STATUS::flags
 *
 * @see ::XMULTI_REF_STATUS::flags
 * @see ::XMR_QL_MASK
 * @see ::_GET_XMR_QL
 * @see ::_PUT_XMR_QL
 */
enum XMR_QL
{
  XMR_QL_UNKNOWN,
  XMR_QL_GREEN,
  XMR_QL_YELLOW,
  XMR_QL_RED,
  N_XMR_QL
};

#define XMR_QL_TDEV_MASK  ( 0x03 << 0 )
#define XMR_QL_MTIE_MASK  ( 0x03 << 2 )

#define _GET_XMR_QL_TDEV( _x )              ( ( ( _x ) & XMR_QL_TDEV_MASK ) >> 0 )
#define _PUT_XMR_QL_TDEV( _x, _ql )                                                  \
do {                                                                                 \
  ( _x ) = ( ( _x ) & ~XMR_QL_TDEV_MASK ) | ( ( ( _ql ) << 0 ) & XMR_QL_TDEV_MASK ); \
} while ( 0 )


#define _GET_XMR_QL_MTIE( _x )              ( ( ( _x ) & XMR_QL_MTIE_MASK ) >> 2 )
#define _PUT_XMR_QL_MTIE( _x, _ql )                                                  \
do {                                                                                 \
  ( _x ) = ( ( _x ) & ~XMR_QL_MTIE_MASK ) | ( ( ( _ql ) << 2 ) & XMR_QL_MTIE_MASK ); \
} while ( 0 )



/**
 * @brief XMULTI_REF status bits
 */
enum XMR_REF_STATUS_BITS
{
  XMRS_BIT_NOT_SUPP,           ///< ref type cfg'd for this level is not supported
  XMRS_BIT_NO_CONN,            ///< input signal is disconnected
  XMRS_BIT_NO_SIGNAL,          ///< no input signal
  XMRS_BIT_IS_MASTER,          ///< reference is master source
  XMRS_BIT_IS_LOCKED,          ///< locked to input signal
  XMRS_BIT_IS_ACCURATE,        ///< oscillator control has reached full accuracy
  XMRS_BIT_NOT_SETTLED,        ///< reference time signal not settled
  XMRS_BIT_NOT_PHASE_LOCKED,   ///< oscillator not phase locked to PPS
  XMRS_BIT_NUM_SRC_EXC,        ///< number of available sources exceeds what can be handled
  XMRS_BIT_IS_EXTERNAL,        ///< this ref source is on extension card
  XMRS_BIT_LOW_JITTER,         ///< this ref source has low jitter
  XMRS_BIT_ITU_LIMIT_VIOLATED, ///< ITU limits violated (valid if device has ::XMR_METRICS)
  N_XMRS_BITS                  ///< number of know status bits
};



/**
 * @brief Bit masks associated with ::XMR_REF_STATUS_BITS
 *
 * Used with ::XMULTI_REF_STATUS::status.
 *
 * @see ::XMR_REF_STATUS_BITS
 *
 * @anchor XMR_REF_STATUS_BIT_MASKS @{ */

#define XMRS_MSK_NOT_SUPP            ( 1UL << XMRS_BIT_NOT_SUPP )            ///< see ::XMRS_BIT_NOT_SUPP
#define XMRS_MSK_NO_CONN             ( 1UL << XMRS_BIT_NO_CONN )             ///< see ::XMRS_BIT_NO_CONN
#define XMRS_MSK_NO_SIGNAL           ( 1UL << XMRS_BIT_NO_SIGNAL )           ///< see ::XMRS_BIT_NO_SIGNAL
#define XMRS_MSK_IS_MASTER           ( 1UL << XMRS_BIT_IS_MASTER )           ///< see ::XMRS_BIT_IS_MASTER
#define XMRS_MSK_IS_LOCKED           ( 1UL << XMRS_BIT_IS_LOCKED )           ///< see ::XMRS_BIT_IS_LOCKED
#define XMRS_MSK_IS_ACCURATE         ( 1UL << XMRS_BIT_IS_ACCURATE )         ///< see ::XMRS_BIT_IS_ACCURATE
#define XMRS_MSK_NOT_SETTLED         ( 1UL << XMRS_BIT_NOT_SETTLED )         ///< see ::XMRS_BIT_NOT_SETTLED
#define XMRS_MSK_NOT_PHASE_LOCKED    ( 1UL << XMRS_BIT_NOT_PHASE_LOCKED )    ///< see ::XMRS_BIT_NOT_PHASE_LOCKED
#define XMRS_MSK_NUM_SRC_EXC         ( 1UL << XMRS_BIT_NUM_SRC_EXC )         ///< see ::XMRS_BIT_NUM_SRC_EXC
#define XMRS_MSK_IS_EXTERNAL         ( 1UL << XMRS_BIT_IS_EXTERNAL )         ///< see ::XMRS_BIT_IS_EXTERNAL
#define XMRS_MSK_LOW_JITTER          ( 1UL << XMRS_BIT_LOW_JITTER )          ///< see ::XMRS_BIT_LOW_JITTER
#define XMRS_MSK_ITU_LIMIT_VIOLATED  ( 1UL << XMRS_BIT_ITU_LIMIT_VIOLATED )  ///< see ::XMRS_BIT_ITU_LIMIT_VIOLATED

/** @} anchor XMR_REF_STATUS_BIT_MASKS */



/**
 * @brief XMRS status bit name strings
 *
 * @see ::XMR_REF_STATUS_BITS
 */
#define MBG_XMRS_STATUS_STRS      \
{                                 \
  "Ref type not supported",       \
  "No connection",                \
  "No signal",                    \
  "Is master",                    \
  "Is locked",                    \
  "Is accurate",                  \
  "Not settled",                  \
  "Phase not locked",             \
  "Number sources exceeds limit", \
  "Is external",                  \
  "Low jitter",                   \
  "ITU Limit violated"            \
}



/*
 * An initializer for a ::XMULTI_REF_STATUS variable
 * with status invalid / not used
 */
#define XMULTI_REF_STATUS_INVALID                          \
{                                                          \
  { (uint8_t) MULTI_REF_NONE, 0 },  /* id; instance 0 ? */ \
  XMRS_MSK_NO_CONN | XMRS_MSK_NO_SIGNAL,  /* status */     \
  { 0 },                                  /* offset */     \
  0                                      /* reserved */    \
}



/**
 * @brief General info on supported XMR sources and instances
 *
 * @note This structure is only supported if ::GPS_HAS_XMRS_MULT_INSTC
 * is set in ::RECEIVER_INFO::features.
 *
 * The field ::XMULTI_REF_INSTANCES::n_xmr_settings reports the maximum number
 * of entries that can be held by the input source table provided by this device.
 * The input source table entry with the lowest index has the highest priority,
 * and values 0..::XMULTI_REF_INSTANCES::n_xmr_settings-1 can be used as index
 * when reading ::XMULTI_REF_INFO_IDX or ::XMULTI_REF_STATUS_IDX from the device,
 * or when writing ::XMULTI_REF_SETTINGS_IDX to the device to configure
 * the priority/order of input sources.
 *
 * An input source table entry is empty if ::XMULTI_REF_ID::type is set to
 * ::MULTI_REF_NONE in ::XMULTI_REF_SETTINGS::id, and accordingly
 * in ::XMULTI_REF_STATUS::id.
 *
 * The array ::XMULTI_REF_INSTANCES::n_inst reports how many instances are supported
 * for every known reference type. For example, if 2 PPS input signals were supported
 * then ::XMULTI_REF_INSTANCES::n_inst[::MULTI_REF_PPS] was set to 2. Even though
 * this array can hold up to ::MAX_N_MULTI_REF_TYPES entries, the number entries
 * which are actually used is ::N_MULTI_REF, according to the number of known
 * reference signal types, which is less or equal than ::MAX_N_MULTI_REF_TYPES.
 */
typedef struct
{
  uint32_t flags;    ///< see ::XMR_INST_FLAG_BIT_MASKS
  uint16_t n_xmr_settings;   ///< number of ::XMULTI_REF_INFO_IDX or ::XMULTI_REF_STATUS_IDX which can be retrieved
  uint8_t slot_id;   ///< ID of the slot in which this device is installed, 0 or up to 15, if multiple slots not supported
  uint8_t reserved;  ///< reserved, don't use, currently always 0
  uint8_t n_inst[MAX_N_MULTI_REF_TYPES];   ///< the number of supported instances of each input signal type

} XMULTI_REF_INSTANCES;

#define _mbg_swab_xmulti_ref_instances( _p )  \
do                                            \
{                                             \
  _mbg_swab32( &(_p)->flags );                \
  _mbg_swab16( &(_p)->n_xmr_settings );       \
} while ( 0 )



/**
 * @brief Enumeration of flag bits used with XMULTI_REF instances
 *
 * @see ::XMR_INST_FLAG_BIT_MASKS
 */
enum XMR_INST_FLAGS
{
  /// This flag indicates that configuration programs may set
  /// ::XMULTI_REF_ID::type to ::MULTI_REF_NONE in ::XMULTI_REF_SETTINGS::id
  /// for unused priority levels, and that this will be reflected in
  /// ::XMULTI_REF_STATUS::id accordingly. With some older firmware versions
  /// this was not supported.
  XMRIF_BIT_MRF_NONE_SUPP,

  XMRIF_BIT_HOLDOVER_STATUS_SUPP,  ///< ::XMR_HOLDOVER_STATUS and associated types supported

  XMRIF_BIT_EXT_SRC_INFO_SUPP,     ///< ::XMR_EXT_SRC_INFO structure supported

  N_XMRIF_BITS  ///< number of known flag bits
};


/**
 * @brief Bit masks associated with ::XMR_INST_FLAGS
 *
 * Used with ::XMULTI_REF_INSTANCES::flags.
 *
 * @see ::XMR_INST_FLAGS
 */
enum XMR_INST_FLAG_BIT_MASKS
{
  XMRIF_MSK_MRF_NONE_SUPP        = ( 1UL << XMRIF_BIT_MRF_NONE_SUPP ),        ///< see ::XMRIF_BIT_MRF_NONE_SUPP
  XMRIF_MSK_HOLDOVER_STATUS_SUPP = ( 1UL << XMRIF_BIT_HOLDOVER_STATUS_SUPP ), ///< see ::XMRIF_BIT_HOLDOVER_STATUS_SUPP
  XMRIF_MSK_EXT_SRC_INFO_SUPP    = ( 1UL << XMRIF_BIT_EXT_SRC_INFO_SUPP )     ///< see ::XMRIF_BIT_EXT_SRC_INFO_SUPP
};



/**
 * @brief XMR holdover interval, or elapsed holdover time, in [s]
 */
typedef uint32_t XMR_HOLDOVER_INTV;

#define _mbg_swab_xmr_holdover_intv( _p ) \
  _mbg_swab32( _p )



/**
 * @brief A code used to indicate that a input source table index is unspecified
 */
#define XMR_PRIO_LVL_UNSPEC   -1



/**
 * @brief XMR holdover status
 *
 * Only supported if ::XMRIF_MSK_HOLDOVER_STATUS_SUPP is set in ::XMULTI_REF_INSTANCES::flags
 *
 * Reports the current holdover status including the elapsed holdover time
 * and the currently active holdover interval, as well as the indices of the
 * current and next XMR time source.
 *
 * The flag ::XMR_HLDOVR_MSK_IN_HOLDOVER is set if holdover mode is currently active.
 *
 * The fields ::XMR_HOLDOVER_STATUS::curr_prio and ::XMR_HOLDOVER_STATUS::nxt_prio
 * specify the current or next priority level which can be in the range
 * 0..::XMULTI_REF_INSTANCES::n_xmr_settings-1, or ::XMR_PRIO_LVL_UNSPEC if the
 * index is undefined, e.g. because no input source is available to which can
 * be switched after the holdover interval.
 *
 * The ::XMR_HOLDOVER_STATUS::mode field indicates the current XMR/holdover mode
 * which is usually ::XMR_HLDOVR_AUTONOMOUS. However, in certain applications
 * XMR switching is controlled remotely, in which case ::XMR_HOLDOVER_STATUS::mode
 * is set to ::XMR_HLDOVR_REMOTE.
 *
 * If the device is in remote mode and needs to switch XMR sources then mode changes
 * to ::XMR_HLDOVR_PRE_AUTONOMOUS, and the ::XMR_HOLDOVER_STATUS::remote_watchdog
 * starts to count down. If the watchdog expires before a remote switch command
 * has been received the device switches to ::XMR_HLDOVR_AUTONOMOUS.
 */
typedef struct
{
  uint8_t mode;                ///< XMR/holdover mode, see ::XMR_HOLDOVER_STATUS_MODES
  int8_t curr_prio;            ///< current priority level, 0..::XMULTI_REF_INSTANCES::n_xmr_settings, or ::XMR_PRIO_LVL_UNSPEC
  int8_t nxt_prio;             ///< next priority level after holdover, 0..::XMULTI_REF_INSTANCES::n_xmr_settings, or ::XMR_PRIO_LVL_UNSPEC
  uint8_t remote_watchdog;     ///< counts down in ::XMR_HLDOVR_PRE_AUTONOMOUS mode
  uint32_t time_offset_ns;     ///< estimated time offset in holdover operation
  XMR_HOLDOVER_INTV elapsed;   ///< elapsed time in holdover mode, only valid if ::XMR_HLDOVR_MSK_IN_HOLDOVER is set
  XMR_HOLDOVER_INTV interval;  ///< current holdover interval, only valid if ::XMR_HLDOVR_MSK_IN_HOLDOVER is set
  uint32_t flags;              ///< holdover status flags, see ::XMR_HOLDOVER_STATUS_FLAG_MASKS

} XMR_HOLDOVER_STATUS;

#define _mbg_swab_xmr_holdover_status( _p )        \
do                                                 \
{                                                  \
  _mbg_swab8( &(_p)->mode );                       \
  _mbg_swab8( &(_p)->curr_prio );                  \
  _mbg_swab8( &(_p)->nxt_prio );                   \
  _mbg_swab8( &(_p)->remote_watchdog );            \
  _mbg_swab32( &(_p)->time_offset_ns );            \
  _mbg_swab_xmr_holdover_intv( &(_p)->elapsed );   \
  _mbg_swab_xmr_holdover_intv( &(_p)->interval );  \
  _mbg_swab32( &(_p)->flags );                     \
} while ( 0 )




/**
 * @brief XMR holdover status modes
 *
 * Used with ::XMR_HOLDOVER_STATUS::mode.
 *
 * @see ::XMR_HOLDOVER_STATUS_MODE_NAMES
 */
enum XMR_HOLDOVER_STATUS_MODES
{
  XMR_HLDOVR_AUTONOMOUS,        ///< autonomous mode, XMR sources are selected automatically by the device
  XMR_HLDOVR_PRE_AUTONOMOUS,    ///< going to switch to autonomous mode when ::XMR_HOLDOVER_STATUS::remote_watchdog reaches 0
  XMR_HLDOVR_REMOTE,            ///< remote mode, XMR switching done by external command/control
  N_XMR_HOLDOVER_STATUS_MODES   ///< the number of known modes
};


/**
 * @brief String initializers for XMR holdover status mode
 *
 * @see ::XMR_HOLDOVER_STATUS_MODES
 */
#define XMR_HOLDOVER_STATUS_MODE_NAMES \
{                                      \
  "Autonomous",                        \
  "Pre-Autonomous",                    \
  "Remote"                             \
}



/**
 * @brief XMR holdover status flag bits
 *
 * Used to define ::XMR_HOLDOVER_STATUS_FLAG_MASKS.
 */
enum XMR_HOLDOVER_STATUS_FLAG_BITS
{
  XMR_HLDOVR_BIT_IN_HOLDOVER,       ///< the device is currently in holdover mode
  XMR_HLDOVR_BIT_TRANSITION_ENBD,   ///< timebase is in transition (being slewed) after sources have been switched
  XMR_HLDOVR_BIT_IN_TRANSITION,     ///< transition is currently active, slewing in progress
  XMR_HLDOVR_BIT_TIME_OFFS_VALID,   ///< values in field ::XMR_HOLDOVER_STATUS::time_offset_ns are valid
  N_XMR_HOLDOVER_STATUS_FLAG_BITS   ///< the number of known status flags
};


/**
 * @brief XMR holdover status flag masks
 *
 * Used with ::XMR_HOLDOVER_STATUS::flags.
 */
enum XMR_HOLDOVER_STATUS_FLAG_MASKS
{
  XMR_HLDOVR_MSK_IN_HOLDOVER     = ( 1UL << XMR_HLDOVR_BIT_IN_HOLDOVER ),      ///< see ::XMR_HLDOVR_BIT_IN_HOLDOVER
  XMR_HLDOVR_MSK_TRANSITION_ENBD = ( 1UL << XMR_HLDOVR_BIT_TRANSITION_ENBD ),  ///< see ::XMR_HLDOVR_BIT_TRANSITION_ENBD
  XMR_HLDOVR_MSK_IN_TRANSITION   = ( 1UL << XMR_HLDOVR_BIT_IN_TRANSITION ),    ///< see ::XMR_HLDOVR_BIT_IN_TRANSITION
  XMR_HLDOVR_MSK_TIME_OFFS_VALID = ( 1UL << XMR_HLDOVR_BIT_TIME_OFFS_VALID )   ///< see ::XMR_HLDOVR_BIT_TIME_OFFS_VALID
};



/**
 * @brief XMR source feature flag bits
 *
 * Used to define ::XMR_EXT_SRC_FEAT_FLAG_MSKS
 */
enum XMR_EXT_SRC_FEAT_FLAG_BITS
{
  XMR_EXT_SRC_FEAT_FLAG_BIT_STATS,    ///< XMR source provides ::XMR_STATS
  XMR_EXT_SRC_FEAT_FLAG_BIT_METRICS,  ///< XMR source provides ::XMR_METRICS
  N_XMR_EXT_SRC_FEAT_FLAG_BITS
};



/**
 * @brief XMR source feature flag bit masks
 *
 * Used with ::XMR_EXT_SRC_INFO::feat_flags.
 *
 * @see ::XMR_EXT_SRC_FEAT_FLAG_BITS
 */
enum XMR_EXT_SRC_FEAT_FLAG_MSKS
{
  XMR_EXT_SRC_FEAT_FLAG_MSK_STATS   = ( 1UL << XMR_EXT_SRC_FEAT_FLAG_BIT_STATS ),  ///< see ::XMR_EXT_SRC_FEAT_FLAG_BIT_STATS
  XMR_EXT_SRC_FEAT_FLAG_MSK_METRICS = ( 1UL << XMR_EXT_SRC_FEAT_FLAG_BIT_METRICS ) ///< see ::XMR_EXT_SRC_FEAT_FLAG_BIT_METRICS
};



typedef struct
{
  uint16_t supp_flags;    ///< indicates which flags are supported by ::XMULTI_REF_SETTINGS::flags, see ::XMR_SETTINGS_FLAG_MSKS
  uint16_t feat_flags;    ///< see ::XMR_EXT_SRC_FEAT_FLAG_MSKS
  uint32_t reserved_0;

} XMR_EXT_SRC_INFO;

#define _mbg_swab_xmr_ext_src_info( _p )  \
do                                        \
{                                         \
  _mbg_swab16( &(_p)->supp_flags );       \
  _mbg_swab16( &(_p)->feat_flags );       \
  _mbg_swab32( &(_p)->reserved_0 );       \
} while ( 0 )



typedef struct
{
  uint16_t          idx;            //
  XMR_EXT_SRC_INFO  info;           //

} XMR_EXT_SRC_INFO_IDX;             //

#define _mbg_swab_xmr_ext_src_info_idx( _p )  \
do                                            \
{                                             \
  _mbg_swab16( &(_p)->idx );                  \
  _mbg_swab_xmr_ext_src_info( &(_p)->info );  \
} while ( 0 )



/**
 * @brief XMR statistics for a particular source
 *
 * This structure is only provided by an XMR source which has
 * ::XMR_EXT_SRC_FEAT_FLAG_MSK_STATS set in ::XMR_EXT_SRC_INFO::feat_flags.
 *
 * @see ::XMR_STATS_IDX
 * @see ::XMR_EXT_SRC_INFO::feat_flags
 * @see ::XMR_EXT_SRC_FEAT_FLAG_MSK_STATS
 */
typedef struct
{
  uint32_t timestamp;       ///< time stamp when the record was taken, UTC, seconds since 1970
  NANO_TIME last_mue;       ///< mean value (mue) of prev. interval
  NANO_TIME last_sigma;     ///< standard deviation (sigma) of prev. interval
  NANO_TIME last_max;       ///< maximum value within interval
  NANO_TIME last_min;       ///< minimum value within interval
  NANO_TIME reserved_0;     ///< currently reserved, unused, always 0
  NANO_TIME step_comp_val;  ///< current step compensation value
  NANO_TIME auto_bias;      ///< current time automatic bias compensation
  uint32_t reserved_1;      ///< currently reserved, unused, always 0
  uint32_t reserved_2;      ///< currently reserved, unused, always 0
  uint32_t flags;           ///< see ::XMR_STATS_FLAGS_MSKS

} XMR_STATS;

#define _mbg_swab_xmr_stats( _p )               \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->timestamp );              \
  _mbg_swab_nano_time( &(_p)->last_mue );       \
  _mbg_swab_nano_time( &(_p)->last_sigma );     \
  _mbg_swab_nano_time( &(_p)->last_max );       \
  _mbg_swab_nano_time( &(_p)->last_min );       \
  _mbg_swab_nano_time( &(_p)->reserved_0 );     \
  _mbg_swab_nano_time( &(_p)->step_comp_val );  \
  _mbg_swab_nano_time( &(_p)->auto_bias );      \
  _mbg_swab32( &(_p)->reserved_1 );             \
  _mbg_swab32( &(_p)->reserved_2 );             \
  _mbg_swab32( &(_p)->flags );                  \
} while ( 0 )



/**
 * @brief Enumeration of bits used to define ::XMR_STATS_FLAGS_MSKS
 *
 * @see ::XMR_STATS_FLAGS_MSKS
 */
enum XMR_STATS_FLAGS_BITS
{
  XMR_STATS_FLAG_BIT_STEP_DETECTED,     ///< A time step was detected at the input source
  XMR_STATS_FLAG_BIT_STEP_COMPENSATED,  ///< A time step was compensated at the input source
  XMR_STATS_FLAG_BIT_AUTO_BIAS_VALID,   ///< The value in ::XMR_STATS::auto_bias is valid
  N_XMR_STATS_FLAGS_BITS
};



/**
 * @brief Flag bit masks used with ::XMR_STATS::flags
 *
 * @see ::XMR_STATS_FLAGS_BITS
 */
enum XMR_STATS_FLAGS_MSKS
{
  XMR_STATS_FLAG_MSK_STEP_DETECTED     = ( 1UL << XMR_STATS_FLAG_BIT_STEP_DETECTED ),    ///< see ::XMR_STATS_FLAG_BIT_STEP_DETECTED
  XMR_STATS_FLAG_MSK_STEP_COMPENSATED  = ( 1UL << XMR_STATS_FLAG_BIT_STEP_COMPENSATED ), ///< see ::XMR_STATS_FLAG_BIT_STEP_COMPENSATED
  XMR_STATS_FLAG_MSK_AUTO_BIAS_VALID   = ( 1UL << XMR_STATS_FLAG_BIT_AUTO_BIAS_VALID )   ///< see ::XMR_STATS_FLAG_BIT_AUTO_BIAS_VALID
};



/**
 * @brief String initializers for XMR Stats Flags
 *
 * @see ::XMR_STATS_FLAGS_MSKS
 */
#define DEFAULT_XMR_STATS_FLAG_NAMES \
{                                    \
  "Step Detected",                   \
  "Step Compensated",                \
  "Auto BIAS valid"                  \
}



/**
 * @brief XMR statistics for a particular source, with index
 *
 * @see ::XMR_STATS
 */
typedef struct
{
  uint16_t idx;      ///< the priority level index (highest == 0), 0..::XMULTI_REF_INSTANCES::n_xmr_settings-1
  XMR_STATS stats;   ///< XMR statistics of the particular source

} XMR_STATS_IDX;

#define _mbg_swab_xmr_stats_idx( _p )   \
do                                      \
{                                       \
  _mbg_swab16( &(_p)->idx );            \
  _mbg_swab_xmr_stats( &(_p)->stats );  \
} while ( 0 )



#define MAX_XMR_METRICS  20

typedef struct
{
  uint32_t timestamp;
  uint32_t flags;                  ///< idx bit set if mtie[idx] is valid
  uint8_t  mtie_scale;             ///< scale factors of MTIE
  uint8_t  tdev_scale;             ///< scale factors of TDEV
  uint16_t reserved_0;             ///< currently unused
  uint32_t reserved_1;             ///< currently unused
  uint32_t reserved_2;             ///< currently unused
  uint32_t mtie[MAX_XMR_METRICS];  ///< mtie scaled 32 bit fixed point unsigned
  uint32_t tdev[MAX_XMR_METRICS];  ///< tdev scaled 32 bit fixed point unsigned

} XMR_METRICS;

#define _mbg_swab_xmr_metrics( _p )        \
do                                         \
{                                          \
  int i;                                   \
                                           \
  _mbg_swab32( &(_p)->timestamp );         \
  _mbg_swab32( &(_p)->flags );             \
  _mbg_swab8( &(_p)->mtie_scale );         \
  _mbg_swab8( &(_p)->tdev_scale );         \
  _mbg_swab16( &(_p)->reserved_0 );        \
  _mbg_swab32( &(_p)->reserved_1 );        \
  _mbg_swab32( &(_p)->reserved_2 );        \
                                           \
  for ( i = 0; i < MAX_XMR_METRICS; i++ )  \
    _mbg_swab32( &(_p)->mtie[i] );         \
                                           \
  for ( i = 0; i < MAX_XMR_METRICS; i++ )  \
    _mbg_swab32( &(_p)->tdev[i] );         \
                                           \
} while ( 0 )



// conversion factor scaled FPU32 to double
#define _fpu32_to_double_fac( _x ) ( 1.0 / ( 4294967296.0 * ( _x ) ) )



/**
 * @brief XMR timing metrics for a particular source, with index
 *
 * @see ::XMR_METRICS
 */
typedef struct
{
  uint16_t    idx;
  XMR_METRICS metrics;

} XMR_METRICS_IDX;

#define _mbg_swab_xmr_metrics_idx( _p )     \
do                                          \
{                                           \
  _mbg_swab16( &(_p)->idx );                \
  _mbg_swab_xmr_metrics( &(_p)->metrics );  \
} while ( 0 )



/**
 * @brief Enumeration of ITU limit masks
 *
 * Used for detection of ::XMR_METRICS mask violation.
 *
 * @see ::ITU_LIMIT_MASKS
 * @see ::XMR_METRICS
 */
enum ITU_LIMITS
{
  ITU_LIMIT_G811_PRC,
  ITU_LIMIT_G823_SSU,
  ITU_LIMIT_G823_SEC,
  ITU_LIMIT_G8272_PRTC,
  ITU_LIMIT_G82721_EPRTC,
  N_ITU_LIMITS
} ;



/**
 * @brief Enumeration of ITU limit masks
 *
 * Used for detection of ::XMR_METRICS mask violation.
 *
 * @see ::ITU_LIMITS
 * @see ::XMR_METRICS
 */
enum ITU_LIMIT_MASKS
{
  MSK_ITU_LIMIT_G811_PRC      =  ( 1UL << ITU_LIMIT_G811_PRC ),
  MSK_ITU_LIMIT_G823_SSU      =  ( 1UL << ITU_LIMIT_G823_SSU ),
  MSK_ITU_LIMIT_G823_SEC      =  ( 1UL << ITU_LIMIT_G823_SEC ),
  MSK_ITU_LIMIT_G8272_PRTC    =  ( 1UL << ITU_LIMIT_G8272_PRTC ),
  MSK_ITU_LIMIT_G82721_EPRTC  =  ( 1UL << ITU_LIMIT_G82721_EPRTC )
};



/**
 * @brief String initializers for ITU limit masks
 *
 * Used for detection of ::XMR_METRICS mask violation.
 *
 * @see ::ITU_LIMITS
 * @see ::XMR_METRICS
 */
#define ITU_LIMIT_SHORT_STRS      \
{                                 \
  "G811 (PRC)",                   \
  "G823 (SSU)",                   \
  "G823 (SEC)",                   \
  "G8272  (PRTC)",                \
  "G82721 (ePRTC)"                \
}



/**
 * @brief supported limits for qualtity metrics
 *
 * @see ::XMR_METRICS
 */
typedef struct
{
  uint8_t  ql_mask;            ///< see  :ITU_LIMIT_MASKS
  uint8_t  hysteresis;         ///< hysteresis (percent) between yellow and red alarm
  uint16_t reserved_0;
  uint32_t reserved_1;

} XMR_QL_SETTINGS;



typedef struct
{
  uint32_t        supp_ql_masks;     ///< see  :ITU_LIMIT_MASKS
  uint32_t        reserved_0;
  uint32_t        reserved_1;
  XMR_QL_SETTINGS settings;

} XMR_QL_INFO;



typedef struct
{
  uint16_t        idx;
  XMR_QL_SETTINGS settings;

} XMR_QL_SETTINGS_IDX;



typedef struct
{
  uint16_t    idx;
  XMR_QL_INFO info;

} XMR_QL_INFO_IDX;


/** @} defgroup group_multi_ref_ext */

/** @} defgroup group_multi_ref_all */


/**
 * @defgroup group_gpio GPIO port configuration stuff
 *
 * @note This is only supported if ::GPS_HAS_GPIO is set
 * in the ::RECEIVER_INFO::features mask.
 *
 * @{ */


/**
 * @brief General GPIO config info to be read from a device
 *
 * Used to query from a device how many GPIO ports are supported
 * by the device, then index 0..::MBG_GPIO_CFG_LIMITS::num_io-1
 * configuration or status records can be read from or written to
 * the device.
 */
typedef struct
{
  uint32_t num_io;     ///< number of supported GPIO ports
  uint32_t reserved;   ///< reserved, currently always 0
  uint32_t flags;      ///< see ::MBG_GPIO_CFG_LIMIT_FLAG_MASKS

} MBG_GPIO_CFG_LIMITS;

#define _mbg_swab_mbg_gpio_cfg_limits( _p ) \
do                                          \
{                                           \
  _mbg_swab32( &(_p)->num_io );             \
  _mbg_swab32( &(_p)->reserved );           \
  _mbg_swab32( &(_p)->flags );              \
} while ( 0 )



/**
 * @brief GPIO limits flag bits used to define ::MBG_GPIO_CFG_LIMIT_FLAG_MASKS
 *
 * @see ::MBG_GPIO_CFG_LIMIT_FLAG_MASKS
 */
enum MBG_GPIO_CFG_LIMIT_FLAG_BITS
{
  MBG_GPIO_CFG_LIMIT_FLAG_BIT_STATUS_SUPP,  ///< indicates that ::MBG_GPIO_STATUS is supported
  N_MBG_GPIO_CFG_LIMIT_FLAG_BITS
};



/**
 * @brief GPIO limits flag masks associated with ::MBG_GPIO_CFG_LIMIT_FLAG_BITS
 *
 * Used with ::MBG_GPIO_CFG_LIMITS::flags
 *
 * @see ::MBG_GPIO_CFG_LIMIT_FLAG_BITS
 */
enum MBG_GPIO_CFG_LIMIT_FLAG_MASKS
{
  MBG_GPIO_CFG_LIMIT_FLAG_MASK_STATUS_SUPP = ( 1UL << MBG_GPIO_CFG_LIMIT_FLAG_BIT_STATUS_SUPP ),  ///< see ::MBG_GPIO_CFG_LIMIT_FLAG_BIT_STATUS_SUPP
};



/**
 * @brief Enumeration of GPIO types
 *
 * Usually a specific GPIO port can only be either an input
 * or an output, and supports only a single signal type.
 * This is due to hardware limitations, i.e. input or output
 * circuitry required for the given signal.
 *
 * @see ::DEFAULT_GPIO_TYPES_SHORT_STRS
 */
enum MBG_GPIO_TYPES
{
  MBG_GPIO_TYPE_FREQ_IN,            ///< Variable frequency input, freq == 0 if input not used
  MBG_GPIO_TYPE_FREQ_OUT,           ///< Variable frequency output
  MBG_GPIO_TYPE_FIXED_FREQ_OUT,     ///< Fixed frequency output
  MBG_GPIO_TYPE_BITS_IN,            ///< Framed data stream input
  MBG_GPIO_TYPE_BITS_OUT,           ///< Framed data stream output
  MBG_GPIO_TYPE_VIDEO_OUT,          ///< Video signal output (PAL, NTSC, ...)
  MBG_GPIO_TYPE_VIDEO_SYNC_OUT,     ///< Video sync signal output (H-Sync, V-Sync, ...)
  MBG_GPIO_TYPE_STUDIO_CLOCK_OUT,   ///< Studio clock output
  MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT,  ///< Digital Audio output (DARS, ...)
  N_MBG_GPIO_TYPES                  ///< Number of known types
};



#define DEFAULT_GPIO_TYPES_SHORT_STRS \
{                                     \
  "Freq. In",                         \
  "Freq. Out",                        \
  "Fixed Freq Out",                   \
  "BITS In",                          \
  "BITS Out",                         \
  "Video Out",                        \
  "Video Sync Out",                   \
  "Studio Clock Out",                 \
  "Digital Audio Out"                 \
}



/**
 * @brief Enumeration of known signal shapes
 *
 * Used to specify the signal shape of an input or output
 * frequency signal.
 *
 * @see ::MBG_GPIO_SIGNAL_SHAPE_MASKS
 * @see ::DEFAULT_GPIO_SIGNAL_SHAPE_NAMES
 */
enum MBG_GPIO_SIGNAL_SHAPES
{
  MBG_GPIO_SIGNAL_SHAPE_UNSPECIFIED,  ///< unknown or unspecified signal shape
  MBG_GPIO_SIGNAL_SHAPE_SINE,         ///< sine wave
  MBG_GPIO_SIGNAL_SHAPE_SQUARE,       ///< square wave
  N_MBG_GPIO_SIGNAL_SHAPES            ///< number of known signal shapes
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_SIGNAL_SHAPES
 *
 * Used e.g. with ::MBG_GPIO_FREQ_IN_SUPP::supp_shapes,
 * ::MBG_GPIO_FREQ_OUT_SUPP::supp_shapes,
 * and ::MBG_GPIO_FIXED_FREQ_OUT_SUPP::supp_shapes.
 *
 * @see ::MBG_GPIO_SIGNAL_SHAPES
 */
enum MBG_GPIO_SIGNAL_SHAPE_MASKS
{
  MBG_GPIO_SIGNAL_SHAPE_MSK_UNSPECIFIED = ( 1UL << MBG_GPIO_SIGNAL_SHAPE_UNSPECIFIED ),  ///< see ::MBG_GPIO_SIGNAL_SHAPE_UNSPECIFIED
  MBG_GPIO_SIGNAL_SHAPE_MSK_SINE        = ( 1UL << MBG_GPIO_SIGNAL_SHAPE_SINE ),         ///< see ::MBG_GPIO_SIGNAL_SHAPE_SINE
  MBG_GPIO_SIGNAL_SHAPE_MSK_SQUARE      = ( 1UL << MBG_GPIO_SIGNAL_SHAPE_SQUARE )        ///< see ::MBG_GPIO_SIGNAL_SHAPE_SQUARE
};



/**
 * @brief String initializers for GPIO signal shapes
 *
 * @see ::MBG_GPIO_SIGNAL_SHAPES
 */
#define DEFAULT_GPIO_SIGNAL_SHAPE_NAMES \
{                                       \
  "(unspec. shape)",                    \
  "Sine wave",                          \
  "Rectangle Pulse"                     \
}



/**
 * @brief A structure used to specify a variable frequency
 *
 * Used to specify a variable frequency for GPIO input or output
 */
typedef struct
{
  uint32_t hz;      ///< integral number [Hz]
  uint32_t frac;    ///< fractional part, binary (0x80000000 --> 0.5, 0xFFFFFFFF --> 0.9999999...)

} MBG_GPIO_FREQ;

#define _mbg_swab_mbg_gpio_freq( _p ) \
do                                    \
{                                     \
  _mbg_swab32( &(_p)->hz );           \
  _mbg_swab32( &(_p)->frac);          \
} while ( 0 )



/**
 * @brief Configuration of a GPIO variable frequency input
 *
 * Used as sub-structure of ::MBG_GPIO_SETTINGS.
 *
 * @see ::MBG_GPIO_TYPE_FREQ_IN
 * @see ::MBG_GPIO_SETTINGS
 */
typedef struct
{
  MBG_GPIO_FREQ freq;  ///< frequency in range ::MBG_GPIO_FREQ_IN_SUPP::freq_min..::MBG_GPIO_FREQ_IN_SUPP::freq_max, or 0 if input is not used
  uint32_t csc_limit;  ///< max. cycle slip [1/1000 cycle units], see ::MBG_GPIO_FREQ_IN_SUPP::csc_limit_max
  uint32_t shape;      ///< selected signal shape, see ::MBG_GPIO_SIGNAL_SHAPES
  uint32_t reserved;   ///< reserved, currently always 0
  uint32_t flags;      ///< reserved, currently always 0

} MBG_GPIO_FREQ_IN_SETTINGS;

#define _mbg_swab_mbg_gpio_freq_in_settings( _p ) \
do                                                \
{                                                 \
  _mbg_swab_mbg_gpio_freq( &(_p)->freq );         \
  _mbg_swab32( &(_p)->csc_limit );                \
  _mbg_swab32( &(_p)->shape );                    \
  _mbg_swab32( &(_p)->reserved );                 \
  _mbg_swab32( &(_p)->flags );                    \
} while ( 0 )



/**
 * @brief Supported options for a variable frequency GPIO input
 *
 * Used as sub-structure of ::MBG_GPIO_LIMITS.
 *
 * @see ::MBG_GPIO_TYPE_FREQ_IN
 * @see ::MBG_GPIO_LIMITS
 */
typedef struct
{
  uint32_t freq_min;       ///< minimum output frequency [Hz]
  uint32_t freq_max;       ///< maximum output frequency [Hz]
  uint32_t csc_limit_max;  ///< 1/1000 units of the signal period, limited due to 10 ns sampling interval, see ::MBG_GPIO_FREQ_IN_SETTINGS::csc_limit //##++++++++++++++++
  uint32_t supp_shapes;    ///< bit mask of supported signal shapes, see ::MBG_GPIO_SIGNAL_SHAPE_MASKS
  uint32_t supp_limits;    ///< supported ITU limit masks for BITS signal see ::ITU_LIMIT_MASKS
  uint32_t flags;          ///< reserved, currently always 0

} MBG_GPIO_FREQ_IN_SUPP;

#define _mbg_swab_mbg_gpio_freq_in_supp( _p ) \
do                                            \
{                                             \
  _mbg_swab32( &(_p)->freq_min );             \
  _mbg_swab32( &(_p)->freq_max );             \
  _mbg_swab32( &(_p)->csc_limit_max );        \
  _mbg_swab32( &(_p)->supp_shapes );          \
  _mbg_swab32( &(_p)->supp_limits );          \
  _mbg_swab32( &(_p)->flags );                \
} while ( 0 )



/**
 * @brief Configuration of a GPIO variable frequency output
 *
 * Used as sub-structure of ::MBG_GPIO_SETTINGS.
 *
 * @see ::MBG_GPIO_TYPE_FREQ_OUT
 * @see ::MBG_GPIO_SETTINGS
 */
typedef struct
{
  MBG_GPIO_FREQ freq;   ///< frequency, see ::MBG_GPIO_FREQ_OUT_SUPP::freq_min and ::MBG_GPIO_FREQ_OUT_SUPP::freq_max
  int32_t milli_phase;  ///< phase [1/1000 degree units], see ::MBG_GPIO_FREQ_OUT_SUPP::milli_phase_max
  uint32_t shape;       ///< selected signal shape, see ::MBG_GPIO_SIGNAL_SHAPES
  uint32_t reserved;    ///< reserved, currently always 0
  uint32_t flags;       ///< reserved, currently always 0

} MBG_GPIO_FREQ_OUT_SETTINGS;

#define _mbg_swab_mbg_gpio_freq_out_settings( _p )  \
do                                                  \
{                                                   \
  _mbg_swab_mbg_gpio_freq( &(_p)->freq );           \
  _mbg_swab32( &(_p)->milli_phase );                \
  _mbg_swab32( &(_p)->shape );                      \
  _mbg_swab32( &(_p)->reserved );                   \
  _mbg_swab32( &(_p)->flags );                      \
} while ( 0 )



/**
 * @brief Supported options for a variable frequency GPIO output
 *
 * Used as sub-structure of ::MBG_GPIO_LIMITS.
 *
 * @see ::MBG_GPIO_TYPE_FREQ_OUT
 * @see ::MBG_GPIO_LIMITS
 */
typedef struct
{
  uint32_t freq_min;         ///< minimum output frequency [Hz], see ::MBG_GPIO_FREQ_OUT_SETTINGS::freq
  uint32_t freq_max;         ///< maximum output frequency [Hz], see ::MBG_GPIO_FREQ_OUT_SETTINGS::freq
  uint32_t freq_resolution;  ///< frequency resolution [Hz], unspecified if 0
  uint32_t milli_phase_max;  ///< max. abs. milli_phase, see ::MBG_GPIO_FREQ_OUT_SETTINGS::milli_phase
  uint32_t supp_shapes;      ///< bit mask of supported signal shapes, see ::MBG_GPIO_SIGNAL_SHAPE_MASKS
  uint32_t reserved;         ///< reserved, currently always 0
  uint32_t flags;            ///< reserved, currently always 0

} MBG_GPIO_FREQ_OUT_SUPP;

#define _mbg_swab_mbg_gpio_freq_out_supp( _p ) \
do                                             \
{                                              \
  _mbg_swab32( &(_p)->freq_min );              \
  _mbg_swab32( &(_p)->freq_max );              \
  _mbg_swab32( &(_p)->freq_resolution );       \
  _mbg_swab32( &(_p)->milli_phase_max );       \
  _mbg_swab32( &(_p)->supp_shapes );           \
  _mbg_swab32( &(_p)->reserved );              \
  _mbg_swab32( &(_p)->flags );                 \
} while ( 0 )



/**
 * @brief Enumeration of predefined fixed frequencies
 *
 * @see ::MBG_GPIO_FIXED_FREQ_MASKS
 * @see ::MBG_GPIO_FIXED_FREQ_STRS
 */
enum MBG_GPIO_FIXED_FREQS
{
  MBG_GPIO_FIXED_FREQ_8kHz,      ///< 8 kHz
  MBG_GPIO_FIXED_FREQ_48kHz,     ///< 48 kHz
  MBG_GPIO_FIXED_FREQ_1MHz,      ///< 1 MHz
  MBG_GPIO_FIXED_FREQ_1544kHz,   ///< 1.544 MHz
  MBG_GPIO_FIXED_FREQ_2048kHz,   ///< 2.048 MHz
  MBG_GPIO_FIXED_FREQ_5MHz,      ///< 5 MHz
  MBG_GPIO_FIXED_FREQ_10MHz,     ///< 10 MHz
  MBG_GPIO_FIXED_FREQ_19440kHz,  ///< 19.44 MHz
  N_MBG_GPIO_FIXED_FREQ          ///< number of predefined fixed frequencies
};


/**
 * @brief Bit masks associated with ::MBG_GPIO_FIXED_FREQS
 *
 * @see ::MBG_GPIO_FIXED_FREQS
 * @see ::MBG_GPIO_FIXED_FREQ_STRS
 */
enum MBG_GPIO_FIXED_FREQ_MASKS
{
  MSK_MBG_GPIO_FIXED_FREQ_8kHz     = ( 1UL << MBG_GPIO_FIXED_FREQ_8kHz ),     ///< see ::MBG_GPIO_FIXED_FREQ_8kHz
  MSK_MBG_GPIO_FIXED_FREQ_48kHz    = ( 1UL << MBG_GPIO_FIXED_FREQ_48kHz ),    ///< see ::MBG_GPIO_FIXED_FREQ_48kHz
  MSK_MBG_GPIO_FIXED_FREQ_1MHz     = ( 1UL << MBG_GPIO_FIXED_FREQ_1MHz ),     ///< see ::MBG_GPIO_FIXED_FREQ_1MHz
  MSK_MBG_GPIO_FIXED_FREQ_1544kHz  = ( 1UL << MBG_GPIO_FIXED_FREQ_1544kHz ),  ///< see ::MBG_GPIO_FIXED_FREQ_1544kHz
  MSK_MBG_GPIO_FIXED_FREQ_2048kHz  = ( 1UL << MBG_GPIO_FIXED_FREQ_2048kHz ),  ///< see ::MBG_GPIO_FIXED_FREQ_2048kHz
  MSK_MBG_GPIO_FIXED_FREQ_5MHz     = ( 1UL << MBG_GPIO_FIXED_FREQ_5MHz ),     ///< see ::MBG_GPIO_FIXED_FREQ_5MHz
  MSK_MBG_GPIO_FIXED_FREQ_10MHz    = ( 1UL << MBG_GPIO_FIXED_FREQ_10MHz ),    ///< see ::MBG_GPIO_FIXED_FREQ_10MHz
  MSK_MBG_GPIO_FIXED_FREQ_19440kHz = ( 1UL << MBG_GPIO_FIXED_FREQ_19440kHz )  ///< see ::MBG_GPIO_FIXED_FREQ_19440kHz
};


/**
 * @brief Initializers for an array of GPIO fixed frequency name strings
 *
 * @see ::MBG_GPIO_FIXED_FREQS
 * @see ::MBG_GPIO_FIXED_FREQ_MASKS
 */
#define MBG_GPIO_FIXED_FREQ_STRS \
{                                \
  "8 kHz",                       \
  "48 kHz",                      \
  "1 MHz",                       \
  "1544 kHz",                    \
  "2048 kHz",                    \
  "5 MHz",                       \
  "10 MHz",                      \
  "19440 kHz"                    \
}



/**
 * @brief Configuration of a GPIO fixed frequency output
 *
 * Used as sub-structure of ::MBG_GPIO_SETTINGS.
 *
 * @see ::MBG_GPIO_TYPE_FIXED_FREQ_OUT
 * @see ::MBG_GPIO_SETTINGS
 */
typedef struct
{
  uint32_t freq_idx;  ///< fixed frequency index, see ::MBG_GPIO_FIXED_FREQS
  uint32_t shape;     ///< selected signal shape, see ::MBG_GPIO_SIGNAL_SHAPES
  uint32_t reserved;  ///< reserved, currently always 0
  uint32_t flags;     ///< reserved, currently always 0

} MBG_GPIO_FIXED_FREQ_OUT_SETTINGS;

#define _mbg_swab_mbg_gpio_fixed_freq_out_settings( _p ) \
do                                                       \
{                                                        \
  _mbg_swab32( &(_p)->freq_idx );                        \
  _mbg_swab32( &(_p)->shape );                           \
  _mbg_swab32( &(_p)->reserved );                        \
  _mbg_swab32( &(_p)->flags );                           \
} while ( 0 )



/**
 * @brief Supported options for a fixed frequency output
 *
 * Used as sub-structure of ::MBG_GPIO_LIMITS.
 *
 * @see ::MBG_GPIO_TYPE_FIXED_FREQ_OUT
 * @see ::MBG_GPIO_LIMITS
 */
typedef struct
{
  uint32_t supp_freq;    ///< bit mask of supported fixed frequencies, see ::MBG_GPIO_FIXED_FREQ_MASKS
  uint32_t supp_shapes;  ///< bit mask of supported signal shapes, see ::MBG_GPIO_SIGNAL_SHAPE_MASKS
  uint32_t reserved;     ///< reserved, currently always 0
  uint32_t supp_flags;   ///< reserved, currently always 0

} MBG_GPIO_FIXED_FREQ_OUT_SUPP;

#define _mbg_swab_mbg_gpio_fixed_freq_out_supp( _p ) \
do                                                   \
{                                                    \
  _mbg_swab32( &(_p)->supp_freq );                   \
  _mbg_swab32( &(_p)->supp_shapes );                 \
  _mbg_swab32( &(_p)->reserved );                    \
  _mbg_swab32( &(_p)->supp_flags );                  \
} while ( 0 )



/**
 * @brief Enumeration of BITS signal formats
 *
 * Used with ::MBG_GPIO_BITS_IN_SETTINGS::format and ::MBG_GPIO_BITS_OUT_SETTINGS::format
 *
 * @see ::MBG_GPIO_BITS_FORMAT_MASKS
 */
enum MBG_GPIO_BITS_FORMATS
{
  MBG_GPIO_BITS_E1_FRAMED,  ///< 2.048 MBit
  MBG_GPIO_BITS_T1_FRAMED,  ///< 1.544 MBit
  MBG_GPIO_BITS_E1_TIMING,  ///< 2.048 MHz
  MBG_GPIO_BITS_T1_TIMING,  ///< 2.048 MHz
  N_MBG_GPIO_BITS_FORMATS   ///< number of defined formats
};


/**
 * @brief Bit masks associated with ::MBG_GPIO_BITS_FORMATS
 *
 * Used with ::MBG_GPIO_BITS_IN_SUPP::supp_fmts and ::MBG_GPIO_BITS_OUT_SUPP::supp_fmts.
 *
 * @see ::MBG_GPIO_BITS_FORMATS
 */
enum MBG_GPIO_BITS_FORMAT_MASKS
{
  MSK_MBG_GPIO_BITS_E1_FRAMED = ( 1UL << MBG_GPIO_BITS_E1_FRAMED ),  ///< see ::MBG_GPIO_BITS_E1_FRAMED
  MSK_MBG_GPIO_BITS_T1_FRAMED = ( 1UL << MBG_GPIO_BITS_T1_FRAMED ),  ///< see ::MBG_GPIO_BITS_T1_FRAMED
  MSK_MBG_GPIO_BITS_E1_TIMING = ( 1UL << MBG_GPIO_BITS_E1_TIMING ),  ///< see ::MBG_GPIO_BITS_E1_TIMING
  MSK_MBG_GPIO_BITS_T1_TIMING = ( 1UL << MBG_GPIO_BITS_T1_TIMING )   ///< see ::MBG_GPIO_BITS_T1_TIMING
};


/**
 * @brief Initializers for an array of GPIO bit format strings
 *
 * @see ::MBG_GPIO_BITS_FORMATS
 * @see ::MBG_GPIO_BITS_FORMAT_MASKS
 */
#define MBG_GPIO_BITS_FORMAT_STRS   \
{                                   \
  "E1 Framed",                      \
  "T1 Framed",                      \
  "E1 Timing",                      \
  "T1 Timing"                       \
}



/**
 * @brief Minimum and maximum known SSM values
 *
 * Values according to ITU G.704-1998
 *
 * Used with ::MBG_GPIO_BITS_IN_SETTINGS::quality::e1.ssm
 * and ::MBG_GPIO_BITS_OUT_SETTINGS::ssm.
 */
enum GPIO_SSM_VALS
{
  GPIO_SSM_UNKNOWN,    ///< Quality unknown, existing synchronization network
  GPIO_SSM_RSVD_1,     ///< (reserved)
  GPIO_SSM_G_811,      ///< Rec. G.811
  GPIO_SSM_RSVD_3,     ///< (reserved)
  GPIO_SSM_SSU_A,      ///< SSU-A
  GPIO_SSM_RSVD_5,     ///< (reserved)
  GPIO_SSM_RSVD_6,     ///< (reserved)
  GPIO_SSM_RSVD_7,     ///< (reserved)
  GPIO_SSM_SSU_B,      ///< SSU-B
  GPIO_SSM_RSVD_9,     ///< (reserved)
  GPIO_SSM_RSVD_10,    ///< (reserved)
  GPIO_SSM_RSVD_SETS,  ///< Synchronous Equipment Timing Source (SETS)
  GPIO_SSM_RSVD_12,    ///< (reserved)
  GPIO_SSM_RSVD_13,    ///< (reserved)
  GPIO_SSM_RSVD_14,    ///< (reserved)
  GPIO_SSM_DONT_USE,   ///< don't use
  N_GPIO_SSM_VALS
};



/**
 * @brief Minimum and maximum SA BITS groups
 *
 * Used with ::MBG_GPIO_BITS_IN_SETTINGS::quality::e1::sa_bits
 * and ::MBG_GPIO_BITS_OUT_SETTINGS::sa_bits.
 */
enum GPIO_SA_BITS_GROUPS
{
  MIN_SA_BITS_GROUP = 4,
  MAX_SA_BITS_GROUP = 8
};



/**
 * @brief Configuration of a GPIO as BITS input module
 *
 * Used as sub-structure of ::MBG_GPIO_SETTINGS.
 *
 * @see ::MBG_GPIO_TYPE_BITS_IN
 * @see ::MBG_GPIO_SETTINGS
 */
typedef struct
{
  uint32_t format;        ///< signal format, see ::MBG_GPIO_BITS_FORMATS
  uint32_t reserved;      ///< reserved, currently always 0
  uint32_t csc_limit;     ///< max. cycle slip [1/1000 cycle units]

  union quality
  {
    struct e1
    {
      uint8_t  ssm;       ///< minimum E1 SSM for acceptance, 0..::N_GPIO_SSM_VALS-1
      uint8_t  sa_bits;   ///< sa bits group carrying SSM, ::MIN_SA_BITS_GROUP..::MAX_SA_BITS_GROUP
      uint16_t reserved;  ///< reserved, currently always 0
    } e1;                 ///< used with E1 formats

    struct t1
    {
      uint8_t  min_boc;
      uint8_t  reserved_0;  ///< reserved, currently always 0
      uint16_t reserved_1;  ///< reserved, currently always 0
    } t1;                   ///< used with T1 formats

    uint32_t u32;    ///< dummy to force at least 32 bit alignment

  } quality;

  uint32_t err_msk;  ///< controls which types of error can be ignored, see ::MBG_GPIO_BITS_ERR_MASKS
  uint32_t flags;    ///< reserved, currently always 0

} MBG_GPIO_BITS_IN_SETTINGS;

#define _mbg_swab_mbg_gpio_bits_in_settings( _p, _recv )    \
do                                                          \
{                                                           \
  uint32_t f = (_p)->format;                                \
  if ( (_recv) )                                            \
    _mbg_swab32( &f);                                       \
  _mbg_swab32( &(_p)->format );                             \
  _mbg_swab32( &(_p)->reserved );                           \
  _mbg_swab32( &(_p)->csc_limit );                          \
  switch( f )                                               \
  {                                                         \
    case MBG_GPIO_BITS_E1_FRAMED :                          \
    case MBG_GPIO_BITS_E1_TIMING :                          \
      _mbg_swab8( &(_p)->quality.e1.ssm );                  \
      _mbg_swab8( &(_p)->quality.e1.sa_bits );              \
      _mbg_swab16( &(_p)->quality.e1.reserved );            \
      break;                                                \
                                                            \
    case MBG_GPIO_BITS_T1_FRAMED :                          \
    case MBG_GPIO_BITS_T1_TIMING :                          \
      _mbg_swab8( &(_p)->quality.t1.min_boc );              \
      _mbg_swab8( &(_p)->quality.t1.reserved_0 );           \
      _mbg_swab16( &(_p)->quality.t1.reserved_1 );          \
      break;                                                \
                                                            \
    default:                                                \
      break;                                                \
  }                                                         \
  _mbg_swab32( &(_p)->err_msk );                            \
  _mbg_swab32( &(_p)->flags );                              \
} while ( 0 )



/**
 * @brief Enumeration of BITS input error conditions
 */
enum MBG_GPIO_BITS_ERRS
{
  MBG_GPIO_BITS_ERR_LOS,  ///< loss of signal
  MBG_GPIO_BITS_ERR_LOF,  ///< loss of frame
  N_MBG_GPIO_BITS_ERRS    ///< number of known errors
};


/**
 * @brief Bit masks associated with BITS input error conditions
 *
 * Used with ::MBG_GPIO_BITS_IN_SETTINGS::err_msk
 *
 * @see ::MBG_GPIO_BITS_ERRS
 */
enum MBG_GPIO_BITS_ERR_MASKS
{
  MSK_MBG_GPIO_BITS_ERR_LOS = ( 1UL << MBG_GPIO_BITS_ERR_LOS ),  ///< see ::MBG_GPIO_BITS_ERR_LOS
  MSK_MBG_GPIO_BITS_ERR_LOF = ( 1UL << MBG_GPIO_BITS_ERR_LOF )   ///< see ::MBG_GPIO_BITS_ERR_LOF
};



/**
 * @brief Supported options of a BITS GPIO input
 *
 * Used as sub-structure of ::MBG_GPIO_LIMITS.
 *
 * @see ::MBG_GPIO_TYPE_BITS_IN
 * @see ::MBG_GPIO_LIMITS
 */
typedef struct
{
  uint32_t supp_fmts;         ///< bit mask of supported formats, see ::MBG_GPIO_BITS_FORMAT_MASKS
  uint32_t reserved;          ///< reserved, currently always 0

} MBG_GPIO_BITS_IN_SUPP;

#define _mbg_swab_mbg_gpio_bits_in_supp( _p ) \
do                                            \
{                                             \
  _mbg_swab32( &(_p)->supp_fmts );            \
  _mbg_swab32( &(_p)->reserved );             \
} while ( 0 )



/**
 * @brief Configuration of a GPIO as BITS output module
 *
 * Used as sub-structure of ::MBG_GPIO_SETTINGS.
 *
 * @see ::MBG_GPIO_TYPE_BITS_OUT
 * @see ::MBG_GPIO_SETTINGS
 */
typedef struct
{
  uint32_t format;      ///< signal format, see ::MBG_GPIO_BITS_FORMATS
  uint32_t flags;       ///< flags for encoder control etc., see ::MBG_GPIO_BITS_OUT_FLAG_MASKS
  uint8_t  sa_bits;     ///< number of SA bit group for E1 SSM, ::MIN_SA_BITS_GROUP..::MAX_SA_BITS_GROUP
  uint8_t  ssm;         ///< ssm for E1 mode, 0..::N_GPIO_SSM_VALS-1
  uint8_t  boc;         ///< boc for T1 mode, 0..0x1F  //##++++++++++++++
  uint8_t  reserved_0;  ///< reserved, currently always 0
  uint32_t reserved_1;  ///< reserved, currently always 0
  uint32_t reserved_2;  ///< reserved, currently always 0
  uint32_t reserved_3;  ///< reserved, currently always 0

} MBG_GPIO_BITS_OUT_SETTINGS;

#define _mbg_swab_mbg_gpio_bits_out_settings( _p )  \
do                                                  \
{                                                   \
  _mbg_swab32( &(_p)->format );                     \
  _mbg_swab32( &(_p)->flags );                      \
  _mbg_swab8( &(_p)->sa_bits );                     \
  _mbg_swab8( &(_p)->ssm );                         \
  _mbg_swab8( &(_p)->boc );                         \
  _mbg_swab8( &(_p)->reserved_0 );                  \
  _mbg_swab32( &(_p)->reserved_1 );                 \
  _mbg_swab32( &(_p)->reserved_2 );                 \
  _mbg_swab32( &(_p)->reserved_3 );                 \
} while ( 0 )



/**
 * @brief Enumeration of flags used with BITS type GPIO outputs
 *
 * @see ::MBG_GPIO_BITS_OUT_FLAG_MASKS
 * @see ::MBG_GPIO_BITS_OUT_FLAG_STRS
 */
enum MBG_GPIO_BITS_OUT_FLAGS
{
  MBG_GPIO_BITS_OUT_FLAG_HDB3,  ///< enable HDB3 encoding (E1 mode only)
  MBG_GPIO_BITS_OUT_FLAG_B8ZS,  ///< enable B8ZS encoding (T1 mode only)
  N_MBG_GPIO_BITS_OUT_FLAGS     ///< number of known flags
};


/**
 * @brief Bit masks associated with ::MBG_GPIO_BITS_OUT_FLAGS
 *
 * Used with ::MBG_GPIO_BITS_OUT_SETTINGS::flags
 *
 * @see ::MBG_GPIO_BITS_OUT_FLAGS
 * @see ::MBG_GPIO_BITS_OUT_FLAG_STRS
 */
enum MBG_GPIO_BITS_OUT_FLAG_MASKS
{
  MSK_MBG_GPIO_BITS_OUT_FLAG_HDB3 = ( 1UL << MBG_GPIO_BITS_OUT_FLAG_HDB3 ),  ///< see ::MBG_GPIO_BITS_OUT_FLAG_HDB3
  MSK_MBG_GPIO_BITS_OUT_FLAG_B8ZS = ( 1UL << MBG_GPIO_BITS_OUT_FLAG_B8ZS )   ///< see ::MBG_GPIO_BITS_OUT_FLAG_B8ZS
};


/**
 * @brief String initializers for an array of GPIO BITS out flags
 *
 * @see ::MBG_GPIO_BITS_OUT_FLAGS
 * @see ::MBG_GPIO_BITS_OUT_FLAG_MASKS
 */
#define MBG_GPIO_BITS_OUT_FLAG_STRS \
{                                   \
  "HDB3",                           \
  "B8ZS"                            \
}


/**
 * @brief Supported options of a BITS type GPIO output
 *
 * Used as sub-structure of ::MBG_GPIO_LIMITS.
 *
 * @see ::MBG_GPIO_TYPE_BITS_OUT
 * @see ::MBG_GPIO_LIMITS
 */
typedef struct
{
  uint32_t supp_fmts;   ///< bit mask of supported formats, see ::MBG_GPIO_BITS_FORMAT_MASKS
  uint32_t supp_flags;  ///< bit mask of supported flags, see ::MBG_GPIO_BITS_OUT_FLAG_MASKS

} MBG_GPIO_BITS_OUT_SUPP;

#define _mbg_swab_mbg_gpio_bits_out_supp( _p ) \
do                                             \
{                                              \
  _mbg_swab32( &(_p)->supp_fmts );             \
  _mbg_swab32( &(_p)->supp_flags );            \
} while ( 0 )



/**
 * @brief Enumeration of Video signal formats
 *
 * Used with ::MBG_GPIO_VIDEO_OUT_SETTINGS::format
 *
 * @see ::MBG_GPIO_VIDEO_FORMAT_MASKS
 */
enum MBG_GPIO_VIDEO_FORMATS
{
  MBG_GPIO_VIDEO_FORMAT_OFF,                  ///< OFF
  MBG_GPIO_VIDEO_SD_FORMAT_NTSC,              ///< NTSC 525i
  MBG_GPIO_VIDEO_SD_FORMAT_PAL,               ///< PAL standard (Germany) 625i
  MBG_GPIO_VIDEO_HD_FORMAT_720_P_50Hz,        ///< SMPTE296M-3   720p at 50    Hz
  MBG_GPIO_VIDEO_HD_FORMAT_1080_I_50Hz,       ///< SMPTE274M-6  1080i at 50    Hz
  MBG_GPIO_VIDEO_HD_FORMAT_720_P_59_94Hz,     ///< SMPTE296M-1   720p at 59.94 Hz
  MBG_GPIO_VIDEO_HD_FORMAT_1080_I_59_94Hz,    ///< SMPTE274M-7  1080i at 59.94 Hz
  MBG_GPIO_VIDEO_SD_FORMAT_PAL_M,             ///< PAL M (Brazil) 525i
  N_MBG_GPIO_VIDEO_FORMATS                    ///< number of defined video formats
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_VIDEO_FORMATS
 *
 * Used with ::MBG_GPIO_VIDEO_OUT_SUPP::supp_formats
 *
 * @see ::MBG_GPIO_VIDEO_FORMATS
 */
enum MBG_GPIO_VIDEO_FORMAT_MASKS
{
  MSK_MBG_GPIO_VIDEO_FORMAT_OFF               = ( 1UL << MBG_GPIO_VIDEO_FORMAT_OFF               ),  ///< see ::MBG_GPIO_VIDEO_FORMAT_OFF
  MSK_MBG_GPIO_VIDEO_SD_FORMAT_NTSC           = ( 1UL << MBG_GPIO_VIDEO_SD_FORMAT_NTSC           ),  ///< see ::MBG_GPIO_VIDEO_SD_FORMAT_NTSC
  MSK_MBG_GPIO_VIDEO_SD_FORMAT_PAL            = ( 1UL << MBG_GPIO_VIDEO_SD_FORMAT_PAL            ),  ///< see ::MBG_GPIO_VIDEO_SD_FORMAT_PAL
  MSK_MBG_GPIO_VIDEO_HD_FORMAT_720_P_50Hz     = ( 1UL << MBG_GPIO_VIDEO_HD_FORMAT_720_P_50Hz     ),  ///< see ::MBG_GPIO_VIDEO_HD_FORMAT_720_P_50Hz
  MSK_MBG_GPIO_VIDEO_HD_FORMAT_1080_I_50Hz    = ( 1UL << MBG_GPIO_VIDEO_HD_FORMAT_1080_I_50Hz    ),  ///< see ::MBG_GPIO_VIDEO_HD_FORMAT_1080_I_50Hz
  MSK_MBG_GPIO_VIDEO_HD_FORMAT_720_P_59_94Hz  = ( 1UL << MBG_GPIO_VIDEO_HD_FORMAT_720_P_59_94Hz  ),  ///< see ::MBG_GPIO_VIDEO_HD_FORMAT_720_P_59_94Hz
  MSK_MBG_GPIO_VIDEO_HD_FORMAT_1080_I_59_94Hz = ( 1UL << MBG_GPIO_VIDEO_HD_FORMAT_1080_I_59_94Hz ),  ///< see ::MBG_GPIO_VIDEO_HD_FORMAT_1080_I_59_94Hz
  MSK_MBG_GPIO_VIDEO_SD_FORMAT_PAL_M          = ( 1UL << MBG_GPIO_VIDEO_SD_FORMAT_PAL_M          )   ///< see ::MBG_GPIO_VIDEO_SD_FORMAT_PAL_M
};


/**
 * @brief A combination of bit masks for SD video formats
 * @see ::MBG_GPIO_VIDEO_FORMAT_MASKS
 */
#define MBG_GPIO_VIDEO_SD_FORMATS  ( MSK_MBG_GPIO_VIDEO_FORMAT_OFF | MSK_MBG_GPIO_VIDEO_SD_FORMAT_NTSC | MSK_MBG_GPIO_VIDEO_SD_FORMAT_PAL | \
                                     MSK_MBG_GPIO_VIDEO_SD_FORMAT_PAL_M )

/**
 * @brief A combination of bit masks for HD video formats
 * @see ::MBG_GPIO_VIDEO_FORMAT_MASKS
 */
#define MBG_GPIO_VIDEO_HD_FORMATS  ( MSK_MBG_GPIO_VIDEO_FORMAT_OFF | MSK_MBG_GPIO_VIDEO_HD_FORMAT_720_P_50Hz | MSK_MBG_GPIO_VIDEO_HD_FORMAT_1080_I_50Hz | \
                                     MSK_MBG_GPIO_VIDEO_HD_FORMAT_720_P_59_94Hz | MSK_MBG_GPIO_VIDEO_HD_FORMAT_1080_I_59_94Hz )



/**
 * @brief Initializers for an array of video output name strings
 *
 * @see ::MBG_GPIO_VIDEO_FORMATS
 * @see ::MBG_GPIO_VIDEO_FORMAT_MASKS
 */
#define MBG_GPIO_VIDEO_OUT_STRS     \
{                                   \
  "OFF",                            \
  "NTSC (525i)",                    \
  "PAL (625i)",                     \
  "720p 50 Hz",                     \
  "1080i 50 Hz",                    \
  "720p 59.94 Hz",                  \
  "1080i 59.94 Hz",                 \
  "PAL M (525i)"                    \
}



/**
 * @brief Enumeration of flags used with video type GPIO outputs
 */
enum MBG_GPIO_VIDEO_OUT_FLAGS
{
  MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF,    ///< if set, Out1: HD, Out2: SD
  MBG_GPIO_VIDEO_OUT_HAS_TC_SD,           ///< supports Time Code for SD Black Bursts
  N_MBG_GPIO_VIDEO_OUT_FLAGS              ///< number of known flags
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_VIDEO_OUT_FLAGS
 *
 * Used with ::MBG_GPIO_VIDEO_OUT_SETTINGS::flags
 *
 * @see ::MBG_GPIO_VIDEO_OUT_FLAGS
 */
enum MBG_GPIO_VIDEO_OUT_FLAG_MASKS
{
  MSK_MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF = ( 1UL << MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF ),   ///< see ::MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF
  MSK_MBG_GPIO_VIDEO_OUT_HAS_TC_SD        = ( 1UL << MBG_GPIO_VIDEO_OUT_HAS_TC_SD )           ///< see ::MBG_GPIO_VIDEO_OUT_HAS_TC_SD
};



/**
 * @brief Enumeration of epochs used with video type GPIO outputs
 *
 * Used with ::MBG_GPIO_VIDEO_OUT_SETTINGS::epoch, and used to
 * define ::MBG_GPIO_VIDEO_EPOCH_MASKS
 *
 * @see ::MBG_GPIO_VIDEO_EPOCH_MASKS
 * @see ::MBG_GPIO_VIDEO_EPOCH_STRS
 */
enum MBG_GPIO_VIDEO_EPOCHS
{
  SMPTE_TAI_EPOCH_1970,                 ///< 1970-01-01 00:00:00
  SMPTE_TAI_EPOCH_1958,                 ///< 1958-01-01 00:00:00
  SMPTE_UTC_EPOCH_1972,                 ///< 1972-01-01 00:00:00
  SMPTE_GPS_EPOCH_1980,                 ///< 1980-01-06 00:00:00
  N_MBG_GPIO_VIDEO_EPOCHS               ///< number of known epochs
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_VIDEO_EPOCHS
 *
 * Used with :: MBG_GPIO_VIDEO_OUT_SUPP::supp_epochs
 *
 * @see ::MBG_GPIO_VIDEO_EPOCHS
 */
enum MBG_GPIO_VIDEO_EPOCH_MASKS
{
  MSK_SMPTE_TAI_EPOCH_1970 = ( 1UL << SMPTE_TAI_EPOCH_1970 ),   ///< see ::SMPTE_TAI_EPOCH_1970
  MSK_SMPTE_TAI_EPOCH_1958 = ( 1UL << SMPTE_TAI_EPOCH_1958 ),   ///< see ::SMPTE_TAI_EPOCH_1958
  MSK_SMPTE_UTC_EPOCH_1972 = ( 1UL << SMPTE_UTC_EPOCH_1972 ),   ///< see ::SMPTE_UTC_EPOCH_1972
  MSK_SMPTE_GPS_EPOCH_1980 = ( 1UL << SMPTE_GPS_EPOCH_1980 )    ///< see ::SMPTE_GPS_EPOCH_1980
};



/**
 * @brief Initializers for an array of video epoch strings
 *
 * @see ::MBG_GPIO_VIDEO_EPOCHS
 */
#define MBG_GPIO_VIDEO_EPOCH_STRS     \
{                                     \
  "TAI D1970-01-01 T00:00:00",        \
  "TAI D1958-01-01 T00:00:00",        \
  "UTC D1972-01-01 T00:00:00",        \
  "GPS D1980-01-06 T00:00:00"         \
}



/**
 * @brief Enumeration of time code modes used with video type GPIO outputs
 *
 * Used with ::MBG_GPIO_VIDEO_OUT_SETTINGS::tc_mode
 *
 */
enum MBG_GPIO_VIDEO_TC_MODES
{
  MBG_GPIO_VIDEO_TC_MODE_NONE,          ///< None
  MBG_GPIO_VIDEO_TC_MODE_VITC,          ///< Vertical Interval Time Code
  N_MBG_GPIO_VIDEO_TC_MODES
};


/**
 * @brief Bit masks associated with ::MBG_GPIO_VIDEO_TC_MODES
 *
 * Used with ::MBG_GPIO_VIDEO_OUT_SETTINGS::tc_mode
 *
 */
enum MBG_GPIO_VIDEO_TC_MODE_MASKS
{
  MSK_MBG_GPIO_VIDEO_TC_MODE_NONE = ( 1UL << MBG_GPIO_VIDEO_TC_MODE_NONE ),       ///< see ::MBG_GPIO_VIDEO_TC_MODE_NONE
  MSK_MBG_GPIO_VIDEO_TC_MODE_VITC = ( 1UL << MBG_GPIO_VIDEO_TC_MODE_VITC )        ///< see ::MBG_GPIO_VIDEO_TC_MODE_VITC
};


/**
 * @brief Initializers for an array of video time code modes
 *
 * @see ::MBG_GPIO_VIDEO_TC_MODES
 */
#define MBG_GPIO_VIDEO_TC_MODE_STRS \
{                                   \
  "None",                           \
  "VITC"                            \
}



/**
 * @brief Configuration of a GPIO as video output module
 *
 * Used as sub-structure of ::MBG_GPIO_SETTINGS.
 *
 * @see ::MBG_GPIO_TYPE_VIDEO_OUT
 * @see ::MBG_GPIO_SETTINGS
 */
typedef struct
{
  uint32_t format;                      ///< video format, see ::MBG_GPIO_VIDEO_FORMATS
  uint32_t flags;                       ///< flags, see ::MBG_GPIO_VIDEO_OUT_FLAG_MASKS
  int32_t  phase_offset;                ///< Phase offset in [ns]
  uint8_t  epoch;                       ///< epoch, see ::MBG_GPIO_VIDEO_EPOCHS

  uint8_t  tc_mode;                     ///< time code mode, see ::MBG_GPIO_VIDEO_TC_MODES
  uint8_t  tc_line0;                    ///< first time code line location, valid lines: 6-22
  uint8_t  tc_line1;                    ///< second time code line location, valid lines: 6-22

  uint32_t reserved0;                   ///< reserved, currently always 0
  uint32_t reserved1;                   ///< reserved, currently always 0

} MBG_GPIO_VIDEO_OUT_SETTINGS;

#define _mbg_swab_mbg_gpio_video_out_settings( _p ) \
do                                                  \
{                                                   \
  _mbg_swab32( &(_p)->format );                     \
  _mbg_swab32( &(_p)->flags );                      \
  _mbg_swab32( &(_p)->phase_offset );               \
  _mbg_swab8( &(_p)->epoch );                       \
  _mbg_swab8( &(_p)->tc_mode );                     \
  _mbg_swab8( &(_p)->tc_line0 );                    \
  _mbg_swab8( &(_p)->tc_line1 );                    \
  _mbg_swab32( &(_p)->reserved0 );                  \
  _mbg_swab32( &(_p)->reserved1 );                  \
} while ( 0 )



/**
 * @brief Supported options of a video type GPIO output
 *
 * Used as sub-structure of ::MBG_GPIO_LIMITS.
 *
 * @see ::MBG_GPIO_TYPE_VIDEO_OUT
 * @see ::MBG_GPIO_LIMITS
 */
typedef struct
{
  uint32_t supp_formats;                ///< supported video formats, see ::MBG_GPIO_VIDEO_FORMAT_MASKS
  uint32_t supp_flags;                  ///< supported flags, see ::MBG_GPIO_VIDEO_OUT_FLAG_MASKS
  uint32_t supp_epochs;                 ///< supported epochs, see ::MBG_GPIO_VIDEO_EPOCH_MASKS

  uint8_t supp_tc_modes;                ///< supported tc_modes, see ::MBG_GPIO_VIDEO_TC_MODE_MASKS

  uint8_t reserved0;                    ///< reserved, currently always 0
  uint8_t reserved2;                    ///< reserved, currently always 0
  uint16_t reserved3;                   ///< reserved, currently always 0
  uint32_t reserved1;                   ///< reserved, currently always 0

} MBG_GPIO_VIDEO_OUT_SUPP;

#define _mbg_swab_mbg_gpio_video_out_supp( _p ) \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->supp_formats );           \
  _mbg_swab32( &(_p)->supp_flags );             \
  _mbg_swab32( &(_p)->supp_epochs );            \
  _mbg_swab8( &(_p)->supp_tc_modes );           \
  _mbg_swab8( &(_p)->reserved0 );               \
  _mbg_swab16( &(_p)->reserved2 );              \
  _mbg_swab16( &(_p)->reserved3 );              \
  _mbg_swab32( &(_p)->reserved1 );              \
} while ( 0 )



/**
 * @brief Enumeration of types used with video sync GPIO outputs
 * Depends on configured video output
 */
enum MBG_GPIO_VIDEO_SYNC_TYPES
{
  MBG_GPIO_VIDEO_SYNC_TYPE_OFF,               ///< Output Off
  MBG_GPIO_VIDEO_SYNC_TYPE_SD_HSYNC,          ///< SD horizontal sync
  MBG_GPIO_VIDEO_SYNC_TYPE_SD_VSYNC,          ///< SD vertical sync
  MBG_GPIO_VIDEO_SYNC_TYPE_SD_FRAME,          ///< SD frame/field sync
  MBG_GPIO_VIDEO_SYNC_TYPE_SD_BLANK,          ///< SD blanking interval
  MBG_GPIO_VIDEO_SYNC_TYPE_HD_HSYNC,          ///< HD horizontal sync
  MBG_GPIO_VIDEO_SYNC_TYPE_HD_VSYNC,          ///< HD vertical sync
  MBG_GPIO_VIDEO_SYNC_TYPE_HD_FRAME,          ///< HD frame/field sync
  MBG_GPIO_VIDEO_SYNC_TYPE_HD_BLANK,          ///< HD blanking interval
  N_MBG_GPIO_VIDEO_SYNC_TYPES                 ///< number of known types
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_VIDEO_SYNC_TYPES
 *
 * Used with ::MBG_GPIO_VIDEO_SYNC_OUT_SUPP::supp_types
 *
 * @see ::MBG_GPIO_VIDEO_SYNC_TYPES
 */
enum MBG_GPIO_VIDEO_SYNC_TYPE_MASKS
{
  MSK_MBG_GPIO_VIDEO_SYNC_TYPE_OFF       = ( 1UL << MBG_GPIO_VIDEO_SYNC_TYPE_OFF      ),
  MSK_MBG_GPIO_VIDEO_SYNC_TYPE_SD_HSYNC  = ( 1UL << MBG_GPIO_VIDEO_SYNC_TYPE_SD_HSYNC ),
  MSK_MBG_GPIO_VIDEO_SYNC_TYPE_SD_VSYNC  = ( 1UL << MBG_GPIO_VIDEO_SYNC_TYPE_SD_VSYNC ),
  MSK_MBG_GPIO_VIDEO_SYNC_TYPE_SD_FRAME  = ( 1UL << MBG_GPIO_VIDEO_SYNC_TYPE_SD_FRAME ),
  MSK_MBG_GPIO_VIDEO_SYNC_TYPE_SD_BLANK  = ( 1UL << MBG_GPIO_VIDEO_SYNC_TYPE_SD_BLANK ),
  MSK_MBG_GPIO_VIDEO_SYNC_TYPE_HD_HSYNC  = ( 1UL << MBG_GPIO_VIDEO_SYNC_TYPE_HD_HSYNC ),
  MSK_MBG_GPIO_VIDEO_SYNC_TYPE_HD_VSYNC  = ( 1UL << MBG_GPIO_VIDEO_SYNC_TYPE_HD_VSYNC ),
  MSK_MBG_GPIO_VIDEO_SYNC_TYPE_HD_FRAME  = ( 1UL << MBG_GPIO_VIDEO_SYNC_TYPE_HD_FRAME ),
  MSK_MBG_GPIO_VIDEO_SYNC_TYPE_HD_BLANK  = ( 1UL << MBG_GPIO_VIDEO_SYNC_TYPE_HD_BLANK )
};



/**
 * @brief Initializers for an array of video sync output name strings
 *
 * @see ::MBG_GPIO_VIDEO_SYNC_TYPES
 * @see ::MBG_GPIO_VIDEO_SYNC_TYPE_MASKS
 */
#define MBG_GPIO_VIDEO_SYNC_OUT_STRS  \
{                                     \
  "OFF",                              \
  "SD H-Sync",                        \
  "SD V-Sync",                        \
  "SD Frame",                         \
  "SD Blank",                         \
  "HD H-Sync",                        \
  "HD V-Sync",                        \
  "HD Frame",                         \
  "HD Blank"                          \
}



/**
 * @brief A combination of bit masks for SD video sync types
 * @see ::MBG_GPIO_VIDEO_SYNC_TYPE_MASKS
 */
#define MBG_GPIO_VIDEO_SYNC_SD_TYPES     ( MSK_MBG_GPIO_VIDEO_SYNC_TYPE_OFF      | MSK_MBG_GPIO_VIDEO_SYNC_TYPE_SD_HSYNC | MSK_MBG_GPIO_VIDEO_SYNC_TYPE_SD_VSYNC | \
                                           MSK_MBG_GPIO_VIDEO_SYNC_TYPE_SD_FRAME | MSK_MBG_GPIO_VIDEO_SYNC_TYPE_SD_BLANK )

/**
 * @brief A combination of bit masks for HD video sync types
 * @see ::MBG_GPIO_VIDEO_SYNC_TYPE_MASKS
 */
#define MBG_GPIO_VIDEO_SYNC_HD_TYPES     ( MSK_MBG_GPIO_VIDEO_SYNC_TYPE_OFF      | MSK_MBG_GPIO_VIDEO_SYNC_TYPE_HD_HSYNC | MSK_MBG_GPIO_VIDEO_SYNC_TYPE_HD_VSYNC | \
                                           MSK_MBG_GPIO_VIDEO_SYNC_TYPE_HD_FRAME | MSK_MBG_GPIO_VIDEO_SYNC_TYPE_HD_BLANK )



/**
 * @brief Configuration of a GPIO as sync output module
 *
 * Used as sub-structure of ::MBG_GPIO_SETTINGS.
 *
 * @see ::MBG_GPIO_TYPE_VIDEO_SYNC_OUT
 * @see ::MBG_GPIO_SETTINGS
 */
typedef struct
{
  uint32_t type;       ///< sync type, see :: MBG_GPIO_SYNC_TYPES
  uint32_t flags;      ///< flags, currently always 0
  uint32_t reserved0;  ///< reserved, currently always 0
  uint32_t reserved1;  ///< reserved, currently always 0
  uint32_t reserved2;  ///< reserved, currently always 0
  uint32_t reserved3;  ///< reserved, currently always 0

} MBG_GPIO_VIDEO_SYNC_OUT_SETTINGS;

#define _mbg_swab_mbg_gpio_video_sync_out_settings( _p ) \
do                                                       \
{                                                        \
  _mbg_swab32( &(_p)->type );                            \
  _mbg_swab32( &(_p)->flags );                           \
  _mbg_swab32( &(_p)->reserved0 );                       \
  _mbg_swab32( &(_p)->reserved1 );                       \
  _mbg_swab32( &(_p)->reserved2 );                       \
  _mbg_swab32( &(_p)->reserved3 );                       \
} while ( 0 )



/**
 * @brief Supported options of a sync type GPIO output
 *
 * Used as sub-structure of ::MBG_GPIO_LIMITS.
 *
 * @see ::MBG_GPIO_TYPE_VIDEO_SYNC_OUT
 * @see ::MBG_GPIO_LIMITS
 */
typedef struct
{
  uint32_t supp_types;  ///< supported types, see ::MBG_GPIO_VIDEO_SYNC_TYPE_MASKS
  uint32_t supp_flags;  ///< supported flags, currently always 0
  uint32_t reserved0;   ///< reserved, currently always 0
  uint32_t reserved1;   ///< reserved, currently always 0

} MBG_GPIO_VIDEO_SYNC_OUT_SUPP;

#define _mbg_swab_mbg_gpio_video_sync_out_supp( _p ) \
do                                                   \
{                                                    \
  _mbg_swab32( &(_p)->supp_types );                  \
  _mbg_swab32( &(_p)->supp_flags );                  \
  _mbg_swab32( &(_p)->reserved0 );                   \
  _mbg_swab32( &(_p)->reserved1 );                   \
} while ( 0 )



/**
 * @brief Enumeration of studio clock base frequencies
 *
 * Used with ::MBG_GPIO_STUDIO_CLOCK_OUT_SETTINGS::base_freq
 *
 * @see ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_MASKS
 */
enum MBG_GPIO_STUDIO_CLOCK_BASE_FREQS
{
  MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_32KHZ,        ///< 32 kHz base frequency
  MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_44_1KHZ,      ///< 44.1 kHz base frequency
  MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_48KHZ,        ///< 48 kHz base frequency
  N_MBG_GPIO_STUDIO_CLOCK_BASE_FREQS            ///< number of defined base frequencies
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQS
 *
 * Used with ::MBG_GPIO_STUDIO_CLOCK_OUT_SUPP::supp_base_freqs
 *
 * @see ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQS
 */
enum MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_MASKS
{
  MSK_MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_32KHZ   = ( 1UL << MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_32KHZ   ),   ///< see ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_32KHZ
  MSK_MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_44_1KHZ = ( 1UL << MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_44_1KHZ ),   ///< see ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_44_1KHZ
  MSK_MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_48KHZ   = ( 1UL << MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_48KHZ   )    ///< see ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_48KHZ
};



/**
 * @brief Initializers for an array of base frequencies of studio clock output name strings
 *
 * @see ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQS
 * @see ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_MASKS
 */
#define MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_STRS  \
{                                             \
  "32 kHz",                                   \
  "44.1 kHz",                                 \
  "48 kHz"                                    \
}



/**
 * @brief Enumeration of studio clock scales
 *
 * Used with ::MBG_GPIO_STUDIO_CLOCK_OUT_SETTINGS::scale
 * Multiply scale with base frequency
 *
 * @see ::MBG_GPIO_STUDIO_CLOCK_SCALE_MASKS
 */
enum MBG_GPIO_STUDIO_CLOCK_SCALES
{
  MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_32,
  MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_16,
  MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_8,
  MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_4,
  MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_2,
  MBG_GPIO_STUDIO_CLOCK_SCALE_1,
  MBG_GPIO_STUDIO_CLOCK_SCALE_2,
  MBG_GPIO_STUDIO_CLOCK_SCALE_4,
  MBG_GPIO_STUDIO_CLOCK_SCALE_8,
  MBG_GPIO_STUDIO_CLOCK_SCALE_16,
  MBG_GPIO_STUDIO_CLOCK_SCALE_32,
  MBG_GPIO_STUDIO_CLOCK_SCALE_64,
  MBG_GPIO_STUDIO_CLOCK_SCALE_128,
  MBG_GPIO_STUDIO_CLOCK_SCALE_256,
  MBG_GPIO_STUDIO_CLOCK_SCALE_512,
  N_MBG_GPIO_STUDIO_CLOCK_SCALES              ///< number of defined scales
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_STUDIO_CLOCK_SCALES
 *
 * Used with ::MBG_GPIO_STUDIO_CLOCK_OUT_SUPP::supp_scales[N_MBG_GPIO_STUDIO_CLOCK_BASE_FREQS]
 *
 * @see ::MBG_GPIO_STUDIO_CLOCK_SCALES
 */
enum MBG_GPIO_STUDIO_CLOCK_SCALE_MASKS
{
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_32   = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_32 ),   ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_32
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_16   = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_16 ),   ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_16
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_8    = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_8 ),    ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_8
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_4    = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_4 ),    ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_4
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_2    = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_2 ),    ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_1_DIV_2
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_1          = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_1 ),          ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_1
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_2          = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_2 ),          ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_2
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_4          = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_4 ),          ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_4
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_8          = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_8 ),          ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_8
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_16         = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_16 ),         ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_16
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_32         = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_32 ),         ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_32
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_64         = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_64 ),         ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_64
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_128        = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_128 ),        ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_128
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_256        = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_256 ),        ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_256
  MSK_MBG_GPIO_STUDIO_CLOCK_SCALE_512        = ( 1U << MBG_GPIO_STUDIO_CLOCK_SCALE_512 )         ///< see ::MBG_GPIO_STUDIO_CLOCK_SCALE_512
};



/**
 * @brief Initializers for an array of scales of studio clock output name strings
 *
 * @see ::MBG_GPIO_STUDIO_CLOCK_SCALES
 * @see ::MBG_GPIO_STUDIO_CLOCK_SCALE_MASKS
 */
#define MBG_GPIO_STUDIO_CLOCK_SCALE_STRS  \
{                                         \
  "1/32",                                 \
  "1/16",                                 \
  "1/8",                                  \
  "1/4",                                  \
  "1/2",                                  \
  "1",                                    \
  "2",                                    \
  "4",                                    \
  "8",                                    \
  "16",                                   \
  "32",                                   \
  "64",                                   \
  "128",                                  \
  "256",                                  \
  "512"                                   \
}



/**
 * @brief Enumeration of flags used with studio clock type GPIO outputs
 */
enum MBG_GPIO_STUDIO_CLOCK_FLAGS
{
  MBG_GPIO_STUDIO_CLOCK_OUTPUT_ENABLED,     ///< if set, enables output
  N_MBG_GPIO_STUDIO_CLOCK_FLAGS             ///< number of known flags
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_STUDIO_CLOCK_FLAGS
 *
 * Used with ::MBG_GPIO_STUDIO_CLOCK_OUT_SETTINGS::flags
 *
 * @see ::MBG_GPIO_STUDIO_CLOCK_FLAGS
 */
enum MBG_GPIO_STUDIO_CLOCK_FLAG_MASKS
{
  MSK_MBG_GPIO_STUDIO_CLOCK_OUTPUT_ENABLED = ( 1UL << MBG_GPIO_STUDIO_CLOCK_OUTPUT_ENABLED )   ///< see ::MBG_GPIO_STUDIO_CLOCK_OUTPUT_ENABLED
};



/**
 * @brief Configuration of a GPIO as studio clock output module
 *
 * Used as sub-structure of ::MBG_GPIO_SETTINGS.
 *
 * @see ::MBG_GPIO_TYPE_STUDIO_CLOCK_OUT
 * @see ::MBG_GPIO_SETTINGS
 */
typedef struct
{
  uint32_t base_freq;                   ///< base frequency, see ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQS
  uint32_t scale;                       ///< scale, see ::MBG_GPIO_STUDIO_CLOCK_SCALES
  uint32_t flags;                       ///< flags, see ::MBG_GPIO_STUDIO_CLOCK_FLAGS
  uint32_t reserved0;                   ///< reserved, currently always 0
  uint32_t reserved1;                   ///< reserved, currently always 0

} MBG_GPIO_STUDIO_CLOCK_OUT_SETTINGS;

#define _mbg_swab_mbg_gpio_studio_clock_out_settings( _p ) \
do                                                         \
{                                                          \
  _mbg_swab32( &(_p)->base_freq );                         \
  _mbg_swab32( &(_p)->scale );                             \
  _mbg_swab32( &(_p)->flags );                             \
  _mbg_swab32( &(_p)->reserved0 );                         \
  _mbg_swab32( &(_p)->reserved1 );                         \
} while ( 0 )



#define MAX_SUPP_BASE_FREQUENCIES    8  ///< max. supported base frequencies for studio clock outputs

/**
 * @brief Configuration of a GPIO as studio clock output module
 *
 * Used as sub-structure of ::MBG_GPIO_LIMITS.
 *
 * @see ::MBG_GPIO_TYPE_STUDIO_CLOCK_OUT
 * @see ::MBG_GPIO_LIMITS
 */
typedef struct
{
  uint8_t  supp_base_freqs;                          ///< supported base frequencies, see ::MBG_GPIO_STUDIO_CLOCK_BASE_FREQ_MASKS
  uint8_t  reserved0;                                ///< reserved, currently always 0
  uint16_t reserved1;                                ///< reserved, currently always 0
  uint16_t supp_scales[MAX_SUPP_BASE_FREQUENCIES];   ///< supported scales for each base frequency, see ::MBG_GPIO_STUDIO_CLOCK_SCALE_MASKS
  uint32_t supp_flags;                               ///< supported flags, see::MBG_GPIO_STUDIO_CLOCK_FLAG_MASKS
  uint32_t reserved2;                                ///< reserved, currently always 0

} MBG_GPIO_STUDIO_CLOCK_OUT_SUPP;

#define _mbg_swab_mbg_gpio_studio_clock_out_supp( _p )    \
do                                                        \
{                                                         \
  uint8_t idx;                                            \
  _mbg_swab8( &(_p)->supp_base_freqs );                   \
  _mbg_swab8( &(_p)->reserved0 );                         \
  _mbg_swab16( &(_p)->reserved1 );                        \
  for( idx = 0; idx < MAX_SUPP_BASE_FREQUENCIES; idx++ )  \
    _mbg_swab16( &(_p)->supp_scales[idx] );               \
  _mbg_swab32( &(_p)->supp_flags );                       \
  _mbg_swab32( &(_p)->reserved2 );                        \
} while ( 0 )



/**
 * @brief Enumeration of types used with GPIO type digital audio outputs
 *
 * Used with ::MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT_SETTINGS::type, and used to
 * define ::MBG_GPIO_DIGITAL_AUDIO_TYPE_MASKS
 *
 * @see ::MBG_GPIO_DIGITAL_AUDIO_TYPE_MASKS
 * @see ::MBG_GPIO_DIGITAL_AUDIO_TYPE_STRS
 */
enum MBG_GPIO_DIGITAL_AUDIO_TYPES
{
  MBG_GPIO_DIGITAL_AUDIO_TYPE_OFF,
  MBG_GPIO_DIGITAL_AUDIO_TYPE_DARS, ///< DARS
  N_MBG_GPIO_DIGITAL_AUDIO_TYPES    ///< number of known types
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_DIGITAL_AUDIO_TYPES
 *
 * Used with :: MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT_SUPP::supp_types
 *
 * @see ::MBG_GPIO_DIGITAL_AUDIO_TYPES
 */
enum MBG_GPIO_DIGITAL_AUDIO_TYPE_MASKS
{
  MSK_MBG_GPIO_DIGITAL_AUDIO_TYPE_OFF  = ( 1UL << MBG_GPIO_DIGITAL_AUDIO_TYPE_OFF ),   ///< see ::MBG_GPIO_DIGITAL_AUDIO_TYPE_OFF
  MSK_MBG_GPIO_DIGITAL_AUDIO_TYPE_DARS = ( 1UL << MBG_GPIO_DIGITAL_AUDIO_TYPE_DARS )  ///< see ::MBG_GPIO_DIGITAL_AUDIO_TYPE_DARS
};



/**
 * @brief Initializers for an array of video epoch strings
 *
 * @see ::MBG_GPIO_VIDEO_EPOCHS
 */
#define MBG_GPIO_DIGITAL_AUDIO_TYPE_STRS  \
{                                         \
  "OFF",                                  \
  "DARS"                                  \
}



/**
 * @brief Enumeration of flags used with GPIO type digital audio outputs
 */
enum MBG_GPIO_DIGITAL_AUDIO_FLAGS
{
  MBG_GPIO_DIGITAL_AUDIO_RESERVED_FLAG,     ///< reserved
  N_MBG_GPIO_DIGITAL_AUDIO_FLAGS            ///< number of known flags
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_DIGITAL_AUDIO_FLAGS
 *
 * Used with ::MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT_SETTINGS::flags
 *
 * @see ::MBG_GPIO_DIGITAL_AUDIO_FLAGS
 */
enum MBG_GPIO_DIGITAL_AUDIO_FLAG_MASKS
{
  MSK_MBG_GPIO_DIGITAL_AUDIO_RESERVED_FLAG = ( 1UL << MBG_GPIO_DIGITAL_AUDIO_RESERVED_FLAG )   ///< see ::MBG_GPIO_DIGITAL_AUDIO_RESERVED_FLAG
};



/**
 * @brief Configuration of a GPIO digital audio output
 *
 * Used as sub-structure of ::MBG_GPIO_SETTINGS.
 *
 * @see ::MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT
 * @see ::MBG_GPIO_SETTINGS
 */
typedef struct
{
  uint32_t type;        ///< digital audio type, see ::MBG_GPIO_DIGITAL_AUDIO_TYPES
  uint32_t flags;       ///< reserved, currently always 0
  uint32_t reserved0;   ///< reserved, currently always 0
  uint32_t reserved1;   ///< reserved, currently always 0
  uint32_t reserved2;   ///< reserved, currently always 0

} MBG_GPIO_DIGITAL_AUDIO_OUT_SETTINGS;

#define _mbg_swab_mbg_gpio_digital_audio_out_settings( _p ) \
do                                                          \
{                                                           \
  _mbg_swab32( &(_p)->type );                               \
  _mbg_swab32( &(_p)->flags );                              \
  _mbg_swab32( &(_p)->reserved0 );                          \
  _mbg_swab32( &(_p)->reserved1 );                          \
  _mbg_swab32( &(_p)->reserved2 );                          \
} while ( 0 )



/**
 * @brief Supported options for digital audio output
 *
 * Used as sub-structure of ::MBG_GPIO_LIMITS.
 *
 * @see ::MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT
 * @see ::MBG_GPIO_LIMITS
 */
typedef struct
{
  uint32_t supp_types;  ///< supported digital audio types, see ::MBG_GPIO_DIGITAL_AUDIO_TYPE_MASKS
  uint32_t supp_flags;  ///< reserved, currently always 0
  uint32_t reserved0;   ///< reserved, currently always 0
  uint32_t reserved1;   ///< reserved, currently always 0
  uint32_t reserved2;   ///< reserved, currently always 0

} MBG_GPIO_DIGITAL_AUDIO_OUT_SUPP;

#define _mbg_swab_mbg_gpio_digital_audio_out_supp( _p ) \
do                                                      \
{                                                       \
  _mbg_swab32( &(_p)->supp_types );                     \
  _mbg_swab32( &(_p)->supp_flags );                     \
  _mbg_swab32( &(_p)->reserved0 );                      \
  _mbg_swab32( &(_p)->reserved1 );                      \
  _mbg_swab32( &(_p)->reserved2 );                      \
} while ( 0 )



/**
 * @brief Enumeration of general flags used with a GPIO
 *
 * @see ::MBG_GPIO_FLAG_MASKS
 */
enum MBG_GPIO_FLAGS
{
  MBG_GPIO_DEPENDS_ON_ASS_IO_IDX,  ///< indicates that this output depends on GPIO with ::MBG_GPIO_SETTINGS::ass_io_idx and may not be configured independently
  N_MBG_GPIO_FLAGS                 ///< number of known flags
};



/**
 * @brief Bit masks associated with ::MBG_GPIO_FLAGS
 *
 * Used with ::MBG_GPIO_LIMITS::flags and ::MBG_GPIO_SETTINGS::flags
 *
 * @see ::MBG_GPIO_FLAGS
 */
enum MBG_GPIO_FLAG_MASKS
{
  MSK_MBG_GPIO_DEPENDS_ON_ASS_IO_IDX =    ( 1UL << MBG_GPIO_DEPENDS_ON_ASS_IO_IDX )     ///< see ::MBG_GPIO_DEPENDS_ON_ASS_IO_IDX
};



/**
 * @brief A generic structure used to hold a GPIO port's settings
 */
typedef struct
{
  uint32_t type;        ///< GPIO type, see ::MBG_GPIO_TYPES

  uint16_t reserved_1;  ///< reserved, currently always 0
  uint8_t reserved_2;   ///< reserved, currently always 0
  uint8_t ass_io_idx;   ///< associated GPIO index, only valid if ::MSK_MBG_GPIO_DEPENDS_ON_ASS_IO_IDX is set in flags field

  uint32_t flags;       ///< flags, see ::MBG_GPIO_FLAG_MASKS

  /// settings depending on the GPIO type, see ::MBG_GPIO_TYPES
  union
  {
    MBG_GPIO_FREQ_IN_SETTINGS freq_in;                      ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_FREQ_IN
    MBG_GPIO_FREQ_OUT_SETTINGS freq_out;                    ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_FREQ_OUT
    MBG_GPIO_FIXED_FREQ_OUT_SETTINGS ff_out;                ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_FIXED_FREQ_OUT
    MBG_GPIO_BITS_IN_SETTINGS bits_in;                      ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_BITS_IN
    MBG_GPIO_BITS_OUT_SETTINGS bits_out;                    ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_BITS_OUT
    MBG_GPIO_VIDEO_OUT_SETTINGS video_out;                  ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_VIDEO_OUT
    MBG_GPIO_VIDEO_SYNC_OUT_SETTINGS video_sync_out;        ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_VIDEO_SYNC_OUT
    MBG_GPIO_STUDIO_CLOCK_OUT_SETTINGS studio_clk_out;      ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_STUDIO_CLOCK_OUT
    MBG_GPIO_DIGITAL_AUDIO_OUT_SETTINGS digital_audio_out;  ///< if ::MBG_GPIO_SETTINGS::type is ::;MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT
  } u;

} MBG_GPIO_SETTINGS;

#define _mbg_swab_mbg_gpio_settings( _p, _recv )                                                                                \
do                                                                                                                              \
{                                                                                                                               \
  uint32_t t = (_p)->type;                                                                                                      \
  if ( (_recv) )                                                                                                                \
    _mbg_swab32( &t );                                                                                                          \
  _mbg_swab32( &(_p)->type );                                                                                                   \
  _mbg_swab16( &(_p)->reserved_1 );                                                                                             \
  _mbg_swab8( &(_p)->reserved_2 );                                                                                              \
  _mbg_swab8( &(_p)->ass_io_idx );                                                                                              \
  _mbg_swab32( &(_p)->flags );                                                                                                  \
  switch( t )                                                                                                                   \
  {                                                                                                                             \
    case MBG_GPIO_TYPE_FREQ_IN           : _mbg_swab_mbg_gpio_freq_in_settings( &(_p)->u.freq_in );                     break;  \
    case MBG_GPIO_TYPE_FREQ_OUT          : _mbg_swab_mbg_gpio_freq_out_settings( &(_p)->u.freq_out );                   break;  \
    case MBG_GPIO_TYPE_FIXED_FREQ_OUT    : _mbg_swab_mbg_gpio_fixed_freq_out_settings( &(_p)->u.ff_out );               break;  \
    case MBG_GPIO_TYPE_BITS_IN           : _mbg_swab_mbg_gpio_bits_in_settings( &(_p)->u.bits_in, (_recv) );            break;  \
    case MBG_GPIO_TYPE_BITS_OUT          : _mbg_swab_mbg_gpio_bits_out_settings( &(_p)->u.bits_out );                   break;  \
    case MBG_GPIO_TYPE_VIDEO_OUT         : _mbg_swab_mbg_gpio_video_out_settings( &(_p)->u.video_out );                 break;  \
    case MBG_GPIO_TYPE_VIDEO_SYNC_OUT    : _mbg_swab_mbg_gpio_video_sync_out_settings( &(_p)->u.video_sync_out );       break;  \
    case MBG_GPIO_TYPE_STUDIO_CLOCK_OUT  : _mbg_swab_mbg_gpio_studio_clock_out_settings( &(_p)->u.studio_clk_out );     break;  \
    case MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT : _mbg_swab_mbg_gpio_digital_audio_out_settings( &(_p)->u.digital_audio_out ); break;  \
    default : break;                                                                                                            \
  }                                                                                                                             \
} while ( 0 )



/**
 * @brief A GPIO port's current settings, plus port index
 */
typedef struct
{
  uint32_t idx;                ///< port index, 0..::MBG_GPIO_CFG_LIMITS::num_io-1
  MBG_GPIO_SETTINGS settings;  ///< current settings

} MBG_GPIO_SETTINGS_IDX;

#define _mbg_swab_mbg_gpio_settings_idx( _p, _recv )        \
do                                                          \
{                                                           \
  _mbg_swab32( &(_p)->idx );                                \
  _mbg_swab_mbg_gpio_settings( &(_p)->settings, (_recv ) ); \
} while ( 0 )



/**
 * @brief A generic structure used to specify a GPIO port's limits
 */
typedef struct
{
  uint32_t type;        ///< GPIO type, see ::MBG_GPIO_TYPES
  uint32_t reserved;    ///< reserved, currently always 0
  uint32_t supp_flags;  ///< supported flags, see ::MBG_GPIO_FLAG_MASKS

  /// limits depending on the GPIO type, see ::MBG_GPIO_TYPES
  union
  {
    MBG_GPIO_FREQ_IN_SUPP freq_in;                      ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_FREQ_IN
    MBG_GPIO_FREQ_OUT_SUPP freq_out;                    ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_FREQ_OUT
    MBG_GPIO_FIXED_FREQ_OUT_SUPP ff_out;                ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_FIXED_FREQ_OUT
    MBG_GPIO_BITS_IN_SUPP bits_in;                      ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_BITS_IN
    MBG_GPIO_BITS_OUT_SUPP bits_out;                    ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_BITS_OUT
    MBG_GPIO_VIDEO_OUT_SUPP video_out;                  ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_VIDEO_OUT
    MBG_GPIO_VIDEO_SYNC_OUT_SUPP video_sync_out;        ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_VIDEO_SYNC_OUT
    MBG_GPIO_STUDIO_CLOCK_OUT_SUPP studio_clk_out;      ///< if ::MBG_GPIO_SETTINGS::type is ::MBG_GPIO_TYPE_STUDIO_CLOCK_OUT
    MBG_GPIO_DIGITAL_AUDIO_OUT_SUPP digital_audio_out;  ///< if ::MBG_GPIO_SETTINGS::type is ::;MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT
  } u;

} MBG_GPIO_LIMITS;

#define _mbg_swab_mbg_gpio_limits( _p, _recv )                                                                              \
do                                                                                                                          \
{                                                                                                                           \
  uint32_t t = (_p)->type;                                                                                                  \
  if ( (_recv) )                                                                                                            \
    _mbg_swab32( &t );                                                                                                      \
  _mbg_swab32( &(_p)->type );                                                                                               \
  _mbg_swab32( &(_p)->reserved );                                                                                           \
  _mbg_swab32( &(_p)->supp_flags );                                                                                         \
  switch( t )                                                                                                               \
  {                                                                                                                         \
    case MBG_GPIO_TYPE_FREQ_IN           : _mbg_swab_mbg_gpio_freq_in_supp( &(_p)->u.freq_in );                     break;  \
    case MBG_GPIO_TYPE_FREQ_OUT          : _mbg_swab_mbg_gpio_freq_out_supp( &(_p)->u.freq_out );                   break;  \
    case MBG_GPIO_TYPE_FIXED_FREQ_OUT    : _mbg_swab_mbg_gpio_fixed_freq_out_supp( &(_p)->u.ff_out );               break;  \
    case MBG_GPIO_TYPE_BITS_IN           : _mbg_swab_mbg_gpio_bits_in_supp( &(_p)->u.bits_in );                     break;  \
    case MBG_GPIO_TYPE_BITS_OUT          : _mbg_swab_mbg_gpio_bits_out_supp( &(_p)->u.bits_out );                   break;  \
    case MBG_GPIO_TYPE_VIDEO_OUT         : _mbg_swab_mbg_gpio_video_out_supp( &(_p)->u.video_out );                 break;  \
    case MBG_GPIO_TYPE_VIDEO_SYNC_OUT    : _mbg_swab_mbg_gpio_video_sync_out_supp( &(_p)->u.video_sync_out );       break;  \
    case MBG_GPIO_TYPE_STUDIO_CLOCK_OUT  : _mbg_swab_mbg_gpio_studio_clock_out_supp( &(_p)->u.studio_clk_out );     break;  \
    case MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT : _mbg_swab_mbg_gpio_digital_audio_out_supp( &(_p)->u.digital_audio_out ); break;  \
    default : break;                                                                                                        \
  }                                                                                                                         \
} while ( 0 )



/**
 * @brief A GPIO port's current settings and limits
 */
typedef struct
{
  MBG_GPIO_SETTINGS settings;  ///< current settings
  MBG_GPIO_LIMITS limits;      ///< limits of this GPIO port

} MBG_GPIO_INFO;


#define _mbg_swab_mbg_gpio_info( _p, _recv )                \
do                                                          \
{                                                           \
  _mbg_swab_mbg_gpio_settings( &(_p)->settings, (_recv) );  \
  _mbg_swab_mbg_gpio_limits( &(_p)->limits, (_recv) );      \
} while ( 0 )


/**
 * @brief A GPIO port's current settings and limits, plus port index
 */
typedef struct
{
  uint32_t idx;        ///< port index, 0..::MBG_GPIO_CFG_LIMITS::num_io-1
  MBG_GPIO_INFO info;  ///< limits and current settings of this GPIO port

} MBG_GPIO_INFO_IDX;

#define _mbg_swab_mbg_gpio_info_idx( _p, _recv )    \
do                                                  \
{                                                   \
  _mbg_swab32( &(_p)->idx );                        \
  _mbg_swab_mbg_gpio_info( &(_p)->info, (_recv) );  \
} while ( 0 )



/**
 * @brief Status information on a single GPIO port
 */
typedef struct
{
  uint8_t port_state;   ///< see ::MBG_GPIO_PORT_STATES
  uint8_t reserved_0;   ///< reserved, currently unused and always 0
  uint16_t reserved_1;  ///< reserved, currently unused and always 0
  uint32_t reserved_2;  ///< reserved, currently unused and always 0
  uint32_t reserved_3;  ///< reserved, currently unused and always 0

} MBG_GPIO_STATUS;

#define _mbg_swab_mbg_gpio_status( _p ) \
do                                      \
{                                       \
  _mbg_swab8( &(_p)->port_state );      \
  _mbg_swab8( &(_p)->reserved_0 );      \
  _mbg_swab16( &(_p)->reserved_1 );     \
  _mbg_swab32( &(_p)->reserved_2 );     \
  _mbg_swab32( &(_p)->reserved_3 );     \
} while ( 0 )



/**
 * @brief Status information on a specific GPIO port
 */
typedef struct
{
  uint16_t idx;            ///< port index, 0..::MBG_GPIO_CFG_LIMITS::num_io-1
  MBG_GPIO_STATUS status;  ///< status information

} MBG_GPIO_STATUS_IDX;

#define _mbg_swab_mbg_gpio_status_idx( _p )   \
do                                            \
{                                             \
  _mbg_swab16( &(_p)->idx );                  \
  _mbg_swab_mbg_gpio_status( &(_p)->status ); \
} while ( 0 )



/**
 * @brief GPIO port states
 *
 * Used with ::MBG_GPIO_STATUS::port_state
 *
 * @see ::DEFAULT_GPIO_PORT_STATE_NAMES
 */
enum MBG_GPIO_PORT_STATES
{
  MBG_GPIO_PORT_UNUSED,       ///< configured as unused input
  MBG_GPIO_PORT_OUTPUT_ENBD,  ///< configured output signal enabled
  MBG_GPIO_INPUT_SIG_AVAIL,   ///< input signal is available
  N_MBG_GPIO_PORT_STATES      ///< number of known port states
};



/**
 * @brief String initializers for GPIO port state names
 *
 * @see ::MBG_GPIO_PORT_STATES
 */
#define DEFAULT_GPIO_PORT_STATE_NAMES \
{                                     \
  "unused",                           \
  "output enabled",                   \
  "input signal available"            \
}


/** @} defgroup group_gpio */



/**
 * @defgroup group_havequick HaveQuick definitions
 *
 * @note This is only supported if the ::GPS_HAS_HAVEQUICK bit is set
 * in the ::RECEIVER_INFO::features mask.
 *
 * @{ */


/**
 * @brief Enumeration of HaveQuick formats
 *
 * @see ::HAVEQUICK_SETTINGS::format
 * @see ::HAVEQUICK_FORMAT_MASKS
 */
enum HAVEQUICK_FORMATS
{
  HQ_FMT_STANAG4246_1,
  HQ_FMT_STANAG4246_2,
  HQ_FMT_STANAG4246_PTTI,
  HQ_FMT_STANAG4372_SATURN_1,
  HQ_FMT_STANAG4372_SATURN_2,
  HQ_FMT_STANAG4430_EXTD,
  N_HQ_FMT                     ///< number of known formats
};


/**
 * @brief Bit masks associated with the enumerated HaveQuick formats
 *
 * @see ::HAVEQUICK_INFO::supp_formats
 * @see ::HAVEQUICK_FORMATS
 */
enum HAVEQUICK_FORMAT_MASKS
{
  HQ_MSK_STANAG4246_1         = ( 1UL << HQ_FMT_STANAG4246_1 ),         ///< see ::HQ_FMT_STANAG4246_1
  HQ_MSK_STANAG4246_2         = ( 1UL << HQ_FMT_STANAG4246_2 ),         ///< see ::HQ_FMT_STANAG4246_2
  HQ_MSK_STANAG4246_PTTI      = ( 1UL << HQ_FMT_STANAG4246_PTTI ),      ///< see ::HQ_FMT_STANAG4246_PTTI
  HQ_MSK_STANAG4372_SATURN_1  = ( 1UL << HQ_FMT_STANAG4372_SATURN_1 ),  ///< see ::HQ_FMT_STANAG4372_SATURN_1
  HQ_MSK_STANAG4372_SATURN_2  = ( 1UL << HQ_FMT_STANAG4372_SATURN_2 ),  ///< see ::HQ_FMT_STANAG4372_SATURN_2
  HQ_MSK_STANAG4430_EXTD      = ( 1UL << HQ_FMT_STANAG4430_EXTD )       ///< see ::HQ_FMT_STANAG4430_EXTD
};

/*
 * String initializers for each Havequick format
 */
#define HQ_FMT_NAME_STANAG4246_1          "STANAG4246 1"
#define HQ_FMT_NAME_STANAG4246_2          "STANAG4246 2"
#define HQ_FMT_NAME_STANAG4246_PTTI       "STANAG4246 PTTI"
#define HQ_FMT_NAME_STANAG4372_SATURN_1   "STANAG4372 SATURN 1"
#define HQ_FMT_NAME_STANAG4372_SATURN_2   "STANAG4372 SATURN 2"
#define HQ_FMT_NAME_STANAG4430_EXTD       "STANAG4430 EXTD"

#define HQ_FMT_SHRT_NAME_STANAG4246_1          "STG4246 1"
#define HQ_FMT_SHRT_NAME_STANAG4246_2          "STG4246 2"
#define HQ_FMT_SHRT_NAME_STANAG4246_PTTI       "STG4246 PTTI"
#define HQ_FMT_SHRT_NAME_STANAG4372_SATURN_1   "STG4372 SATURN1"
#define HQ_FMT_SHRT_NAME_STANAG4372_SATURN_2   "STG4372 SATURN2"
#define HQ_FMT_SHRT_NAME_STANAG4430_EXTD       "STG4430 EXTD"

/*
 * The definition below can be used to initialize
 * an array of ::N_HQ_FMT name strings.
 */
#define DEFAULT_HQ_FMT_NAMES          \
{                                     \
  HQ_FMT_NAME_STANAG4246_1,           \
  HQ_FMT_NAME_STANAG4246_2,           \
  HQ_FMT_NAME_STANAG4246_PTTI,        \
  HQ_FMT_NAME_STANAG4372_SATURN_1,    \
  HQ_FMT_NAME_STANAG4372_SATURN_2,    \
  HQ_FMT_NAME_STANAG4430_EXTD         \
}

#define DEFAULT_HQ_SHRT_FMT_NAMES          \
{                                          \
  HQ_FMT_SHRT_NAME_STANAG4246_1,           \
  HQ_FMT_SHRT_NAME_STANAG4246_2,           \
  HQ_FMT_SHRT_NAME_STANAG4246_PTTI,        \
  HQ_FMT_SHRT_NAME_STANAG4372_SATURN_1,    \
  HQ_FMT_SHRT_NAME_STANAG4372_SATURN_2,    \
  HQ_FMT_SHRT_NAME_STANAG4430_EXTD         \
}



/**
 * @brief Configuration settings for a HaveQuick input or output
 */
typedef struct
{
  uint16_t format;          ///< see ::HAVEQUICK_FORMATS
  uint16_t flags;           ///< see ::HAVEQUICK_FLAG_MASKS
  int32_t  offset;          ///< Tx: unused, Rx: offset of incoming time in [s]
  uint32_t reserved_0;      ///< reserved, currently always 0
  uint32_t reserved_1;      ///< reserved, currently always 0

} HAVEQUICK_SETTINGS;

#define _mbg_swab_havequick_settings( _p )   \
do                                           \
{                                            \
  _mbg_swab16( &(_p)->format );              \
  _mbg_swab16( &(_p)->flags );               \
  _mbg_swab32( &(_p)->offset );              \
  _mbg_swab32( &(_p)->reserved_0 );          \
  _mbg_swab32( &(_p)->reserved_1 );          \
} while ( 0 )

/**
 * @brief Current settings and capabilities of a HaveQuick input or output
 */
typedef struct
{
  HAVEQUICK_SETTINGS settings;  ///< current settings
  uint32_t supp_formats;        ///< see ::HAVEQUICK_FORMAT_MASKS
  uint16_t supp_flags;          ///< mask of flags supported in settings, see ::HAVEQUICK_FLAG_MASKS
  uint16_t reserved;            ///< reserved, currently always 0

} HAVEQUICK_INFO;

#define _mbg_swab_havequick_info( _p )               \
do                                                   \
{                                                    \
  _mbg_swab_havequick_settings( &(_p)->settings );   \
  _mbg_swab32( &(_p)->supp_formats );                \
  _mbg_swab16( &(_p)->supp_flags );                  \
  _mbg_swab16( &(_p)->reserved );                    \
} while ( 0 )


/**
 * @brief Known HaveQuick control flags
 *
 * @see ::HAVEQUICK_FLAG_MASKS
 */
enum HAVEQUICK_FLAG_BITS
{
  HQ_FLAG_TX_GEN_LOCAL_TIME,
  HQ_FLAG_SIGNAL_INVERTED,
  HQ_FLAG_USE_EXT_PPS,
  N_HQ_FLAG_BITS
};


/**
 * @brief Bit masks associated with HaveQuick control flags
 *
 * @see ::HAVEQUICK_SETTINGS::flags
 * @see ::HAVEQUICK_INFO::supp_flags
 * @see ::HAVEQUICK_FLAG_BITS
 */
enum HAVEQUICK_FLAG_MASKS
{
  HQ_MSK_TX_GEN_LOCAL_TIME = ( 1UL << HQ_FLAG_TX_GEN_LOCAL_TIME ), ///< see ::HQ_FLAG_TX_GEN_LOCAL_TIME
  HQ_MSK_SIGNAL_INVERTED   = ( 1UL << HQ_FLAG_SIGNAL_INVERTED ),   ///< see ::HQ_FLAG_SIGNAL_INVERTED
  HQ_MSK_USE_EXT_PPS       = ( 1UL << HQ_FLAG_USE_EXT_PPS )        ///< see ::HQ_FLAG_USE_EXT_PPS
};

/** @} defgroup group_havequick */



/**
 * @defgroup group_evt_log Event logging support
 *
 * @note This is only available if ::GPS_HAS_EVT_LOG is set in ::RECEIVER_INFO::features.
 *
 * @{ */

/**
 * @brief Number of event log entries that can be stored and yet have been saved
 */
typedef struct
{
  uint32_t used;     ///< current number of saved log entries
  uint32_t max;      ///< max number of log entries which can be saved

} MBG_NUM_EVT_LOG_ENTRIES;

#define _mbg_swab_mbg_num_evt_log_entries( _p ) \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->used );                   \
  _mbg_swab32( &(_p)->max );                    \
} while ( 0 )


typedef uint16_t MBG_EVT_CODE;
#define _mbg_swab_evt_code( _p ) _mbg_swab16( _p )

typedef uint16_t MBG_EVT_INFO;
#define _mbg_swab_evt_info( _p ) _mbg_swab16( _p )

/**
 * @brief An event log entry
 */
typedef struct
{
  uint32_t time;       ///< like time_t, seconds since 1970
  MBG_EVT_CODE code;   ///< event ID or'ed with severity level, see @ref MBG_EVENT_CODES
  MBG_EVT_INFO info;   ///< optional event info, depending on event ID

} MBG_EVT_LOG_ENTRY;

#define _mbg_swab_mbg_evt_log_entry( _p ) \
do                                        \
{                                         \
  _mbg_swab32( &(_p)->time );             \
  _mbg_swab_evt_code( &(_p)->code );      \
  _mbg_swab_evt_info( &(_p)->info );      \
} while ( 0 )


// ::MBG_EVT_LOG_ENTRY::code is a combination of some bits used for the ID,
// plus some bits used for the severity/level. The sum of bits must not
// exceed (8 * sizeof ::MBG_EVT_LOG_ENTRY::code):

#define MBG_EVT_ID_BITS      13
#define MBG_EVT_LVL_BITS     3

#define MBG_EVT_ID_MASK      ( (MBG_EVT_CODE) ( 1UL << MBG_EVT_ID_BITS ) - 1 )
#define MBG_EVT_LVL_MASK     ( (MBG_EVT_CODE) ( 1UL << MBG_EVT_LVL_BITS ) - 1 )


// Combine an ID and Level to a code which can be stored
// in the code field:
#define _mbg_mk_evt_code( _id, _lvl ) \
  ( (MBG_EVT_CODE) ( (MBG_EVT_CODE)(_id) | ( (MBG_EVT_CODE)(_lvl) << MBG_EVT_ID_BITS ) ) )

// Extract the event ID from the code field:
#define _mbg_get_evt_id( _code ) \
  ( (_code) & MBG_EVT_ID_MASK )

// Extract the severity level from the code field:
#define _mbg_get_evt_lvl( _code ) \
  ( ( (_code) >> MBG_EVT_ID_BITS ) & MBG_EVT_LVL_MASK )


/**
 * @brief Enumeration of event IDs
 *
 * @see @ref MBG_EVENT_CODES
 * @see @ref MBG_EVT_ID_BITS
 * @see @ref MBG_EVT_LVL_BITS
 */
enum MBG_EVT_IDS
{
  MBG_EVT_ID_NONE,          ///< no event (empty entry)
  MBG_EVT_ID_POW_UP_RES,    ///< power up reset
  MBG_EVT_ID_WDOG_RES,      ///< watchdog reset
  MBG_EVT_ID_COLD_BOOT,     ///< entering cold boot mode
  MBG_EVT_ID_WARM_BOOT,     ///< entering warm boot mode
  MBG_EVT_ID_NORMAL_OP,     ///< entering normal operation
  MBG_EVT_ID_ANT_DISCONN,   ///< antenna disconnect detected
  MBG_EVT_ID_ANT_SHORT,     ///< antenna short circuit detected
  MBG_EVT_ID_ANT_OK,        ///< antenna OK after failure
  MBG_EVT_ID_LOW_SATS,      ///< no satellites can be received though antenna not failing
  N_MBG_EVT_ID
};


#define ENG_EVT_ID_NAME_NONE          "No event"
#define ENG_EVT_ID_NAME_POW_UP_RES    "Power Up Reset"
#define ENG_EVT_ID_NAME_WDOG_RES      "Watchdog Reset"
#define ENG_EVT_ID_NAME_COLD_BOOT     "Cold Boot"
#define ENG_EVT_ID_NAME_WARM_BOOT     "Warm Boot"
#define ENG_EVT_ID_NAME_NORMAL_OP     "Normal Operation"
#define ENG_EVT_ID_NAME_ANT_DISCONN   "Antenna Disconn."
#define ENG_EVT_ID_NAME_ANT_SHORT     "Ant. Short-Circ."
#define ENG_EVT_ID_NAME_ANT_OK        "Antenna OK"
#define ENG_EVT_ID_NAME_LOW_SATS      "Few Sats Only"


#define MBG_EVT_ID_NAMES_ENG    \
{                               \
  ENG_EVT_ID_NAME_NONE,         \
  ENG_EVT_ID_NAME_POW_UP_RES,   \
  ENG_EVT_ID_NAME_WDOG_RES,     \
  ENG_EVT_ID_NAME_COLD_BOOT,    \
  ENG_EVT_ID_NAME_WARM_BOOT,    \
  ENG_EVT_ID_NAME_NORMAL_OP,    \
  ENG_EVT_ID_NAME_ANT_DISCONN,  \
  ENG_EVT_ID_NAME_ANT_SHORT,    \
  ENG_EVT_ID_NAME_ANT_OK,       \
  ENG_EVT_ID_NAME_LOW_SATS      \
}



/**
 * @brief Enumeration of event severity levels
 *
 * @see @ref MBG_EVENT_CODES
 * @see @ref MBG_EVT_ID_BITS
 * @see @ref MBG_EVT_LVL_BITS
 */
enum MBG_EVT_LVLS
{
  MBG_EVT_LVL_NONE,
  MBG_EVT_LVL_DEBUG,
  MBG_EVT_LVL_INFO,
  MBG_EVT_LVL_WARN,
  MBG_EVT_LVL_ERR,
  MBG_EVT_LVL_CRIT,
  N_MBG_EVT_LVL
};


#define ENG_EVT_LVL_NAME_NONE    "None"
#define ENG_EVT_LVL_NAME_DEBUG   "Debug"
#define ENG_EVT_LVL_NAME_INFO    "Info"
#define ENG_EVT_LVL_NAME_WARN    "Warn"
#define ENG_EVT_LVL_NAME_ERR     "Err"
#define ENG_EVT_LVL_NAME_CRIT    "Crit."


#define MBG_EVT_LVL_NAMES_ENG \
{                             \
  ENG_EVT_LVL_NAME_NONE,      \
  ENG_EVT_LVL_NAME_DEBUG,     \
  ENG_EVT_LVL_NAME_INFO,      \
  ENG_EVT_LVL_NAME_WARN,      \
  ENG_EVT_LVL_NAME_ERR,       \
  ENG_EVT_LVL_NAME_CRIT       \
}


/**
 * @brief Predefined event codes with associated severity levels
 *
 * @see ::MBG_EVT_IDS
 * @see ::MBG_EVT_LVLS
 *
 * @anchor MBG_EVENT_CODES @{ */

#define MBG_EVT_NONE         _mbg_mk_evt_code( MBG_EVT_ID_NONE, MBG_EVT_LVL_NONE )
#define MBG_EVT_POW_UP_RES   _mbg_mk_evt_code( MBG_EVT_ID_POW_UP_RES, MBG_EVT_LVL_WARN )
#define MBG_EVT_WDOG_RES     _mbg_mk_evt_code( MBG_EVT_ID_WDOG_RES, MBG_EVT_LVL_CRIT )
#define MBG_EVT_COLD_BOOT    _mbg_mk_evt_code( MBG_EVT_ID_COLD_BOOT, MBG_EVT_LVL_ERR )
#define MBG_EVT_WARM_BOOT    _mbg_mk_evt_code( MBG_EVT_ID_WARM_BOOT, MBG_EVT_LVL_ERR )
#define MBG_EVT_NORMAL_OP    _mbg_mk_evt_code( MBG_EVT_ID_NORMAL_OP, MBG_EVT_LVL_INFO )
#define MBG_EVT_ANT_DISCONN  _mbg_mk_evt_code( MBG_EVT_ID_ANT_DISCONN, MBG_EVT_LVL_CRIT )
#define MBG_EVT_ANT_SHORT    _mbg_mk_evt_code( MBG_EVT_ID_ANT_SHORT, MBG_EVT_LVL_CRIT )
#define MBG_EVT_ANT_OK       _mbg_mk_evt_code( MBG_EVT_ID_ANT_OK, MBG_EVT_LVL_INFO )
#define MBG_EVT_LOW_SATS     _mbg_mk_evt_code( MBG_EVT_ID_LOW_SATS, MBG_EVT_LVL_WARN )

/** @} anchor MBG_EVENT_CODES */

/** @} defgroup group_evt_log */



/**
 * @defgroup group_ims IMS support
 *
 * @note This is only supported if ::GPS_HAS_IMS is set in ::RECEIVER_INFO::features.
 *
 * @{ */

/**
 * @brief Generic state of an IMS device
 */
typedef struct
{
  uint8_t chassis_id;    ///< chassis ID, 0 if installed on the backplane
  uint8_t slot_id;       ///< slot number on the chassis
  uint16_t num_sensors;  ///< number of sensors provided by the device
  uint32_t reserved;     ///< reserved, currently always 0
  uint32_t flags;        ///< see ::MBG_IMS_STATE_FLAG_MASKS

} MBG_IMS_STATE;

#define _mbg_swab_mbg_ims_state( _p ) \
do                                    \
{                                     \
  _mbg_swab16( &(_p)->num_sensors );  \
  _mbg_swab32( &(_p)->reserved );     \
  _mbg_swab32( &(_p)->flags );        \
} while ( 0 )



/**
 * @brief Enumeration of bits used to define ::MBG_IMS_STATE_FLAG_MASKS
 *
 * @see ::MBG_IMS_STATE_FLAG_MASKS
 */
enum MBG_IMS_STATE_FLAG_BITS
{
  MBG_IMS_STATE_FLAG_BIT_HAS_FDM,   ///< device supports FDM API
  N_MBG_IMS_STATE_FLAG_BITS
};


/**
 * @brief Bit masks used with ::MBG_IMS_STATE::flags
 *
 * @see ::MBG_IMS_STATE_FLAG_BITS
 */
enum MBG_IMS_STATE_FLAG_MASKS
{
  MBG_IMS_STATE_FLAG_MSK_HAS_FDM = ( 1UL << MBG_IMS_STATE_FLAG_BIT_HAS_FDM )    ///< see ::MBG_IMS_STATE_FLAG_BIT_HAS_FDM
};



/**
 * @brief Generic state of an IMS sensor
 */
typedef struct
{
  uint16_t type;       ///< sensor type, see ::MBG_IMS_SENSORS
  uint16_t idx;        ///< index of the sensor of this type
  int32_t val;         ///< sensor value, in units according to the type
  int16_t exp;         ///< 10s exponent of the sensor value
  uint16_t reserved;   ///< currently unused, always 0
  uint32_t flags;      ///< currently unused, always 0

} MBG_IMS_SENSOR_STATE;

#define _mbg_swab_mbg_ims_sensor_state( _p ) \
do                                           \
{                                            \
  _mbg_swab16( &(_p)->type );                \
  _mbg_swab16( &(_p)->idx );                 \
  _mbg_swab32( &(_p)->val );                 \
  _mbg_swab16( &(_p)->exp );                 \
  _mbg_swab16( &(_p)->reserved );            \
  _mbg_swab32( &(_p)->flags );               \
} while ( 0 )


/**
 * @brief Generic state of an IMS sensor, with sensor index
 */
typedef struct
{
  uint32_t idx;                ///< sensor index, 0..::MBG_IMS_STATE::num_sensors-1
  MBG_IMS_SENSOR_STATE state;  ///< sensor state

} MBG_IMS_SENSOR_STATE_IDX;

#define _mbg_swab_mbg_ims_sensor_state_idx( _p )  \
do                                                \
{                                                 \
  _mbg_swab32( &(_p)->idx );                      \
  _mbg_swab_mbg_ims_sensor_state( &(_p)->state ); \
} while ( 0 )



/**
 * @brief IMS sensor types
 *
 * Used with ::MBG_IMS_SENSOR_STATE::type
 */
enum MBG_IMS_SENSORS
{
  MBG_IMS_SENSOR_TEMP_C,   ///< temperature in degrees Celsius
  MBG_IMS_SENSOR_VOLTAGE,  ///< voltage in val/exp, output state in flags
  MBG_IMS_SENSOR_PLL,      ///< control voltage in val/exp, lock state in flags
  N_MBG_IMS_SENSORS        ///< number of supported sensor types
};



/**
 * @brief IMS sensor state flags for voltage
 *
 * Used with ::MBG_IMS_SENSOR_STATE::flags in case ::MBG_IMS_SENSOR_STATE::type
 * is ::MBG_IMS_SENSOR_VOLTAGE.
 */
enum MBG_IMS_SENSOR_STATE_FLAG_MASK_VOLTAGE
{
  MBG_IMS_SENSOR_VOLTAGE_OUT_ENB = 0x01,  ///< output is enabled
  MBG_IMS_SENSOR_VOLTAGE_OUT_OVR = 0x02   ///< output overload
};


/**
 * @brief IMS sensor state flags for PLL
 *
 * Used with ::MBG_IMS_SENSOR_STATE::flags in case ::MBG_IMS_SENSOR_STATE::type
 * is ::MBG_IMS_SENSOR_PLL.
 */
enum MBG_IMS_SENSOR_STATE_FLAG_MASK_PLL
{
  MBG_IMS_SENSOR_PLL_LOCKED = 0x01  ///< PLL is locked
};



/**
 * @brief DAC limit specs
 */
typedef struct
{
  int32_t dac_val_min;    ///< min. possible DAC Value, positive or negative
  int32_t dac_val_max;    ///< max. possible DAC Value, positive or negative

  int32_t u_min;          ///< min. possible real voltage range [mV], positive or negative, depending on ::MBG_DAC_SPECS::dac_val_min
  int32_t u_max;          ///< max. possible real voltage range [mV], positive or negative, depending on ::MBG_DAC_SPECS::dac_val_max

  uint32_t reserved_0;    ///< reserved, currently always 0
  uint32_t reserved_1;    ///< reserved, currently always 0

} MBG_DAC_SPECS;

#define _mbg_swab_mbg_dac_specs( _p ) \
do                                    \
{                                     \
  _mbg_swab32( &(_p)->dac_val_min );  \
  _mbg_swab32( &(_p)->dac_val_max );  \
  _mbg_swab32( &(_p)->u_min );        \
  _mbg_swab32( &(_p)->u_max );        \
  _mbg_swab32( &(_p)->reserved_0 );   \
  _mbg_swab32( &(_p)->reserved_1 );   \
} while ( 0 )



/**
 * @brief Output state of FDM device.
 *
 * @note This is only supported if ::MBG_IMS_STATE_FLAG_MSK_HAS_FDM is set in ::MBG_IMS_STATE::flags
 */
typedef struct
{
  int32_t dac_val;            ///< current DAC value, positive or negative
  uint32_t mode;              ///< current output mode, see ::MBG_IMS_FDM_OUTPUT_MODES

  MBG_DAC_SPECS dac_specs;    ///< DAC specific limits

  uint32_t reserved_0;        ///< reserved, currently always 0
  uint32_t reserved_1;        ///< reserved, currently always 0

} MBG_IMS_FDM_OUTPUT_STATE;

#define _mbg_swab_mbg_ims_fdm_output_state( _p )  \
do                                                \
{                                                 \
  _mbg_swab32( &(_p)->dac_val );                  \
  _mbg_swab32( &(_p)->mode );                     \
  _mbg_swab_mbg_dac_specs( &(_p)->dac_specs );    \
  _mbg_swab32( &(_p)->reserved_0 );               \
  _mbg_swab32( &(_p)->reserved_1 );               \
} while ( 0 )



/**
 * @brief Output state of FDM device plus index.
 */
typedef struct
{
  uint32_t idx;
  MBG_IMS_FDM_OUTPUT_STATE state;

} MBG_IMS_FDM_OUTPUT_STATE_IDX;

#define _mbg_swab_mbg_ims_fdm_output_state_idx( _p )  \
do                                                    \
{                                                     \
  _mbg_swab32( &(_p)->idx );                          \
  _mbg_swab_mbg_ims_fdm_output_state( &(_p)->state ); \
} while ( 0 )



/**
 * @brief Output settings of FDM device
 *
 * @note This is only supported if ::MBG_IMS_STATE_FLAG_MSK_HAS_FDM is set in ::MBG_IMS_STATE::flags
 */
typedef struct
{
  uint32_t mode;              ///< mode, see ::MBG_IMS_FDM_OUTPUT_MODES
  uint32_t reserved;          ///< reserved, currently always 0

} MBG_IMS_FDM_OUTPUT_SETTINGS;

#define _mbg_swab_mbg_ims_fdm_output_settings( _p ) \
do                                                  \
{                                                   \
  _mbg_swab32( &(_p)->mode );                       \
  _mbg_swab32( &(_p)->reserved );                   \
} while ( 0 )


/**
 * @brief Output settings for FDM devices plus index.
 */
typedef struct
{
  uint32_t idx;
  MBG_IMS_FDM_OUTPUT_SETTINGS settings;

} MBG_IMS_FDM_OUTPUT_SETTINGS_IDX;

#define _mbg_swab_mbg_ims_fdm_output_settings_idx( _p )     \
do                                                          \
{                                                           \
  _mbg_swab32( &(_p)->idx );                                \
  _mbg_swab_mbg_ims_fdm_output_settings( &(_p)->settings ); \
} while ( 0 )



/**
 * @brief Specific output settings and limits.
 */
typedef struct
{
  MBG_IMS_FDM_OUTPUT_SETTINGS settings;   ///< current settings
  uint32_t supp_modes;                    ///< supported modes, see ::MBG_IMS_FDM_OUTPUT_MODE_MASKS
  MBG_DAC_SPECS dac_specs;                ///< DAC specific limits

} MBG_IMS_FDM_OUTPUT_INFO;

#define _mbg_swab_mbg_ims_fdm_output_info( _p )             \
do                                                          \
{                                                           \
  _mbg_swab_mbg_ims_fdm_output_settings( &(_p)->settings ); \
  _mbg_swab32( &(_p)->supp_modes );                         \
  _mbg_swab_mbg_dac_specs( &(_p)->dac_specs );              \
} while ( 0 )



/**
 * @brief Specific output settings and limits, plus index.
 */
typedef struct
{
  uint32_t idx;
  MBG_IMS_FDM_OUTPUT_INFO info;

} MBG_IMS_FDM_OUTPUT_INFO_IDX;

#define _mbg_swab_mbg_ims_fdm_output_info_idx( _p ) \
do                                                  \
{                                                   \
  _mbg_swab32( &(_p)->idx );                        \
  _mbg_swab_mbg_ims_fdm_output_info( &(_p)->info ); \
} while ( 0 )



/**
 * @brief Enumeration of known output modes
 *
 * Used with ::MBG_IMS_FDM_OUTPUT_STATE::mode
 *
 * @see ::MBG_IMS_FDM_OUTPUT_MODE_MASKS
 */
enum MBG_IMS_FDM_OUTPUT_MODES
{
  MBG_IMS_FDM_OUTPUT_MODE_FD,     ///< Analog output reflects frequency deviation
  MBG_IMS_FDM_OUTPUT_MODE_TD,     ///< Analog output reflects time deviation
  N_MBG_IMS_FDM_OUTPUT_MODES      ///< Number of known output modes
};



/**
 * @brief Bit masks used with ::MBG_IMS_FDM_OUTPUT_STATE::mode
 *
 * @see ::MBG_IMS_FDM_OUTPUT_MODES
 */
enum MBG_IMS_FDM_OUTPUT_MODE_MASKS
{
  MBG_IMS_FDM_OUTPUT_MODE_MSK_FD = ( 1UL << MBG_IMS_FDM_OUTPUT_MODE_FD ),      ///< see ::MBG_IMS_FDM_OUTPUT_MODE_FD
  MBG_IMS_FDM_OUTPUT_MODE_MSK_TD = ( 1UL << MBG_IMS_FDM_OUTPUT_MODE_TD )       ///< see ::MBG_IMS_FDM_OUTPUT_MODE_TD
};



/**
 * @brief A generic structure used to specify FDM limits
 */
typedef struct
{
  uint8_t n_outputs;        ///< number of outputs per module
  uint8_t reserved_0;       ///< reserved, currently always 0
  uint16_t reserved_1;      ///< reserved, currently always 0

  uint32_t fd_neg_limit;    ///< min. frequency deviation limit, 1/::MBG_IMS_FDM_LIMITS::fd_scale Hz units
  uint32_t fd_pos_limit;    ///< max. frequency deviation limit, 1/::MBG_IMS_FDM_LIMITS::fd_scale Hz units
  uint32_t fd_scale;        ///< scale for ::MBG_IMS_FDM_LIMITS::fd_neg_limit and ::MBG_IMS_FDM_LIMITS::fd_pos_limit

  uint32_t td_neg_limit;    ///< min. time deviation limit, 1/::MBG_IMS_FDM_LIMITS::td_scale s units
  uint32_t td_pos_limit;    ///< max. time deviation limit, 1/::MBG_IMS_FDM_LIMITS::td_scale s units
  uint32_t td_scale;        ///< scale for ::MBG_IMS_FDM_LIMITS::td_neg_limit and ::MBG_IMS_FDM_LIMITS::td_pos_limit

  uint32_t reserved_2;      ///< reserved, currently always 0

} MBG_IMS_FDM_LIMITS;

#define _mbg_swab_mbg_ims_fdm_limits( _p )  \
do                                          \
{                                           \
  _mbg_swab8( &(_p)->n_outputs );           \
  _mbg_swab8( &(_p)->reserved_0 );          \
  _mbg_swab16( &(_p)->reserved_1 );         \
                                            \
  _mbg_swab32( &(_p)->fd_neg_limit );       \
  _mbg_swab32( &(_p)->fd_pos_limit );       \
  _mbg_swab32( &(_p)->fd_scale );           \
                                            \
  _mbg_swab32( &(_p)->td_neg_limit );       \
  _mbg_swab32( &(_p)->td_pos_limit );       \
  _mbg_swab32( &(_p)->td_scale );           \
                                            \
  _mbg_swab32( &(_p)->reserved_2 );         \
} while ( 0 )



/**
 * @brief State of FDM device
 *
 * @note This is only supported if ::MBG_IMS_STATE_FLAG_MSK_HAS_FDM is set in ::MBG_IMS_STATE::flags.
 *
 */
typedef struct
{
  MBG_GPIO_FREQ freq;         ///< Current frequency

  NANO_TIME_64 t_ref;         ///< Current reference time
  NANO_TIME_64 t_plt;         ///< Current power line time
  NANO_TIME_64 t_sync;        ///< Last sync Time (reference time)

  uint32_t line_freq;         ///< Nominal line frequency, see ::MBG_IMS_FDM_LINE_FREQS
  uint32_t flags;             ///< Flags, see ::MBG_IMS_FDM_STATE_FLAG_MASKS
  uint32_t reserved;          ///< Reserved, currently always 0

} MBG_IMS_FDM_STATE;

#define _mbg_swab_mbg_ims_fdm_state( _p )  \
do                                         \
{                                          \
  _mbg_swab_mbg_gpio_freq( &(_p)->freq );  \
  _mbg_swab_nano_time_64( &(_p)->t_ref );  \
  _mbg_swab_nano_time_64( &(_p)->t_plt );  \
  _mbg_swab_nano_time_64( &(_p)->t_sync ); \
  _mbg_swab32( &(_p)->line_freq );         \
  _mbg_swab32( &(_p)->flags );             \
  _mbg_swab32( &(_p)->reserved );          \
} while ( 0 )



/**
 * @brief Enumeration known line frequencies
 *
 * Used with ::MBG_IMS_FDM_STATE::line_freq
 *
 * @see ::MBG_IMS_FDM_LINE_FREQ_MASKS
 */
enum MBG_IMS_FDM_LINE_FREQS
{
  MBG_IMS_FDM_LINE_FREQ_AUTO,    ///< Auto detect line frequency
  MBG_IMS_FDM_LINE_FREQ_50HZ,    ///< 50Hz line frequency
  MBG_IMS_FDM_LINE_FREQ_60HZ,    ///< 60Hz line frequency
  N_MBG_IMS_FDM_LINE_FREQS       ///< number of known line frequencies
};


/**
 * @brief Bit masks corresponding to defined line frequencies
 *
 * @see ::MBG_IMS_FDM_LINE_FREQS
 */
enum MBG_IMS_FDM_LINE_FREQ_MASKS
{
  MBG_IMS_FDM_LINE_FREQ_MSK_AUTO = ( 1UL << MBG_IMS_FDM_LINE_FREQ_AUTO ),   ///< see ::MBG_IMS_FDM_LINE_FREQ_AUTO
  MBG_IMS_FDM_LINE_FREQ_MSK_50HZ = ( 1UL << MBG_IMS_FDM_LINE_FREQ_50HZ ),   ///< see ::MBG_IMS_FDM_LINE_FREQ_50HZ
  MBG_IMS_FDM_LINE_FREQ_MSK_60HZ = ( 1UL << MBG_IMS_FDM_LINE_FREQ_60HZ )    ///< see ::MBG_IMS_FDM_LINE_FREQ_60HZ
};


/**
 * @brief Initializers for an array of line freq. name strings
 *
 * @see ::MBG_IMS_FDM_LINE_FREQS
 */
#define MBG_IMS_FDM_LINE_FREQ_STRS  \
{                                   \
  "Auto",                           \
  "50 Hz",                          \
  "60 Hz",                          \
}


/**
 * @brief Enumeration of flag bits used to define ::MBG_IMS_FDM_STATE_FLAG_MASKS
 */
enum MBG_IMS_FDM_STATE_FLAG_BITS
{
  MBG_IMS_FDM_STATE_FLAG_BIT_SYNC_AFTER_RESET,  ///< if sync'ed after reset
  MBG_IMS_FDM_STATE_FLAG_BIT_PLT_IS_LOCKED,     ///< Power Line Time is locked
  MBG_IMS_FDM_STATE_FLAG_BIT_FD_OVERFLOW,       ///< Frequency deviation overflow occurred
  MBG_IMS_FDM_STATE_FLAG_BIT_TD_OVERFLOW,       ///< Time deviation overflow occurred
  N_MBG_IMS_FDM_STATE_FLAG_BITS                 ///< number of known state flag bits
};


/**
 * @brief Bit masks used with ::MBG_IMS_FDM_STATE::flags
 *
 * @see ::MBG_IMS_FDM_STATE_FLAG_BITS
 */
enum MBG_IMS_FDM_STATE_FLAG_MASKS
{
  MBG_IMS_FDM_STATE_FLAG_MSK_SYNC_AFTER_RESET = ( 1UL << MBG_IMS_FDM_STATE_FLAG_BIT_SYNC_AFTER_RESET ),  ///< see ::MBG_IMS_FDM_STATE_FLAG_BIT_SYNC_AFTER_RESET
  MBG_IMS_FDM_STATE_FLAG_MSK_PLT_IS_LOCKED    = ( 1UL << MBG_IMS_FDM_STATE_FLAG_BIT_PLT_IS_LOCKED ),     ///< see ::MBG_IMS_FDM_STATE_FLAG_BIT_PLT_IS_LOCKED
  MBG_IMS_FDM_STATE_FLAG_MSK_FD_OVERFLOW      = ( 1UL << MBG_IMS_FDM_STATE_FLAG_BIT_FD_OVERFLOW ),       ///< see ::MBG_IMS_FDM_STATE_FLAG_BIT_FD_OVERFLOW
  MBG_IMS_FDM_STATE_FLAG_MSK_TD_OVERFLOW      = ( 1UL << MBG_IMS_FDM_STATE_FLAG_BIT_TD_OVERFLOW )        ///< see ::MBG_IMS_FDM_STATE_FLAG_BIT_TD_OVERFLOW
};



/**
 * @brief FDM device settings
 *
 * @note This is only supported if ::MBG_IMS_STATE_FLAG_BIT_HAS_FDM is set in ::MBG_IMS_STATE::flags.
 *
 */
typedef struct
{
  uint32_t fd_neg_limit; ///< min. frequency deviation limit in 1 mHz steps
  uint32_t fd_pos_limit; ///< max. frequency deviation limit in 1 mHz steps

  uint32_t td_neg_limit; ///< min. time deviation limit in 1 ms steps
  uint32_t td_pos_limit; ///< max. time deviation limit in 1 ms steps

  uint32_t line_freq;    ///< nominal line frequency, see ::MBG_IMS_FDM_LINE_FREQS
  uint32_t reserved;     ///< reserved, currently always 0

} MBG_IMS_FDM_SETTINGS;

#define _mbg_swab_mbg_ims_fdm_settings( _p )  \
do                                            \
{                                             \
  _mbg_swab32( &(_p)->fd_neg_limit );         \
  _mbg_swab32( &(_p)->fd_pos_limit );         \
  _mbg_swab32( &(_p)->td_neg_limit );         \
  _mbg_swab32( &(_p)->td_pos_limit );         \
  _mbg_swab32( &(_p)->line_freq );            \
  _mbg_swab32( &(_p)->reserved );             \
} while ( 0 )



/**
 * @brief IMS FDM flags
 *
 * @see ::MBG_IMS_FDM_FLAG_MASKS
 */
enum MBG_IMS_FDM_FLAGS
{
  MBG_IMS_FDM_FLAG_CAN_SET_TDEV,    ///< Device supports command GPS_FDM_SET_TD
  N_MBG_IMS_FDM_FLAGS               ///< Number of known FDM flags
};



/**
 * @brief IMS FDM flag masks
 *
 * @see ::MBG_IMS_FDM_FLAGS
 */
enum MBG_IMS_FDM_FLAG_MASKS
{
  MBG_IMS_FDM_FLAG_MASK_CAN_SET_TDEV    = ( 1UL << MBG_IMS_FDM_FLAG_CAN_SET_TDEV )  ///< see ::MBG_IMS_FDM_FLAG_CAN_SET_TDEV
};



/**
 * @brief Specific FDM settings and limits.
 */
typedef struct
{
  MBG_IMS_FDM_SETTINGS settings;
  uint32_t supp_line_freqs;      ///< Bit mask of supported line frequencies, see ::MBG_IMS_FDM_LINE_FREQ_MASKS
  uint32_t reserved;             ///< Reserved, currently always 0
  uint32_t flags;                ///< Flags, see ::MBG_IMS_FDM_FLAG_MASKS

} MBG_IMS_FDM_INFO;

#define _mbg_swab_mbg_ims_fdm_info( _p )              \
do                                                    \
{                                                     \
  _mbg_swab_mbg_ims_fdm_settings( &(_p)->settings );  \
  _mbg_swab32( &(_p)->supp_line_freqs );              \
  _mbg_swab32( &(_p)->reserved );                     \
  _mbg_swab32( &(_p)->flags );                        \
} while ( 0 )

/** @} defgroup group_ims */



/**
 * @defgroup group_generic_io Generic I/O support.
 *
 * The definitions below are used with the GENERIC_IO API.
 *
 * This API is <b>NOT</b> supported by all devices, it depends on
 * the type of the device, and the firmware version. The macro
 * _pcps_has_generic_io() or the corresponding function
 * mbg_dev_has_generic_io() should be used by applications to
 * check whether a particular bus-level device supports this.
 *
 * @{ */

typedef uint16_t GEN_IO_INFO_TYPE;

#define _mbg_swab_gen_io_info_type( _p )  \
  _mbg_swab16( _p )



/**
 * @brief The data structure used with the ::PCPS_GEN_IO_GET_INFO command
 *
 * Used to determine how many data sets of a specific type are supported
 * by the device.
 */
typedef struct
{
  GEN_IO_INFO_TYPE type;  // see ::PCPS_GEN_IO_TYPES
  uint16_t num;           // supported number of data sets of the specified type

} GEN_IO_INFO;

#define _mbg_swab_gen_io_info( _p )           \
do                                            \
{                                             \
  _mbg_swab_gen_io_info_type( &(_p)->type );  \
  _mbg_swab16( &(_p)->num );                  \
} while ( 0 )



/**
 * @brief Data types used with ::GEN_IO_INFO::type
 *
 * The first type specifier, ::PCPS_GEN_IO_GET_INFO, can
 * be used to find out which of the other data types are
 * supported, and how many data sets of the specified type
 * are supported by a device.
 */
enum PCPS_GEN_IO_TYPES
{
  PCPS_GEN_IO_GET_INFO,              ///< ::GEN_IO_INFO (read only)
  PCPS_GEN_IO_CAL_REC_IRIG_RX_COMP,  ///< ::CAL_REC_IRIG_RX_COMP (read/write)
  N_PCPS_GEN_IO_TYPE                 ///< number of known types
};

/** @} defgroup group_generic_io */



typedef uint16_t ROM_CSUM;      /* The ROM checksum */
typedef uint16_t RCV_TIMEOUT;   /* [min] (only if ::HAS_RCV_TIMEOUT) */
typedef uint16_t IGNORE_LOCK;   /* (only if ::GPS_HAS_IGNORE_LOCK) */

/*
 * Originally ::IGNORE_LOG above has been a boolean value (equal or
 * not equal 0) which was evaluated the same way for all ports.
 *
 * Due to special firmware requirements it has been changed to a
 * bit maskable property in order to be able to specify the behaviour
 * for individual ports.
 *
 * In order to keep compatibility with older versions the LSB is used
 * to specify ignore_lock for all ports. The next higher bits are used
 * to specify ignore_lock for an individual port, where the bit position
 * depends on the port number, e.g. 0x02 for COM0, 0x04 for COM1, etc.
 * The macros below can be used to simplify the code:
 */

/* return a bit mask depending on the port number */
#define IGNORE_LOCK_FOR_ALL_PORTS            0x01

#define _ignore_lock_for_all_ports()         ( IGNORE_LOCK_FOR_ALL_PORTS )

#define _ignore_lock_for_port( _n )          ( 0x02 << (_n) )

/* check if all ports are ignore_lock'ed */
#define _is_ignore_lock_all_ports( _il )     ( (_il) & IGNORE_LOCK_FOR_ALL_PORTS )

/* check if a specific port is ignore_lock'ed */
#define _is_ignore_lock_for_port( _il, _n ) \
        ( (_il) & ( _ignore_lock_for_port(_n) | IGNORE_LOCK_FOR_ALL_PORTS ) )



/**
 * @defgroup group_scu Definitions used with SCU devices
 *
 * The structures below are used with the SCU multiplexer board
 * in a redundant system.
 *
 * @see ::GPS_MODEL_IS_SCU
 *
 * @{ */

typedef struct
{
  uint32_t hw_id;         ///< hardware identification
  uint32_t fw_id;         ///< firmware identification
  uint16_t flags;         ///< reserved currently 0
  uint8_t  clk0_info;     ///< reference clock 0 type
  uint8_t  clk1_info;     ///< reference clock 1 type
  uint16_t epld_status;   ///< EPLD status word, see ::SCU_STAT_MASKS
  uint16_t epld_control;  ///< EPLD control word, see ::SCU_CTRL_MASKS

} SCU_STAT_INFO;

#define _mbg_swab_scu_stat_info( _p )  \
do                                     \
{                                      \
  _mbg_swab32( &(_p)->hw_id );         \
  _mbg_swab32( &(_p)->fw_id );         \
  _mbg_swab16( &(_p)->flags );         \
  _mbg_swab8( &(_p)->clk0_info );      \
  _mbg_swab8( &(_p)->clk1_info );      \
  _mbg_swab16( &(_p)->epld_status );   \
  _mbg_swab16( &(_p)->epld_control );  \
} while ( 0 )



typedef struct
{
  uint16_t epld_control_mask;   ///< control mask, determines which bit is to be changed, see ::SCU_CTRL_MASKS
  uint16_t epld_control_value;  ///< control value, determines value of bits to be changed, see ::SCU_CTRL_MASKS
  uint32_t flags;               ///< reserved, currently 0

} SCU_STAT_SETTINGS;

#define _mbg_swab_scu_stat_settings( _p )    \
do                                           \
{                                            \
  _mbg_swab16( &(_p)->epld_control_mask );   \
  _mbg_swab16( &(_p)->epld_control_value );  \
  _mbg_swab32( &(_p)->flags );               \
} while ( 0 )



/**
 * @brief Bit masks used to check the SCU EPLD status
 *
 * Used with ::SCU_STAT_INFO::epld_status
 */
enum SCU_STAT_MASKS
{
  MSK_EPLD_STAT_TS1        = 0x0001,  ///< state of time sync signal clk_1
  MSK_EPLD_STAT_TS2        = 0x0002,  ///< state of time sync signal clk_2
  MSK_EPLD_STAT_TL_ERROR   = 0x0004,  ///< state of time limit error input
  MSK_EPLD_STAT_PSU1_OK    = 0x0008,  ///< state of power supply 1 monitoring input
  MSK_EPLD_STAT_PSU2_OK    = 0x0010,  ///< state of power supply 2 monitoring input
  MSK_EPLD_STAT_AUTO       = 0x0020,  ///< AUTOMATIC/REMOTE or MANUAL Mode
  MSK_EPLD_STAT_SEL        = 0x0040,  ///< select bit for output MUX, ( clk_1 = 0 )
  MSK_EPLD_STAT_ENA        = 0x0080,  ///< enable Bit for output MUX, set if enabled
  MSK_EPLD_STAT_HAS_LAN    = 0x0100,  ///< indicates that the device has a network interface
  MSK_EPLD_STAT_RESERVED0  = 0x0200,  ///< reserved, DO NOT USE!
  MSK_EPLD_STAT_RESERVED1  = 0x0400,  ///< reserved, DO NOT USE!
  MSK_EPLD_STAT_HAS_4_PSUS = 0x0800,  ///< indicates 4 power supplies instead of 2
  MSK_EPLD_STAT_PSU3_OK    = 0x1000,  ///< state of power supply 3 monitoring input
  MSK_EPLD_STAT_PSU4_OK    = 0x2000,  ///< state of power supply 4 monitoring input
  MSK_EPLD_STAT_ACO        = 0x4000,  ///< Access control override bit
  MSK_EPLD_STAT_WDOG_OK    = 0x8000   ///< WDT_OK set to zero if watchdog expired
};



/**
 * @brief Bit masks used to control the SCU EPLD
 *
 * Used with ::SCU_STAT_INFO::epld_control, ::SCU_STAT_SETTINGS::epld_control_mask,
 * and ::SCU_STAT_SETTINGS::epld_control_value.
 */
enum SCU_CTRL_MASKS
{
  MSK_EPLD_CTL_DISB_SERIAL = 0x0001,  ///< disable serial output on error
  MSK_EPLD_CTL_DISB_PPS    = 0x0002,  ///< disable PPS output on error
  MSK_EPLD_CTL_DISB_10MHZ  = 0x0004,  ///< disable 10 MHz output on error

  MSK_EPLD_CNTL_SEL_REM    = 0x0800,  ///< remote select for output MUX (clk_1 = 0)
  MSK_EPLD_CNTL_DIS_REM    = 0x1000,  ///< remote disable for output MUX
  MSK_EPLD_CNTL_REMOTE     = 0x2000,  ///< must be set to enable remote operation
  MSK_EPLD_CNTL_SEL_SNMP   = 0x4000,  ///< select clk for comm. (clk1 = 0)
  MSK_EPLD_CNTL_ENA_SNMP   = 0x8000,  ///< connect COM0 channels to XPORT
};



/**
 * @brief Definitions for ::SCU_STAT_INFO::clk0_info and ::SCU_STAT_INFO::clk1_info
 *
 * Can be used to determine the reference clock type connected to the SCU input channels.
 */
enum SCU_CLK_INFO_TYPES
{
 SCU_CLK_INFO_GPS,                ///< ref. clock is GPS receiver
 SCU_CLK_INFO_DCF_PZF,            ///< ref. clock is DCF77 PZF receiver
 SCU_CLK_INFO_DCF_AM,             ///< ref. clock is DCF77 AM receiver
 SCU_CLK_INFO_TCR,                ///< ref. clock is IRIG time code receiver
 N_SCU_CLK_INFO                   ///< number of known types
};

/** @} defgroup group_scu */



/*------------------------------------------------------------------------*/

#define REMOTE    0x10
#define BOOT      0x20

/**
 * @brief Satellite receiver modes of operation.
 *
 * @note Some of the code combinations are deprecated with recent
 * satellite receivers. However, this doesn't matter since the mode
 * is just read from the receiver.
 */
enum RECEIVER_MODES
{
  TRACK    = ( 0x01 ),
  AUTO_166 = ( 0x02 ),
  WARM_166 = ( 0x03          | BOOT ),
  COLD_166 = ( 0x04          | BOOT ),
  AUTO_BC  = ( 0x05 | REMOTE ),
  WARM_BC  = ( 0x06 | REMOTE | BOOT ),
  COLD_BC  = ( 0x07 | REMOTE | BOOT ),
  UPDA_166 = ( 0x08          | BOOT ),
  UPDA_BC  = ( 0x09 | REMOTE | BOOT )
};



typedef int16_t DAC_VAL;

#define _mbg_swab_dac_val( _p ) \
  _mbg_swab16( _p )



/**
 * @brief Satellite receiver status information
 */
typedef struct
{
  uint16_t mode;          ///< Mode of operation, see ::RECEIVER_MODES
  uint16_t good_svs;      ///< Numb. of satellites that can currently be received and used
  uint16_t svs_in_view;   ///< Numb. of satellites that should be visible above the horizon
  DAC_VAL dac_val;        ///< Oscillator fine DAC value
  DAC_VAL dac_cal;        ///< Oscillator calibration DAC value ( see ::OSC_DAC_RANGE, ::OSC_DAC_BIAS )

} STAT_INFO;

#define _mbg_swab_stat_info( _p )      \
do                                     \
{                                      \
  _mbg_swab16( &(_p)->mode );          \
  _mbg_swab16( &(_p)->good_svs );      \
  _mbg_swab16( &(_p)->svs_in_view );   \
  _mbg_swab_dac_val( &(_p)->dac_val ); \
  _mbg_swab_dac_val( &(_p)->dac_cal ); \
} while ( 0 )


#define OSC_DAC_RANGE     4096UL
#define OSC_DAC_BIAS      ( OSC_DAC_RANGE / 2 )



/**
 * @brief An enumeration of known satellite navigation systems
 *
 * @see ::MBG_GNSS_TYPE_MASKS
 * @see ::GNSS_TYPE_STRS
 */
enum MBG_GNSS_TYPES
{
  GNSS_TYPE_GPS,      ///< GPS, United States
  GNSS_TYPE_GLONASS,  ///< GLONASS, Russia
  GNSS_TYPE_BEIDOU,   ///< BEIDOU, China
  GNSS_TYPE_GALILEO,  ///< GALILEO, Europe
  GNSS_TYPE_WAAS,     ///< WAAS, Wide Area Augmentation System
  GNSS_TYPE_EGNOS,    ///< EGNOS, European Geostationary Navigation Overlay Service
  GNSS_TYPE_QZSS,     ///< QZSS, Quasi Zenit Satellite System
  N_GNSS_TYPES        ///< Number of defined codes
};


/**
 * @brief Bit masks associated with ::MBG_GNSS_TYPES
 *
 * @see ::MBG_GNSS_TYPES
 */
enum MBG_GNSS_TYPE_MASKS
{
  MBG_GNSS_TYPE_MSK_GPS     = ( 1UL << GNSS_TYPE_GPS ),      ///< see ::GNSS_TYPE_GPS
  MBG_GNSS_TYPE_MSK_GLONASS = ( 1UL << GNSS_TYPE_GLONASS ),  ///< see ::GNSS_TYPE_GLONASS
  MBG_GNSS_TYPE_MSK_BEIDOU  = ( 1UL << GNSS_TYPE_BEIDOU ),   ///< see ::GNSS_TYPE_BEIDOU
  MBG_GNSS_TYPE_MSK_GALILEO = ( 1UL << GNSS_TYPE_GALILEO ),  ///< see ::GNSS_TYPE_GALILEO
  MBG_GNSS_TYPE_MSK_WAAS    = ( 1UL << GNSS_TYPE_WAAS ),     ///< see ::GNSS_TYPE_WAAS
  MBG_GNSS_TYPE_MSK_EGNOS   = ( 1UL << GNSS_TYPE_EGNOS ),    ///< see ::GNSS_TYPE_EGNOS
  MBG_GNSS_TYPE_MSK_QZSS    = ( 1UL << GNSS_TYPE_QZSS )      ///< see ::GNSS_TYPE_QZSS
};


/**
 * @brief Name strings for the the known satellite navigation systems
 *
 * @see ::MBG_GNSS_TYPES
 */
#define GNSS_TYPE_STRS \
{                      \
  "GPS",               \
  "GLONASS",           \
  "BEIDOU",            \
  "GALILEO",           \
  "WAAS",              \
  "EGNOS",             \
  "QZSS"               \
}


#define N_GNSS_MODE_PRIO  8

/**
 * @brief GNSS mode settings
 *
 * @see ::MBG_GNSS_TYPES
 */
typedef struct
{
  uint32_t gnss_set;                ///< bit mask of currently used GNSS systems, see ::MBG_GNSS_TYPE_MASKS
  uint8_t  prio[N_GNSS_MODE_PRIO];  ///< see ::MBG_GNSS_TYPES, unused fields set to 0xFF, idx 0 is highest prio
  uint32_t flags;                   ///< unused, currently always 0 (should be named MBG_GNSS_MODE_SETTINGS_FLAG_MASKS)

} MBG_GNSS_MODE_SETTINGS;

#define _mbg_swab_mbg_gnss_mode_settings( _p ) \
do                                             \
{                                              \
  _mbg_swab32( &(_p)->gnss_set );              \
  _mbg_swab32( &(_p)->flags );                 \
} while ( 0 )



typedef struct
{
  MBG_GNSS_MODE_SETTINGS settings;  ///< Current GNSS mode settings
  uint32_t supp_gnss_types;         ///< Bit masks of supported GNSS types, see ::MBG_GNSS_TYPE_MASKS
  uint16_t flags;                   ///< See ::MBG_GNSS_MODE_INFO_FLAG_MASKS
  uint16_t n_sv_status;             ///< Number of ::GNSS_SV_STATUS_IDX structures that can be read (only if ::MBG_GNSS_FLAG_MSK_HAS_SV_STATUS)

} MBG_GNSS_MODE_INFO;

#define _mbg_swab_mbg_gnss_mode_info( _p )              \
do                                                      \
{                                                       \
  _mbg_swab_mbg_gnss_mode_settings( &(_p)->settings );  \
  _mbg_swab32( &(_p)->supp_gnss_types );                \
  _mbg_swab16( &(_p)->flags );                          \
  _mbg_swab16( &(_p)->n_sv_status );                    \
} while ( 0 )



/**
 * @brief Flag bits used to define ::MBG_GNSS_MODE_INFO_FLAG_MASKS
 *
 * @see ::MBG_GNSS_MODE_INFO_MASKS
 */
enum MBG_GNSS_MODE_INFO_FLAG_BITS
{
  MBG_GNSS_FLAG_EXCLUSIVE,             ///< Only one of the supported GNSS systems can be used at the same time
  MBG_GNSS_FLAG_HAS_PRIORITY,          ///< Priority can be configured using the ::MBG_GNSS_MODE_SETTINGS::prio field
  MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER, ///< The ::GNSS_SAT_INFO_IDX structure is supported by the device
  MBG_GNSS_FLAG_HAS_SV_STATUS,         ///< The ::GNSS_SV_STATUS_IDX structure is supported by the device
  N_MBG_GNSS_FLAGS
};


/**
 * @brief Flag masks used with MBG_GNSS_MODE_INFO::flags
 *
 * @see ::MBG_GNSS_MODE_FLAG_BITS
 */
enum MBG_GNSS_MODE_INFO_FLAG_MASKS
{
  MBG_GNSS_FLAG_MSK_EXCLUSIVE             = ( 1UL << MBG_GNSS_FLAG_EXCLUSIVE ),              ///< see ::MBG_GNSS_FLAG_EXCLUSIVE
  MBG_GNSS_FLAG_MSK_HAS_PRIORITY          = ( 1UL << MBG_GNSS_FLAG_HAS_PRIORITY ),           ///< see ::MBG_GNSS_FLAG_HAS_PRIORITY
  MBG_GNSS_FLAG_MSK_SAT_INFO_IDX_SUPP_SER = ( 1UL << MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER ),  ///< see ::MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER
  MBG_GNSS_FLAG_MSK_HAS_SV_STATUS         = ( 1UL << MBG_GNSS_FLAG_HAS_SV_STATUS )           ///< see ::MBG_GNSS_FLAG_HAS_SV_STATUS
};



#define MAX_USED_SATS   32

/**
 * @brief Satellite information for a particular GNSS type.
 */
typedef struct
{
  uint8_t  gnss_type;           ///< GNSS type as enumerated in ::MBG_GNSS_TYPES
  uint8_t  reserved;            ///< Reserved, currently always 0
  uint16_t good_svs;            ///< Num. of satellites that can currently be received and used
  uint16_t svs_in_view;         ///< Num. of satellites that should be visible above the horizon
  uint8_t  svs[MAX_USED_SATS];  ///< IDs of the satellites actually used for navigation, 0 == not used

} GNSS_SAT_INFO;

#define _mbg_swab_gnss_sat_info( _p )  \
do                                     \
{                                      \
  _mbg_swab16( &(_p)->good_svs );      \
  _mbg_swab16( &(_p)->svs_in_view );   \
} while ( 0 )



/**
 * @brief One of several sets of satellite information for a particular GNSS type.
 *
 *
 */
typedef struct
{
  /// GNSS system type index according to ::MBG_GNSS_MODE_INFO::supp_gnss_types.
  /// I.e., idx 0 corresponds to the GNSS system for which the least significant
  /// bit is set in ::MBG_GNSS_MODE_INFO::supp_gnss_types, idx 1 corresponds to
  /// GNSS system for which the next higher bit is set, etc. This must *not*
  /// necessarily match the sequence of the ::MBG_GNSS_TYPES enumeration.
  uint16_t idx;

  GNSS_SAT_INFO gnss_sat_info;   ///< see ::GNSS_SAT_INFO

} GNSS_SAT_INFO_IDX;

#define _mbg_swab_gnss_sat_info_idx( _p )          \
do                                                 \
{                                                  \
  _mbg_swab16( &(_p)->idx );                       \
  _mbg_swab_gnss_sat_info( &(_p)->gnss_sat_info ); \
} while ( 0 )



/**
 * @defgroup group_gnss_sv_status GNSS Satellite Status
 *
 * @note These structures and associated types are only supported by a device
 * if ::MBG_XFEATURE_GNSS_SV_INFO is set in the extended device features.  // FIXME
 *
 * @{ */

/**
 * @brief Detailed GNSS satellite status
 *
 * @see ::GNSS_SV_STATUS_IDX
 * @see @ref group_gnss_sv_stat_flags
 */
typedef struct
{
  uint8_t gnss_type;    ///< GNSS type as enumerated in ::MBG_GNSS_TYPES
  uint8_t svno;         ///< Satellite number, see ::TODO
  uint8_t cn_ratio;     ///< Carrier-to-noise ratio [dbHz]
  int8_t elev;          ///< Elevation [deg], range: -90..90 deg

  int16_t azim;         ///< Azimuth [deg], range: 0..360 deg
  int16_t pr_residual;  ///< Pseudo range residual [m]

  uint32_t stat_flags;  ///< see @ref group_gnss_sv_stat_flags

} GNSS_SV_STATUS;

#define _mbg_swab_gnss_sv_status( _p )  \
do                                      \
{                                       \
  _mbg_swab8( &(_p)->gnss_type );       \
  _mbg_swab8( &(_p)->svno );            \
  _mbg_swab8( &(_p)->cn_ratio );        \
  _mbg_swab8( &(_p)->elev );            \
  _mbg_swab16( &(_p)->azim );           \
  _mbg_swab16( &(_p)->pr_residual );    \
  _mbg_swab32( &(_p)->stat_flags );     \
} while ( 0 )



/**
 * @defgroup group_gnss_sv_stat_flags GNSS status flags encoding
 *
 * Used with ::GNSS_SV_STATUS::stat_flags.
 *
 * @{ */

/// Bits 0 to 2 are a 3 bit quality indicator, see ::GNSS_SV_STAT_QUALITY_INDS
#define _gnss_sv_stat_quality_ind( __stat_flags ) \
  ( (uint8_t) ( (__stat_flags) & 0x00000007UL ) )

/// Bit 3 is set if the SV is actually used for navigation
#define _gnss_sv_stat_sv_used( __stat_flags ) \
  ( ( (__stat_flags) & 0x00000008UL ) != 0 )

/// Bits 4 and 5 are a 2 bit health code, see ::GNSS_SV_STAT_HEALTH_CODES
#define _gnss_sv_stat_health_code( __stat_flags ) \
  ( (uint8_t) ( ( (__stat_flags) & 0x00000030UL ) >> 4 ) )

/// Bit 6 is set if differential correction is available for this SV
#define _gnss_sv_stat_diff_corr( __stat_flags ) \
  ( ( (__stat_flags) & 0x00000040UL ) != 0 )

/// Bit 7 is set if carrier smoothed pseudorange is used for this SV
#define _gnss_sv_stat_smoothed( __stat_flags ) \
  ( ( (__stat_flags) & 0x00000080UL ) != 0 )

/// Bits 8 to 10 are a 3 bit code indicating the orbit source, see ::GNSS_SV_STAT_ORBIT_SOURCES
#define _gnss_sv_stat_orbit_src( __stat_flags ) \
  ( (uint8_t) ( ( (__stat_flags) & 0x00000700UL ) >> 8 ) )

/// Bit 11 is set if ephemeris parameters are available for this SV
#define _gnss_sv_stat_eph_avail( __stat_flags ) \
  ( ( (__stat_flags) & 0x00000800UL ) != 0 )

/// Bit 12 is set if almanac parameters are available for this SV
#define _gnss_sv_stat_alm_avail( __stat_flags ) \
  ( ( (__stat_flags) & 0x00001000UL ) != 0 )

/// Bit 13 is set if AssistNow Offline data is available for this SV
#define _gnss_sv_stat_ano_avail( __stat_flags ) \
  ( ( (__stat_flags) & 0x00002000UL ) != 0 )

/// Bit 14 is set if AssistNow Autonomous data is available for this SV
#define _gnss_sv_stat_aop_avail( __stat_flags ) \
  ( ( (__stat_flags) & 0x00004000UL ) != 0 )

/// Bit 15 is reserved.

/// Bit 16 is set if SBAS corrections have been used for this SV
#define _gnss_sv_stat_sbas_corr_used( __stat_flags ) \
  ( ( (__stat_flags) & 0x00010000UL ) != 0 )

/// Bit 17 is set if RTCM corrections have been used for this SV
#define _gnss_sv_stat_rtcm_corr_used( __stat_flags ) \
  ( ( (__stat_flags) & 0x00020000UL ) != 0 )

/// Bits 18 and 19 are reserved.

/// Bit 20 is set if pseudorange corrections have been used for this SV
#define _gnss_sv_stat_pr_corr_used( __stat_flags ) \
  ( ( (__stat_flags) & 0x00100000UL ) != 0 )

/// Bit 21 is set if carrier range corrections have been used for this SV
#define _gnss_sv_stat_cr_corr_used( __stat_flags ) \
  ( ( (__stat_flags) & 0x00200000UL ) != 0 )

/// Bit 22 is set if range rate (doppler) corrections have been used for this SV
#define _gnss_sv_stat_do_corr_used( __stat_flags ) \
  ( ( (__stat_flags) & 0x00400000UL ) != 0 )

/// Bits 23 to 31 are reserved.

/** @} defgroup group_gnss_sv_stat_flags */


/**
 * @brief Quality indicators used with ::GNSS_SV_STATUS::sv_stat
 *
 * @see ::_gnss_sv_stat_quality_ind
 */
enum GNSS_SV_STAT_QUALITY_INDS
{
  GNSS_SV_STAT_NO_SIGNAL,              ///< No signal
  GNSS_SV_STAT_SEARCHING,              ///< Searching signal
  GNSS_SV_STAT_ACQUIRED,               ///< Signal acquired
  GNSS_SV_STAT_UNUSABLE,               ///< Signal detected but unusable
  GNSS_SV_STAT_CODE_LOCKED,            ///< Code locked and time synchronized
  GNSS_SV_STAT_CODE_CARRIER_LOCKED,    ///< Code and carrier locked, and time synchronized
  GNSS_SV_STAT_CODE_CARRIER_LOCKED_2,  ///< Code and carrier locked, and time synchronized
  GNSS_SV_STAT_CODE_CARRIER_LOCKED_3   ///< Code and carrier locked, and time synchronized
};


/**
 * @brief Health indicators used with ::GNSS_SV_STATUS::sv_stat
 *
 * @see ::_gnss_sv_stat_health_code
 */
enum GNSS_SV_STAT_HEALTH_CODES
{
  GNSS_SV_STAT_HEALTH_UNKNOWN,  ///< Health status unknown
  GNSS_SV_STAT_HEALTH_OK,       ///< Healthy
  GNSS_SV_STAT_HEALTH_NOT_OK    ///< Unhealthy
};


/**
 * @brief Orbit source codes used with ::GNSS_SV_STATUS::sv_stat
 *
 * @see ::_gnss_sv_stat_orbit_src
 */
enum GNSS_SV_STAT_ORBIT_SOURCES
{
  GNSS_SV_STAT_ORBIT_SRC_UNKNOWN,    ///< Orbit source unknown
  GNSS_SV_STAT_ORBIT_SRC_EPH,        ///< Ephemeris data used for orbit
  GNSS_SV_STAT_ORBIT_SRC_ALM,        ///< Almanac data used for orbit
  GNSS_SV_STAT_ORBIT_SRC_ASSN_OFFL,  ///< AssistNow Offline orbit is used
  GNSS_SV_STAT_ORBIT_SRC_ASSN_AUTO,  ///< AssistNow Autonomous orbit is used
  GNSS_SV_STAT_ORBIT_OTHER_1,        ///< Other orbit information is used
  GNSS_SV_STAT_ORBIT_OTHER_2,        ///< Other orbit information is used
  GNSS_SV_STAT_ORBIT_OTHER_3         ///< Other orbit information is used
};



/**
 * @brief Detailed GNSS satellite status, plus index
 *
 * @see ::GNSS_SV_STATUS
 */
typedef struct
{
  uint32_t idx;                   ///< Range 0..::MBG_GNSS_MODE_INFO::n_sv_status-1
  GNSS_SV_STATUS gnss_sv_status;

} GNSS_SV_STATUS_IDX;

#define _mbg_swab_gnss_sv_status_idx( _p )            \
do                                                    \
{                                                     \
  _mbg_swab32( &(_p)->idx );                          \
  _mbg_swab_gnss_sv_status( &(_p)->gnss_sv_status );  \
} while ( 0 )


/** @} defgroup group_gnss_sv_status */



#ifndef _IDENT_DEFINED

  typedef union
  {
    char c[16];       // as string which may NOT be terminated
    int16_t wrd[8];
    uint32_t lw[4];
  } IDENT;

  #define _IDENT_DEFINED
#endif

#define _mbg_swab_ident( _p )     \
do                                \
{                                 \
  int i;                          \
  for ( i = 0; i < 4; i++ )       \
    _mbg_swab32( &(_p)->lw[i] );  \
} while ( 0 )



/**
 * @brief A data type used to configure the length of an antenna cable [m]
 */
typedef uint16_t ANT_CABLE_LEN;

#define _mbg_swab_ant_cable_len( _p )    _mbg_swab16( _p )



/**
 * @defgroup group_net_cfg Network configuration stuff
 *
 * @{ */

/**
 * @defgroup group_net_basic_types Basic network parameter types
 *
 * @{ */

/**
 * @brief The MAC address of a network interface
 */
typedef struct
{
  uint8_t b[6];

} MBG_MAC_ADDR;

#define _mbg_swab_mbg_mac_addr( _p ) \
  _nop_macro_fnc()



/**
 * @brief An IPv4 address
 */
typedef uint32_t IP4_ADDR;

#define _mbg_swab_ip4_addr( _p ) \
  _mbg_swab32( _p )



/** @brief The number of bits used for an IPv6 address */
#define IP6_ADDR_BITS   128

/** @brief The number of bytes used for an IPv6 address */
#define IP6_ADDR_BYTES   ( IP6_ADDR_BITS / 8 )    // == 16

/**
 * @brief An IPv6 address
 */
typedef struct
{
  uint8_t b[IP6_ADDR_BYTES];  ///< bytes holding the address bits (not the string notation), b[0] == LSBs

} IP6_ADDR;

#define _mbg_swab_ip6_addr( _p )  _nop_macro_fnc()



/**
 * @brief An IPv6 address plus number of netmask bits
 */
typedef struct
{
  IP6_ADDR addr;        ///< bit mask of the bytes holding the address bits, b[0] == LSBs
  uint8_t prefix;       ///< Number of subnet mask bits for CIDR notation, e.g. 24 for /24
  uint8_t reserved[3];  ///< Reserved, alignment, currently 0

} IP6_ADDR_CIDR;



/** @brief The max number of chars required for an IPv6 address string */
#define MAX_IP6_ADDR_STR_LEN  43  ///< e.g. 2001:0db8:85a3:08d3:1319:8a2e:0370:7344/128

/** @brief Buffer size required to store an IPv6 address string */
#define IP6_ADDR_STR_SIZE     ( MAX_IP6_ADDR_STR_LEN + 1 )   ///< ::MAX_IP6_ADDR_STR_LEN + terminating 0

/** @brief A buffer for an IPv6 address string */
typedef char IP6_ADDR_STR[IP6_ADDR_STR_SIZE];



/**
 * @brief Possible IPv6 Multicast Scopes
 *
 * If the first (most significant) byte of an IPv6 address is 0xFF this
 * indicates that the address is a multicast address, and in this case
 * the second byte determines the scope for which the specified address
 * is valid. These scope ID numbers are assigned in RFC 7346 which
 * supersedes RFC 4291.
 *
 * @see ::IPV6_MULTICAST_SCOPE_NAME_TABLE_ENTRIES
 */
enum IPV6_MULTICAST_SCOPES
{
  IPV6_MULTICAST_SCOPE_INTF_LOCAL = 0x01,  ///< Interface-Local scope
  IPV6_MULTICAST_SCOPE_LINK_LOCAL,         ///< Link-Local scope
  IPV6_MULTICAST_SCOPE_REALM_LOCAL,        ///< Realm-Local scope
  IPV6_MULTICAST_SCOPE_ADMIN_LOCAL,        ///< Admin-Local scope
  IPV6_MULTICAST_SCOPE_SITE_LOCAL,         ///< Site-Local scope
  IPV6_MULTICAST_SCOPE_ORGA_LOCAL = 0x08,  ///< Organization-Local scope
  IPV6_MULTICAST_SCOPE_GLOBAL_SCOPE = 0x0E ///< Global scope
};


/**
 * @brief Name strings for IPv6 multicast scopes
 *
 * This can e.g. be used to initialize an array of ::MBG_CODE_NAME_TABLE_ENTRY elements.
 *
 * @see ::IPV6_MULTICAST_SCOPES
 */
#define IPV6_MULTICAST_SCOPE_NAME_TABLE_ENTRIES                              \
{                                                                            \
  { IPV6_MULTICAST_SCOPE_INTF_LOCAL,   "FF01 - Interface-Local Scope" },     \
  { IPV6_MULTICAST_SCOPE_LINK_LOCAL,   "FF02 - Link-Local Scope" },          \
  { IPV6_MULTICAST_SCOPE_REALM_LOCAL,  "FF03 - Realm-Local Scope" },         \
  { IPV6_MULTICAST_SCOPE_ADMIN_LOCAL,  "FF04 - Admin-Local Scope" },         \
  { IPV6_MULTICAST_SCOPE_SITE_LOCAL,   "FF05 - Site-Local Scope" },          \
  { IPV6_MULTICAST_SCOPE_ORGA_LOCAL,   "FF08 - Organization-Local Scope" },  \
  { IPV6_MULTICAST_SCOPE_GLOBAL_SCOPE, "FF0E - Global Scope" },              \
  { 0, NULL }                                                                \
}



/**
 * @brief The maximum length of a fully qualified host/domain domain name (FQDN)
 *
 * In theory each single component (host name, domain name, top level domain name)
 * of a FQDN can have up to 63 characters, but the overall length is limited to
 * 255 characters (see RFC-1123). We specify one more character for the trailing 0.
 */
#define MBG_MAX_HOSTNAME_LEN  256


/**
 * @brief A buffer for a fully qualified domain name (FQDN) or a numeric IP address string
 */
typedef char MBG_HOSTNAME[MBG_MAX_HOSTNAME_LEN];   ///< ASCIIZ format

#define _mbg_swab_mbg_host_name( _p )  _nop_macro_fnc()


/** @} defgroup group_net_basic_types */



/**
 * @brief The maximum length of an interface name
 *
 * We use an extra name here for the Meinberg-specific structures
 * to avoid a name clash with system definitions, e.g. Linux systems
 * define IFNAMSIZ usually as 16 in linux/if.h.
 */
#define MBG_IFNAMSIZ 16


/**
 * @brief Hardware type for identification of physical interfaces
 *
 * Use own definition for use under Windows,
 * original ARPHRD_ETHER comes from linux/if_arp.h
 */
#define MBG_ARPHRD_ETHER 1


/**
 * @defgroup group_vlan_cfg Definitions used with VLAN configuration
 *
 * @{ */

/**
 * @brief VLAN configuration
 *
 * @note This is a combination of a VLAN ID number plus a VLAN priority code.
 */
typedef uint16_t MBG_VLAN_CFG;

#define _mbg_swab_mbg_vlan_cfg( _p ) _mbg_swab16( _p )

#define VLAN_ID_BITS        12                        ///< number of bits to hold the ID
#define N_VLAN_ID           ( 1 << VLAN_ID_BITS )     ///< number of ID values
#define MIN_VLAN_ID         0                         ///< minimum ID value
#define MAX_VLAN_ID         ( N_VLAN_ID - 1 )         ///< maximum ID value

// vlan_id = ( vlan_cfg >> VLAN_ID_SHIFT ) & VLAN_ID_MSK
#define VLAN_ID_SHIFT       0
#define VLAN_ID_MSK         ( ( 1 << VLAN_ID_BITS ) - 1 )


#define VLAN_PRIORITY_BITS  3                             ///< number of bits to hold priority
#define N_VLAN_PRIORITY     ( 1 << VLAN_PRIORITY_BITS )   ///< number of priority values
#define MIN_VLAN_PRIORITY   0                             ///< minimum priority
#define MAX_VLAN_PRIORITY   ( N_VLAN_PRIORITY - 1 )       ///< maximum priority

// vlan_priority = ( vlan_cfg >> VLAN_PRIORITY_SHIFT ) & VLAN_PRIORITY_MSK
#define VLAN_PRIORITY_SHIFT ( ( 8 * sizeof( MBG_VLAN_CFG ) ) - VLAN_PRIORITY_BITS )
#define VLAN_PRIORITY_MSK   ( ( 1 << VLAN_PRIORITY_BITS ) - 1 )

/**
 * @brief Macros used to encode/decode packed vlan_cfg variables
 */
#define _decode_vlan_id( _cfg )         ( ( (_cfg) >> VLAN_ID_SHIFT ) & VLAN_ID_MSK )
#define _decode_vlan_priority( _cfg )   ( ( (_cfg) >> VLAN_PRIORITY_SHIFT ) & VLAN_PRIORITY_MSK )
#define _encode_vlan_cfg( _id, _prty )  ( ( (_id) << VLAN_ID_SHIFT ) | ( (_prty) << VLAN_PRIORITY_SHIFT ) )

/** @} defgroup group_vlan_cfg */



/**
 * @defgroup group_ip4_cfg Simple IPv4-only configuration or status
 *
 * This is only supported if the flag ::GPS_HAS_LAN_IP4 is set
 * in ::RECEIVER_INFO::features.
 * @see @ref group_ext_net_cfg Extended network configuration and status
 *
 * @{ */

/**
 * @brief Settings of an IPv4-only network interface
 */
typedef struct
{
  IP4_ADDR ip_addr;      ///< the IP address
  IP4_ADDR netmask;      ///< the network mask
  IP4_ADDR broad_addr;   ///< the broadcast address
  IP4_ADDR gateway;      ///< the default gateway
  uint16_t flags;        ///< see ::MBG_IP4_FLAG_MASKS
  MBG_VLAN_CFG vlan_cfg; ///< VLAN configuration

} IP4_SETTINGS;

#define _mbg_swab_ip4_settings( _p )         \
do                                           \
{                                            \
  _mbg_swab_ip4_addr( &(_p)->ip_addr );      \
  _mbg_swab_ip4_addr( &(_p)->netmask );      \
  _mbg_swab_ip4_addr( &(_p)->broad_addr );   \
  _mbg_swab_ip4_addr( &(_p)->gateway );      \
  _mbg_swab16( &(_p)->flags );               \
  _mbg_swab_mbg_vlan_cfg( &(_p)->vlan_cfg ); \
} while ( 0 )



/**
 * @brief Simple LAN interface information
 *
 * This structure can be retrieved from a device
 * to check the device's capabilities.
 *
 * It is only supported if the flag ::GPS_HAS_LAN_IP4 is set
 * in ::RECEIVER_INFO::features.
 *
 * @see @ref group_ext_net_cfg Extended network configuration and status
 */
typedef struct
{
  uint16_t type;                 ///< type of LAN interface, see ::LAN_IF_TYPES
  MBG_MAC_ADDR mac_addr;         ///< MAC address
  uint16_t ver_code;             ///< version number (hex)
  char ver_str[GPS_ID_STR_SIZE]; ///< version string
  char sernum[GPS_ID_STR_SIZE];  ///< serial number
  uint32_t rsvd_0;               ///< reserved, currently always 0
  uint16_t flags;                ///< see ::MBG_IP4_FLAG_MASKS
  uint16_t rsvd_1;               ///< reserved, currently always 0

} LAN_IF_INFO;

#define _mbg_swab_lan_if_info( _p )  \
do                                   \
{                                    \
  _mbg_swab16( &(_p)->type );        \
  _mbg_swab16( &(_p)->ver_code );    \
  _mbg_swab32( &(_p)->rsvd_0 );      \
  _mbg_swab16( &(_p)->flags );       \
  _mbg_swab16( &(_p)->rsvd_1 );      \
} while ( 0 )


/**
 * @brief Codes used with ::LAN_IF_INFO::type
 */
enum LAN_IF_TYPES
{
  LAN_IF_TYPE_XPORT,    ///< LAN interface on an XPORT, superseded by RSC devices
  LAN_IF_TYPE_PTP,      ///< LAN interface is a special PTP interface
  LAN_IF_TYPE_RSC,      ///< RSC device, supersedes XPORT
  N_LAN_IF_TYPE         ///< number of defined LAN interface types
};


/**
 * @brief Enumeration of flag bits used with ::IP4_SETTINGS::flags and ::LAN_IF_INFO::flags
 *
 * @see ::MBG_IP4_FLAG_MASKS
 */
enum MBG_IP4_FLAG_BITS
{
  /// In ::LAN_IF_INFO::flags this reports if DHCP is supported by the device.
  /// If supported then it can also be used with ::IP4_SETTINGS::flags to enable
  /// or disable DHCP for the network interface.
  IP4_BIT_DHCP,

  /// Only used with ::IP4_SETTINGS::flags. Set if port link has been established.
  IP4_BIT_LINK,

  /// In ::LAN_IF_INFO::flags this reports if VLAN is supported by the device.
  /// If supported then it can also be used with ::IP4_SETTINGS::flags to enable
  /// or disable VLAN for the network interface.
  IP4_BIT_VLAN,

  N_IP4_BIT  ///< number of defined flag bits
};


/**
 * @brief Bit masks used with ::IP4_SETTINGS::flags and ::LAN_IF_INFO::flags
 *
 * @see ::MBG_IP4_FLAG_BITS
 */
enum MBG_IP4_FLAG_MASKS
{
  IP4_MSK_DHCP = ( 1UL << IP4_BIT_DHCP ),  ///< see ::IP4_BIT_DHCP
  IP4_MSK_LINK = ( 1UL << IP4_BIT_LINK ),  ///< see ::IP4_BIT_LINK
  IP4_MSK_VLAN = ( 1UL << IP4_BIT_VLAN ),  ///< see ::IP4_BIT_VLAN
};

/** @} defgroup group_ip4_cfg */



/**
 * @defgroup group_ext_net_cfg_types Types used for extended network configuration and status
 *
 * @{ */

/**
 * @brief Enumeration of types used with ::MBG_IP_ADDR::type
 */
enum MBG_IP_ADDR_TYPES
{
  MBG_IP_ADDR_TYPE_UNKNOWN,
  MBG_IP_ADDR_TYPE_IP4,
  MBG_IP_ADDR_TYPE_IP6,
  N_MBG_IP_ADDR_TYPES
};

/*
 * Default initializers for English mode string names. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_IP_ADDR_TYPE_STR_ENG_UNKNOWN "unknown"
#define MBG_IP_ADDR_TYPE_STR_ENG_IP4     "IPv4"
#define MBG_IP_ADDR_TYPE_STR_ENG_IP6     "IPv6"

#define MBG_IP_ADDR_TYPE_NAMES_ENG  \
{                                   \
  MBG_IP_ADDR_TYPE_STR_ENG_UNKNOWN, \
  MBG_IP_ADDR_TYPE_STR_ENG_IP4,     \
  MBG_IP_ADDR_TYPE_STR_ENG_IP6      \
}


/**
 * @brief Feature flag bits used to define ::MBG_NET_GLB_CFG_INFO_MASKS
 *
 * @see ::MBG_NET_GLB_CFG_INFO_MASKS
 */
enum MBG_NET_GLB_CFG_INFO_FLAGS
{
  MBG_NET_GLB_SUPP_STAGE_2,     ///< Supports commands which have been added in stage 2
  MBG_NET_GLB_SUPP_BONDING,     ///< Supports bonding
  N_MBG_NET_GLB_INFO_FLAGS
};


/**
 * @brief Flag masks used with ::MBG_NET_GLB_CFG_INFO::feat_flags
 *
 * @see ::MBG_NET_GLB_CFG_INFO_FLAGS
 */
enum MBG_NET_GLB_CFG_INFO_MASKS
{
  MBG_NET_GLB_SUPP_STAGE_2_MASK  = (1UL << MBG_NET_GLB_SUPP_STAGE_2),  ///< see ::MBG_NET_GLB_SUPP_STAGE_2
  MBG_NET_GLB_SUPP_BONDING_MASK  = (1UL << MBG_NET_GLB_SUPP_BONDING)   ///< see ::MBG_NET_GLB_SUPP_BONDING
};



/**
 * @brief Network interface link speed mode enumeration
 *
 * @see @ref MBG_NET_INTF_LINK_SPEED_MODE_MASKS
 */
enum MBG_NET_INTF_LINK_SPEED_MODES
{
  MBG_NET_INTF_LINK_SPEED_MODE_UNKNOWN,              ///< Unknown speed mode
  MBG_NET_INTF_LINK_SPEED_MODE_10_T_HALF,            ///< 10baseT Half Duplex (10 MBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_10_T_FULL,            ///< 10baseT Full Duplex (10 MBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_100_T_HALF,           ///< 100baseT Half Duplex (100 MBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_100_T_FULL,           ///< 100baseT Full Duplex (100 MBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_1000_T_HALF,          ///< 1000baseT Half Duplex (1 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_1000_T_FULL,          ///< 1000baseT Full Duplex (1 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_1000_KX_FULL,         ///< 1000baseKX Full Duplex (1 GBit/s)

  MBG_NET_INTF_LINK_SPEED_MODE_2500_X_FULL,          ///< 2500baseX Full Duplex (2.5 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_10000_T_FULL,         ///< 10000baseT Full Duplex (10 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_10000_KX4_FULL,       ///< 10000baseKX4 Full Duplex (10 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_10000_KR_FULL,        ///< 10000baseKR Full Duplex (10 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_10000_R_FEC,          ///< 10000baseR FEC (forward error correction) (10 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_20000_MLD2_FULL,      ///< 20000baseMLD2 Full Duplex (20 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_20000_KR2_FULL,       ///< 20000baseKR2 Full Duplex (20 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_40000_KR4_FULL,       ///< 40000baseKR4 Full Duplex (40 GBit/s)

  MBG_NET_INTF_LINK_SPEED_MODE_40000_CR4_FULL,       ///< 40000baseCR4 Full Duplex (40 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_40000_SR4_FULL,       ///< 40000baseSR4 Full Duplex (40 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_40000_LR4_FULL,       ///< 40000baseLR4 Full Duplex (40 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_56000_KR4_FULL,       ///< 56000baseKR4 Full Duplex (56 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_56000_CR4_FULL,       ///< 56000baseCR4 Full Duplex (56 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_56000_SR4_FULL,       ///< 56000baseSR4 Full Duplex (56 GBit/s)
  MBG_NET_INTF_LINK_SPEED_MODE_56000_LR4_FULL,       ///< 56000baseLR4 Full Duplex (56 GBit/s)

  N_MBG_NET_INTF_LINK_SPEED_MODES
};



/**
 * @brief Network interface link speed mode masks
 *
 * @see ::MBG_NET_INTF_LINK_SPEED_MODES
 *
 * @anchor MBG_NET_INTF_LINK_SPEED_MODE_MASKS @{ */

#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_UNKNOWN          ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_UNKNOWN )           ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_UNKNOWN
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_10_T_HALF        ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_10_T_HALF )         ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_10_T_HALF
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_10_T_FULL        ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_10_T_FULL )         ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_10_T_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_100_T_HALF       ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_100_T_HALF )        ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_100_T_HALF
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_100_T_FULL       ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_100_T_FULL )        ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_100_T_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_1000_T_HALF      ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_1000_T_HALF )       ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_1000_T_HALF
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_1000_T_FULL      ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_1000_T_FULL )       ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_1000_T_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_1000_KX_FULL     ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_1000_KX_FULL )      ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_1000_KX_FULL

#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_2500_X_FULL      ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_2500_X_FULL )       ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_2500_X_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_10000_T_FULL     ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_10000_T_FULL )      ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_10000_T_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_10000_KX4_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_10000_KX4_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_10000_KX4_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_10000_KR_FULL    ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_10000_KR_FULL )     ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_10000_KR_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_10000_R_FEC      ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_10000_R_FEC )       ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_10000_R_FEC
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_20000_MLD2_FULL  ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_20000_MLD2_FULL )   ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_20000_MLD2_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_20000_KR2_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_20000_KR2_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_20000_KR2_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_40000_KR4_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_40000_KR4_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_40000_KR4_FULL

#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_40000_CR4_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_40000_CR4_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_40000_CR4_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_40000_SR4_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_40000_SR4_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_40000_SR4_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_40000_LR4_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_40000_LR4_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_40000_LR4_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_56000_KR4_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_56000_KR4_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_56000_KR4_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_56000_CR4_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_56000_CR4_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_56000_CR4_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_56000_SR4_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_56000_SR4_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_56000_SR4_FULL
#define MBG_NET_INTF_LINK_SPEED_MODE_MASK_56000_LR4_FULL   ( 1UL << MBG_NET_INTF_LINK_SPEED_MODE_56000_LR4_FULL )    ///< see ::MBG_NET_INTF_LINK_SPEED_MODE_56000_LR4_FULL

/** @} anchor MBG_NET_INTF_LINK_SPEED_MODE_MASKS */



/**
 * @brief Network interface link speeds [Mb/s]
 *
 * @see @ref MBG_NET_INTF_LINK_SPEED_MODE_MASKS
 */
enum MBG_NET_INTF_LINK_SPEEDS
{
  MBG_NET_INTF_LINK_SPEED_UNKNOWN = 0UL,
  MBG_NET_INTF_LINK_SPEED_10 = 10UL,
  MBG_NET_INTF_LINK_SPEED_100 = 100UL,
  MBG_NET_INTF_LINK_SPEED_1000 = 1000UL,
  MBG_NET_INTF_LINK_SPEED_2500 = 2500UL,
  MBG_NET_INTF_LINK_SPEED_10000 = 10000UL,
  MBG_NET_INTF_LINK_SPEED_20000 = 20000UL,
  MBG_NET_INTF_LINK_SPEED_40000 = 40000UL,
  MBG_NET_INTF_LINK_SPEED_56000 = 56000UL
};



/**
 * @brief Network interface link port types
 *
 * @see ::MBG_NET_INTF_LINK_PORT_TYPE_MASKS
 */
enum MBG_NET_INTF_LINK_PORT_TYPES
{
  MBG_NET_INTF_LINK_PORT_TYPE_UNKNOWN,    ///< Unknown port type
  MBG_NET_INTF_LINK_PORT_TYPE_TP,         ///< Twisted Pair (TP) copper cable
  MBG_NET_INTF_LINK_PORT_TYPE_FIBRE,      ///< Fibre Optic (FO) cable
  MBG_NET_INTF_LINK_PORT_TYPE_BNC,        ///< Coaxial BNC cable
  MBG_NET_INTF_LINK_PORT_TYPE_AUI,        ///< Attachment Unit Interface (AUI), externel transceiver
  MBG_NET_INTF_LINK_PORT_TYPE_MII,        ///< Media Independent Interface (MII), external receiver
  MBG_NET_INTF_LINK_PORT_TYPE_DA,         ///< Direct attach SFP+ connection
  N_MBG_NET_INTF_LINK_PORT_TYPES
};



/**
 * @brief Network interface link port masks
 *
 * @see ::MBG_NET_INTF_LINK_PORT_TYPES
 */
enum MBG_NET_INTF_LINK_PORT_TYPE_MASKS
{
  MBG_NET_INTF_LINK_PORT_TYPE_MASK_UNKNOWN  = ( 1UL << MBG_NET_INTF_LINK_PORT_TYPE_UNKNOWN ),     ///< see ::MBG_NET_INTF_LINK_PORT_TYPE_UNKNOWN
  MBG_NET_INTF_LINK_PORT_TYPE_MASK_TP       = ( 1UL << MBG_NET_INTF_LINK_PORT_TYPE_TP ),          ///< see ::MBG_NET_INTF_LINK_PORT_TYPE_TP
  MBG_NET_INTF_LINK_PORT_TYPE_MASK_FIBRE    = ( 1UL << MBG_NET_INTF_LINK_PORT_TYPE_FIBRE ),       ///< see ::MBG_NET_INTF_LINK_PORT_TYPE_FIBRE
  MBG_NET_INTF_LINK_PORT_TYPE_MASK_BNC      = ( 1UL << MBG_NET_INTF_LINK_PORT_TYPE_BNC ),         ///< see ::MBG_NET_INTF_LINK_PORT_TYPE_BNC
  MBG_NET_INTF_LINK_PORT_TYPE_MASK_AUI      = ( 1UL << MBG_NET_INTF_LINK_PORT_TYPE_AUI ),         ///< see ::MBG_NET_INTF_LINK_PORT_TYPE_AUI
  MBG_NET_INTF_LINK_PORT_TYPE_MASK_MII      = ( 1UL << MBG_NET_INTF_LINK_PORT_TYPE_MII ),         ///< see ::MBG_NET_INTF_LINK_PORT_TYPE_MII
  MBG_NET_INTF_LINK_PORT_TYPE_MASK_DA       = ( 1UL << MBG_NET_INTF_LINK_PORT_TYPE_DA )           ///< see ::MBG_NET_INTF_LINK_PORT_TYPE_DA
};



/**
 * @brief Initializers for network interface link port type long strings
 *
 * @see ::MBG_NET_INTF_LINK_PORT_TYPE
 */
#define MBG_NET_INTF_LINK_PORT_TYPE_LONG_STRS     \
{                                                 \
  "Unknown",                                      \
  "Twisted Pair",                                 \
  "Fibre Optic",                                  \
  "Coaxial BNC",                                  \
  "Attachment Unit Interface",                    \
  "Media Independent Interface",                  \
  "Direct Attach SFP+"                            \
}


/**
 * @brief Initializers for network interface link port type short strings
 *
 * @see ::MBG_NET_INTF_LINK_PORT_TYPE
 */
#define MBG_NET_INTF_LINK_PORT_TYPE_SHORT_STRS    \
{                                                 \
  "Unknown",                                      \
  "TP",                                           \
  "FO",                                           \
  "BNC",                                          \
  "AUI",                                          \
  "MII",                                          \
  "DA"                                            \
}



/**
 * @brief Network interface link state bits
 *
 * @see @ref MBG_NET_INTF_LINK_STATE_MASKS
 *
 * @note See official Linux kernel documentation
 * https://www.kernel.org/doc/Documentation/networking/operstates.txt
 * for states below and explanations. Windows supports this in nearly the same way
 * using similar names struct IP_ADAPTER_ADDRESSES which is explained at
 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa366058%28v=vs.85%29.aspx
 */
enum MBG_NET_INTF_LINK_STATE_BITS
{
  MBG_NET_INTF_LINK_STATE_BIT_UP,
  MBG_NET_INTF_LINK_STATE_BIT_RUNNING,
  MBG_NET_INTF_LINK_STATE_BIT_LOWER_UP,
  MBG_NET_INTF_LINK_STATE_BIT_DORMANT,
  MBG_NET_INTF_LINK_STATE_BIT_BROADCAST,
  MBG_NET_INTF_LINK_STATE_BIT_MULTICAST,
  MBG_NET_INTF_LINK_STATE_BIT_ALL_MULTI,
  MBG_NET_INTF_LINK_STATE_BIT_DEBUG,

  MBG_NET_INTF_LINK_STATE_BIT_LOOPBACK,
  MBG_NET_INTF_LINK_STATE_BIT_POINT_TO_POINT,
  MBG_NET_INTF_LINK_STATE_BIT_NO_ARP,
  MBG_NET_INTF_LINK_STATE_BIT_PROMISC,
  MBG_NET_INTF_LINK_STATE_BIT_MASTER,
  MBG_NET_INTF_LINK_STATE_BIT_SLAVE,
  MBG_NET_INTF_LINK_STATE_BIT_PORT_SEL,
  MBG_NET_INTF_LINK_STATE_BIT_AUTO_MEDIA,

  MBG_NET_INTF_LINK_STATE_BIT_ECHO,
  MBG_NET_INTF_LINK_STATE_BIT_DYNAMIC,
  MBG_NET_INTF_LINK_STATE_BIT_NO_TRAILERS,

  N_MBG_NET_INTF_LINK_STATE_BITS
};



/**
 * @brief Network interface link state masks
 *
 * @see ::MBG_NET_INTF_LINK_STATE_BITS (reclined to Linux' if.h, Windows is similiar)
 *
 * @anchor MBG_NET_INTF_LINK_STATE_MASKS @{ */

#define MBG_NET_INTF_LINK_STATE_MASK_UP              ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_UP )              ///< see ::MBG_NET_INTF_LINK_STATE_BIT_UP
#define MBG_NET_INTF_LINK_STATE_MASK_RUNNING         ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_RUNNING )         ///< see ::MBG_NET_INTF_LINK_STATE_BIT_RUNNING
#define MBG_NET_INTF_LINK_STATE_MASK_LOWER_UP        ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_LOWER_UP )        ///< see ::MBG_NET_INTF_LINK_STATE_BIT_LOWER_UP
#define MBG_NET_INTF_LINK_STATE_MASK_DORMANT         ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_DORMANT )         ///< see ::MBG_NET_INTF_LINK_STATE_BIT_DORMANT
#define MBG_NET_INTF_LINK_STATE_MASK_BROADCAST       ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_BROADCAST )       ///< see ::MBG_NET_INTF_LINK_STATE_BIT_BROADCAST
#define MBG_NET_INTF_LINK_STATE_MASK_MULTICAST       ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_MULTICAST )       ///< see ::MBG_NET_INTF_LINK_STATE_BIT_MULTICAST
#define MBG_NET_INTF_LINK_STATE_MASK_ALL_MULTI       ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_ALL_MULTI )       ///< see ::MBG_NET_INTF_LINK_STATE_BIT_ALL_MULTI
#define MBG_NET_INTF_LINK_STATE_MASK_DEBUG           ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_DEBUG )           ///< see ::MBG_NET_INTF_LINK_STATE_BIT_DEBUG

#define MBG_NET_INTF_LINK_STATE_MASK_LOOPBACK        ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_LOOPBACK )        ///< see ::MBG_NET_INTF_LINK_STATE_BIT_LOOPBACK
#define MBG_NET_INTF_LINK_STATE_MASK_POINT_TO_POINT  ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_POINT_TO_POINT )  ///< see ::MBG_NET_INTF_LINK_STATE_BIT_POINT_TO_POINT
#define MBG_NET_INTF_LINK_STATE_MASK_NO_ARP          ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_NO_ARP )          ///< see ::MBG_NET_INTF_LINK_STATE_BIT_NO_ARP
#define MBG_NET_INTF_LINK_STATE_MASK_PROMISC         ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_PROMISC )         ///< see ::MBG_NET_INTF_LINK_STATE_BIT_PROMISC
#define MBG_NET_INTF_LINK_STATE_MASK_MASTER          ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_MASTER )          ///< see ::MBG_NET_INTF_LINK_STATE_BIT_MASTER
#define MBG_NET_INTF_LINK_STATE_MASK_SLAVE           ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_SLAVE )           ///< see ::MBG_NET_INTF_LINK_STATE_BIT_SLAVE
#define MBG_NET_INTF_LINK_STATE_MASK_PORT_SEL        ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_PORT_SEL )        ///< see ::MBG_NET_INTF_LINK_STATE_BIT_PORT_SEL
#define MBG_NET_INTF_LINK_STATE_MASK_AUTO_MEDIA      ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_AUTO_MEDIA )      ///< see ::MBG_NET_INTF_LINK_STATE_BIT_AUTO_MEDIA

#define MBG_NET_INTF_LINK_STATE_MASK_ECHO            ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_ECHO )            ///< see ::MBG_NET_INTF_LINK_STATE_BIT_ECHO
#define MBG_NET_INTF_LINK_STATE_MASK_DYNAMIC         ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_DYNAMIC)          ///< see ::MBG_NET_INTF_LINK_STATE_BIT_DYNAMIC
#define MBG_NET_INTF_LINK_STATE_MASK_NO_TRAILERS     ( 1UL << MBG_NET_INTF_LINK_STATE_BIT_NO_TRAILERS)      ///< see ::MBG_NET_INTF_LINK_STATE_BIT_NO_TRAILERS

/** @} anchor MBG_NET_INTF_LINK_STATE_MASKS */



/**
 * @brief Network interface link option bits
 *
 * @see ::MBG_NET_INTF_LINK_OPT_MASKS
 */
enum MBG_NET_INTF_LINK_OPTS
{
  MBG_NET_INTF_LINK_OPT_CAN_SET_MAC,
  MBG_NET_INTF_LINK_OPT_CAN_SYNCE_IN,
  MBG_NET_INTF_LINK_OPT_CAN_SYNCE_OUT,
  MBG_NET_INTF_LINK_OPT_CAN_AUTONEG,
  MBG_NET_INTF_LINK_OPT_CAN_NTP_HW_TS,
  MBG_NET_INTF_LINK_OPT_CAN_PTP_HW_TS,
  N_MBG_NET_INTF_LINK_OPTS
};



/**
 * @brief Network interface link option masks
 *
 * @see ::MBG_NET_INTF_LINK_OPTS
 */
enum MBG_NET_INTF_LINK_OPT_MASKS
{
  MBG_NET_INTF_LINK_OPT_MASK_CAN_SET_MAC    = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_SET_MAC ),     ///< see ::MBG_NET_INTF_LINK_OPT_CAN_SET_MAC
  MBG_NET_INTF_LINK_OPT_MASK_CAN_SYNCE_IN   = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_SYNCE_IN ),    ///< see ::MBG_NET_INTF_LINK_OPT_CAN_SYNCE_IN
  MBG_NET_INTF_LINK_OPT_MASK_CAN_SYNCE_OUT  = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_SYNCE_OUT ),   ///< see ::MBG_NET_INTF_LINK_OPT_CAN_SYNCE_OUT
  MBG_NET_INTF_LINK_OPT_MASK_CAN_AUTONEG    = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_AUTONEG ),     ///< see ::MBG_NET_INTF_LINK_OPT_CAN_AUTONEG
  MBG_NET_INTF_LINK_OPT_MASK_CAN_NTP_HW_TS  = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_NTP_HW_TS ),   ///< see ::MBG_NET_INTF_LINK_OPT_CAN_NTP_HW_TS
  MBG_NET_INTF_LINK_OPT_MASK_CAN_PTP_HW_TS  = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_PTP_HW_TS )    ///< see ::MBG_NET_INTF_LINK_OPT_CAN_PTP_HW_TS
};



/**
 * @brief Network interface link bonding mode
 *
 * Used with ::MBG_NET_INTF_LINK_SETTINGS::bond_mode
 *
 * @note if_bonding.h contains bonding modes under Linux, found no hint under Windows.
 * BUT: Something similiar (concerning naming) can be configured under Windows
 * via GUI in device manager, if supported.
 */
enum MBG_NET_INTF_LINK_BOND_MODES
{
  MBG_NET_INTF_LINK_BOND_MODE_ROUNDROBIN,
  MBG_NET_INTF_LINK_BOND_MODE_ACTIVEBACKUP,
  MBG_NET_INTF_LINK_BOND_MODE_XOR,
  MBG_NET_INTF_LINK_BOND_MODE_BROADCAST,
  MBG_NET_INTF_LINK_BOND_MODE_8023AD,
  MBG_NET_INTF_LINK_BOND_MODE_TLB,
  MBG_NET_INTF_LINK_BOND_MODE_ALB,
  N_MBG_NET_INTF_LINK_BOND_MODES
};



/**
 * @brief Network interface link bonding mode masks
 *
 * @see ::MBG_NET_INTF_LINK_BOND_MODES
 */
enum MBG_NET_INTF_LINK_BOND_MODE_MASKS
{
  MBG_NET_INTF_LINK_BOND_MODE_MASK_ROUNDROBIN   = ( 1UL << MBG_NET_INTF_LINK_BOND_MODE_ROUNDROBIN ),    ///< see ::MBG_NET_INTF_LINK_BOND_MODE_ROUNDROBIN
  MBG_NET_INTF_LINK_BOND_MODE_MASK_ACTIVEBACKUP = ( 1UL << MBG_NET_INTF_LINK_BOND_MODE_ACTIVEBACKUP ),  ///< see ::MBG_NET_INTF_LINK_BOND_MODE_ACTIVEBACKUP
  MBG_NET_INTF_LINK_BOND_MODE_MASK_XOR          = ( 1UL << MBG_NET_INTF_LINK_BOND_MODE_XOR ),           ///< see ::MBG_NET_INTF_LINK_BOND_MODE_XOR
  MBG_NET_INTF_LINK_BOND_MODE_MASK_BROADCAST    = ( 1UL << MBG_NET_INTF_LINK_BOND_MODE_BROADCAST ),     ///< see ::MBG_NET_INTF_LINK_BOND_MODE_BROADCAST
  MBG_NET_INTF_LINK_BOND_MODE_MASK_8023AD       = ( 1UL << MBG_NET_INTF_LINK_BOND_MODE_8023AD ),        ///< see ::MBG_NET_INTF_LINK_BOND_MODE_8023AD
  MBG_NET_INTF_LINK_BOND_MODE_MASK_TLB          = ( 1UL << MBG_NET_INTF_LINK_BOND_MODE_TLB ),           ///< see ::MBG_NET_INTF_LINK_BOND_MODE_TLB
  MBG_NET_INTF_LINK_BOND_MODE_MASK_ALB          = ( 1UL << MBG_NET_INTF_LINK_BOND_MODE_ALB ),           ///< see ::MBG_NET_INTF_LINK_BOND_MODE_ALB
};



/**
 * @brief Network interface link bonding mode name strings
 *
 * @see ::MBG_NET_INTF_LINK_BOND_MODES
 */
#define MBG_NET_INTF_LINK_BOND_MODE_STRS    \
{                                           \
  "Round Robin",                            \
  "Active Backup",                          \
  "XOR",                                    \
  "Broadcast",                              \
  "802.3ad (LACP)",                         \
  "TLB",                                    \
  "ALB"                                     \
}



/**
 * @brief Network interface link bonding states
 *
 * Used with ::MBG_NET_INTF_LINK_SETTINGS::bond_state
 */
enum MBG_NET_INTF_LINK_BOND_STATES
{
  MBG_NET_INTF_LINK_BOND_STATE_ACTIVE,
  MBG_NET_INTF_LINK_BOND_STATE_BACKUP,
  N_MBG_NET_INTF_LINK_BOND_STATES
};


/**
 * @brief Network interface link type bits
 *
 * Used with ::MBG_NET_INTF_LINK_SETTINGS::type
 *
 * @see ::MBG_NET_INTF_LINK_TYPE_MASKS
 */
enum MBG_NET_INTF_LINK_TYPES
{
  MBG_NET_INTF_LINK_TYPE_PHYS,        ///< Real physical network interface
  MBG_NET_INTF_LINK_TYPE_VLAN,        ///< VLAN interface, assigned to physical interface
  MBG_NET_INTF_LINK_TYPE_BOND,        ///< Bonding interface, which acts as bonding master
  N_MBG_NET_INTF_LINK_TYPE_BITS
};


/**
 * @brief Network interface link type masks
 *
 * Used with ::MBG_NET_INTF_LINK_INFO::supp_types
 *
 * @see ::MBG_NET_INTF_LINK_TYPES
 */
enum MBG_NET_INTF_LINK_TYPE_MASKS
{
  MBG_NET_INTF_LINK_TYPE_MASK_PHYS       = ( 1UL << MBG_NET_INTF_LINK_TYPE_PHYS ),     ///< see ::MBG_NET_INTF_LINK_TYPE_PHYS
  MBG_NET_INTF_LINK_TYPE_MASK_VLAN       = ( 1UL << MBG_NET_INTF_LINK_TYPE_VLAN ),     ///< see ::MBG_NET_INTF_LINK_TYPE_VLAN
  MBG_NET_INTF_LINK_TYPE_MASK_BOND       = ( 1UL << MBG_NET_INTF_LINK_TYPE_BOND )      ///< see ::MBG_NET_INTF_LINK_TYPE_BOND
};


/**
 * @brief Network interface address bits
 *
 * @see ::MBG_NET_INTF_ADDR_MASKS
 *
 * Used with ::MBG_NET_INTF_ADDR_INFO::supp_flags and ::MBG_NET_INTF_ADDR_SETTINGS::flags
 */
enum MBG_NET_INTF_ADDR_BITS
{
  MBG_NET_INTF_ADDR_BIT_DHCP4,             ///< Address has been automatically assigned by DHCP via IPv4
  MBG_NET_INTF_ADDR_BIT_DHCP6,             ///< Address has been automatically assigned by DHCP via IPv6
  N_MBG_NET_INTF_ADDR_FLAGS
};



/**
 * @brief Network interface address masks
 *
 * @see ::MBG_NET_INTF_ADDR_BITS
 */
enum MBG_NET_INTF_ADDR_MASKS
{
  MBG_NET_INTF_ADDR_MASK_DHCP4        = ( 1UL << MBG_NET_INTF_ADDR_BIT_DHCP4 ),        ///< see ::MBG_NET_INTF_ADDR_BIT_DHCP4
  MBG_NET_INTF_ADDR_MASK_DHCP6        = ( 1UL << MBG_NET_INTF_ADDR_BIT_DHCP6 )         ///< see ::MBG_NET_INTF_ADDR_BIT_DHCP6
};


enum MBG_NET_INTF_ROUTE_TYPES
{
  MBG_NET_INTF_ROUTE_TYPE_UNKNOWN,
  MBG_NET_INTF_ROUTE_TYPE_DEFAULT_GATEWAY,
  MBG_NET_INTF_ROUTE_TYPE_DEST_GATEWAY,
  MBG_NET_INTF_ROUTE_TYPE_DEST_ADDR,
  N_MBG_NET_INTF_ROUTE_TYPES
};

/** @} defgroup group_ext_net_cfg_types */



/**
 * @defgroup group_ext_net_cfg Extended network configuration and status
 *
 * This is only supported if the flag ::GPS_HAS_NET_CFG is set
 * in ::RECEIVER_INFO::features.
 *
 * @{ */

/**
 * @brief Global network configuration settings
 */
typedef struct
{
  MBG_HOSTNAME hostname;      ///< hostname, eventually FQDN including domain name

  uint8_t num_intf_link;      ///< number of detected/configured physical network interfaces (links), see ::MBG_NET_INTF_LINK_INFO_IDX
  uint8_t num_intf_addr;      ///< number of configured interface addresses, see ::MBG_NET_INTF_ADDR_INFO_IDX
  uint8_t num_dns_srvr;       ///< number of configured DNS servers, see ::MBG_IP_ADDR_IDX
  uint8_t num_dns_srch_dom;   ///< number of configured DNS search domains, see ::MBG_NET_NAME_IDX
  uint8_t num_intf_route;     ///< number of configured interface routes, see ::MBG_NET_INTF_ROUTE_INFO_IDX

  uint8_t reserved;           ///< currently reserved, always 0
  uint16_t flags;             ///< currently reserved, always 0

} MBG_NET_GLB_CFG_SETTINGS;

#define _mbg_swab_net_glb_cfg_settings( _p )  \
do                                            \
{                                             \
  _mbg_swab32( &(_p)->flags );                \
} while ( 0 )


/**
 * @brief Global current network settings and supported features
 */
typedef struct
{
  MBG_NET_GLB_CFG_SETTINGS glb_settings;
  uint16_t n_supp_intf_link;              ///< max. number of supported physical network interfaces (links), see ::MBG_NET_INTF_LINK_SETTINGS_IDX, ::MBG_NET_INTF_LINK_INFO_IDX
  uint16_t n_supp_intf_addr;              ///< max. number of supported interface addresses, see ::MBG_NET_INTF_ADDR_SETTINGS_IDX, ::MBG_NET_INTF_ADDR_INFO_IDX
  uint16_t n_supp_dns_srvr;               ///< max. number of supported DNS server addresses, using ::MBG_IP_ADDR_IDX records
  uint16_t n_supp_dns_srch_dom;           ///< max. number of supported DNS search domain records, using ::MBG_NET_NAME_IDX records
  uint16_t n_supp_intf_route;             ///< max. number of supported interface routes, see ::MBG_NET_INTF_ROUTE_SETTINGS_IDX, ::MBG_NET_INTF_ROUTE_INFO_IDX
  uint16_t max_hostname_len;              ///< max. length of hostname including trailing 0; if set to 0, max. length is 256 (see rfc1123)
  uint32_t reserved_1;                    ///< currently reserved, always 0
  uint32_t reserved_2;                    ///< currently reserved, always 0
  uint32_t feat_flags;                    ///< Feature flags, see ::MBG_NET_GLB_CFG_INFO_MASKS
  uint32_t flags_2;                       ///< currently reserved, always 0

} MBG_NET_GLB_CFG_INFO;

#define _mbg_swab_net_glb_cfg_info( _p )                 \
do                                                       \
{                                                        \
  _mbg_swab_net_glb_cfg_settings( &(_p)->glb_settings ); \
  _mbg_swab16( &(_p)->n_supp_intf_link );                \
  _mbg_swab16( &(_p)->n_supp_intf_addr );                \
  _mbg_swab16( &(_p)->n_supp_dns_srvr );                 \
  _mbg_swab16( &(_p)->n_supp_dns_srch_dom );             \
  _mbg_swab16( &(_p)->n_supp_intf_route );               \
  _mbg_swab16( &(_p)->max_hostname_len );                \
  _mbg_swab32( &(_p)->reserved_1 );                      \
  _mbg_swab32( &(_p)->reserved_2 );                      \
  _mbg_swab32( &(_p)->feat_flags );                      \
  _mbg_swab32( &(_p)->flags_2 );                         \
} while ( 0 )



/**
 * @brief An IPv4 or IPv6 network address
 */
typedef struct
{
  uint8_t type;           ///< see ::MBG_IP_ADDR_TYPES
  uint8_t reserved_1;     ///< reserved, currently always 0 @todo Do we need this as scope indicator?
  uint16_t reserved_2;    ///< reserved, currently always 0

  union u_addr
  {
    IP4_ADDR ip4_addr;    ///< IPv4 address if ::MBG_IP_ADDR::type == MBG_IP_ADDR_TYPE_IP4
    IP6_ADDR ip6_addr;    ///< IPv6 address if ::MBG_IP_ADDR::type == MBG_IP_ADDR_TYPE_IP6
  } u_addr;

} MBG_IP_ADDR;

#define _mbg_swab_ip_addr( _p )                      \
do                                                   \
{                                                    \
  _mbg_swab8( &(_p)->type );                         \
  _mbg_swab8( &(_p)->reserved_1 );                   \
  _mbg_swab16( &(_p)->reserved_2 );                  \
                                                     \
  switch ( (_p)->type )                              \
  {                                                  \
    case MBG_IP_ADDR_TYPE_IP4:                       \
      _mbg_swab_ip4_addr( &(_p)->u_addr.ip4_addr );  \
      break;                                         \
                                                     \
    case MBG_IP_ADDR_TYPE_IP6:                       \
      _mbg_swab_ip6_addr( &(_p)->u_addr.ip6_addr );  \
      break;                                         \
  }                                                  \
                                                     \
} while ( 0 )



/**
 * @brief An IPv4 or IPv6 network address, plus index
 */
typedef struct
{
  uint16_t idx;
  MBG_IP_ADDR addr;      ///< network address

} MBG_IP_ADDR_IDX;

#define _mbg_swab_ip_addr_idx( _p )  \
do                                   \
{                                    \
  _mbg_swab16( &(_p)->idx );         \
  _mbg_swab_ip_addr( &(_p)->addr );  \
} while ( 0 )


/**
 * @brief An IPv4 or IPv6 network address plus UDP or TCP port number
 */
typedef struct
{
  MBG_IP_ADDR addr;  ///< see ::MBG_IP_ADDR

  uint16_t port;     ///< UDP or TCP port
  uint16_t flags;    ///< currently always 0
  //##+++++ TODO should the flags field indicate if the port is UDP and/or TCP?

} MBG_IP_ADDR_PORT;

#define _mbg_swab_ip_addr_port( _p )  \
do                                    \
{                                     \
  _mbg_swab_ip_addr( &(_p)->addr );   \
  _mbg_swab16( &(_p)->port );         \
  _mbg_swab16( &(_p)->flags );        \
} while ( 0 )



/**
 * @brief Network host or domain name
 */
typedef struct
{
  MBG_HOSTNAME name;

} MBG_NET_NAME;

#define _mbg_swab_net_name( _p )           \
do                                         \
{                                          \
  _mbg_swab_mbg_host_name( &(_p)->name );  \
} while ( 0 )



/**
 * @brief Network host or domain name, plus index
 */
typedef struct
{
  uint16_t idx;
  MBG_NET_NAME net_name;

} MBG_NET_NAME_IDX;

#define _mbg_swab_net_name_idx( _p )      \
do                                        \
{                                         \
  _mbg_swab16( &(_p)->idx );              \
  _mbg_swab_net_name( &(_p)->net_name );  \
} while ( 0 )



/**
 * @brief Physical network interface link specific settings
 */
typedef struct
{
  char          name[MBG_IFNAMSIZ]; ///< Interface name
  MBG_MAC_ADDR  mac_addr;           ///< Physical hardware address
  MBG_MAC_ADDR  broadcast;          ///< Physical broadcast address

  uint32_t      if_index;           ///< Interface index assigned by the kernel
  uint32_t      common_if_index;    ///< Common interface index assigned by the lib (associated with the MAC address),
                                    ///< Valid if ::MBG_NET_INTF_LINK_SETTINGS::type is ::MBG_NET_INTF_LINK_TYPE_PHYS
  uint32_t      ass_if_index;       ///< Interface index of the associated physical interface link,
                                    ///< Valid if ::MBG_NET_INTF_LINK_SETTINGS::type is ::MBG_NET_INTF_LINK_TYPE_VLAN

  uint32_t      flags;              ///< Reserved, currently 0
  uint32_t      states;             ///< see @ref MBG_NET_INTF_LINK_STATE_MASKS

  uint32_t      hw_type;            ///< Hardware type of interface (see linux/if_arp.h, i.e. ARPHRD_ETHER) ::TODO
  uint32_t      mtu;                ///< Max. packet size in bytes
  uint32_t      txqlen;             ///< Transmission queue length (number of packets)
  uint32_t      speed;              ///< Link speed in MBit/s

  uint8_t       type;               ///< see ::MBG_NET_INTF_LINK_TYPES
  uint8_t       duplex;             ///< Duplex mode, half (0) or full (1)
  uint8_t       autoneg;            ///< Indicates, whether autonegotiation is enabled or disabled
  uint8_t       port_type;          ///< see ::MBG_NET_INTF_LINK_PORT_TYPES

  uint8_t       bond_mode;          ///< Bonding mode, see ::MBG_NET_INTF_LINK_BOND_MODES
                                    ///< Valid if ::MBG_NET_INTF_LINK_STATE_MASK_MASTER is set in ::MBG_NET_INTF_LINK_SETTINGS::states
  uint8_t       bond_state;         ///< Status of this interface in the bonding group, see ::MBG_NET_INTF_LINK_BOND_STATES
                                    ///< Valid if MBG_NET_INTF_LINK_STATE_MASK_SLAVE is set in ::MBG_NET_INTF_LINK_SETTINGS::states
  uint16_t      bond_idx;           ///< Interface index of the bonding master link, see ::MBG_NET_INTF_LINK_SETTINGS::if_index
                                    ///< Valid, if MBG_NET_INTF_LINK_STATE_MASK_SLAVE is set in ::MBG_NET_INTF_LINK_SETTINGS::states

  uint16_t      vlan_cfg;           ///< VLAN configuration options, see ::MBG_VLAN_CFG
                                    ///< Valid if ::MBG_NET_INTF_LINK_SETTINGS::type is ::MBG_NET_INTF_LINK_TYPE_VLAN
  uint16_t      reserved_1;         ///< Reserved, currently 0

  uint32_t      reserved_2;         ///< Reserved, currently 0
  uint32_t      reserved_3;         ///< Reserved, currently 0

} MBG_NET_INTF_LINK_SETTINGS;

#define _mbg_swab_net_intf_link_settings( _p )  \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->if_index );               \
  _mbg_swab32( &(_p)->common_if_index );        \
  _mbg_swab32( &(_p)->ass_if_index );           \
  _mbg_swab32( &(_p)->flags );                  \
  _mbg_swab32( &(_p)->states );                 \
  _mbg_swab32( &(_p)->hw_type );                \
  _mbg_swab32( &(_p)->mtu );                    \
  _mbg_swab32( &(_p)->txqlen );                 \
  _mbg_swab32( &(_p)->speed );                  \
  _mbg_swab16( &(_p)->bond_idx );               \
  _mbg_swab16( &(_p)->vlan_cfg );               \
  _mbg_swab16( &(_p)->reserved_1 );             \
  _mbg_swab32( &(_p)->reserved_2 );             \
  _mbg_swab32( &(_p)->reserved_3 );             \
} while ( 0 )



/**
 * @brief Link (physical interface) specific settings, plus index
 */
typedef struct
{
  uint16_t idx;              ///< 0..::MBG_NET_GLB_CFG_INFO::n_supp_intf_link-1
  MBG_NET_INTF_LINK_SETTINGS settings;

} MBG_NET_INTF_LINK_SETTINGS_IDX;

#define _mbg_swab_net_intf_link_settings_idx( _p )     \
do                                                     \
{                                                      \
  _mbg_swab16( &(_p)->idx );                           \
  _mbg_swab_net_intf_link_settings( &(_p)->settings ); \
} while ( 0 )



/**
 * @brief Link (physical interface) specific settings, flags and supported features
 */
typedef struct
{
  MBG_NET_INTF_LINK_SETTINGS    link_settings;       ///< see ::MBG_NET_INTF_LINK_SETTINGS
  uint32_t                      supp_flags;          ///< Reserved, currently 0
  uint32_t                      supp_states;         ///< see @ref MBG_NET_INTF_LINK_STATE_MASKS
  uint32_t                      supp_types;          ///< see ::MBG_NET_INTF_LINK_TYPE_MASKS
  uint32_t                      supp_speed_modes;    ///< see @ref MBG_NET_INTF_LINK_SPEED_MODE_MASKS
  uint32_t                      supp_port_types;     ///< see ::MBG_NET_INTF_LINK_PORT_TYPE_MASKS
  uint32_t                      supp_opts;           ///< see ::MBG_NET_INTF_LINK_OPT_MASKS
  uint32_t                      supp_bond_modes;     ///< see ::MBG_NET_INTF_LINK_BOND_MODE_MASKS
  uint32_t                      reserved_1;
  uint32_t                      reserved_2;
  uint32_t                      reserved_3;
  uint32_t                      reserved_4;
} MBG_NET_INTF_LINK_INFO;

#define _mbg_swab_net_intf_link_info( _p )                   \
do                                                           \
{                                                            \
  _mbg_swab_net_intf_link_settings( &(_p)->link_settings );  \
  _mbg_swab32( &(_p)->supp_flags );                          \
  _mbg_swab32( &(_p)->supp_states );                         \
  _mbg_swab32( &(_p)->supp_types );                          \
  _mbg_swab32( &(_p)->supp_speed_modes );                    \
  _mbg_swab32( &(_p)->supp_port_types );                     \
  _mbg_swab32( &(_p)->supp_opts );                           \
  _mbg_swab32( &(_p)->supp_bond_modes );                     \
  _mbg_swab32( &(_p)->reserved_1 );                          \
  _mbg_swab32( &(_p)->reserved_2 );                          \
  _mbg_swab32( &(_p)->reserved_3 );                          \
  _mbg_swab32( &(_p)->reserved_4 );                          \
} while ( 0 )



/**
 * @brief Query MBG_NET_INTF_LINK_INFO by its index
 */
typedef struct
{
  uint16_t idx;                       ///< 0..::MBG_NET_GLB_CFG_SETTINGS::num_intf_link-1
  MBG_NET_INTF_LINK_INFO info;        ///< see ::MBG_NET_INTF_LINK_INFO

} MBG_NET_INTF_LINK_INFO_IDX;

#define _mbg_swab_net_intf_link_info_idx( _p )  \
do                                              \
{                                               \
  _mbg_swab16( &(_p)->idx );                    \
  _mbg_swab_net_intf_link_info( &(_p)->info );  \
} while ( 0 )


/**
 * @brief Network interface address specific settings, flags and supported features
 *
 * @note Use if_index to identify uniquely its associated network link.
 */
typedef struct
{
  char          label[MBG_IFNAMSIZ];  ///< Interface label

  uint32_t      addr_index;           ///< Index of the address on the physical interface it is assigned to
  uint32_t      ass_if_index;         ///< Index of the associated interface link, see ::MBG_NET_INTF_LINK_SETTINGS::if_index

  uint32_t      flags;                ///< see ::MBG_NET_INTF_ADDR_MASKS

  MBG_IP_ADDR   ip;                   ///< IP address associated with this interface
  MBG_IP_ADDR   broadcast;            ///< Broadcast address associated with this interface

  uint8_t       prefix_bits;          ///< Number of subnet mask bits for CIDR notation, e.g. 24 for /24
  uint8_t       reserved_1;           ///< Reserved, currently 0
  uint16_t      reserved_2;           ///< Reserved, currently 0

  uint32_t      reserved_3;           ///< Reserved, currently 0
  uint32_t      reserved_4;           ///< Reserved, currently 0
  uint32_t      reserved_5;           ///< Reserved, currently 0

} MBG_NET_INTF_ADDR_SETTINGS;

#define _mbg_swab_net_intf_addr_settings( _p )  \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->addr_index );             \
  _mbg_swab32( &(_p)->ass_if_index );           \
  _mbg_swab32( &(_p)->flags );                  \
  _mbg_swab_ip_addr( &(_p)->ip );               \
  _mbg_swab_ip_addr( &(_p)->broadcast );        \
  _mbg_swab16( &(_p)->reserved_2 );             \
  _mbg_swab32( &(_p)->reserved_3 );             \
  _mbg_swab32( &(_p)->reserved_4 );             \
  _mbg_swab32( &(_p)->reserved_5 );             \
} while ( 0 )


/**
 * @brief Query MBG_NET_INTF_ADDR_SETTINGS by its index
 */
typedef struct
{
  uint16_t idx;                               ///< 0..::MBG_NET_GLB_CFG_SETTINGS::num_intf_addr-1
  MBG_NET_INTF_ADDR_SETTINGS settings;        ///< see ::MBG_NET_INTF_ADDR_SETTINGS

} MBG_NET_INTF_ADDR_SETTINGS_IDX;

#define _mbg_swab_net_intf_addr_settings_idx( _p )      \
do                                                      \
{                                                       \
  _mbg_swab16( &(_p)->idx );                            \
  _mbg_swab_net_intf_addr_settings( &(_p)->settings );  \
} while ( 0 )


/**
 * @brief Network interface address specific settings, flags and supported features
 */
typedef struct
{
  MBG_NET_INTF_ADDR_SETTINGS addr_settings;   ///< see ::MBG_NET_INTF_ADDR_SETTINGS
  uint32_t supp_flags;                        ///< see ::MBG_NET_INTF_ADDR_MASKS
  uint32_t reserved_1;                        ///< Reserved, currently 0
  uint32_t reserved_2;                        ///< Reserved, currently 0

} MBG_NET_INTF_ADDR_INFO;

#define _mbg_swab_net_intf_addr_info( _p )                   \
do                                                           \
{                                                            \
  _mbg_swab_net_intf_addr_settings( &(_p)->addr_settings );  \
  _mbg_swab32( &(_p)->supp_flags );                          \
  _mbg_swab32( &(_p)->reserved_1 );                          \
  _mbg_swab32( &(_p)->reserved_2 );                          \
} while ( 0 )


/**
 * @brief Query MBG_NET_INTF_ADDR_INFO by its index
 */
typedef struct
{
  uint16_t idx;                   ///< 0..::MBG_NET_GLB_CFG_SETTINGS::num_intf_addr-1
  MBG_NET_INTF_ADDR_INFO info;    ///< see ::MBG_NET_INTF_ADDR_INFO

} MBG_NET_INTF_ADDR_INFO_IDX;

#define _mbg_swab_net_intf_addr_info_idx( _p )  \
do                                              \
{                                               \
  _mbg_swab16( &(_p)->idx );                    \
  _mbg_swab_net_intf_addr_info( &(_p)->info );  \
} while ( 0 )


/**
 * @brief Network interface route specific settings
 *
 * @note Use link_mac and ass_addr_idx to identify the associated network address and network link (via address)
 */
typedef struct
{
  uint8_t type;                   ///< Type of the route entry, see ::MBG_NET_INTF_ROUTE_TYPES
  uint8_t reserved_1;             ///< Reserved, currently 0
  uint16_t reserved_2;            ///< Reserved, currently 0

  MBG_IP_ADDR gateway;            ///< Gateway IP address, only used if type is
                                  ///< ::MBG_NET_INTF_ROUTE_TYPE_DEFAULT_GATEWAY or ::MBG_NET_INTF_ROUTE_TYPE_DEST_GATEWAY
  MBG_IP_ADDR dst;                ///< Destination IP address, only used if ::MBG_NET_INTF_ROUTE_SETTINGS::type is
                                  ///< ::MBG_NET_INTF_ROUTE_TYPE_DEST_GATEWAY or ::MBG_NET_INTF_ROUTE_TYPE_DEST_ADDR
  uint8_t dst_prefix_bits;        ///< Prefix Bits for the destination address

  uint32_t ass_if_index;          ///< Index of the associated interface link, see ::MBG_NET_INTF_LINK_SETTINGS::if_index
  uint32_t ass_addr_index;        ///< Index of the associated interface address, see ::MBG_NET_INTF_ADDR_SETTINGS::addr_index,
                                  ///< Valid if ::MBG_NET_INTF_ROUTE_SETTINGS::type is ::MBG_NET_INTF_ROUTE_TYPE_DEST_GATEWAY or ::MBG_NET_INTF_ROUTE_TYPE_DEST_ADDR

  uint32_t reserved_3;            ///< Reserved, currently 0
  uint32_t reserved_4;            ///< Reserved, currently 0
  uint32_t reserved_5;            ///< Reserved, currently 0

} MBG_NET_INTF_ROUTE_SETTINGS;

#define _mbg_swab_net_intf_route_settings( _p )  \
do                                               \
{                                                \
  _mbg_swab16( &(_p)->reserved_2 );              \
  _mbg_swab_ip_addr( &(_p)->gateway );           \
  _mbg_swab_ip_addr( &(_p)->dst );               \
  _mbg_swab32( &(_p)->ass_if_index );            \
  _mbg_swab32( &(_p)->ass_addr_index );          \
  _mbg_swab32( &(_p)->reserved_3 );              \
  _mbg_swab32( &(_p)->reserved_4 );              \
  _mbg_swab32( &(_p)->reserved_5 );              \
} while ( 0 )


/**
 * @brief Query MBG_NET_INTF_ROUTE_SETTINGS by its index
 */
typedef struct
{
  uint16_t idx;                                 ///< 0..::MBG_NET_GLB_CFG_SETTINGS::num_intf_route-1
  MBG_NET_INTF_ROUTE_SETTINGS settings;         ///< see ::MBG_NET_INTF_ROUTE_SETTINGS

} MBG_NET_INTF_ROUTE_SETTINGS_IDX;

#define _mbg_swab_net_intf_route_settings_idx( _p )      \
do                                                       \
{                                                        \
  _mbg_swab16( &(_p)->idx );                             \
  _mbg_swab_net_intf_route_settings( &(_p)->settings );  \
} while ( 0 )


/**
 * @brief Network interface address specific settings
 */
typedef struct
{
  MBG_NET_INTF_ROUTE_SETTINGS route_settings;   ///< see ::MBG_NET_INTF_ROUTE_SETTINGS
  uint32_t reserved_1;                          ///< Reserved, currently 0
  uint32_t reserved_2;                          ///< Reserved, currently 0
  uint32_t reserved_3;                          ///< Reserved, currently 0
  uint32_t reserved_4;                          ///< Reserved, currently 0
} MBG_NET_INTF_ROUTE_INFO;

#define _mbg_swab_net_intf_route_info( _p )                    \
do                                                                        \
{                                                              \
  _mbg_swab_net_intf_route_settings( &(_p)->route_settings );  \
  _mbg_swab32( &(_p)->reserved_1 );                            \
  _mbg_swab32( &(_p)->reserved_2 );                            \
  _mbg_swab32( &(_p)->reserved_3 );                            \
  _mbg_swab32( &(_p)->reserved_4 );                            \
} while ( 0 )


/**
 * @brief Query MBG_NET_INTF_ROUTE_INFO by its index
 */
typedef struct
{
  uint16_t idx;                                 ///< 0..::MBG_NET_GLB_CFG_SETTINGS::num_intf_route-1
  MBG_NET_INTF_ROUTE_INFO info;                 ///< see ::MBG_NET_INTF_ROUTE_INFO

} MBG_NET_INTF_ROUTE_INFO_IDX;

#define _mbg_swab_net_intf_route_info_idx( _p )  \
do                                               \
{                                                \
  _mbg_swab16( &(_p)->idx );                     \
  _mbg_swab_net_intf_route_info( &(_p)->info );  \
} while ( 0 )


/** @} defgroup group_ext_net_cfg */

/** @} defgroup group_net_cfg */





/**
 * @defgroup group_ucap_net User Captures via Network
 *
 * @note Group for the user capture via network feature
 * Only supported if ::MBG_XFEATURE_UCAP_NET is set in extended features
 * Corresponding GPS commands are ::GPS_UCAP_NET_GLB_INFO and ::GPS_UCAP_NET_RECV_INFO_IDX
 *
 * @{ */


#define MBG_UCAP_NET_DEFAULT_UDP_PORT               50815

/**
 * @brief Transfer mode for user captures via network
 *
 * @see ::MBG_UCAP_NET_TRANSF_MODE_MASKS
 *
 * Used with ::MBG_UCAP_NET_RECV_SETTINGS::mode
 */
enum MBG_UCAP_NET_TRANSF_MODE
{
  MBG_UCAP_NET_TRANSF_MODE_UNKNOWN,                 ///< Unknown transfer mode
  MBG_UCAP_NET_TRANSF_MODE_ON_REQ,                  ///< User captures will be transferred on request only
  MBG_UCAP_NET_TRANSF_MODE_AUTO,                    ///< User captures are being transferred automatically
  N_MBG_UCAP_NET_TRANSF_MODES
};


/**
 * @brief Masks for transfer mode used with ::MBG_UCAP_NET_GLB_INFO::supp_modes
 *
 * @see ::MBG_UCAP_NET_TRANSF_MODE
 */
enum MBG_UCAP_NET_TRANSF_MODE_MASKS
{
  MBG_UCAP_NET_TRANSF_MODE_MASK_UNKNOWN             = ( 1UL << MBG_UCAP_NET_TRANSF_MODE_UNKNOWN ),  ///< see ::MBG_UCAP_NET_TRANSF_MODE_UNKNOWN
  MBG_UCAP_NET_TRANSF_MODE_MASK_ON_REQ              = ( 1UL << MBG_UCAP_NET_TRANSF_MODE_ON_REQ ),   ///< see ::MBG_UCAP_NET_TRANSF_MODE_ON_REQ
  MBG_UCAP_NET_TRANSF_MODE_MASK_AUTO                = ( 1UL << MBG_UCAP_NET_TRANSF_MODE_AUTO )      ///< see ::MBG_UCAP_NET_TRANSF_MODE_AUTO
};



/**
 * @brief Transfer protocol for user captures via network
 *
 * @see ::MBG_UCAP_NET_TRANSF_PROTO_MASKS
 *
 * Used with ::MBG_UCAP_NET_RECV_SETTINGS::proto
 */
enum MBG_UCAP_NET_TRANSF_PROTO
{
  MBG_UCAP_NET_TRANSF_PROTO_UNKNOWN,                ///< Unknown transfer mode
  MBG_UCAP_NET_TRANSF_PROTO_UDP,                    ///< User captures are transferred via UDP
  N_MBG_UCAP_NET_TRANSF_PROTOS
};


/**
 * @brief Masks for transfer protocol used with ::MBG_UCAP_NET_GLB_INFO::supp_protos
 *
 * @see ::MBG_UCAP_NET_TRANSF_PROTO
 */
enum MBG_UCAP_NET_TRANSF_PROTO_MASKS
{
  MBG_UCAP_NET_TRANSF_PROTO_MASK_UNKNOWN            = ( 1UL << MBG_UCAP_NET_TRANSF_PROTO_UNKNOWN ), ///< see ::MBG_UCAP_NET_TRANSF_PROTO_UNKNOWN
  MBG_UCAP_NET_TRANSF_PROTO_MASK_UDP                = ( 1UL << MBG_UCAP_NET_TRANSF_PROTO_UDP )      ///< see ::MBG_UCAP_NET_TRANSF_PROTO_UDP
};



/**
 * @brief Supported flags for user captures via network
 *
 * @see ::MBG_UCAP_NET_SUPP_FLAG_MASKS
 */
enum MBG_UCAP_NET_SUPP_FLAGS
{
  MBG_UCAP_NET_SUPP_FLAG_IPV6,
  N_MBG_UCAP_NET_SUPP_FLAGS
};


/**
 * @brief Masks for supported flags used with ::MBG_UCAP_NET_GLB_INFO::supp_flags
 *
 * @see ::MBG_UCAP_NET_TRANSF_PROTO
 */
enum MBG_UCAP_NET_SUPP_FLAG_MASKS
{
  MBG_UCAP_NET_SUPP_FLAG_MASK_IPV6                  = ( 1UL << MBG_UCAP_NET_SUPP_FLAG_IPV6 )        ///< see ::MBG_UCAP_NET_SUPP_FLAG_IPV6
};


/**
 * @brief Global settings for user captures via network
 *
 * @note This structure shall be used to set the current global settings of a device
 * with GPS command ::GPS_UCAP_NET_GLB_INFO.
 */
typedef struct
{
  uint32_t num_recvs;                       ///< Number of configured network receivers, see ::MBG_UCAP_NET_RECV_INFO_IDX
  uint32_t reserved_0;                      ///< Reserved, currently always 0
  uint32_t reserved_1;                      ///< Reserved, currently always 0
  uint32_t reserved_2;                      ///< Reserved, currently always 0

} MBG_UCAP_NET_GLB_SETTINGS;


#define _mbg_swab_ucap_net_glb_settings( _p )  \
do                                             \
{                                              \
  _mbg_swab32( &(_p)->num_recvs );             \
  _mbg_swab32( &(_p)->reserved_0 );            \
  _mbg_swab32( &(_p)->reserved_1 );            \
  _mbg_swab32( &(_p)->reserved_2 );            \
} while ( 0 )



/**
 * @brief Global settings, features and flags for user captures via network
 *
 * @note This structure shall be used to read the current global settings from a device
 * with GPS command ::GPS_UCAP_NET_GLB_INFO.
 */
typedef struct
{
  MBG_UCAP_NET_GLB_SETTINGS settings;       ///< see ::MBG_UCAP_NET_GLB_SETTINGS

  uint32_t n_supp_recvs;                    ///< Number of supported network receivers, see ::MBG_UCAP_NET_RECV_INFO_IDX
  uint32_t supp_modes;                      ///< Supported transfer modes, see ::MBG_UCAP_NET_TRANSF_MODE_MASKS
  uint32_t supp_protos;                     ///< Supported transfer protocols, see ::MBG_UCAP_NET_TRANSF_PROTO_MASKS
  uint32_t reserved_0;                      ///< Reserved, currently always 0
  uint32_t reserved_1;                      ///< Reserved, currently always 0
  uint32_t supp_flags;                      ///< Supported flags, see ::MBG_UCAP_NET_SUPP_FLAG_MASKS

} MBG_UCAP_NET_GLB_INFO;


#define _mbg_swab_ucap_net_glb_info( _p )               \
do                                                      \
{                                                       \
  _mbg_swab_ucap_net_glb_settings( &(_p)->settings );   \
  _mbg_swab32( &(_p)->n_supp_recvs );                   \
  _mbg_swab32( &(_p)->supp_modes );                     \
  _mbg_swab32( &(_p)->supp_protos );                    \
  _mbg_swab32( &(_p)->reserved_0 );                     \
  _mbg_swab32( &(_p)->reserved_1 );                     \
  _mbg_swab32( &(_p)->supp_flags );                     \
} while ( 0 )



/**
 * @brief Settings for receivers of user captures via network
 */
typedef struct
{
  uint8_t mode;                             ///< Transfer mode, see ::MBG_UCAP_NET_TRANSF_MODE
  uint8_t proto;                            ///< Transfer protocol, see ::MBG_UCAP_NET_TRANSF_PROTO
  uint16_t reserved_1;                      ///< Reserved, currently always 0

  uint32_t reserved_2;                      ///< Reserved, currently always 0
  uint32_t reserved_3;                      ///< Reserved, currently always 0
  uint32_t ucaps;                           ///< Bit mask for active user captures

  MBG_IP_ADDR_PORT addr;                    ///< Destination IP and port address of the network receiver, see ::MBG_IP_ADDR_PORT

} MBG_UCAP_NET_RECV_SETTINGS;


#define _mbg_swab_ucap_net_recv_settings( _p )          \
do                                                      \
{                                                       \
  _mbg_swab16( &(_p)->reserved_1 );                     \
  _mbg_swab32( &(_p)->reserved_2 );                     \
  _mbg_swab32( &(_p)->reserved_3 );                     \
  _mbg_swab32( &(_p)->ucaps );                          \
  _mbg_swab_ip_addr_port( &(_p)->addr );                \
} while ( 0 )



/**
 * @brief Settings for receivers of user captures via network
 *
 * @note This structure shall be used to write the settings to the device
 * with GPS command ::GPS_UCAP_NET_RECV_INFO_IDX.
 * This can be done for index 0 to ::MBG_UCAP_NET_GLB_SETTINGS::num_recvs-1.
 *
 * @see ::MBG_UCAP_NET_RECV_SETTINGS
 */
typedef struct
{
  uint16_t idx;                             ///< 0..::MBG_UCAP_NET_GLB_SETTINGS::num_recvs-1
  MBG_UCAP_NET_RECV_SETTINGS settings;      ///< see ::MBG_UCAP_NET_RECV_SETTINGS

} MBG_UCAP_NET_RECV_SETTINGS_IDX;


#define _mbg_swab_ucap_net_recv_settings_idx( _p )      \
do                                                      \
{                                                       \
  _mbg_swab16( &(_p)->idx );                            \
  _mbg_swab_ucap_net_recv_settings( &(_p)->settings );  \
} while ( 0 )



/**
 * @brief Settings, features and flags for receivers of user captures via network
 */
typedef struct
{
  MBG_UCAP_NET_RECV_SETTINGS settings;      ///< see ::MBG_UCAP_NET_RECV_SETTINGS

  uint32_t reserved_0;                      ///< Reserved, currently always 0
  uint32_t reserved_1;                      ///< Reserved, currently always 0
  uint32_t reserved_2;                      ///< Reserved, currently always 0
  uint32_t reserved_3;                      ///< Reserved, currently always 0

} MBG_UCAP_NET_RECV_INFO;


#define _mbg_swab_ucap_net_recv_info( _p )              \
do                                                      \
{                                                       \
  _mbg_swab_ucap_net_recv_settings( &(_p)->settings );  \
  _mbg_swab32( &(_p)->reserved_0 );                     \
  _mbg_swab32( &(_p)->reserved_1 );                     \
  _mbg_swab32( &(_p)->reserved_2 );                     \
  _mbg_swab32( &(_p)->reserved_3 );                     \
} while ( 0 )



/**
 * @brief Settings, features and flags for receivers of user captures via network
 *
 * @note This structure shall be used to read the current settings from the device
 * with GPS command ::GPS_UCAP_NET_RECV_INFO_IDX.
 * This can be done for index 0 to ::MBG_UCAP_NET_GLB_SETTINGS::num_recvs-1.
 *
 * @see ::MBG_UCAP_NET_RECV_INFO
 */
typedef struct
{
  uint16_t idx;                             ///< 0..::MBG_UCAP_NET_GLB_INFO::n_supp_recvs-1
  MBG_UCAP_NET_RECV_INFO info;              ///< see ::MBG_UCAP_NET_RECV_INFO

} MBG_UCAP_NET_RECV_INFO_IDX;


#define _mbg_swab_ucap_net_recv_info_idx( _p )  \
do                                              \
{                                               \
  _mbg_swab16( &(_p)->idx );                    \
  _mbg_swab_ucap_net_recv_info( &(_p)->info );  \
} while ( 0 )

/** @} defgroup ext_ucap */



/**
 * @defgroup group_ptp Definitions used with PTP/IEEE1588
 *
 * @{ */

/**
 * @brief Enumeration of protocols possibly used with PTP
 *
 * @see ::PTP_NW_PROT_MASKS
 */
enum PTP_NW_PROTS
{
  PTP_NW_PROT_RESERVED,      ///< reserved
  PTP_NW_PROT_UDP_IPV4,      ///< IPv4
  PTP_NW_PROT_UDP_IPV6,      ///< IPv6
  PTP_NW_PROT_IEEE_802_3,    ///< Ethernet (raw layer 2)
  PTP_NW_PROT_DEVICE_NET,    ///< DeviceNet
  PTP_NW_PROT_CONTROL_NET,   ///< ControlNet
  PTP_NW_PROT_PROFINET,      ///< ProfiNet
  N_PTP_NW_PROT              ///< number of defined protocols
};


/**
 * @brief Bit masks for enumerated protocols possibly used with PTP
 *
 * @see ::PTP_NW_PROTS
 */
enum PTP_NW_PROT_MASKS
{
  PTP_NW_PROT_MSK_RESERVED    = ( 1UL << PTP_NW_PROT_RESERVED ),    ///< see ::PTP_NW_PROT_RESERVED
  PTP_NW_PROT_MSK_UDP_IPV4    = ( 1UL << PTP_NW_PROT_UDP_IPV4 ),    ///< see ::PTP_NW_PROT_UDP_IPV4
  PTP_NW_PROT_MSK_UDP_IPV6    = ( 1UL << PTP_NW_PROT_UDP_IPV6 ),    ///< see ::PTP_NW_PROT_UDP_IPV6
  PTP_NW_PROT_MSK_IEEE_802_3  = ( 1UL << PTP_NW_PROT_IEEE_802_3 ),  ///< see ::PTP_NW_PROT_IEEE_802_3
  PTP_NW_PROT_MSK_DEVICE_NET  = ( 1UL << PTP_NW_PROT_DEVICE_NET ),  ///< see ::PTP_NW_PROT_DEVICE_NET
  PTP_NW_PROT_MSK_CONTROL_NET = ( 1UL << PTP_NW_PROT_CONTROL_NET ), ///< see ::PTP_NW_PROT_CONTROL_NET
  PTP_NW_PROT_MSK_PROFINET    = ( 1UL << PTP_NW_PROT_PROFINET )     ///< see ::PTP_NW_PROT_PROFINET
};



/**
 * @brief Name strings for the protocols possibly used with PTP
 *
 * @see ::PTP_NW_PROTS
 */
#define PTP_NW_PROT_STRS   \
{                          \
  "Reserved",              \
  "UDP/IPv4 (L3)",         \
  "UDP/IPv6 (L3)",         \
  "IEEE 802.3 (L2)",       \
  "DeviceNet",             \
  "ControlNet",            \
  "PROFINET"               \
}


/**
 * @brief Short name strings for the protocols possibly used with PTP
 *
 * @see ::PTP_NW_PROTS
 */
#define PTP_NW_PROT_STRS_SHORT \
{                              \
  "RSV",                       \
  "IP4",                       \
  "IP6",                       \
  "ETH",                       \
  "DN",                        \
  "CN",                        \
  "PN"                         \
}


/**
 * @brief Possible states of a PTP port
 */
enum PTP_PORT_STATES
{
  PTP_PORT_STATE_UNINITIALIZED,  ///< uninitialized
  PTP_PORT_STATE_INITIALIZING,   ///< currently initializing
  PTP_PORT_STATE_FAULTY,         ///< faulty
  PTP_PORT_STATE_DISABLED,       ///< disabled
  PTP_PORT_STATE_LISTENING,      ///< listening for PTP packets
  PTP_PORT_STATE_PRE_MASTER,     ///< going to become master
  PTP_PORT_STATE_MASTER,         ///< master
  PTP_PORT_STATE_PASSIVE,        ///< passive
  PTP_PORT_STATE_UNCALIBRATED,   ///< uncalibrated
  PTP_PORT_STATE_SLAVE,          ///< slave
  N_PTP_PORT_STATE               ///< number of defined port states
};


/**
 * @brief Name strings for the PTP port states
 */
#define PTP_PORT_STATE_STRS   \
{                             \
  "UNINITIALIZED",            \
  "INITIALIZING",             \
  "FAULTY",                   \
  "DISABLED",                 \
  "LISTENING",                \
  "PRE_MASTER",               \
  "MASTER",                   \
  "PASSIVE",                  \
  "UNCALIBRATED",             \
  "SLAVE"                     \
}


/**
 * @brief An entry for a table of parameters which can not be accessed by an enumerated index
 */
typedef struct
{
  uint8_t value;      ///< the parameter value
  const char *name;   ///< the parameter name

} PTP_TABLE;



/**
 * @brief An enumeration of PTP delay mechanisms
 *
 * @note This is different than the numeric values specified
 * in the published specs for IEEE1588. In addition, the specs
 * define code 0x14 for "disabled".
 *
 * @see ::PTP_DELAY_MECH_MASKS
 * @see ::PTP_DELAY_MECH_NAMES
 */
enum PTP_DELAY_MECHS
{
  PTP_DELAY_MECH_E2E,  ///< End-to-End (in PTP2 specs: 0x01)
  PTP_DELAY_MECH_P2P,  ///< Peer-to-Peer (in PTP2 specs: 0x02)
  N_PTP_DELAY_MECH     ///< number of defined delay mechanisms
};


/**
 * @brief Bit masks associated with enumerated PTP delay mechanisms
 *
 * @see ::PTP_DELAY_MECH_MASKS
 */
enum PTP_DELAY_MECH_MASKS
{
  PTP_DELAY_MECH_MSK_E2E = ( 1UL << PTP_DELAY_MECH_E2E ),  ///< see ::PTP_DELAY_MECH_E2E
  PTP_DELAY_MECH_MSK_P2P = ( 1UL << PTP_DELAY_MECH_P2P )   ///< see ::PTP_DELAY_MECH_P2P
};


#define PTP_DELAY_MECH_NAME_E2E   "E2E"
#define PTP_DELAY_MECH_NAME_P2P   "P2P"

/**
 * @brief Name strings for the PTP delay mechanisms
 *
 * @see ::PTP_DELAY_MECHS
 */
#define PTP_DELAY_MECH_NAMES \
{                            \
  PTP_DELAY_MECH_NAME_E2E,   \
  PTP_DELAY_MECH_NAME_P2P    \
}



/**
 * @brief An enumeration of accuracy classes used with PTP
 *
 * @note This enumeration does not start at 0 but with a bias
 * specified by ::PTP_CLOCK_ACCURACY_NUM_BIAS.
 *
 * @see ::PTP_CLOCK_ACCURACY_STRS
 */
enum PTP_CLOCK_ACCURACIES
{
  PTP_CLOCK_ACCURACY_NUM_BIAS = 0x20,
  PTP_CLOCK_ACCURACY_25ns = PTP_CLOCK_ACCURACY_NUM_BIAS,
  PTP_CLOCK_ACCURACY_100ns,
  PTP_CLOCK_ACCURACY_250ns,
  PTP_CLOCK_ACCURACY_1us,
  PTP_CLOCK_ACCURACY_2_5us,
  PTP_CLOCK_ACCURACY_10us,
  PTP_CLOCK_ACCURACY_25us,
  PTP_CLOCK_ACCURACY_100us,
  PTP_CLOCK_ACCURACY_250us,
  PTP_CLOCK_ACCURACY_1ms,
  PTP_CLOCK_ACCURACY_2_5ms,
  PTP_CLOCK_ACCURACY_10ms,
  PTP_CLOCK_ACCURACY_25ms,
  PTP_CLOCK_ACCURACY_100ms,
  PTP_CLOCK_ACCURACY_250ms,
  PTP_CLOCK_ACCURACY_1s,
  PTP_CLOCK_ACCURACY_10s,
  PTP_CLOCK_ACCURACY_MORE_10s,
  PTP_CLOCK_ACCURACY_RESERVED_1,
  PTP_CLOCK_ACCURACY_RESERVED_2,
  PTP_CLOCK_ACCURACY_RESERVED_3,
  PTP_CLOCK_ACCURACY_RESERVED_4,
  N_PTP_CLOCK_ACCURACY
  //##++++ TODO: Add a code for 0xFE (unknown), or eventually
  // redesign the lookup of associated strings completely.
};


/**
 * @brief Name strings for PTP accuracy classes
 *
 * @note The enumeration does not start at 0 but with a bias
 * specified by ::PTP_CLOCK_ACCURACY_NUM_BIAS, so this bias needs
 * to be accounted for when accessing a string table.
 *
 * @see ::PTP_CLOCK_ACCURACIES
 */
#define PTP_CLOCK_ACCURACY_STRS \
{                               \
  "< 25 ns",                    \
  "< 100 ns",                   \
  "< 250 ns",                   \
  "< 1 us",                     \
  "< 2.5 us",                   \
  "< 10 us",                    \
  "< 25 us",                    \
  "< 100 us",                   \
  "< 250 us",                   \
  "< 1 ms",                     \
  "< 2.5 ms",                   \
  "< 10 ms",                    \
  "< 25 ms",                    \
  "< 100 ms",                   \
  "< 250 ms",                   \
  "< 1 s",                      \
  "< 10 s",                     \
  "more than 10 s",             \
  "reserved_1",                 \
  "reserved_2",                 \
  "reserved_3",                 \
  "reserved_4"                  \
}



/**
 * @brief Codes to specify the type of a time source used with PTP
 *
 * @see ::PTP_TIME_SOURCE_TABLE
 */
enum PTP_TIME_SOURCES
{
  PTP_TIME_SOURCE_ATOMIC_CLOCK        = 0x10,
  PTP_TIME_SOURCE_GPS                 = 0x20,
  PTP_TIME_SOURCE_TERRESTRIAL_RADIO   = 0x30,
  PTP_TIME_SOURCE_PTP                 = 0x40,
  PTP_TIME_SOURCE_NTP                 = 0x50,
  PTP_TIME_SOURCE_HAND_SET            = 0x60,
  PTP_TIME_SOURCE_OTHER               = 0x90,
  PTP_TIME_SOURCE_INTERNAL_OSCILLATOR = 0xA0
};



/**
 * @brief A table of PTP time source codes plus associated name strings
 *
 * @see ::PTP_TIME_SOURCES
 */
#define PTP_TIME_SOURCE_TABLE                                     \
{                                                                 \
  { PTP_TIME_SOURCE_ATOMIC_CLOCK, "Atomic Clock" },               \
  { PTP_TIME_SOURCE_GPS, "GPS" },                                 \
  { PTP_TIME_SOURCE_TERRESTRIAL_RADIO, "Terrestrial Radio" },     \
  { PTP_TIME_SOURCE_PTP, "PTP" },                                 \
  { PTP_TIME_SOURCE_NTP, "NTP" },                                 \
  { PTP_TIME_SOURCE_HAND_SET, "HAND SET" },                       \
  { PTP_TIME_SOURCE_OTHER, "OTHER" },                             \
  { PTP_TIME_SOURCE_INTERNAL_OSCILLATOR, "Internal Oscillator" }, \
  { 0, NULL }                                                     \
}


/**
 * @brief An enumeration of roles which can be taken by a PTP node
 *
 * A role in this context specifies a certain mode of operation.
 * Depending on its specification a devices may not be able to take
 * each of the specified roles.
 *
 * @note: A device in MULTICAST_AUTO role can be either master or slave,
 * so the port state needs to be checked to determine the current
 * mode of operation.
 *
 * @see ::PTP_ROLE_MASKS
 * @see ::PTP_ROLE_STRS
 * @see ::PTP_ROLE_STRS_SHORT
 */
enum PTP_ROLES
{
  PTP_ROLE_MULTICAST_SLAVE,    ///< slave in multicast mode
  PTP_ROLE_UNICAST_SLAVE,      ///< slave in unicast mode
  PTP_ROLE_MULTICAST_MASTER,   ///< multicast master
  PTP_ROLE_UNICAST_MASTER,     ///< unicast master
  PTP_ROLE_MULTICAST_AUTO,     ///< multicast master or slave (auto selection)
  PTP_ROLE_BOTH_MASTER,        ///< simultanous multicast and unicast master
  PTP_ROLE_NTP_SERVER,         ///< NTP Unicast Server
  PTP_ROLE_NTP_CLIENT,         ///< NTP Unicast Client
  PTP_ROLE_TIME_MONITOR,       ///< Time Monitor for external PTP or NTP devices
  PTP_ROLE_V1_MASTER,          ///< PTPv1 Master in Multicast mode
  PTP_ROLE_V1_SLAVE,           ///< PTPv1 Slave in Multicast mode
  N_PTP_ROLES                  ///< number of defined roles
};


/**
 * @brief Bit mask associated with ::PTP_ROLES
 *
 * A role in this context specifies a certain mode of operation.
 * Depending on its specification a devices may not be able to take
 * each of the specified roles.
 *
 * @note: A device in MULTICAST_AUTO role can be either master or slave,
 * so the port state needs to be checked to determine the current
 * mode of operation.
 *
 * @see ::PTP_ROLES
 * @see ::get_supp_ptp_role_mask
 */
enum PTP_ROLE_MASKS
{
  PTP_ROLE_MSK_MULTICAST_SLAVE  = ( 1UL << PTP_ROLE_MULTICAST_SLAVE ),   ///< see ::PTP_ROLE_MULTICAST_SLAVE
  PTP_ROLE_MSK_UNICAST_SLAVE    = ( 1UL << PTP_ROLE_UNICAST_SLAVE ),     ///< see ::PTP_ROLE_UNICAST_SLAVE
  PTP_ROLE_MSK_MULTICAST_MASTER = ( 1UL << PTP_ROLE_MULTICAST_MASTER ),  ///< see ::PTP_ROLE_MULTICAST_MASTER
  PTP_ROLE_MSK_UNICAST_MASTER   = ( 1UL << PTP_ROLE_UNICAST_MASTER ),    ///< see ::PTP_ROLE_UNICAST_MASTER
  PTP_ROLE_MSK_MULTICAST_AUTO   = ( 1UL << PTP_ROLE_MULTICAST_AUTO ),    ///< see ::PTP_ROLE_MULTICAST_AUTO
  PTP_ROLE_MSK_BOTH_MASTER      = ( 1UL << PTP_ROLE_BOTH_MASTER ),       ///< see ::PTP_ROLE_BOTH_MASTER
  PTP_ROLE_MSK_NTP_SERVER       = ( 1UL << PTP_ROLE_NTP_SERVER ),        ///< see ::PTP_ROLE_NTP_SERVER
  PTP_ROLE_MSK_NTP_CLIENT       = ( 1UL << PTP_ROLE_NTP_CLIENT ),        ///< see ::PTP_ROLE_NTP_CLIENT
  PTP_ROLE_MSK_TIME_MONITOR     = ( 1UL << PTP_ROLE_TIME_MONITOR ),      ///< see ::PTP_ROLE_TIME_MONITOR
  PTP_ROLE_MSK_V1_MASTER        = ( 1UL << PTP_ROLE_V1_MASTER ),         ///< see ::PTP_ROLE_MULTICAST_MASTER
  PTP_ROLE_MSK_V1_SLAVE         = ( 1UL << PTP_ROLE_V1_SLAVE )           ///< see ::PTP_ROLE_UNICAST_SLAVE
};


#define PTP_ROLE_MSK_SLAVES    ( PTP_ROLE_MSK_MULTICAST_SLAVE  \
                               | PTP_ROLE_MSK_UNICAST_SLAVE    \
                               | PTP_ROLE_MSK_MULTICAST_AUTO )

#define PTP_ROLE_MSK_MASTERS   ( PTP_ROLE_MSK_MULTICAST_MASTER \
                               | PTP_ROLE_MSK_UNICAST_MASTER   \
                               | PTP_ROLE_MSK_MULTICAST_AUTO   \
                               | PTP_ROLE_BOTH_MASTER )


/**
 * @brief Name strings for defined PTP roles
 *
 * @see ::PTP_ROLES
 * @see ::PTP_ROLE_STRS_SHORT
 */
#define PTP_ROLE_STRS  \
{                      \
  "Multicast Slave",   \
  "Unicast Slave",     \
  "Multicast Master",  \
  "Unicast Master",    \
  "Multicast (Auto)",  \
  "UC+MC Master",      \
  "NTP Server",        \
  "NTP Client",        \
  "Time Monitor",      \
  "V1 Master",         \
  "V1 Slave"           \
}


/**
 * @brief Short name strings for defined PTP roles
 *
 * @see ::PTP_ROLES
 * @see ::PTP_ROLE_STRS
 */
#define PTP_ROLE_STRS_SHORT  \
{                            \
  "MCS",                     \
  "UCS",                     \
  "MCM",                     \
  "UCM",                     \
  "MCA",                     \
  "UMM",                     \
  "NSV",                     \
  "NCL",                     \
  "MON",                     \
  "V1M",                     \
  "V1S"                      \
}


/**
 * @brief A PTP clock identity
 *
 * @note This usually consists of a 6 byte MAC address with
 * 2 fixed bytes inserted, or all ones as wildcard.
 */
typedef struct
{
  uint8_t b[8];

} PTP_CLOCK_ID;

#define _mbg_swab_ptp_clock_id( _p )   _nop_macro_fnc()  // nothing to swap

#define PTP_CLOCK_ID_WILDCARD   { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }


/**
 * @brief A PTP port ID
 */
typedef uint16_t PTP_PORT_ID;

#define _mbg_swab_ptp_port_id( _p )  _mbg_swab16( _p )

#define PTP_PORT_ID_WILDCARD   0xFFFF


/**
 * @brief A PTP port identity
 *
 * @note For further information, see IEEE 1588-2008, chapter 5.3.5
 *
 * @see ::PTP_CLOCK_ID
 * @see ::PTP_PORT_ID
 */
typedef struct
{
  PTP_CLOCK_ID clock_identity;
  PTP_PORT_ID port_number;

} PTP_PORT_IDENTITY;


#define _mbg_swab_ptp_port_identity( _p )                 \
{                                                         \
  _mbg_swab_ptp_clock_id( &(_p)->clock_identity );        \
  _mbg_swab_ptp_port_id( &(_p)->port_number );            \
}


/**
 * @brief PTP clock quality
 *
 * @note For further information, see IEEE 1588-2008, chapter 5.3.7
 */
typedef struct
{
  uint8_t clock_class;                ///< PTP clock class representing the current sync status
  int8_t clock_accuracy;              ///< see ::PTP_CLOCK_ACCURACIES
  uint16_t log_variance;              ///< PTP offset scaled log variance representing the time stability

} PTP_CLOCK_QUALITY;


#define _mbg_swab_ptp_clock_quality( _p )     \
{                                             \
  _mbg_swab8( &(_p)->clock_class );           \
  _mbg_swab8( &(_p)->clock_accuracy );        \
  _mbg_swab16( &(_p)->log_variance );         \
}


/**
 * @brief PTP time interval
 *
 * @note For further information, see IEEE 1588-2008, chapter 5.3.2
 *
 */
typedef struct
{
  int64_t scaled_nanoseconds;

} PTP_TIME_INTERVAL;


#define _mbg_swab_ptp_time_interval( _p )     \
{                                             \
  _mbg_swab64( &(_p)->scaled_nanoseconds );   \
}


/**
 * @brief An enumeration of time scales used with PTP
 *
 * @note The standard time scale used by PTP is TAI, which is a linear time scale.
 * The protocol provides a %UTC offset to be able to convert TAI to compute %UTC, which
 * can observe leap seconds. For the arbitrary time scale the %UTC offset is unspecified,
 * so arbitrary time can be %UTC, or something else.
 *
 * @see ::PTP_TIMESCALE_NAMES
 * @see ::PTP_TIMESCALE_NAMES_SHORT
 */
enum PTP_TIME_SCALES
{
  PTP_TIMESCALE_PTP,   ///< PTP default, TAI
  PTP_TIMESCALE_ARB,   ///< arbitrary time scale, maybe %UTC
  N_PTP_TIMESCALE
};


/**
 * @brief Name strings for the PTP time scales
 */
#define PTP_TIMESCALE_NAME_PTP  "PTP Standard (TAI)"
#define PTP_TIMESCALE_NAME_ARB  "Arbitrary"

/**
 * @brief Short name strings for the PTP time scales
 */
#define PTP_TIMESCALE_NAME_PTP_SHORT  "PTP"
#define PTP_TIMESCALE_NAME_ARB_SHORT  "Arb"


/**
 * @brief A table of name strings for the PTP time scales
 *
 * @see ::PTP_TIME_SCALES
 * @see ::PTP_TIMESCALE_NAMES_SHORT
 */
#define PTP_TIMESCALE_NAMES \
{                           \
  PTP_TIMESCALE_NAME_PTP,   \
  PTP_TIMESCALE_NAME_ARB    \
}

/**
 * @brief A table of short name strings for the PTP time scales
 *
 * @see ::PTP_TIME_SCALES
 * @see ::PTP_TIMESCALE_NAMES
 */
#define PTP_TIMESCALE_NAMES_SHORT \
{                                 \
  PTP_TIMESCALE_NAME_PTP_SHORT,   \
  PTP_TIMESCALE_NAME_ARB_SHORT    \
}



/**
 * @brief A structure to used to read the status of the PTP protocol stack
 */
typedef struct
{
  uint16_t nw_prot;                ///< one of the enumerated protocols, see ::PTP_NW_PROTS
  uint8_t ptp_prot_version;        ///< PTP protocol version, 1, or 2, usually 2 for v2
  uint8_t port_state;              ///< one of the enumerated port states, see ::PTP_PORT_STATES
  uint32_t flags;                  ///< see ::PTP_STATE_FLAGS
  NANO_TIME offset;                ///< estimated time offset from the upstream time source
  NANO_TIME path_delay;
  NANO_TIME mean_path_delay;
  NANO_TIME delay_asymmetry;

  PTP_CLOCK_ID gm_id;              ///< identifier ot the upstream time source

  uint16_t clock_offset_scaled_log_variance;
  uint8_t clock_class;
  uint8_t clock_accuracy;          ///< see ::PTP_CLOCK_ACCURACIES

  uint32_t tsu_secs;               ///< current seconds value of time stamp unit
  uint32_t reserved_2;             ///< reserved, currently always 0

  uint8_t domain_number;           ///< the PTP clock domain number, 0:3
  uint8_t time_source;             ///< see ::PTP_TIME_SOURCES
  uint8_t delay_mech;              ///< see ::PTP_DELAY_MECHS
  int8_t log_delay_req_intv;

  int16_t utc_offset;              ///< %UTC offset observed against TAI
  DAC_VAL osc_dac_cal;             ///< disciplination value of the oscillator

  uint8_t parent_clock_class;      ///< clock class of the parent node
  uint8_t parent_clock_accuracy;   ///< clock accuracy of the parent node, see ::PTP_CLOCK_ACCURACIES

  uint16_t reserved_3;             ///< reserved, currently always 0

} PTP_STATE;

#define _mbg_swab_ptp_state( _p )                         \
do                                                        \
{                                                         \
  _mbg_swab16( &(_p)->nw_prot );                          \
  _mbg_swab32( &(_p)->flags );                            \
  _mbg_swab_nano_time( &(_p)->offset );                   \
  _mbg_swab_nano_time( &(_p)->path_delay );               \
  _mbg_swab_nano_time( &(_p)->mean_path_delay );          \
  _mbg_swab_nano_time( &(_p)->delay_asymmetry );          \
  _mbg_swab_ptp_clock_id( &(_p)->gm_id );                 \
  _mbg_swab16( &(_p)->clock_offset_scaled_log_variance ); \
  _mbg_swab32( &(_p)->tsu_secs );                         \
  _mbg_swab32( &(_p)->reserved_2 );                       \
  _mbg_swab16( &(_p)->utc_offset );                       \
  _mbg_swab_dac_val( &(_p)->osc_dac_cal );                \
  _mbg_swab16( &(_p)->reserved_3 );                       \
} while ( 0 )


/**
 * @brief Flags bits used with PTP_STATE::flags
 *
 * @see ::PTP_STATE_FLAG_MASKS
 */
enum PTP_STATE_FLAGS
{
  PTP_FLAG_SLAVE_ONLY,        ///< the port can only be slave
  PTP_FLAG_IS_SLAVE,          ///< the port is currently slave
  PTP_FLAG_TIMESCALE_IS_PTP,  ///< the timescale is PTP standard, not arbitrary
  PTP_FLAG_LS_ANN,            ///< a leap second is being announced
  PTP_FLAG_LS_ANN_NEG,        ///< the announced leap second is negative
  PTP_FLAG_IS_UNICAST,        ///< the port currently operates in unicast mode
  PTP_FLAG_UTC_VALID,         ///< %UTC parameters are valid
  PTP_FLAG_ONE_STEP,          ///< One-Step Clock active
  N_PTP_STATE_FLAGS           ///< the number of defined flag bits
};

/**
 * @brief Flags masks used with PTP_STATE::flags
 *
 * @see ::PTP_STATE_FLAGS
 */
enum PTP_STATE_FLAG_MASKS
{
  PTP_FLAG_MSK_SLAVE_ONLY       = ( 1UL << PTP_FLAG_SLAVE_ONLY ),        ///< see ::PTP_FLAG_SLAVE_ONLY
  PTP_FLAG_MSK_IS_SLAVE         = ( 1UL << PTP_FLAG_IS_SLAVE ),          ///< see ::PTP_FLAG_IS_SLAVE
  PTP_FLAG_MSK_TIMESCALE_IS_PTP = ( 1UL << PTP_FLAG_TIMESCALE_IS_PTP ),  ///< see ::PTP_FLAG_TIMESCALE_IS_PTP
  PTP_FLAG_MSK_LS_ANN           = ( 1UL << PTP_FLAG_LS_ANN ),            ///< see ::PTP_FLAG_LS_ANN
  PTP_FLAG_MSK_LS_ANN_NEG       = ( 1UL << PTP_FLAG_LS_ANN_NEG ),        ///< see ::PTP_FLAG_LS_ANN_NEG
  PTP_FLAG_MSK_IS_UNICAST       = ( 1UL << PTP_FLAG_IS_UNICAST ),        ///< see ::PTP_FLAG_IS_UNICAST
  PTP_FLAG_MSK_UTC_VALID        = ( 1UL << PTP_FLAG_UTC_VALID ),         ///< see ::PTP_FLAG_UTC_VALID
  PTP_FLAG_MSK_ONE_STEP         = ( 1UL << PTP_FLAG_ONE_STEP )           ///< see ::PTP_FLAG_ONE_STEP
};



/**
 * @brief A structure used to configure a PTP port
 */
typedef struct
{
  uint16_t nw_prot;               ///< see ::PTP_NW_PROTS
  uint8_t selected_presets;       ///< selected PTP presets, see ::PTP_PRESETS
  uint8_t domain_number;          ///< the PTP clock domain number, 0:3

  uint8_t delay_mech;             ///< see ::PTP_DELAY_MECHS
  uint8_t ptp_role;               ///< one of the supported PTP roles, see ::PTP_ROLES
  uint8_t priority_1;             ///< priority 1
  uint8_t priority_2;             ///< priority 2

  uint8_t dflt_clk_class_unsync_cold;   // 6:255
  uint8_t dflt_clk_class_unsync_warm;   // 6:255
  uint8_t dflt_clk_class_sync_cold;     // 6:255
  uint8_t dflt_clk_class_sync_warm;     // 6:255

  uint8_t ann_rcpt_timeout;       ///< announce msg. receipt timeout, see ::PTP_ANN_RCPT_TIMEOUT_LIMITS
  uint8_t opt_ext;                ///< optional configuration extension, see ::PTP_OPT_EXTS
  int16_t sync_intv;              ///< log2 of the sync interval [s]

  int16_t ann_intv;               ///< log2 of the announce interval [s]
  int16_t delay_req_intv;         ///< log2 of the delay request interval [s]

  uint32_t upper_bound;           ///< sync state set to false if above this limit [ns]
  uint32_t lower_bound;           ///< sync state set to true if below this limit [ns]

  uint32_t reserved;              ///< reserved, currently always 0
  uint32_t flags;                 ///< see @ref PTP_CFG_FLAG_MASKS

} PTP_CFG_SETTINGS;

#define _mbg_swab_ptp_cfg_settings( _p )  \
do                                        \
{                                         \
  _mbg_swab16( &(_p)->nw_prot );          \
  _mbg_swab16( &(_p)->sync_intv );        \
  _mbg_swab16( &(_p)->ann_intv );         \
  _mbg_swab16( &(_p)->delay_req_intv );   \
  _mbg_swab32( &(_p)->upper_bound );      \
  _mbg_swab32( &(_p)->lower_bound );      \
  _mbg_swab32( &(_p)->reserved );         \
  _mbg_swab32( &(_p)->flags );            \
} while ( 0 )



/**
 * @brief Possible values for PTP_CFG_SETTINGS::ann_rcpt_timeout
 */
enum PTP_ANN_RCPT_TIMEOUT_LIMITS
{
  PTP_ANN_RCPT_TIMEOUT_MIN = 2,
  PTP_ANN_RCPT_TIMEOUT_MAX = 8,
  DEFAULT_PTP_ANN_RCPT_TIMEOUT = 3
};



/**
 * @brief A structure to used to query the current configuration and capabilities of a PTP port
 */
typedef struct
{
  PTP_CFG_SETTINGS settings;        ///< the current configuration

  uint8_t ptp_proto_version;        ///< PTP protocol version, 1, or 2, usually 2 for v2
  uint8_t reserved_1;               ///< reserved, currently always 0
  uint16_t reserved_2;              ///< reserved, currently always 0

  int16_t sync_intv_min;            ///< log2 of minimum sync interval [s]
  int16_t sync_intv_max;            ///< log2 of maximum sync interval [s]
  int16_t ann_intv_min;             ///< log2 of minimum announce interval [s]
  int16_t ann_intv_max;             ///< log2 of maximum announce interval [s]
  int16_t delay_req_intv_min;       ///< log2 of minimum delay request interval [s]
  int16_t delay_req_intv_max;       ///< log2 of maximum delay request interval [s]

  uint32_t supp_flags;              ///< a bit mask of supported features, see @ref PTP_CFG_FLAG_MASKS
  uint32_t supp_nw_prot;            ///< a bit mask of supported network protocols, see ::PTP_NW_PROT_MASKS
  uint32_t supp_opt_ext;            ///< a bit mask of supported optional extensions, see ::PTP_OPT_EXT_MASKS
  uint32_t supp_delay_mech;         ///< a bit mask of supported delay mechanisms, see ::PTP_DELAY_MECH_MASKS

} PTP_CFG_INFO;

#define _mbg_swab_ptp_cfg_info( _p )              \
do                                                \
{                                                 \
  _mbg_swab_ptp_cfg_settings( &(_p)->settings );  \
  _mbg_swab16( &(_p)->reserved_2 );               \
  _mbg_swab16( &(_p)->sync_intv_min );            \
  _mbg_swab16( &(_p)->sync_intv_max );            \
  _mbg_swab16( &(_p)->ann_intv_min );             \
  _mbg_swab16( &(_p)->ann_intv_max );             \
  _mbg_swab16( &(_p)->delay_req_intv_min );       \
  _mbg_swab16( &(_p)->delay_req_intv_max );       \
  _mbg_swab32( &(_p)->supp_flags );               \
  _mbg_swab32( &(_p)->supp_nw_prot );             \
  _mbg_swab32( &(_p)->supp_opt_ext );             \
  _mbg_swab32( &(_p)->supp_delay_mech );          \
} while ( 0 )



/**
 * @brief Flags bits used with PTP configuration
 *
 * Flags labeled [R/-] can only be used with ::PTP_CFG_INFO::supp_flags
 * to indicate that the associated feature is supported in general.
 *
 * If a flag labeled [R/W] is set in ::PTP_CFG_INFO::supp_flags then
 * this flag can also be used with ::PTP_CFG_SETTINGS::flags to control
 * the associated feature.
 *
 * @note Originally, all devices supported the multicast slave role, so
 * there was no extra flag to indicate this. However, some newer devices
 * may not support the multicast slave role, so two new flags have been
 * introduced to cope with this:
 * If ::PTP_CFG_SUPP_MCAST_SLAVE_FLAG is set then a different flag
 * ::PTP_CFG_CAN_BE_MULTICAST_SLAVE needs to be checked to tell if
 * the multicast slave role is supported, or not.
 * If ::PTP_CFG_SUPP_MCAST_SLAVE_FLAG is not set then the device
 * definitely supports the multicast slave role.
 *
 * @see @ref PTP_CFG_FLAG_MASKS
 */
enum PTP_CFG_FLAGS
{
  PTP_CFG_TIME_SCALE_IS_PTP,        ///< [R/W] time scale is PTP/TAI, else arbitrary
  PTP_CFG_V1_HW_COMPAT,             ///< [R/W] maybe required for certain NIC chips, not used by Meinberg
  PTP_CFG_CAN_BE_UNICAST_SLAVE,     ///< [R/-] supports unicast slave role, see ::PTP_ROLE_UNICAST_SLAVE
  PTP_CFG_CAN_BE_MULTICAST_MASTER,  ///< [R/-] supports multicast master role, see ::PTP_ROLE_MULTICAST_MASTER
  PTP_CFG_CAN_BE_UNICAST_MASTER,    ///< [R/-] supports unicast master, see ::PTP_ROLE_UNICAST_MASTER
  PTP_CFG_CAN_BE_MULTICAST_AUTO,    ///< [R/-] can automatically become multicast master or slave, see ::PTP_CFG_CAN_BE_MULTICAST_AUTO
  PTP_CFG_SUPP_UTC_VALID,           ///< [R/-] ::PTP_FLAG_UTC_VALID bit in ::PTP_STATE::flags is supported
  PTP_CFG_CAN_BE_BOTH_MASTER,       ///< [R/-] supports unicast and multicast master role at the same time, see ::PTP_CFG_CAN_BE_BOTH_MASTER

  PTP_CFG_HYBRID_MASTER,            ///< [R/W] supports hybrid mode in master roles
  PTP_CFG_HYBRID_SLAVE,             ///< [R/W] supports hybrid mode in slave roles
  PTP_CFG_ONE_STEP_MASTER,          ///< [R/W] supports one-step mode in master roles
  PTP_CFG_MNGMNT_MSGS_DISB,         ///< [R/W] supports disabling of PTP management messages
  PTP_CFG_SUPP_MCAST_SLAVE_FLAG,    ///< [R/-] indicates that ::PTP_CFG_CAN_BE_MULTICAST_SLAVE flag is supported and can be checked
  PTP_CFG_CAN_BE_MULTICAST_SLAVE,   ///< [R/-] if ::PTP_CFG_SUPP_MCAST_SLAVE_FLAG bit set, indicates if multicast slave role is supported
  PTP_CFG_ONE_STEP_L2,              ///< [R/-] supports the combination of One-Step and Layer2 mode
  PTP_CFG_ONE_STEP_P2P,             ///< [R/-] supports the combination of One-Step and P2P Delay Mechanism

  PTP_CFG_TSU_RESET,                ///< [R/-] supports TSU reset via register cmd
  PTP_CFG_NTP_HW_TS_MASTER,         ///< [R/-] supports the NTP HW time stamping in Master mode
  PTP_CFG_NTP_HW_TS_SLAVE,          ///< [R/-] supports the NTP HW time stamping in Slave mode
  PTP_CFG_SYNCE_MASTER,             ///< [R/-] Hardware supports Synchronous Ethernet Out
  PTP_CFG_SYNCE_SLAVE,              ///< [R/-] Hardware supports Synchronous Ethernet In
  PTP_CFG_HAS_MUX,                  ///< [R/-] Hardware supports multiplexed signal outputs
  PTP_CFG_CAN_BE_TIME_MONITOR,      ///< [R/-] can be Monitoring device for external PTP or NTP devices //### TODO Shouldn't this be an XFEATURE flag?
  PTP_CFG_HAS_STATISTICS,           ///< [R/-] ::MBG_PTP_STATISTICS_INFO can be queried

  PTP_CFG_CAN_BE_V1_MASTER,         ///< [R/-] supports PTPv1 MASTER role
  PTP_CFG_CAN_BE_V1_SLAVE,          ///< [R/-] supports PTPv1 SLAVE role
  PTP_CFG_HAS_V2_COMMON_DATASETS,   ///< [R/-] PTPv2 common dataset structures (see IEEE1588-2008, chapter 8.2) can be queried
  PTP_CFG_HAS_V1_COMMON_DATASETS,   ///< [R/-] PTPv1 common dataset structures can be queried

  N_PTP_CFG_FLAGS                   ///< the number of defined flags
};


/**
 * @defgroup group_PTP_CFG_FLAG_MASKS Bit masks used with PTP_CFG_INFO::supp_flags and PTP_CFG_SETTINGS::flags
 *
 * @see ::PTP_CFG_INFO::supp_flags
 * @see ::PTP_CFG_SETTINGS::flags
 * @see ::PTP_CFG_FLAGS
 *
 * @anchor PTP_CFG_FLAG_MASKS
 *
 * @{ */

#define PTP_CFG_MSK_TIME_SCALE_IS_PTP        ( 1UL << PTP_CFG_TIME_SCALE_IS_PTP )       ///< see ::PTP_CFG_TIME_SCALE_IS_PTP
#define PTP_CFG_MSK_V1_HW_COMPAT             ( 1UL << PTP_CFG_V1_HW_COMPAT )            ///< see ::PTP_CFG_V1_HW_COMPAT
#define PTP_CFG_MSK_CAN_BE_UNICAST_SLAVE     ( 1UL << PTP_CFG_CAN_BE_UNICAST_SLAVE )    ///< see ::PTP_CFG_CAN_BE_UNICAST_SLAVE
#define PTP_CFG_MSK_CAN_BE_MULTICAST_MASTER  ( 1UL << PTP_CFG_CAN_BE_MULTICAST_MASTER ) ///< see ::PTP_CFG_CAN_BE_MULTICAST_MASTER
#define PTP_CFG_MSK_CAN_BE_UNICAST_MASTER    ( 1UL << PTP_CFG_CAN_BE_UNICAST_MASTER )   ///< see ::PTP_CFG_CAN_BE_UNICAST_MASTER
#define PTP_CFG_MSK_CAN_BE_MULTICAST_AUTO    ( 1UL << PTP_CFG_CAN_BE_MULTICAST_AUTO )   ///< see ::PTP_CFG_CAN_BE_MULTICAST_AUTO
#define PTP_CFG_MSK_SUPP_UTC_VALID           ( 1UL << PTP_CFG_SUPP_UTC_VALID )          ///< see ::PTP_CFG_SUPP_UTC_VALID
#define PTP_CFG_MSK_CAN_BE_BOTH_MASTER       ( 1UL << PTP_CFG_CAN_BE_BOTH_MASTER )      ///< see ::PTP_CFG_CAN_BE_BOTH_MASTER

#define PTP_CFG_MSK_HYBRID_MASTER            ( 1UL << PTP_CFG_HYBRID_MASTER )           ///< see ::PTP_CFG_HYBRID_MASTER
#define PTP_CFG_MSK_HYBRID_SLAVE             ( 1UL << PTP_CFG_HYBRID_SLAVE )            ///< see ::PTP_CFG_HYBRID_SLAVE
#define PTP_CFG_MSK_ONE_STEP_MASTER          ( 1UL << PTP_CFG_ONE_STEP_MASTER )         ///< see ::PTP_CFG_ONE_STEP_MASTER
#define PTP_CFG_MSK_MNGMNT_MSGS_DISB         ( 1UL << PTP_CFG_MNGMNT_MSGS_DISB )        ///< see ::PTP_CFG_MNGMNT_MSGS_DISB
#define PTP_CFG_MSK_SUPP_MCAST_SLAVE_FLAG    ( 1UL << PTP_CFG_SUPP_MCAST_SLAVE_FLAG )   ///< see ::PTP_CFG_SUPP_MCAST_SLAVE_FLAG
#define PTP_CFG_MSK_CAN_BE_MULTICAST_SLAVE   ( 1UL << PTP_CFG_CAN_BE_MULTICAST_SLAVE )  ///< see ::PTP_CFG_CAN_BE_MULTICAST_SLAVE
#define PTP_CFG_MSK_ONE_STEP_L2              ( 1UL << PTP_CFG_ONE_STEP_L2 )             ///< see ::PTP_CFG_ONE_STEP_L2
#define PTP_CFG_MSK_ONE_STEP_P2P             ( 1UL << PTP_CFG_ONE_STEP_P2P )            ///< see ::PTP_CFG_ONE_STEP_P2P

#define PTP_CFG_MSK_TSU_RESET                ( 1UL << PTP_CFG_TSU_RESET )               ///< see ::PTP_CFG_TSU_RESET
#define PTP_CFG_MSK_NTP_HW_TS_MASTER         ( 1UL << PTP_CFG_NTP_HW_TS_MASTER )        ///< see ::PTP_CFG_NTP_HW_TS_MASTER
#define PTP_CFG_MSK_NTP_HW_TS_SLAVE          ( 1UL << PTP_CFG_NTP_HW_TS_SLAVE)          ///< see ::PTP_CFG_NTP_HW_TS_SLAVE
#define PTP_CFG_MSK_SYNCE_MASTER             ( 1UL << PTP_CFG_SYNCE_MASTER )            ///< see ::PTP_CFG_SYNCE_MASTER
#define PTP_CFG_MSK_SYNCE_SLAVE              ( 1UL << PTP_CFG_SYNCE_SLAVE )             ///< see ::PTP_CFG_SYNCE_SLAVE
#define PTP_CFG_MSK_HAS_MUX                  ( 1UL << PTP_CFG_HAS_MUX )                 ///< see ::PTP_CFG_HAS_MUX
#define PTP_CFG_MSK_CAN_BE_TIME_MONITOR      ( 1UL << PTP_CFG_CAN_BE_TIME_MONITOR )     ///< see ::PTP_CFG_CAN_BE_TIME_MONITOR
#define PTP_CFG_MSK_HAS_STATISTICS           ( 1UL << PTP_CFG_HAS_STATISTICS )          ///< see ::PTP_CFG_HAS_STATISTICS

#define PTP_CFG_MSK_CAN_BE_V1_MASTER         ( 1UL << PTP_CFG_CAN_BE_V1_MASTER )        ///< see ::PTP_CFG_CAN_BE_V1_MASTER
#define PTP_CFG_MSK_CAN_BE_V1_SLAVE          ( 1UL << PTP_CFG_CAN_BE_V1_SLAVE )         ///< see ::PTP_CFG_CAN_BE_V1_SLAVE
#define PTP_CFG_MSK_HAS_V2_COMMON_DATASETS   ( 1UL << PTP_CFG_HAS_V2_COMMON_DATASETS )  ///< see ::PTP_CFG_HAS_V2_COMMON_DATASETS
#define PTP_CFG_MSK_HAS_V1_COMMON_DATASETS   ( 1UL << PTP_CFG_HAS_V1_COMMON_DATASETS )  ///< see ::PTP_CFG_HAS_V1_COMMON_DATASETS

/** @} defgroup group_PTP_CFG_FLAG_MASKS */



/** @brief A bit mask of the unicast role bits within the flag bits */
#define PTP_CFG_MSK_SUPPORT_PTP_UNICAST ( PTP_CFG_MSK_CAN_BE_UNICAST_SLAVE  | \
                                          PTP_CFG_MSK_CAN_BE_UNICAST_MASTER )



/**
 * @brief Register in TSU-GbE FPGA to determine board features of the current TSU board revision
 */
typedef uint16_t PTP_HW_FEATURES;



/**
 * @brief Bits used to define ::PTP_HW_FEAT_MASKS
 */
enum PTP_HW_FEAT_BITS
{
  PTP_FEAT_SYNCE_EXT_MUX,    ///< [R] supports SyncE and external signal multiplexer
  N_PTP_HW_FEAT              ///< the number of defined features
};


// TODO fix comment linkage
/**
 * @brief Bit masks used with ::PTP_HW_FEATURES
 *
 * @see ::PTP_HW_FEAT_BITS
 */
enum PTP_HW_FEAT_MASKS
{
  PTP_HW_FEAT_MSK_SYNCE_EXT_MUX = ( 1UL << PTP_FEAT_SYNCE_EXT_MUX )  ///< see ::PTP_FEAT_SYNCE_EXT_MUX
};



/**
 * @brief Known optional PTP protocol extensions, see ::PTP_CFG_SETTINGS::opt_ext
 *
 * @see ::PTP_OPT_EXT_MASKS
 */
enum PTP_OPT_EXTS
{
  PTP_OPT_EXT_NONE,           ///< no extension used
  PTP_OPT_EXT_POWER,          ///< IEEE C37.238-2011 profile extension
  PTP_OPT_EXT_TELECOM,        ///< ITU-T G.8265.1 profile extension
  PTP_OPT_EXT_TELECOM_PHASE,  ///< ITU-T G.8275.1 profile extension
  PTP_OPT_EXT_SMPTE,          ///< SMPTE ST 2059-2 profile extension
  PTP_OPT_EXT_8021AS,         ///< IEEE 802.1AS profile extension
  PTP_OPT_EXT_6185093,        ///< IEC/IEEE FDIS 61850-9-3 Power Utility profile extension
  PTP_OPT_EXT_TELECOM_PTS,    ///< ITU-T G.8275.2 profile extension
  N_PTP_OPT_EXT               ///< number of known optional extensions
};


/**
 * @brief Flag masks used with ::PTP_CFG_INFO::supp_opt_ext
 *
 * @see ::PTP_OPT_EXTS
 */
enum PTP_OPT_EXT_MASKS
{
  PTP_MSK_OPT_EXT_NONE           = ( 1UL << PTP_OPT_EXT_NONE ),           ///< this is actually not used, see ::PTP_OPT_EXT_NONE
  PTP_MSK_OPT_EXT_POWER          = ( 1UL << PTP_OPT_EXT_POWER ),          ///< see ::PTP_OPT_EXT_POWER
  PTP_MSK_OPT_EXT_TELECOM        = ( 1UL << PTP_OPT_EXT_TELECOM ),        ///< see ::PTP_OPT_EXT_TELECOM
  PTP_MSK_OPT_EXT_TELECOM_PHASE  = ( 1UL << PTP_OPT_EXT_TELECOM_PHASE ),  ///< see ::PTP_OPT_EXT_TELECOM_PHASE
  PTP_MSK_OPT_EXT_SMPTE          = ( 1UL << PTP_OPT_EXT_SMPTE ),          ///< see ::PTP_OPT_EXT_SMPTE
  PTP_MSK_OPT_EXT_8021AS         = ( 1UL << PTP_OPT_EXT_8021AS ),         ///< see ::PTP_OPT_EXT_8021AS
  PTP_MSK_OPT_EXT_6185093        = ( 1UL << PTP_OPT_EXT_6185093 ),        ///< see ::PTP_OPT_EXT_6185093
  PTP_MSK_OPT_EXT_TELECOM_PTS    = ( 1UL << PTP_OPT_EXT_TELECOM_PTS )     ///< see ::PTP_OPT_EXT_TELECOM_PTS
};



/**
 * @brief Enumeration of PTP cfg presets used with ::PTP_CFG_SETTINGS::selected_presets
 *
 * This can be used by configuration programs to determine
 * the last recently selected presets.
 *
 * @see ::PTP_PRESETS_STRS
 * @see ::PTP_PRESETS_MASKS
 */
enum PTP_PRESETS
{
  PTP_PRESETS_CUSTOM,         ///< customizable, always supported
  PTP_PRESETS_DFLT_E2E,       ///< pure IEEE1588-2008 (PTPv2) with E2E
  PTP_PRESETS_DFLT_P2P,       ///< pure IEEE1588-2008 (PTPv2) with P2P
  PTP_PRESETS_POWER,          ///< IEEE C37.238 profile extension, only if ::PTP_MSK_OPT_EXT_POWER is set
  PTP_PRESETS_TELECOM,        ///< ITU-T G.8265.1 profile extension, only if ::PTP_MSK_OPT_EXT_TELECOM is set
  PTP_PRESETS_TELECOM_PHASE,  ///< ITU-T G.8275.1 profile extension, only if ::PTP_MSK_OPT_EXT_TELECOM_PHASE is set
  PTP_PRESETS_SMPTE,          ///< SMPTE ST 2059-2 profile extension, only if ::PTP_MSK_OPT_EXT_SMPTE is set
  PTP_PRESETS_AES67,          ///< AES67 media profile
  PTP_PRESETS_8021AS,         ///< IEEE 802.1AS -like profile, only if ::PTP_MSK_OPT_EXT_8021AS is set
  PTP_PRESETS_6185093,        ///< IEC/IEEE FDIS 61850-9-3, only if ::PTP_MSK_OPT_EXT_6185093 is set
  PTP_PRESETS_TELECOM_PTS,    ///< ITU-T G.8275.2 profile extension, only if ::PTP_MSK_OPT_EXT_TELECOM_PTS is set
  PTP_PRESETS_DOCSIS_31,      ///< only if ::PTP_MSK_OPT_EXT_TELECOM_PHASE is set
  N_PTP_PRESETS               ///< number of supported presets
};


/**
 * @brief Flag masks used with ::PTP_CFG_INFO::supp_opt_ext
 *
 * @see ::PTP_PRESETS
 */
enum PTP_PRESETS_MASKS
{
  PTP_MSK_PRESETS_CUSTOM         = ( 1UL << PTP_PRESETS_CUSTOM ),         ///< see ::PTP_PRESETS_CUSTOM
  PTP_MSK_PRESETS_DFLT_E2E       = ( 1UL << PTP_PRESETS_DFLT_E2E ),       ///< see ::PTP_PRESETS_DFLT_E2E
  PTP_MSK_PRESETS_DFLT_P2P       = ( 1UL << PTP_PRESETS_DFLT_P2P ),       ///< see ::PTP_PRESETS_DFLT_P2P
  PTP_MSK_PRESETS_POWER          = ( 1UL << PTP_PRESETS_POWER ),          ///< see ::PTP_PRESETS_POWER
  PTP_MSK_PRESETS_TELECOM        = ( 1UL << PTP_PRESETS_TELECOM ),        ///< see ::PTP_PRESETS_TELECOM
  PTP_MSK_PRESETS_TELECOM_PHASE  = ( 1UL << PTP_PRESETS_TELECOM_PHASE ),  ///< see ::PTP_PRESETS_TELECOM_PHASE
  PTP_MSK_PRESETS_SMPTE          = ( 1UL << PTP_PRESETS_SMPTE ),          ///< see ::PTP_PRESETS_SMPTE
  PTP_MSK_PRESETS_AES67          = ( 1UL << PTP_PRESETS_AES67 ),          ///< see ::PTP_PRESETS_AES67
  PTP_MSK_PRESETS_8021AS         = ( 1UL << PTP_PRESETS_8021AS ),         ///< see ::PTP_PRESETS_8021AS
  PTP_MSK_PRESETS_6185093        = ( 1UL << PTP_PRESETS_6185093),         ///< see ::PTP_PRESETS_6185093
  PTP_MSK_PRESETS_TELECOM_PTS    = ( 1UL << PTP_PRESETS_TELECOM_PTS),      ///< see ::PTP_PRESETS_TELECOM_PTS
  PTP_MSK_PRESETS_DOCSIS_31      = ( 1UL << PTP_PRESETS_DOCSIS_31)        ///< see ::PTP_PRESETS_DOCSIS_31
};


/**
 * @brief Name strings for defined PTP presets
 *
 * @see ::PTP_PRESETS
 */
#define PTP_PRESETS_STRS       \
{                              \
  "Custom",                    \
  "Default E2E IEEE1588-2008", \
  "Default P2P IEEE1588-2008", \
  "Power IEEE C37.238",        \
  "Telecom ITU-T G.8265.1",    \
  "Telecom ITU-T G.8275.1",    \
  "SMPTE ST 2059-2",           \
  "AES67 Media Profile",       \
  "IEEE 802.1AS",              \
  "Utility IEC 61850-9-3",     \
  "Telecom ITU-T G.8275.2",    \
  "DOCSIS 3.1"                 \
}



/**
 * @brief Additional parameters for Power Profile
 */
#define PTP_POWER_PROFILE_GM_ID_MIN   3
#define PTP_POWER_PROFILE_GM_ID_MAX   255

typedef struct
{
  uint32_t  network_incaccuracy;   ///< Pre-defined network inaccuracy from master in [ns]
  uint8_t   grandmaster_id;        ///< [::PTP_POWER_PROFILE_GM_ID_MIN..::PTP_POWER_PROFILE_GM_ID_MAX]
  uint8_t   reserved_1;
  uint16_t  reserved_2;
  TZDL      tzdl;

} PTP_POWER_PROFILE_CFG;

#define _mbg_swab_ptp_power_profile_cfg( _p )  \
do                                             \
{                                              \
  _mbg_swab32( &(_p)->network_incaccuracy );   \
  _mbg_swab8( &(_p)->grandmaster_id );         \
  _mbg_swab8( &(_p)->reserved_1 );             \
  _mbg_swab16( &(_p)->reserved_2 );            \
  _mbg_swab_tzdl( &(_p)->tzdl );               \
  _mbg_swab32( &(_p)->flags );                 \
} while ( 0 )



#if defined( _PRELIMINARY_CODE )

// TODO: These definitions are preliminary and maybe subject to changes.

/**
 * @brief SMPTE System Frame Rates according to SMPTE ST 2059-2
 *
 * @see ::TODO
 */
enum SMPTE_SYSTEM_FRAME_RATES
{
  SMPTE_23_98HZ,
  SMPTE_24HZ,
  SMPTE_25HZ,
  SMPTE_29_97HZ,
  SMPTE_50HZ,
  SMPTE_59_94HZ,
  N_SMPTE_SYSTEM_FRAME_RATES
};


#define SMPTE_SYSTEM_FRAME_RATE_STR \
{                                   \
  "24Hz (23.98)",                   \
  "24Hz",                           \
  "25Hz",                           \
  "30Hz (29.97)",                   \
  "50Hz",                           \
  "60Hz (59.94)"                    \
}


#define SMPTE_FRAME_RATE_NUM \
{                            \
  24000,                     \
  24000,                     \
  25000,                     \
  30000,                     \
  50000,                     \
  60000,                     \
}

#define SMPTE_FRAME_RATE_DENUM \
{                              \
  1001,                        \
  1000,                        \
  1000,                        \
  1001,                        \
  1000,                        \
  1001,                        \
}


/**
 * @brief Additional parameters for SMPTE ST 2059-2 profile
 *
 * This stucture holds the synchronization metadata required for the SMPTE profile.
 * This structure is only used for internal storage of the data. The data is
 * distributed through a network by using management messages and the dedicated
 * organization extension TLV defined in the SMPTE profile.
 */
typedef struct
{
  /// Default system frame rate
  /// Default video frame rate of the slave system as a lowest term rational.
  /// The data type shall be composed of a pair of unsigned Int32 values coded
  /// in big-endian form where the first shall be the numerator and the second
  /// shall be the denominator. The denominator shall be the smallest value
  /// that represents the frame rate denominator
  /// For example, 29.97 Hz: (30000/1001) or 25 Hz: (25/1).
  uint32_t defaultSystemFrameRateNum;
  uint32_t defaultSystemFrameRateDenum;
  /// Master locking status
  /// Complementary information to clockClass (0: Not in use, 1: Free Run,
  /// 2: Cold Locking, 3: Warm Locking, 4: Locked)
  uint8_t masterLockingStatus;
  /// Time Address Flags
  /// Indicates the intended ST 12-1 flags.
  /// Bit 0: Drop frame (0: Non-drop-frame, 1: Drop-frame)
  /// Bit 1: Color Frame Identification (0: Not in use, 1: In use)
  /// Bits 2-7:  Reserved
  uint8_t timeAddressFlags;
  /// Current local offset
  /// Offset in seconds of Local Time from grandmaster PTP time. For example,
  /// if Local Time is Eastern Standard Time (North America) UTC-5 and the
  /// number of leap seconds is 35, the value will be -18035 (decimal).

  uint8_t reserved_1;
  uint8_t reserved_2;

  int32_t currentLocalOffset;
  /// Jump seconds
  /// The size of the next discontinuity, in seconds, of Local Time. A value
  /// of zero indicates that no discontinuity is expected. A positive value
  /// indicates that the discontinuity will cause the currentLocalOffset to increase.
  int32_t jumpSeconds;
  /// Time of next jump
  /// The value of the seconds portion of the grandmastermaster PTP  time at the time
  /// that the next discontinuity of the currentLocalOffset will occur. The
  /// discontinuity occurs at the start of the second indicated
  uint8_t timeOfNextJump[6];
  /// Time of next jam
  /// The value of the seconds portion of the PTP time corresponding to the next
  /// scheduled occurrence of the Daily Jam. If no Daily Jam is scheduled, the
  /// value of timeOfNextJam shall be zero.
  uint8_t timeOfNextJam[6];
  /// Time of previous jam
  /// The value of the seconds portion of the PTP time corresponding to the
  /// previous occurrence of the Daily Jam.
  uint8_t timeOfPreviousJam[6];
  /// Previous jam local offset
  /// The value of currentLocalOffset at the previous daily jam time.
  /// If a discontinuity of Local Time occurs at the jam time, this parameter
  /// reflects the offset after the discontinuity.
  uint8_t reserved_3;
  uint8_t reserved_4;
  uint32_t reserved_5;

  int32_t previousJamLocalOffset;
  /// Daylight saving
  /// Bit 0:  Current Daylight Saving (0: Not in effect, 1: In effect)
  /// Bit 1: Daylight Saving at next discontinuity (0: Not in effect, 1: In effect)
  /// Bit 2: Daylight Saving at previous daily jam time (0: Not in effect, 1: In effect)
  /// Bits 3-7: Reserved
  uint8_t daylightSaving;
  /// Leap second jump
  /// The reason for the forthcoming discontinuity of currentLocalOffset indicated by
  /// timeOfNextJump
  /// Bit 0:
  ///   0: Other than a change in the number of leap seconds (default)
  ///   1: A change in number of leap seconds
  /// Bits 1-7: Reserved
  uint8_t leapSecondJump;

  uint8_t reserved_6;
  uint8_t reserved_7;

  uint32_t reserved_8;
  uint32_t reserved_9;
  uint32_t reserved_10;

} PTP_SMPTE_PROFILE_CFG;



/**
 * @brief Additional parameters for Telecom8275.1 profile
 */
typedef struct
{
  uint8_t  use_alternate_multicast_address;
  uint8_t  reserved_1;
  uint8_t  reserved_2;
  uint8_t  reserved_3;
  uint32_t reserved_4;

} PTP_TELECOMG8275_PROFILE_CFG;

#define _mbg_swab_ptp_telecom8275_profile_cfg( _p )          \
do                                                           \
{                                                            \
  _mbg_swab8( &(_p)->use_alternate_multicast_mac_address );  \
  _mbg_swab8( &(_p)->reserved_1 );                           \
  _mbg_swab8( &(_p)->reserved_2 );                           \
  _mbg_swab8( &(_p)->reserved_3 );                           \
  _mbg_swab32( &(_p)->reserved_4 );                          \
} while ( 0 )



/**
 * @brief A type which holds one of the ITU-T SSM codes
 *
 * @see ::ITU_SSM_CODES
 */
typedef uint16_t ITU_SSM_CODE;



/**
 * @brief ITU-T SSM codes acc. to Recommendation G.781
 *
 * @see ::ITU_SSM_CODE
 */
enum ITU_SSM_CODES
{
  ITU_SSM_CODE_STU_UKN,
  ITU_SSM_CODE_PRS,
  ITU_SSM_CODE_PRC,
  ITU_SSM_CODE_INV3,
  ITU_SSM_CODE_SSU_A_TNC,
  ITU_SSM_CODE_INV5,
  ITU_SSM_CODE_INV6,
  ITU_SSM_CODE_ST2,
  ITU_SSM_CODE_SSU_B,
  ITU_SSM_CODE_INV9,
  ITU_SSM_CODE_ST3,
  ITU_SSM_CODE_SEC,
  ITU_SSM_CODE_SMC,
  ITU_SSM_CODE_ST3E,
  ITU_SSM_CODE_PROV,
  ITU_SSM_CODE_DNU_DUS,
  N_ITU_SSM_CODES
};


#define N_SSM_CODES_OPTION_1    5
#define N_SSM_CODES_OPTION_2    9


/**
 * @brief Name strings for SSM codes, network option I
 *
 * @see ::ITU_SSM_CODES
 */
#define ITU_SSM_CODE_OPT_1_STRS \
{                               \
  "",                           \
  "",                           \
  "QL-PRC",                     \
  "",                           \
  "QL-SSU-A",                   \
  "",                           \
  "",                           \
  "",                           \
  "QL-SSU-B",                   \
  "",                           \
  "",                           \
  "QL-SEC",                     \
  "",                           \
  "",                           \
  "",                           \
  "QL-DNU"                      \
}



/**
 * @brief Name strings for SSM codes, network option II
 *
 * @see ::ITU_SSM_CODES
 */
#define ITU_SSM_CODE_OPT_2_STRS \
{                               \
  "QL-STU",                     \
  "QL-PRS",                     \
  "",                           \
  "",                           \
  "QL-TNC",                     \
  "",                           \
  "",                           \
  "QL-ST2",                     \
  "",                           \
  "",                           \
  "QL-ST3",                     \
  "",                           \
  "QL-SMC",                     \
  "QL-ST3E",                    \
  "QL-PROV",                    \
  "QL-DUS"                      \
}



/**
 * @brief Name strings for SSM codes, option I and II combined
 *
 * @see ::ITU_SSM_CODES
 */
#define ITU_SSM_CODE_STRS_COMBINED \
{                                  \
  "QL-STU/UKN",                    \
  "QL-PRS",                        \
  "QL-PRC",                        \
  "QL-INV3",                       \
  "QL-SSU-A/TNC",                  \
  "QL-INV5",                       \
  "QL-INV6",                       \
  "QL-ST2",                        \
  "QL-SSU-B",                      \
  "QL-INV9",                       \
  "QL-EEC2/ST3",                   \
  "QL-EEC1/SEC",                   \
  "QL-SMC",                        \
  "QL-ST3E",                       \
  "QL-PROV",                       \
  "QL-DNU/DUS",                    \
}



/**
 * @brief Maximum T1 SSM only quality levels
 *
 * @see ::T1_SSM_QLVL
 * @see ::T1_SSM_QLVL_STRS
 * @see ::T1_SSM_QLVL_ARRAY
 */
#define MAX_T1_SSM_QLVL 8



/**
 * @brief T1 SSM only quality level (6 bit encoded)
 *
 * @see ::MAX_T1_SSM_QLVL
 * @see ::T1_SSM_QLVL_STRS
 * @see ::T1_SSM_QLVL_ARRAY
 */
enum T1_SSM_QLVL
{
  T1_SSM_QLVL_ST1_TRACE = 2,
  T1_SSM_QLVL_SYNC_TRACE_UNKNOWN = 4,
  T1_SSM_QLVL_ST2_TRACE = 6,
  T1_SSM_QLVL_ST3_TRACE = 8,
  T1_SSM_QLVL_SONET_MIN_CLOCK_TRACE = 17,
  T1_SSM_QLVL_ST4_TRACE = 20,
  T1_SSM_QLVL_DNU_FOR_SYNC = 24,
  T1_SSM_QLVL_RESERVED = 32
};



/**
 * @brief T1 SSM only quality level array
 *
 * @see ::MAX_T1_SSM_QLVL
 * @see ::T1_SSM_QLVL_STRS
 * @see ::T1_SSM_QLVL
 */
#define T1_SSM_QLVL_ARRAY               \
{                                       \
  T1_SSM_QLVL_ST1_TRACE,                \
  T1_SSM_QLVL_SYNC_TRACE_UNKNOWN,       \
  T1_SSM_QLVL_ST2_TRACE,                \
  T1_SSM_QLVL_ST3_TRACE,                \
  T1_SSM_QLVL_SONET_MIN_CLOCK_TRACE,    \
  T1_SSM_QLVL_ST4_TRACE,                \
  T1_SSM_QLVL_DNU_FOR_SYNC,             \
  T1_SSM_QLVL_RESERVED                  \
}



/**
 * @brief Name strings for T1 SSM quality levels
 *
 * @see ::MAX_T1_SSM_QLVL
 * @see ::T1_SSM_QLVL
 * @see ::T1_SSM_QLVL_ARRAY
 */
#define T1_SSM_QLVL_STRS                \
{                                       \
  "Stratum 1 traceable",                \
  "Synchronized traceability unknown",  \
  "Stratum 2 traceable",                \
  "Stratum 3 traceable",                \
  "SONET minimum clock traceable",      \
  "Stratum 4 traceable",                \
  "Do not use for sync",                \
  "Reserved for network sync"           \
}



/**
 * @brief SDH network options
 *
 * @see ::SDH_NETWORK_OPTION_MASKS
 */
enum SDH_NETWORK_OPTIONS
{
  SDH_NETWORK_OPTION_1,
  SDH_NETWORK_OPTION_2,
  N_SDH_NETWORK_OPTIONS

};



/**
 * @brief Flag masks used with ::MBG_SYNC_E_INFO::supp_sdh_network_opts
 *
 * @see ::SDH_NETWORK_OPTIONS
 */
enum SDH_NETWORK_OPTION_MASKS
{
  SDH_NETWORK_OPTION_1_MSK = ( 1UL << SDH_NETWORK_OPTION_1 ),  ///< see ::SDH_NETWORK_OPTION_1
  SDH_NETWORK_OPTION_2_MSK = ( 1UL << SDH_NETWORK_OPTION_2 ),  ///< see ::SDH_NETWORK_OPTION_2
};



/**
 * @brief Name strings for SDH network options
 *
 * @see ::SDH_NETWORK_OPTION
 */
#define SDH_NETWORK_OPTION_STRS \
{                               \
  "SDH Network Opt. 1",         \
  "SDH Network Opt. 2",         \
}



//##++++ TODO: shouldn't this be merged with / replaced by MBG_NET_LINK_MODES?
/**
 * @brief Link modes for SyncE on a 1000BASE-T interface
 *
 * @see ::GBIT_LINK_COPPER_MODE_MASKS
 */
enum GBIT_LINK_COPPER_MODES
{
  GBIT_LINK_COPPER_AUTO,                // valid if synce is disabled
  GBIT_LINK_COPPER_FORCE_SYNCE_AUTO,
  GBIT_LINK_COPPER_FORCE_OR_IS_MASTER,  // Used in both structures, settings and status
  GBIT_LINK_COPPER_FORCE_OR_IS_SLAVE,   // Used in both structures, settings and status
  GBIT_LINK_COPPER_PREFER_MASTER,
  GBIT_LINK_COPPER_PREFER_SLAVE,
  N_GBIT_LINK_COPPER_MODES
};



/**
 * @brief Flag masks used with ::MBG_SYNC_E_INFO::supp_gbit_link_copper_modes
 *
 * @see ::GBIT_LINK_COPPER_MODES
 */
enum GBIT_LINK_COPPER_MODE_MASKS
{
  GBIT_LINK_COPPER_AUTO_MSK               = ( 1UL << GBIT_LINK_COPPER_AUTO ),               ///< see ::GBIT_LINK_COPPER_AUTO_MSK
  GBIT_LINK_COPPER_FORCE_SYNCE_AUTO_MSK   = ( 1UL << GBIT_LINK_COPPER_FORCE_SYNCE_AUTO ),   ///< see ::GBIT_LINK_COPPER_FORCE_SYNCE_AUTO
  GBIT_LINK_COPPER_FORCE_OR_IS_MASTER_MSK = ( 1UL << GBIT_LINK_COPPER_FORCE_OR_IS_MASTER ), ///< see ::GBIT_LINK_COPPER_FORCE_OR_IS_MASTER
  GBIT_LINK_COPPER_FORCE_OR_IS_SLAVE_MSK  = ( 1UL << GBIT_LINK_COPPER_FORCE_OR_IS_SLAVE ),  ///< see ::GBIT_LINK_COPPER_FORCE_OR_IS_SLAVE
  GBIT_LINK_COPPER_PREFER_MASTER_MSK      = ( 1UL << GBIT_LINK_COPPER_PREFER_MASTER ),      ///< see ::GBIT_LINK_COPPER_PREFER_MASTER
  GBIT_LINK_COPPER_PREFER_SLAVE_MSK       = ( 1UL << GBIT_LINK_COPPER_PREFER_SLAVE )        ///< see ::GBIT_LINK_COPPER_PREFER_SLAVE
};



//##++++ TODO: shouldn't this be merged with MBG_NET_LINK_ROLE_BITS / MBG_NET_LINK_ROLE_MASKS?
/**
 * @brief Link status for SyncE on a 1000BASE-T interface
 *
 * @see ::TODO
 */
enum GBIT_LINK_STATUS
{
  GBIT_LINK_COPPER_IS_MASTER,  ///< GBIT Link is currently clock master
  GBIT_LINK_COPPER_IS_SLAVE,   ///< GBIT Link is currently clock slave
  GBIT_LINK_COPPER_CFG_FAULT,  ///< GBIT Link has a configruation fault (conflict with link partner
  GBIT_LINK_COPPER_IS_FE,      ///< Link is running on Fast Ethernet (no MASTER/SLAVE decision)
  GBIT_LINK_DOWN,              ///< Currently no link
  GBIT_LINK_FIBER,             ///< GBIT Linkup on SFP interface
  N_GBIT_LINK_STATUS
};


#define GBIT_LINK_STATUS_STRS   \
{                               \
  "MASTER (1000BASE-T)",        \
  "SLAVE (1000BASE-T)",         \
  "CFG FAULT",                  \
  "AUTO (100BASE-TX)",          \
  "LINK DOWN",                  \
  "AUTO (SFP LINK UP)",         \
}

#else  // !defined( _PRELIMINARY_CODE ), dummy declarations

typedef int PTP_SMPTE_PROFILE_CFG;
typedef int PTP_TELECOMG8275_PROFILE_CFG;
typedef int ITU_SSM_CODE;

#endif  // defined( _PRELIMINARY_CODE )



/**
 * @brief Limits to be considered when specifying PTP unicast masters
 */
typedef struct
{
  uint16_t n_supp_master;      ///< number of unicast masters which can be specified
  int16_t sync_intv_min;       ///< log2 of minimum sync interval [s]
  int16_t sync_intv_max;       ///< log2 of maximum sync interval [s]
  int16_t ann_intv_min;        ///< log2 of minimum announce interval [s]
  int16_t ann_intv_max;        ///< log2 of maximum announce interval [s]
  int16_t delay_req_intv_min;  ///< log2 of minimum delay request interval [s]
  int16_t delay_req_intv_max;  ///< log2 of maximum delay request interval [s]
  uint16_t reserved_0;         ///< reserved, currently always 0
  uint32_t supp_flags;         ///< a bit mask indicating which flags are supported
  uint32_t reserved_1;         ///< reserved, currently always 0

} PTP_UC_MASTER_CFG_LIMITS;

#define _mbg_swab_ptp_uc_master_cfg_limits( _p ) \
do                                               \
{                                                \
  _mbg_swab16( &(_p)->n_supp_master );           \
  _mbg_swab16( &(_p)->sync_intv_min );           \
  _mbg_swab16( &(_p)->sync_intv_max );           \
  _mbg_swab16( &(_p)->ann_intv_min );            \
  _mbg_swab16( &(_p)->ann_intv_max );            \
  _mbg_swab16( &(_p)->delay_req_intv_min );      \
  _mbg_swab16( &(_p)->delay_req_intv_max );      \
  _mbg_swab16( &(_p)->reserved_0 );              \
  _mbg_swab32( &(_p)->supp_flags );              \
  _mbg_swab32( &(_p)->reserved_1 );              \
} while ( 0 )



/**
 * @brief Configuration settings specifiying how to query a PTP unicast master
 *
 * This structure is used on a unicast slave to specify the settings of
 * a unicast master polled by the slave. The number of unicast masters
 * which can be specified depends on the capabilities of the slave device
 * and is returned in ::PTP_UC_MASTER_CFG_LIMITS::n_supp_master.
 *
 * The structure ::PTP_UC_MASTER_SETTINGS_IDX should be sent to the device
 * to save the configuration.
 */
typedef struct
{
  MBG_HOSTNAME gm_host;        ///< grandmaster's hostname or IP address
  PTP_CLOCK_ID gm_clock_id;    ///< use clock ID of master port, or ::PTP_CLOCK_ID_WILDCARD
  PTP_PORT_ID gm_port_id;      ///< use target port ID of master port (e.g. 135) or ::PTP_PORT_ID_WILDCARD
  int16_t sync_intv;           ///< sync interval [log2 s]
  int16_t ann_intv;            ///< announce interval [log2 s]
  int16_t delay_req_intv;      ///< delay request interval [log2 s]
  int32_t fix_offset;          ///< constant time offset to be compensated [ns]
  uint16_t message_duration;   ///< time period until master stops sending messages [s]
  uint16_t reserved_0;         ///< reserved, currently always 0
  uint32_t reserved_1;         ///< reserved, currently always 0
  uint32_t flags;              ///< reserved, currently always 0

} PTP_UC_MASTER_SETTINGS;

#define _mbg_swab_ptp_uc_master_settings( _p )   \
do                                               \
{                                                \
  _mbg_swab_ptp_clock_id( &(_p)->gm_clock_id );  \
  _mbg_swab_ptp_port_id( &(_p)->gm_port_id );    \
  _mbg_swab16( &(_p)->sync_intv );               \
  _mbg_swab16( &(_p)->ann_intv );                \
  _mbg_swab16( &(_p)->delay_req_intv );          \
  _mbg_swab32( &(_p)->fix_offset );              \
  _mbg_swab16( &(_p)->message_duration );        \
  _mbg_swab16( &(_p)->reserved_0 );              \
  _mbg_swab32( &(_p)->reserved_1 );              \
  _mbg_swab32( &(_p)->flags );                   \
} while ( 0 )



/**
 * @brief Unicast PTP master message duration limits
 *
 * Each unicast PTP master sends messages to a unicast slave only
 * for a given interval as requested by the particular slave, which
 * is called message duration.
 * These symbols define the minimum and maximum message duration
 * configured on a slave for a specific unicast master, i.e. for
 * PTP_UC_MASTER_SETTINGS::message_duration. The values are defined
 * in the PTP v2 standard.
 */
enum PTP_UC_MSG_DURATION_LIMITS
{
  PTP_UC_MSG_DURATION_MIN =   10,  ///< minimum message duration [s]
  PTP_UC_MSG_DURATION_MAX = 1000   ///< maximum message duration [s]
};



/**
 * @brief Configuration settings for a specific PTP unicast master
 */
typedef struct
{
  uint32_t idx;                     ///< index, 0..PTP_UC_MASTER_CFG_LIMITS::n_supp_master-1
  PTP_UC_MASTER_SETTINGS settings;  ///< specification for the unicast master with that index

} PTP_UC_MASTER_SETTINGS_IDX;

#define _mbg_swab_ptp_uc_master_settings_idx( _p )      \
do                                                      \
{                                                       \
  _mbg_swab32( &(_p)->idx );                            \
  _mbg_swab_ptp_uc_master_settings( &(_p)->settings );  \
} while ( 0 )



/**
 * @brief Current settings and general capabilities of a unicast master
 *
 * This structure is used with a PTP unicast slave device to specify
 * a PTP unicast master which can be queried by the slave device.
 */
typedef struct
{
  PTP_UC_MASTER_SETTINGS settings;  ///< current settings
  uint32_t reserved;                ///< reserved, currently always 0
  uint32_t flags;                   ///< reserved, currently always 0

} PTP_UC_MASTER_INFO;

#define _mbg_swab_ptp_uc_master_info( _p )              \
do                                                      \
{                                                       \
  _mbg_swab_ptp_uc_master_settings( &(_p)->settings );  \
  _mbg_swab32( &(_p)->reserved );                       \
  _mbg_swab32( &(_p)->flags );                          \
} while ( 0 )



/**
 * @brief Current settings and general capabilities of a specific unicast master
 *
 * This structure is used with a PTP unicast slave device to specify
 * a PTP unicast master which can be queried by the slave device.
 *
 * This structure should be read from the device to retrieve the
 * current settings and capabilities. The number of supported
 * configuration records is PTP_UC_MASTER_CFG_LIMITS::n_supp_master.
 *
 * @note The ::PTP_UC_MASTER_SETTINGS_IDX structure should be send back
 * to the device to save the configuration.
 */
typedef struct
{
  uint32_t idx;             ///< index, 0..PTP_UC_MASTER_CFG_LIMITS::n_supp_master-1
  PTP_UC_MASTER_INFO info;  ///< capabilities and current settings

} PTP_UC_MASTER_INFO_IDX;

#define _mbg_swab_ptp_uc_master_info_idx( _p )  \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->idx );                    \
  _mbg_swab_ptp_uc_master_info( &(_p)->info );  \
} while ( 0 )



typedef struct
{
  uint32_t counter_cfg;
  uint32_t flags;
  uint32_t reserved_1;
  uint32_t reserved_2;

} MBG_PTP_STATISTICS_SETTINGS;



typedef struct
{
  MBG_PTP_STATISTICS_SETTINGS settings;
  uint32_t supp_flags;                    ///< Supported settings, currently 0
  uint32_t reserved_1;

} MBG_PTP_STATISTICS_INFO;



typedef struct
{
  uint32_t status;          ///< status word flags (use PacketCounterStat_e)
  uint32_t rx;              ///< overall Rx packet counter
  uint32_t rxPerSec;              ///< overall Rx packet counter
  uint32_t tx;              ///< overall Tx packet counter
  uint32_t txPerSec;              ///< overall Tx packet counter
  /// invalid Rx packet counter
  /// Indicates one of the following issues: wrong PTP version, wrong domain number,
  /// message from self, message from other BC port, multicast message in unicast mode
  /// or message extraction error (size error or inconsistent format).
  uint32_t errorRx;
  uint32_t announceMsgRx;   ///< Accepted Announce message Rx counter
  uint32_t announceMsgPerSecRx;   ///< Accepted Announce message Rx counter
  uint32_t announceMsgTx;   ///< Announce message Tx counter
  uint32_t announceMsgPerSecTx;   ///< Announce message Tx counter
  uint32_t syncMsgRx;       ///< Accepted Sync message Rx counter
  uint32_t syncMsgPerSecRx;       ///< Accepted Sync message Rx counter
  uint32_t syncMsgTx;       ///< Sync message Tx counter
  uint32_t syncMsgPerSecTx;       ///< Sync message Tx counter
  uint32_t followUpMsgRx;   ///< Accepted Follow-up message Rx counter
  uint32_t followUpMsgPerSecRx;   ///< Accepted Follow-up message Rx counter
  uint32_t followUpMsgTx;   ///< Follow-up message Tx counter
  uint32_t followUpMsgPerSecTx;   ///< Follow-up message Tx counter
  uint32_t dlyReqMsgRx;     ///< Accepted Delay request message Rx counter
  uint32_t dlyReqMsgPerSecRx;     ///< Accepted Delay request message Rx counter
  uint32_t dlyReqMsgTx;     ///< Delay request message Tx counter
  uint32_t dlyReqMsgPerSecTx;     ///< Delay request message Tx counter
  uint32_t dlyRespMsgRx;    ///< Accepted Delay response message Rx counter
  uint32_t dlyRespMsgPerSecRx;    ///< Accepted Delay response message Rx counter
  uint32_t dlyRespMsgTx;    ///< Delay response message Tx counter
  uint32_t dlyRespMsgPerSecTx;    ///< Delay response message Tx counter
  uint32_t pDlyReqMsgRx;    ///< Accepted PDelay Request message Rx counter
  uint32_t pDlyReqMsgPerSecRx;    ///< Accepted PDelay Request message Rx counter
  uint32_t pDlyReqMsgTx;    ///< PDelay Request message Tx counter
  uint32_t pDlyReqMsgPerSecTx;    ///< PDelay Request message Tx counter
  uint32_t pDlyRespMsgRx;   ///< Accepted PDelay Response message Rx counter
  uint32_t pDlyRespMsgPerSecRx;   ///< Accepted PDelay Response message Rx counter
  uint32_t pDlyRespMsgTx;   ///< PDelay Response message Tx counter
  uint32_t pDlyRespMsgPerSecTx;   ///< PDelay Response message Tx counter
  uint32_t pDlyFollowUpRx;  ///< Accepted PDelay Follow-Up message Rx counter
  uint32_t pDlyFollowUpPerSecRx;  ///< Accepted PDelay Follow-Up message Rx counter
  uint32_t pDlyFollowUpTx;  ///< PDelay Follow-Up message Tx counter
  uint32_t pDlyFollowUpPerSecTx;  ///< PDelay Follow-Up message Tx counter
  uint32_t signallingRx;    ///< Accepted Signalling message Rx counter
  uint32_t signallingPerSecRx;    ///< Accepted Signalling message Rx counter
  uint32_t signallingTx;    ///< Signalling message Tx counter
  uint32_t signallingPerSecTx;    ///< Signalling message Tx counter
  uint32_t mgmtRx;          ///< Accepted Management message Rx counter
  uint32_t mgmtPerSecRx;          ///< Accepted Management message Rx counter
  uint32_t mgmtTx;          ///< Management message Tx counter
  uint32_t mgmtPerSecTx;          ///< Management message Tx counter
  uint32_t mgmtErr;         ///< Management error counter (rx)
  uint32_t annReceptTout;   ///< Announce recept timeout count

  uint32_t numUcConn;       ///< Number of current Unicast client connections
  uint32_t maxNumUcConn;    ///< Maximum Number of Unicast client connections (due to licence or CPU performance)
  uint32_t numMsgPerSec;    ///< Number of all messages per second (TX/RX)
  uint32_t maxMsgPerSec;    ///< max allowed number of all messages per second in Multicast/Hybrid mode (due to licence or CPU performance)

} MBG_PTP_STATISTICS_STATUS;



enum PTP_V1_COMM_IDS
{
  V1_PTP_CLOSED,
  V1_PTP_ETHER,
  /* reserved */
  V1_PTP_FFBUS = 4,
  V1_PTP_PROFIBUS,
  V1_PTP_LON,
  V1_PTP_DNET,
  V1_PTP_SDS,
  V1_PTP_CONTROLNET,
  V1_PTP_CANOPEN,
  /* reserved */
  V1_PTP_IEEE1394 = 243,
  V1_PTP_IEEE802_11A,
  V1_PTP_IEEE_WIRELESS,
  V1_PTP_INFINIBAND,
  V1_PTP_BLUETOOTH,
  V1_PTP_IEEE802_15_1,
  V1_PTP_IEEE1451_3,
  V1_PTP_IEEE1451_5,
  V1_PTP_USB,
  V1_PTP_ISA,
  V1_PTP_PCI,
  V1_PTP_VXI,
  V1_PTP_DEFAULT
};



#define PTP_CODE_STRING_LENGTH 4
#define PTP_SUBDOMAIN_NAME_LENGTH 16


/**
 * @brief PTPv1 UUID structure used in ::MBG_PTP_V1_DEFAULT_DATASET
 *
 * @see ::MBG_PTP_V1_DEFAULT_DATASET
 */
typedef struct
{
  uint8_t       communication_technology;
  uint8_t       reserved_1;
  uint16_t      reserved_2;
  PTP_CLOCK_ID  clock_uuid;
  PTP_PORT_ID   port_id;
  uint16_t      reserved_3;
} PTP_V1_UUID;


#define _mbg_swab_ptp_v1_uuid( _p )              \
do                                               \
{                                                \
  _mbg_swab16( &(_p)->reserved_2 );              \
  _mbg_swab_ptp_clock_id( &(_p)->clock_uuid );   \
  _mbg_swab_ptp_port_id( &(_p)->port_id );       \
  _mbg_swab16( &(_p)->reserved_3 );              \
} while ( 0 )



/**
 * @brief PTPv1 default dataset flags
 *
 * @see ::PTP_V1_DEFAULT_DATASET_FLAGS_MASKS
 */
enum PTP_V1_DEFAULT_DATASET_FLAGS
{
  V1_DFLT_CLK_FOLLOWUP_CAPABLE,
  V1_DFLT_PREFERRED,
  V1_DFLT_INITIALIZABLE,
  V1_DFLT_EXT_TIMING,
  V1_DFLT_IS_BC
};



/**
 * @brief PTPv1 default dataset flag masks used with ::MBG_PTP_V1_DEFAULT_DATASET::flags
 *
 * @see ::PTP_V1_DEFAULT_DATASET_FLAGS
 */
enum PTP_V1_DEFAULT_DATASET_FLAGS_MASKS
{
  V1_DFLT_MSK_CLK_FOLLOWUP_CAPABLE  = ( 1UL << V1_DFLT_CLK_FOLLOWUP_CAPABLE ),      ///< see ::V1_DFLT_CLK_FOLLOWUP_CAPABLE
  V1_DFLT_MSK_PREFERRED             = ( 1UL << V1_DFLT_PREFERRED ),                 ///< see ::V1_DFLT_PREFERRED
  V1_DFLT_MSK_INITIALIZABLE         = ( 1UL << V1_DFLT_INITIALIZABLE ),             ///< see ::V1_DFLT_INITIALIZABLE
  V1_DFLT_MSK_EXT_TIMING            = ( 1UL << V1_DFLT_EXT_TIMING),                 ///< see ::V1_DFLT_EXT_TIMING
  V1_DFLT_MSK_IS_BC                 = ( 1UL << V1_DFLT_IS_BC )                      ///< see ::V1_DFLT_IS_BC
};



/**
 * @brief PTPv1 default dataset containing global information about the device
 *
 * @see ::PTP_V1_UUID
 */
typedef struct {
  PTP_V1_UUID uuid;
  uint8_t     clock_stratum;
  uint8_t     clock_identifier[PTP_CODE_STRING_LENGTH];
  uint16_t    clock_variance;
  int8_t      sync_interval;
  uint8_t     subdomain_name[PTP_SUBDOMAIN_NAME_LENGTH];
  uint16_t    number_ports;
  uint16_t    number_foreign_records;
  uint32_t    flags;
} MBG_PTP_V1_DEFAULT_DATASET;


#define _mbg_swab_ptp_v1_default_dataset( _p )   \
do                                               \
{                                                \
  _mbg_swab_ptp_v1_uuid( &(_p)->uuid );          \
  _mbg_swab16( &(_p)->clock_variance );          \
  _mbg_swab16( &(_p)->number_ports );            \
  _mbg_swab16( &(_p)->number_foreign_records );  \
  _mbg_swab32( &(_p)->flags );                   \
} while ( 0 )



/**
 * @brief PTPv1 current dataset containing information about the synchronization status of the device
 *
 * @see ::NANO_TIME
 */
typedef struct
{
  uint16_t  steps_removed;
  uint16_t  reserved_1;
  NANO_TIME offset_from_master;
  NANO_TIME one_way_delay;
} MBG_PTP_V1_CURRENT_DATASET;


#define _mbg_swab_ptp_v1_current_dataset( _p )       \
do                                                   \
{                                                    \
  _mbg_swab16( &(_p)->steps_removed );               \
  _mbg_swab16( &(_p)->reserved_1 );                  \
  _mbg_swab_nano_time( &(_p)->offset_from_master );  \
  _mbg_swab_nano_time( &(_p)->one_way_delay );       \
} while ( 0 )



/**
 * @brief PTPv1 parent dataset flags
 *
 * @see ::PTP_V1_PARENT_DATASET_FLAGS_MASKS
 */
enum PTP_V1_PARENT_DATASET_FLAGS
{
  V1_PARENT_FOLLOWUP_CAPABLE,
  V1_PARENT_EXT_TIMING,
  V1_PARENT_STATS,
  V1_PARENT_UTC_REASONABLE,
  V1_PARENT_GM_PREFERRED,
  V1_PARENT_GM_IS_BC
};



/**
 * @brief PTPv1 parent dataset flag masks used with ::MBG_PTP_V1_PARENT_DATASET::flags
 *
 * @see ::PTP_V1_PARENT_DATASET_FLAGS
 */
enum PTP_V1_PARENT_DATASET_FLAGS_MASKS
{
  V1_PARENT_MSK_FOLLOWUP_CAPABLE  = ( 1UL << V1_PARENT_FOLLOWUP_CAPABLE ),      ///< see ::V1_PARENT_FOLLOWUP_CAPABLE
  V1_PARENT_MSK_EXT_TIMING        = ( 1UL << V1_PARENT_EXT_TIMING ),            ///< see ::V1_PARENT_EXT_TIMING
  V1_PARENT_MSK_STATS             = ( 1UL << V1_PARENT_STATS ),                 ///< see ::V1_PARENT_STATS
  V1_PARENT_MSK_UTC_REASONABLE    = ( 1UL << V1_PARENT_UTC_REASONABLE ),        ///< see ::V1_PARENT_UTC_REASONABLE
  V1_PARENT_MSK_GM_PREFERRED      = ( 1UL << V1_PARENT_GM_PREFERRED ),          ///< see ::V1_PARENT_GM_PREFERRED
  V1_PARENT_MSK_GM_IS_BC          = ( 1UL << V1_PARENT_GM_IS_BC )               ///< see ::V1_PARENT_GM_IS_BC
};



/**
 * @brief PTPv1 parent dataset containing information about the master (parent) of the device
 *
 * @see ::PTP_V1_UUID
 */
typedef struct
{
  PTP_V1_UUID uuid;
  uint16_t    parent_last_sync_sequence_number;
  int16_t     parent_variance;
  int16_t     observed_variance;
  uint16_t    reserved_1;
  int32_t     observed_drift;
  PTP_V1_UUID grandmaster_uuid;
  uint8_t     grandmaster_stratum;
  uint8_t     grandmaster_identifier[PTP_CODE_STRING_LENGTH];
  int16_t     grandmaster_variance;
  uint16_t    grandmaster_sequence_number;
  uint16_t    reserved_2;
  uint32_t    flags;
} MBG_PTP_V1_PARENT_DATASET;


#define _mbg_swab_ptp_v1_parent_dataset( _p )             \
do                                                        \
{                                                         \
  _mbg_swab_ptp_v1_uuid( &(_p)->uuid );                   \
  _mbg_swab16( &(_p)->parent_last_sync_sequence_number ); \
  _mbg_swab16( &(_p)->parent_variance );                  \
  _mbg_swab16( &(_p)->observed_variance );                \
  _mbg_swab16( &(_p)->reserved_1 );                       \
  _mbg_swab32( &(_p)->observed_drift );                   \
  _mbg_swab_ptp_v1_uuid( &(_p)->grandmaster_uuid );       \
  _mbg_swab16( &(_p)->grandmaster_variance );             \
  _mbg_swab16( &(_p)->grandmaster_sequence_number );      \
  _mbg_swab16( &(_p)->reserved_2 );                       \
  _mbg_swab32( &(_p)->flags );                            \
} while ( 0 )



/**
 * @brief PTPv1 time drop dataset flags
 *
 * @see ::PTP_V1_TIME_PROP_DATASET_FLAGS_MASKS
 */
enum PTP_V1_TIME_PROP_DATASET_DATASET_FLAGS
{
  V1_TPROP_LEAP_59,
  V1_TPROP_LEAP_61,
};



/**
 * @brief PTPv1 time drop dataset flag masks used with ::MBG_PTP_V1_TIME_PROP_DATASET::flags
 *
 * @see ::PTP_V1_TIME_PROP_DATASET_DATASET_FLAGS
 */
enum PTP_V1_TIME_PROP_DATASET_FLAGS_MASKS
{
  V1_TPROP_MSK_LEAP_59  = ( 1UL << V1_TPROP_LEAP_59 ),        ///< see ::V1_TPROP_LEAP_59
  V1_TPROP_MSK_LEAP_61  = ( 1UL << V1_TPROP_LEAP_61 ),        ///< see ::V1_TPROP_LEAP_61
};



/**
 * @brief PTPv1 time drop dataset
 *
 */
typedef struct
{
  int16_t   current_utc_offset;
  uint16_t  epoch_number;
  uint32_t  flags;
} MBG_PTP_V1_TIME_PROPERTIES_DATASET;


#define _mbg_swab_ptp_v1_time_properties_dataset( _p )  \
do                                                      \
{                                                       \
  _mbg_swab16( &(_p)->current_utc_offset );             \
  _mbg_swab16( &(_p)->epoch_number );                   \
  _mbg_swab32( &(_p)->flags );                          \
} while ( 0 )



/**
 * @brief PTPv1 port dataset flags
 *
 * @see ::PTP_V1_PORT_DATASET_FLAGS_MASKS
 */
enum PTP_V1_PORT_DATASET_DATASET_FLAGS
{
  V1_PORT_DATASET_BURST_ENB,
};



/**
 * @brief PTPv1 port dataset flag masks used with ::MBG_PTP_V1_PORT_DATASET::flags
 *
 * @see ::PTP_V1_PORT_DATASET_DATASET_FLAGS
 */
enum PTP_V1_PORT_DATASET_FLAGS_MASKS
{
  V1_PORT_DATASET_MSK_BURST_ENB  = ( 1UL << V1_PORT_DATASET_BURST_ENB ),        ///< see ::V1_PORT_DATASET_BURST_ENB
};



/**
 * @brief PTPv1 port dataset containing information about the appropriate port of the device
 *
 * @see ::PTP_V1_UUID
 */
typedef struct
{
  uint8_t     port_state;
  uint8_t     reserved_1;
  uint16_t    last_sync_event_sequence_number;
  uint16_t    last_general_event_sequence_number;
  uint16_t    reserved_2;
  uint32_t    subdomain_address;
  uint16_t    event_port_address;
  uint16_t    general_port_address;
  PTP_V1_UUID uuid;
  uint32_t    flags;
} MBG_PTP_V1_PORT_DATASET;


#define _mbg_swab_ptp_v1_port_dataset( _p )                    \
do                                                             \
{                                                              \
  _mbg_swab16( &(_p)->last_sync_event_sequence_number );       \
  _mbg_swab16( &(_p)->last_general_event_sequence_number );    \
  _mbg_swab16( &(_p)->reserved_2 );                            \
  _mbg_swab32( &(_p)->subdomain_address );                     \
  _mbg_swab16( &(_p)->event_port_address );                    \
  _mbg_swab16( &(_p)->general_port_address );                  \
  _mbg_swab_ptp_v1_uuid( &(_p)->uuid );                        \
  _mbg_swab32( &(_p)->flags );                                 \
} while ( 0 )



/**
 * @brief Index structure for PTPv1 port dataset
 *
 * @note Port dataset with index 0..::MBG_PTP_V1_DEFAULT_DATASET::number_ports - 1 can be queried from a device
 *
 * @see ::MBG_PTP_V1_PORT_DATASET
 */
typedef struct
{
  uint16_t idx;                                       ///< Index of the port dataset, 0..::MBG_PTP_V1_DEFAULT_DATASET::number_ports - 1
  MBG_PTP_V1_PORT_DATASET port_dataset;               ///< see ::MBG_PTP_V1_PORT_DATASET

} MBG_PTP_V1_PORT_DATASET_IDX;


#define _mbg_swab_ptp_v1_port_dataset_idx( _p )           \
{                                                         \
  _mbg_swab16( &(_p)->idx );                              \
  _mbg_swab_ptp_v1_port_dataset( &(_p)->port_dataset );   \
}


/**
 * @brief Flags structure for the PTPv2 default dataset
 *
 * @note For further information, see IEEE 1588-2008, chapters 8.2.1 and 15.5.3.3.1
 *
 * @see ::MBG_PTP_V2_DEFAULT_DATASET
 */
typedef struct
{
  uint8_t two_step        : 1;                        ///< indicates, whether the clock is a two-step clock
  uint8_t slave_only      : 1;                        ///< indicates, whether the clock is a slave-only clock
  uint8_t reserved        : 6;                        ///< reserved, currently always 0

} MBG_PTP_V2_DEFAULT_DATASET_FLAGS;

#define _mbg_swab_ptp_v2_default_dataset_flags( _p ) \
  _nop_macro_fnc()


/**
 * @brief PTPv2 default dataset
 *
 * @note For further information, see IEEE 1588-2008, chapters 8.2.1 and 15.5.3.3.1
 *
 * @see ::MBG_PTP_V2_DEFAULT_DATASET_FLAGS
 * @see ::PTP_CLOCK_QUALITY
 * @see ::PTP_CLOCK_ID
 */
typedef struct
{
  MBG_PTP_V2_DEFAULT_DATASET_FLAGS flags;             ///< flags field, see ::MBG_PTP_V2_DEFAULT_DATASET_FLAGS
  uint8_t reserved_1;                                 ///< reserved, currently always 0
  uint16_t number_ports;                              ///< number of PTP ports on the device
  uint8_t priority_1;                                 ///< priority 1 attribute for the local clock
  PTP_CLOCK_QUALITY clock_quality;                    ///< quality of the local clock, see ::PTP_CLOCK_QUALITY
  uint8_t priority_2;                                 ///< priority 2 attribute for the local clock
  PTP_CLOCK_ID clock_identity;                        ///< identity of the local clock, see ::PTP_CLOCK_ID
  uint8_t domain_number;                              ///< domain attribute of the local clock
  uint8_t reserved_2;                                 ///< reserved, currently always 0

} MBG_PTP_V2_DEFAULT_DATASET;


#define _mbg_swab_ptp_v2_default_dataset( _p )            \
{                                                         \
  _mbg_swab_ptp_v2_default_dataset_flags( &(_p)->flags ); \
  _mbg_swab8( &(_p)->reserved_1 );                        \
  _mbg_swab16( &(_p)->number_ports );                     \
  _mbg_swab8( &(_p)->priority_1 );                        \
  _mbg_swab_ptp_clock_quality( &(_p)->clock_quality );    \
  _mbg_swab8( &(_p)->priority_2 );                        \
  _mbg_swab_ptp_clock_id( &(_p)->clock_identity );        \
  _mbg_swab8( &(_p)->domain_number );                     \
  _mbg_swab8( &(_p)->reserved_2 );                        \
}


/**
 * @brief PTPv2 current dataset
 *
 * @note For further information, see IEEE 1588-2008, chapters 8.2.2 and 15.5.3.4.1
 *
 * @see ::PTP_TIME_INTERVAL
 */
typedef struct
{
  uint16_t steps_removed;                             ///< number of communication paths between local clock and grandmaster
  PTP_TIME_INTERVAL offset_from_master;               ///< current time difference between master and slave, see ::PTP_TIME_INTERVAL
  PTP_TIME_INTERVAL mean_path_delay;                  ///< current mean propagation time between master and slave, see ::PTP_TIME_INTERVAL

} MBG_PTP_V2_CURRENT_DATASET;


#define _mbg_swab_ptp_v2_current_dataset( _p )                \
{                                                             \
  _mbg_swab16( &(_p)->steps_removed );                        \
  _mbg_swab_ptp_time_interval( &(_p)->offset_from_master );   \
  _mbg_swab_ptp_time_interval( &(_p)->mean_path_delay );      \
}


/**
 * @brief Flags structure for the PTPv2 parent dataset
 *
 * @note For further information, see IEEE 1588-2008, chapters 8.2.3.3 and 15.5.3.5.1.2
 *
 * @see ::MBG_PTP_V2_PARENT_DATASET
 */
typedef struct
{
  uint8_t parent_stats    : 1;                        ///< indicates, whether the variance and change rate values are valid
  uint8_t reserved        : 7;                        ///< reserved, currently always 0

} MBG_PTP_V2_PARENT_DATASET_FLAGS;

#define _mbg_swab_ptp_v2_parent_dataset_flags( _p )\
  _nop_macro_fnc()



/**
 * @brief PTPv2 parent dataset
 *
 * @note For further information, see IEEE 1588-2008, chapters 8.2.3 and 15.5.3.5.1
 *
 * @see ::PTP_PORT_IDENTITY
 * @see ::MBG_PTP_V2_PARENT_DATASET_FLAGS
 * @see ::PTP_CLOCK_QUALITY
 * @see ::PTP_CLOCK_ID
 */
typedef struct
{
  PTP_PORT_IDENTITY parent_port_identity;             ///< identity of the master port, that issues the sync messages, see ::PTP_PORT_IDENTITY
  MBG_PTP_V2_PARENT_DATASET_FLAGS flags;              ///< flags field, see ::MBG_PTP_V2_PARENT_DATASET_FLAGS
  uint8_t reserved;                                   ///< reserved, currently always 0
  uint16_t parent_log_variance;                       ///< estimate of the parent clock's PTP variance, only valid if ::flags::parent_stats is set
  int32_t parent_phase_change_rate;                   ///< estimate of the parent clock's phase change rate, only valid if ::flags::parent_stats is set
  uint8_t grandmaster_priority_1;                     ///< priority 1 attribute of the grandmaster clock
  PTP_CLOCK_QUALITY grandmaster_clock_quality;        ///< quality of the grandmaster clock, see ::PTP_CLOCK_QUALITY
  uint8_t grandmaster_priority_2;                     ///< priority 2 attribute of the grandmaster clock
  PTP_CLOCK_ID grandmaster_identity;                  ///< identity of the grandmaster clock, see ::PTP_CLOCK_ID

} MBG_PTP_V2_PARENT_DATASET;


#define _mbg_swab_ptp_v2_parent_dataset( _p )                      \
{                                                                  \
  _mbg_swab_ptp_port_identity( &(_p)->parent_port_identity );      \
  _mbg_swab_ptp_v2_parent_dataset_flags( &(_p)->flags );           \
  _mbg_swab8( &(_p)->reserved );                                   \
  _mbg_swab16( &(_p)->parent_log_variance );                       \
  _mbg_swab32( &(_p)->parent_phase_change_rate );                  \
  _mbg_swab8( &(_p)->grandmaster_priority_1 );                     \
  _mbg_swab_ptp_clock_quality( &(_p)->grandmaster_clock_quality ); \
  _mbg_swab8( &(_p)->grandmaster_priority_2 );                     \
  _mbg_swab_ptp_clock_id( &(_p)->grandmaster_identity );           \
}


/**
 * @brief Flags structure for the PTPv2 time properties dataset
 *
 * @note For further information, see IEEE 1588-2008, chapters 8.2.4 and 15.5.3.6.1
 *
 * @see ::MBG_PTP_V2_TIME_PROPERTIES_DATASET
 */
typedef struct
{
  uint8_t leap_61             : 1;                    ///< set, if the last minute of the current UTC day containts 61 seconds
  uint8_t leap_59             : 1;                    ///< set, if the last minute of the current UTC day containts 59 seconds
  uint8_t utc_offset_valid    : 1;                    ///< set, if the current UTC offset is known to be correct
  uint8_t ptp_timescale       : 1;                    ///< set, if the timescale of the grandmaster clock is PTP
  uint8_t time_traceable      : 1;                    ///< set, if timescale and utc offset are traceable to a primary reference
  uint8_t frequency_traceable : 1;                    ///< set, if the frequency determining the timescale is traceable to a primary reference
  uint8_t reserved            : 2;                    ///< reserved, currently always 0

} MBG_PTP_V2_TIME_PROPERTIES_DATASET_FLAGS;


#define _mbg_swab_ptp_v2_time_properties_dataset_flags( _p ) \
  _nop_macro_fnc()


/**
 * @brief PTPv2 time properties dataset
 *
 * @note For further information, see IEEE 1588-2008, chapters 8.2.4 and 15.5.3.6.1
 *
 * @see ::MBG_PTP_V2_TIME_PROPERTIES_DATASET_FLAGS
 */
typedef struct
{
  int16_t current_utc_offset;                         ///< offset between TAI and UTC in seconds
  MBG_PTP_V2_TIME_PROPERTIES_DATASET_FLAGS flags;     ///< flags field, see ::MBG_PTP_V2_TIME_PROPERTIES_DATASET_FLAGS
  uint8_t time_source;                                ///< source of time used by the grandmaster clock, see ::PTP_TIME_SOURCES

} MBG_PTP_V2_TIME_PROPERTIES_DATASET;


#define _mbg_swab_ptp_v2_time_properties_dataset( _p )             \
{                                                                  \
  _mbg_swab16( &(_p)->current_utc_offset );                        \
  _mbg_swab_ptp_v2_time_properties_dataset_flags( &(_p)->flags );  \
  _mbg_swab8( &(_p)->time_source );                                \
}


/**
 * @brief PTPv2 port dataset
 *
 * @note For further information, see IEEE 1588-2008, chapters 8.2.5 and 15.5.3.7.1
 *
 * @see ::PTP_PORT_IDENTITY
 * @see ::PTP_TIME_INTERVAL
 * @see ::MBG_PTP_V2_PORT_DATASET_IDX
 */
typedef struct
{
  PTP_PORT_IDENTITY port_identity;                    ///< identity of the local port, see ::PTP_PORT_IDENTITY
  uint8_t port_state;                                 ///< state of the protocol engine associated with this port, see ::PTP_PORT_STATES
  int8_t log_min_delay_req_interval;                  ///< minimum delay request interval for this port
  PTP_TIME_INTERVAL peer_mean_path_delay;             ///< estimate of the current one-way propagation delay on the link, only valid if P2P is used, see ::PTP_TIME_INTERVAL
  int8_t log_announce_interval;                       ///< announce interval to be used by this port
  uint8_t announce_receipt_timeout;                   ///< shall be an integral multiple of ::announce_interval
  int8_t log_sync_interval;                           ///< mean sync interval to be used for multicast messages
  uint8_t delay_mechanism;                            ///< propagation delay measuring option, see ::PTP_DELAY_MECHS
  int8_t log_min_pdelay_req_interval;                 ///< minimum peer delay request interval for this port
  uint8_t version_number : 4;                         ///< PTP version in use on the port
  uint8_t reserved : 4;                               ///< reserved, currently always 0

} MBG_PTP_V2_PORT_DATASET;


#define _mbg_swab_ptp_v2_port_dataset( _p )                        \
{                                                                  \
  _mbg_swab_ptp_port_identity( &(_p)->port_identity );             \
  _mbg_swab8( &(_p)->port_state );                                 \
  _mbg_swab8( &(_p)->log_min_delay_req_interval );                 \
  _mbg_swab_ptp_time_interval( &(_p)->peer_mean_path_delay );      \
  _mbg_swab8( &(_p)->log_announce_interval );                      \
  _mbg_swab8( &(_p)->announce_receipt_timeout );                   \
  _mbg_swab8( &(_p)->log_sync_interval );                          \
  _mbg_swab8( &(_p)->delay_mechanism );                            \
  _mbg_swab8( &(_p)->log_min_pdelay_req_interval );                \
}


/**
 * @brief Index structure for PTPv2 port dataset
 *
 * @note Port dataset with index 0..::MBG_PTP_V2_DEFAULT_DATASET::number_ports - 1 can be queried from a device
 *
 * @see ::MBG_PTP_V2_PORT_DATASET
 */
typedef struct
{
  uint16_t idx;                                       ///< Index of the port dataset, 0..::MBG_PTP_V2_DEFAULT_DATASET::number_ports - 1
  MBG_PTP_V2_PORT_DATASET port_dataset;               ///< see ::MBG_PTP_V2_PORT_DATASET

} MBG_PTP_V2_PORT_DATASET_IDX;


#define _mbg_swab_ptp_v2_port_dataset_idx( _p )           \
{                                                         \
  _mbg_swab16( &(_p)->idx );                              \
  _mbg_swab_ptp_v2_port_dataset( &(_p)->port_dataset );   \
}


/** @} defgroup group_ptp */



/**
 * @defgroup group_ntp Definitions used with NTP
 *
 * @{ */


/**
 * @brief Enumeration of known NTP roles
 *
 * @see ::NTP_GLB_SETTINGS::ntp_role
 */
enum NTP_ROLES
{
  NTP_ROLE_NONE = 0,       ///< NTP services disabled
  NTP_ROLE_CLIENT,         ///< NTP client
  NTP_ROLE_SERVER,         ///< NTP server
  NTP_ROLE_CLIENT_SERVER,  ///< both NTP client and server
  N_NTP_ROLES              ///< number of supported roles
};


/**
 * @brief Flag masks associated with NTP roles
 *
 * @see ::NTP_GLB_INFO::supp_ntp_roles
 */
enum NTP_ROLE_MASKS
{
  NTP_MSK_ROLE_NONE          = ( 1UL << NTP_ROLE_NONE ),           ///< see ::NTP_ROLE_NONE
  NTP_MSK_ROLE_CLIENT        = ( 1UL << NTP_ROLE_CLIENT ),         ///< see ::NTP_ROLE_CLIENT
  NTP_MSK_ROLE_SERVER        = ( 1UL << NTP_ROLE_SERVER ),         ///< see ::NTP_ROLE_SERVER
  NTP_MSK_ROLE_CLIENT_SERVER = ( 1UL << NTP_ROLE_CLIENT_SERVER ),  ///< see ::NTP_ROLE_CLIENT_SERVER
};


/**
 * @brief Enumeration of global NTP flags
 *
 * @see @ref NTP_FLAG_MASKS
 */
enum NTP_FLAGS
{
  NTP_IPV4,             ///< NTP via IPv4/UDP
  NTP_IPV6,             ///< NTP via IPv6/UDP
  NTP_SYMM_KEYS,        ///< support symmetric key authentication (MD5)
  NTP_AUTOKEY,          ///< include authentication fields encrypted using the autokey scheme
  NTP_BURST,            ///< send a burst of eight packets at each polling cycle
  NTP_IBURST,           ///< send a burst of eight packets at the first polling cycle
  NTP_NO_SELECT,        ///< marks a server as not to be selected for time synchronization
  NTP_PREEMPT,          ///< specifies the association as preemptable rather than the default persistent
  NTP_PREFER,           ///< marks a server as preferred peer for time synchronization
  NTP_TRUE,             ///< force the association to assume truechimer status; always survive the selection and clustering algorithms
  NTP_BROADCAST,        ///< transmission via broadcast, point to multipoint
  NTP_MULTICAST,        ///< transmission via multicast, point to multipoint
  NTP_MANYCAST,         ///< transmission via manycast, point to multipoint
  NTP_POOL,             ///< peer shall be treated as a pool server
  NTP_PEER,             ///< specifies a symmetric-active association should be used with this server
  NTP_BROADCASTCLIENT,  ///< receive broadcast messages on all interfaces
  NTP_MULTICASTCLIENT,  ///< receive messages from the given multicast group
  NTP_MANYCASTCLIENT,   ///< manycast shall be used on the given multicast address to discover peers
  NTP_RESTRICTIONS,     ///< NTP supports restrictions
  NTP_DISCARD,          ///< NTP supports "discard" rate limiting
  NTP_REFCLOCKS,        ///< NTP supports refclocks
  NTP_STATISTICS,       ///< NTP supports statistics (e.g. clockstats, loopstats, etc...)
  NTP_MISCELLANEOUS,    ///< NTP supports misc options (e.g. tinker, driftfile, orphan mode, etc...)
  NTP_TRUSTED_KEYS,     ///< NTP supports specifying trusted symmetric keys
  NTP_FIXED_REFCLOCKS,  ///< NTP refclocks not configurable

  N_NTP_FLAGS
};



/**
 * @brief Flag masks associated with ::NTP_FLAGS
 *
 * Used with ::NTP_GLB_INFO::supp_flags, ::NTP_GLB_SETTINGS::flags, NTP_CLNT_MODE_INFO::supp_flags,
 * ::NTP_CLNT_MODE_INFO::supp_peer_flags, ::NTP_CLNT_MODE_SETTINGS::flags, ::NTP_PEER_SETTINGS::flags,
 * ::NTP_SRV_MODE_SETTINGS::flags, and ::NTP_SRV_MODE_INFO::supp_flags.
 *
 * @todo We may need structures to configure symmetric keys, and autokey certificates.
 *
 * @see ::NTP_FLAGS
 *
 * @anchor NTP_FLAG_MASKS @{ */

#define NTP_MSK_IPV4             ( 1UL << NTP_IPV4 )            ///< see ::NTP_IPV4
#define NTP_MSK_IPV6             ( 1UL << NTP_IPV6 )            ///< see ::NTP_IPV6
#define NTP_MSK_SYMM_KEYS        ( 1UL << NTP_SYMM_KEYS )       ///< see ::NTP_SYMM_KEYS; if set, ::NTP_SYMM_KEY_LIMITS can be queried
#define NTP_MSK_AUTOKEY          ( 1UL << NTP_AUTOKEY )         ///< see ::NTP_AUTOKEY
#define NTP_MSK_BURST            ( 1UL << NTP_BURST )           ///< see ::NTP_BURST
#define NTP_MSK_IBURST           ( 1UL << NTP_IBURST )          ///< see ::NTP_IBURST
#define NTP_MSK_NO_SELECT        ( 1UL << NTP_NO_SELECT )       ///< see ::NTP_NO_SELECT
#define NTP_MSK_PREEMPT          ( 1UL << NTP_PREEMPT )         ///< see ::NTP_PREEMPT
#define NTP_MSK_PREFER           ( 1UL << NTP_PREFER )          ///< see ::NTP_PREFER
#define NTP_MSK_TRUE             ( 1UL << NTP_TRUE )            ///< see ::NTP_TRUE
#define NTP_MSK_BROADCAST        ( 1UL << NTP_BROADCAST )       ///< see ::NTP_BROADCAST
#define NTP_MSK_MULTICAST        ( 1UL << NTP_MULTICAST )       ///< see ::NTP_MULTICAST
#define NTP_MSK_MANYCAST         ( 1UL << NTP_MANYCAST )        ///< see ::NTP_MANYCAST
#define NTP_MSK_POOL             ( 1UL << NTP_POOL )            ///< see ::NTP_POOL
#define NTP_MSK_PEER             ( 1UL << NTP_PEER )            ///< see ::NTP_PEER
#define NTP_MSK_BROADCASTCLIENT  ( 1UL << NTP_BROADCASTCLIENT)  ///< see ::NTP_BROADCASTCLIENT
#define NTP_MSK_MULTICASTCLIENT  ( 1UL << NTP_MULTICASTCLIENT)  ///< see ::NTP_MULTICASTCLIENT
#define NTP_MSK_MANYCASTCLIENT   ( 1UL << NTP_MANYCASTCLIENT)   ///< see ::NTP_MANYCASTCLIENT
#define NTP_MSK_RESTRICTIONS     ( 1UL << NTP_RESTRICTIONS )    ///< see ::NTP_RESTRICTIONS
#define NTP_MSK_DISCARD          ( 1UL << NTP_DISCARD )         ///< see ::NTP_DISCARD
#define NTP_MSK_REFCLOCKS        ( 1UL << NTP_REFCLOCKS )       ///< see ::NTP_REFCLOCKS
#define NTP_MSK_STATISTICS       ( 1UL << NTP_STATISTICS )      ///< see ::NTP_STATISTICS; if set, ::NTP_STATS_GLB_INFO can be queried
#define NTP_MSK_MISCELLANEOUS    ( 1UL << NTP_MISCELLANEOUS )   ///< see ::NTP_MISCELLANEOUS
#define NTP_MSK_TRUSTED_KEYS     ( 1UL << NTP_TRUSTED_KEYS )    ///< see ::NTP_TRUSTED_KEYS
#define NTP_MSK_FIXED_REFCLOCKS  ( 1UL << NTP_FIXED_REFCLOCKS ) ///< see ::NTP_FIXED_REFCLOCKS


/** @} anchor NTP_FLAG_MASKS */



/**
 * @brief Global configuration settings of an NTP device (client/server)
 *
 * This structure should be sent to an NTP device to configure global settings
 */
typedef struct
{
  uint8_t ntp_role;           ///< one of the supported NTP roles, see ::NTP_ROLES
  uint8_t num_symm_keys;      ///< number of configured symm keys
  uint8_t num_trusted_keys;   ///< number of activated symm keys
  uint8_t reserved_1;         ///< reserved, currently 0

  uint32_t reserved_2;        ///< reserved, currently 0
  uint32_t reserved_3;        ///< reserved, currently 0

  uint32_t flags;             ///< NTP flags, see @ref NTP_FLAG_MASKS

} NTP_GLB_SETTINGS;

#define _mbg_swab_ntp_glb_settings( _p ) \
do                                       \
{                                        \
  _mbg_swab32( &(_p)->flags );           \
} while ( 0 )


/**
 * @brief Global configuration info of an NTP device (client/server)
 *
 * This structure can be used to determine possible configurations of an NTP device
 */
typedef struct
{
  NTP_GLB_SETTINGS settings;   ///< current configuration settings

  uint8_t max_symm_keys;       ///< number of available symm keys that can be generated, see ::NTP_SYMM_KEY_INFO_IDX
  uint8_t max_trusted_keys;    ///< number of available trusted keys, see ::NTP_TRUSTED_KEY_INFO_IDX

  uint16_t reserved_2;         ///< reserved, currently 0
  uint32_t reserved_3;         ///< reserved, currently 0

  uint32_t supp_ntp_roles;     ///< supported NTP roles, see ::NTP_ROLE_MASKS
  uint32_t supp_flags;         ///< supported NTP flags, see @ref NTP_FLAG_MASKS

} NTP_GLB_INFO;

#define _mbg_swab_ntp_glb_info( _p )             \
do                                               \
{                                                \
  _mbg_swab_ntp_glb_settings( &(_p)->settings ); \
  _mbg_swab32( &(_p)->supp_ntp_roles );          \
  _mbg_swab32( &(_p)->supp_flags );              \
} while ( 0 )


#if defined( _PRELIMINARY_CODE )

/**
 * @brief Enumeration of supported NTP restriction types/keywords
 *
 * Used with ::NTP_RESTR::type
 *
 * @see https://www.eecis.udel.edu/~mills/ntp/html/accopt.html#restrict
 * @see ::NTP_RESTR_TYPE_MSKS
 */
enum NTP_RESTR_TYPES
{
  NTP_RESTR_TYPE_DEFAULT,
  NTP_RESTR_TYPE_SOURCE,
  NTP_RESTR_TYPE_ADDRESS,
  N_NTP_RESTR_TYPES
};



/**
 * @brief Bit masks associated with ::NTP_RESTR_TYPES
 *
 * Used with ::NTP_RESTR_LIMITS::supp_types
 *
 * @see ::NTP_RESTR_TYPES
 */
enum NTP_RESTR_TYPE_MSKS
{
  NTP_RESTR_TYPE_MSK_DEFAULT = ( 1UL << NTP_RESTR_TYPE_DEFAULT ), ///< see ::NTP_RESTR_TYPE_DEFAULT
  NTP_RESTR_TYPE_MSK_SOURCE  = ( 1UL << NTP_RESTR_TYPE_SOURCE ),  ///< see ::NTP_RESTR_TYPE_SOURCE
  NTP_RESTR_TYPE_MSK_ADDRESS = ( 1UL << NTP_RESTR_TYPE_ADDRESS )  ///< see ::NTP_RESTR_TYPE_ADDRESS
};



/**
 * @brief Enumeration of supported NTP restriction flags
 *
 * Used to define ::NTP_RESTR_FLAG_MSKS
 *
 * @see https://www.eecis.udel.edu/~mills/ntp/html/accopt.html#restrict
 * @see ::NTP_RESTR_FLAG_MSKS
 */
enum NTP_RESTR_FLAGS
{
  NTP_RESTR_FLAG_FLAKE,
  NTP_RESTR_FLAG_IGNORE,
  NTP_RESTR_FLAG_KOD,
  NTP_RESTR_FLAG_LIMITED,
  NTP_RESTR_FLAG_LOWPRIOTRAP,
  NTP_RESTR_FLAG_MSSNTP,
  NTP_RESTR_FLAG_NOMODIFY,
  NTP_RESTR_FLAG_NOQUERY,
  NTP_RESTR_FLAG_NOPEER,
  NTP_RESTR_FLAG_NOSERVE,
  NTP_RESTR_FLAG_NOTRAP,
  NTP_RESTR_FLAG_NOTRUST,
  NTP_RESTR_FLAG_NTPPORT,
  NTP_RESTR_FLAG_VERSION,
  NTP_RESTR_FLAG_IPV4,        ///< This default restriction only applies to IPv4
  NTP_RESTR_FLAG_IPV6,        ///< This default restriction only applies to IPv6
  N_NTP_RESTR_FLAGS
};



/**
 * @brief Flag masks associated with ::NTP_RESTR_FLAGS
 *
 * Used with ::NTP_RESTR::flags and ::NTP_RESTR_LIMITS::supp_flags
 *
 * @see ::NTP_RESTR_FLAGS
 */
enum NTP_RESTR_FLAG_MSKS
{
  NTP_RESTR_FLAG_MSK_FLAKE       = ( 1UL << NTP_RESTR_FLAG_FLAKE ),      ///< see ::NTP_RESTR_FLAG_FLAKE
  NTP_RESTR_FLAG_MSK_IGNORE      = ( 1UL << NTP_RESTR_FLAG_IGNORE ),     ///< see ::NTP_RESTR_FLAG_IGNORE
  NTP_RESTR_FLAG_MSK_KOD         = ( 1UL << NTP_RESTR_FLAG_KOD ),        ///< see ::NTP_RESTR_FLAG_KOD
  NTP_RESTR_FLAG_MSK_LIMITED     = ( 1UL << NTP_RESTR_FLAG_LIMITED ),    ///< see ::NTP_RESTR_FLAG_LIMITED
  NTP_RESTR_FLAG_MSK_LOWPRIOTRAP = ( 1UL << NTP_RESTR_FLAG_LOWPRIOTRAP ),///< see ::NTP_RESTR_FLAG_LOWPRIOTRAP
  NTP_RESTR_FLAG_MSK_MSSNTP      = ( 1UL << NTP_RESTR_FLAG_MSSNTP ),     ///< see ::NTP_RESTR_FLAG_MSSNTP
  NTP_RESTR_FLAG_MSK_NOMODIFY    = ( 1UL << NTP_RESTR_FLAG_NOMODIFY ),   ///< see ::NTP_RESTR_FLAG_NOMODIFY
  NTP_RESTR_FLAG_MSK_NOQUERY     = ( 1UL << NTP_RESTR_FLAG_NOQUERY ),    ///< see ::NTP_RESTR_FLAG_NOQUERY
  NTP_RESTR_FLAG_MSK_NOPEER      = ( 1UL << NTP_RESTR_FLAG_NOPEER ),     ///< see ::NTP_RESTR_FLAG_NOPEER
  NTP_RESTR_FLAG_MSK_NOSERVE     = ( 1UL << NTP_RESTR_FLAG_NOSERVE ),    ///< see ::NTP_RESTR_FLAG_NOSERVE
  NTP_RESTR_FLAG_MSK_NOTRAP      = ( 1UL << NTP_RESTR_FLAG_NOTRAP ),     ///< see ::NTP_RESTR_FLAG_NOTRAP
  NTP_RESTR_FLAG_MSK_NOTRUST     = ( 1UL << NTP_RESTR_FLAG_NOTRUST ),    ///< see ::NTP_RESTR_FLAG_NOTRUST
  NTP_RESTR_FLAG_MSK_NTPPORT     = ( 1UL << NTP_RESTR_FLAG_NTPPORT ),    ///< see ::NTP_RESTR_FLAG_NTPPORT
  NTP_RESTR_FLAG_MSK_VERSION     = ( 1UL << NTP_RESTR_FLAG_VERSION ),    ///< see ::NTP_RESTR_FLAG_VERSION
  NTP_RESTR_FLAG_MSK_IPV4        = ( 1UL << NTP_RESTR_FLAG_IPV4 ),       ///< see ::NTP_RESTR_FLAG_IPV4
  NTP_RESTR_FLAG_MSK_IPV6        = ( 1UL << NTP_RESTR_FLAG_IPV6 )        ///< see ::NTP_RESTR_FLAG_IPV6
};



/**
 * @brief General NTP restriction limits to be read from a device
 *
 * Used to query from a device how many NTP restrictions are supported
 * by the device, then index 0..::NTP_RESTR_LIMITS::cur_restrs-1
 * restriction records can be read from a device. A maximum of
 * ::NTP_RESTR_LIMITS::max_restrs can be configured at all.
 */
typedef struct
{
  uint16_t max_restrs;  ///< Number of maximum supported restrictions
  uint16_t cur_restrs;  ///< Number of currently configured restrictions
  uint32_t supp_types;  ///< Supported restriction types, see ::NTP_RESTR_TYPE_MSKS
  uint32_t supp_flags;  ///< Supported restriction flags, see ::NTP_RESTR_FLAG_MSKS
  uint32_t reserved;    ///< Future use

} NTP_RESTR_LIMITS;

#define _mbg_swab_ntp_restr_limits( _p ) \
do                                       \
{                                        \
  _mbg_swab16( &(_p)->max_restrs );      \
  _mbg_swab16( &(_p)->cur_restrs );      \
  _mbg_swab32( &(_p)->supp_types );      \
  _mbg_swab32( &(_p)->supp_flags );      \
  _mbg_swab32( &(_p)->reserved );        \
} while ( 0 )

/**
 * @brief NTP restriction
 *
 * Structure contains all flags and information needed for a valid NTP restriction
 * as described at ntp.org's manual page.
 */
typedef struct
{
  uint8_t  type;        ///< Restriction type, see ::NTP_RESTR_TYPES
  uint8_t  reserved_1;  ///< Future use
  uint16_t reserved_2;  ///< Future use
  uint32_t flags;       ///< Restriction flags, see ::NTP_RESTR_FLAG_MSKS

  MBG_HOSTNAME addr;    ///< used if ::NTP_RESTR::type == ::NTP_RESTR_TYPE_ADDRESS
                        ///< can contain a hostname, or an IPv4 or IPv6 address
                        ///< with or without CIDR extension (eg. 172.16.0.0/16).
} NTP_RESTR;

#define _mbg_swab_ntp_restr( _p )                  \
do                                                 \
{                                                  \
  _mbg_swab16( &(_p)->reserved_2 );                \
  _mbg_swab32( &(_p)->flags );                     \
  _mbg_swab_ntp_restr_discard( &(_p)->u.discard ); \
} while ( 0 )



/**
 * @brief NTP restriction, plus index
 *
 * @see ::NTP_RESTR
 */
typedef struct
{
  uint16_t  idx;
  NTP_RESTR restr;

} NTP_RESTR_IDX;

#define _mbg_swab_ntp_restr_idx( _p )  \
do                                     \
{                                      \
  _mbg_swab16( &(_p)->idx );           \
  _mbg_swab_ntp_restr( &(_p)->restr ); \
} while ( 0 )



/**
 * @brief General NTP "discard" rate limiting limits to be read from a device
 *
 * Used to query from a device what range of values is supported
 * for the NTP "discard" rate limiting configuration.
 */
typedef struct
{
  uint8_t avg_min;      ///< Minimum value for avg
  uint8_t avg_max;      ///< Maximum value for avg
  uint8_t min_min;      ///< Minimum value for min
  uint8_t min_max;      ///< Maximum value for min
  uint16_t monitor_min; ///< Maximum value for min
  uint16_t monitor_max; ///< Maximum value for min

  uint32_t reserved;    ///< Future use

} NTP_DISCARD_LIMITS;

#define _mbg_swab_ntp_discard_limits( _p ) \
do                                         \
{                                          \
  _mbg_swab16( &(_p)->monitor_min );       \
  _mbg_swab16( &(_p)->monitor_max );       \
  _mbg_swab32( &(_p)->reserved );          \
} while ( 0 )



/**
 * @brief NTP "discard" rate limiting settings as described at ntp.org's manual
 */
typedef struct
{
  uint8_t avg;        ///< Specify the minimum average interpacket spacing in log2 s.
  uint8_t min;        ///< Specify the minimum interpacket spacing (guard time) in seconds.
  uint16_t monitor;   ///< ### TODO Which is the unit of this field?
  uint32_t reserved;  ///< Possible future use

} NTP_DISCARD_SETTINGS;

#define _mbg_swab_ntp_discard_settings( _p ) \
do                                           \
{                                            \
  _mbg_swab16( &(_p)->monitor );             \
  _mbg_swab32( &(_p)->reserved );            \
} while ( 0 )



/**
 * @brief Enumeration of supported refclock types
 *
 * Used with ::NTP_REFCLK_CFG_SETTINGS::type
 *
 * @see https://www.eecis.udel.edu/~mills/ntp/html/refclock.html
 * @see ::NTP_REFCLK_TYPE_MSKS
 */
enum NTP_REFCLK_TYPES
{
  NTP_REFCLK_TYPE_LOCAL,     ///< NTP local clock
  NTP_REFCLK_TYPE_TRUETIME,  ///< NTP Truetime driver
  NTP_REFCLK_TYPE_PARSE,     ///< NTP parse driver
  NTP_REFCLK_TYPE_NMEA,      ///< NTP NMEA driver
  NTP_REFCLK_TYPE_PPS,       ///< NTP atom driver (standalone PPS)
  NTP_REFCLK_TYPE_SHM,       ///< NTP shared memory driver
  N_NTP_REFCLK_TYPES
};



/**
 * @brief Bit masks associated with ::NTP_REFCLK_TYPES
 *
 * Used with ::NTP_REFCLK_CFG_INFO::supp_refclk_types
 *
 * @see ::NTP_REFCLK_TYPES
 */
enum NTP_REFCLK_TYPE_MSKS
{
  NTP_REFCLK_TYPE_MSK_LOCAL     = ( 1UL << NTP_REFCLK_TYPE_LOCAL ),     ///< see ::NTP_REFCLK_TYPE_LOCAL
  NTP_REFCLK_TYPE_MSK_TRUETIME  = ( 1UL << NTP_REFCLK_TYPE_TRUETIME ),  ///< see ::NTP_REFCLK_TYPE_TRUETIME
  NTP_REFCLK_TYPE_MSK_PARSE     = ( 1UL << NTP_REFCLK_TYPE_PARSE ),     ///< see ::NTP_REFCLK_TYPE_PARSE
  NTP_REFCLK_TYPE_MSK_NMEA      = ( 1UL << NTP_REFCLK_TYPE_NMEA ),      ///< see ::NTP_REFCLK_TYPE_NMEA
  NTP_REFCLK_TYPE_MSK_PPS       = ( 1UL << NTP_REFCLK_TYPE_PPS ),       ///< see ::NTP_REFCLK_TYPE_PPS
  NTP_REFCLK_TYPE_MSK_SHM       = ( 1UL << NTP_REFCLK_TYPE_SHM )        ///< see ::NTP_REFCLK_TYPE_SHM
};





/**
 * @brief Numbers related to the "fudge" flags used with ntpd's refclock interface
 *
 * Used with ::NTP_REFCLK_CFG_SETTINGS::drv_flags_enable
 * and ::NTP_REFCLK_CFG_SETTINGS::drv_flags_value
 *
 * The refclock interface provided by ntpd supports a number of flags
 * (flag1..flag4) which can be "fudged" in ntp.conf to control specific
 * features of a particular refclock driver, e.g.:
 * "fudge 127.127.8.0 flag1 1"
 *
 * Which feature is controlled by which flag depends on the refclock
 * driver type, so usually each flag has a different meaning for
 * different refclock types.
 *
 * There are different cases to be distinguished:
 *
 * - if a flag is not specified at all in ntp.conf then
 *   the controlled feature is enabled or disabled
 *   according to the driver's default settings
 *
 * - if a flag is specified as '0' or '1' in ntp.conf then
 *   the controlled feature is enabled or disabled
 *   according to the flag's setting.
 *
 * Thus, the bit mask in ::NTP_REFCLK_CFG_SETTINGS::drv_flags_enable
 * controls if the associated fudge flag should be specified in ntp.conf,
 * and if it is specified then the associated bit in
 * ::NTP_REFCLK_CFG_SETTINGS::drv_flags_value controls if the fudge flag
 * is set to 0 or 1.
 *
 * @anchor NTP_FUDGE_FLAG_NUMBERS @{ */

#define NTP_MIN_REFCLOCK_FUDGE_FLAG   1  ///< minimum refclock fudge flag number, associated with bit 0
#define N_NTP_REFCLOCK_FUDGE_FLAGS    4  ///< the number of supported fudge flags

/** @} anchor NTP_FUDGE_FLAG_NUMBERS */



/**
 * @brief NTP refclock specific settings
 *
 * Used to configure a NTP refclock.
 */
typedef struct
{
  uint8_t  type;                ///< See ::NTP_REFCLK_TYPES
  uint8_t  instance;            ///< Refclock instance of the specified type. Usually up to 4 instances of the same type are supported by ntpd.
  uint8_t  mode;                ///< Driver specific "mode" //### TODO Flag to enable "mode"?
  int8_t   stratum;             ///< Stratum number to be fudged; -1 if unspecified and thus default is to be used

  int8_t   refid[4];            ///< Reference id used by driver  //### TODO Flag to enable "refid"?

  uint8_t  minpoll;             ///< Minimum polling interval, [log2 seconds], 0 if unused/unspecified
  uint8_t  maxpoll;             ///< Maximum polling interval, [log2 seconds], 0 if unused/unspecified
  uint8_t  reserved_1;          ///< Reserved for future use
  uint8_t  reserved_2;          ///< Future use

  NANO_TIME_64 time1;           ///< Driver specific
  NANO_TIME_64 time2;           ///< Driver specific

  uint16_t drv_flags_enable;   ///< Enable/disable driver specific flags, see @ref NTP_FUDGE_FLAG_NUMBERS
  uint16_t drv_flags_value;    ///< 0 or 1, if (drv_flags_enable & x) == 1, see @ref NTP_FUDGE_FLAG_NUMBERS

  uint32_t flags;               ///< See @ref NTP_FLAG_MASKS. Only flags specified in ::TODO can be used here.

  uint32_t reserved_3;          ///< Future use

} NTP_REFCLK_CFG_SETTINGS;

#define _mbg_swab_ntp_refclk_cfg_settings( _p ) \
do                                              \
{                                               \
  _mbg_swab_nano_time_64( &(_p)->time1 );       \
  _mbg_swab_nano_time_64( &(_p)->time2 );       \
  _mbg_swab16( &(_p)->drv_flags_enable );       \
  _mbg_swab16( &(_p)->drv_flags_value );        \
  _mbg_swab32( &(_p)->flags );                  \
} while ( 0 )



/**
 * @brief NTP refclock settings index
 *
 * @see ::NTP_REFCLK_CFG_SETTINGS
 */
typedef struct
{
  uint16_t idx;
  NTP_REFCLK_CFG_SETTINGS settings;   ///< See ::NTP_REFCLK_CFG_SETTINGS

} NTP_REFCLK_CFG_SETTINGS_IDX;

#define _mbg_swab_ntp_refclk_cfg_settings_idx( _p )     \
do                                                      \
{                                                       \
  _mbg_swab16( &(_p)->idx );                            \
  _mbg_swab_ntp_refclk_cfg_settings( &(_p)->settings ); \
} while ( 0 )



/**
 * @brief NTP refclock configuration and supported refclock types
 *
 * This structure can be used to set a NTP refclock's configuration
 * and get to know its overall supported refclocks.
 */
typedef struct
{
  NTP_REFCLK_CFG_SETTINGS settings;  ///< See ::NTP_REFCLK_CFG_SETTINGS

  uint32_t supp_refclk_types;        ///< See ::NTP_REFCLK_TYPE_MSKS

} NTP_REFCLK_CFG_INFO;

#define _mbg_swab_ntp_refclk_cfg_info( _p )             \
do                                                      \
{                                                       \
  _mbg_swab_ntp_refclk_cfg_settings( &(_p)->settings ); \
  _mbg_swab32( &(_p)->supp_refclk_types );              \
} while ( 0 )



/**
 * @brief NTP refclock info, with index
 *
 * @see ::NTP_REFCLK_CFG_INFO
 */
typedef struct
{
  uint16_t idx;
  NTP_REFCLK_CFG_INFO info;

} NTP_REFCLK_CFG_INFO_IDX;

#define _mbg_swab_ntp_refclk_cfg_info_idx( _p )  \
do                                               \
{                                                \
  _mbg_swab16( &(_p)->idx );                     \
  _mbg_swab_ntp_refclk_cfg_info( &(_p)->info );  \
} while ( 0 )


/**
 * @brief Enumeration of NTP supported symmetric key hashing algorithms
 *
 * @see ::NTP_SYMM_KEY_HASH_MASKS
 *
 * @note Support of external libraries (e.g.: OpenSSL) may be needed for
 *       some hashing algorithms.
 */
enum NTP_SYMM_KEY_HASHES
{
  NTP_SYMM_KEY_HASH_MD5,      ///< NTP supports MD5 as key hashing algorithm
  NTP_SYMM_KEY_HASH_SHA1,     ///< NTP supports SHA1 as key hashing algorithm
  N_NTP_SYMM_KEY_HASHES
};



/**
 * @brief Flag masks associated with ::NTP_SYMM_KEY_HASHES
 *
 * @see ::NTP_SYMM_KEY_HASHES
 */
enum NTP_SYMM_KEY_HASH_MASKS
{
  NTP_SYMM_KEY_HASH_MSK_MD5  = ( 1UL << NTP_SYMM_KEY_HASH_MD5 ),  ///< see ::NTP_SYMM_KEY_HASH_MD5
  NTP_SYMM_KEY_HASH_MSK_SHA1 = ( 1UL << NTP_SYMM_KEY_HASH_SHA1 ), ///< see ::NTP_SYMM_KEY_HASH_SHA1
};


/**
 * @brief Name strings for defined NTP symm key hashes
 *
 * @see ::NTP_SYMM_KEY_HASHES
 */
#define NTP_SYMM_KEY_HASHES_STRS \
{                                \
  "MD5",                         \
  "SHA1"                         \
}



/**
 * @brief General NTP symmetric key limits to be read from a device
 *
 * ::NTP_SYMM_KEY_LIMITS::supp_hashes specifies supported hashing algorithms
 * to create keys with. See ::NTP_SYMM_KEY_HASH_MASKS. Structure can be queried
 * if ::NTP_MSK_SYMM_KEYS is set in ::NTP_GLB_INFO::supp_flags
 */
typedef struct
{
  uint16_t supp_hashes;     ///< See ::NTP_SYMM_KEY_HASH_MASKS
  uint16_t reserved_1;      ///< Future use
  uint32_t reserved_2;      ///< Future use
  uint32_t reserved_3;      ///< Future use
  uint32_t reserved_4;      ///< Future use

} NTP_SYMM_KEY_LIMITS;

#define _mbg_swab_ntp_symm_key_limits( _p ) \
do                                          \
{                                           \
  _mbg_swab16( &(_p)->supp_hashes );        \
} while ( 0 )



/// Maximum length of a symmetric key. 128 byte was chosen to be
/// prepared for hash algorithms like SHA256, SH384, up to SHA512.
#define N_NTP_SYMM_KEY_LEN 128


/**
 * @brief NTP symmetric key specific settings
 *
 * This structure is used to configure a symmetric key for NTP.
 */
typedef struct
{
  uint16_t id;                      ///< Configurable key id (1..65534)
  uint8_t  hash;                    ///< See ::NTP_SYMM_KEY_HASHES
  uint8_t  reserved_1;              ///< Future use
  uint32_t reserved_2;              ///< Future use
  uint8_t  key[N_NTP_SYMM_KEY_LEN]; ///< Hashed phrase, see ::N_NTP_SYMM_KEY_LEN

} NTP_SYMM_KEY_SETTINGS;

#define _mbg_swab_ntp_symm_key_settings( _p ) \
do                                            \
{                                             \
  _mbg_swab16( &(_p)->id );                   \
} while ( 0 )



/**
 * @brief NTP symmetric key settings, with index
 *
 * @see ::NTP_SYMM_KEY_SETTINGS
 */
typedef struct
{
  uint16_t idx;
  NTP_SYMM_KEY_SETTINGS settings;

} NTP_SYMM_KEY_SETTINGS_IDX;

#define _mbg_swab_ntp_symm_key_settings_idx( _p )     \
do                                                    \
{                                                     \
  _mbg_swab16( &(_p)->idx );                          \
  _mbg_swab_ntp_symm_key_settings( &(_p)->settings ); \
} while ( 0 )


/**
 * @brief NTP symmkey info
 *
 * This structure is used to query a symmetric key for NTP.
 */
typedef struct
{
  NTP_SYMM_KEY_SETTINGS settings;

  uint32_t reserved_1;              ///< Future use
  uint32_t reserved_2;              ///< Future use
  uint32_t reserved_3;              ///< Future use
  uint32_t reserved_4;              ///< Future use

} NTP_SYMM_KEY_INFO;

#define _mbg_swab_ntp_symm_key_info( _p )             \
do                                                    \
{                                                     \
  _mbg_swab_ntp_symm_key_settings( &(_p)->settings ); \
} while ( 0 )


/**
 * @brief NTP symm key info, with index
 *
 * @see ::NTP_SYMM_KEY_INFO
 */
typedef struct
{
  uint16_t idx;
  NTP_SYMM_KEY_INFO info;

} NTP_SYMM_KEY_INFO_IDX;

#define _mbg_swab_ntp_symm_key_info_idx( _p )     \
do                                                \
{                                                 \
  _mbg_swab16( &(_p)->idx );                      \
  _mbg_swab_ntp_symm_key_info( &(_p)->info );     \
} while ( 0 )


/**
 * @brief NTP trusted key settings
 *
 * This structure is used to configure a trusted symmetric key for NTP.
 */
typedef struct
{
  uint16_t id;                      ///< Configurable key id (1..65534)
  uint16_t reserved_1;              ///< Future use
  uint32_t reserved_2;              ///< Future use

} NTP_TRUSTED_KEY_SETTINGS;

#define _mbg_swab_ntp_trusted_key_settings( _p ) \
do                                               \
{                                                \
  _mbg_swab16( &(_p)->id );                      \
} while ( 0 )


/**
 * @brief NTP trusted key settings, with index
 *
 * @see ::NTP_TRUSTED_KEY_SETTINGS
 */
typedef struct
{
  uint16_t idx;
  NTP_TRUSTED_KEY_SETTINGS settings;

} NTP_TRUSTED_KEY_SETTINGS_IDX;

#define _mbg_swab_ntp_trusted_key_settings_idx( _p )      \
do                                                        \
{                                                         \
  _mbg_swab16( &(_p)->idx );                              \
  _mbg_swab_ntp_trusted_key_settings( &(_p)->settings );  \
} while ( 0 )

/**
 * @brief NTP trusted key info
 *
 * This structure is used to query a trusted symmetric key for NTP.
 */
typedef struct
{
  NTP_TRUSTED_KEY_SETTINGS settings;

  uint32_t reserved_1;              ///< Future use
  uint32_t reserved_2;              ///< Future use
  uint32_t reserved_3;              ///< Future use
  uint32_t reserved_4;              ///< Future use

} NTP_TRUSTED_KEY_INFO;

#define _mbg_swab_ntp_trusted_key_info( _p )             \
do                                                       \
{                                                        \
  _mbg_swab_ntp_trusted_key_settings( &(_p)->settings ); \
} while ( 0 )


/**
 * @brief NTP trusted key info, with index
 *
 * @see ::NTP_TRUSTED_KEY_INFO
 */
typedef struct
{
  uint16_t idx;
  NTP_TRUSTED_KEY_INFO info;

} NTP_TRUSTED_KEY_INFO_IDX;

#define _mbg_swab_ntp_trusted_key_info_idx( _p )  \
do                                                \
{                                                 \
  _mbg_swab16( &(_p)->idx );                      \
  _mbg_swab_ntp_trusted_key_info( &(_p)->info );  \
} while ( 0 )


/**
 * @brief Enumeration of NTP supported statistics
 *
 * @see ::NTP_GLB_STATS_MASKS
 */
enum NTP_GLB_STATS_FLAGS
{
  NTP_GLB_STATS_FLAG_ENABLE,        ///< NTP stats can generally be enabled or disabled
  NTP_GLB_STATS_FLAG_CLOCKSTATS,    ///< NTP supports clockstats
  NTP_GLB_STATS_FLAG_CRYPTOSTATS,   ///< NTP supports cryptostats
  NTP_GLB_STATS_FLAG_LOOPSTATS,     ///< NTP supports loopstats
  NTP_GLB_STATS_FLAG_PEERSTATS,     ///< NTP supports peerstats
  NTP_GLB_STATS_FLAG_RAWSTATS,      ///< NTP supports rawstats
  NTP_GLB_STATS_FLAG_SYSSTATS,      ///< NTP supports sysstats
  NTP_GLB_STATS_FLAG_FILEGEN,       ///< NTP supports sets of files
                                    ///< If flag is set there are structures needed
                                    ///< that are not avail right now. Future use
  N_NTP_GLB_STATS_FLAGS
};



/**
 * @brief Flag masks associated with ::NTP_GLB_STATS_FLAGS
 *
 * @see ::NTP_GLB_STATS_FLAGS
 */
enum NTP_GLB_STATS_MASKS
{
  NTP_GLB_STATS_MSK_ENABLE      = ( 1UL << NTP_GLB_STATS_FLAG_ENABLE ),       ///< See ::NTP_GLB_STATS_FLAG_ENABLE
  NTP_GLB_STATS_MSK_CLOCKSTATS  = ( 1UL << NTP_GLB_STATS_FLAG_CLOCKSTATS ),   ///< See ::NTP_GLB_STATS_FLAG_CLOCKSTATS
  NTP_GLB_STATS_MSK_CRYPTOSTATS = ( 1UL << NTP_GLB_STATS_FLAG_CRYPTOSTATS ),  ///< See ::NTP_GLB_STATS_FLAG_CRYPTOSTATS
  NTP_GLB_STATS_MSK_LOOPSTATS   = ( 1UL << NTP_GLB_STATS_FLAG_LOOPSTATS ),    ///< See ::NTP_GLB_STATS_FLAG_LOOPSTATS
  NTP_GLB_STATS_MSK_PEERSTATS   = ( 1UL << NTP_GLB_STATS_FLAG_PEERSTATS ),    ///< See ::NTP_GLB_STATS_FLAG_PEERSTATS
  NTP_GLB_STATS_MSK_RAWSTATS    = ( 1UL << NTP_GLB_STATS_FLAG_RAWSTATS ),     ///< See ::NTP_GLB_STATS_FLAG_RAWSTATS
  NTP_GLB_STATS_MSK_SYSSTATS    = ( 1UL << NTP_GLB_STATS_FLAG_SYSSTATS ),     ///< See ::NTP_GLB_STATS_FLAG_SYSSTATS
  NTP_GLB_STATS_MSK_FILEGEN     = ( 1UL << NTP_GLB_STATS_FLAG_FILEGEN )       ///< See ::NTP_GLB_STATS_FLAG_FILEGEN
};



/**
 * @brief Global NTP statistics settings to be read from / written to a device
 *
 * ::NTP_GLB_STATS_MSK_ENABLE is the switch to enable / disable statistics in
 * general. In case the bit is set all other bits stand for special statistic
 * types that can be enabled or disabled by setting or deleting its specific bit.
 */
typedef struct
{
  uint32_t flags;           ///< See ::NTP_GLB_STATS_MASKS
  uint32_t reserved_1;      ///< Future use
  uint32_t reserved_2;      ///< Future use

} NTP_STATS_GLB_SETTINGS;

#define _mbg_swab_ntp_stats_glb_settings( _p ) \
do                                             \
{                                              \
  _mbg_swab32( &(_p)->flags );                 \
  _mbg_swab32( &(_p)->reserved_1 );            \
  _mbg_swab32( &(_p)->reserved_2 );            \
} while ( 0 )



/**
 * @brief NTP statistics settings
 *
 * This structure can be used to determine possible NTP statistic options
 * and can be queried if ::NTP_MSK_STATISTICS bit is set in ::NTP_GLB_INFO::supp_flags.
 */
typedef struct
{
  NTP_STATS_GLB_SETTINGS settings;  ///< See ::NTP_STATS_GLB_SETTINGS

  uint32_t supp_stats;              ///< See ::NTP_GLB_STATS_MASKS
  uint32_t reserved_1;              ///< Future use
  uint32_t reserved_2;              ///< Future use
  uint32_t reserved_3;              ///< Future use

} NTP_STATS_GLB_INFO;

#define _mbg_swab_ntp_stats_glb_info( _p )              \
do                                                      \
{                                                       \
  _mbg_swab_ntp_stats_glb_settings( &(_p)->settings );  \
  _mbg_swab32( &(_p)->supp_stats );                     \
  _mbg_swab32( &(_p)->reserved_1 );                     \
  _mbg_swab32( &(_p)->reserved_2 );                     \
  _mbg_swab32( &(_p)->reserved_3 );                     \
} while ( 0 )



/**
 * @brief Enumeration of NTP supported (various) misc options
 *
 * @see ::NTP_MISC_MSKS
 */
enum NTP_MISC_FLAGS
{
  NTP_MISC_FLAG_DRIFTFILE,    ///< NTP supports driftfile
  NTP_MISC_FLAG_ORPHAN_MODE,  ///< NTP supports orphan mode
  NTP_MISC_FLAG_LEAPFILE,     ///< NTP supports leapfile
  N_NTP_MISC_FLAGS
};



/**
 * @brief Flag masks associated with ::NTP_MISC_FLAGS
 *
 * @see ::NTP_MISC_FLAGS
 */
enum NTP_MISC_MSKS
{
  NTP_MISC_MSK_DRIFTFILE      = ( 1UL << NTP_MISC_FLAG_DRIFTFILE ),     ///< See ::NTP_MISC_FLAG_DRIFTFILE
  NTP_MISC_MSK_ORPHAN_MODE    = ( 1UL << NTP_MISC_FLAG_ORPHAN_MODE ),   ///< See ::NTP_MISC_FLAG_ORPHAN_MODE
  NTP_MISC_MSK_LEAPFILE       = ( 1UL << NTP_MISC_FLAG_LEAPFILE )       ///< See ::NTP_MISC_FLAG_LEAPFILE
};



/**
 * @brief General NTP misc limits to be read from a device
 *
 * This structure can be used to determine various NTP options
 * and can be queried if ::NTP_MSK_MISCELLANEOUS bit is set in ::NTP_GLB_INFO::supp_flags.
 */
typedef struct
{
  uint32_t supp_flags;     ///< See ::NTP_MISC_MSKS
  uint32_t reserved_1;     ///< Future use
  uint32_t reserved_2;     ///< Future use

} NTP_MISC_LIMITS;

#define _mbg_swab_ntp_misc_limits( _p ) \
do                                      \
{                                       \
  _mbg_swab32( &(_p)->supp_flags );     \
} while ( 0 )



/**
 * @brief NTP driftfile settings to be read from / written to a device
 *
 * If ::NTP_MISC_MSK_DRIFTFILE is set in ::NTP_MISC_LIMITS::supp_flags
 * ::NTP_MISC_DRIFTFILE_SETTINGS can be read / written.
 */
typedef struct
{
  uint8_t  enable;      ///< Enable / disable writing a driftfile
  uint8_t  reserved_1;  ///< Future use
  uint16_t reserved_2;  ///< Future use

} NTP_MISC_DRIFTFILE_SETTINGS;

#define _mbg_swab_ntp_misc_driftfile_settings( _p ) \
do                                                  \
{                                                   \
} while ( 0 )


/**
 * @brief Enumeration of NTP supported (various) misc options
 *
 * @see ::NTP_ORPHAN_MODE_MSK
 */
enum NTP_ORPHAN_MODE_FLAGS
{
  NTP_ORPHAN_MODE_FLAG_SUPP_DISABLE,    ///< Orphan Mode support disabling

  N_NTP_ORPHAN_MODE_FLAGS
};



/**
 * @brief Flag masks associated with ::NTP_ORPHAN_MODE_FLAGS
 *
 * @see ::NTP_ORPHAN_MODE_FLAGS
 */
enum NTP_ORPHAN_MODE_MSK
{
  NTP_ORPHAN_MODE_MSK_SUPP_DISABLE = ( 1UL << NTP_ORPHAN_MODE_FLAG_SUPP_DISABLE )     ///< See ::NTP_ORPHAN_MODE_FLAG_SUPP_DISABLE
};


/**
 * @brief NTP orphan mode settings to be read from / written to a device
 *
 * If ::NTP_MISC_MSK_ORPHAN_MODE is set in ::NTP_MISC_LIMITS::supp_flags
 * ::NTP_MISC_ORPHAN_MODE_SETTINGS can be read / written.
 */
typedef struct
{
  uint8_t  enable;          ///< Generally enable / disable orphan mode
  uint8_t  mode;            ///< Stratum level when no ref source available
  uint16_t reserved_1;      ///< Future use

  uint32_t reserved_2;      ///< Future use

} NTP_MISC_ORPHAN_MODE_SETTINGS;

#define _mbg_swab_ntp_misc_orphan_mode_settings( _p ) \
do                                                    \
{                                                     \
} while ( 0 )


/**
 * @brief NTP orphan mode info
 *
 */
typedef struct
{
  NTP_MISC_ORPHAN_MODE_SETTINGS settings;  ///< See ::NTP_MISC_ORPHAN_MODE_SETTINGS

  uint32_t supp_flags;              ///< See ::NTP_ORPHAN_MODE_MSK
  uint32_t reserved_1;              ///< Future use
  uint32_t reserved_2;              ///< Future use
  uint32_t reserved_3;              ///< Future use

} NTP_MISC_ORPHAN_MODE_INFO;

#define _mbg_swab_ntp_misc_orphan_mode_info( _p )             \
do                                                            \
{                                                             \
  _mbg_swab_ntp_misc_orphan_mode_settings( &(_p)->settings ); \
  _mbg_swab32( &(_p)->supp_flags );                           \
} while ( 0 )


/**
 * @brief NTP leapfile settings to be read from / written to a device
 *
 * If ::NTP_MISC_MSK_LEAPFILE is set in ::NTP_MISC_LIMITS::supp_flags
 * ::NTP_MISC_LEAPFILE_SETTINGS can be read / written.
 */
typedef struct
{
  uint8_t  enable;      ///< Generally enable / disable leapfile
  uint8_t  reserved_1;  ///< Stratum level when no ref source available
  uint16_t reserved_2;  ///< Future use

} NTP_MISC_LEAPFILE_SETTINGS;

#define _mbg_swab_ntp_misc_leapfile_settings( _p ) \
do                                                 \
{                                                  \
  _mbg_swab16( &(_p)->reserved_2 );                \
} while ( 0 )


#else  // !defined( _PRELIMINARY_CODE ), dummy declarations

  typedef int NTP_RESTR_LIMITS;
  typedef int NTP_RESTR;
  typedef int NTP_RESTR_IDX;
  typedef int NTP_DISCARD_LIMITS;
  typedef int NTP_DISCARD_SETTINGS;
  typedef int NTP_REFCLK_CFG_SETTINGS;
  typedef int NTP_REFCLK_CFG_SETTINGS_IDX;
  typedef int NTP_REFCLK_CFG_INFO;
  typedef int NTP_REFCLK_CFG_INFO_IDX;
  typedef int NTP_SYMM_KEY_LIMITS;
  typedef int NTP_SYMM_KEY_SETTINGS;
  typedef int NTP_SYMM_KEY_SETTINGS_IDX;
  typedef int NTP_SYMM_KEY_INFO;
  typedef int NTP_SYMM_KEY_INFO_IDX;
  typedef int NTP_TRUSTED_KEY_SETTINGS;
  typedef int NTP_TRUSTED_KEY_SETTINGS_IDX;
  typedef int NTP_TRUSTED_KEY_INFO;
  typedef int NTP_TRUSTED_KEY_INFO_IDX;
  typedef int NTP_STATS_GLB_SETTINGS;
  typedef int NTP_STATS_GLB_INFO;
  typedef int NTP_MISC_LIMITS;
  typedef int NTP_MISC_DRIFTFILE_SETTINGS;
  typedef int NTP_MISC_ORPHAN_MODE_SETTINGS;
  typedef int NTP_MISC_ORPHAN_MODE_INFO;
  typedef int NTP_MISC_LEAPFILE_SETTINGS;

#endif  // defined( _PRELIMINARY_CODE )


/**
 * @brief Client settings of an NTP device
 *
 * This structure should be sent to an NTP client to configure client parameters
 */
typedef struct
{
  uint8_t num_peers;            ///< number available peers
  uint8_t reserved_1;           ///< reserved, currently 0
  uint16_t reserved_2;          ///< reserved, currently 0

  uint32_t reserved_3;          ///< reserved, currently 0

  uint32_t flags;               ///< NTP flags, see @ref NTP_FLAG_MASKS

} NTP_CLNT_MODE_SETTINGS;

#define _mbg_swab_ntp_clnt_mode_settings( _p ) \
do                                             \
{                                              \
  _mbg_swab32( &(_p)->reserved_1 );            \
  _mbg_swab32( &(_p)->reserved_2 );            \
  _mbg_swab32( &(_p)->flags );                 \
} while ( 0 )



/**
 * @brief Client settings info of an NTP device
 *
 * This structure can be used to determine possible NTP client settings and the current configuration
 */
typedef struct
{
  NTP_CLNT_MODE_SETTINGS settings;

  uint8_t  n_supp_peers;       ///< maximal number of configurable peers
  uint8_t  n_supp_pref_peers;  ///< maximal number of configurable preferred ref sources
  uint8_t  poll_intv_min;      ///< minimal supported NTP polling interval
  uint8_t  poll_intv_max;      ///< maximal supported NTP polling interval

  uint32_t reserved_1;         ///< reserved, currently 0
  uint32_t reserved_2;         ///< reserved, currently 0

  uint32_t supp_flags;         ///< supported NTP flags, see @ref NTP_FLAG_MASKS
  uint32_t supp_peer_flags;    ///< supported NTP flags for peers, see @ref NTP_FLAG_MASKS

} NTP_CLNT_MODE_INFO;

#define _mbg_swab_ntp_clnt_mode_info( _p )             \
do                                                     \
{                                                      \
  _mbg_swab_ntp_clnt_mode_settings( &(_p)->settings ); \
  _mbg_swab32( &(_p)->reserved_1 );                    \
  _mbg_swab32( &(_p)->reserved_2 );                    \
  _mbg_swab32( &(_p)->supp_flags );                    \
  _mbg_swab32( &(_p)->supp_peer_flags );               \
} while ( 0 )



/**
 * @brief General NTP peer settings limits to be read from a device
 *
 * Used to query from a device how many NTP associations are supported
 * by the device, then index 0..::NTP_PEER_LIMITS::n_cur_peers-1
 * peer records can be read from a device. A maximum of
 * ::NTP_PEER_LIMITS::n_supp_peers can be configured at all.
 */
typedef struct
{
  uint16_t n_supp_peers;               ///< maximum number of configurable peers
  uint16_t n_cur_peers;                ///< current number of configured peers

  uint8_t  poll_intv_min;              ///< minimum supported NTP polling interval
  uint8_t  poll_intv_max;              ///< maximum supported NTP polling interval
  uint8_t  reserved_1;                 ///< reserved, currently 0
  uint8_t  reserved_2;                 ///< reserved, currently 0

  uint32_t supp_assoc_types;           ///< supported types of NTP associations
  uint32_t reserved_3;                 ///< reserved, currently 0

  uint32_t supp_flags_server;          ///< supported flags for unicast associations
  uint32_t supp_flags_peer;            ///< supported flags for unicast symmetric-active assocations
  uint32_t supp_flags_pool;            ///< supported flags for unicast pool associations
  uint32_t supp_flags_broadcast;       ///< supported flags for broadcast associations
  uint32_t supp_flags_multicast;       ///< supported flags for multicast associations
  uint32_t supp_flags_manycast;        ///< supported flags for manycast associations
  uint32_t supp_flags_broadcastclient; ///< supported flags for broadcast client associations
  uint32_t supp_flags_multicastclient; ///< supported flags for multicast client associations
  uint32_t supp_flags_manycastclient;  ///< supported flags for manycast client associations
  uint32_t reserved_4;                 ///< reserved, currently 0
  uint32_t reserved_5;                 ///< reserved, currently 0
  uint32_t reserved_6;                 ///< reserved, currently 0

} NTP_PEER_LIMITS;

#define _mbg_swab_ntp_peer_limits( _p )             \
do                                                  \
{                                                   \
  _mbg_swab16( &(_p)->n_supp_peers );               \
  _mbg_swab16( &(_p)->n_cur_peers );                \
  _mbg_swab32( &(_p)->supp_assoc_types );           \
  _mbg_swab32( &(_p)->reserved_3 );                 \
  _mbg_swab32( &(_p)->supp_flags_server );          \
  _mbg_swab32( &(_p)->supp_flags_peer );            \
  _mbg_swab32( &(_p)->supp_flags_pool );            \
  _mbg_swab32( &(_p)->supp_flags_broadcast );       \
  _mbg_swab32( &(_p)->supp_flags_multicast );       \
  _mbg_swab32( &(_p)->supp_flags_manycast );        \
  _mbg_swab32( &(_p)->supp_flags_broadcastclient ); \
  _mbg_swab32( &(_p)->supp_flags_multicastclient ); \
  _mbg_swab32( &(_p)->supp_flags_manycastclient );  \
  _mbg_swab32( &(_p)->reserved_4 );                 \
  _mbg_swab32( &(_p)->reserved_5 );                 \
  _mbg_swab32( &(_p)->reserved_6 );                 \
} while ( 0 )



/**
 * @brief Peer settings for NTP devices to configure an upload NTP server
 *
 * This structure should be read from the NTP client device to retrieve the
 * current settings and capabilities. The number of supported peers is
 * ::NTP_CLNT_MODE_INFO::n_supp_peers.
 *
 * @note The ::NTP_PEER_SETTINGS_IDX structure should be send back
 * to the device to save the configuration.
 */
typedef struct
{
  MBG_HOSTNAME hostname;  ///< hostname or IP address of the peer, not used
                          ///< when the NTP_BROADCASTCLIENT flag is set

  uint8_t  min_poll;      ///< minimal configurable NTP polling interval
  uint8_t  max_poll;      ///< maximal configurable NTP polling interval
  uint8_t  ttl;           ///< time-to-live to use with broadcast/multicast/manycast
  uint8_t  reserved_1;    ///< reserved, currently 0

  uint32_t key;           ///< ID of the symmetric key used with this association,
                          ///< this must be in the range 1-65534, 0 = disabled
  uint32_t reserved_3;    ///< reserved, currently 0
  uint32_t reserved_4;    ///< reserved, currently 0

  uint32_t flags;         ///< additional options configured, see @ref NTP_FLAG_MASKS

} NTP_PEER_SETTINGS;

#define _mbg_swab_ntp_peer_settings( _p ) \
do                                        \
{                                         \
  _mbg_swab32( &(_p)->key );              \
  _mbg_swab32( &(_p)->reserved_3 );       \
  _mbg_swab32( &(_p)->reserved_4 );       \
  _mbg_swab32( &(_p)->flags );            \
} while ( 0 )



/**
 * @brief Peer settings for NTP devices
 *
 * @see ::NTP_PEER_SETTINGS
 */
typedef struct
{
  uint32_t idx;
  NTP_PEER_SETTINGS peer_settings;

} NTP_PEER_SETTINGS_IDX;

#define _mbg_swab_ntp_peer_settings_idx( _p )          \
do                                                     \
{                                                      \
  _mbg_swab32( &(_p)->idx );                           \
  _mbg_swab_ntp_peer_settings( &(_p)->peer_settings ); \
} while ( 0 )


/**
 * @brief Server settings of an NTP device
 *
 * This structure should be sent to an NTP server to configure server parameters
 */
typedef struct
{
  uint8_t num_refclks;         ///< number of available refclks @ref NTP_REFCLK_CFG_INFO
  uint8_t reserved_1;          ///< reserved, currently 0
  uint16_t reserved_2;         ///< reserved, currently 0

  uint32_t reserved_3;   ///< reserved, currently 0

  uint32_t flags;        ///< NTP flags, see @ref NTP_FLAG_MASKS

} NTP_SRV_MODE_SETTINGS;

#define _mbg_swab_ntp_srv_mode_settings( _p ) \
do                                            \
{                                             \
  _mbg_swab32( &(_p)->flags );                \
} while ( 0 )


/**
 * @brief Server settings info of an NTP device
 *
 * This structure should be used to query an NTP server configuration from a device
 */
typedef struct
{
  NTP_SRV_MODE_SETTINGS settings;

  uint8_t max_refclks;            ///< number of supported refclks @ref NTP_REFCLK_CFG_INFO
  uint8_t reserved_1;             ///< reserved, currently 0
  uint16_t reserved_2;            ///< reserved, currently 0

  uint32_t reserved_3;            ///< reserved, currently 0

  uint32_t supp_flags;            ///< supported NTP flags, see @ref NTP_FLAG_MASKS

} NTP_SRV_MODE_INFO;

#define _mbg_swab_ntp_srv_mode_info( _p )             \
do                                                    \
{                                                     \
  _mbg_swab_ntp_srv_mode_settings( &(_p)->settings ); \
  _mbg_swab32( &(_p)->supp_flags );                   \
} while ( 0 )


/**
 * @brief Structure that represents a timestamp in NTP Short Format
 *
 * Maximal value for seconds is 65535.
 * Resolution of fractions is 15 microseconds.
 */
typedef struct
{
  uint16_t seconds;
  uint16_t fractions;

} NTP_SHORT_TSTAMP;

#define _mbg_swab_ntp_short_tstamp( _p ) \
do                                       \
{                                        \
  _mbg_swab16( &(_p)->seconds );         \
  _mbg_swab16( &(_p)->fractions );       \
}



/**
 * @brief Structure that represents a timestamp in NTP Timestamp Format
 */
typedef struct
{
  uint32_t seconds;    ///< seconds since NTP epoch, see ::NTP_SEC_BIAS
  uint32_t fractions;  ///< binary fractional part of a second, 0xFFFFFFFF -> 0.9999999... s (resolution 2^-32s =~ 233 ps)

} NTP_TSTAMP;

#define _mbg_swab_ntp_tstamp( _p ) \
do                                 \
{                                  \
  _mbg_swab32( &(_p)->seconds );   \
  _mbg_swab32( &(_p)->fractions ); \
} while ( 0 )



/**
 * @brief Enumeration of known NTP implementations
 *
 * Used with ::NTP_SYS_STATE::impl_type
 */
enum NTP_IMPL
{
  NTP_IMPL_UNKNOWN = 0,   ///< Unknown NTP implementation
  NTP_IMPL_NTPD,          ///< Network Time Protocol daemon (ntpd)
  NTP_IMPL_NTPDATE,       ///< NTP client only (ntpdate)
  NTP_IMPL_SNTP,          ///< Simple Network Time Protocol (sntp)
  NTP_IMPL_W32TIME,       ///< Windows time service (w32time)
  NTP_IMPL_MBGNTP,        ///< Meinberg NTP implementation (mbgntp)
  N_NTP_IMPLS
};

/*
 * Default initializers for English leapsecond string names. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_IMPL_STR_ENG            "Implemetation Type:"

#define MBG_NTP_IMPL_STR_ENG_UNKNOWN    "Unknown NTP implementation"
#define MBG_NTP_IMPL_STR_ENG_NTPD       "Network Time Protocol daemon (ntpd)"
#define MBG_NTP_IMPL_STR_ENG_NTPDATE    "NTP client only (ntpdate)"
#define MBG_NTP_IMPL_STR_ENG_SNTP       "Simple Network Time Protocol (sntp)"
#define MBG_NTP_IMPL_STR_ENG_W32TIME    "Windows time service (w32time)"
#define MBG_NTP_IMPL_STR_ENG_MBGNTP     "Meinberg NTP implementation (mbgntp)"


#define MBG_NTP_IMPL_NAMES_ENG   \
{                                \
  MBG_NTP_IMPL_STR_ENG_UNKNOWN,  \
  MBG_NTP_IMPL_STR_ENG_NTPD,     \
  MBG_NTP_IMPL_STR_ENG_NTPDATE,  \
  MBG_NTP_IMPL_STR_ENG_SNTP,     \
  MBG_NTP_IMPL_STR_ENG_W32TIME,  \
  MBG_NTP_IMPL_STR_ENG_MBGNTP    \
}



/**
 * @brief Enumeration of CPU types using NTP
 *
 * Used with ::NTP_SYS_STATE::cpu_type
 */
enum NTP_CPU_TYPES
{
  NTP_CPU_TYPE_UNKNOWN = 0,
  NTP_CPU_TYPE_X86,
  NTP_CPU_TYPE_I386,
  NTP_CPU_TYPE_I486,
  NTP_CPU_TYPE_I586,
  NTP_CPU_TYPE_I686,
  NTP_CPU_TYPE_X64,
  NTP_CPU_TYPE_X86_64,
  NTP_CPU_TYPE_AMD64,
  NTP_CPU_TYPE_SUN4U,
  NTP_CPU_TYPE_ARM,
  N_NTP_CPU_TYPES
};



/**
 * @brief Name strings for known CPU types using NTP
 *
 * @see ::NTP_CPU_TYPES
 */
#define NTP_CPU_TYPES_STRS \
{                          \
  "Unknown",               \
  "x86",                   \
  "i386",                  \
  "i486",                  \
  "i586",                  \
  "i686",                  \
  "x64",                   \
  "x86_64",                \
  "amd64",                 \
  "sun4u",                 \
  "arm"                    \
}



/**
 * @brief Enumeration of operating systems using NTP
 *
 * Used with ::NTP_SYS_STATE::system
*/
enum NTP_SYSTEMS
{
  NTP_SYSTEM_UNKNOWN = 0,
  NTP_SYSTEM_NONE,
  NTP_SYSTEM_WINDOWS,
  NTP_SYSTEM_LINUX,
  NTP_SYSTEM_BSD,
  NTP_SYSTEM_SOLARIS,
  N_NTP_SYSTEMS
};



/**
 * @brief Name strings for operating systens using NTP
 *
 * @see ::NTP_SYSTEMS
 */
#define NTP_SYSTEMS_STRS \
{                        \
  "Unknown",             \
  "No OS",               \
  "Windows",             \
  "Linux",               \
  "BSD",                 \
  "Solaris"              \
}



/**
 * @brief Enumeration of NTP leap indication bits
 *
 * Used with ::NTP_SYS_STATE::leap_ind
 *
 */
enum NTP_LI_BITS
{
  NTP_LEAP_NONE = 0,        ///< normal synchronized state
  NTP_LEAP_ADD_SEC,         ///< insert second after 23:59:59 of the current day
  NTP_LEAP_DEL_SEC,         ///< delete second 23:59:59 of the current day
  NTP_LEAP_ALARM,           ///< never synchronized
  N_NTP_LI_BITS
};



/*
 * Default initializers for English leapsecond string names. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_LEAP_STR_ENG         "Leapsecond indication:"

#define MBG_NTP_LEAP_STR_ENG_NONE    "None"
#define MBG_NTP_LEAP_STR_ENG_ADD_SEC "Insert second"
#define MBG_NTP_LEAP_STR_ENG_DEL_SEC "Delete second"
#define MBG_NTP_LEAP_STR_ENG_ALARM   "Alarm"

#define MBG_NTP_LEAP_NAMES_ENG   \
{                                \
  MBG_NTP_LEAP_STR_ENG_NONE,     \
  MBG_NTP_LEAP_STR_ENG_ADD_SEC,  \
  MBG_NTP_LEAP_STR_ENG_DEL_SEC,  \
  MBG_NTP_LEAP_STR_ENG_ALARM     \
}



/**
 * @brief Enumeration of NTP synchronization source bits
 *
 * Used with ::NTP_SYS_STATE::sys_sync_src
 *
 */
enum NTP_SYNC_SRC_BITS
{
  NTP_SYNC_SRC_UNSPEC = 0,  ///< not yet synchronized
  NTP_SYNC_SRC_PPS,         ///< pulse-per-second signal (Cs, Ru, GPS, etc.)
  NTP_SYNC_SRC_LF_RADIO,    ///< VLF/LF radio (WWVB, DCF77, etc.)
  NTP_SYNC_SRC_HF_RADIO,    ///< MF/HF radio (WWV, etc.)
  NTP_SYNC_SRC_UHF_RADIO,   ///< VHF/UHF radio/satellite (GPS, Galileo, etc.)
  NTP_SYNC_SRC_LOCAL,       ///< local timecode (IRIG, LOCAL driver, etc.)
  NTP_SYNC_SRC_NTP,         ///< NTP
  NTP_SYNC_SRC_OTHER,       ///< other (IEEE 1588, openntp, crony, etc.)
  NTP_SYNC_SRC_WRISTWATCH,  ///< eyeball and wristwatch
  NTP_SYNC_SRC_TELEPHONE,   ///< telephone modem (ACTS, PTB, etc.)
  N_NTP_SYNC_SRC_BITS
};



/*
 * Default initializers for English sync source string names. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_SYNC_SRC_STR_ENG_LABEL       "Sync Source:"

#define MBG_NTP_SYNC_SRC_STR_ENG_UNSPEC      "Not yet synchronized"
#define MBG_NTP_SYNC_SRC_STR_ENG_PPS         "Pulse per second signal"
#define MBG_NTP_SYNC_SRC_STR_ENG_LF_RADIO    "VLF/LF radio"
#define MBG_NTP_SYNC_SRC_STR_ENG_HF_RADIO    "MF/HF radio"
#define MBG_NTP_SYNC_SRC_STR_ENG_UHF_RADIO   "VHF/UHF radio/satellite"
#define MBG_NTP_SYNC_SRC_STR_ENG_LOCAL       "local timecode"
#define MBG_NTP_SYNC_SRC_STR_ENG_NTP         "NTP"
#define MBG_NTP_SYNC_SRC_STR_ENG_OTHER       "other"
#define MBG_NTP_SYNC_SRC_STR_ENG_WRISTWATCH  "eyeball and wristwatch"
#define MBG_NTP_SYNC_SRC_STR_ENG_TELEPHONE   "telephone modem"

#define MBG_NTP_SYNC_SRC_NAMES_ENG     \
{                                      \
  MBG_NTP_SYNC_SRC_STR_ENG_UNSPEC,     \
  MBG_NTP_SYNC_SRC_STR_ENG_PPS,        \
  MBG_NTP_SYNC_SRC_STR_ENG_LF_RADIO,   \
  MBG_NTP_SYNC_SRC_STR_ENG_HF_RADIO,   \
  MBG_NTP_SYNC_SRC_STR_ENG_UHF_RADIO,  \
  MBG_NTP_SYNC_SRC_STR_ENG_LOCAL,      \
  MBG_NTP_SYNC_SRC_STR_ENG_NTP,        \
  MBG_NTP_SYNC_SRC_STR_ENG_OTHER,      \
  MBG_NTP_SYNC_SRC_STR_ENG_WRISTWATCH, \
  MBG_NTP_SYNC_SRC_STR_ENG_TELEPHONE   \
}



/**
 * @brief Enumeration of NTP system event message bits
 *
 * Used with ::NTP_SYS_STATE::sys_rec_evt
 *
 */
enum NTP_SYS_EVT_BITS
{
  NTP_SYS_EVT_UNSPEC = 0,      ///< unspecified NTP event
  NTP_SYS_EVT_FREQ_NOT_SET,    ///< frequency file not available
  NTP_SYS_EVT_FREQ_SET,        ///< frequency set from frequency file
  NTP_SYS_EVT_SPIKE_DETECT,    ///< spike detected
  NTP_SYS_EVT_FREQ_MODE,       ///< initial frequency training mode
  NTP_SYS_EVT_CLOCK_SYNC,      ///< clock synchronized
  NTP_SYS_EVT_RESTART,         ///< program restart
  NTP_SYS_EVT_PANIC_STOP,      ///< clock error more than 600 s
  NTP_SYS_EVT_NO_SYSTEM_PEER,  ///< no system peer
  NTP_SYS_EVT_LEAP_ARMED,      ///< leap second armed from file or autokey
  NTP_SYS_EVT_LEAP_DISARMED,   ///< leap second disarmed
  NTP_SYS_EVT_LEAP_EVENT,      ///< leap event
  NTP_SYS_EVT_CLOCK_STEP,      ///< clock stepped
  NTP_SYS_EVT_KERNEL,          ///< kernel information message
  NTP_SYS_EVT_TAI,             ///< leapsecond values update from file
  NTP_SYS_EVT_STALE_LS_VALUES, ///< new NIST leapseconds file needed
  N_NTP_SYS_EVT_BITS
};



/*
 * Default initializers for English sync source string names. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_SYS_EVT_STR_ENG_CNT_LABEL         "System Event Counter:"
#define MBG_NTP_SYS_EVT_STR_ENG_MSG_LABEL         "System Event Message:"

#define MBG_NTP_SYS_EVT_STR_ENG_UNSPEC            "Unspecified NTP event"
#define MBG_NTP_SYS_EVT_STR_ENG_FREQ_NOT_SET      "Frequency file not available"
#define MBG_NTP_SYS_EVT_STR_ENG_FREQ_SET          "Frequency set from frequency file"
#define MBG_NTP_SYS_EVT_STR_ENG_SPIKE_DETECT      "Spike detected"
#define MBG_NTP_SYS_EVT_STR_ENG_FREQ_MODE         "Initial frequency training mode"
#define MBG_NTP_SYS_EVT_STR_ENG_CLOCK_SYNC        "Clock synchronized"
#define MBG_NTP_SYS_EVT_STR_ENG_RESTART           "Program restart"
#define MBG_NTP_SYS_EVT_STR_ENG_PANIC_STOP        "Clock error more than 600 s"
#define MBG_NTP_SYS_EVT_STR_ENG_NO_SYSTEM_PEER    "No system peer"
#define MBG_NTP_SYS_EVT_STR_ENG_LEAP_ARMED        "Leap second armed from file or autokey"
#define MBG_NTP_SYS_EVT_STR_ENG_LEAP_DISARMED     "Leap second disarmed"
#define MBG_NTP_SYS_EVT_STR_ENG_LEAP_EVENT        "Leap event"
#define MBG_NTP_SYS_EVT_STR_ENG_CLOCK_STEP        "Clock stepped"
#define MBG_NTP_SYS_EVT_STR_ENG_KERNEL            "Kernel information message"
#define MBG_NTP_SYS_EVT_STR_ENG_TAI               "Leap second values update from file"
#define MBG_NTP_SYS_EVT_STR_ENG_STALE_LS_VALUES   "New NIST leapseconds file needed"


#define MBG_NTP_SYS_EVT_NAMES_ENG           \
{                                           \
  MBG_NTP_SYS_EVT_STR_ENG_UNSPEC,           \
  MBG_NTP_SYS_EVT_STR_ENG_FREQ_NOT_SET,     \
  MBG_NTP_SYS_EVT_STR_ENG_FREQ_SET,         \
  MBG_NTP_SYS_EVT_STR_ENG_SPIKE_DETECT,     \
  MBG_NTP_SYS_EVT_STR_ENG_FREQ_MODE,        \
  MBG_NTP_SYS_EVT_STR_ENG_CLOCK_SYNC,       \
  MBG_NTP_SYS_EVT_STR_ENG_RESTART,          \
  MBG_NTP_SYS_EVT_STR_ENG_PANIC_STOP,       \
  MBG_NTP_SYS_EVT_STR_ENG_NO_SYSTEM_PEER,   \
  MBG_NTP_SYS_EVT_STR_ENG_LEAP_ARMED,       \
  MBG_NTP_SYS_EVT_STR_ENG_LEAP_DISARMED,    \
  MBG_NTP_SYS_EVT_STR_ENG_LEAP_EVENT,       \
  MBG_NTP_SYS_EVT_STR_ENG_CLOCK_STEP,       \
  MBG_NTP_SYS_EVT_STR_ENG_KERNEL,           \
  MBG_NTP_SYS_EVT_STR_ENG_TAI,              \
  MBG_NTP_SYS_EVT_STR_ENG_STALE_LS_VALUES   \
}



/**
 * @brief Enumeration of supported NTP system state values
 *
 * @see ::NTP_SYS_STATE_SUPP_FLAG_MASKS
 */
enum NTP_SYS_STATE_SUPP_FLAGS
{
  NTP_SYS_STATE_SUPP_STD = 0,    ///< supports standard values of ::NTP_SYS_STATE, all fields except below and reserved
  NTP_SYS_STATE_SUPP_EVENTS,     ///< supports sys state events (::NTP_SYS_STATE::sys_evt_cnt, ::NTP_SYS_STATE::sys_rec_evt)
  NTP_SYS_STATE_SUPP_PRECISION,  ///< supports precision indication, see ::NTP_SYS_STATE::precision
  NTP_SYS_STATE_SUPP_ROOT_DELAY, ///< supports root delay to syspeer, see ::NTP_SYS_STATE::root_delay
  NTP_SYS_STATE_SUPP_ROOT_DISP,  ///< supports root dispersion, see ::NTP_SYS_STATE::root_disp
  NTP_SYS_STATE_SUPP_FREQ,       ///< supports frequency offset, see ::NTP_SYS_STATE::freq
  NTP_SYS_STATE_SUPP_SYS_JITTER, ///< supports combined jitter, see ::NTP_SYS_STATE::sys_jitter
  NTP_SYS_STATE_SUPP_CLK_JITTER, ///< supports clock jitter, see ::NTP_SYS_STATE::clk_jitter
  NTP_SYS_STATE_SUPP_CLK_WANDER, ///< supports clock wander, see ::NTP_SYS_STATE::clk_wander
  N_NTP_SYS_STATE_SUPP_FLAGS
};



/**
 * @brief Flag masks for NTP_SYS_STATE_SUPP_FLAGS
 *
 * Used with ::NTP_SYS_STATE::supp_flags
 *
 * @see ::NTP_SYS_STATE_SUPP_FLAGS
 */
enum NTP_SYS_STATE_SUPP_FLAG_MASKS
{
  NTP_SYS_STATE_SUPP_STD_MSK        = ( 1UL << NTP_SYS_STATE_SUPP_STD ),        ///< see ::NTP_SYS_STATE_SUPP_STD
  NTP_SYS_STATE_SUPP_EVENTS_MSK     = ( 1UL << NTP_SYS_STATE_SUPP_EVENTS ),     ///< see ::NTP_SYS_STATE_SUPP_EVENTS
  NTP_SYS_STATE_SUPP_PRECISION_MSK  = ( 1UL << NTP_SYS_STATE_SUPP_PRECISION ),  ///< see ::NTP_SYS_STATE_SUPP_PRECISION
  NTP_SYS_STATE_SUPP_ROOT_DELAY_MSK = ( 1UL << NTP_SYS_STATE_SUPP_ROOT_DELAY ), ///< see ::NTP_SYS_STATE_SUPP_ROOT_DELAY
  NTP_SYS_STATE_SUPP_ROOT_DISP_MSK  = ( 1UL << NTP_SYS_STATE_SUPP_ROOT_DISP ),  ///< see ::NTP_SYS_STATE_SUPP_ROOT_DISP
  NTP_SYS_STATE_SUPP_FREQ_MSK       = ( 1UL << NTP_SYS_STATE_SUPP_FREQ ),       ///< see ::NTP_SYS_STATE_SUPP_FREQ
  NTP_SYS_STATE_SUPP_SYS_JITTER_MSK = ( 1UL << NTP_SYS_STATE_SUPP_SYS_JITTER ), ///< see ::NTP_SYS_STATE_SUPP_SYS_JITTER
  NTP_SYS_STATE_SUPP_CLK_JITTER_MSK = ( 1UL << NTP_SYS_STATE_SUPP_CLK_JITTER ), ///< see ::NTP_SYS_STATE_SUPP_CLK_JITTER
  NTP_SYS_STATE_SUPP_CLK_WANDER_MSK = ( 1UL << NTP_SYS_STATE_SUPP_CLK_WANDER )  ///< see ::NTP_SYS_STATE_SUPP_CLK_WANDER
};



/**
 * @brief Structure that represents the current system status of an NTP device
 *
 * This structure can be requested from a monitoring program to determine the device system status
 */
typedef struct
{
  uint32_t supp_flags;           ///< Supported NTP system state values, see ::NTP_SYS_STATE_SUPP_FLAG_MASKS

  uint8_t leap_ind;              ///< Leap indicator, see ::NTP_LI_BITS
  uint8_t sys_sync_src;          ///< Current synchronization source, see ::NTP_SYNC_SRC_BITS
  uint8_t sys_evt_cnt;           ///< Number of events, since the last time the event code changed
  uint8_t sys_rec_evt;           ///< Most recent event message, see ::NTP_SYS_EVT_BITS

  uint8_t impl_type;             ///< NTP implementation type, see ::NTP_IMPL
  uint8_t major_version;         ///< Major version number
  uint8_t minor_version;         ///< Minor version number
  uint8_t micro_version;         ///< Micro version number

  uint16_t patch_lvl;            ///< Patch level number
  uint8_t cpu_type;              ///< Processor type, see ::NTP_CPU_TYPES
  uint8_t system;                ///< Operating system, see ::NTP_SYSTEMS

  uint8_t stratum;               ///< Current stratum level of the system
  int8_t precision;              ///< Precision of the system clock (2^precision)
  uint16_t reserved_1;           ///< Reserved, currently always 0

  int32_t root_delay;            ///< [us] Total roundtrip delay to the system peer
  int32_t root_disp;             ///< [us] Total dispersion to the system peer

  MBG_IP_ADDR ref_id;            ///< Reference ID of the current system peer, see ::MBG_IP_ADDR

  NTP_TSTAMP ref_time;           ///< Last time the system time has been adjusted, see ::NTP_TSTAMP
  NTP_TSTAMP sys_time;           ///< Current system time, see ::NTP_TSTAMP

  uint16_t sys_peer;             ///< Assocation ID of the current system peer
  uint8_t poll;                  ///< Current polling interval for the system peer (tc)
  uint8_t minpoll;               ///< Minimal polling interval for the system peer (mintc)

  int64_t offset;                ///< [ns] Combined offset to the system peer

  int32_t freq;                  ///< [ppb] Frequency offset relative to hardware clock
  int32_t sys_jitter;            ///< [us] Combined jitter of the system
  int32_t clk_jitter;            ///< [us] Jitter of the clock
  int32_t clk_wander;            ///< [ppb] Frequency wander of the clock

  uint32_t reserved_2;           ///< Reserved, currently always 0
  uint32_t reserved_3;           ///< Reserved, currently always 0

} NTP_SYS_STATE;

#define _mbg_swab_ntp_sys_state( _p )       \
do                                          \
{                                           \
  _mbg_swab32( &(_p)->supp_flags );         \
                                            \
  _mbg_swab8( &(_p)->leap_ind );            \
  _mbg_swab8( &(_p)->sys_sync_src );        \
  _mbg_swab8( &(_p)->sys_evt_cnt );         \
  _mbg_swab8( &(_p)->sys_rec_evt );         \
                                            \
  _mbg_swab8( &(_p)->impl_type );           \
  _mbg_swab8( &(_p)->major_version );       \
  _mbg_swab8( &(_p)->minor_version );       \
  _mbg_swab8( &(_p)->micro_version );       \
                                            \
  _mbg_swab16( &(_p)->patch_lvl );          \
  _mbg_swab8( &(_p)->cpu_type );            \
  _mbg_swab8( &(_p)->system );              \
                                            \
  _mbg_swab8( &(_p)->stratum );             \
  _mbg_swab8( &(_p)->precision );           \
  _mbg_swab16( &(_p)->reserved_1 );         \
                                            \
  _mbg_swab32( &(_p)->root_delay );         \
  _mbg_swab32( &(_p)->root_disp );          \
                                            \
  _mbg_swab_ip_addr( &(_p)->ref_id );       \
                                            \
  _mbg_swab_ntp_tstamp( &(_p)->ref_time );  \
  _mbg_swab_ntp_tstamp( &(_p)->sys_time );  \
                                            \
  _mbg_swab16( &(_p)->sys_peer );           \
  _mbg_swab8( &(_p)->poll );                \
  _mbg_swab8( &(_p)->minpoll );             \
                                            \
  _mbg_swab64( &(_p)->offset );             \
                                            \
  _mbg_swab32( &(_p)->freq );               \
  _mbg_swab32( &(_p)->sys_jitter );         \
  _mbg_swab32( &(_p)->clk_jitter );         \
  _mbg_swab32( &(_p)->clk_wander );         \
                                            \
  _mbg_swab32( &(_p)->reserved_2 );         \
  _mbg_swab32( &(_p)->reserved_3 );         \
                                            \
} while ( 0 )



/**
 * @brief Enumeration of NTP mode bits
 *
 * Used with ::NTP_PEER_STATE::host_mode and ::NTP_PEER_STATE::peer_mode
 *
 */
enum NTP_MODE_BITS
{
  NTP_MODE_RESERVED = 0,
  NTP_MODE_SYMM_ACT,
  NTP_MODE_SYMM_PASS,
  NTP_MODE_CLIENT,
  NTP_MODE_SERVER,
  NTP_MODE_BROADCAST,
  NTP_MODE_CONTROL,
  NTP_MODE_PRIVATE,
  N_NTP_MODE_BITS
};



/*
 * Default initializers for English NTP peer mode string names. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_MODE_STR_ENG_HOST_LABEL       "Host Mode:"
#define MBG_NTP_MODE_STR_ENG_PEER_LABEL       "Peer Mode:"

#define MBG_NTP_PEER_MODE_STR_ENG_RESERVED    "Reserved"
#define MBG_NTP_PEER_MODE_STR_ENG_SYMM_ACT    "Symm Act"
#define MBG_NTP_PEER_MODE_STR_ENG_SYMM_PASS   "Symm Pass"
#define MBG_NTP_PEER_MODE_STR_ENG_CLIENT      "Client"
#define MBG_NTP_PEER_MODE_STR_ENG_SERVER      "Server"
#define MBG_NTP_PEER_MODE_STR_ENG_BROADCAST   "Broadcast"
#define MBG_NTP_PEER_MODE_STR_ENG_CONTROL     "Control"
#define MBG_NTP_PEER_MODE_STR_ENG_PRIVATE     "Private"

#define MBG_NTP_MODE_STAT_NAMES_ENG     \
{                                       \
  MBG_NTP_PEER_MODE_STR_ENG_RESERVED,   \
  MBG_NTP_PEER_MODE_STR_ENG_SYMM_ACT,   \
  MBG_NTP_PEER_MODE_STR_ENG_SYMM_PASS,  \
  MBG_NTP_PEER_MODE_STR_ENG_CLIENT,     \
  MBG_NTP_PEER_MODE_STR_ENG_SERVER,     \
  MBG_NTP_PEER_MODE_STR_ENG_BROADCAST,  \
  MBG_NTP_PEER_MODE_STR_ENG_CONTROL,    \
  MBG_NTP_PEER_MODE_STR_ENG_PRIVATE     \
}



/**
 * @brief Enumeration of NTP peer reach status
 *
 * Used with ::NTP_PEER_STATE::peer_reach_stat
 */
enum NTP_REACH_STAT_BITS
{
  NTP_REACH_STAT_UNKNOWN = 0,         ///< unknown reach status
  NTP_REACH_STAT_NO_LINK,             ///< no network connection
  NTP_REACH_STAT_DNS_UNREACH,         ///< DNS server could not be reached
  NTP_REACH_STAT_DNS_UNRESOLVED,      ///< DNS name could not be resolved
  NTP_REACH_STAT_PEER_UNREACH,        ///< peer could not be reached
  NTP_REACH_STAT_PEER_NOT_SYNC,       ///< peer is not sync (leap alarm, stratum 16)
  NTP_REACH_STAT_PEER_BAD_QUALITY,    ///< peer has bad quality (dispersion, ...)
  NTP_REACH_STAT_OK,                  ///< reach status is fine
  N_NTP_REACH_STAT_BITS
};



/*
 * Default initializers for English reach status string names. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_PEER_REACH_STAT_STR_ENG_LABEL            "Reach State:"

#define MBG_NTP_PEER_REACH_STAT_STR_ENG_UNKNOWN          "Unknown"
#define MBG_NTP_PEER_REACH_STAT_STR_ENG_NO_LINK          "No link"
#define MBG_NTP_PEER_REACH_STAT_STR_ENG_DNS_UNREACH      "DNS Server unreached"
#define MBG_NTP_PEER_REACH_STAT_STR_ENG_DNS_UNRESOLVED   "DNS name not resolved"
#define MBG_NTP_PEER_REACH_STAT_STR_ENG_PEER_UNREACH     "Peer not reached"
#define MBG_NTP_PEER_REACH_STAT_STR_ENG_PEER_NOT_SYNC    "Peer not sync"
#define MBG_NTP_PEER_REACH_STAT_STR_ENG_PEER_BAD_QUALITY "Peer has bad quality"
#define MBG_NTP_PEER_REACH_STAT_STR_ENG_OK               "Good"

#define MBG_NTP_PEER_REACH_STAT_NAMES_ENG            \
{                                                    \
  MBG_NTP_PEER_REACH_STAT_STR_ENG_UNKNOWN,           \
  MBG_NTP_PEER_REACH_STAT_STR_ENG_NO_LINK,           \
  MBG_NTP_PEER_REACH_STAT_STR_ENG_DNS_UNREACH,       \
  MBG_NTP_PEER_REACH_STAT_STR_ENG_DNS_UNRESOLVED,    \
  MBG_NTP_PEER_REACH_STAT_STR_ENG_PEER_UNREACH,      \
  MBG_NTP_PEER_REACH_STAT_STR_ENG_PEER_NOT_SYNC,     \
  MBG_NTP_PEER_REACH_STAT_STR_ENG_PEER_BAD_QUALITY,  \
  MBG_NTP_PEER_REACH_STAT_STR_ENG_OK                 \
}



/**
 * @brief Enumeration of NTP peer selection status
 *
 * Used with ::NTP_PEER_STATE::peer_sel_stat
 *
 */
enum NTP_PEER_SEL_STATUS_BITS
{
  NTP_PEER_SEL_REJECT = 0,  ///< discarded as not valid (TEST10-TEST13)
  NTP_PEER_SEL_FALSETICK,   ///< discarded by intersection algorithm
  NTP_PEER_SEL_EXCESS,      ///< discarded by table overflow (not used)
  NTP_PEER_SEL_OUTLYER,     ///< discarded by the cluster algorithm
  NTP_PEER_SEL_CANDIDATE,   ///< included by the combine algorithm
  NTP_PEER_SEL_BACKUP,      ///< backup (more than tos maxclock sources)
  NTP_PEER_SEL_SYS_PEER,    ///< system peer
  NTP_PEER_SEL_PPS_PEER,    ///< PPS peer (when the prefer peer is valid)
  N_NTP_PEER_SEL_STATUS_BITS
};



/*
 * Default initializers for English peer select status string names. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_PEER_SEL_STATUS_STR_ENG_LABEL       "Selected Status:"

#define MBG_NTP_PEER_SEL_STATUS_STR_ENG_REJECT      "Not valid"
#define MBG_NTP_PEER_SEL_STATUS_STR_ENG_FALSETICK   "Falsetick"
#define MBG_NTP_PEER_SEL_STATUS_STR_ENG_EXCESS      "Excess"
#define MBG_NTP_PEER_SEL_STATUS_STR_ENG_OUTLYER     "Outlyer"
#define MBG_NTP_PEER_SEL_STATUS_STR_ENG_CANDIDATE   "Candidate"
#define MBG_NTP_PEER_SEL_STATUS_STR_ENG_BACKUP      "Backup"
#define MBG_NTP_PEER_SEL_STATUS_STR_ENG_SYS_PEER    "System Peer"
#define MBG_NTP_PEER_SEL_STATUS_STR_ENG_PPS_PEER    "PPS Peer"

#define MBG_NTP_PEER_SEL_STATUS_NAMES_ENG       \
{                                               \
  MBG_NTP_PEER_SEL_STATUS_STR_ENG_REJECT,       \
  MBG_NTP_PEER_SEL_STATUS_STR_ENG_FALSETICK,    \
  MBG_NTP_PEER_SEL_STATUS_STR_ENG_EXCESS,       \
  MBG_NTP_PEER_SEL_STATUS_STR_ENG_OUTLYER,      \
  MBG_NTP_PEER_SEL_STATUS_STR_ENG_CANDIDATE,    \
  MBG_NTP_PEER_SEL_STATUS_STR_ENG_BACKUP,       \
  MBG_NTP_PEER_SEL_STATUS_STR_ENG_SYS_PEER,     \
  MBG_NTP_PEER_SEL_STATUS_STR_ENG_PPS_PEER      \
}



/**
 * @brief Enumeration of NTP peer status codes
 *
 * @see ::NTP_PEER_STATUS_FLAG_MASKS
 *
 */
enum NTP_PEER_STATUS_FLAGS
{
  NTP_PEER_STATUS_BCST = 0, ///< broadcast association
  NTP_PEER_STATUS_REACH,    ///< host reachable
  NTP_PEER_STATUS_AUTHENB,  ///< authentication enabled
  NTP_PEER_STATUS_AUTH,     ///< authentication ok
  NTP_PEER_STATUS_CONFIG,   ///< persistent association
  N_NTP_PEER_STATUS_FLAGS
};


/**
 * @brief Flag masks for NTP_PEER_STATUS_FLAGS
 *
 * Used with ::NTP_PEER_STATE::peer_status_flags
 *
 * @see ::NTP_PEER_STATUS_FLAGS
 */
enum NTP_PEER_STATUS_FLAG_MASKS
{
  NTP_PEER_STATUS_BCST_MSK    = ( 1UL << NTP_PEER_STATUS_BCST ),    ///< see ::NTP_PEER_STATUS_BCST
  NTP_PEER_STATUS_REACH_MSK   = ( 1UL << NTP_PEER_STATUS_REACH ),   ///< see ::NTP_PEER_STATUS_REACH
  NTP_PEER_STATUS_AUTHENB_MSK = ( 1UL << NTP_PEER_STATUS_AUTHENB ), ///< see ::NTP_PEER_STATUS_AUTHENB
  NTP_PEER_STATUS_AUTH_MSK    = ( 1UL << NTP_PEER_STATUS_AUTH ),    ///< see ::NTP_PEER_STATUS_AUTH
  NTP_PEER_STATUS_CONFIG_MSK  = ( 1UL << NTP_PEER_STATUS_CONFIG ),  ///< see ::NTP_PEER_STATUS_CONFIG
};


/*
 * Default initializers for English peer status string names. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_PEER_STATUS_STR_ENG_LABEL    "Peer Status:"

#define MBG_NTP_PEER_STATUS_STR_ENG_BCST     "Broadcast association"
#define MBG_NTP_PEER_STATUS_STR_ENG_REACH    "Host reachable"
#define MBG_NTP_PEER_STATUS_STR_ENG_AUTHENB  "Authentication enabled"
#define MBG_NTP_PEER_STATUS_STR_ENG_CONFIG   "Persistant assosiation"

#define MBG_NTP_PEER_STATUS_NAMES_ENG    \
{                                        \
  MBG_NTP_PEER_STATUS_STR_ENG_BCST,      \
  MBG_NTP_PEER_STATUS_STR_ENG_REACH,     \
  MBG_NTP_PEER_STATUS_STR_ENG_REACH,     \
  MBG_NTP_PEER_STATUS_STR_ENG_AUTHENB,   \
  MBG_NTP_PEER_STATUS_STR_ENG_CONFIG     \
}



/**
 * @brief Enumeration of NTP peer event message codes
 *
 * Used with ::NTP_PEER_STATE::peer_rec_evt
 *
 */
enum NTP_PEER_EVT_BITS
{
  NTP_PEER_EVT_UNSPEC = 0,       ///< unspecified NTP event
  NTP_PEER_EVT_MOBILIZE,         ///< association mobilized
  NTP_PEER_EVT_DEMOBILIZE,       ///< association demobilized
  NTP_PEER_EVT_UNREACHABLE,      ///< server unreachable
  NTP_PEER_EVT_REACHABLE,        ///< server reachable
  NTP_PEER_EVT_RESTART,          ///< association restart
  NTP_PEER_EVT_NO_REPLY,         ///< no server found (ntpdate mode)
  NTP_PEER_EVT_RATE_EXCEEDED,    ///< rate exceeded (kiss code RATE)
  NTP_PEER_EVT_ACCESS_DENIED,    ///< access denied (kiss code DENY)
  NTP_PEER_EVT_LEAP_ARMED,       ///< leap armed from server LI code
  NTP_PEER_EVT_SYS_PEER,         ///< become system peer
  NTP_PEER_EVT_CLOCK_EVENT,      ///< see clock status word
  NTP_PEER_EVT_BAD_AUTH,         ///< authentication failure
  NTP_PEER_EVT_POPCORN,          ///< popcorn spike suppressor
  NTP_PEER_EVT_INTERLEAVE_MODE,  ///< entering interleave mode
  NTP_PEER_EVT_INTERLEAVE_ERROR, ///< interleave error (recovered)
  N_NTP_PEER_EVT_BITS
};



/*
 * Default initializers for English event message codes. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_PEER_EVT_STR_ENG_CNT_LABEL        "Peer Event Counter:"
#define MBG_NTP_PEER_EVT_STR_ENG_MSG_LABEL        "Peer Event Message:"

#define MBG_NTP_PEER_EVT_STR_ENG_UNSPEC           "Unspecified NTP event"
#define MBG_NTP_PEER_EVT_STR_ENG_MOBILIZE         "Association mobilized"
#define MBG_NTP_PEER_EVT_STR_ENG_DEMOBILIZE       "Association demobilized"
#define MBG_NTP_PEER_EVT_STR_ENG_UNREACHABLE      "Server unreachable"
#define MBG_NTP_PEER_EVT_STR_ENG_REACHABLE        "Server reachable"
#define MBG_NTP_PEER_EVT_STR_ENG_RESTART          "Association restart"
#define MBG_NTP_PEER_EVT_STR_ENG_NO_REPLY         "No server found"
#define MBG_NTP_PEER_EVT_STR_ENG_RATE_EXCEEDED    "Rate exceeded"
#define MBG_NTP_PEER_EVT_STR_ENG_ACCESS_DENIED    "Access denied"
#define MBG_NTP_PEER_EVT_STR_ENG_LEAP_ARMED       "Leap second armed from LI code"
#define MBG_NTP_PEER_EVT_STR_ENG_SYS_PEER         "Become system Peer"
#define MBG_NTP_PEER_EVT_STR_ENG_CLOCK_EVENT      "Clock event"
#define MBG_NTP_PEER_EVT_STR_ENG_BAD_AUTH         "Authentication failure"
#define MBG_NTP_PEER_EVT_STR_ENG_POPCORN          "Popcorn Spike suspressor"
#define MBG_NTP_PEER_EVT_STR_ENG_INTERLEAVE_MODE  "Entering Interleave mode"
#define MBG_NTP_PEER_EVT_STR_ENG_INTERLEAVE_ERROR "Interleave error"


#define MBG_NTP_PEER_EVT_NAMES_ENG          \
{                                           \
  MBG_NTP_PEER_EVT_STR_ENG_UNSPEC,          \
  MBG_NTP_PEER_EVT_STR_ENG_MOBILIZE,        \
  MBG_NTP_PEER_EVT_STR_ENG_DEMOBILIZE,      \
  MBG_NTP_PEER_EVT_STR_ENG_UNREACHABLE,     \
  MBG_NTP_PEER_EVT_STR_ENG_REACHABLE,       \
  MBG_NTP_PEER_EVT_STR_ENG_RESTART,         \
  MBG_NTP_PEER_EVT_STR_ENG_NO_REPLY,        \
  MBG_NTP_PEER_EVT_STR_ENG_RATE_EXCEEDED,   \
  MBG_NTP_PEER_EVT_STR_ENG_ACCESS_DENIED,   \
  MBG_NTP_PEER_EVT_STR_ENG_LEAP_ARMED,      \
  MBG_NTP_PEER_EVT_STR_ENG_SYS_PEER,        \
  MBG_NTP_PEER_EVT_STR_ENG_CLOCK_EVENT,     \
  MBG_NTP_PEER_EVT_STR_ENG_BAD_AUTH,        \
  MBG_NTP_PEER_EVT_STR_ENG_POPCORN,         \
  MBG_NTP_PEER_EVT_STR_ENG_INTERLEAVE_MODE, \
  MBG_NTP_PEER_EVT_STR_ENG_INTERLEAVE_ERROR \
}


/**
 * @brief Enumeration of NTP flash status bit codes
 *
 * @see ::NTP_FLASH_STAT_FLAG_MASKS
 *
 */
enum NTP_FLASH_STAT_FLAGS
{
  NTP_FLASH_STAT_PKT_DUP = 0,    ///< duplicate packet
  NTP_FLASH_STAT_PKT_BOGUS,      ///< bogus packet
  NTP_FLASH_STAT_PKT_UNSYNC,     ///< server not synchronized
  NTP_FLASH_STAT_PKT_DENIED,     ///< access denied
  NTP_FLASH_STAT_PKT_AUTH,       ///< authentication failure
  NTP_FLASH_STAT_PKT_STRATUM,    ///< invalid leap or stratum
  NTP_FLASH_STAT_PKT_HEADER,     ///< header distance exceeded
  NTP_FLASH_STAT_PKT_AUTOKEY,    ///< Autokey sequence error
  NTP_FLASH_STAT_PKT_CRYPTO,     ///< Autokey protocol error
  NTP_FLASH_STAT_PEER_STRATUM,   ///< invalid header or stratum
  NTP_FLASH_STAT_PEER_DIST,      ///< distance threshold exceeded
  NTP_FLASH_STAT_PEER_LOOP,      ///< synchronization loop
  NTP_FLASH_STAT_PEER_UNREACH,   ///< unreachable or nonselect
  N_NTP_FLASH_STAT_FLAGS
};



/**
 * @brief Flag masks for ::NTP_FLASH_STAT_FLAGS
 *
 * Used with ::NTP_PEER_STATE::flash_stat_flags
 *
 * @see ::NTP_FLASH_STAT_FLAGS
 */
enum NTP_FLASH_STAT_FLAG_MASKS
{
  NTP_FLASH_STAT_PKT_DUP_MSK      = ( 1UL << NTP_FLASH_STAT_PKT_DUP ),      ///< see ::NTP_FLASH_STAT_PKT_DUP
  NTP_FLASH_STAT_PKT_BOGUS_MSK    = ( 1UL << NTP_FLASH_STAT_PKT_BOGUS ),    ///< see ::NTP_FLASH_STAT_PKT_BOGUS
  NTP_FLASH_STAT_PKT_UNSYNC_MSK   = ( 1UL << NTP_FLASH_STAT_PKT_UNSYNC ),   ///< see ::NTP_FLASH_STAT_PKT_UNSYNC
  NTP_FLASH_STAT_PKT_DENIED_MSK   = ( 1UL << NTP_FLASH_STAT_PKT_DENIED ),   ///< see ::NTP_FLASH_STAT_PKT_DENIED
  NTP_FLASH_STAT_PKT_AUTH_MSK     = ( 1UL << NTP_FLASH_STAT_PKT_AUTH ),     ///< see ::NTP_FLASH_STAT_PKT_AUTH
  NTP_FLASH_STAT_PKT_STRATUM_MSK  = ( 1UL << NTP_FLASH_STAT_PKT_STRATUM ),  ///< see ::NTP_FLASH_STAT_PKT_STRATUM
  NTP_FLASH_STAT_PKT_HEADER_MSK   = ( 1UL << NTP_FLASH_STAT_PKT_HEADER ),   ///< see ::NTP_FLASH_STAT_PKT_HEADER
  NTP_FLASH_STAT_PKT_AUTOKEY_MSK  = ( 1UL << NTP_FLASH_STAT_PKT_AUTOKEY ),  ///< see ::NTP_FLASH_STAT_PKT_AUTOKEY
  NTP_FLASH_STAT_PKT_CRYPTO_MSK   = ( 1UL << NTP_FLASH_STAT_PKT_CRYPTO ),   ///< see ::NTP_FLASH_STAT_PKT_CRYPTO
  NTP_FLASH_STAT_PEER_STRATUM_MSK = ( 1UL << NTP_FLASH_STAT_PEER_STRATUM ), ///< see ::NTP_FLASH_STAT_PEER_STRATUM
  NTP_FLASH_STAT_PEER_DIST_MSK    = ( 1UL << NTP_FLASH_STAT_PEER_DIST ),    ///< see ::NTP_FLASH_STAT_PEER_DIST
  NTP_FLASH_STAT_PEER_LOOP_MSK    = ( 1UL << NTP_FLASH_STAT_PEER_LOOP ),    ///< see ::NTP_FLASH_STAT_PEER_LOOP
  NTP_FLASH_STAT_PEER_UNREACH_MSK = ( 1UL << NTP_FLASH_STAT_PEER_UNREACH ), ///< see ::NTP_FLASH_STAT_PEER_UNREACH
};



/*
 * Default initializers for English ntp flash state mask. Initializers
 * for multi-language strings can be found in tmonlstr.h.
 */
#define MBG_NTP_FLASH_STR_ENG_LABEL          "Flash Status:"

#define MBG_NTP_FLASH_STR_ENG_PKT_DUP        "Duplicate packet"
#define MBG_NTP_FLASH_STR_ENG_PKT_BOGUS      "Bogus packet"
#define MBG_NTP_FLASH_STR_ENG_PKT_UNSYNC     "Server not synchronized"
#define MBG_NTP_FLASH_STR_ENG_PKT_DENIED     "Access denied"
#define MBG_NTP_FLASH_STR_ENG_PKT_AUTH       "Authentication failure"
#define MBG_NTP_FLASH_STR_ENG_PKT_STRATUM    "Invalid leap or stratum"
#define MBG_NTP_FLASH_STR_ENG_PKT_HEADER     "Header distance exceeded"
#define MBG_NTP_FLASH_STR_ENG_PKT_AUTOKEY    "Autokey sequence error"
#define MBG_NTP_FLASH_STR_ENG_PKT_CRYPTO     "Autokey protocol error"
#define MBG_NTP_FLASH_STR_ENG_PEER_STRATUM   "Invalid header or stratum"
#define MBG_NTP_FLASH_STR_ENG_PEER_DIST      "Distance threshold exceeded"
#define MBG_NTP_FLASH_STR_ENG_PEER_LOOP      "Synchronization loop"
#define MBG_NTP_FLASH_STR_ENG_PEER_UNREACH   "Unreachable or nonselect"


#define MBG_NTP_FLASH_NAMES_ENG        \
{                                      \
  MBG_NTP_FLASH_STR_ENG_PKT_DUP,       \
  MBG_NTP_FLASH_STR_ENG_PKT_BOGUS,     \
  MBG_NTP_FLASH_STR_ENG_PKT_UNSYNC,    \
  MBG_NTP_FLASH_STR_ENG_PKT_DENIED,    \
  MBG_NTP_FLASH_STR_ENG_PKT_AUTH,      \
  MBG_NTP_FLASH_STR_ENG_PKT_STRATUM,   \
  MBG_NTP_FLASH_STR_ENG_PKT_HEADER,    \
  MBG_NTP_FLASH_STR_ENG_PKT_AUTOKEY,   \
  MBG_NTP_FLASH_STR_ENG_PKT_CRYPTO,    \
  MBG_NTP_FLASH_STR_ENG_PEER_STRATUM,  \
  MBG_NTP_FLASH_STR_ENG_PEER_DIST,     \
  MBG_NTP_FLASH_STR_ENG_PEER_LOOP,     \
  MBG_NTP_FLASH_STR_ENG_PEER_UNREACH   \
}



/**
 * @brief Enumeration of supported NTP peer state values
 *
 * @see ::NTP_PEER_STATE_SUPP_FLAG_MASKS
 */
enum NTP_PEER_STATE_SUPP_FLAGS
{
  NTP_PEER_STATE_SUPP_STD,          ///< supports standard values of ::NTP_PEER_STATE, all fields except below and reserved
  NTP_PEER_STATE_SUPP_ASS_ID,       ///< supports association ID, see ::NTP_PEER_STATE::ass_id
  NTP_PEER_STATE_SUPP_EVENTS,       ///< supports peer state events (NTP_PEER_STATE::peer_evt_cnt, NTP_PEER_STATE::peer_rec_evt)
  NTP_PEER_STATE_SUPP_REACH_STAT,   ///< supports peer reach status, see ::NTP_PEER_STATE::peer_reach_stat
  NTP_PEER_STATE_SUPP_PRECISION,    ///< supports precision indication, see ::NTP_PEER_STATE::precision
  NTP_PEER_STATE_SUPP_ROOT_DELAY,   ///< supports root delay to syspeer, see ::NTP_PEER_STATE::root_delay
  NTP_PEER_STATE_SUPP_ROOT_DISP,    ///< supports root dispersion, see ::NTP_PEER_STATE::root_disp
  NTP_PEER_STATE_SUPP_HEADWAY,      ///< supports headway, see ::NTP_PEER_STATE::headway
  NTP_PEER_STATE_SUPP_FLASH_STAT,   ///< supports flash status word, see ::NTP_PEER_STATE::flash_stat_flags
  NTP_PEER_STATE_SUPP_KEY_ID,       ///< supports symmetric key id, see ::NTP_PEER_STATE::key_id
  NTP_PEER_STATE_SUPP_DISP,         ///< supports filter dispersion, see ::NTP_PEER_STATE::disp
  NTP_PEER_STATE_SUPP_JITTER,       ///< supports filter jitter, see ::NTP_PEER_STATE::jitter
  NTP_PEER_STATE_SUPP_XLEAVE,       ///< supports interleave delay, see ::NTP_PEER_STATE::xleave
  N_NTP_PEER_STATE_SUPP_FLAGS
};


/**
 * @brief Flag masks for NTP_PEER_STATE_SUPP_FLAGS
 *
 * Used with ::NTP_PEER_STATE::supp_flags
 *
 * @see ::NTP_PEER_STATE_SUPP_FLAGS
 */
enum NTP_PEER_STATE_SUPP_FLAG_MASKS
{
  NTP_PEER_STATE_SUPP_STD_MSK         = ( 1UL << NTP_PEER_STATE_SUPP_STD ),         ///< see ::NTP_PEER_STATE_SUPP_STD
  NTP_PEER_STATE_SUPP_ASS_ID_MSK      = ( 1UL << NTP_PEER_STATE_SUPP_ASS_ID ),      ///< see ::NTP_PEER_STATE_SUPP_ASS_ID
  NTP_PEER_STATE_SUPP_EVENTS_MSK      = ( 1UL << NTP_PEER_STATE_SUPP_EVENTS ),      ///< see ::NTP_PEER_STATE_SUPP_EVENTS
  NTP_PEER_STATE_SUPP_REACH_STAT_MSK  = ( 1UL << NTP_PEER_STATE_SUPP_REACH_STAT ),  ///< see ::NTP_PEER_STATE_SUPP_REACH_STAT
  NTP_PEER_STATE_SUPP_PRECISION_MSK   = ( 1UL << NTP_PEER_STATE_SUPP_PRECISION ),   ///< see ::NTP_PEER_STATE_SUPP_PRECISION
  NTP_PEER_STATE_SUPP_ROOT_DELAY_MSK  = ( 1UL << NTP_PEER_STATE_SUPP_ROOT_DELAY ),  ///< see ::NTP_PEER_STATE_SUPP_ROOT_DELAY
  NTP_PEER_STATE_SUPP_ROOT_DISP_MSK   = ( 1UL << NTP_PEER_STATE_SUPP_ROOT_DISP ),   ///< see ::NTP_PEER_STATE_SUPP_ROOT_DISP
  NTP_PEER_STATE_SUPP_HEADWAY_MSK     = ( 1UL << NTP_PEER_STATE_SUPP_HEADWAY ),     ///< see ::NTP_PEER_STATE_SUPP_HEADWAY
  NTP_PEER_STATE_SUPP_FLASH_STAT_MSK  = ( 1UL << NTP_PEER_STATE_SUPP_FLASH_STAT ),  ///< see ::NTP_PEER_STATE_SUPP_FLASH_STAT
  NTP_PEER_STATE_SUPP_KEY_ID_MSK      = ( 1UL << NTP_PEER_STATE_SUPP_KEY_ID ),      ///< see ::NTP_PEER_STATE_SUPP_KEY_ID
  NTP_PEER_STATE_SUPP_DISP_MSK        = ( 1UL << NTP_PEER_STATE_SUPP_DISP ),        ///< see ::NTP_PEER_STATE_SUPP_DISP
  NTP_PEER_STATE_SUPP_JITTER_MSK      = ( 1UL << NTP_PEER_STATE_SUPP_JITTER ),      ///< see ::NTP_PEER_STATE_SUPP_JITTER
  NTP_PEER_STATE_SUPP_XLEAVE_MSK      = ( 1UL << NTP_PEER_STATE_SUPP_XLEAVE ),      ///< see ::NTP_PEER_STATE_SUPP_XLEAVE
};



/**
 * @brief Structure that represents the status of an NTP peer
 *
 * This structure should be requested via ::NTP_PEER_STATE_IDX
 *
 * @see ::NTP_PEER_STATE_IDX
 */
typedef struct
{
  uint32_t supp_flags;           ///< Supported NTP peer state values, see ::NTP_PEER_STATE_SUPP_FLAG_MASKS

  uint16_t ass_id;               ///< Association ID of the peer
  uint16_t peer_status_flags;    ///< Peer status flags, see ::NTP_PEER_STATUS_FLAG_MASKS

  uint8_t leap_ind;              ///< Leap indicator, see ::NTP_LI_BITS
  uint8_t peer_sel_stat;         ///< Current selection status of the peer, see ::NTP_PEER_SEL_STATUS_BITS
  uint8_t peer_evt_cnt;          ///< Number of events, since the last time the event code changed
  uint8_t peer_rec_evt;          ///< Most recent event message, see ::NTP_PEER_EVT_BITS

  uint8_t peer_reach_stat;       ///< Current reach status of the peer, see ::NTP_REACH_STAT_BITS
  uint8_t reserved_1;            ///< Reserved, currently always 0
  uint16_t reserved_2;           ///< Reserved, currently always 0

  MBG_IP_ADDR_PORT src_addr;     ///< Source address of the NTP peer, see ::MBG_IP_ADDR_PORT
  MBG_IP_ADDR_PORT dst_addr;     ///< Destination address of the NTP peer, see ::MBG_IP_ADDR_PORT

  uint8_t stratum;               ///< Current stratum level of the NTP peer
  int8_t precision;              ///< Precision of the peer clock (2^precision)
  uint16_t reserved_3;           ///< Reserved, currently always 0

  int32_t root_delay;            ///< [us] Total roundtrip delay to the system peer of the NTP peer
  int32_t root_disp;             ///< [us] Total dispersion to the system peer of the NTP peer

  MBG_IP_ADDR ref_id;            ///< Reference ID of the NTP peer, see ::MBG_IP_ADDR

  NTP_TSTAMP ref_time;           ///< Last time the NTP peers time has been adjusted, see ::NTP_TSTAMP
  NTP_TSTAMP rec_time;           ///< Current system time of the NTP peer, see ::NTP_TSTAMP

  uint8_t reach;                 ///< Shift register for the last 8 polling intervals
  uint8_t reserved_4;            ///< Reserved, currently always 0
  uint16_t unreach;              ///< Counter for the number of unsuccessful polling intervals

  uint8_t host_mode;             ///< NTP mode of the requesting host, see ::NTP_MODE_BITS
  uint8_t peer_mode;             ///< NTP mode of the peer, see ::NTP_MODE_BITS
  uint8_t host_poll;             ///< Host NTP polling interval
  uint8_t peer_poll;             ///< Peer NTP polling interval

  uint8_t headway;               ///< Indicator for the KoD packet, TODO: further investigation
  uint8_t reserved_5;            ///< Reserved, currently always 0
  uint16_t flash_stat_flags;     ///< Flash status flags, see ::NTP_FLASH_STAT_FLAG_MASKS

  uint16_t key_id;               ///< ID of symmetric authentication key
  uint16_t reserved_6;           ///< Reserved, currently always 0

  int64_t offset;                ///< [ns] filter offset to this NTP peer
  int64_t delay;                 ///< [ns] filter delay to this NTP peer

  int32_t disp;                  ///< [us] filter dispersion of the NTP peer
  int32_t jitter;                ///< [us] filter jitter of the NTP peer

  uint32_t xleave;               ///< [ns] interleave delay of the NTP peer

  uint8_t n_filter_values;       ///< Number of filter values available, currently always 0
  uint8_t reserved_7;            ///< Reserved, currently always 0
  uint16_t reserved_8;           ///< Reserved, currently always 0

  uint32_t reserved_9;           ///< Reserved, currently always 0

} NTP_PEER_STATE;



#define _mbg_swab_ntp_peer_state( _p )        \
do                                            \
{                                             \
  _mbg_swab32( &(_p)->supp_flags );           \
                                              \
  _mbg_swab16( &(_p)->ass_id );               \
  _mbg_swab16( &(_p)->peer_status_flags );    \
                                              \
  _mbg_swab8( &(_p)->leap_ind );              \
  _mbg_swab8( &(_p)->peer_sel_stat );         \
  _mbg_swab8( &(_p)->peer_evt_cnt );          \
  _mbg_swab8( &(_p)->peer_rec_evt );          \
                                              \
  _mbg_swab8( &(_p)->peer_reach_stat );       \
  _mbg_swab8( &(_p)->reserved_1 );            \
  _mbg_swab16( &(_p)->reserved_2 );           \
                                              \
  _mbg_swab_ip_addr_port( &(_p)->src_addr );  \
  _mbg_swab_ip_addr_port( &(_p)->dst_addr );  \
                                              \
  _mbg_swab8( &(_p)->stratum );               \
  _mbg_swab8( &(_p)->precision );             \
  _mbg_swab16( &(_p)->reserved_3 );           \
                                              \
  _mbg_swab32( &(_p)->root_delay );           \
  _mbg_swab32( &(_p)->root_disp );            \
                                              \
  _mbg_swab_ip_addr( &(_p)->ref_id );         \
                                              \
  _mbg_swab_ntp_tstamp( &(_p)->ref_time );    \
  _mbg_swab_ntp_tstamp( &(_p)->rec_time );    \
                                              \
  _mbg_swab8( &(_p)->reach );                 \
  _mbg_swab8( &(_p)->reserved_4 );            \
  _mbg_swab16( &(_p)->unreach );              \
                                              \
  _mbg_swab8( &(_p)->host_mode );             \
  _mbg_swab8( &(_p)->peer_mode );             \
  _mbg_swab8( &(_p)->host_poll );             \
  _mbg_swab8( &(_p)->peer_poll );             \
                                              \
  _mbg_swab8( &(_p)->headway );               \
  _mbg_swab8( &(_p)->reserved_5 );            \
  _mbg_swab16( &(_p)->flash_stat_flags );     \
                                              \
  _mbg_swab16( &(_p)->key_id );               \
  _mbg_swab16( &(_p)->reserved_6 );           \
                                              \
  _mbg_swab64( &(_p)->offset );               \
  _mbg_swab64( &(_p)->delay );                \
                                              \
  _mbg_swab32( &(_p)->disp );                 \
  _mbg_swab32( &(_p)->jitter );               \
                                              \
  _mbg_swab32( &(_p)->xleave );               \
                                              \
  _mbg_swab8( &(_p)->n_filter_values );       \
  _mbg_swab8( &(_p)->reserved_7 );            \
  _mbg_swab16( &(_p)->reserved_8 );           \
                                              \
  _mbg_swab32( &(_p)->reserved_9 );           \
                                              \
} while ( 0 )



/**
 * @brief Structure that contains an index value and the NTP peer state
 *
 * This structure can be requested by a monitoring program to observe the status of configured NTP peers
 *
 * @see ::NTP_PEER_STATE
 */
typedef struct
{
  uint32_t idx;                  ///< The index of the observed NTP peer
  NTP_PEER_STATE peer_state;     ///< Peer state, see ::NTP_PEER_STATE

} NTP_PEER_STATE_IDX;

#define _mbg_swab_ntp_peer_state_idx( _p )        \
do                                                \
{                                                 \
  _mbg_swab32( &(_p)->idx );                      \
  _mbg_swab_ntp_peer_state( &(_p)->peer_state );  \
} while ( 0 )


/** @} defgroup group_ntp */



/**
 * @defgroup group_lno Definitions used with LNO devices
 *
 * @{ */

#define MAX_LNO_OUTPUT  4

/**
 * @brief LNO status
 */
typedef struct
{
  uint16_t sine_lvl[MAX_LNO_OUTPUT];  ///< signal levels at the outputs

  uint16_t max_sine_lvl;    ///< max level of an output, e.g. 1024
  uint8_t n_outputs;        ///< actual number of outputs [0..::MAX_LNO_OUTPUT-1]
  uint8_t out_enb_state;    ///< e.g. bit 0 is set if corresponding output 0 is enabled, etc.

  uint16_t reserved_0;      ///< reserved, currently always 0
  uint16_t flags;           ///< status flags, see ::LNO_STATE_FLAG_BITS

} LNO_STATE;

#define _mbg_swab_lno_state( _p )        \
do                                       \
{                                        \
  int i;                                 \
                                         \
  for ( i = 0; i < MAX_LNO_OUTPUT; i++ ) \
    _mbg_swab16( &(_p)->sine_lvl[i] );   \
                                         \
  _mbg_swab_16( &(_p)->max_sine_lvl );   \
  _mbg_swab_16( &(_p)->reserved_0 );     \
  _mbg_swab_16( &(_p)->flags );          \
} while ( 0 )


/**
 * @brief Flags used with LNO_STATE::flags
 */
enum LNO_STATE_FLAG_BITS
{
  LNO_FLAG_BIT_PLL_LOCKED,        ///< PLL is locked
  N_LNO_FLAG_BIT                  ///< number of known bits
};

#define LNO_FLAG_PLL_LOCKED         ( 1UL << LNO_FLAG_BIT_PLL_LOCKED )

/** @} defgroup group_lno */



/**
 * @defgroup group_vst Definitions used with Versatile Storage
 *
 * Versatile storage is used to store binary data on a device where the storage
 * device must not necessarily know about the data structure. It just stores
 * a piece of data, and retrieves it on demand.
 *
 * The structures and associated API calls are only supported if the
 * ::GPS_HAS_VST bit is set in ::RECEIVER_INFO::features.
 *
 * @{ */

/**
 * @brief Known common VST data types
 */
enum VST_DATA_TYPES
{
  VST_DATA_TYPE_MAC_ADDR,   //##++++++++++++ This is just an example. More to be added.
  N_VST_DATA_TYPES
};


/**
 * @brief
 */
typedef struct
{
  uint16_t data_type;  ///< data type identifier, see ::VST_DATA_TYPES for common types
  uint16_t idx;        ///< Index for several sets of the same type
  uint16_t data_len;   ///< length of the data set appended to the header
  uint16_t reserved;   ///< reserved, currently always 0

} VST_HEADER;

#define _mbg_swab_vst_header( _p )  \
do                                  \
{                                   \
  _mbg_swab16( &(_p)->data_type );  \
  _mbg_swab16( &(_p)->idx );        \
  _mbg_swab16( &(_p)->data_len );   \
  _mbg_swab16( &(_p)->reserved );   \
} while ( 0 )

/** @} defgroup group_vst */



/**
 * @defgroup group_shs Definitions used with SHS devices
 *
 * An SHS (Secure Hybrid System) device compares the times from 2 sources
 * and eventually sets an alarm (warning and/or error) flag if the difference
 * between the 2 time sources exceeds a configurable limit.
 *
 * These structures and associated definitions are used to query the SHS
 * capabilities, configure the SHS device according to its capabilities,
 * and query the SHS status.
 *
 * The structures and associated API calls are only supported if the
 * ::GPS_HAS_SHS bit is set in ::RECEIVER_INFO::features.
 *
 * The ::SHS_INFO structure can be read to retrieve the capabilities and
 * current settings of the device. The ::SHS_SETTINGS structure can then
 * be set up according to the capabilities, and be written back to configure
 * the device.
 *
 * If ::SHS_SETTINGS::err_limit and/or ::SHS_SETTINGS::warn_limit are
 * not 0 then the SHS device checks if the time difference between the
 * 2 clocks exceeds these limits and sets ::SHS_STATUS::shs_state
 * as appropriate.
 *
 * If indicated by ::SHS_INFO::supp_flags the SHS device can also take
 * certain actions if the time difference exceeds the error limit.
 * If this happens then the same flags are set in ::SHS_STATUS::flags
 * to indicate the action has been taken.
 *
 * @{ */

/**
 * @brief Current configuration of an SHS controller
 *
 * @see ::SHS_INFO
 * @see ::SHS_STATUS
 */
typedef struct
{
  NANO_TIME err_limit;   ///< time difference limit above which an error is indicated
  NANO_TIME warn_limit;  ///< time difference limit above which a warning is indicated
  uint32_t reserved;     ///< reserved, currently always 0
  uint32_t flags;        ///< see ::SHS_FLAG_MASKS

} SHS_SETTINGS;

#define _mbg_swab_shs_settings( _p )        \
do                                          \
{                                           \
  _mbg_swab_nano_time( &(_p)->err_limit );  \
  _mbg_swab_nano_time( &(_p)->warn_limit ); \
  _mbg_swab32( &(_p)->reserved );           \
  _mbg_swab32( &(_p)->flags );              \
} while ( 0 )



/**
 * @brief Current SHS settings and general SHS capabilities
 *
 * @see ::SHS_SETTINGS
 * @see ::SHS_STATUS
 */
typedef struct
{
  SHS_SETTINGS settings;  ///< current configuration settings
  NANO_TIME max_limit;    ///< if not 0, the max. allowed value for ::SHS_SETTINGS::err_limit and ::SHS_SETTINGS::warn_limit
  uint32_t reserved;      ///< reserved, currently always 0
  uint32_t supp_flags;    ///< indicates which flags are supported for ::SHS_SETTINGS::flags, see ::SHS_FLAG_MASKS

} SHS_INFO;

#define _mbg_swab_shs_info( _p )             \
do                                           \
{                                            \
  _mbg_swab_shs_settings( &(_p)->settings ); \
  _mbg_swab_nano_time( &(_p)->max_limit );   \
  _mbg_swab32( &(_p)->reserved );            \
  _mbg_swab32( &(_p)->flags );               \
} while ( 0 )



/**
 * @brief Current SHS status
 */
typedef struct
{
  NANO_TIME time_diff;         ///< current time difference between the 2 clocks
  TM_STATUS_EXT clk_status_1;  ///< status of first clock
  TM_STATUS_EXT clk_status_2;  ///< status of second clock
  uint8_t shs_state;           ///< see ::SHS_STATES
  uint8_t reserved_1;          ///< reserved, currently always 0
  uint16_t reserved_2;         ///< reserved, currently always 0
  uint32_t flags;              ///< see ::SHS_FLAG_MASKS

} SHS_STATUS;

#define _mbg_swab_shs_status( _p )          \
do                                          \
{                                           \
  _mbg_swab_nano_time( &(_p)->time_diff );  \
  _mbg_swab32( &(_p)->clk_status_1 );       \
  _mbg_swab32( &(_p)->clk_status_2 );       \
  _mbg_swab16( &(_p)->reserved_2 );         \
  _mbg_swab32( &(_p)->flags );              \
} while ( 0 )



/**
 * @brief SHS configuration flag bits
 *
 * Codes used with ::SHS_STATUS::shs_state
 */
enum SHS_STATES
{
  SHS_STATE_DISABLED,  ///< time difference not checked, eventually no limits configured
  SHS_STATE_OK,        ///< time difference OK, below warning limit
  SHS_STATE_WARNING,   ///< time difference exceeds warning limit
  SHS_STATE_ERROR,     ///< time difference exceeds error limit
  SHS_STATE_FATAL,     ///< one or both time sources disconnected
  N_SHS_STATES
};



/**
 * @brief SHS flag bits
 *
 * @see ::SHS_FLAG_MASKS
 */
enum SHS_FLAG_BITS
{
  SHS_FLAG_BIT_DISB_SERIAL,  ///< disable serial output in state ::SHS_STATE_ERROR
  SHS_FLAG_BIT_DISB_PPS,     ///< disable PPS output in state ::SHS_STATE_ERROR
  SHS_FLAG_BIT_DISB_10MHZ,   ///< disable 10 MHz output in state ::SHS_STATE_ERROR
  N_SHS_FLAG_BITS
};


/**
 * @brief SHS flag masks
 *
 * With ::SHS_INFO::supp_flags these flags indicate what is supported
 * by the SHS controller, e.g. what action can be taken automatically.
 * Each bit set in ::SHS_INFO::supp_flags can be set by a configuration
 * tool in ::SHS_SETTINGS::flags to enable the associated feature.
 * If a corresponding bit is set in ::SHS_STATUS::flags this means the
 * associated feature has been enabled, e.g. an action has been taken.
 *
 * @see ::SHS_FLAG_BITS
 */
enum SHS_FLAG_MASKS
{
  SHS_FLAG_DISB_SERIAL = ( 1UL << SHS_FLAG_BIT_DISB_SERIAL ), ///< see ::SHS_FLAG_BIT_DISB_SERIAL
  SHS_FLAG_DISB_PPS    = ( 1UL << SHS_FLAG_BIT_DISB_PPS ),    ///< see ::SHS_FLAG_BIT_DISB_PPS
  SHS_FLAG_DISB_10MHZ  = ( 1UL << SHS_FLAG_BIT_DISB_10MHZ )   ///< see ::SHS_FLAG_BIT_DISB_10MHZ
};

/** @} defgroup group_shs */



/**
 * @defgroup group_xbp eXtended Binary Protocol definitions
 *
 * @note These structures are only supported if ::GPS_HAS_XBP is set
 * in ::RECEIVER_INFO::features.
 *
 * @{ */

/**
 * @brief An XBP port specifier
 *
 * Each controller can provide up to 255 ports with numbers 0..254.
 * XBP port number ::XBP_PORT_RESERVED is reserved to mark unused ports.
 */
typedef uint8_t XBP_PORT;


/**
 * @brief An identifier used to mark an XBP port unused
 */
#define XBP_PORT_RESERVED   ( (XBP_PORT) -1 )


/**
 * @brief Maximum XBP bus/controller cascading level
 *
 * Should be 7 so the total size of ::XBP_ADDR is 8 bytes.
 */
#define MAX_XBP_CASC_LVL   7


/**
 * @brief An XBP address specifier
 *
 * A generic scheme to address devices connected to cascaded controllers.
 */
typedef struct
{
  uint8_t hop_count;                ///< Used as index to the addr array
  XBP_PORT addr[MAX_XBP_CASC_LVL];  ///< An array of port numbers on cascaded controllers

} XBP_ADDR;

#define _mbg_swab_xbp_addr( _p )  _nop_macro_fnc()   // only single bytes



/**
 * @brief A structure used to report XBP features and limits
 */
typedef struct
{
  uint32_t features;     ///< Mask of XBP features, see ::XBP_FEAT_MASKS
  uint32_t flags;        ///< XBP flags, currently not used
  uint32_t reserved_0;   ///< reserved, currently not used
  uint32_t reserved_1;   ///< reserved, currently not used
  uint32_t reserved_2;   ///< reserved, currently not used
  uint32_t reserved_3;   ///< reserved, currently not used

} XBP_LIMITS;

#define _mbg_swab_xbp_limits( _p )   \
do                                   \
{                                    \
  _mbg_swab32( &(_p)->features );    \
  _mbg_swab32( &(_p)->flags );       \
  _mbg_swab32( &(_p)->reserved_0 );  \
  _mbg_swab32( &(_p)->reserved_1 );  \
  _mbg_swab32( &(_p)->reserved_2 );  \
  _mbg_swab32( &(_p)->reserved_3 );  \
} while ( 0 )



/**
 * @brief Enumeration of bits used to define ::XBP_FEAT_MASKS
 */
enum XBP_FEAT_BITS
{
  XBP_FEAT_BIT_NODES,   ///< Supports ::XBP_NODE_LIMITS and associated structures
  N_XBP_FEAT_BITS
};


/**
 * @brief XBP feature masks used with ::XBP_LIMITS::features
 *
 * @see ::XBP_FEAT_BITS
 */
enum XBP_FEAT_MASKS
{
  XBP_FEAT_MASK_NODES = ( 1UL << XBP_FEAT_BIT_NODES )   ///< See ::XBP_FEAT_BIT_NODES
};



/**
 * @brief Information on available XBP nodes
 *
 * Only supported if ::XBP_FEAT_MASK_NODES is set in ::XBP_LIMITS::features.
 */
typedef struct
{
  uint32_t node_count;  ///< Number of XBP nodes available in the system
  uint32_t reserved_0;  ///< Currently reserved, always 0
  uint32_t reserved_1;  ///< Currently reserved, always 0
  // TODO: do we need additional fields here?

} XBP_NODE_LIMITS;

#define _mbg_swab_xbp_node_limits( _p )  \
do                                       \
{                                        \
  _mbg_swab32( &(_p)->node_count );      \
  _mbg_swab32( &(_p)->reserved_0 );      \
  _mbg_swab32( &(_p)->reserved_1 );      \
} while ( 0 )



/**
 * @brief Possible states of an XBP device
 *
 * Used with ::XBP_NODE_INFO::state.
 */
enum XBP_DEVICE_STATES
{
  XBP_DEVICE_STATE_UNKNOWN,
  XBP_DEVICE_STATE_NOT_AVAILABLE,
  XBP_DEVICE_STATE_INITIALIZING,
  XBP_DEVICE_STATE_AVAILABLE,
  XBP_DEVICE_STATE_DISCONNECTED,
  N_XBP_DEVICE_STATES
};



/**
 * @brief Information on a specific XBP node
 *
 * Only supported if ::XBP_FEAT_MASK_NODES is set in ::XBP_LIMITS::features.
 * The number of instances supported by a device is specified
 * in ::XBP_NODE_LIMITS::node_count.
 */
typedef struct
{
  XBP_ADDR addr;  ///< The address of the specific node

  /// ::RECEIVER_INFO of the device connected to this node.
  /// If no device is available then ::RECEIVER_INFO::model_code
  /// is set to ::GPS_MODEL_UNKNOWN (== 0).
  RECEIVER_INFO ri;

  uint8_t state;     ///< The device state, see ::XBP_DEVICE_STATES
  uint8_t reserved;  ///< Currently reserved, always 0
  uint32_t flags;    ///< Currently reserved, always 0

} XBP_NODE_INFO;

#define _mbg_swab_xbp_node_info( _p )    \
do                                       \
{                                        \
  _mbg_swab_xbp_addr( &(_p)->addr );     \
  _mbg_swab_receiver_info( &(_p)->ri );  \
  _mbg_swab8( &(_p)->state );            \
  _mbg_swab8( &(_p)->reserved );         \
  _mbg_swab32( &(_p)->flags );           \
} while ( 0 )



/**
 * @brief Information on an XBP node with specific index
 *
 * Only supported if ::XBP_FEAT_MASK_NODES is set in ::XBP_LIMITS::features.
 */
typedef struct
{
  uint32_t idx;             ///< node index, 0..::XBP_NODE_LIMITS::node_count-1
  XBP_NODE_INFO node_info;  ///< ::RECEIVER_INFO of the device behind this node

} XBP_NODE_INFO_IDX;

#define _mbg_swab_xbp_node_info_idx( _p )       \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->idx );                    \
  _mbg_swab_xbp_node_info( &(_p)->node_info );  \
} while ( 0 )


/** @} defgroup group_xbp */



/**
 * @defgroup group_tlv_api Meinberg TLV API definitions
 *
 * @note These structures and definitions are only supported by a device
 * if ::MBG_XFEATURE_TLV_API is set in the extended device features.
 *
 * @{ */


/**
 * @brief A data type used to hold a unique ID (UID) for a TLV transaction
 */
typedef uint32_t MBG_TLV_UID;

#define _mbg_swab_tlv_uid( _p )  \
  _mbg_swab32( _p )



/**
 * @brief A data type to hold one of the ::MBG_TLV_TYPES or ::MBG_TLV_FEAT_TYPES
 *
 * @see ::MBG_TLV_TYPES
 * @see ::MBG_TLV_FEAT_TYPES
 */
typedef uint32_t MBG_TLV_TYPE;

#define _mbg_swab_tlv_type( _p )  \
  _mbg_swab32( _p )



/**
 * @defgroup group_tlv_feat Meinberg TLV feature definitions
 *
 * @{ */


/**
 * @brief The maximum number of TLV feature types.
 *
 * Warning: Changing this number breaks API compatibility!
 *
 * @see ::MBG_TLV_FEAT_TYPES
 */
#define MAX_MBG_TLV_FEAT_TYPES    128  //### TODO Is this sufficient?


/**
 * @brief Enumeration of known TLV feature types.
 *
 * TLV feature types are used to specify the content of a binary TLV message
 * so that the receiver knows how to interpret the content.
 *
 * Used with ::MBG_TLV_INFO::supp_tlv_feat and ::MBG_TLV_DATA::type.  ### TODO
 *
 * @see ::MBG_TLV_FEAT_BUFFER
 * @see ::MBG_TLV_FEAT_TYPE_NAMES
 * @see ::MBG_TLV_TYPES
 * @see ::MBG_TLV_TYPE
 */
enum MBG_TLV_FEAT_TYPES
{
  /// Expects two TLV types in order:
  /// 1) ::MBG_TLV_TYPE_STR     => Firmware version as string
  /// 2) ::MBG_TLV_TYPE_FILE    => Firmware file as data blob
  MBG_TLV_FEAT_TYPE_FW_UPDATE,

  /// If announce message's total bytes are 0, it is a diagnostics file
  /// request. If its total bytes are not 0, TLV type ::MBG_TLV_TYPE_FILE
  /// is expected and it should contain a file as data blob.
  MBG_TLV_FEAT_TYPE_DIAG_FILE,

  /// Only used as action trigger on a remote site, expects no data.
  MBG_TLV_FEAT_TYPE_FW_ROLLBACK,

  /// Expects two TLV types in order:
  /// 1) ::MBG_TLV_TYPE_STR     => Full qualified path including filename on target system
  /// 2) ::MBG_TLV_TYPE_FILE    => File as data blob
  MBG_TLV_FEAT_TYPE_FILE_TRANSFER,

  /// 1) ::MBG_TLV_TYPE_STR     => Command line call as string
  MBG_TLV_FEAT_TYPE_EXEC_CMD,

  /// 1) ::MBG_TLV_TYPE_FILE    => Encrypted license file as data blob
  MBG_TLV_FEAT_TYPE_LICENSE_UPGRADE,

  /// 1) ::MBG_TLV_TYPE_BLOB    => ::MBG_LICENSE_LIMITS, see @ref group_license_limits
  MBG_TLV_FEAT_TYPE_LICENSE_LIMITS,

  /// 1) ::MBG_TLV_TYPE_BLOB    => ::MBG_LICENSE_PTPV2_IDX, see @ref group_license_limits
  MBG_TLV_FEAT_TYPE_LICENSE_PTPV2_IDX,

  /// 1) ::MBG_TLV_TYPE_BLOB    => ::MBG_LICENSE_NTP_IDX, see @ref group_license_limits
  MBG_TLV_FEAT_TYPE_LICENSE_NTP_IDX,

  /// Expects two TLV types in order:
  /// 1) ::MBG_TLV_TYPE_STR     => Full qualified path including filename on target system
  MBG_TLV_FEAT_TYPE_FILE_REQUEST,

  /// 1) ::MBG_TLV_TYPE_BLOB    => ::MBG_LICENSE_PTPV1_IDX, see @ref group_license_limits
  MBG_TLV_FEAT_TYPE_LICENSE_PTPV1_IDX,

  /// 1) ::MBG_TLV_TYPE_BLOB    => ::MBG_LICENSE_TIME_MONITOR_IDX, see @ref group_license_limits
  MBG_TLV_FEAT_TYPE_LICENSE_TIME_MONITOR_IDX,

  N_MBG_TLV_FEAT_TYPES
  // NOTE If new TLV feature types are appended here then an appropriate
  // name string has to be appended to ::MBG_TLV_FEAT_TYPE_NAMES, and care must
  // be taken that ::N_MBG_TLV_FEAT_TYPES doesn't exceed ::MAX_MBG_TLV_FEAT_TYPES.
};


/**
 * @brief Names of TLV API features
 *
 * Can be used to initialize a string array of ::N_MBG_TLV_FEAT_TYPES entries,
 * so the number of strings must correspond to ::N_MBG_TLV_FEAT_TYPES.
 *
 * @see ::MBG_TLV_FEAT_TYPES
 */
#define MBG_TLV_FEAT_TYPE_NAMES  \
{                                \
  "TLV Firmware Update",         \
  "TLV Diagnostics File",        \
  "TLV Firmware Rollback",       \
  "TLV File Transfer",           \
  "TLV Execute Command",         \
  "TLV License Upgrade",         \
  "TLV License Limits",          \
  "TLV License PTPV2",           \
  "TLV License NTP",             \
  "TLV File Request",            \
  "TLV License PTPV1 IDX",       \
  "TLV License Time Monitor"     \
}



/**
 * @brief Array size required to store up to ::MAX_MBG_TLV_FEAT_TYPES bits
 *
 * The number of bytes required to store up to ::MAX_MBG_TLV_FEAT_TYPES
 * feature bits in a byte array.
 */
#define MAX_MBG_TLV_FEAT_BYTES    ( MAX_MBG_TLV_FEAT_TYPES / 8 )


/**
 * @brief A structure used to store a bit mask of supported TLV context types.
 *
 * Bit masks for up to ::MAX_MBG_TLV_FEAT_TYPES totally can be stored,
 * but only ::N_MBG_TLV_FEAT_TYPES types are currently defined.
 * The ::_set_tlv_feat_bit macro should be used by the firmware
 * to set a bit mask in the buffer, and the ::check_tlv_feat_supp
 * function should be used to implement API calls which test if an
 * extended TLV context type is supported.
 *
 * @see ::_set_tlv_feat_bit
 * @see ::check_tlv_feat_supp
 */
typedef struct
{
  uint8_t b[MAX_MBG_TLV_FEAT_BYTES];

} MBG_TLV_FEAT_BUFFER;



/**
 * @brief Set a TLV context type bit in a ::MBG_TLV_FEAT_BUFFER
 *
 * Should be used by the firmware only to set one of the ::MBG_TLV_FEAT_TYPES
 * bits in an ::MBG_TLV_FEAT_BUFFER after power-up.
 *
 * @param[in]  _tlv_feat_type   One of the ::MBG_TLV_FEAT_TYPES
 * @param[in]  _tlv_feat_buffp  Pointer to a ::MBG_TLV_FEAT_BUFFER
 */
#define _set_tlv_feat_bit( _tlv_feat_type, _tlv_feat_buffp ) \
  _set_array_bit( _tlv_feat_type, (_tlv_feat_buffp)->b, MAX_MBG_TLV_FEAT_BYTES )


/** @} defgroup group_tlv_feat */



/**
 * @brief A structure used to query current TLV capabilities
 *
 * This is only supported by a device if the ::MBG_XFEATURE_TLV_API bit
 * is set in the extended device features.
 */
typedef struct
{
  uint32_t reserved;                  ///< Future use
  uint32_t flags;                     ///< Future use
  MBG_TLV_FEAT_BUFFER supp_tlv_feat;  ///< A byte array of supported TLV feature bits, see ::MBG_TLV_FEAT_TYPES

} MBG_TLV_INFO;

#define _mbg_swab_tlv_info( _p )   \
do                                 \
{                                  \
  _mbg_swab32( &(_p)->reserved );  \
  _mbg_swab32( &(_p)->flags );     \
} while ( 0 )



/**
 * @brief Enumeration of known TLV types
 *
 * Used with ::MBG_TLV_TYPE types, e.g. in ::MBG_TLV_HDR::tlv_type
 * or ::MBG_TLV_DATA::type.
 *
 * @see ::MBG_TLV_FEAT_TYPES
 * @see ::MBG_TLV_TYPE
 */
enum MBG_TLV_TYPES
{
  MBG_TLV_TYPE_STR,
  MBG_TLV_TYPE_FILE,
  MBG_TLV_TYPE_BLOB,        ///< In fact, a file is also a blob but
                            ///< give the child a different name to avoid confusion.
                            ///< Use this for getting/setting fixed structures!
  N_MBG_TLV_TYPES
};



/**
 * @brief General TLV data structure
 *
 * Structure containing common, additional data required to send
 * an announce message for following TLVs.
 */
typedef struct
{
  MBG_TLV_UID uid;       ///< Unique ID identifying following TLVs, 0 if empty/not set.
  MBG_TLV_TYPE type;     ///< One of the ::MBG_TLV_TYPES or ::MBG_TLV_FEAT_TYPES depending on the type of message.
  uint32_t total_bytes;  ///< Number of all bytes including header(s) that are related to a TLV block transaction.
  uint32_t reserved_1;   ///< Reserved for future use

} MBG_TLV_DATA;

#define _mbg_swab_tlv_data( _p )      \
do                                    \
{                                     \
  _mbg_swab_tlv_uid( &(_p)->uid );    \
  _mbg_swab_tlv_type( &(_p)->type );  \
  _mbg_swab32( &(_p)->total_bytes );  \
  _mbg_swab32( &(_p)->reserved_1 );   \
} while ( 0 )



/**
 * @brief Structure containing state information while reading TLV data.
 */
typedef struct
{
  MBG_TLV_DATA data;    ///< See ::MBG_TLV_DATA
  uint32_t read_bytes;  ///< Number of bytes read
  uint32_t reserved_1;  ///< Future use

} MBG_TLV_RCV_STATE;



/**
 * @brief A structure initiating a TLV transfer
 *
 * ::MBG_TLV_ANNOUNCE should be sent first, before starting a
 * TLV transfer, to inform the remote site about following TLVs.
 * Following sequence of TLVs is not fixed and implementation
 * dependent.
 */
typedef struct
{
  MBG_TLV_DATA data;    ///< See ::MBG_TLV_DATA
  uint32_t reserved_1;  ///< Future use
  uint32_t reserved_2;  ///< Future use

} MBG_TLV_ANNOUNCE;

#define _mbg_swab_tlv_announce( _p )  \
do                                    \
{                                     \
  _mbg_swab_tlv_data( &(_p)->data );  \
  _mbg_swab32( &(_p)->reserved_1 );   \
  _mbg_swab32( &(_p)->reserved_2 );   \
} while ( 0 )



#define MSG_TLV_MAX_VALUE_SIZE 480

/**
 * @brief TLV header structure containing information on current TLV transaction
 */
typedef struct
{
  MBG_TLV_UID uid;          ///< Unique source ID. See ::MBG_TLV_DATA::uid
  MBG_TLV_UID tlv_type;     ///< "Subtype" identifying current TLV, see ::MBG_TLV_TYPES
  uint32_t cur_bytes;       ///< Number of bytes in ::MBG_TLV::value
  uint32_t trans_bytes;     ///< Number of bytes transferred so far related to this TLV type.
  uint32_t total_bytes;     ///< Number of total bytes (size) of this TLV type without header.
                            ///< It is fixed and must not be changed during a TLV transaction.
  uint32_t reserved_1;      ///< Future use
  uint32_t reserved_2;      ///< Future use
  uint32_t reserved_3;      ///< Future use

} MBG_TLV_HDR;

#define _mbg_swab_tlv_header( _p )        \
do                                        \
{                                         \
  _mbg_swab_tlv_uid( &(_p)->uid );        \
  _mbg_swab_tlv_type( &(_p)->tlv_type );  \
  _mbg_swab32( &(_p)->cur_bytes );        \
  _mbg_swab32( &(_p)->trans_bytes );      \
  _mbg_swab32( &(_p)->total_bytes );      \
  _mbg_swab32( &(_p)->reserved_1 );       \
  _mbg_swab32( &(_p)->reserved_2 );       \
  _mbg_swab32( &(_p)->reserved_3 );       \
} while ( 0 )



/**
 * @brief TLV structure containing information on current TLV transaction and its current data.
 */
typedef struct
{
  MBG_TLV_HDR hdr;                          ///< See ::MBG_TLV_HDR
  uint8_t value[MSG_TLV_MAX_VALUE_SIZE];    ///< See ::MSG_TLV_MAX_VALUE_SIZE

} MBG_TLV;

#define _mbg_swab_tlv( _p )             \
do                                      \
{                                       \
  _mbg_swab_tlv_header( &(_p)->hdr );   \
} while ( 0 )

/** @} defgroup group_tlv_api */



/**
 * @defgroup group_gps_nav_data Definitions used with navigational data received from GPS satellites
 *
 * @note These structures and definitions are only supported by a device
 * if ::GPS_MODEL_IS_GPS is set in the @ref GPS_BUILTIN_FEATURE_MASKS
 *
 * @{ */


/**
 * @brief Ephemeris parameters of one specific satellite
 *
 * Needed to compute the position of a satellite at a given time with
 * high precision. Valid for an interval of 4 to 6 hours from start
 * of transmission.
 */
typedef struct
{
  CSUM csum;       ///<    checksum of the remaining bytes
  int16_t valid;   ///<    flag data are valid

  HEALTH health;   ///<    health indication of transmitting SV      [---]
  IOD IODC;        ///<    Issue Of Data, Clock
  IOD IODE2;       ///<    Issue of Data, Ephemeris (Subframe 2)
  IOD IODE3;       ///<    Issue of Data, Ephemeris (Subframe 3)
  T_GPS tt;        ///<    time of transmission
  T_GPS t0c;       ///<    Reference Time Clock                      [---]
  T_GPS t0e;       ///<    Reference Time Ephemeris                  [---]

  double sqrt_A;   ///<    Square Root of semi-major Axis        [sqrt(m)]
  double e;        ///<    Eccentricity                              [---]
  double M0;       ///< +- Mean Anomaly at Ref. Time                 [rad]
  double omega;    ///< +- Argument of Perigee                       [rad]
  double OMEGA0;   ///< +- Longit. of Asc. Node of orbit plane       [rad]
  double OMEGADOT; ///< +- Rate of Right Ascension               [rad/sec]
  double deltan;   ///< +- Mean Motion Diff. from computed value [rad/sec]
  double i0;       ///< +- Inclination Angle                         [rad]
  double idot;     ///< +- Rate of Inclination Angle             [rad/sec]
  double crc;      ///< +- Cosine Corr. Term to Orbit Radius           [m]
  double crs;      ///< +- Sine Corr. Term to Orbit Radius             [m]
  double cuc;      ///< +- Cosine Corr. Term to Arg. of Latitude     [rad]
  double cus;      ///< +- Sine Corr. Term to Arg. of Latitude       [rad]
  double cic;      ///< +- Cosine Corr. Term to Inclination Angle    [rad]
  double cis;      ///< +- Sine Corr. Term to Inclination Angle      [rad]

  double af0;      ///< +- Clock Correction Coefficient 0            [sec]
  double af1;      ///< +- Clock Correction Coefficient 1        [sec/sec]
  double af2;      ///< +- Clock Correction Coefficient 2      [sec/sec^2]
  double tgd;      ///< +- estimated group delay differential        [sec]

  uint16_t URA;    ///<    predicted User Range Accuracy

  uint8_t L2code;  ///<    code on L2 channel                         [---]
  uint8_t L2flag;  ///<    L2 P data flag                             [---]

} EPH;



/**
 * @brief Almanac parameters of one specific satellite
 *
 * A reduced precision set of parameters used to check if a satellite
 * is in view at a given time. Valid for an interval of more than 7 days
 * from start of transmission.
 */
typedef struct
{
  CSUM csum;       ///<    checksum of the remaining bytes
  int16_t valid;   ///<    flag data are valid

  HEALTH health;   ///<                                               [---]
  T_GPS t0a;       ///<    Reference Time Almanac                     [sec]

  double sqrt_A;   ///<    Square Root of semi-major Axis         [sqrt(m)]
  double e;        ///<    Eccentricity                               [---]

  double M0;       ///< +- Mean Anomaly at Ref. Time                  [rad]
  double omega;    ///< +- Argument of Perigee                        [rad]
  double OMEGA0;   ///< +- Longit. of Asc. Node of orbit plane        [rad]
  double OMEGADOT; ///< +- Rate of Right Ascension                [rad/sec]
  double deltai;   ///< +-                                            [rad]
  double af0;      ///< +- Clock Correction Coefficient 0             [sec]
  double af1;      ///< +- Clock Correction Coefficient 1         [sec/sec]

} ALM;



/**
 * @brief Summary of configuration and health data of all satellites
 */
typedef struct
{
  CSUM csum;                  ///< checksum of the remaining bytes
  int16_t valid;              ///< flag data are valid

  T_GPS tot_51;               ///< time of transmission, page 51
  T_GPS tot_63;               ///< time of transmission, page 63
  T_GPS t0a;                  ///< complete reference time almanac

  CFG cfg[N_SVNO_GPS];        ///< 4 bit SV configuration code from page 63
  HEALTH health[N_SVNO_GPS];  ///< 6 bit SV health codes from pages 51, 63

} CFGH;



/**
 * @brief GPS %UTC correction parameters
 *
 * %UTC correction parameters basically as sent by the GPS satellites.
 *
 * The csum field is only used by the card's firmware to check the
 * consistency of the structure in non-volatile memory.
 *
 * The field labeled valid indicates if the parameter set is valid, i.e.
 * if it contains data received from the satellites.
 *
 * t0t, A0 and A1 contain fractional correction parameters for the current
 * GPS-%UTC time offset in addition to the whole seconds. This is evaluated
 * by the receivers' firmware to convert GPS time to %UTC time.
 *
 * The delta_tls field contains the current full seconds offset between
 * GPS time and %UTC, which corresponds to the number of leap seconds inserted
 * into the %UTC time scale since GPS was put into operation in January 1980.
 *
 * delta_tlfs holds the number of "future" leap seconds, i.e. the %UTC offset
 * after the next leap second event defined by WNlsf and DNt.
 *
 * The fields WNlsf and DNt specify the GPS week number and the day number
 * in that week for the end of which a leap second has been scheduled.
 *
 * @note: The satellites transmit WNlsf only as a signed 8 bit value, so it
 * can only define a point in time which is +/- 127 weeks off the current time.
 * The firmware tries to expand this based on the current week number, but
 * the result is ambiguous if the leap second occurs or occurred more
 * than 127 weeks in the future or past.
 *
 * So the leap second date should <b>only</b> be evaluated and displayed
 * in a user interface if the fields delta_tls and delta_tlsf have
 * different values, in which case there is indeed a leap second announcement
 * inside the +/- 127 week range.
 */
typedef struct
{
  CSUM csum;          ///<  Checksum of the remaining bytes
  int16_t valid;      ///<  Flag indicating %UTC parameters are valid

  T_GPS t0t;          ///<  Reference Time %UTC Parameters [wn|sec]
  double A0;          ///<  +- Clock Correction Coefficient 0 [sec]
  double A1;          ///<  +- Clock Correction Coefficient 1 [sec/sec]

  uint16_t WNlsf;     ///<  Week number of nearest leap second
  int16_t DNt;        ///<  The day number at the end of which a leap second occurs
  int8_t delta_tls;   ///<  Current %UTC offset to GPS system time [sec]
  int8_t delta_tlsf;  ///<  Future %UTC offset to GPS system time after next leap second transition [sec]

} UTC;

#define _mbg_swab_utc_parm( _p )  \
do                                \
{                                 \
  _mbg_swab_csum( &(_p)->csum );  \
  _mbg_swab16( &(_p)->valid );    \
  _mbg_swab_t_gps( &(_p)->t0t );  \
  _mbg_swab_double( &(_p)->A0 );  \
  _mbg_swab_double( &(_p)->A1 );  \
  _mbg_swab16( &(_p)->WNlsf );    \
  _mbg_swab16( &(_p)->DNt );      \
} while ( 0 )



/**
 * @brief Ionospheric correction parameters
 */
typedef struct
{
  CSUM csum;       ///<    checksum of the remaining bytes
  int16_t valid;   ///<    flag data are valid

  double alpha_0;  ///<    Ionosph. Corr. Coeff. Alpha 0              [sec]
  double alpha_1;  ///<    Ionosph. Corr. Coeff. Alpha 1          [sec/deg]
  double alpha_2;  ///<    Ionosph. Corr. Coeff. Alpha 2        [sec/deg^2]
  double alpha_3;  ///<    Ionosph. Corr. Coeff. Alpha 3        [sec/deg^3]

  double beta_0;   ///<    Ionosph. Corr. Coeff. Beta 0               [sec]
  double beta_1;   ///<    Ionosph. Corr. Coeff. Beta 1           [sec/deg]
  double beta_2;   ///<    Ionosph. Corr. Coeff. Beta 2         [sec/deg^2]
  double beta_3;   ///<    Ionosph. Corr. Coeff. Beta 3         [sec/deg^3]

} IONO;



/**
 * @brief GPS ASCII message
 */
typedef struct
{
  CSUM csum;       ///< checksum of the remaining bytes */
  int16_t valid;   ///< flag data are valid
  char s[23];      ///< 22 chars GPS ASCII message plus trailing zero

} ASCII_MSG;

/** @} defgroup group_gps_nav_data */



enum GPS_PLATFORMS
{
  GPS_PLATFORM_PORTABLE,
  GPS_PLATFORM_FIXED,
  GPS_PLATFORM_STATIONARY,
  GPS_PLATFORM_PEDESTRIAN,
  GPS_PLATFORM_AUTOMOTIVE,
  GPS_PLATFORM_SEA,
  GPS_PLATFORM_AIRBORNE_1G,
  GPS_PLATFORM_AIRBORNE_2G,
  GPS_PLATFORM_AIRBORNE_4G,
  N_GPS_PLATFORMS
};


#define GPS_PLATFORM_STRS \
{                         \
  "Portable    ",         \
  "Fixed       ",         \
  "Stationary  ",         \
  "Pedestrian  ",         \
  "Automotive  ",         \
  "Sea         ",         \
  "Airborne <1G",         \
  "Airborne <2G",         \
  "Airborne <4G"          \
}



enum TIME_MODES
{
  TIME_MODE_DISABLED,
  TIME_MODE_SURVEY_IN,
  TIME_MODE_FIXED,
  N_TIME_MODES
};



typedef struct
{
  uint32_t time_mode;
  uint32_t survey_in_duration;
  uint32_t survey_in_pos_var;
  int32_t  fixedPosX;         // cm
  int32_t  fixedPosY;         // cm
  int32_t  fixedPosZ;         // cm
  uint32_t fixedPosVar;       // cm
  uint32_t flags;             // currently 0
  uint32_t reserved;          // currently 0

} NAV_TIME_MODE_SETTINGS;



/**
 * Navigation Engine settings to set configuration
 * parameters of a dynamic platform model.
 */
typedef struct
{
  uint8_t   dynamic_platform;
  uint8_t   fix_mode;
  int8_t    min_elevation;
  uint8_t   static_hold_threshold;
  int32_t   fixed_altitude;
  uint32_t  fixed_altitude_variance;
  uint32_t  flags;          // currently 0
  uint32_t  reserved;       // currently 0
  NAV_TIME_MODE_SETTINGS nav_time_mode_settings;

} NAV_ENGINE_SETTINGS;



/**
 * @defgroup group_led_api Meinberg TLV API definitions
 *
 * @note These structures and definitions are only supported by a device
 * if ::MBG_XFEATURE_LED_API is set in the extended device features.
 *
 * @{ */


/**
 * @brief General LED info to be read from a device
 *
 * Used to query from a device how many LEDs are supported
 * by the device, then index 0..::MBG_LED_LIMITS::num_leds-1
 * ::MBG_LED_INFO_IDX or ::MBG_LED_SETTINGS_IDX structures
 * can be read from or written to the device.
 *
 * @see ::MBG_LED_SETTINGS_IDX
 * @see ::MBG_LED_INFO_IDX
 */
typedef struct
{
  uint8_t num_leds;     ///< Number of supported LEDs, see ::MBG_LED_SETTINGS_IDX::idx and ::MBG_LED_INFO_IDX::idx
  uint8_t reserved_0;   ///< Currently reserved, unused, always 0
  uint16_t reserved_1;  ///< Currently reserved, unused, always 0
  uint32_t reserved_2;  ///< Currently reserved, unused, always 0

} MBG_LED_LIMITS;

#define _mbg_swab_mbg_led_limits( _p ) \
do                                     \
{                                      \
  _mbg_swab8( &(_p)->num_leds );       \
  _mbg_swab8( &(_p)->reserved_0 );     \
  _mbg_swab16( &(_p)->reserved_1 );    \
  _mbg_swab32( &(_p)->reserved_2 );    \
} while ( 0 )



/**
 * @brief Possible modes of LEDs
 *
 * Used with ::MBG_LED_SETTINGS::mode
 *
 * @see ::MBG_LED_MODE_MASKS
 */
enum MBG_LED_MODES
{
  MBG_LED_MODE_OFF,
  MBG_LED_MODE_ON,
  MBG_LED_MODE_FLASH,
  MBG_LED_MODE_FLASH_5S,
  N_MBG_LED_MODES
};



/**
 * @brief Bit masks associated with LED modes
 *
 * Used with ::MBG_LED_INFO::supp_modes
 *
 * @see ::MBG_LED_MODES
 */
enum MBG_LED_MODE_MASKS
{
  MBG_LED_MODE_MASK_OFF       = ( 1UL << MBG_LED_MODE_OFF ),      ///< see ::MBG_LED_MODE_OFF
  MBG_LED_MODE_MASK_ON        = ( 1UL << MBG_LED_MODE_ON ),       ///< see ::MBG_LED_MODE_ON
  MBG_LED_MODE_MASK_FLASH     = ( 1UL << MBG_LED_MODE_FLASH ),    ///< see ::MBG_LED_MODE_FLASH
  MBG_LED_MODE_MASK_FLASH_5S  = ( 1UL << MBG_LED_MODE_FLASH_5S )  ///< see ::MBG_LED_MODE_FLASH_5S
};


/**
 * @brief Names of LED modes
 *
 * Can be used to initialize a string array of ::N_MBG_LED_MODES entries,
 * so the number of strings must correspond to ::N_MBG_LED_MODES.
 *
 * @see ::MBG_LED_MODES
 * @see ::MBG_LED_MODE_MASKS
 */
#define MBG_LED_MODE_STRS   \
{                           \
  "Off",                    \
  "On",                     \
  "Flash",                  \
  "Flash 5s"                \
}



/**
 * @brief Possible colors of LEDs
 *
 * Used with ::MBG_LED_SETTINGS::color
 *
 * @see ::MBG_LED_COLOR_MASKS
 */
enum MBG_LED_COLORS
{
  MBG_LED_COLOR_GREEN,
  MBG_LED_COLOR_RED,
  MBG_LED_COLOR_YELLOW,
  MBG_LED_COLOR_BLUE,
  N_MBG_LED_COLORS
};



/**
 * @brief Bit masks of possible LED colors
 *
 * Used with ::MBG_LED_INFO::supp_colors
 *
 * @see ::MBG_LED_COLORS
 */
enum MBG_LED_COLOR_MASKS
{
  MBG_LED_COLOR_MASK_GREEN  = ( 1UL <<  MBG_LED_COLOR_GREEN ),   ///< see ::MBG_LED_COLOR_GREEN
  MBG_LED_COLOR_MASK_RED    = ( 1UL <<  MBG_LED_COLOR_RED ),     ///< see ::MBG_LED_COLOR_RED
  MBG_LED_COLOR_MASK_YELLOW = ( 1UL <<  MBG_LED_COLOR_YELLOW ),  ///< see ::MBG_LED_COLOR_YELLOW
  MBG_LED_COLOR_MASK_BLUE   = ( 1UL <<  MBG_LED_COLOR_BLUE )     ///< see ::MBG_LED_COLOR_BLUE
};



/**
 * @brief Names of LED colors
 *
 * Can be used to initialize a string array of ::N_MBG_LED_COLORS entries,
 * so the number of strings must correspond to ::N_MBG_LED_COLORS.
 *
 * @see ::MBG_LED_COLORS
 * @see ::MBG_LED_COLOR_MASKS
 */
#define MBG_LED_COLOR_STRS  \
{                           \
  "Green",                  \
  "Red",                    \
  "Yellow",                 \
  "Blue"                    \
}



/**
 * @brief Configuration settings for a single LED
 *
 * @see ::MBG_LED_SETTINGS_IDX
 */
typedef struct
{
  uint8_t mode;               ///< LED mode, see ::MBG_LED_MODES
  uint8_t color;              ///< LED color, see ::MBG_LED_COLORS
  uint16_t reserved;          ///< Currently reserved, unused, always 0

} MBG_LED_SETTINGS;

#define _mbg_swab_mbg_led_settings( _p ) \
do                                       \
{                                        \
  _mbg_swab8( &(_p)->mode );             \
  _mbg_swab8( &(_p)->color );            \
  _mbg_swab16( &(_p)->reserved );        \
} while ( 0 )



/**
 * @brief Configuration settings for a single LED, plus index
 *
 * @see ::MBG_LED_SETTINGS
 * @see ::MBG_LED_LIMITS
 */
typedef struct
{
  uint16_t idx;               ///< 0..::MBG_LED_LIMITS::num_leds-1
  MBG_LED_SETTINGS settings;  ///< LED settings

} MBG_LED_SETTINGS_IDX;

#define _mbg_swab_mbg_led_settings_idx( _p )     \
do                                               \
{                                                \
  _mbg_swab16( &(_p)->idx );                     \
  _mbg_swab_mbg_led_settings( &(_p)->settings ); \
} while ( 0 )



/**
 * @brief Current settings and general capabilities of an LED
 *
 * This structure should be read from the device to retrieve the
 * current settings of an LED plus its capabilities, e.g. the
 * supported modes, colors, etc.
 *
 * @see ::MBG_LED_INFO_IDX
 */
typedef struct
{
  MBG_LED_SETTINGS settings;  ///< Current LED settings
  uint32_t supp_modes;        ///< Supported modes, see ::MBG_LED_MODE_MASKS
  uint32_t supp_colors;       ///< Supported colors, see ::MBG_LED_COLOR_MASKS
  uint32_t reserved;          ///< Currently reserved, unused, always 0
  uint32_t flags;             ///< Currently reserved, unused, always 0

} MBG_LED_INFO;

#define _mbg_swab_mbg_led_info( _p )             \
do                                               \
{                                                \
  _mbg_swab_mbg_led_settings( &(_p)->settings ); \
  _mbg_swab32( &(_p)->supp_modes );              \
  _mbg_swab32( &(_p)->supp_colors );             \
  _mbg_swab32( &(_p)->reserved );                \
  _mbg_swab32( &(_p)->flags );                   \
} while ( 0 )



/**
 * @brief Current settings and general capabilities of an LED, plus index
 *
 * @see ::MBG_LED_INFO
 * @see ::MBG_LED_LIMITS
 */
typedef struct
{
  uint16_t idx;               ///< 0..::MBG_LED_LIMITS::num_leds-1
  MBG_LED_INFO info;          ///< LED info

} MBG_LED_INFO_IDX;

#define _mbg_swab_mbg_led_info_idx( _p ) \
do                                       \
{                                        \
  _mbg_swab16( &(_p)->idx );             \
  _mbg_swab_mbg_led_info( &(_p)->info ); \
} while ( 0 )

/** @} defgroup group_led_api */



/**
 * @defgroup group_lne_api Definitions specific to LNE devices
 *
 * @note These structures and definitions are only supported by a device
 * if ::MBG_XFEATURE_LNE_API is set in the extended device features.
 *
 * @{ */


/**
 * @brief General info to be read from an LNE device
 *
 * Used to query from a device e.g. how many LNE ports are provided
 * by the device, then index 0..::MBG_LNE_LIMITS::num_ports-1
 * ::MBG_LNE_PORT_INFO_IDX or ::MBG_LNE_PORT_SETTINGS_IDX structures
 * can be read from or written to the device.
 *
 * @see ::MBG_LNE_PORT_SETTINGS_IDX
 * @see ::MBG_LNE_PORT_INFO_IDX
 */
typedef struct
{
  uint8_t num_ports;    ///< Number of supported ports, see ::MBG_LNE_PORT_SETTINGS_IDX::idx and ::MBG_LNE_PORT_INFO_IDX::idx
  uint8_t reserved_0;   ///< Currently reserved, unused, always 0
  uint16_t reserved_1;  ///< Currently reserved, unused, always 0
  uint32_t features;    // ### TODO Mask of supported features, see ::MBG_LNE_FEAT_MASKS
                        ///< Currently reserved, unused, always 0
  uint32_t reserved_2;  ///< Currently reserved, unused, always 0

} MBG_LNE_LIMITS;

#define _mbg_swab_mbg_lne_limits( _p ) \
do                                     \
{                                      \
  _mbg_swab8( &(_p)->num_ports );      \
  _mbg_swab8( &(_p)->reserved_0 );     \
  _mbg_swab16( &(_p)->reserved_1 );    \
  _mbg_swab32( &(_p)->features );      \
  _mbg_swab32( &(_p)->reserved_2 );    \
} while ( 0 )



#if 0  //### TODO //#################

/**
 * @brief LNE feature bits
 *
 * Used to define ::MBG_LNE_FEAT_MASKS
 *
 * @see ::MBG_LNE_FEAT_MASKS
 */
enum MBG_LNE_FEAT_BITS
{
  MBG_LNE_FEAT_BIT_SWITCH_PWR,  ///< Power switching off all LNE ports at once supported, see ::MBG_LNE_PWR_STATE
  N_MBG_LNE_FEAT_BITS
};



/**
 * @brief LNE feature bit masks
 *
 * Used with ::MBG_LNE_LIMITS::features
 *
 * @see ::MBG_LNE_FEAT_BITS
 */
enum MBG_LNE_FEAT_MASKS
{
  MBG_LNE_FEAT_MASK_SWITCH_PWR = ( 1UL << MBG_LNE_FEAT_BIT_SWITCH_PWR )   ///< see ::MBG_LNE_FEAT_BIT_SWITCH_PWR
};

#endif



/**
 * @brief Configuration settings for a single LNE port
 *
 * @see ::MBG_LNE_PORT_SETTINGS_IDX
 */
typedef struct
{
  uint32_t reserved_0;         ///< currently reserved, unused, always 0
  uint32_t reserved_1;         ///< currently reserved, unused, always 0
  uint32_t reserved_2;         ///< currently reserved, unused, always 0
  uint32_t flags;              ///< currently reserved, unused, always 0

} MBG_LNE_PORT_SETTINGS;

#define _mbg_swab_mbg_lne_port_settings( _p ) \
do                                            \
{                                             \
  _mbg_swab32( &(_p)->reserved_0 );           \
  _mbg_swab32( &(_p)->reserved_1 );           \
  _mbg_swab32( &(_p)->reserved_2 );           \
  _mbg_swab32( &(_p)->flags );                \
} while ( 0 )



/**
 * @brief Configuration settings for a single LNE port, plus index
 *
 * @see ::MBG_LNE_PORT_SETTINGS
 * @see ::MBG_LNE_LIMITS
 */
typedef struct
{
  uint16_t idx;                    ///< 0..::MBG_LNE_LIMITS::num_ports-1
  MBG_LNE_PORT_SETTINGS settings;  ///< LNE settings

} MBG_LNE_PORT_SETTINGS_IDX;

#define _mbg_swab_mbg_lne_port_settings_idx( _p )     \
do                                                    \
{                                                     \
  _mbg_swab16( &(_p)->idx );                          \
  _mbg_swab_mbg_lne_port_settings( &(_p)->settings ); \
} while ( 0 )



/**
 * @brief Current settings and general capabilities of an LNE port
 *
 * This structure should be read from the device to retrieve the
 * current settings of an LNE port plus its capabilities, ### e.g. the
 * supported modes, colors, etc.
 *
 * @see ::MBG_LNE_PORT_INFO_IDX
 */
typedef struct
{
  MBG_LNE_PORT_SETTINGS settings;  ///< Current LNE port settings
  MBG_MAC_ADDR mac_addr;           ///< The MAC address assigned to this port
  uint32_t reserved_0;             ///< currently reserved, unused, always 0
  uint32_t reserved_1;             ///< currently reserved, unused, always 0
  uint32_t reserved_2;             ///< currently reserved, unused, always 0
  uint32_t flags;                  ///< see ::LNE_PORT_FLAG_MASKS

} MBG_LNE_PORT_INFO;

#define _mbg_swab_mbg_lne_port_info( _p )             \
do                                                    \
{                                                     \
  _mbg_swab_mbg_lne_port_settings( &(_p)->settings ); \
  _mbg_swab_mbg_mac_addr( &(_p)->mac_addr );          \
  _mbg_swab32( &(_p)->reserved_0 );                   \
  _mbg_swab32( &(_p)->reserved_1 );                   \
  _mbg_swab32( &(_p)->reserved_2 );                   \
  _mbg_swab32( &(_p)->flags );                        \
} while ( 0 )



/**
 * @brief Current settings and general capabilities of an LNE port, plus index
 *
 * @see ::MBG_LNE_PORT_INFO
 * @see ::MBG_LNE_LIMITS
 */
typedef struct
{
  uint16_t idx;                    ///< 0..::MBG_LED_LIMITS::num_leds-1
  MBG_LNE_PORT_INFO info;          ///< LNE port info

} MBG_LNE_PORT_INFO_IDX;

#define _mbg_swab_mbg_lne_port_info_idx( _p ) \
do                                            \
{                                             \
  _mbg_swab16( &(_p)->idx );                  \
  _mbg_swab_mbg_lne_port_info( &(_p)->info ); \
} while ( 0 )



/**
 * @brief LNE port flag bits
 *
 * Used to define ::LNE_PORT_FLAG_MASKS
 *
 * @see ::LNE_PORT_FLAG_MASKS
 */
enum LNE_PORT_FLAG_BITS
{
  LNE_PORT_FLAG_BIT_IS_SFP,
  N_LNE_PORT_FLAG_BITS
};



/**
 * @brief LNE port flag bit masks
 *
 * Used with ::MBG_LNE_PORT_INFO::flags
 *
 * @see ::LNE_PORT_FLAG_BITS
 */
enum LNE_PORT_FLAG_MASKS
{
  LNE_PORT_FLAG_MASK_IS_SFP = ( 1UL << LNE_PORT_FLAG_BIT_IS_SFP )   ///< see ::LNE_PORT_FLAG_BIT_IS_SFP
};


/** @} defgroup group_lne_api */



/**
 * @defgroup group_pwr_ctl_api Definitions for power control API
 *
 * @note These structures and definitions are only supported by a device
 * if ::MBG_XFEATURE_PWR_CTL_API is set in the extended device features.
 *
 * @{ */


/**
 * @brief Device power states
 *
 * Used with ::MBG_PWR_CTL::state.
 */
enum MBG_PWR_STATES
{
  MBG_PWR_STATE_OFF,
  MBG_PWR_STATE_ON,
  N_MBG_PWR_STATES
};



/**
 * @brief Device power control
 *
 * Used to change or retrieve a device's power state
 */
typedef struct
{
  uint8_t state;        ///< see ::MBG_PWR_STATES
  uint8_t reserved_0;   ///< Currently reserved, unused, always 0
  uint16_t reserved_1;  ///< Currently reserved, unused, always 0

} MBG_PWR_CTL;

#define _mbg_swab_mbg_pwr_ctl( _p ) \
do                                  \
{                                   \
  _mbg_swab8( &(_p)->state );       \
  _mbg_swab8( &(_p)->reserved_0 );  \
  _mbg_swab16( &(_p)->reserved_1 ); \
} while ( 0 )

/** @} defgroup group_pwr_ctl_api */




/**
 * @defgroup group_ext_sys_info Extended system information
 *
 * @note This structure and its definitions are only supported by a device
 * if ::MBG_XFEATURE_EXT_SYS_INFO is set in the extended device features.
 *
 * @{ */


/**
 * @brief Bits used to define ::MBG_EXT_SYS_INFO_MSKS
 *
 * @see ::MBG_EXT_SYS_INFO_MSKS
 */
enum MBG_EXT_SYS_INFO_BITS
{
  MBG_EXT_SYS_INFO_BIT_SW_REV,
  MBG_EXT_SYS_INFO_BIT_HW_REV,
  MBG_EXT_SYS_INFO_BIT_OS_REV,
  MBG_EXT_SYS_INFO_BIT_FPGA_REV,
  MBG_EXT_SYS_INFO_BIT_CORE_MOD_REV,
  N_MBG_EXT_SYS_INFO_BITS
};



/**
 * @brief Bit masks of supported revision numbers
 *
 * Used with ::MBG_EXT_SYS_INFO::supp_members
 *
 * @see ::MBG_EXT_SYS_INFO_BITS
 */
enum MBG_EXT_SYS_INFO_MSKS
{
  MBG_EXT_SYS_INFO_MSK_SW_REV         = ( 1UL << MBG_EXT_SYS_INFO_BIT_SW_REV ),           ///< see ::MBG_EXT_SYS_INFO_BIT_SW_REV
  MBG_EXT_SYS_INFO_MSK_HW_REV         = ( 1UL << MBG_EXT_SYS_INFO_BIT_HW_REV ),           ///< see ::MBG_EXT_SYS_INFO_BIT_HW_REV
  MBG_EXT_SYS_INFO_MSK_OS_REV         = ( 1UL << MBG_EXT_SYS_INFO_BIT_OS_REV ),           ///< see ::MBG_EXT_SYS_INFO_BIT_OS_REV
  MBG_EXT_SYS_INFO_MSK_FPGA_REV       = ( 1UL << MBG_EXT_SYS_INFO_BIT_FPGA_REV ),         ///< see ::MBG_EXT_SYS_INFO_BIT_FPGA_REV
  MBG_EXT_SYS_INFO_MSK_CORE_MOD_REV   = ( 1UL << MBG_EXT_SYS_INFO_BIT_CORE_MOD_REV )      ///< see ::MBG_EXT_SYS_INFO_BIT_CORE_MOD_REV
};


enum MBG_EXT_SYS_INFO_PROC_TYPES
{
  MBG_EXT_SYS_INFO_PROC_TYPE_NONE,
  MBG_EXT_SYS_INFO_PROC_TYPE_CORTEX_A9,
  MBG_EXT_SYS_INFO_PROC_TYPE_CORTEX_SAM3u,
  MBG_EXT_SYS_INFO_PROC_TYPE_CORTEX_SAM3s,
  MBG_EXT_SYS_INFO_PROC_TYPE_CORTEX_STM32F4,
  N_MBG_EXT_SYS_INFO_PROC_TYPES
};

#define MBG_EXT_SYS_INFO_PROC_STRS  \
{                                   \
  "None",                           \
  "Cortex A9",                      \
  "Cortex SAM3u",                   \
  "Cortex SAM3s",                   \
  "Cortex STM32F4"                  \
}

enum MBG_EXT_SYS_INFO_FPGA_TYPES
{
  MBG_EXT_SYS_INFO_FPGA_TYPE_NONE,
  MBG_EXT_SYS_INFO_FPGA_TYPE_CYCLONE5_SOC,      ///< System on chip
  MBG_EXT_SYS_INFO_FPGA_TYPE_CYCLONE5,          ///< Stand alone FPGA
  MBG_EXT_SYS_INFO_FPGA_TYPE_CYCLONE4GX15,
  MBG_EXT_SYS_INFO_FPGA_TYPE_CYLCONE4CE22,
  N_MBG_EXT_SYS_INFO_FPGA_TYPES
};

#define MBG_EXT_SYS_INFO_FPGA_STRS  \
{                                   \
  "None",                           \
  "Cyclone5 SoC",                   \
  "Cyclone5",                       \
  "Cyclone4GX15",                   \
  "Cyclone4CE22"                    \
}

enum MBG_EXT_SYS_INFO_CORE_MOD_TYPES
{
  MBG_EXT_SYS_INFO_CORE_MOD_TYPE_NONE,
  MBG_EXT_SYS_INFO_CORE_MOD_TYPE_UBX_LEA_M8F,        ///< u-blox GNSS module without Galileo support
  MBG_EXT_SYS_INFO_CORE_MOD_TYPE_UBX_LEA_M8T,        ///< u-blox GNSS module with Galileo support
  N_MBG_EXT_SYS_INFO_CORE_MOD_TYPES
};

#define MBG_EXT_SYS_INFO_CORE_MOD_STRS  \
{                                       \
  "None",                               \
  "u-blox LEA-M8F",                     \
  "u-blox LEA-M8T"                      \
}

typedef struct
{
  uint32_t supp_members;    ///< ::MBG_EXT_SYS_INFO_MSKS

  uint32_t sw_rev;
  uint32_t hw_rev;
  uint32_t os_rev;
  uint32_t fpga_rev;

  uint16_t proc_type;       ///< See ::MBG_EXT_SYS_INFO_PROC_TYPES
  uint16_t fpga_type;       ///< See ::MBG_EXT_SYS_INFO_FPGA_TYPES
  uint16_t core_mod_type;   ///< See ::MBG_EXT_SYS_INFO_CORE_MOD_TYPES
  uint16_t reserved;

  uint32_t core_mod_rev;

  /* Reserved for future use, currently 0 */
  uint32_t reserved_rev_3;
  uint32_t reserved_rev_4;
  uint32_t reserved_rev_5;
  uint32_t reserved_rev_6;
  uint32_t reserved_rev_7;
  uint32_t reserved_rev_8;
  uint32_t reserved_rev_9;
  uint32_t reserved_rev_10;
  uint32_t reserved_rev_11;

} MBG_EXT_SYS_INFO;

#define _mbg_swab_ext_sys_info( _p )    \
do                                      \
{                                       \
  _mbg_swab32( &(_p)->supp_members );   \
  _mbg_swab32( &(_p)->sw_rev );         \
  _mbg_swab32( &(_p)->hw_rev );         \
  _mbg_swab32( &(_p)->os_rev );         \
  _mbg_swab32( &(_p)->fpga_rev );       \
  _mbg_swab16( &(_p)->proc_type );      \
  _mbg_swab16( &(_p)->fpga_type );      \
  _mbg_swab16( &(_p)->core_mod_type );  \
  _mbg_swab16( &(_p)->reserved );       \
  _mbg_swab32( &(_p)->core_mod_rev );   \
} while ( 0 )


#define _mbg_encode_revision( _major, _minor, _patch ) \
  ( ( (_major) << 24) | ( (_minor) << 16 ) | (_patch) )


#define _mbg_decode_revision( _rev, _major, _minor, _patch ) \
{                                                            \
  (_major) = ( (_rev) >> 24 ) & 0xff;                        \
  (_minor) = ( (_rev) >> 16 ) & 0xff;                        \
  (_patch) = (_rev) & 0xffff;                                \
}


/** @} defgroup group_ext_sys_info */


/**
 * @defgroup group_license_limits License information
 *
 * @note This structure and its definitions are only supported by a device
 * if ::MBG_XFEATURE_LICENSE_LIMITS is set in the extended device features.
 *
 * @{ */


#define MBG_MAX_LICENSES 32


/**
 * @brief General license information to be read from a device
 *
 * Used to query from a device how many and which different license types
 * are supported. If a special type is supported (licenses[MBG_LICENSE_BASE_TYPES] > 0), its
 * license specific information can be queried from 0..licenses[MBG_LICENSE_BASE_TYPES]-1 via
 * its license specific [...]_IDX structures and TLV API command codes.
 * See ::MBG_XFEATURE_TLV_API and ::MBG_TLV_FEAT_TYPES.
 */
typedef struct
{
  uint8_t licenses[MBG_MAX_LICENSES];       ///< To get the number of supported licenses
                                            ///< of a specific type you need to access the array
                                            ///< with the specififc license index defined at ::MBG_LICENSE_BASE_TYPES.
} MBG_LICENSE_LIMITS;


enum MBG_LICENSE_BASE_TYPES
{
  MBG_LICENSE_BASE_TYPE_PTPV2,
  MBG_LICENSE_BASE_TYPE_NTP,
  MBG_LICENSE_BASE_TYPE_PTPV1,
  MBG_LICENSE_BASE_TYPE_TIME_MONITOR,
  N_MBG_LICENSE_BASE_TYPES
};


/**
 * @brief Bits used to define ::MBG_LICENSE_BASE_MSKS
 *
 * @see ::MBG_LICENSE_BASE_MSKS
 */
enum MBG_LICENSE_BASE_FLAGS
{
  MBG_LICENSE_BASE_FLAG_SUPP_UPGRADE,        ///< License supports upgrading / modifying
  N_MBG_LICENSE_BASE_FLAGS
};


/**
 * @brief Bit masks of common supported base license flags
 *
 * Used with ::MBG_LICENSE_BASE::supp_flags
 *
 * @see ::MBG_LICENSE_BASE_FLAGS
 */
enum MBG_LICENSE_BASE_MSKS
{
  MBG_LICENSE_BASE_MSK_SUPP_UPGRADE = ( 1UL << MBG_LICENSE_BASE_FLAG_SUPP_UPGRADE )     ///< See ::MBG_LICENSE_BASE_FLAG_SUPP_UPGRADE
};


/**
 * @brief Common license information
 *
 * Should be part of each individual license type.
 */
typedef struct
{
  uint8_t type;                 ///< See ::MBG_LICENSE_BASE_TYPES
  uint8_t reserved_1;           ///< Reserved for future use, currently 0
  uint16_t reserved_2;          ///< Reserved for future use, currently 0
  uint32_t supp_flags;          ///< See ::MBG_LICENSE_BASE_MSKS
  uint32_t reserved_3;          ///< Reserved for future use, currently 0
  uint32_t reserved_4;          ///< Reserved for future use, currently 0

} MBG_LICENSE_BASE;

#define _mbg_swab_license_base( _p )  \
do                                    \
{                                     \
  _mbg_swab32( &(_p)->supp_flags );   \
} while ( 0 )


/**
 * @brief Bits used to define ::MBG_LICENSE_PTPV2_MEMBER_MSKS
 *
 * @see ::MBG_LICENSE_PTPV2_MEMBER_MSKS
 */
enum MBG_LICENSE_PTPV2_MEMBERS
{
  MBG_LICENSE_PTPV2_MEMBER_MAX_UCLIENTS,
  MBG_LICENSE_PTPV2_MEMBER_MAX_MTRANS,
  N_MBG_LICENSE_PTPV2_MEMBERS
};


/**
 * @brief Bit masks of PTPV2 license specific members
 *
 * Used with ::MBG_LICENSE_PTPV2::supp_members
 *
 * @see ::MBG_LICENSE_PTPV2_MEMBERS
 */
enum MBG_LICENSE_PTPV2_MEMBER_MSKS
{
  MBG_LICENSE_PTPV2_MEMBER_MSK_MAX_UCLIENTS = ( 1UL << MBG_LICENSE_PTPV2_MEMBER_MAX_UCLIENTS ),  ///< See ::MBG_LICENSE_PTPV2_MEMBER_MAX_UCLIENTS
  MBG_LICENSE_PTPV2_MEMBER_MSK_MAX_MTRANS   = ( 1UL << MBG_LICENSE_PTPV2_MEMBER_MAX_MTRANS )     ///< See ::MBG_LICENSE_PTPV2_MEMBER_MAX_MTRANS
};


/**
 * @brief PTPV2 specific license information
 *
 */
typedef struct
{
  MBG_LICENSE_BASE base;        ///< See ::MBG_LICENSE_BASE
  uint32_t supp_members;        ///< See ::MBG_LICENSE_PTPV2_MEMBER_MSKS
  uint32_t reserved_1;          ///< Reserved for future use, currently 0
  uint16_t max_uclients;        ///< Maximal number of supported unicast clients.
  uint16_t reserved_2;          ///< Reserved for future use, currently 0
  uint32_t max_mtrans;          ///< Maximal number of supported multicast transactions per second.
  uint32_t reserved_3;          ///< Reserved for future use, currently 0
  uint32_t reserved_4;          ///< Reserved for future use, currently 0
  uint32_t reserved_5;          ///< Reserved for future use, currently 0
  uint32_t reserved_6;          ///< Reserved for future use, currently 0

} MBG_LICENSE_PTPV2;

#define _mbg_swab_license_ptpv2( _p )     \
do                                        \
{                                         \
  _mbg_swab_license_base( &(_p)->base );  \
  _mbg_swab32( &(_p)->supp_members );     \
  _mbg_swab16( &(_p)->max_uclients );     \
  _mbg_swab32( &(_p)->max_mtrans );       \
} while ( 0 )


typedef struct
{
  uint32_t idx;
  MBG_LICENSE_PTPV2 license;

} MBG_LICENSE_PTPV2_IDX;

#define _mbg_swab_license_ptpv2_idx( _p )     \
do                                            \
{                                             \
  _mbg_swab_license_ptpv2( &(_p)->license );  \
  _mbg_swab32( &(_p)->idx );                  \
} while ( 0 )


/**
 * @brief Bits used to define ::MBG_LICENSE_NTP_MEMBER_MSKS
 *
 * @see ::MBG_LICENSE_NTP_MEMBER_MSKS
 */
enum MBG_LICENSE_NTP_MEMBERS
{
  MBG_LICENSE_NTP_MEMBER_MAX_RPS,
  N_MBG_LICENSE_NTP_MEMBERS
};


/**
 * @brief Bit masks of NTP license specific members
 *
 * Used with ::MBG_LICENSE_NTP::supp_members
 *
 * @see ::MBG_LICENSE_PTPV2_MEMBERS
 */
enum MBG_LICENSE_NTP_MEMBER_MSKS
{
  MBG_LICENSE_NTP_MEMBER_MSK_MAX_RPS = ( 1UL << MBG_LICENSE_NTP_MEMBER_MAX_RPS )    ///< See ::MBG_LICENSE_NTP_MEMBER_MAX_RPS
};


/**
 * @brief NTP specific license information
 */
typedef struct
{
  MBG_LICENSE_BASE base;        ///< See ::MBG_LICENSE_BASE
  uint32_t supp_members;        ///< See ::MBG_LICENSE_NTP_MEMBER_MSKS
  uint32_t max_rps;             ///< Maximum number of supported NTP requests per second
  uint32_t reserved_1;          ///< Reserved for future use, currently 0
  uint32_t reserved_2;          ///< Reserved for future use, currently 0
  uint32_t reserved_3;          ///< Reserved for future use, currently 0
  uint32_t reserved_4;          ///< Reserved for future use, currently 0
  uint32_t reserved_5;          ///< Reserved for future use, currently 0
  uint32_t reserved_6;          ///< Reserved for future use, currently 0

} MBG_LICENSE_NTP;

#define _mbg_swab_license_ntp( _p )       \
do                                        \
{                                         \
  _mbg_swab_license_base( &(_p)->base );  \
  _mbg_swab32( &(_p)->supp_members );     \
  _mbg_swab32( &(_p)->max_rps );          \
} while ( 0 )



typedef struct
{
  uint32_t idx;
  MBG_LICENSE_NTP license;

} MBG_LICENSE_NTP_IDX;

#define _mbg_swab_license_ntp_idx( _p )     \
do                                          \
{                                           \
  _mbg_swab_license_ntp( &(_p)->license );  \
  _mbg_swab32( &(_p)->idx );                \
} while ( 0 )

/**
 * @brief Bits used to define ::MBG_LICENSE_PTPV1_MEMBER_MSKS
 *
 * @see ::MBG_LICENSE_PTPV1_MEMBER_MSKS
 */
enum MBG_LICENSE_PTPV1_MEMBERS
{
  MBG_LICENSE_PTPV1_MEMBER_MAX_RPS,
  N_MBG_LICENSE_PTPV1_MEMBERS
};


/**
 * @brief Bit masks of PTPV1 license specific members
 *
 * Used with ::MBG_LICENSE_PTPV1::supp_members
 *
 * @see ::MBG_LICENSE_PTPV2_MEMBERS
 */
enum MBG_LICENSE_PTPV1_MEMBER_MSKS
{
  MBG_LICENSE_PTPV1_MEMBER_MSK_MAX_RPS = ( 1UL << MBG_LICENSE_PTPV1_MEMBER_MAX_RPS )    ///< See ::MBG_LICENSE_PTPV1_MEMBER_MAX_RPS
};


/**
 * @brief NTP specific license information
 */
typedef struct
{
  MBG_LICENSE_BASE base;        ///< See ::MBG_LICENSE_BASE
  uint32_t supp_members;        ///< See ::MBG_LICENSE_PTPV1_MEMBER_MSKS
  uint32_t max_rps;             ///< Maximum number of supported PTPv1 delay requests per second
  uint32_t reserved_1;          ///< Reserved for future use, currently 0
  uint32_t reserved_2;          ///< Reserved for future use, currently 0
  uint32_t reserved_3;          ///< Reserved for future use, currently 0
  uint32_t reserved_4;          ///< Reserved for future use, currently 0
  uint32_t reserved_5;          ///< Reserved for future use, currently 0
  uint32_t reserved_6;          ///< Reserved for future use, currently 0

} MBG_LICENSE_PTPV1;

#define _mbg_swab_license_ptpv1( _p )     \
do                                        \
{                                         \
  _mbg_swab_license_base( &(_p)->base );  \
  _mbg_swab32( &(_p)->supp_members );     \
  _mbg_swab32( &(_p)->max_rps );          \
} while ( 0 )


typedef struct
{
  uint32_t idx;
  MBG_LICENSE_PTPV1 license;

} MBG_LICENSE_PTPV1_IDX;

#define _mbg_swab_license_ptpv1_idx( _p )     \
do                                            \
{                                             \
  _mbg_swab_license_ptpv1( &(_p)->license );  \
  _mbg_swab32( &(_p)->idx );                  \
} while ( 0 )

/**
 * @brief Bits used to define ::MBG_LICENSE_TIME_MONITOR_MEMBER_MSKS
 *
 * @see ::MBG_LICENSE_TIME:MONITOR_MEMBER_MSKS
 */
enum MBG_LICENSE_TIME_MONITOR_MEMBERS
{
  MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_PTPV2_CLIENTS,
  MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_NTP_CLIENTS,
  N_MBG_LICENSE_TIME_MONITOR_MEMBERS
};


/**
 * @brief Bit masks of Time Monitor license specific members
 *
 * Used with ::MBG_LICENSE_TIME_MONITOR::supp_members
 *
 * @see ::MBG_LICENSE_TIME_MONITOR_MEMBERS
 */
enum MBG_LICENSE_TIME_MONITOR_MEMBER_MSKS
{
  MBG_LICENSE_TIME_MONITOR_MEMBER_MSK_MAX_PTPV2_CLIENTS = ( 1UL << MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_PTPV2_CLIENTS ),  ///< See ::MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_PTPV2_CLIENTS
  MBG_LICENSE_TIME_MONITOR_MEMBER_MSK_MAX_NTP_CLIENTS   = ( 1UL << MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_NTP_CLIENTS )     ///< See ::MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_NTP_CLIENTS
};


/**
 * @brief Time Monitor specific license information
 *
 */
typedef struct
{
  MBG_LICENSE_BASE base;        ///< See ::MBG_LICENSE_BASE
  uint32_t supp_members;        ///< See ::MBG_LICENSE_TIME_MONITOR_MEMBER_MSKS
  uint32_t reserved_1;          ///< Reserved for future use, currently 0
  uint16_t max_ptpv2_clients;   ///< Maximum number of supported PTPv2 clients to be monitored
  uint16_t max_ntp_clients;     ///< Maximum number of supported NTP clients to be monitored
  uint32_t reserved_2;          ///< Reserved for future use, currently 0
  uint32_t reserved_3;          ///< Reserved for future use, currently 0
  uint32_t reserved_4;          ///< Reserved for future use, currently 0
  uint32_t reserved_5;          ///< Reserved for future use, currently 0
  uint32_t reserved_6;          ///< Reserved for future use, currently 0

} MBG_LICENSE_TIME_MONITOR;

#define _mbg_swab_license_time_monitor( _p )  \
do                                            \
{                                             \
  _mbg_swab_license_base( &(_p)->base );      \
  _mbg_swab32( &(_p)->supp_members );         \
  _mbg_swab16( &(_p)->max_ptpv2_clients );    \
  _mbg_swab16( &(_p)->max_ntp_clients );      \
} while ( 0 )


typedef struct
{
  uint32_t idx;
  MBG_LICENSE_TIME_MONITOR license;

} MBG_LICENSE_TIME_MONITOR_IDX;

#define _mbg_swab_license_time_monitor_idx( _p )     \
do                                                   \
{                                                    \
  _mbg_swab_license_time_monitor( &(_p)->license );  \
  _mbg_swab32( &(_p)->idx );                         \
} while ( 0 )

/** @} defgroup group_license_limits */



/**
 * @defgroup group_clk_res_info Clock resolution info
 *
 * @note This structure and its definitions are only supported by a device
 * if ::MBG_XFEATURE_CLK_RES_INFO is set in the extended device features.
 *
 * @{ */

/**
 * @brief Clock resolution information
 *
 * @see @ref group_clk_res_info
 */
typedef struct
{
  uint32_t base_clk;        ///< Base clock of the internal time base [MHz]
  uint32_t num_clk_phase;   ///< Number of multi-phase clock signals
  uint32_t reserved_9;
  uint32_t reserved_8;
  uint32_t reserved_7;
  uint32_t reserved_6;
  uint32_t reserved_5;
  uint32_t reserved_4;
  uint32_t reserved_3;
  uint32_t reserved_2;
  uint32_t reserved_1;
  uint32_t reserved_0;

} MBG_CLK_RES_INFO;

#define _mbg_swab_mbg_clk_res_info( _p )  \
do                                        \
{                                         \
  _mbg_swab32( &(_p)->base_clk );         \
  _mbg_swab32( &(_p)->num_clk_phase );    \
  _mbg_swab32( &(_p)->reserved_9 );       \
  _mbg_swab32( &(_p)->reserved_8 );       \
  _mbg_swab32( &(_p)->reserved_7 );       \
  _mbg_swab32( &(_p)->reserved_6 );       \
  _mbg_swab32( &(_p)->reserved_5 );       \
  _mbg_swab32( &(_p)->reserved_4 );       \
  _mbg_swab32( &(_p)->reserved_3 );       \
  _mbg_swab32( &(_p)->reserved_2 );       \
  _mbg_swab32( &(_p)->reserved_1 );       \
  _mbg_swab32( &(_p)->reserved_0 );       \
} while ( 0 )

/** @} defgroup group_clk_res_info */



/**
 * @brief Type of upcoming transaction sequence
 *
 * Used in combination with ::GPS_BEGIN_TRANSACTION and ::GPS_END_TRANSACTION
 * to announce which type of transaction is going to be started. Thus the receiver
 * can prepare for following actions.
 */
enum MBG_TRANSACTION_TYPES
{
  MBG_TRANSACTION_TYPE_NONE,
  /* ### TODO FIXME
   * Network transaction requires at least and as first command:
   *  - ::GPS_NET_GLB_CFG (::MBG_NET_GLB_CFG_INFO)
   * Depending on ::MBG_NET_GLB_CFG_INFO::glb_settings and its num_[...]
   * members there are a couple of index commands which should be handled in any order:
   *  - ::GPS_NET_DNS_SRVR (::MBG_IP_ADDR_IDX)
   *  - ::GPS_NET_DNS_SRCH_DOM (::MBG_NET_NAME_IDX)
   *  - ::GPS_NET_INTF_LINK_IDX (::MBG_NET_INTF_LINK_INFO_IDX)
   *  - ::GPS_NET_INTF_ADDR_IDX (::MBG_NET_INTF_ADDR_INFO_IDX)
   *  - ::GPS_NET_INTF_ROUTE_IDX (::MBG_NET_INTF_ROUTE_INFO_IDX)
   */
  MBG_TRANSACTION_TYPE_NETWORK,
  MBG_TRANSACTION_TYPE_PTP,
  /*
   * Commands in any order if supp. by ::MBG_SNMP_GLB_INFO::max_[...]
   * and ::MBG_SNMP_GLB_INFO::supp_versions
   *
   * Should be used within ::MBG_TRANSACTION_TYPE_MONITORING but may also be
   * used stand-alone.
   *
   *  - ::GPS_SNMP_GLB_SETTINGS
   *  - ::GPS_SNMP_V12_SETTINGS_IDX
   *  - ::GPS_SNMP_V12_TRAP_SETTINGS_IDX
   *  - ::GPS_SNMP_V3_SETTINGS_IDX
   *  - ::GPS_SNMP_V3_TRAP_SETTINGS_IDX
   */
  MBG_TRANSACTION_TYPE_MONITORING_SNMP,
  /*
   * NTP transaction requires at least and as first command:
   * ::GPS_NTP_GLB_CFG
   * Commands in any order if supp. by ::MBG_NTP_GLB_INFO
   * and ::MBG_SNMP_GLB_INFO::supp_versions
   *
   *  - ::GPS_NTP_REFCLK_CFG
   *  - ::GPS_NTP_MISC_LIMITS
   *  - ::GPS_NTP_MISC_ORPHAN_MODE
   *  - ::GPS_NTP_SYMM_KEY_LIMITS
   *  - ::GPS_NTP_SYMM_KEY_CFG
   *  - ::GPS_NTP_TRUSTED_KEY_CFG
   *  - ::GPS_NTP_CLNT_MODE_CFG
   *  - ::GPS_NTP_SRV_MODE_CFG
   *  - ::GPS_NTP_PEER_SETTINGS_IDX
   *  - ::GPS_NTP_SYS_STATE
   *  - ::GPS_NTP_PEER_STATE_IDX
   */
  MBG_TRANSACTION_TYPE_NTP,
  /*
   * IO Port transaction used to read or write ALL_IO_PORT_INFO
   * Commands related to this transaction:
   *
   * - ::GPS_IO_PORT_LIMITS
   * - ::GPS_IO_PORT_SETTINGS_IDX
   * - ::GPS_IO_PORT_INFO_IDX
   * - ::GPS_IO_PORT_TYPE_INFO_IDX
   * - ::GPS_IO_PORT_STATUS_IDX
   */
  MBG_TRANSACTION_TYPE_IO_PORT,
  /*
   * Commands in any order if ::MBG_XFEATURE_MONITORING is set in
   * ::MBG_XFEATURE_BUFFER.
   *
   * Transactions ::MBG_TRANSACTION_TYPE_MONITORING_SNMP and
   * ::MBG_TRANSACTION_TYPE_EVENTS may also be opened within
   * ::MBG_TRANSACTION_TYPE_MONITORING transaction.
   *
   *  - ::GPS_MONITORING_LIMITS
   *  - ::GPS_MONITORING_STATUS
   */
  MBG_TRANSACTION_TYPE_MONITORING,
  /*
   * Commands in any order if ::MBG_XFEATURE_MONITORING is set in
   * ::MBG_XFEATURE_BUFFER.
   *
   * Should be used within ::MBG_TRANSACTION_TYPE_MONITORING but may also be
   * used stand-alone.
   *
   *  - ::GPS_EVENT_IDX
   *  - ::GPS_EVENT_STAT_IDX
   */
  MBG_TRANSACTION_TYPE_EVENTS,

  MAX_MBG_TRANSACTION_TYPES
};


#define MBG_TRANSACTION_MSK_SET            0x8000
#define _mbg_is_set_transaction( _type )   ( ( _type ) & MBG_TRANSACTION_MSK_SET )
#define _mbg_transaction_type_set( _type ) ( ( _type ) |= MBG_TRANSACTION_MSK_SET )


/**
 * @defgroup group_io_ports IO Port API
 *
 * @note This structure and its definitions are only supported by a device
 * if ::MBG_XFEATURE_IO_PORTS is set in the extended device features.
 *
 * @{ */

/**
 * @brief Port types
 *
 * Used with ::MBG_IO_PORT_TYPE_INFO::type and
 * :: MBG_IO_PORT_SETTINGS::type
 */
enum MBG_IO_PORT_TYPES
{
  MBG_IO_PORT_TYPE_NONE = -1,        ///< Only use this for ::MBG_IO_PORT_SETTINGS::type if ::MBG_IO_PORT_SETTINGS::op_mode is ::MBG_IO_PORT_OP_MODE_NONE
  MBG_IO_PORT_TYPE_PPS,
  MBG_IO_PORT_TYPE_10MHz,
  MBG_IO_PORT_TYPE_2048KHz,
  MBG_IO_PORT_TYPE_GPIO,
  MBG_IO_PORT_TYPE_ETHERNET,
  MBG_IO_PORT_TYPE_TERMINAL,
  MBG_IO_PORT_TYPE_MULTI,
  MBG_IO_PORT_TYPE_POUT,
  N_MBG_IO_PORT_TYPES
};


/**
 * @brief Strings descriptions for ::MBG_IO_PORT_TYPES
 *
 * Can be used to initialize a string array of ::N_MBG_IO_PORT_TYPES entries,
 * so the number of strings must correspond to ::N_MBG_IO_PORT_TYPES.
 *
 * @see ::MBG_IO_PORT_TYPES
 */
#define MBG_IO_PORT_TYPE_STRS   \
{                               \
  "PPS",                        \
  "10 MHz",                     \
  "2048 KHz",                   \
  "GPIO",                       \
  "Ethernet",                   \
  "Terminal",                   \
  "Multi",                      \
  "Prog. Output"                \
}


/**
 * @brief Port directions (input or output)
 *
 * @see ::MBG_IO_PORT_DIR_MSKS
 */
enum MBG_IO_PORT_DIRS
{
  MBG_IO_PORT_DIR_NONE = -1,    ///< Only use this for ::MBG_IO_PORT_SETTINGS::direction if ::MBG_IO_PORT_SETTINGS::op_mode is ::MBG_IO_PORT_OP_MODE_NONE
  MBG_IO_PORT_DIR_IN,           ///< Port is input like PPS In
  MBG_IO_PORT_DIR_OUT,          ///< Port is output like 10Mhz
  MBG_IO_PORT_DIR_IN_OUT,       ///< Port can be in- & output in parallel like network port
  N_MBG_IO_PORT_DIRS
};


/**
 * @brief Strings descriptions for ::MBG_IO_PORT_DIRS
 *
 * Can be used to initialize a string array of ::N_MBG_IO_PORT_DIRS entries,
 * so the number of strings must correspond to ::N_MBG_IO_PORT_DIRS.
 *
 * @see ::MBG_IO_PORT_DIRS
 */
#define MBG_IO_PORT_DIR_STRS    \
{                               \
  "Input",                      \
  "Output",                     \
  "Input/Output"                \
}


/**
 * @brief Bit masks of Meinberg I/O port directions
 *
 * Used with ::MBG_IO_PORT_TYPE_INFO::supp_dirs
 *
 * @see ::MBG_IO_PORT_DIRS
 */
enum MBG_IO_PORT_DIR_MSKS
{
  MBG_IO_PORT_MSK_DIR_IN      = ( 1UL << MBG_IO_PORT_DIR_IN ),     ///< See ::MBG_IO_PORT_DIR_IN
  MBG_IO_PORT_MSK_DIR_OUT     = ( 1UL << MBG_IO_PORT_DIR_OUT ),    ///< See ::MBG_IO_PORT_DIR_OUT
  MBG_IO_PORT_MSK_DIR_IN_OUT  = ( 1UL << MBG_IO_PORT_DIR_IN_OUT )  ///< See ::MBG_IO_PORT_DIR_IN_OUT
};


/**
 * @brief Port type sources
 *
 * Configurable sources for an I/O port type
 *
 * @see ::MBG_IO_PORT_SRC_MSKS
 */
enum MBG_IO_PORT_SRCS
{
  MBG_IO_PORT_SRC_NONE = -1,    ///< Only use this for ::MBG_IO_PORT_SETTINGS::source if ::MBG_IO_PORT_SETTINGS::op_mode is ::MBG_IO_PORT_OP_MODE_NONE
  MBG_IO_PORT_SRC_STATIC,       ///< Static, not configurable
  MBG_IO_PORT_SRC_LOCAL,        ///< Locally generated, e.g. on (carrier) board
  MBG_IO_PORT_SRC_ASSOC_CLOCK,  ///< Fixed (wired) clock from back plane (e.g. refclock 1 in M500 IMS)
  MBG_IO_PORT_SRC_ACTIVE_CLOCK, ///< Switched clock from back plane (e.g. selected by RSC)
  MBG_IO_PORT_SRC_CLK1,         ///< Clock 1 fixed (CPU board only)
  MBG_IO_PORT_SRC_CLK2,         ///< Clock 2 fixed (CPU board only)
  MBG_IO_PORT_SRC_ARC,          ///< Any rate converter
  MBG_IO_PORT_SRC_OSC,          ///< Oscillator
  MBG_IO_PORT_SRC_SYNCE,        ///< SyncE
  N_MBG_IO_PORT_SRCS
};


/**
 * @brief Strings descriptions for ::MBG_IO_PORT_SRCS
 *
 * Can be used to initialize a string array of ::N_MBG_IO_PORT_SRCS entries,
 * so the number of strings must correspond to ::N_MBG_IO_PORT_SRCS.
 *
 * @see ::MBG_IO_PORT_SRCS
 */
#define MBG_IO_PORT_SRC_STRS    \
{                               \
  "Static",                     \
  "Locally generated",          \
  "Associated clock",           \
  "Active clock",               \
  "Clock 1 fixed",              \
  "Clock 2 fixed",              \
  "Any rate converter",         \
  "Oscillator",                 \
  "SyncE"                       \
}


/**
 * @brief Bit masks of Meinberg I/O port attitudes
 *
 * Used with ::MBG_IO_PORT_TYPE_INFO::supp_srcs
 *
 * @see ::MBG_IO_PORT_SRCS
 */
enum MBG_IO_PORT_SRC_MSKS
{
  MBG_IO_PORT_SRC_MSK_STATIC       = (1UL << MBG_IO_PORT_SRC_STATIC),       ///< See ::MBG_IO_PORT_SRC_STATIC
  MBG_IO_PORT_SRC_MSK_LOCAL        = (1UL << MBG_IO_PORT_SRC_LOCAL),        ///< See ::MBG_IO_PORT_SRC_LOCAL
  MBG_IO_PORT_SRC_MSK_ASSOC_CLOCK  = (1UL << MBG_IO_PORT_SRC_ASSOC_CLOCK),  ///< See ::MBG_IO_PORT_SRC_ASSOC_CLOCK
  MBG_IO_PORT_SRC_MSK_ACTIVE_CLOCK = (1UL << MBG_IO_PORT_SRC_ACTIVE_CLOCK), ///< See ::MBG_IO_PORT_SRC_ACTIVE_CLOCK
  MBG_IO_PORT_SRC_MSK_CLK1         = (1UL << MBG_IO_PORT_SRC_CLK1),         ///< See ::MBG_IO_PORT_SRC_CLK1
  MBG_IO_PORT_SRC_MSK_CLK2         = (1UL << MBG_IO_PORT_SRC_CLK2),         ///< See ::MBG_IO_PORT_SRC_CLK2
  MBG_IO_PORT_SRC_MSK_ARC          = (1UL << MBG_IO_PORT_SRC_ARC),          ///< See ::MBG_IO_PORT_SRC_ARC
  MBG_IO_PORT_SRC_MSK_OSC          = (1UL << MBG_IO_PORT_SRC_OSC),          ///< See ::MBG_IO_PORT_SRC_OSC
  MBG_IO_PORT_SRC_MSK_SYNCE        = (1UL << MBG_IO_PORT_SRC_SYNCE)         ///< See ::MBG_IO_PORT_SRC_SYNCE
};


/**
 * @brief Port connector types
 *
 * Used with ::MBG_IO_PORT_TYPE_INFO::conn_type
 *
 */
enum MBG_IO_PORT_CONN_TYPES
{
  MBG_IO_PORT_CONN_TYPE_SMA,
  MBG_IO_PORT_CONN_TYPE_BNC,
  MBG_IO_PORT_CONN_TYPE_DSUB25,
  MBG_IO_PORT_CONN_TYPE_RJ45,
  MBG_IO_PORT_CONN_TYPE_SFP,
  MBG_IO_PORT_CONN_TYPE_USB_MICRO_B,
  MBG_IO_PORT_CONN_TYPE_USB_A,
  MBG_IO_PORT_CONN_TYPE_USB_B,
  MBG_IO_PORT_CONN_TYPE_SMA_ANT,
  MBG_IO_PORT_CONN_TYPE_RJ45_ETH,
  MBG_IO_PORT_CONN_TYPE_2_PIN_DFK,
  MBG_IO_PORT_CONN_TYPE_3_PIN_DFK,
  MBG_IO_PORT_CONN_TYPE_16_PIN_DFK,
  MBG_IO_PORT_CONN_TYPE_BNC_ISO,
  MBG_IO_PORT_CONN_TYPE_DSUB9,
  MBG_IO_PORT_CONN_TYPE_FIBRE_ST,
  MBG_IO_PORT_CONN_TYPE_XHE_SPI,
  N_MBG_IO_PORT_CONN_TYPES
};


/**
 * @brief Strings descriptions for ::MBG_IO_PORT_CONN_TYPES
 *
 * Can be used to initialize a string array of ::N_MBG_IO_PORT_CONN_TYPES entries,
 * so the number of strings must correspond to ::N_MBG_IO_PORT_CONN_TYPES.
 *
 * @see ::MBG_IO_PORT_CONN_TYPES
 */
#define MBG_IO_PORT_CONN_TYPE_STRS  \
{                                   \
  "SMA",                            \
  "BNC",                            \
  "D-Sub 25",                       \
  "RJ45",                           \
  "SFP",                            \
  "USB Micro B",                    \
  "USB A",                          \
  "USB B",                          \
  "SMA Antenna",                    \
  "RJ45 Ethernet",                  \
  "DFK 2-Pin",                      \
  "DFK 3-Pin",                      \
  "DFK 16-Pin",                     \
  "BNC isolated",                   \
  "D-Sub 9",                        \
  "Fibre ST",                       \
  "XHE SPI"                         \
}


/**
 * @brief Position of a port on a card
 *
 * Used with ::MBG_IO_PORT_INFO::position
 *
 */
enum MBG_IO_PORT_POS
{
  MBG_IO_PORT_POS_FRONT_COL_1,    ///> Connector column 1, front
  MBG_IO_PORT_POS_REAR_COL_1,     ///> Connector column 1, rear
  MBG_IO_PORT_POS_FRONT_COL_2,    ///> Connector column 2, front
  MBG_IO_PORT_POS_REAR_COL_2,     ///> Connector column 2, rear
  MBG_IO_PORT_POS_FRONT_COL_3,    ///> Connector column 3, front
  MBG_IO_PORT_POS_REAR_COL_3,     ///> Connector column 3, rear
  MBG_IO_PORT_POS_FRONT_COL_4,    ///> Connector column 4, front
  MBG_IO_PORT_POS_REAR_COL_4,     ///> Connector column 4, rear
  N_MBG_IO_PORT_POS
};


/**
 * @brief Bit masks of Meinberg I/O port attitudes
 *
 * Used with ::MBG_IO_PORT_TYPE_INFO::supp_srcs
 *
 * @see ::MBG_IO_PORT_POS
 */
enum MBG_IO_PORT_POS_MSKS
{
  MBG_IO_PORT_POS_MSK_FRONT_COL_1       = (1UL << MBG_IO_PORT_POS_FRONT_COL_1),       ///< See ::MBG_IO_PORT_POS_FRONT_COL_1
  MBG_IO_PORT_POS_MSK_REAR_COL_1        = (1UL << MBG_IO_PORT_POS_REAR_COL_1),        ///< See ::MBG_IO_PORT_POS_REAR_COL_1
  MBG_IO_PORT_POS_MSK_FRONT_COL_2       = (1UL << MBG_IO_PORT_POS_FRONT_COL_2),       ///< See ::MBG_IO_PORT_POS_FRONT_COL_2
  MBG_IO_PORT_POS_MSK_REAR_COL_2        = (1UL << MBG_IO_PORT_POS_REAR_COL_2),        ///< See ::MBG_IO_PORT_POS_REAR_COL_2
  MBG_IO_PORT_POS_MSK_FRONT_COL_3       = (1UL << MBG_IO_PORT_POS_FRONT_COL_3),       ///< See ::MBG_IO_PORT_POS_FRONT_COL_3
  MBG_IO_PORT_POS_MSK_REAR_COL_3        = (1UL << MBG_IO_PORT_POS_REAR_COL_3),        ///< See ::MBG_IO_PORT_POS_REAR_COL_3
  MBG_IO_PORT_POS_MSK_FRONT_COL_4       = (1UL << MBG_IO_PORT_POS_FRONT_COL_4),       ///< See ::MBG_IO_PORT_POS_FRONT_COL_4
  MBG_IO_PORT_POS_MSK_REAR_COL_4        = (1UL << MBG_IO_PORT_POS_REAR_COL_4)         ///< See ::MBG_IO_PORT_POS_REAR_COL_4
};


/**
 * @brief IO Port Limits
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_INFO
 * @see ::MBG_IO_PORT_INFO_U
 * @see ::MBG_IO_PORT_INFO_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS
 * @see ::MBG_IO_PORT_STATUS_IDX
 */
typedef struct
{
  uint8_t num_ports;
  uint8_t reserved_1[3];        ///< Reserved, currently 0
  uint32_t supp_positions;      ///< Determines the size of the card (i.e. 2 rows, front/rear) See ::MBG_IO_PORT_POS_MSKS
  uint32_t reserved_2[10];      ///< Reserved, currently 0

} MBG_IO_PORT_LIMITS;

#define _mbg_swab_io_port_limits( _p )   \
do                                       \
{                                        \
  _mbg_swab32( &(_p)->supp_positions );  \
} while ( 0 )



/**
 * @brief Port Operation Bits
 *
 * Used with ::MBG_IO_PORT_SETTINGS::op_mode
 *
 * For now, there is a per port operation mode setting which
 * is quite equal to ::ENABLE_FLAGS.
 *
 * @see ::MBG_IO_PORT_OP_MODE_MSKS
 */
enum MBG_IO_PORT_OP_MODE_BITS
{
  MBG_IO_PORT_OP_MODE_NONE = -1,      ///< Current mode cannot be determined
  MBG_IO_PORT_OP_MODE_DISABLED,       ///< Disabled port
  MBG_IO_PORT_OP_MODE_ALWAYS,         ///< Always enable port
  MBG_IO_PORT_OP_MODE_IF_SYNC_ONLY,   ///< Enable port if sync only
  MBG_IO_PORT_OP_MODE_AFTER_SYNC,     ///< Always enable port after being sync once
  N_MBG_IO_PORT_OP_MODE_BITS
};


/**
 * @brief Strings descriptions for ::MBG_IO_PORT_OP_MODE_BITS
 *
 * Can be used to initialize a string array of ::N_MBG_IO_PORT_OP_MODE_BITS entries,
 * so the number of strings must correspond to ::N_MBG_IO_PORT_OP_MODE_BITS.
 *
 * @see ::MBG_IO_PORT_OP_MODE_BITS
 */
#define MBG_IO_PORT_OP_MODE_STRS        \
{                                       \
  "Disabled",                           \
  "Always enabled",                     \
  "If sync only",                       \
  "Always after sync"                   \
}



/**
 * @brief Masks for ::MBG_IO_PORT_OP_MODE_BITS
 *
 * Used with ::MBG_IO_PORT_INFO::supp_op_modes
 *
 * @see ::MBG_IO_PORT_OP_MODE_BITS
 */
enum MBG_IO_PORT_OP_MODE_MSKS
{
  MBG_IO_PORT_OP_MODE_MSK_DISABLED        = (1UL << MBG_IO_PORT_OP_MODE_DISABLED),          ///< See ::MBG_IO_PORT_OP_MODE_DISABLED
  MBG_IO_PORT_OP_MODE_MSK_ALWAYS          = (1UL << MBG_IO_PORT_OP_MODE_ALWAYS),            ///< See ::MBG_IO_PORT_OP_MODE_ALWAYS
  MBG_IO_PORT_OP_MODE_MSK_IF_SYNC_ONLY    = (1UL << MBG_IO_PORT_OP_MODE_IF_SYNC_ONLY),      ///< See ::MBG_IO_PORT_OP_MODE_IF_SYNC_ONLY
  MBG_IO_PORT_OP_MODE_MSK_AFTER_SYNC      = (1UL << MBG_IO_PORT_OP_MODE_AFTER_SYNC)         ///< See ::MBG_IO_PORT_OP_MODE_AFTER_SYNC
};


/**
 * @brief Physical or logical group role bits
 *
 * Used with ::MBG_IO_PORT_STATUS::phys_grp_role, ::MBG_IO_PORT_STATUS::log_grp_role
 *
 * @see ::MBG_IO_PORT_GRP_ROLE_MSKS
 */
enum MBG_IO_PORT_GRP_ROLE_BITS
{
  MBG_IO_PORT_GRP_ROLE_NONE,           ///< No group role, only possible if port is not assigned to any group
  MBG_IO_PORT_GRP_ROLE_MASTER,         ///< Master port in group, i.e. configurable port of LIU
  MBG_IO_PORT_GRP_ROLE_SLAVE,          ///< Slave port in group, i.e. non-configurable port of LIU
  MBG_IO_PORT_GRP_ROLE_PASSIVE,        ///< Passive port in group, i.e. passive port of network group (i.e. SFP or RJ45)
  N_MBG_IO_PORT_GRP_ROLE_BITS
};


/**
 * @brief Strings descriptions for ::MBG_IO_PORT_GRP_ROLE_BITS
 *
 * Can be used to initialize a string array of ::N_MBG_IO_PORT_GRP_ROLE_BITS entries,
 * so the number of strings must correspond to ::N_MBG_IO_PORT_GRP_ROLE_BITS.
 *
 * @see ::MBG_IO_PORT_GRP_ROLE_BITS
 */
#define MBG_IO_PORT_GRP_ROLE_STRS         \
{                                         \
  "None",                                 \
  "Master",                               \
  "Slave",                                \
  "Passive"                               \
}


/**
 * @brief Masks for ::MBG_IO_PORT_GRP_ROLE_BITS
 *
 * Used with ::MBG_IO_PORT_INFO::supp_phys_grp_roles
 *
 * @see ::MBG_IO_PORT_GRP_ROLE_BITS
 */
enum MBG_IO_PORT_GRP_ROLE_MSKS
{
  MBG_IO_PORT_GRP_ROLE_MSK_NONE            = (1UL << MBG_IO_PORT_GRP_ROLE_NONE),            ///< See ::MBG_IO_PORT_GRP_ROLE_NONE
  MBG_IO_PORT_GRP_ROLE_MSK_MASTER          = (1UL << MBG_IO_PORT_GRP_ROLE_MASTER),          ///< See ::MBG_IO_PORT_GRP_ROLE_MASTER
  MBG_IO_PORT_GRP_ROLE_MSK_SLAVE           = (1UL << MBG_IO_PORT_GRP_ROLE_SLAVE),           ///< See ::MBG_IO_PORT_GRP_ROLE_SLAVE
  MBG_IO_PORT_GRP_ROLE_MSK_PASSIVE         = (1UL << MBG_IO_PORT_GRP_ROLE_PASSIVE)          ///< See ::MBG_IO_PORT_GRP_ROLE_PASSIVE
};


/**
 * @brief IO Port Settings Union
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_INFO
 * @see ::MBG_IO_PORT_INFO_U
 * @see ::MBG_IO_PORT_INFO_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS
 * @see ::MBG_IO_PORT_STATUS_IDX
 */
typedef union
{
  MBG_GPIO_SETTINGS gpio_settings;
  POUT_SETTINGS pout_settings;

} MBG_IO_PORT_SETTINGS_U;

#define _mbg_swab_io_port_settings_u( _type, _p, _recv )            \
do                                                                  \
{                                                                   \
  switch ( (_type) )                                                \
  {                                                                 \
    case MBG_IO_PORT_TYPE_GPIO:                                     \
    _mbg_swab_mbg_gpio_settings( &(_p)->gpio_settings, (_recv) );   \
    break;                                                          \
                                                                    \
    case MBG_IO_PORT_TYPE_POUT:                                     \
    if ( _recv )                                                    \
      _mbg_swab_pout_settings_on_get( &(_p)->pout_settings );       \
    else _mbg_swab_pout_settings_on_set( &(_p)->pout_settings );    \
    break;                                                          \
                                                                    \
    default: break;                                                 \
  }                                                                 \
} while ( 0 )


#define MBG_IO_PORT_SETTINGS_MIN_SIZE 32


/**
 * @brief IO Port Settings
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_INFO
 * @see ::MBG_IO_PORT_INFO_U
 * @see ::MBG_IO_PORT_INFO_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS
 * @see ::MBG_IO_PORT_STATUS_IDX
 */
typedef struct
{
  uint16_t type;                    ///< ::MBG_IO_PORT_TYPES
  uint8_t direction;                ///< ::MBG_IO_PORT_DIRS
  uint8_t source;                   ///< ::MBG_IO_PORT_SRCS
  uint8_t op_mode;                  ///< ::MBG_IO_PORT_OP_MODE_BITS
  uint8_t reserved_1[3];            ///< Future use and padding, currently 0
  uint32_t reserved_2[6];           ///< Future use and padding, currently 0

  /*
   * Struct members above represent minimum amount of data to be sent.
   * See ::MBG_IO_PORT_SETTINGS_MIN_SIZE
   */

  MBG_IO_PORT_SETTINGS_U data;      ///< Data union for setting's type

} MBG_IO_PORT_SETTINGS;

#define _mbg_swab_io_port_settings( _p, _recv )             \
do                                                          \
{                                                           \
  uint16_t t = (_p)->type;                                  \
  if ( (_recv) )                                            \
    _mbg_swab16( &t );                                      \
  _mbg_swab16( &(_p)->type );                               \
  _mbg_swab_io_port_settings_u( t, &(_p)->data, (_recv) );  \
} while ( 0 )




/**
 * @brief IO Port Settings Index
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_INFO
 * @see ::MBG_IO_PORT_INFO_U
 * @see ::MBG_IO_PORT_INFO_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS
 * @see ::MBG_IO_PORT_STATUS_IDX
 *
 * Indexes from 0..::MBG_IO_PORT_LIMITS::num_ports - 1 are used
 * to set ::MBG_IO_PORT_SETTINGS wrapped in ::MBG_IO_PORT_SETTINGS_IDX.
 */
typedef struct
{
  uint32_t idx;
  MBG_IO_PORT_SETTINGS settings;

} MBG_IO_PORT_SETTINGS_IDX;

#define _mbg_swab_io_port_settings_idx( _p, _recv )         \
do                                                          \
{                                                           \
  _mbg_swab32( &(_p)->idx );                                \
  _mbg_swab_io_port_settings( &(_p)->settings, (_recv) );   \
} while ( 0 )


#define MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE (MBG_IO_PORT_SETTINGS_MIN_SIZE + sizeof( uint32_t ))


#define MBG_IO_PORT_SETTINGS_IDX_SIZES                                                               \
{                                                                                                    \
  MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_PPS       */ \
  MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_10MHz     */ \
  MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_2048KHz   */ \
  MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE + sizeof( MBG_GPIO_SETTINGS ),  /* MBG_IO_PORT_TYPE_GPIO      */ \
  MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_ETHERNET  */ \
  MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_TERMINAL  */ \
  MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_MULTI     */ \
  MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE + sizeof( POUT_SETTINGS )       /* MBG_IO_PORT_TYPE_POUT      */ \
}


#define MBG_NO_PHYS_GROUP            0xFF
#define MBG_NO_LOG_GROUP             0xFF

/**
 * @brief IO Port Info
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_INFO_U
 * @see ::MBG_IO_PORT_INFO_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS
 * @see ::MBG_IO_PORT_STATUS_IDX
 */
typedef struct
{
  uint8_t               num_types;            ///< See ::MBG_IO_PORT_TYPE_INFO
  uint8_t               conn_type;            ///< See ::MBG_IO_PORT_CONN_TYPES
  uint8_t               position;             ///< See ::MBG_IO_PORT_POS
  uint8_t               reserved_1;           ///< Future use and padding, currently 0
  uint16_t              supp_op_modes;        ///< See ::MBG_IO_PORT_OP_MODE_MSKS
  uint16_t              supp_phys_grp_roles;  ///< Supported roles in ::MBG_IO_PORT_STATUS::phys_grp_role, see ::MBG_IO_PORT_GRP_ROLE_MSKS
  uint8_t               phys_grp;             ///< Physical group number (i.e. SFP/RJ45 on HPS100), or ::MBG_NO_PHYS_GROUP
  uint8_t               reserved_2[3];        ///< Future use and padding, currently 0
  uint32_t              reserved_3[8];        ///< Future use and padding, currently 0
  char                  rel_str[16];          ///< Indicates internal relation, i.e. "lan0", "fpga0" or "/dev/ttyS0"
  MBG_IO_PORT_SETTINGS  settings;             ///< See ::MBG_IO_PORT_SETTINGS

} MBG_IO_PORT_INFO;

#define _mbg_port_has_phys_group( _p )                      ( ( _p )->phys_grp != MBG_NO_PHYS_GROUP )

#define _mbg_swab_io_port_info( _p, _recv )                 \
do                                                          \
{                                                           \
  _mbg_swab16( &(_p)->supp_op_modes );                      \
  _mbg_swab16( &(_p)->supp_phys_grp_roles );                \
  _mbg_swab_io_port_settings( &(_p)->settings, (_recv) );   \
} while ( 0 )



#define MBG_IO_PORT_INFO_MIN_SIZE ( 60 + MBG_IO_PORT_SETTINGS_MIN_SIZE )


/**
 * @brief IO Port Info Index
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_U
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS
 * @see ::MBG_IO_PORT_STATUS_IDX
 *
 * Indexes from 0..::MBG_IO_PORT_LIMITS::num_ports - 1 are used
 * to query ::MBG_IO_PORT_INFO wrapped in ::MBG_IO_PORT_INFO_IDX.
 */
typedef struct
{
  uint32_t idx;
  MBG_IO_PORT_INFO info;

} MBG_IO_PORT_INFO_IDX;

#define _mbg_swab_io_port_info_idx( _p, _recv )     \
do                                                  \
{                                                   \
  _mbg_swab32( &(_p)->idx );                        \
  _mbg_swab_io_port_info( &(_p)->info, (_recv) );   \
} while ( 0 )



#define MBG_IO_PORT_INFO_IDX_MIN_SIZE (MBG_IO_PORT_INFO_MIN_SIZE + sizeof( uint32_t ))


#define MBG_IO_PORT_INFO_IDX_SIZES                                                               \
{                                                                                                \
  MBG_IO_PORT_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_PPS       */ \
  MBG_IO_PORT_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_10MHz     */ \
  MBG_IO_PORT_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_2048KHz   */ \
  MBG_IO_PORT_INFO_IDX_MIN_SIZE + sizeof( MBG_GPIO_SETTINGS ),  /* MBG_IO_PORT_TYPE_GPIO      */ \
  MBG_IO_PORT_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_ETHERNET  */ \
  MBG_IO_PORT_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_TERMINAL  */ \
  MBG_IO_PORT_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_MULTI     */ \
  MBG_IO_PORT_INFO_IDX_MIN_SIZE + sizeof( POUT_SETTINGS )       /* MBG_IO_PORT_TYPE_POUT      */ \
}


/**
 * @brief IO Port Type Info Union
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_INFO
 * @see ::MBG_IO_PORT_INFO_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS
 * @see ::MBG_IO_PORT_STATUS_IDX
 */
typedef union
{
  MBG_GPIO_LIMITS gpio_limits;
  POUT_INFO pout_info;

} MBG_IO_PORT_TYPE_INFO_U;

#define _mbg_swab_io_port_type_info_u( _type, _p, _recv )       \
do                                                              \
{                                                               \
  switch ( (_type) )                                            \
  {                                                             \
    case MBG_IO_PORT_TYPE_GPIO:                                 \
    _mbg_swab_mbg_gpio_limits( &(_p)->gpio_limits, (_recv) );   \
    break;                                                      \
                                                                \
    case MBG_IO_PORT_TYPE_POUT:                                 \
    _mbg_swab_pout_info_on_get( &(_p)->pout_info );             \
    break;                                                      \
                                                                \
    default: break;                                             \
  }                                                             \
} while ( 0 )



#define MBG_IO_PORT_TYPE_INFO_MIN_SIZE 32


/**
 * @brief IO Port Type Info
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_INFO_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO_U
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS
 * @see ::MBG_IO_PORT_STATUS_IDX
 */
typedef struct
{
  uint16_t port_type;           ///< See ::MBG_IO_PORT_TYPES
  uint16_t reserved_1;           ///< Future use and padding, currently 0
  uint8_t supp_dirs;            ///< See ::MBG_IO_PORT_DIR_MSKS
  uint8_t reserved_2[3];        ///< Future use and padding, currently 0
  uint32_t supp_srcs;           ///< See ::MBG_IO_PORT_SRC_MSKS
  uint32_t reserved_3[5];       ///< Future use and padding, currently 0

  /*
   * Struct members above represent minimum amount of data to be sent.
   * See ::MBG_IO_PORT_TYPE_INFO_MIN_SIZE
   */

  MBG_IO_PORT_TYPE_INFO_U data; ///< Port type specific data

} MBG_IO_PORT_TYPE_INFO;

#define _mbg_swab_io_port_type_info( _p, _recv )             \
do                                                           \
{                                                            \
  uint16_t t = (_p)->port_type;                              \
  if ( (_recv) )                                             \
    _mbg_swab16( &t );                                       \
  _mbg_swab16( &(_p)->port_type );                           \
  _mbg_swab_io_port_type_info_u( t, &(_p)->data, (_recv) );  \
  _mbg_swab32( &(_p)->supp_srcs );                           \
} while ( 0 )


#define MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE (MBG_IO_PORT_TYPE_INFO_MIN_SIZE + 2 * sizeof( uint32_t ))


#define MBG_IO_PORT_TYPE_INFO_IDX_SIZES                                                               \
{                                                                                                     \
  MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_PPS       */ \
  MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_10MHz     */ \
  MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_2048KHz   */ \
  MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE + sizeof( MBG_GPIO_LIMITS ),    /* MBG_IO_PORT_TYPE_GPIO      */ \
  MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_ETHERNET  */ \
  MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_TERMINAL  */ \
  MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE,                                /* MBG_IO_PORT_TYPE_MULTI     */ \
  MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE + sizeof( POUT_INFO )           /* MBG_IO_PORT_TYPE_POUT      */ \
}


/**
 * @brief IO Port Type Info Index
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_U
 * @see ::MBG_IO_PORT_STATUS
 * @see ::MBG_IO_PORT_STATUS_IDX
 *
 * Indexes from 0..::MBG_IO_PORT_INFO::num_types - 1 are used
 * to query ::MBG_IO_PORT_TYPE_INFO wrapped in ::MBG_IO_PORT_TYPE_INFO_IDX.
 *
 */
typedef struct
{
  uint32_t port_idx;
  uint32_t port_type_idx;
  MBG_IO_PORT_TYPE_INFO info;

} MBG_IO_PORT_TYPE_INFO_IDX;

#define _mbg_swab_io_port_type_info_idx( _p, _recv )    \
do                                                      \
{                                                       \
  _mbg_swab32( &(_p)->port_idx );                       \
  _mbg_swab32( &(_p)->port_type_idx );                  \
  _mbg_swab_io_port_type_info( &(_p)->info, (_recv) );  \
} while ( 0 )



#define MAX_IO_PORT_STATUS_BITS    64


/**
 * @brief Port Type Status Bits
 *
 */
enum MBG_IO_PORT_STATUS_BITS
{
  MBG_IO_PORT_STATUS_BIT_DISABLED,                      ///< See ::MBG_IO_PORT_OP_MODE_DISABLED. Other bits should be 0 in this case
  MBG_IO_PORT_STATUS_BIT_CARRIER_DETECTED,              ///< Port has physical carrier connection (e.g. BNC cable in BPE's case)
  MBG_IO_PORT_STATUS_BIT_INPUT_SIGNAL_NEVER_AVAIL,      ///< Input signal has NEVER been avail
  MBG_IO_PORT_STATUS_BIT_INPUT_SIGNAL_AVAIL,            ///< Input signal is avail right now
  MBG_IO_PORT_STATUS_BIT_INPUT_SIGNAL_LOST,             ///< Input signal is currently not avail, but has been avail before
  MBG_IO_PORT_STATUS_BIT_SHORT_CIRCUIT,                 ///< Short circuit
  N_MBG_IO_PORT_STATUS_BITS
};


/**
 * @brief Strings descriptions for ::MBG_IO_PORT_STATUS_BITS
 *
 * Can be used to initialize a string array of ::N_MBG_IO_PORT_STATUS_BITS entries,
 * so the number of strings must correspond to ::N_MBG_IO_PORT_STATUS_BITS.
 *
 * @see ::MBG_IO_PORT_STATUS_BITS
 */
#define MBG_IO_PORT_STATUS_STRS         \
{                                       \
  "Disabled",                           \
  "Carrier detected",                   \
  "Input signal has never been avail",  \
  "Input signal is avail",              \
  "Input signal is currently lost",     \
  "Short circuit"                       \
}


/**
 * @brief Array size required to store all status bits
 *
 * The number of bytes required to store up to ::MAX_IO_PORT_STATUS_BITS
 * feature bits in a byte array.
 */
#define MAX_IO_PORT_STATUS_BYTES   ( MAX_IO_PORT_STATUS_BITS / 8 )


/**
 * @brief A structure used to store port status bits
 *
 * Up to ::MAX_IO_PORT_STATUS_BITS totally can be stored, but only
 * ::N_MBG_IO_PORT_STATUS_BITS are currently defined.
 *
 * The ::_set_io_port_status_bit macro should be used by the firmware
 * to set a status bit in the buffer, and the ::check_byte_array_bit
 * to check if a bit is set
 *
 * @see ::_set_io_port_status_bit
 * @see ::check_byte_array_bit
 */
typedef struct
{
  uint8_t b[MAX_IO_PORT_STATUS_BYTES];

} MBG_IO_PORT_STATUS_BUFFER;

#define _mbg_swab_io_port_status_buffer( _p )  \
  _nop_macro_fnc()



/**
 * @brief Set an port status bit in a ::MBG_IO_PORT_STATUS_BUFFER
 *
 * Should be used by the firmware only to set one of the ::N_MBG_IO_PORT_STATUS_BITS
 * in an ::MBG_IO_PORT_STATUS_BUFFER after power-up.
 *
 * @param[in]  _status_bit    One of the ::MBG_IO_PORT_STATUS_BITS
 * @param[in]  _status_buffp  Pointer to an ::MBG_IO_PORT_STATUS_BUFFER
 */
#define _set_io_port_status_bit( _status_bit, _status_buffp ) \
  _set_array_bit( _status_bit, (_status_buffp)->b, MAX_IO_PORT_STATUS_BYTES )


/**
 * @brief IO Port Type Status
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_U
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS_IDX
 *
 */
typedef struct
{
  MBG_IO_PORT_STATUS_BUFFER supp_stati; ///< Supported ::MBG_IO_PORT_STATUS_BITS  in ::MBG_IO_PORT_STATUS_BUFFER
  MBG_IO_PORT_STATUS_BUFFER status;     ///< See ::MBG_IO_PORT_STATUS_BUFFER

  uint8_t cfg_counter;                  ///< Updated (increased) when config changes
  uint8_t phys_grp_role;                ///< Physical group role state, see ::MBG_IO_PORT_GRP_ROLE_BITS
  uint8_t log_grp;                      ///< Logical group number (i.e. bond0), or ::MBG_NO_LOG_GROUP
  uint8_t log_grp_role;                 ///< Logical group role (i.e. bond master, bond slave), see ::MBG_IO_PORT_GRP_ROLE_BITS

  uint32_t reserved_2[4];               ///< Future use, currently 0

} MBG_IO_PORT_STATUS;

#define _mbg_port_has_log_group( _p )                    ( ( _p )->log_grp != MBG_NO_LOG_GROUP )

#define _mbg_swab_io_port_status( _p )                   \
do                                                       \
{                                                        \
  _mbg_swab_io_port_status_buffer( &(_p)->supp_stati );  \
  _mbg_swab_io_port_status_buffer( &(_p)->status );      \
} while ( 0 )



/**
 * @brief IO Port Type Status
 *
 * @see @ref group_io_ports
 * @see ::MBG_IO_PORT_SETTINGS_U
 * @see ::MBG_IO_PORT_LIMITS
 * @see ::MBG_IO_PORT_SETTINGS
 * @see ::MBG_IO_PORT_SETTINGS_IDX
 * @see ::MBG_IO_PORT_TYPE_INFO
 * @see ::MBG_IO_PORT_TYPE_INFO_U
 * @see ::MBG_IO_PORT_TYPE_INFO_IDX
 * @see ::MBG_IO_PORT_STATUS
 *
 * Indexes from 0..::MBG_IO_PORT_INFO::num_types - 1 are used
 * to query ::MBG_IO_PORT_TYPE_INFO wrapped in ::MBG_IO_PORT_TYPE_INFO_IDX.
 *
 */
typedef struct
{
  uint32_t idx;
  MBG_IO_PORT_STATUS status;

} MBG_IO_PORT_STATUS_IDX;

#define _mbg_swab_io_port_status_idx( _p )    \
do                                            \
{                                             \
  _mbg_swab32( &(_p)->idx );                  \
  _mbg_swab_io_port_status( &(_p)->status );  \
} while ( 0 )


/** @} defgroup group_io_ports */



/**
 * @defgroup group_monitoring Monitoring / notification
 *
 * @note This structure and its definitions are only supported by a device
 * if ::MBG_XFEATURE_MONITORING is set in the extended device features.
 *
 * TODO: Add proper Doxygen documentation
 *
 * @{ */


#define MBG_MONITORING_STR_SIZE 32

enum MBG_MONITORING_TYPES
{
  MBG_MONITORING_TYPE_SNMP,
  MBG_MONITORING_TYPE_EMAIL,
  MBG_MONITORING_TYPE_SYSLOG,
  N_MBG_MONITORING_TYPES
};

#define MBG_MONITORING_TYPE_STRS    \
{                                   \
  "SNMP",                           \
  "Email",                          \
  "Syslog"                          \
}

enum MBG_MONITORING_TYPE_MSKS
{
  MBG_MONITORING_TYPE_MSK_SNMP = (1UL << MBG_MONITORING_TYPE_SNMP),
  MBG_MONITORING_TYPE_MSK_EMAIL = (1UL << MBG_MONITORING_TYPE_EMAIL),
  MBG_MONITORING_TYPE_MSK_SYSLOG = (1UL << MBG_MONITORING_TYPE_SYSLOG)
};



typedef struct
{
  uint16_t supp_types;                      ///< See ::MBG_MONITORING_TYPE_MSKS
  uint16_t supp_num_events;                 ///< Supported number of events. See ::MBG_EVENT_TYPES
  uint32_t reserved_2[3];

} MBG_MONITORING_LIMITS;

#define _mbg_swab_monitoring_limits( _p )  \
do                                         \
{                                          \
  _mbg_swab16( &(_p)->supp_types );        \
  _mbg_swab16( &(_p)->supp_num_events );   \
} while ( 0 )



/* If ::MBG_MONITORING_TYPE_MSK_SNMP is set in ::MBG_MONITORING_LIMITS::supp_types */

enum MBG_SNMP_VERSIONS
{
  MBG_SNMP_VERSION_V1,
  MBG_SNMP_VERSION_V2c,
  MBG_SNMP_VERSION_V3,
  N_MBG_SNMP_VERSIONS
};

#define MBG_SNMP_VERSION_STRS   \
{                               \
  "Version 1",                  \
  "Version 2c",                 \
  "Version 3"                   \
}

enum MBG_SNMP_VERSION_MSKS
{
  MBG_SNMP_VERSION_MSK_V1 = (1UL << MBG_SNMP_VERSION_V1),
  MBG_SNMP_VERSION_MSK_V2c = (1UL << MBG_SNMP_VERSION_V2c),
  MBG_SNMP_VERSION_MSK_V3 = (1UL << MBG_SNMP_VERSION_V3)
};



typedef struct
{
  uint8_t num_v12_settings;                         ///< Number of configured v1/v2 settings, see ::MBG_SNMP_V12_INFO_IDX
  uint8_t num_v3_settings;                          ///< Number of configured v1/v2 trap receivers, see ::MBG_SNMP_V12_TRAP_INFO_IDX
  uint8_t num_v12_trap_receivers;                   ///< Number of configured v3 settings, see ::MBG_SNMP_V3_INFO_IDX
  uint8_t num_v3_trap_receivers;                    ///< Number of configured v3 trap receivers, see ::MBG_SNMP_V3_TRAP_INFO_IDX
  uint16_t listening_port;                          ///< snmpd listening port, 161 by default
  uint16_t reserved_1;
  uint32_t reserved_2[3];
  char location[MBG_MONITORING_STR_SIZE];
  char contact[MBG_MONITORING_STR_SIZE];
  char name[MBG_MONITORING_STR_SIZE];
  char reserved_3[MBG_MONITORING_STR_SIZE];         ///< Future use
  char reserved_4[MBG_MONITORING_STR_SIZE];         ///< Future use

} MBG_SNMP_GLB_SETTINGS;

#define _mbg_swab_snmp_glb_settings( _p )  \
do                                         \
{                                          \
  _mbg_swab16( &(_p)->listening_port );    \
} while ( 0 )



typedef struct
{
  MBG_SNMP_GLB_SETTINGS settings;
  uint8_t supp_versions;          ///< See ::MBG_SNMP_VERSION_MSKS
  uint8_t max_v12_settings;       ///< Only valid if ::supp_versions contains ::MBG_SNMP_VERSION_MSK_V1 or ::MBG_SNMP_VERSION_MSK_V2c
  uint8_t max_v3_settings;        ///< Only valid if ::supp_versions contains ::MBG_SNMP_VERSION_MSK_V3
  uint8_t max_v12_trap_receivers; ///< Only valid if ::supp_versions contains ::MBG_SNMP_VERSION_MSK_V1 or ::MBG_SNMP_VERSION_MSK_V2c
  uint8_t max_v3_trap_receivers;  ///< Only valid if ::supp_versions contains ::MBG_SNMP_VERSION_MSK_V3
  uint8_t reserved_1[3];
  uint32_t reserved_2[2];

} MBG_SNMP_GLB_INFO;

#define _mbg_swab_snmp_glb_info( _p )               \
do                                                  \
{                                                   \
  _mbg_swab_snmp_glb_settings( &(_p)->settings );   \
} while ( 0 )



enum MBG_SNMP_ACCESS_TYPES
{
  MBG_SNMP_ACCESS_TYPE_RO,
  MBG_SNMP_ACCESS_TYPE_RW,
  N_MBG_SNMP_ACCESS_TYPES
};


#define MBG_SNMP_ACCESS_TYPE_STRS   \
{                                   \
  "Read-only",                      \
  "Read-write"                      \
}



typedef struct
{
  uint8_t version;                  ///< See ::MBG_MONITORING_SNMP_VERSIONS (1 or 2)
  uint8_t access_type;              ///< See ::MBG_SNMP_ACCESS_TYPES, ignore in trap settings
  uint8_t reserved_1[2];
  uint32_t reserved_2[3];
  char community[MBG_MONITORING_STR_SIZE];

} MBG_SNMP_V12_SETTINGS;

#define _mbg_swab_snmp_v12_settings( _p )   \
do                                          \
{                                           \
} while ( 0 )



typedef struct
{
  uint32_t idx;
  MBG_SNMP_V12_SETTINGS settings;

} MBG_SNMP_V12_SETTINGS_IDX;

#define _mbg_swab_snmp_v12_settings_idx( _p )       \
do                                                  \
{                                                   \
  _mbg_swab32( &(_p)->idx );                        \
  _mbg_swab_snmp_v12_settings( &(_p)->settings );   \
} while ( 0 )



typedef struct
{
  MBG_SNMP_V12_SETTINGS settings;
  uint32_t reserved_1[4];

} MBG_SNMP_V12_INFO;

#define _mbg_swab_snmp_v12_info( _p )               \
do                                                  \
{                                                   \
  _mbg_swab_snmp_v12_settings( &(_p)->settings );   \
} while ( 0 )



typedef struct
{
  uint32_t idx;
  MBG_SNMP_V12_INFO info;

} MBG_SNMP_V12_INFO_IDX;

#define _mbg_swab_snmp_v12_info_idx( _p )   \
do                                          \
{                                           \
  _mbg_swab32( &(_p)->idx );                \
  _mbg_swab_snmp_v12_info( &(_p)->info );   \
} while ( 0 )



typedef struct
{
  uint8_t timeout;                            ///< In seconds
  uint8_t retries;
  uint16_t reserved_1;
  uint32_t reserved_2[3];
  char reserved_3[MBG_MONITORING_STR_SIZE];   ///< Future use
  char reserved_4[MBG_MONITORING_STR_SIZE];   ///< Future use
  MBG_SNMP_V12_SETTINGS v12_settings;
  MBG_HOSTNAME receiver_addr;
  uint16_t dest_port;                         ///< receiver destination port, 162 by default
  uint16_t reserved_5;

} MBG_SNMP_V12_TRAP_SETTINGS;

#define _mbg_swab_snmp_v12_trap_settings( _p )          \
do                                                      \
{                                                       \
  _mbg_swab_snmp_v12_settings( &(_p)->v12_settings );   \
  _mbg_swab16( &(_p)->dest_port );                      \
} while ( 0 )



typedef struct
{
  uint32_t idx;
  MBG_SNMP_V12_TRAP_SETTINGS settings;

} MBG_SNMP_V12_TRAP_SETTINGS_IDX;

#define _mbg_swab_snmp_v12_trap_settings_idx( _p )      \
do                                                      \
{                                                       \
  _mbg_swab32( &(_p)->idx );                            \
  _mbg_swab_snmp_v12_trap_settings( &(_p)->settings );  \
} while ( 0 )



typedef struct
{
  MBG_SNMP_V12_TRAP_SETTINGS settings;
  uint32_t reserved_1[4];

} MBG_SNMP_V12_TRAP_INFO;

#define _mbg_swab_snmp_v12_trap_info( _p )              \
do                                                      \
{                                                       \
  _mbg_swab_snmp_v12_trap_settings( &(_p)->settings );  \
} while ( 0 )



typedef struct
{
  uint32_t idx;
  MBG_SNMP_V12_TRAP_INFO info;

} MBG_SNMP_V12_TRAP_INFO_IDX;

#define _mbg_swab_snmp_v12_trap_info_idx( _p )  \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->idx );                    \
  _mbg_swab_snmp_v12_trap_info( &(_p)->info );  \
} while ( 0 )



enum MBG_SNMP_V3_SEC_LEVELS
{
  MBG_SNMP_V3_SEC_LEVEL_NO_AUTH_NO_PRIV,
  MBG_SNMP_V3_SEC_LEVEL_AUTH_NO_PRIV,
  MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV,
  N_MBG_SNMP_V3_SEC_LEVELS
};

#define MBG_SNMP_V3_SEC_LEVEL_STRS  \
{                                   \
  "No auth no priv",                \
  "Auth no priv",                   \
  "Auth priv"                       \
}


enum MBG_SNMP_V3_AUTH_PROTOCOLS
{
  MBG_SNMP_V3_AUTH_PROTOCOL_NONE,
  MBG_SNMP_V3_AUTH_PROTOCOL_MD5,
  MBG_SNMP_V3_AUTH_PROTOCOL_SHA,
  N_MBG_SNMP_V3_AUTH_PROTOCOLS
};

#define MBG_SNMP_V3_AUTH_PROTOCOL_STRS  \
{                                       \
  "None",                               \
  "MD5",                                \
  "SHA"                                 \
}


enum MBG_SNMP_V3_PRIV_PROTOCOLS
{
  MBG_SNMP_V3_PRIV_PROTOCOL_NONE,
  MBG_SNMP_V3_PRIV_PROTOCOL_DES,
  MBG_SNMP_V3_PRIV_PROTOCOL_AES,
  N_MBG_SNMP_V3_PRIV_PROTOCOLS
};


#define MBG_SNMP_V3_PRIV_PROTOCOL_STRS  \
{                                       \
  "None",                               \
  "DES",                                \
  "AES"                                 \
}



typedef struct
{
  uint8_t access_type;                                    ///< See ::MBG_SNMP_ACCESS_TYPES, ignore in trap settings
  uint8_t sec_level;                                      ///< See ::MBG_SNMP_V3_SEC_LEVEL
  uint8_t auth_protocol;                                  ///< See ::MBG_SNMP_V3_AUTH_PROTOCOLS if ::sec_level is
                                                          ///<     ::MBG_SNMP_V3_SEC_LEVEL_AUTH_NO_PRIV or ::MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV
  uint8_t priv_protocol;                                  ///< See ::MBG_SNMP_V3_PRIV_PROTOCOLS if ::sec_level is
                                                          ///<     ::MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV
  uint32_t reserved_1[3];
  char user_name[MBG_MONITORING_STR_SIZE];                ///< Must be set
  char auth_passwd[MBG_MONITORING_STR_SIZE];              ///< Passwd is for user if ::auth_protocol is ::MBG_SNMP_V3_SEC_LEVEL_AUTH_NO_PRIV or ::MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV
  char sec_engine_id[MBG_MONITORING_STR_SIZE];            ///< Mandatory
  char context_engine_id[MBG_MONITORING_STR_SIZE];        ///< Ignore
  char context_name[MBG_MONITORING_STR_SIZE];             ///< Ignore
  char reserved_2[MBG_MONITORING_STR_SIZE];               ///< Future use
  char reserved_3[MBG_MONITORING_STR_SIZE];               ///< Future use
  char priv_passwd[MBG_MONITORING_STR_SIZE];              /// Encryption passwd if ::auth_protocol is ::MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV
  uint32_t boots;                                         ///< Number of system/deamon restarts -> Ignore
  uint32_t time;                                          ///< Timeticks since last "boots" event -> Ignore
  uint32_t reserved_4[2];

} MBG_SNMP_V3_SETTINGS;

#define _mbg_swab_snmp_v3_settings( _p )    \
do                                          \
{                                           \
  _mbg_swab32( &(_p)->boots );              \
  _mbg_swab32( &(_p)->time );               \
} while ( 0 )



typedef struct
{
  uint32_t idx;
  MBG_SNMP_V3_SETTINGS settings;

} MBG_SNMP_V3_SETTINGS_IDX;

#define _mbg_swab_snmp_v3_settings_idx( _p )        \
do                                                  \
{                                                   \
  _mbg_swab32( &(_p)->idx );                        \
  _mbg_swab_snmp_v3_settings( &(_p)->settings );    \
} while ( 0 )



typedef struct
{
  MBG_SNMP_V3_SETTINGS settings;
  uint32_t reserved_1[4];

} MBG_SNMP_V3_INFO;

#define _mbg_swab_snmp_v3_info( _p )                \
do                                                  \
{                                                   \
  _mbg_swab_snmp_v3_settings( &(_p)->settings );    \
} while ( 0 )



typedef struct
{
  uint32_t idx;
  MBG_SNMP_V3_INFO info;

} MBG_SNMP_V3_INFO_IDX;

#define _mbg_swab_snmp_v3_info_idx( _p )    \
do                                          \
{                                           \
  _mbg_swab32( &(_p)->idx );                \
  _mbg_swab_snmp_v3_info( &(_p)->info );    \
} while ( 0 )



typedef struct
{
  uint8_t timeout;                      ///< In seconds
  uint8_t retries;
  uint8_t reserved_1[2];
  uint32_t reserved_2[3];
  MBG_SNMP_V3_SETTINGS v3_settings;
  MBG_HOSTNAME receiver_addr;
  uint16_t dest_port;                   ///< receiver destination port, 162 by default
  uint16_t reserved_3;

} MBG_SNMP_V3_TRAP_SETTINGS;

#define _mbg_swab_snmp_v3_trap_settings( _p )        \
do                                                   \
{                                                    \
  _mbg_swab_snmp_v3_settings( &(_p)->v3_settings );  \
  _mbg_swab16( &(_p)->dest_port );                   \
} while ( 0 )



typedef struct
{
  uint32_t idx;
  MBG_SNMP_V3_TRAP_SETTINGS settings;

} MBG_SNMP_V3_TRAP_SETTINGS_IDX;

#define _mbg_swab_snmp_v3_trap_settings_idx( _p )       \
do                                                      \
{                                                       \
  _mbg_swab32( &(_p)->idx );                            \
  _mbg_swab_snmp_v3_trap_settings( &(_p)->settings );   \
} while ( 0 )



typedef struct
{
  MBG_SNMP_V3_TRAP_SETTINGS settings;
  uint32_t reserved_1[4];

} MBG_SNMP_V3_TRAP_INFO;

#define _mbg_swab_snmp_v3_trap_info( _p )              \
do                                                     \
{                                                      \
  _mbg_swab_snmp_v3_trap_settings( &(_p)->settings );  \
} while ( 0 )



typedef struct
{
  uint32_t idx;
  MBG_SNMP_V3_TRAP_INFO info;

} MBG_SNMP_V3_TRAP_INFO_IDX;

#define _mbg_swab_snmp_v3_trap_info_idx( _p )   \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->idx );                    \
  _mbg_swab_snmp_v3_trap_info( &(_p)->info );   \
} while ( 0 )



enum MBG_EVENT_TYPES
{
  MBG_EVENT_TYPE_NTP_STOPPED,
  MBG_EVENT_TYPE_NTP_NOT_SYNC,
  MBG_EVENT_TYPE_NTP_SYNC,
  MBG_EVENT_TYPE_LINK_DOWN,
  MBG_EVENT_TYPE_LINK_UP,
  MBG_EVENT_TYPE_HEARTBEAT,
  N_MBG_EVENT_TYPES
};

#define MBG_EVENT_TYPE_STRS  \
{                            \
  "NTP stopped",             \
  "NTP not synchronized",    \
  "NTP synchronized",        \
  "Network link down",       \
  "Network link up",         \
  "Heartbeat"                \
}

enum MBG_EVENT_SEVERITIES
{
  MBG_EVENT_SEVERITY_CRITICAL,
  MBG_EVENT_SEVERITY_ERROR,
  MBG_EVENT_SEVERITY_WARNING,
  MBG_EVENT_SEVERITY_INFO,
  MBG_EVENT_SEVERITY_SUCCESS,
  N_MBG_EVENT_SEVERITIES
};

#define MBG_EVENT_SEVERITY_STRS  \
{                                \
  "Critical",                    \
  "Error",                       \
  "Warning",                     \
  "Info",                        \
  "Success"                      \
}

enum MBG_EVENT_SEVERITY_MSKS
{
  MBG_EVENT_SEVERITY_MSK_CRITICAL = (1UL << MBG_EVENT_SEVERITY_CRITICAL),
  MBG_EVENT_SEVERITY_MSK_ERROR = (1UL << MBG_EVENT_SEVERITY_ERROR),
  MBG_EVENT_SEVERITY_MSK_WARNING = (1UL << MBG_EVENT_SEVERITY_WARNING),
  MBG_EVENT_SEVERITY_MSK_INFO = (1UL << MBG_EVENT_SEVERITY_INFO),
  MBG_EVENT_SEVERITY_MSK_SUCCESS = (1UL << MBG_EVENT_SEVERITY_SUCCESS)
};

typedef struct
{
  uint8_t severity;         ///< See ::MBG_EVENT_SEVERITIES
  uint8_t reserved_1;
  uint16_t triggers;        ///< See ::MBG_MONITORING_TYPE_MSKS if set in ::MBG_MONITORING_LIMITS::supp_types
  uint16_t interval;        ///< In seconds if ::MBG_EVENT_FLAG_MSK_INTERVAL is set in ::MBG_EVENT_INFO::supp_flags. 0 otherwise
  uint16_t reserved_2;
  uint32_t reserved_3[6];

} MBG_EVENT_SETTINGS;

#define _mbg_swab_event_settings( _p )          \
do                                              \
{                                               \
  _mbg_swab16( &(_p)->triggers );               \
  _mbg_swab16( &(_p)->interval );               \
} while ( 0 )



/**
 * @brief Structure for monitoring event settings
 *
 * @see ::MBG_EVENT_INFO_IDX
 */
typedef struct
{
  uint32_t idx;
  MBG_EVENT_SETTINGS settings;

} MBG_EVENT_SETTINGS_IDX;

#define _mbg_swab_event_settings_idx( _p )      \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->idx );                    \
  _mbg_swab_event_settings( &(_p)->settings );  \
} while ( 0 )



enum MBG_EVENT_SUPP_FLAGS
{
  MBG_EVENT_SUPP_FLAG_INTERVAL,      ///< Event can be sent cyclical
  N_MBG_EVENT_SUPP_FLAGS
};


enum MBG_EVENT_SUPP_FLAG_MSKS
{
  MBG_EVENT_SUPP_FLAG_MSK_INTERVAL = ( 1UL << MBG_EVENT_SUPP_FLAG_INTERVAL )
};



enum MBG_EVENT_FLAGS
{
  MBG_EVENT_FLAG_NOT_AVAIL,          ///< Event is currently not available, i.e. card in slot has been removed
  N_MBG_EVENT_FLAGS
};


enum MBG_EVENT_FLAG_MSKS
{
  MBG_EVENT_FLAG_MSK_NOT_AVAIL = ( 1UL << MBG_EVENT_FLAG_NOT_AVAIL )
};

#define MBG_OWN_EVENT_CHASSIS               0xFF
#define MBG_OWN_EVENT_SLOT                  0xFF
#define MBG_INV_EVENT_PORT                  0xFF



typedef struct
{
  MBG_EVENT_SETTINGS settings;
  uint16_t type;                            ///< See ::MBG_EVENT_TYPES
  uint8_t chassis_idx;                      ///< Index of the associated IMS chassis
  uint8_t slot_idx;                         ///< Index of the associated IMS slot
  uint8_t port_idx;                         ///< Index of the associated IO port
  uint8_t reserved_1;                       ///< Reserved, currently 0
  uint16_t reserved_2;                      ///< Reserved, currently 0

  uint16_t supp_severities;                 ///< See ::MBG_EVENT_SEVERITY_MSKS
  uint16_t supp_flags;                      ///< See ::MBG_EVENT_SUPP_FLAG_MSKS
  uint16_t supp_triggers;                   ///< See ::MBG_MONITORING_TYPE_MSKS
  uint16_t flags;                           ///< See ::MBG_EVENT_FLAG_MSKS

  uint32_t reserved_3[4];

} MBG_EVENT_INFO;

#define _mbg_swab_event_info( _p )              \
do                                              \
{                                               \
  _mbg_swab_event_settings( &(_p)->settings );  \
  _mbg_swab16( &(_p)->type );                   \
  _mbg_swab16( &(_p)->supp_severities );        \
  _mbg_swab16( &(_p)->supp_flags );             \
  _mbg_swab16( &(_p)->supp_triggers );          \
  _mbg_swab16( &(_p)->flags );                  \
} while ( 0 )



/**
 * @brief Structure for monitoring event info
 *
 * @note idx represents the event type, see ::MBG_EVENT_TYPES
 * Before requesting the struct, its availability should be checked
 * in ::MBG_MONITORING_LIMITS::supp_events.
 *
 * @see ::MBG_EVENT_TYPES
 * @see ::MBG_MONITORING_LIMITS
 */
typedef struct
{
  uint32_t idx;
  MBG_EVENT_INFO info;

} MBG_EVENT_INFO_IDX;

#define _mbg_swab_event_info_idx( _p )          \
do                                              \
{                                               \
  _mbg_swab32( &(_p)->idx );                    \
  _mbg_swab_event_info( &(_p)->info );          \
} while ( 0 )



typedef struct
{
  uint8_t snmp_cfg_counter;         ///< Updated (increased) when SNMP config changes
  uint8_t email_cfg_counter;        ///< Updated (increased) when Email config changes
  uint8_t syslog_cfg_counter;       ///< Updated (increased) when Syslog config changes
  uint8_t event_cfg_counter;        ///< Updated (increased) when event config changes
  uint32_t reserved_2[3];

} MBG_MONITORING_STATUS;

#define _mbg_swab_monitoring_status( _p )       \
do                                              \
{                                               \
} while ( 0 )



enum MBG_EVENT_STATUS_FLAGS
{
  MBG_EVENT_STATUS_FLAG_ACTIVE,      ///< Event is currently active
  N_MBG_EVENT_STATUS_FLAGS
};


enum MBG_EVENT_STATUS_FLAG_MSKS
{
  MBG_EVENT_STATUS_FLAG_MSK_ACTIVE = (1UL << MBG_EVENT_STATUS_FLAG_ACTIVE)
};



typedef struct
{
  uint16_t flags;                           ///< See ::MBG_EVENT_STATUS_FLAGS
  uint16_t reserved_1;
  uint32_t last_triggered;                  ///< Unix timestamp when this event has been triggered
  uint32_t reserved_2[6];

} MBG_EVENT_STATUS;

#define _mbg_swab_event_status( _p )            \
do                                              \
{                                               \
  _mbg_swab16( &(_p)->flags );                  \
  _mbg_swab32( &(_p)->last_triggered );         \
} while ( 0 )



typedef struct
{
  uint16_t idx;
  MBG_EVENT_STATUS status;

} MBG_EVENT_STATUS_IDX;

#define _mbg_swab_event_status_idx( _p )        \
do                                              \
{                                               \
  _mbg_swab16( &(_p)->idx );                    \
  _mbg_swab_event_status( &(_p)->status );      \
} while ( 0 )

/** @} defgroup group_monitoring */


/**
 * @defgroup group_usb_lock
 *
 * @note This structure and its definitions are only supported by a device
 * if ::MBG_XFEATURE_USB_LOCK is set in the extended device features.
 * Feature can electrically disconnect an USB slave device from
 * the USB host bus. It cannot be reset via software, it's a one way action only.
 *
 * TODO: Add proper Doxygen documentation
 *
 * @{ */


enum MBG_USB_LOCK_FLAGS
{
  MBG_USB_LOCK_FLAG_ACTIVE,     ///< USB Connection is interrupted
  N_MBG_USB_LOCK_FLAGS
};


enum MBG_USB_LOCK_FLAG_MSKS
{
  MBG_USB_LOCK_FLAG_MSK_ACTIVE = (1UL << MBG_USB_LOCK_FLAG_ACTIVE)      ///< See ::MBG_USB_LOCK_FLAG_ACTIVE
};


typedef struct
{
  uint8_t flags;                ///< ::MBG_USB_LOCK_FLAG_MSKS
  uint8_t reserved_1[3];
  uint32_t reserved_2[3];

} MBG_USB_LOCK_SETTINGS;

#define _mbg_swab_usb_lock_settings( _p )   do {} while ( 0 )


typedef struct
{
  MBG_USB_LOCK_SETTINGS settings;
  uint8_t supp_flags;           ///< ::MBG_USB_LOCK_FLAG_MSKS
  uint8_t reserved_1[3];
  uint32_t reserved_2[3];

} MBG_USB_LOCK_INFO;

#define _mbg_swab_usb_lock_info( _p )       \
do                                          \
{                                           \
    _mbg_swab_usb_lock_settings( _p );      \
} while ( 0 )


typedef struct
{
  uint8_t flags;                ///< ::MBG_USB_LOCK_FLAG_MSKS
  uint8_t reserved_1[3];
  uint32_t reserved_2[3];

} MBG_USB_LOCK_STATUS;

#define _mbg_swab_usb_lock_status( _p )   do {} while ( 0 )


/** @} defgroup group_usb_lock */


#if defined( _USING_BYTE_ALIGNMENT )
  #pragma pack()      // set default alignment
  #undef _USING_BYTE_ALIGNMENT
#endif

/* End of header body */

#endif  /* _GPSDEFS_H */