[r3527]: branches / Gxsm-2x3-transition-sig / plug-ins / hard / sranger_mk3_hwi_dev.C Maximize Restore History

Download this file

sranger_mk3_hwi_dev.C    3480 lines (2983 with data), 132.2 kB

   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
/* Gxsm - Gnome X Scanning Microscopy
* universal STM/AFM/SARLS/SPALEED/... controlling and
* data analysis software
*
* Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
*
* Authors: Percy Zahl <zahl@users.sf.net>
* additional features: Andreas Klust <klust@users.sf.net>
* WWW Home: http://gxsm.sf.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
/* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
/* irnore this module for docuscan
% PlugInModuleIgnore
*/
#include <locale.h>
#include <libintl.h>
#include <time.h>
#include <climits> // for limits macrors
#include <iomanip> // for setfill, setprecision, setw
#include <ios> // for dec, hex, oct, showbase, showpos, etc.
#include <iostream> // for cout
#include <sstream> // for istringstream
#include "glbvars.h"
#include "xsmtypes.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include "sranger_mk3_hwi.h"
// you may want to handle/emulate some DSP commands later...
#include "dsp-pci32/xsm/dpramdef.h"
#include "dsp-pci32/xsm/xsmcmd.h"
// need some SRanger io-controls
// HAS TO BE IDENTICAL TO THE DRIVER's FILE!
// so far the same for mk2 and mk3
#include "../plug-ins/hard/modules/sranger_mk23_ioctl.h"
// SRanger data exchange structs and consts
#include "MK3-A810_spmcontrol/FB_spm_dataexchange.h"
#ifdef __SRANGER_MK3_DSP_SIGNALS_H
#undef __SRANGER_MK3_DSP_SIGNALS_H
#endif
#define CREATE_DSP_SIGNAL_LOOKUP
#include "MK3-A810_spmcontrol/dsp_signals.h"
// enable debug:
#define SRANGER_DEBUG(S) XSM_DEBUG (DBG_L4, S)
#define SRANGER_ERROR(S) XSM_DEBUG_ERROR (DBG_L4, S)
#define SR_READFIFO_RESET -1
#define SR_EMPTY_PROBE_FIFO -2
extern DSPControl *DSPControlClass;
extern GxsmPlugin sranger_mk2_hwi_pi;
extern DSPPACControl *DSPPACClass;
// some thread states
#define RET_FR_OK 0
#define RET_FR_ERROR -1
#define RET_FR_WAIT 1
#define RET_FR_NOWAIT 2
#define RET_FR_FCT_END 3
#define FR_NO 0
#define FR_YES 1
#define FR_INIT 1
#define FR_FINISH 2
#define FR_FIFO_FORCE_RESET 3
#define CONST_DSP_F16 65536.
#define VOLT2AIC(U) (int)(gapp->xsm->Inst->VoltOut2Dig (gapp->xsm->Inst->BiasV2V (U)))
gpointer FifoReadThread3 (void *ptr_sr);
gpointer ProbeFifoReadThread3 (void *ptr_sr);
gpointer ProbeFifoReadFunction3 (void *ptr_sr, int dspdev);
/* Construktor for Gxsm sranger support base class
* ==================================================
* - open device
* - init things
* - ...
*/
sranger_mk3_hwi_dev::sranger_mk3_hwi_dev(){
SRANGER_DEBUG("open driver");
g_print ("HWI-DEV-MK3-I** HwI SR-MK3 probing\n");
AIC_max_points = 1<<15; // SR-AIC resolution is limiting...
fifo_read_thread = NULL;
probe_fifo_read_thread = NULL;
probe_fifo_thread_active = FALSE;
thread_dsp = 0;
productid = g_strdup ("not yet identified");
swap_flg = 0;
magic_data.magic = 0; // set to zero, this means all data is invalid!
dsp_alternative = 0;
target = SR_HWI_TARGET_NONE;
sranger_mark_id = -2;
// just this as reference is set to NULL as indicatior all pll refs need to be read from DSP first.
dsp_pll.volumeSine = 0;
dsp=0;
thread_dsp=0;
probe_thread_dsp=0;
dsp_alternative=0;
bz_statistics[0]=0;
bz_statistics[1]=0;
bz_statistics[2]=0;
bz_statistics[3]=0;
bz_statistics[4]=0;
gint srdev_index_start = atoi ( strrchr (xsmres.DSPDev, '_')+1); // start at given device, keep looking for higher numbers
while (srdev_index_start >= 0 && srdev_index_start < 8) {
sprintf (xsmres.DSPDev,"/dev/sranger_mk2_%d", srdev_index_start); // override
g_print ("Looking for MK3 with runnign GXSM compatible FB_spmcontrol DSP code starting at %s\n", xsmres.DSPDev);
if((dsp = open (xsmres.DSPDev, O_RDWR)) <= 0){
g_print ("HWI-DEV-MK3-E01-- can not open device >%s<, please check permissions. \nError: %s\n",
xsmres.DSPDev, strerror(errno));
dsp = 0;
if (++srdev_index_start < 8){
g_print ("HWI-DEV-MK3-MSG01-- Continue searching for next device...\n");
continue;
}
SRANGER_ERROR(
"Can�t open <" << xsmres.DSPDev << ">, reason: " << strerror(errno) << std::endl
<< "please make sure:" << std::endl
<< "-> that the device exists and has proper access rights" << std::endl
<< "-> that the kernel module loaded" << std::endl
<< "-> the USB connection to SignalRanger" << std::endl
<< "-> that the SR-MK2/3 is powered on");
productid=g_strdup_printf ("Device used: %s\n\n"
"Make sure:\n"
"-> that the device exists and has proper access rights\n"
"-> that the kernel module loaded (try 'dmesg')\n"
"-> the USB connection to SignalRanger is OK\n"
"-> that the SR-MK2/3 is powered on\n"
"Start 'gxsm2 -h no' to change the device path/name.",
xsmres.DSPDev);
gapp->alert (N_("No Hardware"), N_("Open Device failed."), productid, 1);
exit (-1);
return;
}
else{
int ret;
unsigned int vendor, product;
if ((ret=ioctl(dsp, SRANGER_MK2_IOCTL_VENDOR, (unsigned long)&vendor)) < 0){
SRANGER_ERROR(strerror(ret) << " cannot query VENDOR" << std::endl
<< "Device: " << xsmres.DSPDev);
g_free (productid);
productid=g_strdup_printf ("Device used: %s\n Start 'gxsm2 -h no' to correct the problem.", xsmres.DSPDev);
gapp->alert (N_("Unkonwn Hardware"), N_("Query Vendor ID failed."), productid, 1);
g_print ("HWI-DEV-MK3-E02-- unkown hardware, vendor ID mismatch.\n");
close (dsp);
dsp = 0;
exit (-1);
return;
}
if ((ret=ioctl(dsp, SRANGER_MK2_IOCTL_PRODUCT, (unsigned long)&product)) < 0){
SRANGER_ERROR(strerror(ret) << " cannot query PRODUCT" << std::endl
<< "Device: " << xsmres.DSPDev);
g_free (productid);
productid=g_strdup_printf ("Device used: %s\n Start 'gxsm2 -h no' to correct the problem.", xsmres.DSPDev);
gapp->alert (N_("Unkonwn Hardware"), N_("Query Product ID failed."), productid, 1);
g_print ("HWI-DEV-MK3-E03-- unkown hardware, product ID mismatch.\n");
close (dsp);
dsp = 0;
return;
}
if (vendor == 0x0a59 || vendor == 0x1612){
g_free (productid);
if (vendor == 0x0a59 && product == 0x0101){
productid=g_strdup ("Vendor/Product: B.Paillard, Signal Ranger STD");
gapp->alert (N_("Wrong Hardware detected"), N_("No MK2 found."), productid, 1);
g_print ("HWI-DEV-MK3-E04-- wrong hardware: SR-STD, please use SR-SP2/STD HwI.\n");
target = SR_HWI_TARGET_C54;
close (dsp);
dsp=0;
exit (-1);
return;
}
else if (vendor == 0x0a59 && product == 0x0103){
productid=g_strdup ("Vendor/Product: B.Paillard, Signal Ranger SP2");
gapp-> alert (N_("Wrong Hardware detected"), N_("No MK2 found."), productid, 1);
g_print ("HWI-DEV-MK3-E05-- wrong hardware: SR-SP2, please use SR-SP2/STD HwI.\n");
target = SR_HWI_TARGET_C54;
close (dsp);
dsp=0;
exit (-1);
return;
}else if (vendor == 0x1612 && product == 0x0100){
productid=g_strdup ("Vendor/Product: B.Paillard, Signal Ranger MK2 (1612:0100)");
g_print ("HWI-DEV-MK3-I01-- SR-MK2 1612:0100 found (autoprobe continue).\n");
target = SR_HWI_TARGET_C55;
close (dsp);
dsp=0;
return;
}else if (vendor == 0x1612 && product == 0x0101){
productid=g_strdup ("Vendor/Product: B.Paillard, Signal Ranger MK2-NG (1612:0101)");
g_print ("HWI-DEV-MK3-I02-- SR-MK2-NG 1612:0101 found (autoprobe continue).\n");
target = SR_HWI_TARGET_C55;
close (dsp);
dsp=0;
return;
}else if (vendor == 0x1612 && product == 0x0103){
productid=g_strdup ("Vendor/Product: B.Paillard, Signal Ranger MK3 (1612:0103)");
g_print ("HWI-DEV-MK3-I03-- SR-MK3-NG 1612:0103 found -- OK, taking it.\n");
target = SR_HWI_TARGET_C55;
sranger_mark_id = 3;
}else{
productid=g_strdup ("Vendor/Product: B.Paillard, unkown version!");
gapp->alert (N_("Unkonwn Hardware detected"), N_("No Signal Ranger found."), productid, 1);
g_print ("HWI-DEV-MK3-E06-- SR-MK?? 1612:%s found -- not supported.\n", productid);
close (dsp);
dsp=0;
return;
}
g_print ("HWI-DEV-MK3-I** reading DSP magic informations and code version.\n");
// now read magic struct data
lseek (dsp, FB_SPM_MAGIC_ADR, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &magic_data, sizeof (magic_data));
swap_flg = 0;
g_print ("HWI-DEV-MK3-I*CPU* DSP-MAGIC : %08x [M:%08x]\n", magic_data.magic, FB_SPM_MAGIC);
if (magic_data.magic != FB_SPM_MAGIC){
close (dsp);
dsp=0;
SRANGER_DEBUG ("Wrong Magic");
g_print ("HWI-DEV-MK3-I** weird endianess of host (PPC?) not support yet.\n");
++srdev_index_start;
if (srdev_index_start < 8)
continue; // auto attempt to try next board if any
exit (-1);
return;
}
g_print ("HWI-DEV-MK3-I*CPU* DSP-SoftId : %08x [HwI:%08x]\n", magic_data.dsp_soft_id, FB_SPM_SOFT_ID);
g_print ("HWI-DEV-MK3-I*CPU* DSP-Version: %08x [HwI:%08x]\n", magic_data.version, FB_SPM_VERSION);
if (FB_SPM_VERSION != magic_data.version ||
FB_SPM_SOFT_ID != magic_data.dsp_soft_id){
gchar *details = g_strdup_printf(
"Detected SRanger DSP Software Version: %x.%02x\n"
"GXSM was build for DSP Software Version: %x.%02x\n\n"
"Note: This may cause incompatility problems and unpredictable toubles,\n"
"however, trying to proceed in case you know what you are doing.\n\n"
"SwapFlag: %d Target: %d\n",
magic_data.version >> 8,
magic_data.version & 0xff,
FB_SPM_VERSION >> 8,
FB_SPM_VERSION & 0xff,
swap_flg, target)
SRANGER_DEBUG ("Signal Ranger FB_SPM soft Version mismatch\n" << details);
g_print ("HWI-DEV-MK3-VW01-- DSP software version mismatch warning.\n%s\n", details);
gapp->alert (N_("Warning"), N_("Signal Ranger FB_SPM software version mismatch detected!"), details, 1);
g_free (details);
}
SRANGER_DEBUG ("ProductId:" << productid);
// open some more DSP connections, used by threads
if((thread_dsp = open (xsmres.DSPDev, O_RDWR)) <= 0){
SRANGER_ERROR ("cannot open thread SR connection, trying to continue...");
g_print ("HWI-DEV-MK3-OTE01-- open multi dev error, can not generate thread DSP link.\n");
thread_dsp = 0;
}
// testing...
if((probe_thread_dsp = open (xsmres.DSPDev, O_RDWR)) <= 0){
SRANGER_ERROR ("cannot open probe thread SR connection, trying to continue...");
g_print ("HWI-DEV-MK3-OTE02-- open multi dev error, can not generate probe DSP link.\n");
probe_thread_dsp = 0;
}
if((dsp_alternative = open (xsmres.DSPDev, O_RDWR)) <= 0){
SRANGER_ERROR ("cannot open alternative SR connection, trying to continue...");
g_print ("HWI-DEV-MK3-OTE03-- open multi dev error, can not generate alternate DSP link.\n");
dsp_alternative = 0;
}
}else{
SRANGER_ERROR ("unkown vendor, exiting");
g_print ("HWI-DEV-MK3-E07-- Unkown Device Vendor ID.\n");
close (dsp);
dsp = 0;
return;
}
}
break;
}
// verify / autocorrect and notify about channel configurations needed for MK2-A810 in HR mode
{
int f=0;
GString *details = g_string_new ("\n==> Auto Adjustments done:\n\n");
for (int i=0; i<PIDCHMAX; ++i)
if (strncmp (xsmres.pidsrcZtype[i], "FLOAT", 5)){
g_string_append_printf (details, "DataAq/PIDSrcA%d-ZType=%s -> FLOAT [MK2-%s]\n", i+1, xsmres.pidsrcZtype[i], i==0?"Z_HR":"N/A");
strcpy (xsmres.pidsrcZtype[i], "FLOAT");
f=1;
}
for (int i=0; i<8; ++i)
if (strncmp (xsmres.daqZtype[i], "FLOAT", 5)){
g_string_append_printf (details, "DataAq/DataSrc%s%d-ZType=%s -> FLOAT [A810-ADC%d]\n", i<4?"A":"B", i%4+1, xsmres.daqZtype[i], i);
strcpy (xsmres.daqZtype[i], "FLOAT");
f=1;
}
for (int i=8; i<DAQCHMAX; ++i)
if (strncmp (xsmres.daqZtype[i], "FLOAT", 4)){
g_string_append_printf (details, "DataAq/DataSrc%c1-ZType=%s -> FLOAT [MK2-Data%d]\n", 'C'+i-8, xsmres.daqZtype[i], i);
strcpy (xsmres.daqZtype[i], "LONG");
f=1;
}
if (f){
g_string_append_printf (details, "\n\nPLEASE VERIFY YOUR PREFERENCES!");
gapp->alert (N_("Warning"), N_("MK2-A810 DataAq Preferences Setup Verification"), details->str, 1);
g_print ("HWI-DEV-MK3-WW00A-- configuration/preferences mismatch with current hardware setup -- please adjust.\n");
}
g_string_free(details, TRUE);
details=NULL;
}
}
/* Destructor
* close device
*/
sranger_mk3_hwi_dev::~sranger_mk3_hwi_dev(){
SRANGER_DEBUG ("closing connection to SRanger driver");
if (dsp) close (dsp);
if (thread_dsp) close (thread_dsp);
if (probe_thread_dsp) close (probe_thread_dsp);
if (dsp_alternative) close (dsp_alternative);
if (productid) g_free (productid);
}
// data translation helpers
void sranger_mk3_hwi_dev::swap (guint16 *addr){
guint16 temp1, temp2;
temp1 = temp2 = *addr;
*addr = ((temp2 & 0xFF) << 8) | ((temp1 >> 8) & 0xFF);
}
void sranger_mk3_hwi_dev::swap (gint16 *addr){
guint16 temp1, temp2;
temp1 = temp2 = *addr;
*addr = ((temp2 & 0xFF) << 8) | ((temp1 >> 8) & 0xFF);
}
void sranger_mk3_hwi_dev::swap (gint32 *addr){
gint32 temp1, temp2, temp3, temp4;
temp1 = (*addr) & 0xFF;
temp2 = (*addr >> 8) & 0xFF;
temp3 = (*addr >> 16) & 0xFF;
temp4 = (*addr >> 24) & 0xFF;
if (target == SR_HWI_TARGET_C55)
*addr = (temp3 << 24) | (temp4 << 16) | (temp1 << 8) | temp2;
else // can assume so far else is: if (target == SR_HWI_TARGET_C54)
*addr = (temp1 << 24) | (temp2 << 16) | (temp3 << 8) | temp4;
}
gint32 sranger_mk3_hwi_dev::float_2_sranger_q15 (double x){
if (x >= 1.)
return 32767;
if (x <= -1.)
return -32766;
return (gint32)(x*32767.);
}
// 1<<31 = 2147483648
gint32 sranger_mk3_hwi_dev::float_2_sranger_q31 (double x){
if (x >= 1.)
return 0x7FFFFFFF;
if (x <= -1.)
return -0x7FFFFFFE;
return (gint32)round(x*2147483647.);
}
gint32 sranger_mk3_hwi_dev::int_2_sranger_int (gint32 x){
gint16 tmp = x > 32767 ? 32767 : x < -32766 ? -32766 : x; // saturate
#if 0
if (swap_flg)
swap (&tmp);
#endif
return (gint32)tmp;
}
guint32 sranger_mk3_hwi_dev::uint_2_sranger_uint (guint32 x){
guint16 tmp = x > 0xffff ? 0xffff : x < 0 ? 0 : x; // saturate
#if 0
if (swap_flg)
swap (&tmp);
#endif
return (guint32)tmp;
}
gint32 sranger_mk3_hwi_dev::long_2_sranger_long (gint32 x){
#if 0
if (swap_flg){
swap (&x);
return x;
}
if (target == SR_HWI_TARGET_C55){
gint32 temp0, temp1, temp2, temp3;
gchar x32[4];
temp0 = (x) & 0xFF;
temp1 = (x >> 8) & 0xFF;
temp2 = (x >> 16) & 0xFF;
temp3 = (x >> 24) & 0xFF;
x32[0] = temp2;
x32[1] = temp3;
x32[2] = temp0;
x32[3] = temp1;
x = *((gint32*)x32);
return x;
} else
return x;
#else
return x;
#endif
}
// Image Data FIFO read thread section
// ==================================================
// start_fifo_read:
// Data Transfer Setup:
// Prepare and Fork Image Data FIFO read thread
int sranger_mk3_hwi_dev::start_fifo_read (int y_start,
int num_srcs0, int num_srcs1, int num_srcs2, int num_srcs3,
Mem2d **Mob0, Mem2d **Mob1, Mem2d **Mob2, Mem2d **Mob3){
if (num_srcs0 || num_srcs1 || num_srcs2 || num_srcs3){
fifo_data_num_srcs[0] = num_srcs0;
fifo_data_num_srcs[1] = num_srcs1;
fifo_data_num_srcs[2] = num_srcs2;
fifo_data_num_srcs[3] = num_srcs3;
fifo_data_Mobp[0] = Mob0;
fifo_data_Mobp[1] = Mob1;
fifo_data_Mobp[2] = Mob2;
fifo_data_Mobp[3] = Mob3;
fifo_data_y_index = y_start; // if > 0, scan dir is "bottom-up"
// depricated
// fifo_read_thread = g_thread_create (FifoReadThread3, this, FALSE, NULL);
// works but only from glib 2.32
fifo_read_thread = g_thread_new ("FifoReadThread3", FifoReadThread3, this);
if ((DSPControlClass->Source & 0xffff) && DSPControlClass->probe_trigger_raster_points > 0){
DSPControlClass->probe_trigger_single_shot = 0;
ReadProbeFifo (thread_dsp, FR_FIFO_FORCE_RESET); // reset FIFO
ReadProbeFifo (thread_dsp, FR_INIT); // init
}
}
else{
if (DSPControlClass->vis_Source & 0xffff)
// probe_fifo_read_thread = g_thread_create (ProbeFifoReadThread3, this, FALSE, NULL);
probe_fifo_read_thread = g_thread_new ("ProbeFifoReadThread3", ProbeFifoReadThread3, this);
}
return 0;
}
// FifoReadThread3:
// Image Data FIFO read thread
gpointer FifoReadThread3 (void *ptr_sr){
sranger_mk3_hwi_dev *sr = (sranger_mk3_hwi_dev*)ptr_sr;
int ny = sr->fifo_data_Mobp[sr->fifo_data_num_srcs[0] ? 0:1][0]->GetNy();
SRANGER_DEBUG ("Starting Fifo Read, reading " << ny << " lines, " << "y_index: " << sr->fifo_data_y_index);
// This delay is to avoid some not yet exploited initial fifo-reading delay and unnecessary early fifo overflow - PZ
// usleep(2000000); // wait for GUI stuff to get ready, empiric -- 4s
sr->ReadLineFromFifo (SR_READFIFO_RESET); // init read fifo status
if (sr->fifo_data_y_index == 0){ // top-down
for (int yi=0; yi < ny; ++yi)
if (sr->ReadLineFromFifo (yi))
break;
}else{ // bottom-up
for (int yi=ny-1; yi >= 0; --yi)
if (sr->ReadLineFromFifo (yi))
break;
}
sr->ReadLineFromFifo (SR_EMPTY_PROBE_FIFO); // finish reading all FIFO's (probe may have to be emptied)
SRANGER_DEBUG ("Fifo Read Done.");
std::cout << "BZ DATA STATISTICS: [8: " << sr->bz_statistics[0]
<< ", 16:" << sr->bz_statistics[1]
<< ", 24:" << sr->bz_statistics[2]
<< ", 32:" << sr->bz_statistics[3]
<< ", ST:" << sr->bz_statistics[4]
<< "]" << std::endl;
return NULL;
}
// ReadLineFromFifo:
// read scan line from FIFO -- wait for data, and empty FIFO as quick as possible,
// sort data chunks away int scan-mem2d objects
int sranger_mk3_hwi_dev::ReadLineFromFifo (int y_index){
static int len[4] = { 0,0,0,0 };
static int total_len = 0;
static int fifo_reads = 0;
static DATA_FIFO_MK3 dsp_fifo;
static double max_fill = 0.;
static int fifo_fill_delay = 0;
int xi;
static int readfifo_status = 0;
static int rpos_tmp=0;
static int wpos_tmp=0;
static int fifo_fill=0;
static GTimer *gt=NULL;
static useconds_t fifo_read_sleep_us=500;
// SRANGER_DEBUG ("ReadData: yindex=" << y_index << "---------------------------");
// std::cout << "ReadLineFromFifo:" << y_index << std::endl;
// initiate and unlock scan process now!
if (y_index == SR_READFIFO_RESET){
for (int i=0; i<BZ_MAX_CHANNELS; ++i) bz_last[i] = 0L;
max_fill = 0.;
bz_byte_pos = 0;
bz_scale = 1.;
bz_dsp_srcs = 0;
bz_dsp_ns = 0;
bz_push_mode = 0;
rpos_tmp=0;
wpos_tmp=0;
fifo_fill=0;
for (int i=0; i<5; ++i) bz_statistics[i]=0;
readfifo_status = 0;
fifo_block = 0;
fifo_read_sleep_us=500;
if (gt)
g_timer_reset (gt);
else
gt = g_timer_new ();
g_timer_start (gt);
return 0;
}
// finish reading all FIFO's (probe may have to be emptied)
if (y_index == SR_EMPTY_PROBE_FIFO){
// check probe fifo
if (DSPControlClass->probe_trigger_raster_points > 0){
for (int i=0; i<10; ++i){ // about 1/4s finish time
// free some cpu time now
usleep(25000);
ProbeFifoReadFunction3 (this, thread_dsp);
}
}
return 0;
}
if (!readfifo_status){
fifo_reads = 0; max_fill = 0;
total_len = 0;
for (int dir=0; dir < 4; ++dir){ // number of data chunks per scanline and direction
if (!fifo_data_num_srcs[dir])
len[dir] = 0;
else
len[dir] = fifo_data_Mobp[dir][0]->GetNx();
total_len += len[dir];
// std::cout << "Dir:" << dir << " L: " << len[dir] << std::endl;
}
lseek (thread_dsp, magic_data.datafifo, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (thread_dsp, &dsp_fifo, (MAX_WRITE_DATA_FIFO_SETUP)<<1, "RdLnFifo01");
dsp_fifo.stall = 0; // unlock scanning
check_and_swap (dsp_fifo.stall);
sr_write (thread_dsp, &dsp_fifo, (MAX_WRITE_DATA_FIFO_SETUP)<<1, "RdLnFifo10");
// to PC format
check_and_swap (dsp_fifo.r_position);
check_and_swap (dsp_fifo.w_position);
readfifo_status = 1;
g_print ("FIFO STATUS: r=%04x w=%04x\n",dsp_fifo.r_position, dsp_fifo.w_position);
}
{
int maxnum_f = MAX (MAX (MAX (fifo_data_num_srcs[0]&0x0f, fifo_data_num_srcs[1]&0x0f), fifo_data_num_srcs[2]&0x0f), fifo_data_num_srcs[3]&0x0f);
int maxnum_l = MAX (MAX (MAX ((fifo_data_num_srcs[0]&0xf0)>>4, (fifo_data_num_srcs[1]&0xf0)>>4), (fifo_data_num_srcs[2]&0xf0)>>4), (fifo_data_num_srcs[3]&0xf0)>>4);
float *linebuffer_f = new float[len[0]*(maxnum_f+maxnum_l)+1];
for (int dir = 0; dir < 4 && ScanningFlg; ++dir){
if (!fifo_data_num_srcs[dir]) continue;
xi = 0;
int count=0;
do{
// transfer data from DSP fifo into local fifo buffer -- empty DSP fifo
if (count < 1){
do {
rpos_tmp &= DATAFIFO_MASK;
// check probe fifo
if (DSPControlClass->probe_trigger_raster_points > 0)
ProbeFifoReadFunction3 (this, thread_dsp);
// Get all and empty fifo
// g_print(".");
// Seek for ATOMIC read
// lseek (thread_dsp, magic_data.datafifo, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
// Regular seek for NON-ATOMIC read, testing!!!
lseek (thread_dsp, magic_data.datafifo, SRANGER_MK23_SEEK_DATA_SPACE);
sr_read (thread_dsp, &dsp_fifo, sizeof (dsp_fifo));
bz_need_reswap = 1;
++fifo_reads;
// to PC format
check_and_swap (dsp_fifo.w_position);
check_and_swap (dsp_fifo.length); // to PC
wpos_tmp = dsp_fifo.w_position;
if (dsp_fifo.w_position > 0x1000 || dsp_fifo.length > 0x1000)
g_print ("FIFO STATUS READ ERROR. DATA_FIFO_MK3=\n"
"rpos=%08x wpos=%08x fill=%08x stall=%08x length=%08x\n",
dsp_fifo.r_position, dsp_fifo.w_position, dsp_fifo.fill, dsp_fifo.stall, dsp_fifo.length);
while (wpos_tmp - rpos_tmp < 0) wpos_tmp += dsp_fifo.length;
fifo_fill = wpos_tmp - rpos_tmp;
if (fifo_fill > (dsp_fifo.length>>3)){
if (fifo_read_sleep_us > 150)
fifo_read_sleep_us -= 50;
} else {
if (fifo_read_sleep_us < 20000)
fifo_read_sleep_us += 50;
}
usleep (fifo_read_sleep_us); // 5000
} while (fifo_fill < 10 && ScanningFlg);
// calc and update Fifo stats
{
double fifo_fill_percent;
//#define FIFO_DBG
#ifdef FIFO_DBG
if (wpos_tmp > dsp_fifo.length){
g_print ("FIFO LOOPING: w=%04x (%d) r=%04x (%d) fill=%04x (%d) L=%x %d\n",
dsp_fifo.w_position, dsp_fifo.w_position,
dsp_fifo.r_position, dsp_fifo.r_position,
fifo_fill, fifo_fill, dsp_fifo.length, dsp_fifo.length);
}
#endif
// calc fill percentage
fifo_fill = (int)(fifo_fill_percent=100.*(double)fifo_fill/(double)dsp_fifo.length);
if (fifo_fill_percent > max_fill){
max_fill = fifo_fill_percent;
}
g_free (AddStatusString);
double stat_bzlen = (8.*bz_statistics[0] + 16.*bz_statistics[1] + 24.*bz_statistics[2] + 40.*bz_statistics[3] + 40.*bz_statistics[4])
/(bz_statistics[0] + bz_statistics[1] + bz_statistics[2] + bz_statistics[3] + bz_statistics[4]);
gulong dummy_ms;
AddStatusString = g_strdup_printf ("[%d] Fifo: %.1f%% [%.1f%%] %.1fbit/pix(%d,%d,%d,%d,%d) {%d, %.3fMb/s %.3fms sleep}",
y_index, fifo_fill_percent, max_fill, stat_bzlen,
bz_statistics[0],bz_statistics[1],bz_statistics[2],
bz_statistics[3],bz_statistics[4],
fifo_reads, (8./1024./1024.)*fifo_reads * (double)sizeof(dsp_fifo) / g_timer_elapsed (gt, &dummy_ms),
1e-3*(double)fifo_read_sleep_us
);
#ifdef FIFO_DBG
// g_print (AddStatusString);
g_print ("fifo buffer read #=%04d, w-r=%04x, dir=%d Stats: %s\n", fifo_reads, dsp_fifo.w_position - dsp_fifo.r_position, dir, AddStatusString);
#endif
}
}
// transfer and convert data from fifo buffer
rpos_tmp += count = FifoRead (rpos_tmp, wpos_tmp,
xi, fifo_data_num_srcs[dir], len[dir],
linebuffer_f, dsp_fifo.buffer_ul);
} while (xi < len[dir] && ScanningFlg); // until line completed, then dump data to GXSM
// skip if scan was canceled
if (xi >= len[dir] && ScanningFlg){
// read data into linebuffer
int num_f = fifo_data_num_srcs[dir]&0x0f;
int num_l = (fifo_data_num_srcs[dir]&0xf0)>>4;
for (int i=0; i<(num_f+num_l); ++i){
if (fifo_data_Mobp[dir][i])
fifo_data_Mobp[dir][i]->PutDataLine (y_index, linebuffer_f+i*len[dir]);
}
}
}
delete[] linebuffer_f;
}
fifo_data_y_index = y_index;
// check probe fifo again
if (DSPControlClass->probe_trigger_raster_points > 0)
ProbeFifoReadFunction3 (this, thread_dsp);
return (ScanningFlg) ? 0:1;
}
void Xdumpbuffer3(unsigned char *buffer, int size, int i0){
int i,j,in;
in=size;
for(i=i0; i<in; i+=16){
g_print("W %06X:",(i>>1)&DATAFIFO_MASK);
for(j=0; (j<16) && (i+j)<size; j++)
g_print(" %02x",buffer[(((i>>1)&DATAFIFO_MASK)<<1) + j]);
printf(" ");
for(j=0; (j<16) && (i+j)<size; j++)
if(isprint(buffer[j+i]))
g_print("%c",buffer[(((i>>1)&DATAFIFO_MASK)<<1) + j]);
else
g_print(".");
g_print("\n");
}
}
int xindexx3=0;
int yindexy3=0;
//#define BZ_TEST
#ifdef BZ_TEST
// ------- simulate test ** SIMULATED/EXACT DSP LEVEL CODE HERE FOR TESTING ALGORITHM ** -------------
//#define BZ_MAX_CHANNELS 16
int bz_errors=0;
int testindex=0;
int testindex_max=0;
gint32 bz_testdata[2000];
gint32 bz_last[BZ_MAX_CHANNELS];
int bz_byte_pos=0;
DATA_FIFO datafifo = {
0, 0, // datafifo.r_position, datafifo.w_position
0, 0, // datafifo.fill, datafifo.stall
DATAFIFO_LENGTH, // datafifo.length
1, // datafifo.mode
1,2,3,4,5,6,7,8 // first data...
};
#define BZ_PUSH_NORMAL 0x00000000UL // normal atomatic mode using size indicator bits 31,30:
// -- Info: THIS CONST NAMES .._32,08,16,24 ARE NOT USED, JUST FOR DOCUMENMTATION PURPOSE
#define BZ_PUSH_MODE_32 0x00000000UL // 40:32 => 0b00MMMMMM(8bit) 0xDDDDDDDD(32bit), M:mode bits, D:Data
#define BZ_PUSH_MODE_08 0xC0000000UL // 8:6 => 0b11DDDDDD
#define BZ_PUSH_MODE_16 0x80000000UL // 16:14 => 0b10DDDDDD DDDDDDDD
#define BZ_PUSH_MODE_24 0x40000000UL // 24:22 => 0b01DDDDDD DDDDDDDD DDDDDDDD
#define BZ_PUSH_MODE_32_START 0x01000000UL // if 31,30=0 bits 29..0 available for special modes: 0x02..0x3f
// more modes free for later options and expansions
#define BZ_PUSH_MODE_32_z 0x3f000000UL
DSP_ULONG bz_push_mode=0;
void bz_init(){
int i;
for (i=0; i<BZ_MAX_CHANNELS; ++i) bz_last[i] = 0L;
bz_byte_pos=0; datafifo.buffer.ul[0] = 0UL;
datafifo.w_position = 0;
}
void bz_push(int i, long x){
union { DSP_INT32 l; DSP_UINT32 ul; } delta;
int bits;
bz_testdata[testindex++] = x;
// ERRORS so far to DSP code: norm == 0 test!! missed delta.ul ">>2" in add on parts below!! Fix "else" construct of 32bit full!!
delta.l = x - bz_last[i];
bz_last[i] = x;
if (bz_push_mode)
goto bz_push_mode_32;
bits = _norm (delta.l); // THIS NORM RETURNs 32 for arg=0
std::cout << "BZ_PUSH(i=" << i << ", ***x=" << std::hex << x << std::dec << ") D.l=" << delta.l << " bits=" << bits;
if (bits > 26){ // 8 bit package, 6 bit data
delta.l <<= 26;
std::cout << ">26** 8:6bit** BZdelta.l=" << std::hex << delta.l << std::dec << " bz_byte_pos=" << bz_byte_pos << std::endl;;
switch (bz_byte_pos){
case 0: datafifo.buffer.ul[datafifo.w_position>>1] = 0xC0000000UL | (delta.ul>>2) ; bz_byte_pos=1; break;
case 1: datafifo.buffer.ul[datafifo.w_position>>1] |= (0xC0000000UL | (delta.ul>>2)) >> 8; bz_byte_pos=2; break;
case 2: datafifo.buffer.ul[datafifo.w_position>>1] |= (0xC0000000UL | (delta.ul>>2)) >> 16; bz_byte_pos=3; break;
default: datafifo.buffer.ul[datafifo.w_position>>1] |= (0xC0000000UL | (delta.ul>>2)) >> 24; bz_byte_pos=0;
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
break;
}
} else if (bits > 18){ // 16 bit package, 14 bit data
delta.l <<= 18;
std::cout << ">18**16:14bit** BZdelta.l=" << std::hex << delta.l << std::dec << " bz_byte_pos=" << bz_byte_pos << std::endl;;
switch (bz_byte_pos){
case 0: datafifo.buffer.ul[datafifo.w_position>>1] = 0x80000000UL | (delta.ul>>2) ; bz_byte_pos=2; break;
case 1: datafifo.buffer.ul[datafifo.w_position>>1] |= (0x80000000UL | (delta.ul>>2)) >> 8; bz_byte_pos=3; break;
case 2: datafifo.buffer.ul[datafifo.w_position>>1] |= (0x80000000UL | (delta.ul>>2)) >> 16; bz_byte_pos=0;
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
break;
default: datafifo.buffer.ul[datafifo.w_position>>1] |= (0x80000000UL | (delta.ul>>2)) >> 24;
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
datafifo.buffer.ul[datafifo.w_position>>1] = ((delta.ul>>2)&0x00ff0000UL) << 8; bz_byte_pos=1; break;
}
} else if (bits > 10){ // 24 bit package, 22 bit data
delta.l <<= 10;
std::cout << ">10**24:22bit** BZdelta.l=" << std::hex << delta.l << std::dec << " bz_byte_pos=" << bz_byte_pos << std::endl;
switch (bz_byte_pos){
case 0: datafifo.buffer.ul[datafifo.w_position>>1] = 0x40000000UL | (delta.ul>>2) ; bz_byte_pos=3; break;
case 1: datafifo.buffer.ul[datafifo.w_position>>1] |= (0x40000000UL | (delta.ul>>2)) >> 8; bz_byte_pos=0;
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
break;
case 2: datafifo.buffer.ul[datafifo.w_position>>1] |= (0x40000000UL | (delta.ul>>2)) >> 16;
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
datafifo.buffer.ul[datafifo.w_position>>1] = ((delta.ul>>2)&0x0000ff00UL) << 16; bz_byte_pos=1; break;
default: datafifo.buffer.ul[datafifo.w_position>>1] |= (0x40000000UL | (delta.ul>>2)) >> 24;
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
datafifo.buffer.ul[datafifo.w_position>>1] = ((delta.ul>>2)&0x00ffff00UL) << 8; bz_byte_pos=2; break;
}
} else { // full 32 bit data -- special on byte alignment -- 6 spare unused bits left!
bz_push_mode_32:
delta.l = x;
std::cout << "ELSE**40:32bit** BZdelta.l=" << std::hex << delta.l << std::dec << " bz_byte_pos=" << bz_byte_pos << std::endl;
bits=datafifo.w_position>>1;
switch (bz_byte_pos){
case 0: datafifo.buffer.ul[datafifo.w_position>>1] = bz_push_mode | (delta.ul >> 8); // 0xMMffffff..
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
datafifo.buffer.ul[datafifo.w_position>>1] = delta.ul << 24; bz_byte_pos=1; break;
case 1: datafifo.buffer.ul[datafifo.w_position>>1] |= (bz_push_mode | (delta.ul >> 8)) >> 8; // 0x==MMffff....
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
datafifo.buffer.ul[datafifo.w_position>>1] = delta.ul << 16; bz_byte_pos=2; break;
case 2: datafifo.buffer.ul[datafifo.w_position>>1] |= (bz_push_mode | (delta.ul >> 8)) >> 16; // 0x====MMff......
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
datafifo.buffer.ul[datafifo.w_position>>1] = delta.ul << 8; bz_byte_pos=3; break;
default: datafifo.buffer.ul[datafifo.w_position>>1] |= bz_push_mode >> 24; // 0x====MM........
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK;
datafifo.buffer.ul[datafifo.w_position>>1] = delta.ul;
datafifo.w_position += 2;
datafifo.w_position &= DATAFIFO_MASK; bz_byte_pos=0;
break;
}
Xdumpbuffer3 ((unsigned char*)&datafifo.buffer.ul[bits-4], 32, 0);
}
// std::cout << "----> Fin bz_byte_pos=" << bz_byte_pos << std::endl;;
}
void run_test(){
memset ((unsigned char*)datafifo.buffer.ul, 0, DATAFIFO_LENGTH<<1);
bz_init ();
Xdumpbuffer3 ((unsigned char*)datafifo.buffer.ul, 32, 0);
gint32 tmp = (0x00000011&0x0000ffffUL << 16) | (DSP_ULONG)2;
bz_push_mode = BZ_PUSH_MODE_32_START;
bz_push (0, tmp);
bz_push_mode = BZ_PUSH_NORMAL;
bz_push (1,0x100);
bz_push (2,0x200);
for (int i=0; i<=4; ++i){
bz_push (1,0x100+i);
bz_push (2,0x200+2*i);
}
for (int i=4; i>=0; --i){
bz_push (1,0x100+i);
bz_push (2,0x200+2*i);
}
bz_push (1,0x11223344);
bz_push (2,0xaabbccdd);
bz_push (1,0x55667788);
bz_push (2,0xeeff9900);
bz_push (1,0x11223344);
bz_push (2,0xaabbccdd);
bz_push (1,0x55667788);
bz_push (2,0xeeff9900);
for (int i=0; i<=4; ++i){
bz_push (1,0x100+0x80*i);
bz_push (2,0x200+2*0x80*i);
}
for (int i=4; i>=0; --i){
bz_push (1,0x100+0x80*i);
bz_push (2,0x200+2*0x80*i);
}
for (int i=0; i<=4; ++i){
bz_push (1,0x100+0x800*i);
bz_push (2,0x200+2*0x800*i);
}
for (int i=4; i>=0; --i){
bz_push (1,0x100+0x800*i);
bz_push (2,0x200+2*0x800*i);
}
for (int i=0; i<=4; ++i){
bz_push (1,0x100+0x8000*i);
bz_push (2,0x200+2*0x8000*i);
}
for (int i=4; i>=0; --i){
bz_push (1,0x100+0x8000*i);
bz_push (2,0x200+2*0x8000*i);
}
bz_push (1,0x11223344);
bz_push (2,0xaabbccdd);
bz_push (1,0x55667788);
bz_push (2,0xeeff9900);
srand((unsigned)time(0));
int r;
int lowest=-100, highest=100;
double range=(highest-lowest)+1.;
for (int k=0; k<5; ++k){
for (int i=0; i<=50; ++i){
r = lowest+int(range*random()/(RAND_MAX + 1.0));
bz_push (1,0x100*k+0x800*i+r);
r = lowest+int(range*random()/(RAND_MAX + 1.0));
bz_push (2,0x200*k+2*0x800*i+r);
}
for (int i=50; i>=0; --i){
r = lowest+int(range*random()/(RAND_MAX + 1.0));
bz_push (1,0x100*k+0x800*i+r);
r = lowest+int(range*random()/(RAND_MAX + 1.0));
bz_push (2,0x200*k+2*0x800*i+r);
}
}
lowest=-5000, highest=5000;
range=(highest-lowest)+1.;
for (int k=0; k<3; ++k){
for (int i=0; i<=50; ++i){
r = lowest+int(range*random()/(RAND_MAX + 1.0));
bz_push (1,0x100*k+0x800*i+r);
r = lowest+int(range*random()/(RAND_MAX + 1.0));
bz_push (2,0x200*k+2*0x800*i+r);
}
for (int i=50; i>=0; --i){
r = lowest+int(range*random()/(RAND_MAX + 1.0));
bz_push (1,0x100*k+0x800*i+r);
r = lowest+int(range*random()/(RAND_MAX + 1.0));
bz_push (2,0x200*k+2*0x800*i+r);
}
}
double dlowest=-2147483645., dhighest=2147483645.;
// lowest=-2147483645, highest=2147483645;
range=(dhighest-dlowest)+1.;
for (int k=0; k<100; ++k){
r = (gint32)(dlowest+(range*random()/(RAND_MAX + 1.0)));
bz_push (1,r);
bz_push (2,r>>1);
}
}
// -------------- END DSP LEVEL CODE TEST
#endif
// FifoRead:
// Read data from FIFO ring buffer (ring) now in host memory and convert and sort into temporary secondary buffer (linear)
// Short-Type Data
int sranger_mk3_hwi_dev::FifoRead (int start, int end, int &xi, int num_srcs, int len, float *buffer_f, DSP_UINT32 *fifo_l){
int count=0;
int num_f = num_srcs&0x0f;
int num_l = (num_srcs&0xf0)>>4;
int fi_delta = end-start;
// -- DSP pads at end of scan with full 32-bit 3F00000000 x MAX_CHANNELS -- so packed record is never longer than this:
const int max_length = ((5*(num_srcs+2))>>1);
// g_print ("FIFO read attempt: FIFO BUFFER [start=%x :: end=%x]):\n", start, end);
// Xdumpbuffer3 ((unsigned char*)fifo_l, (end+16)<<1, start<<1);
if (end > 0x4000 || start > 0x4000 || len > 0x4000){
g_print ("FIFO read ERROR ranges out of range:\n( xi=%d numsrcs=%d, len=%d [start=%x :: end=%x]):\n", xi, num_srcs, len, start, end);
return -1;
}
while (end < start) end += DATAFIFO_LENGTH;
end -= max_length;
// make sure we have at least max_length data ready before proceeding
// -- need to have at least one full record, of unkown length, but smaller than the end pad.
if (start > end)
return 0;
if (fifo_block == 0) yindexy3=0;
++fifo_block;
// g_print ("FIFO read[%6d]( xi=%d numsrcs=%d, len=%d FIFO BUFFER CIRC [start=%x.%d :: end=%x]):\n", fifo_block, xi, num_srcs, len, start, bz_byte_pos, end);
#ifdef BZ_TEST
int swfold;
// Xdumpbuffer3 ((unsigned char*)fifo_l, (end-start)<<1, start<<1);
std::cout << "BZ_TEST_START **************" << std::endl;
std::cout << "BZ_TEST_START -- simulating TWO channels, must select two soure channels in GXSM befor hit scan!!" << std::endl;
std::cout << "BZ_TEST_START -- TEST SET MUST FIT FULLY IN DATAFIFOLENGTH=" << DATAFIFO_LENGTH << std::endl;
run_test ();
std::cout << "BZ_TEST_END **************" << std::endl;
// std::cout << "-------------- ABORTING HERE WITH EXIT(0) TEST VERSION SORRY." << std::endl;
// exit(0);
std::cout << "-------------- DATA OVERRIDE ------------ TEST VERSION SORRY." << std::endl;
memcpy ((unsigned char*)fifo_l, (unsigned char*)datafifo.buffer.ul, DATAFIFO_LENGTH<<1);
start=0; end=DATAFIFO_LENGTH-1; swfold=swap_flg; swap_flg = 0; target = SR_HWI_TARGET_C54;
Xdumpbuffer3 ((unsigned char*)fifo_l, end, 0);
testindex_max = testindex-1;
std::cout << "-------------- TEST DATA COUNT: " << testindex_max << std::endl;
testindex=0;
std::cout << "-------------- SWAP VERIFY ------------" << std::endl;
gint32 tt = 0x11223344;
std::cout << "TESTi=" << std::hex << tt << std::dec << std::endl;
check_and_swap (tt);
std::cout << "TESTf=" << std::hex << tt << std::dec << std::endl;
#endif
for (int fi=start; count < end-start; ){
int j=1;
LNG x;
#if 0
if (fi == 0){
g_print ("FIFO top of buffer at fi=0x%04x / count=%d\n-------- Fifo Debug:\n", fi, count);
g_print ("FIFO read[%6d]( xi=%d numsrcs=%d, len=%d FIFO BUFFER CIRC [start=%x.%d :: end=%x]):\n", fifo_block, xi, num_srcs, len, start, bz_byte_pos, end);
Xdumpbuffer3 ((unsigned char*)fifo_l, (end+16)<<1, start<<1);
}
#endif
xindexx3 = xi; // dbg only
for (int i=0; i<(num_f+num_l); ++i){
if (fi >= (end+max_length)){
g_print ("ERROR buffer valid range overrun: i of num_f=%d fi=%4x, x=%d, y=%d\n-------- Fifo Debug:\n", i, fi, xindexx3, yindexy3);
g_print ("FIFO read[%6d]( xi=%d numsrcs=%d, len=%d FIFO BUFFER CIRC [start=%x.%d :: end=%x]):\n", fifo_block, xi, num_srcs, len, start, bz_byte_pos, end);
Xdumpbuffer3 ((unsigned char*)fifo_l, (end+16)<<1, start<<1);
return count;
}
x = bz_unpack (j, fifo_l, fi, count);
if (bz_push_mode <= 0x3f)
switch (bz_push_mode){
case 0: break; // 40:32 bit full data coming in - OK, proceed.
case 1: // decode START package and start over
bz_dsp_ns = x & 0xffff;
bz_dsp_srcs = (x >> 16) & 0xffff;
bz_scale = 1./(double)bz_dsp_ns;
--i;
// g_print ("FIFO read: START_PACKAGE! ns=%d, srcs=%4x\n", bz_dsp_ns, bz_dsp_srcs);
continue;
case 0x3f:
g_print ("FIFO read: AS 0x3F END MARK DETECTED (should not get there, ERROR?)\n-------- Fifo Debug:\n");
g_print ("FIFO read[%6d]( xi=%d numsrcs=%d, len=%d FIFO BUFFER CIRC [start=%x.%d :: end=%x]):\n", fifo_block, xi, num_srcs, len, start, bz_byte_pos, end);
Xdumpbuffer3 ((unsigned char*)fifo_l, (end+16)<<1, start<<1);
return count;
break;
default:
g_print ("FIFO read: 32 Bit Unkown Package MARK %2x DETECTED at fi=0x%04x / count=%d (ERROR?)\n-------- Fifo Debug:\n", bz_push_mode, fi, count);
g_print ("FIFO read[%6d]( xi=%d numsrcs=%d, len=%d FIFO BUFFER CIRC [start=%x.%d :: end=%x]):\n", fifo_block, xi, num_srcs, len, start, bz_byte_pos, end);
Xdumpbuffer3 ((unsigned char*)fifo_l, (end+16)<<1, start<<1);
return count;
break;
}
if (i==0 && bz_dsp_srcs&1) // put 16.16 Topo data chunks from packed stream
buffer_f[xi+i*len] = (float)((double)x/65536.);
else if (i<num_f) // put 32.0 summed data chunks from packed stream and normalize, store as float
buffer_f[xi+i*len] = (float)(bz_scale*(double)x);
else // put plain 32.0 data chunks
buffer_f[xi+i*len] = x;
// DBG STUFF
// if (i==0) buffer_f[xi+i*len] = (float)fi+(float)bz_byte_pos/4.; // dbg ovr.
// if (i==1) buffer_f[xi+i*len] = (float)fi_delta; // dbg ovr.
++j;
}
#ifdef BZ_TEST
if (testindex >= testindex_max){ // || ++xi == len){
std::cout << "------------------------------------------------" << std::endl;
std::cout << "FIFO read BZ DATA STATISTICS: [8: " << bz_statistics[0]
<< ", 16:" << bz_statistics[1]
<< ", 24:" << bz_statistics[2]
<< ", 32:" << bz_statistics[3]
<< ", ST:" << bz_statistics[4]
<< "]" << std::endl;
std::cout << "TEST DONE with " << testindex << " data values. Total Error Count: " << bz_errors << std::endl;
break;
}
#else
if( ++xi == len){ // full line finished
++yindexy3;
break;
}
#endif
}
//#define BZ_TEST_EXIT
#ifdef BZ_TEST_EXIT
swap_flg = swfold;
target = SR_HWI_TARGET_C55;
std::cout << "-------------- ABORTING HERE WITH EXIT(0) TEST VERSION SORRY." << std::endl;
exit(0);
#endif
#if 0
g_print ("FIFO read done[y=%d]. Count=%x.%d\n", yindexy3, count, bz_byte_pos);
for (int j=0; j<num_f; ++j){
g_print ("Buffer[%d,xi#%d]={",j,xi);
for (int i=0; i<xi; ++i)
g_print ("%g,",buffer_f[i+j*len]);
g_print ("}\n");
}
#endif
return count;
}
LNG sranger_mk3_hwi_dev::bz_unpack (int i, DSP_UINT32 *fifo_l, int &fi, int &count){
int bits_mark[4] = { 32, 10, 18, 26 };
union { DSP_INT32 l; DSP_UINT32 ul; } x;
union { DSP_INT32 l; DSP_UINT32 ul; } delta;
int bits;
// manage swap, fi and count here!
if (bz_byte_pos == 0 || bz_need_reswap){
check_and_swap (fifo_l[fi>>1]);
bz_need_reswap = 0;
}
x.l = fifo_l[fi>>1];
switch (bz_byte_pos){
case 0: bits = bits_mark[(x.ul & 0xC0000000UL)>>30]; break;
case 1: bits = bits_mark[(x.ul & 0x00C00000UL)>>22]; break;
case 2: bits = bits_mark[(x.ul & 0x0000C000UL)>>14]; break;
default: bits = bits_mark[(x.ul & 0x000000C0UL)>> 6]; break;
}
// g_print ("BZ_UNPACK(%6x,%6d) [%4d, %4d, %d] bits=%2d @ pos=%d x.ul=%08x ",fi,count,xindexx3, yindexy3, i, bits, bz_byte_pos, x.ul);
switch (bits){
case 26: // 8 bit package, 6 bit data
++bz_statistics[0];
bz_push_mode = 0xC0;
switch (bz_byte_pos){
case 0: delta.ul = (x.ul & 0x3f000000) << 2; delta.l >>= 26; bz_byte_pos=1; break;
case 1: delta.ul = (x.ul & 0x003f0000) << 10; delta.l >>= 26; bz_byte_pos=2; break;
case 2: delta.ul = (x.ul & 0x00003f00) << 18; delta.l >>= 26; bz_byte_pos=3; break;
default: delta.ul = (x.ul & 0x0000003f) << 26; delta.l >>= 26; bz_byte_pos=0; fi+=2; fi&=DATAFIFO_MASK; count+=2; break;
}
bz_last[i] += delta.l;
break;
case 18: // 16 bit package, 14 bit data
++bz_statistics[1];
bz_push_mode = 0x80;
switch (bz_byte_pos){
case 0: delta.ul = (x.ul & 0x3fff0000) << 2; delta.l >>= 18; bz_byte_pos=2; break;
case 1: delta.ul = (x.ul & 0x003fff00) << 10; delta.l >>= 18; bz_byte_pos=3; break;
case 2: delta.ul = (x.ul & 0x00003fff) << 18; delta.l >>= 18; bz_byte_pos=0; fi+=2; fi&=DATAFIFO_MASK; count+=2; break;
default: delta.ul = (x.ul & 0x0000003f) << 26; fi+=2; fi&=DATAFIFO_MASK; count+=2;
check_and_swap (fifo_l[fi>>1L]);
x.l = fifo_l[fi>>1L];
// g_print (" ... 3: x.ul=%08x", x.ul);
delta.ul |= (x.ul & 0xff000000) >> 6; delta.l >>= 18; bz_byte_pos=1; break;
}
bz_last[i] += delta.l;
break;
case 10: // 24 bit package, 22 bit data
++bz_statistics[2];
bz_push_mode = 0x40;
switch (bz_byte_pos){
case 0: delta.ul = (x.ul & 0x3fffff00) << 2; delta.l >>= 10; bz_byte_pos=3; break;
case 1: delta.ul = (x.ul & 0x003fffff) << 10; delta.l >>= 10; bz_byte_pos=0; fi+=2; fi&=DATAFIFO_MASK; count+=2; break;
case 2: delta.ul = (x.ul & 0x00003fff) << 18; fi+=2; fi&=DATAFIFO_MASK; count+=2;
check_and_swap (fifo_l[fi>>1L]);
x.l = fifo_l[fi>>1L];
// g_print (" ... 2: x.ul=%08x", x.ul);
delta.ul |= (x.ul & 0xff000000) >> 14; delta.l >>= 10; bz_byte_pos=1; break;
default: delta.ul = (x.ul & 0x0000003f) << 26; fi+=2; fi&=DATAFIFO_MASK; count+=2;
check_and_swap (fifo_l[fi>>1L]);
x.l = fifo_l[fi>>1L];
// g_print (" ... 3: x.ul=%08x", x.ul);
delta.ul |= (x.ul & 0xffff0000) >> 6; delta.l >>= 10; bz_byte_pos=2; break;
}
bz_last[i] += delta.l;
break;
default: // 40bit package, full 32 bit data, 6 spare uinused bits, byte aligned. ...0x00ffffffff...
switch (bz_byte_pos){
case 0: delta.ul = (x.ul & 0x00ffffff) << 8;
bz_push_mode = (x.ul & 0xff000000) >> 24; fi+=2; fi&=DATAFIFO_MASK; count+=2;
check_and_swap (fifo_l[fi>>1L]);
x.l = fifo_l[fi>>1L];
// g_print (" bzp=%02x ... 0: x.ul=%08x", bz_push_mode, x.ul);
delta.ul |= (x.ul & 0xff000000) >> 24; bz_byte_pos=1; break;
case 1: delta.ul = (x.ul & 0x0000ffff) << 16;
bz_push_mode = (x.ul & 0x00ff0000) >> 16; fi+=2; fi&=DATAFIFO_MASK; count+=2;
check_and_swap (fifo_l[fi>>1L]);
x.l = fifo_l[fi>>1L];
// g_print (" bzp=%02x ... 1: x.ul=%08x", bz_push_mode, x.ul);
delta.ul |= (x.ul & 0xffff0000) >> 16; bz_byte_pos=2; break;
case 2: delta.ul = (x.ul & 0x000000ff) << 24;
bz_push_mode = (x.ul & 0x0000ff00) >> 8; fi+=2; fi&=DATAFIFO_MASK; count+=2;
check_and_swap (fifo_l[fi>>1L]);
x.l = fifo_l[fi>>1L];
// g_print (" bzp=%02x ... 2: x.ul=%08x", bz_push_mode, x.ul);
delta.ul |= (x.ul & 0xffffff00) >> 8; bz_byte_pos=3; break;
default:
bz_push_mode = (x.ul & 0x000000ff); fi+=2; fi&=DATAFIFO_MASK; count+=2;
check_and_swap (fifo_l[fi>>1L]);
x.l = fifo_l[fi>>1L];
// g_print (" bzp=%02x ... 3: x.ul=%08x", bz_push_mode, x.ul);
delta.ul = x.ul; fi+=2; fi&=DATAFIFO_MASK; count+=2; bz_byte_pos=0; break;
}
switch (bz_push_mode){
case 0:
++bz_statistics[3];
bz_last[i] = delta.l;
break; // normal 32 operation
case 1:
++bz_statistics[4];
bz_last[i=0] = delta.l;
break; // special mode 1 "START", put to index 0!
default: break;
}
break;
}
#ifdef BZ_TEST
gint32 v = bz_last[i] - bz_testdata[testindex];
if (v != 0)
bz_errors++;
// std::cout << " ==["<<i<<"]d=" <<delta.l<<" ==> " << std::hex << bz_last[i] << " V(" << bz_testdata[testindex] << ")" << (v==0?"OK":"ERROR") << std::dec << std::endl;
testindex++;
#else
// g_print ("[bzp=%02x] delta.l=%08x (%6g) N[%d] ==> %08x = %6g\n", bz_push_mode, delta.l, (double)delta.l, _norm(delta.l), bz_last[i], (double)bz_last[i]);
#endif
return bz_last[i];
}
// ==================================================
//
// Probe Data FIFO read thread section
//
// ==================================================
// FIFO watch verbosity...
# define LOGMSGS0(X) std::cout << X
//# define LOGMSGS0(X)
# define LOGMSGS(X) std::cout << X
//# define LOGMSGS(X)
# define LOGMSGS2(X) std::cout << X
//# define LOGMSGS2(X)
// ProbeFifoReadThread:
// Independent ProbeFifoRead Thread (manual probe)
gpointer ProbeFifoReadThread3 (void *ptr_sr){
int finish_flag=FALSE;
sranger_mk3_hwi_dev *sr = (sranger_mk3_hwi_dev*)ptr_sr;
if (sr->probe_fifo_thread_active){
LOGMSGS ( "ProbeFifoReadThread3 ERROR: Attempt to start again while in progress! [#" << sr->probe_fifo_thread_active << "]" << std::endl);
return NULL;
}
sr->probe_fifo_thread_active++;
DSPControlClass->probe_ready = FALSE;
if (DSPControlClass->probe_trigger_single_shot)
finish_flag=TRUE;
clock_t timeout = clock() + (clock_t)(CLOCKS_PER_SEC*(0.5+sr->probe_time_estimate/22000.));
LOGMSGS ( "ProbeFifoReadThread3 START " << (DSPControlClass->probe_trigger_single_shot ? "Single":"Multiple") << "-VP[#"
<< sr->probe_fifo_thread_active << "] Timeout is set to:"
<< (timeout-clock()) << "Clks (incl. 0.5s Reserve) (" << ((double)sr->probe_time_estimate/22000.) << "s)" << std::endl);
sr->ReadProbeFifo (sr->probe_thread_dsp, FR_INIT); // init
int i=1;
while (sr->is_scanning () || finish_flag){
#ifdef G_THREADS_ENABLED
if (DSPControlClass->current_auto_flags & FLAG_AUTO_PLOT){
gdk_threads_enter(); // Protect from gtk main loop which also performs a gtk_entry_set_text.
DSPControlClass->Probing_graph_callback (NULL, DSPControlClass, 0);
gdk_flush();
gdk_threads_leave();
}
#endif
++i;
switch (sr->ReadProbeFifo (sr->probe_thread_dsp)){
case RET_FR_NOWAIT:
LOGMSGS2 ( ":NOWAIT:" << i << " TmoClk=" << (timeout-clock()) << std::endl);
continue;
case RET_FR_WAIT:
LOGMSGS ( ":WAIT:" << i << " TmoClk=" << (timeout-clock()) << std::endl);
usleep(50000);
if (finish_flag && clock() > timeout)
goto error;
continue;
case RET_FR_OK:
LOGMSGS2 ( ":OK:" << i << " TmoClk=" << (timeout-clock()) << std::endl);
continue;
case RET_FR_ERROR:
LOGMSGS ( ":ERROR:" << i << " TmoClk=" << (timeout-clock()) << std::endl);
goto error;
case RET_FR_FCT_END:
LOGMSGS ( ":FCT_END:" << i << " TmoClk=" << (timeout-clock()) << std::endl);
if (finish_flag){
#ifdef G_THREADS_ENABLED
if (DSPControlClass->current_auto_flags & FLAG_AUTO_PLOT){
gdk_threads_enter(); // Protect from gtk main loop which also performs a gtk_entry_set_text.
DSPControlClass->Probing_graph_callback (NULL, DSPControlClass, 1);
gdk_flush();
gdk_threads_leave();
}
if (DSPControlClass->current_auto_flags & FLAG_AUTO_SAVE){
gdk_threads_enter(); // Protect from gtk main loop which also performs a gtk_entry_set_text.
DSPControlClass->Probing_save_callback (NULL, DSPControlClass);
gdk_flush();
gdk_threads_leave();
}
#endif
goto finish;
}
DSPControlClass->push_probedata_arrays ();
DSPControlClass->init_probedata_arrays ();
// reset timeout
// timeout = clock() + (clock_t)(CLOCKS_PER_SEC*(0.5+sr->probe_time_estimate/22000.));
continue;
}
LOGMSGS ( ":FIFO THREAD ERROR DETECTION:" << i << " TmoClk=" << (timeout-clock()) << std::endl);
goto error;
}
finish:
LOGMSGS ( "ProbeFifoReadThread3 DONE Single-VP[#" << sr->probe_fifo_thread_active << "] Timeout left (positive is OK):" << (timeout-clock()) << std::endl);
error:
sr->ReadProbeFifo (sr->probe_thread_dsp, FR_FINISH); // finish
--sr->probe_fifo_thread_active;
DSPControlClass->probe_ready = TRUE;
return NULL;
}
// ProbeFifoReadFunction3:
// inlineable ProbeFifoRead Function -- similar to the thread, is called/inlined by/into the Image Data Thread
gpointer ProbeFifoReadFunction3 (void *ptr_sr, int dspdev){
static int plotted=0;
sranger_mk3_hwi_dev *sr = (sranger_mk3_hwi_dev*)ptr_sr;
while (sr->is_scanning ()){
switch (sr->ReadProbeFifo (dspdev)){
case RET_FR_NOWAIT:
plotted = 0;
continue;
case RET_FR_WAIT:
#ifdef G_THREADS_ENABLED
if (!plotted && DSPControlClass->current_auto_flags & FLAG_AUTO_PLOT){
LOGMSGS ( "ProbeFifoReadFunction -- FR_WAIT-ing for data, update plot display." << std::endl);
gdk_threads_enter(); // Protect from gtk main loop which also performs a gtk_entry_set_text.
DSPControlClass->Probing_graph_callback (NULL, DSPControlClass, 0);
gdk_flush();
gdk_threads_leave();
}
#endif
plotted++;
return NULL;
case RET_FR_OK:
plotted = 0;
continue;
case RET_FR_ERROR:
goto error;
case RET_FR_FCT_END:
plotted = 0;
if (DSPControlClass->probedata_length () > 0){
#ifdef G_THREADS_ENABLED
if (DSPControlClass->current_auto_flags & FLAG_AUTO_PLOT){
gdk_threads_enter(); // Protect from gtk main loop which also performs a gtk_entry_set_text.
DSPControlClass->Probing_graph_callback (NULL, DSPControlClass, 1);
gdk_flush();
gdk_threads_leave();
}
if (DSPControlClass->current_auto_flags & FLAG_AUTO_SAVE){
gdk_threads_enter(); // Protect from gtk main loop which also performs a gtk_entry_set_text.
DSPControlClass->Probing_save_callback (NULL, DSPControlClass);
gdk_flush();
gdk_threads_leave();
}
#endif
DSPControlClass->push_probedata_arrays ();
DSPControlClass->init_probedata_arrays ();
LOGMSGS ( "ProbeFifoReadFunction -- Pushed Probe Data on Stack" << std::endl);
}
continue;
}
goto error;
}
error:
return NULL;
}
// ReadProbeFifo:
// read from probe FIFO, this engine needs to be called several times from master thread/function
int sranger_mk3_hwi_dev::ReadProbeFifo (int dspdev, int control){
int pvd_blk_size=0;
static double pv[9];
static int last = 0;
static int last_read_end = 0;
static DATA_FIFO_EXTERN_PCOPY_MK3 fifo;
static PROBE_SECTION_HEADER_MK3 section_header;
static int next_header = 0;
static int number_channels = 0;
static int data_index = 0;
static int end_read = 0;
static int data_block_size=0;
static int need_fct = FR_YES; // need fifo control
static int need_hdr = FR_YES; // need header
static int need_data = FR_YES; // need data
static int ch_lut[32];
static int ch_msk[] = { 0x0000001, 0x0000002, 0x0000010, 0x0000020, 0x0000040, 0x0000080, 0x0000100, 0x0000200, 0x0000400, 0x0000800,
0x0000008, 0x0001000, 0x0002000, 0x0004000, 0x0008000, 0x0000004, 0x0000000 };
static int ch_size[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 0 };
static const char *ch_header[] = {"Zmon-AIC5Out", "Umon-AIC6Out", "AIC0-I", "AIC1", "AIC2", "AIC3", "AIC4", "AIC5", "AIC6", "AIC7",
"LockIn0", "LockIn1stA", "LockIn1stB", "LockIn2ndA", "LockIn2ndB", "Count", NULL };
static short data[EXTERN_PROBEDATAFIFO_LENGTH];
static double dataexpanded[16];
#ifdef LOGMSGS0
static double dbg0=0., dbg1=0.;
static int dbgi0=0;
#endif
switch (control){
case FR_FIFO_FORCE_RESET: // not used normally -- FIFO is reset by DSP at probe_init (single probe)
fifo.r_position = 0;
fifo.w_position = 0;
check_and_swap (fifo.r_position);
check_and_swap (fifo.w_position);
lseek (dspdev, magic_data.probedatafifo, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dspdev, &fifo, 2*sizeof(DSP_INT32)); // reset positions now to prevent reading old/last dataset before DSP starts init/putting data
return RET_FR_OK;
case FR_INIT:
last = 0;
next_header = 0;
number_channels = 0;
data_index = 0;
last_read_end = 0;
need_fct = FR_YES;
need_hdr = FR_YES;
need_data = FR_YES;
DSPControlClass->init_probedata_arrays ();
for (int i=0; i<16; dataexpanded[i++]=0.);
LOGMSGS0 ( std::endl << "************** PROBE FIFO-READ INIT **************" << std::endl);
LOGMSGS ( "FR::INIT-OK." << std::endl);
return RET_FR_OK; // init OK.
case FR_FINISH:
LOGMSGS ( "FR::FINISH-OK." << std::endl);
return RET_FR_OK; // finish OK.
default: break;
}
if (need_fct){ // read and check fifo control?
LOGMSGS2 ( "FR::NEED_FCT, last: 0x" << std::hex << last << std::dec << std::endl);
// Seek for ATOMIC read
// lseek (dspdev, magic_data.probedatafifo, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
// Seek for NON-ATOMIC read -- testing!!!
lseek (dspdev, magic_data.probedatafifo, SRANGER_MK23_SEEK_DATA_SPACE);
sr_read (dspdev, &fifo, sizeof (fifo));
check_and_swap (fifo.w_position);
check_and_swap (fifo.current_section_head_position);
check_and_swap (fifo.current_section_index);
check_and_swap (fifo.p_buffer_base);
end_read = fifo.w_position >= last ? fifo.w_position : EXTERN_PROBEDATAFIFO_LENGTH;
LOGMSGS2 ( "FR::NEED_FCT, magic.prbdata_fifo @Adr: 0x" << std::hex << magic_data.probedatafifo << std::dec << std::endl);
LOGMSGS2 ( "FR::NEED_FCT, magic.prbdata_fifo.p_buf: 0x" << std::hex << fifo.p_buffer_base << std::dec << std::endl);
LOGMSGS2 ( "FR::NEED_FCT, w_position: 0x" << std::hex << fifo.w_position << std::dec << std::endl);
// check for new data
if ((end_read - last) < 1)
return RET_FR_WAIT;
else {
need_fct = FR_NO;
need_data = FR_YES;
}
}
if (need_data){ // read full FIFO block
LOGMSGS ( "FR::NEED_DATA" << std::endl);
int database = (int)fifo.p_buffer_base;
int dataleft = end_read;
int position = 0;
if (fifo.w_position > last_read_end){
// database += last_read_end;
// dataleft -= last_read_end;
}
for (; dataleft > 0; database += 0x4000, dataleft -= 0x4000, position += 0x4000){
LOGMSGS ( "FR::NEED_DATA: B::0x" << std::hex << database << std::dec << std::endl);
lseek (dspdev, database, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dspdev, &data[position], (dataleft >= 0x4000 ? 0x4000 : dataleft)<<1);
}
last_read_end = end_read;
need_data = FR_NO;
}
if (need_hdr){ // we have enough data if control gets here!
LOGMSGS ( "FR::NEED_HDR" << std::endl);
// check for FIFO loop
if (last > (EXTERN_PROBEDATAFIFO_LENGTH - EXTERN_PROBEDATA_MAX_LEFT)){
LOGMSGS0 ( "FR:FIFO LOOP DETECTED -- FR::NEED_HDR ** Data @ "
<< "0x" << std::hex << last
<< " -2 :[" << (*((DSP_UINT32*)&data[last-2]))
<< " " << (*((DSP_UINT32*)&data[last]))
<< " " << (*((DSP_UINT32*)&data[last+2]))
<< " " << (*((DSP_UINT32*)&data[last+4]))
<< " " << (*((DSP_UINT32*)&data[last+6]))
<< "] : FIFO LOOP MARK " << std::dec << ( *((DSP_UINT32*)&data[last]) == 0 ? "OK":"ERROR")
<< std::endl);
next_header -= last;
last = 0;
end_read = fifo.w_position;
}
if (((fifo.w_position - last) < (sizeof (section_header)>>1))){
need_fct = FR_YES;
return RET_FR_WAIT;
}
memcpy ((void*)&(section_header.srcs), (void*)(&data[next_header]), sizeof (section_header));
check_and_swap (section_header.srcs);
check_and_swap (section_header.n);
check_and_swap (section_header.time);
check_and_swap (section_header.x_offset);
check_and_swap (section_header.y_offset);
check_and_swap (section_header.z_offset);
check_and_swap (section_header.x_scan);
check_and_swap (section_header.y_scan);
check_and_swap (section_header.z_scan);
check_and_swap (section_header.u_scan);
check_and_swap (section_header.section);
// set vector of expanded data array representation, section start
pv[0] = section_header.time;
pv[1] = section_header.x_offset;
pv[2] = section_header.y_offset;
pv[3] = section_header.z_offset;
pv[4] = section_header.x_scan;
pv[5] = section_header.y_scan;
pv[6] = section_header.z_scan;
pv[7] = section_header.u_scan;
pv[8] = section_header.section;
LOGMSGS ( "FR::NEED_HDR -- got HDR @ 0x" << std::hex << next_header << std::dec
<< " section: " << section_header.section
<< " time: " << section_header.time
<< " XYZ: " << section_header.x_scan << ", " << section_header.y_scan << ", " << section_header.z_scan
<< std::endl);
// validate header -- if stupid things are happening, values are messed up so check:
if (section_header.time < 0 || section_header.section < 0 || section_header.section > 50 || section_header.n < 0 || section_header.n > 500000){
LOGMSGS0 ( "************** FIFO READ ERROR DETECTED: bad section header **************" << std::endl);
LOGMSGS0 ( "Error reading from ProbeData FIFO base[" << std::hex << fifo.p_buffer_base << std::dec << "]." << std::endl);
LOGMSGS0 ( "==> read bad HDR @ 0x" << std::hex << next_header << std::dec
<< " last: 0x" << std::hex << last << std::dec
<< " section: " << section_header.section
<< " n: " << section_header.n
<< " time: " << section_header.time
<< " XYZ: " << section_header.x_scan << ", " << section_header.y_scan << ", " << section_header.z_scan
<< std::endl);
LOGMSGS0 ( "Last Sec: " << dbg0 << "Last srcs: " << dbg1 << " last last: 0x" << std::hex << dbgi0 << std::dec << std::endl);
// baild out and try recovery
goto auto_recover_and_debug;
}
#ifdef LOGMSGS0
dbg0 = section_header.section;
dbg1 = section_header.srcs;
dbgi0 = last;
#endif
need_hdr = FR_NO;
// analyze header and setup channel lookup table
number_channels=0;
last += sizeof (section_header) >> 1;
next_header += sizeof (section_header) >> 1;
data_block_size = 0;
if (section_header.srcs){
LOGMSGS ( "FR::NEED_HDR: decoding DATA_SRCS to read..." << std::endl);
for (int i = 0; ch_msk[i] && i < 18; ++i){
if (section_header.srcs & ch_msk[i]){
ch_lut[number_channels] = i;
data_block_size += ch_size[i];
++number_channels;
}
if (i == 10 && (data_block_size>>1) & 1){ // adjust for even LONG position
data_block_size += 2;
ch_lut[number_channels] = -1; // dummy fill
++number_channels;
}
}
next_header += section_header.n * (data_block_size >> 1);
data_index = 0;
} else {
LOGMSGS ( "FR::NEED_HDR: DATA_SRCS ZERO." << std::endl);
if (section_header.n == 0){
LOGMSGS ( "FR::NEED_HDR: DATA_N ZERO -> END PROBE OK." << std::endl);
DSPControlClass->probe_trigger_single_shot = 0; // if single shot, stop reading next
number_channels = 0;
data_index = 0;
need_hdr = FR_YES;
return RET_FR_FCT_END;
} else {
LOGMSGS ( "FR::NEED_HDR: no data in this section." << std::endl);
}
LOGMSGS ( "FR::NEED_HDR: need next hrd!" << std::endl);
need_hdr = FR_YES;
return RET_FR_NOWAIT;
}
}
// now read/convert all available/valid data from fifo block we just copied
pvd_blk_size = data_block_size >> 1; // data block size in "word"-indices
LOGMSGS ( "FR::DATA-cvt:"
<< " pvd_blk-sz=" << pvd_blk_size
<< " last=0x" << std::hex << last << std::dec
<< " next_header=0x" << std::hex << next_header << std::dec
<< " end_read=0x" << std::hex << end_read << " EPL:0x" << EXTERN_PROBEDATAFIFO_LENGTH << std::dec
<< " data_index=" << data_index << std::dec
<< std::endl);
for (int element=0; last < end_read; ++last, ++data_index){
// got all data, at next header?
if (last == next_header){
LOGMSGS ( "FR:NEXT HDR EXPECTED" << std::endl);
need_hdr = FR_YES;
return RET_FR_NOWAIT;
}
if (last > next_header){
LOGMSGS0 ( "FR:ERROR:: =====> MISSED NEXT HDR?"
<< " last: 0x" << std::hex << last
<< " next_header: 0x" << std::hex << next_header
<< std::endl);
goto auto_recover_and_debug;
}
int channel = ch_lut[element++];
if (channel >= 0){ // only if valid (skip possible dummy (2) fillings)
// check for long data (4)
if (ch_size[channel] == 4){
LNG *tmp = (LNG*)&data[last];
check_and_swap (*tmp);
dataexpanded[channel] = (double) (*tmp);
++last; ++data_index;
} else { // normal data (2)
check_and_swap (data[last]);
dataexpanded[channel] = (double) data[last];
}
}
// add vector and data to expanded data array representation
if ((data_index % pvd_blk_size) == (pvd_blk_size-1)){
if (data_index >= pvd_blk_size) // skip to next vector
DSPControlClass->add_probevector ();
else // set vector as previously read from section header (pv[]) at sec start
DSPControlClass->set_probevector (pv);
// add full data vector
DSPControlClass->add_probedata (dataexpanded);
element = 0;
// check for FIFO loop now
if (last > (EXTERN_PROBEDATAFIFO_LENGTH - EXTERN_PROBEDATA_MAX_LEFT)){
++last;
LOGMSGS0 ( "FR:FIFO LOOP DETECTED ** Data @ "
<< "0x" << std::hex << last
<< " last-6 :[" << (*((DSP_UINT32*)&data[last-6]))
<< " " << (*((DSP_UINT32*)&data[last-4]))
<< " " << (*((DSP_UINT32*)&data[last-2]))
<< " " << (*((DSP_UINT32*)&data[last]))
<< " " << (*((DSP_UINT32*)&data[last+2]))
<< " " << (*((DSP_UINT32*)&data[last+4]))
<< " " << (*((DSP_UINT32*)&data[last+6]))
<< "] : FIFO LOOP MARK " << std::dec << ( *((DSP_UINT32*)&data[last]) == 0 ? "OK":"ERROR")
<< " FIFOLEN=" << fifo.length << std::endl);
next_header -= last;
last = -1; // compensate for ++last at of for(;;)!
end_read = fifo.w_position;
}
}
}
LOGMSGS ( "FR:FIFO NEED FCT" << std::endl);
need_fct = FR_YES;
return RET_FR_WAIT;
// emergency bailout and auto recovery, FIFO restart
auto_recover_and_debug:
#ifdef LOGMSGS0
LOGMSGS0 ( "************** -- FIFO DEBUG -- **************" << std::endl);
LOGMSGS0 ( "LastArdess: " << "0x" << std::hex << last << std::dec << std::endl);
for (int adr=last-8; adr < last+32; adr+=8){
while (adr < 0) ++adr;
LOGMSGS0 ("0x" << std::hex << adr << "::"
<< " " << (*((DSP_UINT32*)&data[adr]))
<< " " << (*((DSP_UINT32*)&data[adr+2]))
<< " " << (*((DSP_UINT32*)&data[adr+4]))
<< " " << (*((DSP_UINT32*)&data[adr+6]))
<< std::dec << std::endl);
}
LOGMSGS0 ( "************** TRYING AUTO RECOVERY **************" << std::endl);
LOGMSGS0 ( "***** -- STOP * RESET FIFO * START PROBE -- ******" << std::endl);
#endif
// STOP PROBE
// reset positions now to prevent reading old/last dataset before DSP starts init/putting data
DSP_INT32 start_stop[2] = { 0, 1 };
lseek (dspdev, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dspdev, &start_stop, 2*sizeof(DSP_INT32));
// RESET FIFO
// reset positions now to prevent reading old/last dataset before DSP starts init/putting data
fifo.r_position = 0;
fifo.w_position = 0;
check_and_swap (fifo.r_position);
check_and_swap (fifo.w_position);
lseek (dspdev, magic_data.probedatafifo, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dspdev, &fifo, 2*sizeof(DSP_INT32));
// START PROBE
// reset positions now to prevent reading old/last dataset before DSP starts init/putting data
start_stop[0] = 1;
start_stop[1] = 0;
lseek (dspdev, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dspdev, &start_stop, 2*sizeof(DSP_INT32));
// reset all internal and partial reinit FIFO read thread
last = 0;
next_header = 0;
number_channels = 0;
data_index = 0;
last_read_end = 0;
need_fct = FR_YES;
need_hdr = FR_YES;
need_data = FR_YES;
// and start over on next call
return RET_FR_WAIT;
}
/*
* provide some info about the connected hardware/driver/etc.
*/
gchar* sranger_mk3_hwi_dev::get_info(){
static gchar *magic_info = NULL;
if (productid){
gchar *details = NULL;
if (FB_SPM_VERSION != magic_data.version){
details = g_strdup_printf(
"WARNING: Signal Ranger FB_SPM soft Version mismatch detected:\n"
"Detected SRanger DSP Software Version: %x.%02x\n"
"Detected SRanger DSP Software ID: %04X\n"
"GXSM was build for DSP Software Version: %x.%02x\n"
"And DSP Software ID %4X is recommended.\n"
"This may cause incompatility problems, trying to proceed.\n",
magic_data.version >> 8,
magic_data.version & 0xff,
magic_data.dsp_soft_id,
FB_SPM_VERSION >> 8,
FB_SPM_VERSION & 0xff,
FB_SPM_SOFT_ID);
} else {
details = g_strdup_printf("Errors/Warnings: none\n");
}
g_free (magic_info); // g_free irgnors NULL ptr!
magic_info = g_strdup_printf (
"Magic....... : %08X\n"
"Version..... : %08X\n"
"Date........ : %08X%08X\n"
"*-- DSP Control Struct Locations --*\n"
"statemachine : %08x\n"
"analog...... : %08x\n"
"signal_mon.. : %08x\n"
"feedback_mix.: %08x\n"
"z_servo .... : %08x\n"
"m_servo .... : %08x\n"
"scan........ : %08x\n"
"move........ : %08x\n"
"probe....... : %08x\n"
"autoapproach : %08x\n"
"datafifo.... : %08x\n"
"probedatafifo: %08x\n"
"------------------------------------\n"
"%s",
magic_data.magic,
magic_data.version,
magic_data.year,
magic_data.mmdd,
magic_data.statemachine,
magic_data.analog,
magic_data.signal_monitor,
magic_data.feedback_mixer,
magic_data.z_servo,
magic_data.m_servo,
magic_data.scan,
magic_data.move,
magic_data.probe,
magic_data.autoapproach,
magic_data.datafifo,
magic_data.probedatafifo,
details
);
g_free (details);
return g_strconcat (
"*--GXSM Sranger HwI base class--*\n",
"Sranger device: ", productid, "\n",
"*--Features--*\n",
FB_SPM_FEATURES,
"*--Magic Info--*\n",
magic_info,
"*--EOF--*\n",
NULL
);
}
else
return g_strdup("*--GXSM Sranger HwI base class--*\n"
"Sranger device not connected\n"
"or not supported.");
}
double sranger_mk3_hwi_dev::GetUserParam (gint n, gchar *id){
return DSPControlClass->GetUserParam (n, id);
}
gint sranger_mk3_hwi_dev::SetUserParam (gint n, gchar *id, double value){
return DSPControlClass->SetUserParam (n, id, value);
}
// ======================================== ========================================
#if 0
#define CONV_16_C(X) int_2_sranger_int (X)
#define CONV_32_C(X) long_2_sranger_long (X)
#define CONV_16(X) X = int_2_sranger_int (X)
#define CONV_32(X) X = long_2_sranger_long (X)
#else
#define CONV_16_C(X) (X)
#define CONV_32_C(X) (X)
#define CONV_16(X)
#define CONV_32(X)
#endif
void sranger_mk3_hwi_dev::read_dsp_state (gint32 &mode){
lseek (dsp, magic_data.statemachine, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_state, sizeof(dsp_state), "Rd-DSP-State");
CONV_32 (dsp_state.mode);
CONV_32 (dsp_state.DataProcessTime);
CONV_32 (dsp_state.IdleTime);
mode = dsp_state.mode;
}
void sranger_mk3_hwi_dev::write_dsp_state (gint32 mode){
if (mode > 0){
dsp_state.set_mode = mode;
dsp_state.clr_mode = 0;
}
if (mode < 0){
dsp_state.set_mode = 0;
dsp_state.clr_mode = -mode;
}
CONV_32 (dsp_state.set_mode);
CONV_32 (dsp_state.clr_mode);
lseek (dsp, magic_data.statemachine, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_state, 2*sizeof(gint32), "Adj-DSP-State");
}
// DSP_INT cp; /* 0 0*< Const Proportional in Q15 rep =RW */
// DSP_INT ci; /* 1 1*< Const Integral in Q15 rep =RW */
// DSP_INT setpoint; /* 2 2*< real world setpoint, if loaded gain, spm_logn will be calculated and "soll" is updated =WO */
// DSP_INT ca_q15; /* 3 3*< IIR filter adapt: ca = q_sat_limit cut-off (0:=FBW or f0_max) [Q15] */
// DSP_LONG cb_Ic; /* 4 4*< IIR filter adapt: cb_Ic = f_0,min/f_0,max * I_cross [32] */
// DSP_INT I_cross; /* 5 6*< IIR filter adapt: I_crossover */
// DSP_INT I_offset; /* 6 7*< I_offset, log start/characteristic */
// DSP_INT q_factor15; /* 7 8*< IIR filter: q -- (In=1/(1+q) (I+q*In)) in Q15 */
// DSP_INT soll; /* 8 9*< "Soll Wert" Set Point (behind log trafo) =RO */
// DSP_INT ist; /* 9 10*< "Ist Wert" Real System Value (behind log trafo) =RO */
// DSP_INT delta; /*10 11*< "Regelabweichung" ist-soll =RO */
// DSP_LONG i_pl_sum; /*11 12*< CI - summing, includes area-scan plane-correction summing, 32bits! =RO */
// DSP_LONG i_sum; /*12 14*< CI summing only, mirror, 32bits! =RO */
// DSP_LONG I_iir; /*13 16*< Current I smooth (IIR response) =RO */
// DSP_INT z; /*14 18*< "Stellwert" Feedback Control Value "Z" =RO */
// DSP_INT I_fbw; /*15 19*< I full Band width */
// DSP_INT zxx; /*16 20*< spacer */
// DSP_INT zyy; /*17 21*< spacer */
// DSP_LONG I_avg; /*18 22*< not normalized, 256x */
// DSP_LONG I_rms; /*19 24*< not normalized, 256x */
// DSP: FEEDBACK_MIXER
// DSP_INT level[4]; /**< 0 if FUZZY MODE: Level for FUZZY interaction =RW */
// DSP_INT gain[4]; /**< 4 Gain for signal in Q15 rep =RW */
// DSP_INT mode[4]; /**< 8 mixer mode: 0=OFF -- Bit=1/0 for Bit0: Log/Lin, 1:IIR/FULL, 2:FUZZY/NORMAL */
// DSP_INT setpoint[4]; /**< 12 individual setpoint for every signal */
// DSP_INT src_lookup[4]; /**< 16 mixer input source lookups
void sranger_mk3_hwi_dev::conv_dsp_feedback (){
CONV_32 (dsp_z_servo.cp);
CONV_32 (dsp_z_servo.ci);
CONV_32 (dsp_z_servo.setpoint);
CONV_32 (dsp_z_servo.input);
CONV_32 (dsp_m_servo.cp);
CONV_32 (dsp_m_servo.ci);
CONV_32 (dsp_m_servo.setpoint);
CONV_32 (dsp_m_servo.input);
for (int i=0; i<4; ++i){
CONV_32 (dsp_feedback_mixer.level[i]);
CONV_32 (dsp_feedback_mixer.gain[i]);
CONV_32 (dsp_feedback_mixer.mode[i]);
CONV_32 (dsp_feedback_mixer.setpoint[i]);
CONV_32 (dsp_feedback_mixer.src_lookup[i]);
CONV_32 (dsp_feedback_mixer.input_p[i]);
CONV_32 (dsp_feedback_mixer.iir_ca_q15[i]);
CONV_32 (dsp_feedback_mixer.iir_signal[i]); // **
}
CONV_32 (dsp_feedback_mixer.cb_Ic);
CONV_32 (dsp_feedback_mixer.I_cross);
CONV_32 (dsp_feedback_mixer.I_offset);
CONV_32 (dsp_feedback_mixer.q_factor15);
CONV_32 (dsp_feedback_mixer.delta); // **
}
void sranger_mk3_hwi_dev::read_dsp_feedback (){
lseek (dsp, magic_data.z_servo, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_z_servo, sizeof (SERVO_MK3), "Rd-DSP-Z-Servo");
lseek (dsp, magic_data.m_servo, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_m_servo, sizeof (SERVO_MK3), "Rd-DSP-M-Servo");
lseek (dsp, magic_data.feedback_mixer, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_feedback_mixer, sizeof (FEEDBACK_MIXER_MK3), "Rd-DSP-FBMIX"); // read back..., "f0-now" (q_factor_15)
// from DSP to PC -- only SetPoint!
conv_dsp_feedback ();
}
void sranger_mk3_hwi_dev::write_dsp_feedback (
double set_point[4], double factor[4], double gain[4], double level[4], int transform_mode[4],
double IIR_I_crossover, double IIR_f0_max[4], double IIR_f0_min, double LOG_I_offset, int IIR_flag,
double z_servo[3], double m_servo[3], double pllref){
for (int i=0; i<4; ++i){
dsp_feedback_mixer.setpoint[i] = (int)(round(256.*gapp->xsm->Inst->VoltIn2Dig (factor[i]*set_point[i]))); // Q23
dsp_feedback_mixer.level[i] = (int)(round(256.*gapp->xsm->Inst->VoltIn2Dig (factor[i]*level[i])));
dsp_feedback_mixer.gain[i] = float_2_sranger_q15 (gain[i]);
dsp_feedback_mixer.mode[i] = transform_mode[i];
dsp_feedback_mixer.iir_ca_q15[i] = float_2_sranger_q15 (exp (-2.*M_PI*IIR_f0_max[i]/75000.));
std::cout << "IIR["<<i<<"]: "<< dsp_feedback_mixer.iir_ca_q15[i] << std::endl;
}
// IIR self adaptive filter parameters for MIX0 channel, MIX1..3 IIR only -- assuming current
double ca,cb;
double Ic = gapp->xsm->Inst->VoltIn2Dig (gapp->xsm->Inst->nAmpere2V (1e-3*IIR_I_crossover)); // given in pA
ca = exp (-2.*M_PI*IIR_f0_max[0]/75000.);
dsp_feedback_mixer.cb_Ic = (DSP_INT32) (32767. * (cb = IIR_f0_min/IIR_f0_max[0] * Ic));
dsp_feedback_mixer.I_cross = (int)Ic;
dsp_feedback_mixer.I_offset = (int)(round(256.*gapp->xsm->Inst->VoltIn2Dig (gapp->xsm->Inst->nAmpere2V (1e-3*LOG_I_offset)))); // given in pA -- MK3: Q23
if (!IIR_flag)
dsp_feedback_mixer.I_cross = 0; // disable IIR!
#if 0
if (!IIR_flag)
std::cout << "IIR: off" << std::endl;
else {
std::cout << "IIR: ca' Q15= " << dsp_feedback_mixer.ca_q15 << " := " << ca << std::endl;
std::cout << "IIR: cb_Ic' Q31= " << dsp_feedback_mixer.cb_Ic << " := " << cb << std::endl;
std::cout << "IIR: Ic = " << dsp_feedback_mixer.I_cross << std::endl;
std::cout << "IIR: Io = " << dsp_feedback_mixer.I_offset << std::endl;
}
#endif
// Z-Servo --- master feedback settings
// Scale Regler Consts. with 1/VZ and convert to SR-Q15
// NOTE: CP, CI-DSP max at gain "1" = 1 in Q32 -- arb. div/100 for max assumed gain of 100.
dsp_z_servo.cp = float_2_sranger_q31 (0.01 * z_servo[1] / sranger_mk2_hwi_pi.app->xsm->Inst->VZ ());
dsp_z_servo.ci = float_2_sranger_q31 (0.01 * z_servo[2] / sranger_mk2_hwi_pi.app->xsm->Inst->VZ ());
// Motor Servo:
dsp_m_servo.setpoint = float_2_sranger_q31 (256.*gapp->xsm->Inst->VoltIn2Dig (m_servo[0]));
dsp_m_servo.cp = float_2_sranger_q31 (0.01 * m_servo[1]);
dsp_m_servo.ci = float_2_sranger_q31 (0.01 * m_servo[2]);
// from PC to DSP
conv_dsp_feedback ();
lseek (dsp, magic_data.z_servo, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_z_servo, MAX_WRITE_SERVO<<1);
lseek (dsp, magic_data.m_servo, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_m_servo, MAX_WRITE_SERVO<<1);
lseek (dsp, magic_data.feedback_mixer, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_feedback_mixer, MAX_WRITE_FEEDBACK_MIXER<<1);
// from DSP to PC
conv_dsp_feedback ();
}
void sranger_mk3_hwi_dev::recalculate_dsp_scan_speed_parameters () {
double tmp;
DSPControlClass->recalculate_dsp_scan_speed_parameters (tmp_dnx, tmp_dny, tmp_fs_dx, tmp_fs_dy, tmp_nx_pre, tmp_fast_return);
g_print ("*** recalulated DSP scan speed parameters [MK3-Pro] ***\n");
g_print ("sizeof dsp_scan %d B\n", (int) sizeof (dsp_scan));
g_print ("sizeof scan.fs_dx %d B\n", (int) sizeof (dsp_scan.fs_dx));
dsp_scan.fs_dx = (DSP_INT32)tmp_fs_dx;
dsp_scan.fs_dy = (DSP_INT32)tmp_fs_dy;
dsp_scan.dnx = (DSP_INT32)tmp_dnx;
dsp_scan.dny = (DSP_INT32)tmp_dny;
dsp_scan.nx_pre = (DSP_INT32)tmp_nx_pre;
dsp_scan.fast_return = (DSP_INT32)tmp_fast_return;
tmp = 1000. + 3. * ( fabs ((double)dsp_scan.fs_dx*(double)dsp_scan.fm_dz0_xy_vec[i_X]) + fabs((double)dsp_scan.fs_dy*(double)dsp_scan.fm_dz0_xy_vec[i_Y]) )/2147483648.; // =1<<31
g_print ("Z-Slope-Max 3x (real): %g \n", tmp);
if (tmp > 67108864.)
tmp = 67108864.; // 1<<26
g_print ("Z-Slope-Max (real, lim): %g \n", tmp);
dsp_scan.z_slope_max = (DSP_INT32)(tmp);
dsp_scan.Zoff_2nd_xp = tmp_sRe = 0;
dsp_scan.Zoff_2nd_xm = tmp_sIm = 0;
if (tmp_fast_return == -1){ // -1: indicates fast scan mode with X sin actuation
#define CPN(N) ((double)(1LL<<(N))-1.)
double deltasRe, deltasIm;
double Num = (double)dsp_scan.dnx * (double)Nx * 2. + (double)dsp_scan.dny + (double) dsp_scan.nx_pre;
// calculate Sine generator parameter
// -- here 2147483647 * cos (2pi/N), N=n*dnx*2+dny **** cos (2.*M_PI*freq[0]/150000.))
deltasRe = round (CPN(31) * cos (2.*M_PI/Num));
deltasIm = round (CPN(31) * sin (2.*M_PI/Num));
dsp_scan.Zoff_2nd_xp = tmp_sRe = (int)deltasRe; // shared variables, no 2nd line mode in fast scan!
dsp_scan.Zoff_2nd_xm = tmp_sIm = (int)deltasIm;
g_print ("DNX*NX*2+DNY......** %12.2f \n", Num);
g_print ("deltasRe..........** %d \n",dsp_scan.Zoff_2nd_xp);
g_print ("deltasIm..........** %d \n",dsp_scan.Zoff_2nd_xm);
}
g_print ("x,y slope....** %d, %d \n", dsp_scan.fm_dz0_xy_vec[i_X], dsp_scan.fm_dz0_xy_vec[i_Y]);
g_print ("z_slope_max..** %d \n", dsp_scan.z_slope_max);
g_print ("FSdX.........** %d \n", dsp_scan.fs_dx);
g_print ("FSdY.........** %d \n", dsp_scan.fs_dy);
g_print ("DNX..........** %d \n", dsp_scan.dnx);
g_print ("DNY..........** %d \n", dsp_scan.dny);
g_print ("NX...........** %d \n", (int)Nx);
g_print ("NY...........** %d \n", (int)Ny);
g_print ("NXPre........** %d \n", dsp_scan.nx_pre);
}
void sranger_mk3_hwi_dev::recalculate_dsp_scan_slope_parameters () {
double tmp;
double swx = (double)dsp_scan.fs_dx * (double)dsp_scan.dnx * (double)dsp_scan.nx / 4294967296.; // =1<<32
double swy = (double)dsp_scan.fs_dy * (double)dsp_scan.dny * (double)dsp_scan.ny / 4294967296.; // =1<<32
DSPControlClass->recalculate_dsp_scan_slope_parameters (dsp_scan.fs_dx, dsp_scan.fs_dy,
dsp_scan.fm_dz0_xy_vec[i_X], dsp_scan.fm_dz0_xy_vec[i_Y],
swx, swy);
g_print ("*** recalulated DSP slope parameters ***\n");
g_print ("FM_dz0x......** %d\n", dsp_scan.fm_dz0_xy_vec[i_X]);
g_print ("FM_dz0y......** %d\n", dsp_scan.fm_dz0_xy_vec[i_Y]);
tmp = 1000. + 3. * ( fabs ((double)dsp_scan.fs_dx*(double)dsp_scan.fm_dz0_xy_vec[i_X]) + fabs((double)dsp_scan.fs_dy*(double)dsp_scan.fm_dz0_xy_vec[i_Y]) )/2147483648.; // =1<<31
g_print ("Z-Slope-Max 3x (real): %g \n", tmp);
if (tmp > 67108864.)
tmp = 67108864.; // 1<<26
g_print ("Z-Slope-Max (real, lim): %g \n", tmp);
dsp_scan.z_slope_max = (DSP_INT32)(tmp);
}
void sranger_mk3_hwi_dev::conv_dsp_analog (){
CONV_32 (dsp_analog.bias);
CONV_32 (dsp_analog.motor);
}
void sranger_mk3_hwi_dev::read_dsp_analog (){
// read all analog
lseek (dsp, magic_data.analog, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_analog, sizeof (dsp_analog), "Rd-DSP-ANALOG");
// from DSP to PC
conv_dsp_analog ();
}
void sranger_mk3_hwi_dev::write_dsp_analog (double bias, double motor){
read_dsp_analog ();
dsp_analog.bias = (gint32)round (CONST_DSP_F16*gapp->xsm->Inst->VoltOut2Dig (gapp->xsm->Inst->BiasV2Vabs (bias)));
dsp_analog.motor = (gint32)round (CONST_DSP_F16*gapp->xsm->Inst->VoltOut2Dig (gapp->xsm->Inst->BiasV2Vabs (motor)));
// only "bias" and "motor" is touched here!
// from PC to DSP
conv_dsp_analog ();
lseek (dsp, magic_data.analog, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_analog, MAX_WRITE_ANALOG_CONTROL<<1);
// from DSP to PC
conv_dsp_analog ();
}
void sranger_mk3_hwi_dev::conv_dsp_scan (){
CONV_32 (dsp_scan.rotm[0]);
CONV_32 (dsp_scan.rotm[1]);
CONV_32 (dsp_scan.rotm[2]);
CONV_32 (dsp_scan.rotm[3]);
CONV_32 (dsp_scan.fast_return);
CONV_32 (dsp_scan.z_slope_max);
CONV_32 (dsp_scan.nx_pre);
CONV_32 (dsp_scan.dnx_probe);
CONV_32 (dsp_scan.raster_a);
CONV_32 (dsp_scan.raster_b);
CONV_32 (dsp_scan.srcs_xp);
CONV_32 (dsp_scan.srcs_xm);
CONV_32 (dsp_scan.srcs_2nd_xp);
CONV_32 (dsp_scan.srcs_2nd_xm);
CONV_32 (dsp_scan.nx);
CONV_32 (dsp_scan.ny);
CONV_32 (dsp_scan.fs_dx);
CONV_32 (dsp_scan.fs_dy);
CONV_32 (dsp_scan.num_steps_move_xy);
CONV_32 (dsp_scan.fm_dx);
CONV_32 (dsp_scan.fm_dy);
CONV_32 (dsp_scan.fm_dzxy);
CONV_32 (dsp_scan.fm_dz0_xy_vec[i_X]);
CONV_32 (dsp_scan.fm_dz0_xy_vec[i_Y]);
CONV_32 (dsp_scan.dnx);
CONV_32 (dsp_scan.dny);
CONV_32 (dsp_scan.Zoff_2nd_xp);
CONV_32 (dsp_scan.Zoff_2nd_xm);
CONV_32 (dsp_scan.xyz_vec[i_X]);
CONV_32 (dsp_scan.xyz_vec[i_Y]);
CONV_32 (dsp_scan.cfs_dx);
CONV_32 (dsp_scan.cfs_dy);
// gain mirrors
CONV_32 (dsp_scan.xyz_gain);
CONV_32 (dsp_move.xyz_gain);
// RO:
CONV_32 (dsp_scan.sstate);
CONV_32 (dsp_scan.pflg);
}
void sranger_mk3_hwi_dev::read_dsp_scan (gint32 &pflg){
lseek (dsp, magic_data.scan, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_scan, sizeof (dsp_scan));
// from DSP to PC
conv_dsp_scan ();
pflg = dsp_scan.pflg;
}
void sranger_mk3_hwi_dev::write_dsp_scan (){
// from PC to DSP
conv_dsp_scan ();
// adjust ScanParams/Speed...
lseek (dsp, magic_data.scan, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_scan, MAX_WRITE_SCAN<<1);
// from DSP to PC
conv_dsp_scan ();
}
void sranger_mk3_hwi_dev::conv_dsp_scan_event_trigger (){
for (int i=0; i<8; ++i){
CONV_32 (dsp_scan_event_trigger.trig_i_xp[i]);
CONV_32 (dsp_scan_event_trigger.trig_i_xm[i]);
CONV_32 (dsp_scan_event_trigger.xp_bias_setpoint[i]);
CONV_32 (dsp_scan_event_trigger.xm_bias_setpoint[i]);
}
CONV_32 (dsp_scan_event_trigger.pflg);
}
void sranger_mk3_hwi_dev::read_dsp_scan_event_trigger (int &pflg, int i_xp[], int i_xm[], double sp_xp[], double sp_xm[]) {
lseek (dsp, magic_data.scan_event_trigger, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_scan_event_trigger, sizeof (dsp_scan_event_trigger));
// from DSP to PC
conv_dsp_scan_event_trigger ();
pflg = dsp_scan_event_trigger.pflg;
for (int i=0; i<8; ++i){
i_xp[i] = dsp_scan_event_trigger.trig_i_xp[i];
i_xm[i] = dsp_scan_event_trigger.trig_i_xm[i];
if (i<4){
sp_xp[i] = gapp->xsm->Inst->V2BiasV (gapp->xsm->Inst->Dig2VoltOut (dsp_scan_event_trigger.xp_bias_setpoint[i]));
sp_xm[i] = gapp->xsm->Inst->V2BiasV (gapp->xsm->Inst->Dig2VoltOut (dsp_scan_event_trigger.xm_bias_setpoint[i]));
} else {
if (IS_AFM_CTRL){ // AFM (linear)
if (strncmp (xsmres.daqZunit[0], "nN", 2) == 0)
;
else if (strncmp (xsmres.daqZunit[0], "Hz", 2) == 0)
;
else
;
} else {// STM (log)
double f = gapp->xsm->Inst->nAmpere2V (1.);
sp_xp[i] = gapp->xsm->Inst->Dig2VoltIn (dsp_scan_event_trigger.xp_bias_setpoint[i]) / f;
sp_xm[i] = gapp->xsm->Inst->Dig2VoltIn (dsp_scan_event_trigger.xm_bias_setpoint[i]) / f;
}
}
}
}
void sranger_mk3_hwi_dev::write_dsp_scan_event_trigger (int &pflg, int i_xp[], int i_xm[], double sp_xp[], double sp_xm[]) {
dsp_scan_event_trigger.pflg = pflg;
for (int i=0; i<8; ++i){
dsp_scan_event_trigger.trig_i_xp[i] = i_xp[i];
dsp_scan_event_trigger.trig_i_xm[i] = i_xm[i];
if (i<4){
dsp_scan_event_trigger.xp_bias_setpoint[i] = (DSP_INT32) round (gapp->xsm->Inst->VoltOut2Dig (gapp->xsm->Inst->BiasV2Vabs (sp_xp[i])));
dsp_scan_event_trigger.xm_bias_setpoint[i] = (DSP_INT32) round (gapp->xsm->Inst->VoltOut2Dig (gapp->xsm->Inst->BiasV2Vabs (sp_xm[i])));
} else {
if (IS_AFM_CTRL){ // AFM (linear)
if (strncmp (xsmres.daqZunit[0], "nN", 2) == 0)
;
else if (strncmp (xsmres.daqZunit[0], "Hz", 2) == 0)
;
else
;
} else {// STM (log)
dsp_scan_event_trigger.xp_bias_setpoint[i] = (DSP_INT32) (gapp->xsm->Inst->VoltIn2Dig (gapp->xsm->Inst->nAmpere2V (sp_xp[i])));
dsp_scan_event_trigger.xm_bias_setpoint[i] = (DSP_INT32) (gapp->xsm->Inst->VoltIn2Dig (gapp->xsm->Inst->nAmpere2V (sp_xm[i])));
}
}
}
// from PC to DSP
conv_dsp_scan_event_trigger ();
lseek (dsp, magic_data.scan_event_trigger, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_scan_event_trigger, MAX_WRITE_SCAN_EVENT_TRIGGER<<1);
// from DSP to PC
conv_dsp_scan_event_trigger ();
}
void sranger_mk3_hwi_dev::conv_dsp_probe (){
CONV_32 (dsp_probe.start);
CONV_32 (dsp_probe.LIM_up);
CONV_32 (dsp_probe.LIM_dn);
CONV_32 (dsp_probe.noise_amp);
CONV_32 (dsp_probe.AC_amp);
CONV_32 (dsp_probe.AC_frq);
CONV_32 (dsp_probe.AC_phaseA);
CONV_32 (dsp_probe.AC_phaseB);
CONV_32 (dsp_probe.AC_nAve);
CONV_32 (dsp_probe.state);
// CONV_32 (dsp_probe.);
CONV_32 (dsp_probe.vector_head);
}
void sranger_mk3_hwi_dev::read_dsp_lockin (double &AC_amp, double &AC_frq, double &AC_phaseA, double &AC_phaseB, gint32 &AC_lockin_avg_cycels){
lseek (dsp, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_probe, sizeof (dsp_probe));
// from DSP to PC
conv_dsp_probe ();
// update, reconvert
AC_amp = gapp->xsm->Inst->Dig2VoltOut ((double)dsp_probe.AC_amp) / gapp->xsm->Inst->BiasV2V (1.);
AC_frq = dsp_probe.AC_frq; // tmp fix, DSP assumes still 22000
if (AC_frq < 32)
AC_frq = 1. + 75000./128.*AC_frq;
AC_phaseA = (double)dsp_probe.AC_phaseA/16.;
AC_phaseB = (double)dsp_probe.AC_phaseB/16.;
AC_lockin_avg_cycels = dsp_probe.AC_nAve;
}
int sranger_mk3_hwi_dev::dsp_lockin_state(int set=-1){
PROBE_MK3 dsp_probe;
dsp_probe.start = 0;
dsp_probe.stop = 0;
switch (set){
case 0: dsp_probe.stop = PROBE_RUN_LOCKIN_FREE;
CONV_32 (dsp_probe.start);
CONV_32 (dsp_probe.stop);
lseek (dsp, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_probe, MAX_WRITE_PROBE<<1);
return 0;
break;
case 1: dsp_probe.start = PROBE_RUN_LOCKIN_FREE;
CONV_32 (dsp_probe.start);
CONV_32 (dsp_probe.stop);
lseek (dsp, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_probe, MAX_WRITE_PROBE<<1);
return 0;
break;
case -1:
lseek (dsp, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_probe, sizeof (dsp_probe));
CONV_32 (dsp_probe.state);
return dsp_probe.state == PROBE_RUN_LOCKIN_FREE ? 1:0;
break;
}
return -1;
}
void sranger_mk3_hwi_dev::write_dsp_lockin_probe_final (double AC_amp, double AC_frq, double AC_phaseA, double AC_phaseB, gint32 AC_lockin_avg_cycels, double VP_lim_val, double noise_amp, int start) {
// update all from DSP
lseek (dsp, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_probe, sizeof (dsp_probe));
// from DSP to PC
conv_dsp_probe ();
// update with changed user parameters
dsp_probe.start = start ? 1:0;
dsp_probe.LIM_up = VOLT2AIC (VP_lim_val);
dsp_probe.LIM_dn = VOLT2AIC (VP_lim_val);
dsp_probe.AC_amp = VOLT2AIC (AC_amp);
dsp_probe.AC_frq = (int) (AC_frq); // DSP selects dicrete AC Freq. out of 75000/(128/N) N=1,2,4,8
dsp_probe.AC_phaseA = (int)round(AC_phaseA*16.);
dsp_probe.AC_phaseB = (int)round(AC_phaseB*16.);
dsp_probe.AC_nAve = AC_lockin_avg_cycels;
if (DSPPACClass)
dsp_probe.noise_amp = VOLT2AIC (noise_amp);
//## for (int i=0; i<4; ++i){
// dsp_probe.src_lookup[i] = src_lookup[i];
// dsp_probe.prb_lookup[i] = prb_lookup[i];
// dsp_probe.LockIn_lookup[i] = lockin_lookup[i];
// }
// from PC to DSP
conv_dsp_probe ();
lseek (dsp, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_probe, MAX_WRITE_PROBE<<1);
// from DSP to PC
conv_dsp_probe ();
}
void sranger_mk3_hwi_dev::conv_dsp_vector (){
CONV_32 (dsp_vector.n);
CONV_32 (dsp_vector.dnx);
CONV_32 (dsp_vector.srcs);
CONV_32 (dsp_vector.options);
CONV_32 (dsp_vector.ptr_fb);
CONV_32 (dsp_vector.repetitions);
CONV_32 (dsp_vector.i);
CONV_32 (dsp_vector.j);
CONV_32 (dsp_vector.ptr_next);
CONV_32 (dsp_vector.ptr_final);
CONV_32 (dsp_vector.f_du);
CONV_32 (dsp_vector.f_dx);
CONV_32 (dsp_vector.f_dy);
CONV_32 (dsp_vector.f_dz);
CONV_32 (dsp_vector.f_dx0);
CONV_32 (dsp_vector.f_dy0);
CONV_32 (dsp_vector.f_dphi);
}
// PZ may need t oadjust...
#define EXTERN_PROBE_VECTOR_HEAD_DEFAULT 0x10F14000
void sranger_mk3_hwi_dev::write_dsp_vector (int index, PROBE_VECTOR_GENERIC *__dsp_vector){
// update all from DSP
lseek (dsp, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_probe, sizeof (dsp_probe));
// from DSP to PC
conv_dsp_probe ();
if (dsp_probe.vector_head < EXTERN_PROBE_VECTOR_HEAD_DEFAULT || index > 40 || index < 0){
sranger_mk2_hwi_pi.app->message("Error writing Probe Vector:\n Bad vector address, aborting request.");
return;
}
// copy/convert to DSP format
dsp_vector.n = __dsp_vector->n;
dsp_vector.dnx = __dsp_vector->dnx;
dsp_vector.srcs = __dsp_vector->srcs;
dsp_vector.options = __dsp_vector->options;
dsp_vector.ptr_fb = __dsp_vector->ptr_fb;
dsp_vector.repetitions = __dsp_vector->repetitions;
dsp_vector.i = __dsp_vector->i;
dsp_vector.j = __dsp_vector->j;
dsp_vector.ptr_next = __dsp_vector->ptr_next;
dsp_vector.ptr_final = __dsp_vector->ptr_final;
dsp_vector.f_du = __dsp_vector->f_du;
dsp_vector.f_dx = __dsp_vector->f_dx;
dsp_vector.f_dy = __dsp_vector->f_dy;
dsp_vector.f_dz = __dsp_vector->f_dz;
dsp_vector.f_dx0 = __dsp_vector->f_dx0;
dsp_vector.f_dy0 = __dsp_vector->f_dy0;
dsp_vector.f_dphi = __dsp_vector->f_dphi;
// check count ranges
if (dsp_vector.dnx < 0 || dsp_vector.dnx > 32767 || dsp_vector.n < 0 || dsp_vector.n > 32767){
GtkWidget *dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_CLOSE,
"Probe Vector [pc%02d] not acceptable:\n"
"n = %6d [0..32767]\n"
"dnx = %6d [0..32767]\n"
"ATTENTION: May result in unpredictable probe actions.\n"
"AUTO-LIMITING FOR SAFETY.\n"
"Hint: adjust slope/speed/points.. to make fit.",
index, dsp_vector.n, dsp_vector.dnx
);
g_signal_connect_swapped (GTK_OBJECT (dialog), "response",
G_CALLBACK (gtk_widget_destroy),
GTK_OBJECT (dialog));
gtk_widget_show (dialog);
if (dsp_vector.dnx < 0) dsp_vector.dnx = 0;
if (dsp_vector.dnx > 32767) dsp_vector.dnx = 32767;
if (dsp_vector.n < 0) dsp_vector.n = 0;
if (dsp_vector.n > 32767) dsp_vector.n = 32767;
}
// setup VPC essentials
dsp_vector.i = dsp_vector.repetitions; // preload repetitions counter now! (if now already done)
dsp_vector.j = 0; // not yet used -- XXXX
// from PC to to DSP format
conv_dsp_vector();
lseek (dsp, dsp_probe.vector_head + ((index*SIZE_OF_PROBE_VECTOR)<<1), SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &dsp_vector, SIZE_OF_PROBE_VECTOR<<1);
// from DSP to PC
conv_dsp_vector();
}
void sranger_mk3_hwi_dev::read_dsp_vector (int index, PROBE_VECTOR_GENERIC *__dsp_vector){
// update all from DSP
lseek (dsp, magic_data.probe, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_probe, sizeof (dsp_probe));
// from DSP to PC
conv_dsp_probe ();
if (dsp_probe.vector_head < EXTERN_PROBE_VECTOR_HEAD_DEFAULT || index > 40 || index < 0){
sranger_mk2_hwi_pi.app->message("Error reading Probe Vector:\n Bad vector address, aborting request.\n\n");
return;
}
lseek (dsp, dsp_probe.vector_head + ((index*SIZE_OF_PROBE_VECTOR)<<1), SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_vector, SIZE_OF_PROBE_VECTOR<<1);
// from DSP to PC
conv_dsp_vector();
// copy/convert from DSP format
__dsp_vector->n = dsp_vector.n;
__dsp_vector->dnx = dsp_vector.dnx;
__dsp_vector->srcs = dsp_vector.srcs;
__dsp_vector->options = dsp_vector.options;
__dsp_vector->ptr_fb = dsp_vector.ptr_fb;
__dsp_vector->repetitions = dsp_vector.repetitions;
__dsp_vector->i = dsp_vector.i;
__dsp_vector->j = dsp_vector.j;
__dsp_vector->ptr_next = dsp_vector.ptr_next;
__dsp_vector->ptr_final = dsp_vector.ptr_final;
__dsp_vector->f_du = dsp_vector.f_du;
__dsp_vector->f_dx = dsp_vector.f_dx;
__dsp_vector->f_dy = dsp_vector.f_dy;
__dsp_vector->f_dz = dsp_vector.f_dz;
__dsp_vector->f_dx0 = dsp_vector.f_dx0;
__dsp_vector->f_dy0 = dsp_vector.f_dy0;
__dsp_vector->f_dphi = dsp_vector.f_dphi;
}
int sranger_mk3_hwi_dev::read_pll_symbols (){
g_print ("sranger_mk3_hwi_dev::read_pll_symbols\n");
lseek (dsp, magic_data.PLL_lookup, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_pll, sizeof (dsp_pll));
// **** THESE ARE ONLY ADRESSES FOR ACCESS!!! NOT THE DATA ITSELF ******
CONV_32 (dsp_pll.pSignal1);
CONV_32 (dsp_pll.pSignal2);
CONV_32 (dsp_pll.Signal1);
CONV_32 (dsp_pll.Signal2);
// Block length
CONV_32 (dsp_pll.blcklen); // Max MaxSizeSigBuf-1
// Sine variables
CONV_32 (dsp_pll.deltaReT);
CONV_32 (dsp_pll.deltaImT);
CONV_32 (dsp_pll.volumeSine);
// Phase/Amp detector time constant
CONV_32 (dsp_pll.Tau_PAC);
// Phase corrector variables
CONV_32 (dsp_pll.PI_Phase_Out);
CONV_32 (dsp_pll.pcoef_Phase);
CONV_32 (dsp_pll.icoef_Phase);
CONV_32 (dsp_pll.errorPI_Phase);
CONV_32 (dsp_pll.memI_Phase);
CONV_32 (dsp_pll.setpoint_Phase);
CONV_32 (dsp_pll.ctrlmode_Phase);
CONV_32 (dsp_pll.corrmin_Phase);
CONV_32 (dsp_pll.corrmax_Phase);
// Min/Max for the output signals
CONV_32 (dsp_pll.ClipMin);
CONV_32 (dsp_pll.ClipMax);
// Amp corrector variables
CONV_32 (dsp_pll.ctrlmode_Amp);
CONV_32 (dsp_pll.corrmin_Amp);
CONV_32 (dsp_pll.corrmax_Amp);
CONV_32 (dsp_pll.setpoint_Amp);
CONV_32 (dsp_pll.pcoef_Amp);
CONV_32 (dsp_pll.icoef_Amp);
CONV_32 (dsp_pll.errorPI_Amp);
CONV_32 (dsp_pll.memI_Amp);
// LP filter selections
CONV_32 (dsp_pll.LPSelect_Phase);
CONV_32 (dsp_pll.LPSelect_Amp);
// pointers to live signals
CONV_32 (dsp_pll.InputFiltered); // Resonator Output Signal
CONV_32 (dsp_pll.SineOut0); // Excitation Signal
CONV_32 (dsp_pll.phase); // Resonator Phase (no LP filter)
CONV_32 (dsp_pll.PI_Phase_OutMonitor); // Excitation Freq. (no LP filter)
CONV_32 (dsp_pll.amp_estimation); // Resonator Amp. (no LP filter)
CONV_32 (dsp_pll.volumeSineMonitor); // Excitation Amp. (no LP filter) (same as volumeSine)
CONV_32 (dsp_pll.Filter64Out); // Filter64Out [4]: Excitation Freq. (with LP filter), ...
return 0;
} // returns 0 if PLL capability available, else -1
// #define PAC_DEBUGL0_PRINT(format,args...) { g_print(format,##args); }
#define PAC_DEBUGL0_PRINT(format,args...) {;}
//#define PAC_DEBUGLR_PRINT(format,args...) { g_print(format,##args); }
#define PAC_DEBUGLR_PRINT(format,args...) {;}
#define PAC_DEBUGL1_PRINT(format,args...) { g_print(format,##args); }
//#define PAC_DEBUGL1_PRINT(format,args...) {;}
#define PAC_DEBUGL2_PRINT(format,args...) { g_print(format,##args); }
//#define PAC_DEBUGL2_PRINT(format,args...) {;}
double sranger_mk3_hwi_dev::read_pll_variable32 (gint64 address){
gint32 x;
lseek (dsp, address, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &x, sizeof (x));
CONV_32 (x);
PAC_DEBUGL0_PRINT ("sranger_mk3_hwi_dev::read_variable32[0x%06x] = %d\n", address, x);
return (double)x;
}
gint32 sranger_mk3_hwi_dev::read_pll_variable32i (gint64 address){
gint32 x;
lseek (dsp, address, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &x, sizeof (x));
CONV_32 (x);
PAC_DEBUGL0_PRINT ("sranger_mk3_hwi_dev::read_variable32[0x%06x] = %d\n", address, x);
return (double)x;
}
void sranger_mk3_hwi_dev::write_pll_variable32 (gint64 address, double val){
gint32 x = (gint32)val;
PAC_DEBUGL0_PRINT ("sranger_mk3_hwi_dev::write_variable32[0x%06x] = %d\n", address, x);
CONV_32 (x);
lseek (dsp, address, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &x, sizeof (x));
}
void sranger_mk3_hwi_dev::write_pll_variable32 (gint64 address, gint32 val){
gint32 x = val;
PAC_DEBUGL0_PRINT ("sranger_mk3_hwi_dev::write_variable32[0x%06x] = %d\n", address, x);
CONV_32 (x);
lseek (dsp, address, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &x, sizeof (x));
}
// 64bit writes must be atomic!!!
double sranger_mk3_hwi_dev::read_pll_variable64 (gint64 address){
union { gint32 a,b; gint64 x; } v64;
// if (ioctl(dsp, SRANGER_MK3_IOCTL_NON_ATOMIC_TRANSFER, 0) < 0){
// PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::write_pll_variable64: ERROR SWITCHING MK3 TO ATOMIC TRANSFER.\n");
// return 0.;
// }
lseek (dsp, address, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &v64.x, sizeof (v64.x));
// if ((ioctl(dsp, SRANGER_MK3_IOCTL_ATOMIC_TRANSFER, 0)) < 0){
// PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::write_pll_variable64: ERROR SWITCHING MK3 BACK TO NON-ATOMIC TRANSFER.\n");
// }
CONV_32 (v64.a);
CONV_32 (v64.b);
return (double)v64.x;
}
void sranger_mk3_hwi_dev::write_pll_variable64 (gint64 address, gint64 val){
union { gint32 a,b; gint64 x; } v64;
v64.x = val;
CONV_32 (v64.a);
CONV_32 (v64.b);
// if (ioctl(dsp, SRANGER_MK3_IOCTL_NON_ATOMIC_TRANSFER, 0) < 0){
// PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::write_pll_variable64: ERROR SWITCHING MK3 TO ATOMIC TRANSFER.\n");
// return;
// }
lseek (dsp, address, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &v64.x, sizeof (v64.x));
// if ((ioctl(dsp, SRANGER_MK3_IOCTL_ATOMIC_TRANSFER, 0)) < 0){
// PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::write_pll_variable64: ERROR SWITCHING MK3 BACK TO NON-ATOMIC TRANSFER.\n");
// return;
// }
}
void sranger_mk3_hwi_dev::write_pll_variable64 (gint64 address, double val){
write_pll_variable64 (address, (gint64)val);
}
void sranger_mk3_hwi_dev::read_pll_array32 (gint64 address, int n, gint32 *arr){
lseek (dsp, address, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, arr, n * sizeof (arr[0]));
for (int i=0; i<n; ++i)
CONV_32 (arr[i]);
}
void sranger_mk3_hwi_dev::write_pll_array32 (gint64 address, int n, gint32 *arr){
for (int i=0; i<n; ++i)
CONV_32 (arr[i]);
lseek (dsp, address, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, arr, n * sizeof (arr[0]));
for (int i=0; i<n; ++i)
CONV_32 (arr[i]);
}
#define CPN(N) ((double)(1LL<<(N))-1.)
int sranger_mk3_hwi_dev::read_pll (PAC_control &pll, PLL_GROUP group){
// make sure we got tht symbols read
if (group & PLL_SYMBOLS || dsp_pll.volumeSine == 0)
read_pll_symbols ();
if (group & PLL_TAUPAC){
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- PLL_TAU_PAC --\n");
double tau = read_pll_variable32 (dsp_pll.Tau_PAC);
if (tau > 0.)
pll.Tau_PAC = CPN(22)*1.5e-5 / tau;
else
pll.Tau_PAC = 0.;
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll Tau_PAC = %g s\n", pll.Tau_PAC);
}
if (group & PLL_SINE){
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- PLL_SINE --\n");
pll.deltaReT = read_pll_variable32 (dsp_pll.deltaReT);
pll.deltaImT = read_pll_variable32 (dsp_pll.deltaImT);
// pll.FSineHz = pll.deltaImT*150000./(2.*M_PI);
// re = CPN(31), im = 2pi Freq / 150000
pll.FSineHz = read_pll_variable32 (dsp_pll.PI_Phase_Out)*150000./(CPN(29)*2.*M_PI);
pll.PI_Phase_Out = pll.FSineHz;
pll.volumeSine = read_pll_variable32 (dsp_pll.volumeSine)*10./CPN(22);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll deltaReT = %g\n", pll.deltaReT);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll deltaImT = %g\n", pll.deltaImT);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll PI_Phase_Out = %g Hz (=FSineHz)\n", pll.PI_Phase_Out);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll volumeSine = %g V\n", pll.volumeSine);
}
if (group & PLL_CONTROLLER_PHASE){
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- PLL_CONTROLLER_PHASE --\n");
pll.ctrlmode_Phase = read_pll_variable32 (dsp_pll.ctrlmode_Phase);
pll.setpoint_Phase = 0; read_pll_variable32 (dsp_pll.setpoint_Phase)*180./(CPN(22)*M_PI);
pll.corrmax_Phase = read_pll_variable64 (dsp_pll.corrmax_Phase)*150000./(CPN(58)*2.*M_PI);
pll.corrmin_Phase = read_pll_variable64 (dsp_pll.corrmin_Phase)*150000./(CPN(58)*2.*M_PI);
pll.memI_Phase = read_pll_variable64 (dsp_pll.memI_Phase)*150000./(CPN(58)*2.*M_PI);
// pll.icoef_Phase = read_pll_variable32 (dsp_pll.icoef_Phase);
// = ISign * CPN(29)*pow(10.,Igain/20.);
// pll.pcoef_Phase = read_pll_variable32 (dsp_pll.pcoef_Phase);
// = PSign * CPN(29)*pow(10.,Pgain/20.);
pll.errorPI_Phase = read_pll_variable32 (dsp_pll.errorPI_Phase);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- ctrlmode_Phase = %d : %s\n", pll.ctrlmode_Phase, pll.ctrlmode_Phase?"ON":"OFF");
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- setpoint_Phase = %g\n", pll.setpoint_Phase);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- corrmin_Phase = %g\n", pll.corrmax_Phase);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- corrmax_Phase = %g\n", pll.corrmin_Phase);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- memI_Phase = %g\n", pll.memI_Phase);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- errorPI_Phase = %g\n", pll.errorPI_Phase);
}
if (group & PLL_CONTROLLER_AMPLITUDE){
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- PLL_CONTROLLER_AMPLITIDE --\n");
pll.ctrlmode_Amp = read_pll_variable32 (dsp_pll.ctrlmode_Amp);
pll.setpoint_Amp = read_pll_variable32 (dsp_pll.setpoint_Amp)*10./(CPN(29));
pll.corrmax_Amp = read_pll_variable64 (dsp_pll.corrmax_Amp)*10./CPN(58);
pll.corrmin_Amp = read_pll_variable64 (dsp_pll.corrmin_Amp)*10./CPN(58);
pll.memI_Amp = read_pll_variable64 (dsp_pll.memI_Amp)*10./CPN(58);
// pll.icoef_Amp = read_pll_variable32 (dsp_pll.icoef_Amp);
// = ISign * CPN(29)*pow(10.,Igain/20.);
// pll.pcoef_Amp = read_pll_variable32 (dsp_pll.pcoef_Amp);
// = PSign * CPN(29)*pow(10.,Pgain/20.);
pll.errorPI_Amp = read_pll_variable32 (dsp_pll.errorPI_Amp);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- ctrlmode_Amp = %d : %s\n", pll.ctrlmode_Amp, pll.ctrlmode_Amp?"ON":"OFF");
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- setpoint_Amp = %g V\n", pll.setpoint_Amp);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- corrmin_Amp = %g V\n", pll.corrmax_Amp);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- corrmax_Amp = %g V\n", pll.corrmin_Amp);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- memI_Amp = %g\n", pll.memI_Amp);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- errorPI_Amp = %g V\n", pll.errorPI_Amp);
}
if (group & PLL_OPERATION){
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- PLL_OPERATION --\n");
pll.LPSelect_Phase = read_pll_variable32 (dsp_pll.LPSelect_Phase);
pll.LPSelect_Amp = read_pll_variable32 (dsp_pll.LPSelect_Amp);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- LPSelect_Phase = %d\n", pll.LPSelect_Phase);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- LPSelect_Amp = %d\n", pll.LPSelect_Amp);
// 0: Excitation Frequency
// 1: Resonator Phase
// 2: Excitation Amplitude
// 3: Resonator Amplitude
double factor2dsp[4] = { CPN(29)*2.*M_PI/150000.,
CPN(29)*M_PI/180.,
CPN(29)/10.,
CPN(29)/10.
};
gint32 x[4];
read_pll_array32 (dsp_pll.ClipMin, 4, x);
// 2 world
for (int i=0; i<4; ++i){
pll.ClipMin[i] = ((double)x[i]-1.)/factor2dsp[i];
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- ClipMin[%d] = %g\n", i, pll.ClipMin[i]);
}
// 2 DSP ==> DSPPLL.ClipMin[i] = factor2dsp[i] * x + 1.;
read_pll_array32 (dsp_pll.ClipMax, 4, x);
for (int i=0; i<4; ++i){
pll.ClipMax[i] = ((double)x[i]+1.)/factor2dsp[i];
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::read_pll -- ClipMax[%d] = %g\n", i, pll.ClipMax[i]);
}
}
if (group & PLL_READINGS){
PAC_DEBUGLR_PRINT ("sranger_mk3_hwi_dev::read_pll -- PLL_READINGS --\n");
gint32 F64[4];
double factor[4] = { 150000./(CPN(29)*2.*M_PI), // Excit. Freq
180./(CPN(29)*M_PI), // ResPhase
10./CPN(29), // ResAmp LP
10./CPN(29) // ExecAmp LP
};
read_pll_array32 (dsp_pll.Filter64Out, 4, F64);
for (int i=0; i<4; ++i)
pll.Filter64Out[i] = (double)F64[i] * factor[i];
PAC_DEBUGLR_PRINT ("sranger_mk3_hwi_dev::read_pll -- Filter64Out[0] excitation = %g Hz\n", pll.Filter64Out[F64_Excitation]);
PAC_DEBUGLR_PRINT ("sranger_mk3_hwi_dev::read_pll -- Filter64Out[1] ResPhaseLP = %g deg\n", pll.Filter64Out[F64_ResPhaseLP]);
PAC_DEBUGLR_PRINT ("sranger_mk3_hwi_dev::read_pll -- Filter64Out[2] ResAmpLP = %g V\n", pll.Filter64Out[F64_ResAmpLP]);
PAC_DEBUGLR_PRINT ("sranger_mk3_hwi_dev::read_pll -- Filter64Out[3] ExecAmpLP = %g V\n", pll.Filter64Out[F64_ExecAmpLP]);
// life Monitoring
pll.phase = read_pll_variable32 (dsp_pll.phase) * 180./(CPN(22)*M_PI);
pll.amp_estimation = read_pll_variable32 (dsp_pll.amp_estimation) * 10./CPN(22);
pll.res_gain_computed = pll.Filter64Out[F64_ResAmpLP]/pll.Filter64Out[F64_ExecAmpLP];
// pll.InputFiltered = read_pll_variable32 (dsp_pll.InputFiltered);
// pll.PI_Phase_Out = read_pll_variable32 (dsp_pll.PI_Phase_Out);
// pll.volumeSine = read_pll_variable32 (dsp_pll.volumeSine);
// pll.SineOut0 = read_pll_variable32 (dsp_pll.SineOut0);
}
// pll.blcklen = read_pll_variable32 (dsp_pll.blcklen);
// read_pll_arrya32 (dsp_pll.Signal1, pll.blcklen, pll.Signal1);
// read_pll_arrya32 (dsp_pll.Signal2, pll.blcklen, pll.Signal2);
return 0;
} // returns 0 if PLL capability available, else -1
void sranger_mk3_hwi_dev::set_blcklen (int len){
write_pll_variable32 (dsp_pll.blcklen, (gint32)len);
}
#define MK__i32_off(n) ((n)<<2)
// needs set_blcklen to finish and write!
void sranger_mk3_hwi_dev::set_scope (int s1, int s2){
if (s1 >= 0)
switch (s1){
case 0: write_pll_variable32 (dsp_pll.pSignal1, (gint32)dsp_pll.Filter64Out+0); break;
case 1: write_pll_variable32 (dsp_pll.pSignal1, (gint32)dsp_pll.Filter64Out+4); break;
case 2: write_pll_variable32 (dsp_pll.pSignal1, (gint32)dsp_pll.Filter64Out+8); break;
case 3: write_pll_variable32 (dsp_pll.pSignal1, (gint32)dsp_pll.Filter64Out+12); break;
case 4: write_pll_variable32 (dsp_pll.pSignal1, (gint32)dsp_pll.amp_estimation); break;
case 5: write_pll_variable32 (dsp_pll.pSignal1, (gint32)dsp_pll.phase); break;
case 6: write_pll_variable32 (dsp_pll.pSignal1, (gint32)dsp_pll.SineOut0); break;
case 7: write_pll_variable32 (dsp_pll.pSignal1, (gint32)dsp_pll.InputFiltered); break;
// case 8: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.feedback + MK__i32_off (4))); break; // cb_Ic
// case 9: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.feedback + MK__i32_off (19))); break; // z32neg
// case 10: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.feedback + MK__i32_off (12))); break; // I_iir
// case 11: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.feedback + MK__i32_off (17))); break; // I_avg
// case 12: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.feedback + MK__i32_off (18))); break; // I_rms
// case 13: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.feedback_mixer + MK__i32_off (26))); break; // delta
case 14: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.scan + MK__i32_off (30))); break; // xyz_vec[0]
case 15: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.scan + MK__i32_off (31))); break; // xyz_vec[1]
case 16: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.scan + MK__i32_off (32))); break; // xyz_vec[2]
case 17: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.scan + MK__i32_off (33))); break; // xy_r_vec[0]
case 18: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.scan + MK__i32_off (34))); break; // xy_r_vec[1]
case 19: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.AIC_in + MK__i32_off (0))); break; // IN_0
case 20: write_pll_variable32 (dsp_pll.pSignal1, (gint32)(magic_data.AIC_out + MK__i32_off (0))); break; // OUT_0
}
else
write_pll_variable32 (dsp_pll.pSignal1, (gint32)(-s1));
if (s2 >= 0)
switch (s2){
case 0: write_pll_variable32 (dsp_pll.pSignal2, (gint32)dsp_pll.Filter64Out+0); break;
case 1: write_pll_variable32 (dsp_pll.pSignal2, (gint32)dsp_pll.Filter64Out+4); break;
case 2: write_pll_variable32 (dsp_pll.pSignal2, (gint32)dsp_pll.Filter64Out+8); break;
case 3: write_pll_variable32 (dsp_pll.pSignal2, (gint32)dsp_pll.Filter64Out+12); break;
case 4: write_pll_variable32 (dsp_pll.pSignal2, (gint32)dsp_pll.amp_estimation); break;
case 5: write_pll_variable32 (dsp_pll.pSignal2, (gint32)dsp_pll.phase); break;
case 6: write_pll_variable32 (dsp_pll.pSignal2, (gint32)dsp_pll.SineOut0); break;
case 7: write_pll_variable32 (dsp_pll.pSignal2, (gint32)dsp_pll.InputFiltered); break;
// case 8: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.feedback + MK__i32_off (4))); break; // cb_Ic
// case 9: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.feedback + MK__i32_off (19))); break; // z32neg
// case 10: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.feedback + MK__i32_off (12))); break; // I_iir
// case 11: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.feedback + MK__i32_off (17))); break; // I_avg
// case 12: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.feedback + MK__i32_off (18))); break; // I_rms
// case 13: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.feedback_mixer + MK__i32_off (26))); break; // delta
case 14: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.scan + MK__i32_off (30))); break; // xyz_vec[0]
case 15: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.scan + MK__i32_off (31))); break; // xyz_vec[1]
case 16: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.scan + MK__i32_off (32))); break; // xyz_vec[2]
case 17: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.scan + MK__i32_off (33))); break; // xy_r_vec[0]
case 18: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.scan + MK__i32_off (34))); break; // xy_r_vec[1]
case 19: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.AIC_in + MK__i32_off (0))); break; // IN_0
case 20: write_pll_variable32 (dsp_pll.pSignal2, (gint32)(magic_data.AIC_out + MK__i32_off (0))); break; // OUT_0
}
else
write_pll_variable32 (dsp_pll.pSignal2, (gint32)(-s2));
}
void sranger_mk3_hwi_dev::setup_step_response (double dPhase, double dAmplitude){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: setup_step_response %g Deg, %g V\n", dPhase, dAmplitude);
double re=0.;
gint32 start_call[2]={0,0}; // => exec ChangeFreqHL () on DSP after adjused Re/Im.
if (dPhase > 0.)
re = CPN(29) * dPhase * M_PI / 180.;
if (dAmplitude > 0.)
re = CPN(29) * dAmplitude / 10.;
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- deltaReT= %d\n", (int)re);
write_pll_variable32 (dsp_pll.deltaReT, re);
lseek (dsp, magic_data.PLL_lookup, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
if (dAmplitude > 0.){
start_call[0]=4;
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll ==> exec TestAmpPIRest_HL()\n");
} else {
start_call[0]=3;
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll ==> exec TestPhasePIResp_HL()\n");
}
CONV_32 (start_call[0]);
CONV_32 (start_call[1]);
sr_write (dsp, &start_call, 2*sizeof (gint32));
// if (ioctl(dsp, SRANGER_MK2_IOCTL_KERNEL_EXEC, Address of ChangeFreqHL ) < 0){
// PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::write_pll: ERROR K_EXEC call to ChangeFreqFB()\n");
// }
}
int sranger_mk3_hwi_dev::read_pll_signal1 (PAC_control &pll, int n, double scale, gint flag){
pll.blcklen = read_pll_variable32i (dsp_pll.blcklen);
if (pll.blcklen == -1){
if (n > 0 && n <= PAC_BLCKLEN){
read_pll_array32 (dsp_pll.Signal1, n, pll.tmp_array);
PAC_DEBUGL0_PRINT ("adr Signal1=%x\n", dsp_pll.Signal1);
PAC_DEBUGL0_PRINT ("adr pSignal1=%x\n", dsp_pll.pSignal1);
PAC_DEBUGL0_PRINT ("--- pSignal1=%x\n", (gint32)read_pll_variable32 (dsp_pll.pSignal1));
for (int i=0; i<n; ++i)
pll.Signal1[i] = (double)pll.tmp_array[i] * scale;
}
if (flag)
set_blcklen (n);
return 0;
}
return -1;
}
int sranger_mk3_hwi_dev::read_pll_signal2 (PAC_control &pll, int n, double scale, gint flag){
pll.blcklen = read_pll_variable32i (dsp_pll.blcklen);
if (pll.blcklen == -1){
if (n > 0 && n <= PAC_BLCKLEN){
read_pll_array32 (dsp_pll.Signal2, n, pll.tmp_array);
PAC_DEBUGL0_PRINT ("adr Signal2=%x\n", dsp_pll.Signal2);
PAC_DEBUGL0_PRINT ("adr pSignal2=%x\n", dsp_pll.pSignal2);
PAC_DEBUGL0_PRINT ("--- pSignal2=%x\n", (gint32)read_pll_variable32 (dsp_pll.pSignal2));
for (int i=0; i<PAC_BLCKLEN; ++i)
pll.Signal2[i] = (double)pll.tmp_array[i] * scale;
}
if (flag)
set_blcklen (n);
return 0;
}
return -1;
}
int sranger_mk3_hwi_dev::write_pll (PAC_control &pll, PLL_GROUP group, int enable){
static int wait=0;
static int pll_old_init=1;
static PAC_control pll_old;
if (pll_old_init){
read_pll (pll_old, PLL_ALL);
pll_old_init=0;
}
if (group & PLL_SYMBOLS || dsp_pll.volumeSine == 0){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- read symbols\n");
read_pll_symbols ();
}
if (group & PLL_TAUPAC){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- PLL_TAUPAC\n");
if (pll.Tau_PAC != pll_old.Tau_PAC){
if (pll.Tau_PAC > 0.){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- TAU=%g s >> %d\n", pll.Tau_PAC, (int)(CPN(22)*1.5e-5/pll.Tau_PAC));
write_pll_variable32 (dsp_pll.Tau_PAC, (CPN(22)*1.5e-5)/pll.Tau_PAC); // Tau[s]
} else { // OFF
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- TAU=0000\n");
write_pll_variable32 (dsp_pll.Tau_PAC, 0.); // Tau[s]
}
pll_old.Tau_PAC = pll.Tau_PAC;
} else { PAC_DEBUGL1_PRINT ("-- no change Tau_PAC.\n"); }
}
if (group & PLL_SINE){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- PLL_SINE\n");
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- VolumeSine=%g V >> %d\n",pll.volumeSine, (int)(CPN(22)*pll.volumeSine/10.));
write_pll_variable32 (dsp_pll.volumeSine, CPN(22)*pll.volumeSine/10.);
if (pll.FSineHz != pll_old.FSineHz && !pll.ctrlmode_Phase){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- Sine Frequency=%g Hz\n", pll.FSineHz);
double re = round (CPN(31) * cos (2.*M_PI*pll.FSineHz/150000.));
double im = round (CPN(31) * sin (2.*M_PI*pll.FSineHz/150000.));
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- deltaReT= %.0f\n", re);
write_pll_variable32 (dsp_pll.deltaReT, re);
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- deltaImT= %.0f\n", im);
write_pll_variable32 (dsp_pll.deltaImT, im);
// re = CPN(31), im = 2pi Freq / 150000
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- Sine PI_Phase_Out=%g deg >> %d\n",pll.PI_Phase_Out, (int)(CPN(29)*2.*M_PI*pll.FSineHz/150000.));
write_pll_variable32 (dsp_pll.PI_Phase_Out, round (CPN(29)*2.*M_PI*pll.FSineHz/150000.));
pll_old.FSineHz = pll.FSineHz;
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll ==> Exec ChangeFreqHL()\n");
lseek (dsp, magic_data.PLL_lookup, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
gint32 start_call[2]={1,0}; // => exec ChangeFreqHL () on DSP after adjused Re/Im.
CONV_32 (start_call[0]);
CONV_32 (start_call[1]);
sr_write (dsp, &start_call, 2*sizeof (gint32));
// if (ioctl(dsp, SRANGER_MK2_IOCTL_KERNEL_EXEC, Address of ChangeFreqHL ) < 0){
// PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::write_pll: ERROR K_EXEC call to ChangeFreqFB()\n");
// }
} else { PAC_DEBUGL1_PRINT ("-- no change FSineHz or Phase Controller engaged.\n"); }
}
if (group & PLL_CONTROLLER_PHASE){
if (wait) return -1;
wait=1;
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- PLL_CONTROLLER_PHASE\n");
// turn on or off
if (pll.ctrlmode_Phase == 1 && pll_old.ctrlmode_Phase == 0){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: TURN ON -- write_pll PHASE FB: %d ---> ON\n", pll.ctrlmode_Phase);
write_pll_variable32 (dsp_pll.errorPI_Phase, 0.);
write_pll_variable64 (dsp_pll.corrmax_Phase, CPN(58)*2.*M_PI*pll.ClipMax[0]/150000.);
write_pll_variable64 (dsp_pll.corrmin_Phase, CPN(58)*2.*M_PI*pll.ClipMin[0]/150000.);
write_pll_variable64 (dsp_pll.memI_Phase, CPN(58)*2.*M_PI*pll.FSineHz/150000.);
write_pll_variable32 (dsp_pll.ctrlmode_Phase, pll.ctrlmode_Phase);
pll_old.ctrlmode_Phase = 1;
} else if (pll.ctrlmode_Phase == 0 && pll_old.ctrlmode_Phase == 1){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: TURN OFF -- write_pll PHASE FB: %d ---> OFF\n", pll.ctrlmode_Phase);
pll_old.ctrlmode_Phase = 0;
write_pll_variable32 (dsp_pll.ctrlmode_Phase, pll.ctrlmode_Phase);
}
write_pll_variable32 (dsp_pll.setpoint_Phase, CPN(22)*M_PI*pll.setpoint_Phase/180.);
if (group & PLL_CONTROLLER_PHASE_AUTO){
if (pll_old.auto_set_BW_Phase == pll.auto_set_BW_Phase) { wait=0; return -1; }
pll_old.auto_set_BW_Phase = pll.auto_set_BW_Phase;
double cp = 20. * log10 (1.6575e-5 * pll.auto_set_BW_Phase);
double ci = 20. * log10 (1.7357e-10 * pll.auto_set_BW_Phase*pll.auto_set_BW_Phase);
GtkWidget *dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_YES_NO,
"Auto Set Phase: CP=%g dB, CI=%g dB",
cp, ci
);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES){
pll.cp_gain_Phase = cp;
pll.ci_gain_Phase = ci;
}
gtk_widget_destroy (dialog);
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- PLL_CONTROLLER_PHASE AUTO SET...\n");
}
write_pll_variable32 (dsp_pll.icoef_Phase, pll.signum_ci_Phase * CPN(29)*pow (10.,pll.ci_gain_Phase/20.));
// = ISign * CPN(29)*pow(10.,Igain/20.);
write_pll_variable32 (dsp_pll.pcoef_Phase, pll.signum_cp_Phase * CPN(29)*pow (10.,pll.cp_gain_Phase/20.));
// = PSign * CPN(29)*pow(10.,Pgain/20.);
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- PLL_CONTROLLER_PHASE SET: Set=%g deg CP=%g dB, CI=%g dB\n",
pll.setpoint_Phase, pll.cp_gain_Phase, pll.ci_gain_Phase);
wait=0;
}
/*
PAC at 15us !!!
Kp = 20*log10(1.6575e-5*Fc)
Ki = 20*log10(1.7357e-10*Fc^2)
Where Fc is the desired bandwidth of the controller in Hz (the suggested range is between 1.5 Hz
to 4.5kHz).
These gains can be used directly in the P and I formulas (values Pgain and Igain). Note that the
maximum value for both gains is +12 dB. The gain must be clipped at +12dB if the maximum
value is reached. Most of the time the P gain reaches the maximum before the I gain. In this
case, the reduction applied on the P gain must be applied on the I gain to assure a stable
behavior of the controller.
*/
if (group & PLL_CONTROLLER_AMPLITUDE){
if (wait) return -1;
wait=1;
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- PLL_CONTROLLER_AMPLITIDE\n");
// turn on or off
if (pll.ctrlmode_Amp == 1 && pll_old.ctrlmode_Amp == 0){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: TURN ON -- write_pll AMPLITUDE FB: %d\n", pll.ctrlmode_Amp);
write_pll_variable32 (dsp_pll.errorPI_Amp, 0.);
write_pll_variable64 (dsp_pll.corrmax_Amp, CPN(58)*pll.ClipMax[2]/10.);
write_pll_variable64 (dsp_pll.corrmin_Amp, CPN(58)*pll.ClipMin[2]/10.);
write_pll_variable64 (dsp_pll.memI_Amp, CPN(58)*pll.setpoint_Amp/10);
write_pll_variable32 (dsp_pll.ctrlmode_Amp, pll.ctrlmode_Amp);
pll_old.ctrlmode_Amp = 1;
} else if (pll.ctrlmode_Amp == 0 && pll_old.ctrlmode_Amp == 1){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: TURN OFF -- write_pll AMPLITUDE FB: %d\n", pll.ctrlmode_Amp);
pll_old.ctrlmode_Amp = 0;
write_pll_variable32 (dsp_pll.ctrlmode_Amp, pll.ctrlmode_Amp);
}
write_pll_variable32 (dsp_pll.setpoint_Amp, CPN(29)*pll.setpoint_Amp/10.);
if (group & PLL_CONTROLLER_AMPLITUDE_AUTO){
if (pll_old.auto_set_BW_Amp == pll.auto_set_BW_Amp &&
pll_old.Qfactor == pll.Qfactor &&
pll_old.GainRes == pll.GainRes ) { wait=0; return -1; }
pll_old.auto_set_BW_Amp = pll.auto_set_BW_Amp;
pll_old.Qfactor = pll.Qfactor;
pll_old.GainRes = pll.GainRes;
double Q = pll.Qfactor; // Q-factor
double F0 = pll.FSineHz; // Res. Freq
double Fc = pll.auto_set_BW_Amp; // 1.5 .. 10Hz
double gainres = pll.GainRes;
double cp = 20. * log10 (0.08045 * Q*Fc / (gainres*F0));
double ci = 20. * log10 (8.4243e-7 * Q*Fc*Fc / (gainres*F0));
GtkWidget *dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_YES_NO,
"Auto Set Amp: CP=%g dB, CI=%g dB",
cp, ci
);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES){
pll.cp_gain_Amp = cp;
pll.ci_gain_Amp = ci;
}
gtk_widget_destroy (dialog);
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- PLL_CONTROLLER_AMPLITUDE AUTO SET...\n");
}
write_pll_variable32 (dsp_pll.icoef_Amp, pll.signum_ci_Amp * CPN(29)*pow (10.,pll.ci_gain_Amp/20.));
// = ISign * CPN(29)*pow(10.,Igain/20.);
write_pll_variable32 (dsp_pll.pcoef_Amp, pll.signum_cp_Amp * CPN(29)*pow (10.,pll.cp_gain_Amp/20.));
// = PSign * CPN(29)*pow(10.,Pgain/20.);
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- PLL_CONTROLLER_AMPLITUDE AUTO SET: Set=%g V CP=%g dB, CI=%g dB\n",
pll.setpoint_Amp, pll.cp_gain_Amp, pll.ci_gain_Amp);
wait=0;
}
/*
Kp = 20*log10(0.08045*QFc/(Gain_res*F0))
Ki = 20*log10(8.4243e-7*QFc^2/(Gain_res*F0))
Where :
Gainres is the gain of the resonator at the resonance
Q is the Q factor of the resonator
F0 is the frequency at the resonance in Hz
Fc is the desired bandwidth of the controller in Hz (the suggested range is between 1.5 Hz to
10Hz).
These gains can be used directly in the P and I formulas (values PgainAmp and IgainAamp). Note that
the maximum value for both gains is +12 dB. The gain must be clipped at +12dB if the maximum
value is reached. Most of the time the P gain reaches the maximum before the I gain. In this
case, the reduction applied on the P gain must be applied on the I gain to assure a stable
behavior of the controller.
*/
if (group & PLL_OPERATION){
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- PLL_OPERATION\n");
// 0: Excitation Frequency
// 1: Resonator Phase
// 2: Excitation Amplitude
// 3: Resonator Amplitude
double factor2dsp[4] = { CPN(29)*2.*M_PI/150000.,
CPN(29)*M_PI/180.,
CPN(29)/10.,
CPN(29)/10.
};
gint32 x[4];
// 2 world
for (int i=0; i<4; ++i){
x[i] = (gint32)(pll.ClipMin[i]*factor2dsp[i]+1.);
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- ClipMin[%d] = %d (%g)\n", i, x[i], pll.ClipMin[i]);
}
write_pll_array32 (dsp_pll.ClipMin, 4, x);
// 2 DSP ==> DSPPLL.ClipMin[i] = factor2dsp[i] * x + 1.;
for (int i=0; i<4; ++i){
x[i] = (gint32)(pll.ClipMax[i]*factor2dsp[i]+1.);
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll -- ClipMax[%d] = %d (%g)\n", i, x[i], pll.ClipMax[i]);
}
write_pll_array32 (dsp_pll.ClipMax, 4, x);
write_pll_variable32 (dsp_pll.LPSelect_Phase, pll.LPSelect_Phase);
write_pll_variable32 (dsp_pll.LPSelect_Amp, pll.LPSelect_Amp);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::write_pll -- LPSelect_Phase = %d\n", pll.LPSelect_Phase);
PAC_DEBUGL1_PRINT ("sranger_mk3_hwi_dev::write_pll -- LPSelect_Amp = %d\n", pll.LPSelect_Amp);
PAC_DEBUGL1_PRINT ("SR-MK3-HwI-PAC:: write_pll ==> OutputSignalSetUp_HL()\n");
lseek (dsp, magic_data.PLL_lookup, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
gint32 start_call[2]={2,0}; // => exec ChangeFreqHL () on DSP after adjused Re/Im.
CONV_32 (start_call[0]);
CONV_32 (start_call[1]);
sr_write (dsp, &start_call, 2*sizeof (gint32));
}
// write_pll_variable32 (dsp_pll.blcklen, pll.blcklen);
// read_pll_arrya32 (dsp_pll.Signal1, pll.blcklen, pll.Signal1);
// read_pll_arrya32 (dsp_pll.Signal2, pll.blcklen, pll.Signal2);
return 0;
}
/**
* SIGNAL MANAGEMENT
**/
int sranger_mk3_hwi_dev::lookup_signal_by_ptr(gint64 sigptr){
for (int i=0; i<NUM_SIGNALS; ++i)
if (dsp_signal_lookup_managed[i].p == sigptr)
return i;
return -1;
}
const gchar *sranger_mk3_hwi_dev::lookup_signal_name_by_index(int i){
if (i<NUM_SIGNALS && i >= 0)
return (const gchar*)dsp_signal_lookup_managed[i].label;
else
return "INVALID INDEX";
}
const gchar *sranger_mk3_hwi_dev::lookup_signal_unit_by_index(int i){
if (i<NUM_SIGNALS && i >= 0)
return (const gchar*)dsp_signal_lookup_managed[i].unit;
else
return "INVALID INDEX";
}
double sranger_mk3_hwi_dev::lookup_signal_scale_by_index(int i){
if (i<NUM_SIGNALS && i >= 0)
return dsp_signal_lookup_managed[i].scale;
else
return 0.;
}
int sranger_mk3_hwi_dev::change_signal_input(int signal_index, gint32 input_id){
SIGNAL_MANAGE sm = { input_id, signal_index, 0, 0 }; // for read/write control part of signal_monitor only
g_print ("sranger_mk3_hwi_dev::change_module_signal_input\n");
CONV_32 (sm.mindex);
CONV_32 (sm.signal_id);
CONV_32 (sm.act_address_input_set);
CONV_32 (sm.act_address_signal);
lseek (dsp, magic_data.signal_monitor, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &sm, sizeof (sm));
return 0;
}
int sranger_mk3_hwi_dev::query_module_signal_input(gint32 input_id){
SIGNAL_MANAGE sm = { input_id, -1, 0, 0 }; // for read/write control part of signal_monitor only
g_print ("sranger_mk3_hwi_dev::query_module_signal_input_config\n");
CONV_32 (sm.mindex);
CONV_32 (sm.signal_id);
CONV_32 (sm.act_address_input_set);
CONV_32 (sm.act_address_signal);
lseek (dsp, magic_data.signal_monitor, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_write (dsp, &sm, sizeof (sm));
usleep (10000);
lseek (dsp, magic_data.signal_monitor, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &sm, sizeof (sm));
CONV_32 (sm.mindex);
CONV_32 (sm.signal_id);
CONV_32 (sm.act_address_input_set);
CONV_32 (sm.act_address_signal);
int signal_index = lookup_signal_by_ptr (sm.act_address_signal);
std::cout << "Query_Module_Signal[inpid=" << input_id << "]: found Sig " << signal_index
<< " *** mindex=" << sm.mindex
<< ", signal_id=" << sm.signal_id
<< ", act_address_input_set=" << sm.act_address_input_set
<< ", act_address_input_set=" << sm.act_address_signal
<< std::endl;
return signal_index;
}
int sranger_mk3_hwi_dev::read_signal_lookup (){
struct{ DSP_INT32_P p; } dsp_signal_list[NUM_SIGNALS];
g_print ("sranger_mk3_hwi_dev::read_signal_lookup\n");
lseek (dsp, magic_data.signal_lookup, SRANGER_MK23_SEEK_DATA_SPACE | SRANGER_MK23_SEEK_ATOMIC);
sr_read (dsp, &dsp_signal_list, sizeof (dsp_signal_list));
for (int i=0; i<NUM_SIGNALS; ++i){
CONV_32 (dsp_signal_list[i].p);
dsp_signal_lookup_managed[i].p = dsp_signal_list[i].p;
dsp_signal_lookup_managed[i].label = g_strdup(dsp_signal_lookup[i].label);
dsp_signal_lookup_managed[i].unit = g_strdup(dsp_signal_lookup[i].unit);
dsp_signal_lookup_managed[i].scale = dsp_signal_lookup[i].scale;
dsp_signal_lookup_managed[i].module = g_strdup(dsp_signal_lookup[i].module);
std::cout << "Sig[" << i << "]: " << dsp_signal_lookup_managed[i].p
<< ", " << dsp_signal_lookup_managed[i].label
<< ", " << dsp_signal_lookup_managed[i].unit
<< ", " << dsp_signal_lookup_managed[i].scale
<< ", " << dsp_signal_lookup_managed[i].module
<< std::endl;
}
return 0;
}
int sranger_mk3_hwi_dev::read_actual_module_configuration (){
typedef struct { gint32 id; const gchar* name; DSP_INT32_P sigptr; } MOD_INPUT;
MOD_INPUT mod_input_list[] = {
//## [ MODULE_SIGNAL_INPUT_ID, name, actual hooked signal address ]
{ DSP_SIGNAL_Z_SERVO_INPUT_ID, "Z_SERVO", 0 },
{ DSP_SIGNAL_M_SERVO_INPUT_ID, "M_SERVO", 0 },
{ DSP_SIGNAL_MIXER0_INPUT_ID, "MIXER0", 0 },
{ DSP_SIGNAL_MIXER1_INPUT_ID, "MIXER1", 0 },
{ DSP_SIGNAL_MIXER2_INPUT_ID, "MIXER2", 0 },
{ DSP_SIGNAL_MIXER3_INPUT_ID, "MIXER3", 0 },
{ DSP_SIGNAL_DIFF_IN0_ID, "DIFF_IN0", 0 },
{ DSP_SIGNAL_DIFF_IN1_ID, "DIFF_IN1", 0 },
{ DSP_SIGNAL_DIFF_IN2_ID, "DIFF_IN2", 0 },
{ DSP_SIGNAL_DIFF_IN3_ID, "DIFF_IN3", 0 },
{ DSP_SIGNAL_LOCKIN_A_INPUT_ID, "LOCKIN_A", 0 },
{ DSP_SIGNAL_LOCKIN_B_INPUT_ID, "LOCKIN_B", 0 },
{ DSP_SIGNAL_VECPROBE0_INPUT_ID, "VECPROBE0", 0 },
{ DSP_SIGNAL_VECPROBE1_INPUT_ID, "VECPROBE1", 0 },
{ DSP_SIGNAL_VECPROBE2_INPUT_ID, "VECPROBE2", 0 },
{ DSP_SIGNAL_VECPROBE3_INPUT_ID, "VECPROBE3", 0 },
{ DSP_SIGNAL_VECPROBE0_CONTROL_ID, "VECPROBE0_C", 0 },
{ DSP_SIGNAL_VECPROBE1_CONTROL_ID, "VECPROBE1_C", 0 },
{ DSP_SIGNAL_VECPROBE2_CONTROL_ID, "VECPROBE2_C", 0 },
{ DSP_SIGNAL_VECPROBE3_CONTROL_ID, "VECPROBE3_C", 0 },
{ DSP_SIGNAL_OUTMIX_CH5_INPUT_ID, "OUTMIX_CH5", 0 },
{ DSP_SIGNAL_OUTMIX_CH5_ADD_A_INPUT_ID, "OUTMIX_CH5_ADD_A", 0 },
{ DSP_SIGNAL_OUTMIX_CH5_SUB_B_INPUT_ID, "OUTMIX_CH5_SUB_B", 0 },
{ DSP_SIGNAL_OUTMIX_CH5_SMAC_A_INPUT_ID, "OUTMIX_CH5_SMAC_A", 0 },
{ DSP_SIGNAL_OUTMIX_CH5_SMAC_B_INPUT_ID, "OUTMIX_CH5_SMAC_B", 0 },
{ DSP_SIGNAL_OUTMIX_CH6_INPUT_ID, "OUTMIX_CH6", 0 },
{ DSP_SIGNAL_OUTMIX_CH6_ADD_A_INPUT_ID, "OUTMIX_CH6_ADD_A", 0 },
{ DSP_SIGNAL_OUTMIX_CH6_SUB_B_INPUT_ID, "OUTMIX_CH6_SUB_B", 0 },
{ DSP_SIGNAL_OUTMIX_CH6_SMAC_A_INPUT_ID, "OUTMIX_CH6_SMAC_A", 0 },
{ DSP_SIGNAL_OUTMIX_CH6_SMAC_B_INPUT_ID, "OUTMIX_CH6_SMAC_B", 0 },
{ DSP_SIGNAL_OUTMIX_CH7_INPUT_ID, "OUTMIX_CH7", 0 },
{ DSP_SIGNAL_OUTMIX_CH7_ADD_A_INPUT_ID, "OUTMIX_CH7_ADD_A", 0 },
{ DSP_SIGNAL_OUTMIX_CH7_SUB_B_INPUT_ID, "OUTMIX_CH7_SUB_B", 0 },
{ DSP_SIGNAL_OUTMIX_CH7_SMAC_A_INPUT_ID, "OUTMIX_CH7_SMAC_A", 0 },
{ DSP_SIGNAL_OUTMIX_CH7_SMAC_B_INPUT_ID, "OUTMIX_CH7_SMAC_B", 0 },
{ DSP_SIGNAL_OUTMIX_CH8_INPUT_ID, "OUTMIX_CH8_INPUT", 0 },
{ DSP_SIGNAL_OUTMIX_CH8_ADD_A_INPUT_ID, "OUTMIX_CH8_ADD_A_INPUT", 0 },
{ DSP_SIGNAL_OUTMIX_CH9_INPUT_ID, "OUTMIX_CH9_INPUT", 0 },
{ DSP_SIGNAL_OUTMIX_CH9_ADD_A_INPUT_ID, "OUTMIX_CH9_ADD_A_INPUT", 0 },
{ DSP_SIGNAL_ANALOG_AVG_INPUT_ID, "ANALOG_AVG_INPUT", 0 },
{ DSP_SIGNAL_SCOPE_SIGNAL1_INPUT_ID, "SCOPE_SIGNAL1_INPUT", 0 },
{ DSP_SIGNAL_SCOPE_SIGNAL2_INPUT_ID, "SCOPE_SIGNAL2_INPUT", 0 },
{ 0, "END", 0 }
};
for (int i=0; mod_input_list[i].id; ++i){
int si = query_module_signal_input (mod_input_list[i].id);
if (si >= 0 && si < NUM_SIGNALS){
std::cout << "Sig[" << si << "]: " << dsp_signal_lookup_managed[si].label
<< " ===> Mod-Input[" << i << "]: " << mod_input_list[i].name
<< std::endl;
} else {
std::cout << "ERROR query Signal for Mod-Input[" << i << "]: si=" << si
<< std::endl;
}
}
return 0;
}
/* END */