-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathddc_multichan.c
More file actions
2778 lines (2266 loc) · 99.6 KB
/
ddc_multichan.c
File metadata and controls
2778 lines (2266 loc) · 99.6 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
/**************************************************************************
*
* File: ddc_multichan.c
*
* Description: This program demonstrates acquiring data all available
* channels, routed through the digital down converter in
* each channel. Using program defaults, it captures a
* continuous stream of DDC data for each channel.
*
* Data source for the DDC in each channel is ADC 1, so
* data from each channel can be compared to show all
* channels are synchronized. The DATA_SOURCE constant
* is provided in ddc_multichan.h to change DDC input
* source, if desired.
*
* The number of channels used is set by using the maximum
* number of channels determined by the board resource
* structudmare initialization routine after a module has been
* found and initialized.
*
* The program always starts with DDC channel 1 and continues
* using DDC channels in order until all channels are used.
* If the use of the Signal Analyzer is specified in the
* command line arguments, channel 1 will be selected as the
* default data displaying channel.
*
* Data packing mode is fixed to packed.
*
* Program Usage:
* ddc_multichan (to use program defaults) OR
* ddc_multichan -dev ddc (must use 'ddc')
* -chan <c> c = Channel number (1 through 4)
* Default = max available channels
* -xfersize <s> s = number of samples to transfer
* Default = 524288 samples
* -loop <l> l = number loop counts to run (0 = run
* forever)
* -tuneFreq <t> t = DDC tuning (NCO) frequency
* Default = 20.0 MHz
* -decim <d> d = total DDC decimation value (2
* to 65536)
* Default = 30
* -datformat <f> f = data format
* "bin" for binary,
* "asci" for ASCII
* Default = bin
* -vport <p> p = Signal Analyzer port number
* -vhost <h> h = Signal Analyzer host address/name
*
* Example:
* ddc_multichan -chan 1 -xfersize 524288 -loop 10000 -tunefreq 20000000.0
* -decim 30 -datformat bin -vport 3223187469 -vhost localhost
*
* $Revision: 26 $ $Date: 4/15/15 4:16p $
*
* $History: ddc_multichan.c $
*
* ***************** Version 26 *****************
* User: Ccl Date: 4/15/15 Time: 4:16p
* Updated in $/71620/BSP/win64/examples/ddc_multichan
* Allow data writing to a file even if sending data to the viewer fails.
*
* ***************** Version 25 *****************
* User: Ccl Date: 4/08/15 Time: 3:45p
* Updated in $/71620/BSP/win32/examples/ddc_multichan
* Modify to free memory first berfore closing device in exit handler.
*
* ***************** Version 24 *****************
* User: Ccl Date: 3/30/15 Time: 6:17p
* Updated in $/71620/BSP/win32/examples/ddc_multichan
* Correct program descriptions, and change program defaults.
*
* ***************** Version 23 *****************
* User: Ccl Date: 3/27/15 Time: 5:13p
* Updated in $/71620/BSP/win32/examples/ddc_multichan
* Changed program design to allow continuous data acquisition based on
* user specified loop count.
* tm_mye
* ***************** Version 22 *****************
* User: Ccl Date: 1/21/15 Time: 2:37p
* Updated in $/71660/BSP/win64/examples/ddc_multichan
* Changed the use of a debugging function back to a library function.
*
* ***************** Version 21 *****************
* User: Misir Date: 1/14/15 Time: 4:25p
* Updated in $/71640/BSP/win64/examples/ddc_multichan
* Added viewer support.
*
* ***************** Version 20 *****************
* User: Ccl Date: 11/14/14 Time: 4:57p
* Updated in $/71660/BSP/win64/examples/ddc_multichan
* Fix sampling rate for 7164x/7174x.
*
* ***************** Version 19 *****************
* User: Ccl Date: 9/26/14 Time: 4:52p
* Updated in $/71640/BSP/win64/examples/ddc_multichan
* Added call to detect frequency for 7164x and 7174x
* Added support to 71741.
*
* ***************** Version 18 *****************
* User: Misir Date: 7/11/13 Time: 12:44p
* Updated in $/71640/BSP/win32/examples/ddc_multichan
* The 71641 defaults to NON-DESMODE in this example, therefore the only
* valid decimations are 4, 8 and 16. Modifications were made in the ddc
* core setup function to accommodate this.
*
* ***************** Version 17 *****************
* User: Frank Date: 6/20/13 Time: 3:41p
* Updated in $/71660/BSP/win64/examples/ddc_multichan
* corrected Q-data selection
*
* ***************** Version 16 *****************
* User: Frank Date: 3/06/13 Time: 4:28p
* Updated in $/71620/BSP/win64/examples/ddc_multichan
* fixed one output message; general cleanup
*
* ***************** Version 15 *****************
* User: Misir Date: 3/05/13 Time: 4:10p
* Updated in $/71641/BSP/x86_64/examples
* Cleaned up code to support 71641 DDC Core.
*
* ***************** Version 13 *****************
* User: Frank Date: 2/04/13 Time: 4:35p
* Updated in $/71620/BSP/win64/examples/ddc_multichan
* replaced local functions with Pentek Hi-Level lib functions
*
* ***************** Version 12 *****************
* User: Frank Date: 12/07/12 Time: 9:09a
* Updated in $/71660/BSP/win64/examples/ddc_multichan
* modified parseArgs() to output usage message
*
* ***************** Version 11 *****************
* User: Frank Date: 12/03/12 Time: 1:49p
* Updated in $/71660/BSP/win64/examples/ddc_multichan
* corrected Win32 compiler warnings; changed unsigned int's to DWORD
*
* ***************** Version 10 *****************
* User: Frank Date: 11/20/12 Time: 12:40p
* Updated in $/71660/BSP/win64/examples/ddc_multichan
* added device type param to writeBufToFile()
*
* ***************** Version 9 *****************
* User: Frank Date: 11/20/12 Time: 9:56a
* Updated in $/71660/BSP/win64/examples/ddc_multichan
* updated to scan for modules, added program header file, other changes
*
* ***************** Version 8 *****************
* User: Misir Date: 8/01/12 Time: 12:02p
* Updated in $/71621/BSP/win32/examples/ddc_multichan
* Now using the MAX_CHANNELS define.
*
* ***************** Version 7 *****************
* User: Misir Date: 3/09/12 Time: 2:41p
* Updated in $/71621/BSP/win32/examples/ddc_multichan
* Fixed bug concerning Register Dump.
*
* ***************** Version 6 *****************
* User: Ccl Date: 1/20/12 Time: 1:41p
* Updated in $/71651/BSP/win32/examples/ddc_multichan
* Change default tuning frequency value.
*
* ***************** Version 5 *****************
* User: Misir Date: 1/10/12 Time: 11:59a
* Updated in $/71621/BSP/x86_64/examples
* Added OSDEP.
*
* ***************** Version 2 *****************
* User: Misir Date: 5/02/11 Time: 1:54p
* Updated in $/71621/BSP/x86/examples
* Ported new Windows examples to Linux.
*
* ***************** Version 2 *****************
* User: Frank Date: 4/01/11 Time: 12:58p
* Updated in $/71621/BSP/win64/examples/ddc_multichan
* change command line param refClk to refFreq
*
* ***************** Version 1 *****************
* User: Frank Date: 3/24/11 Time: 9:39a
* Created in $/71621/BSP/win64/examples/ddc_multichan
* initial
*
**************************************************************************/
#include "ddc_multichan.h"
#define EXT_TRIG 1
#define DAC 1
#define DANE_CHANGED_TRIG_SOURCE 1
#define ARB_WAVEFORM 1
#define RESET_REGS 0
void ddc_71641_core_setup (MODULE_RESRC *modResrcBase,
P716x_CMDLINE_ARGS progParams,
unsigned int chanNum);
static unsigned int stopFlag = 0;
#if (DEBUG)
unsigned int intrCount = 0;
#endif
int Adc_delay;
volatile int SAMPLES_PER_PRI_GLOBAL;
/**************************************************************************
Parser setup START
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Redefines what the comment prefix should be. By default it is set to ";"
#define INI_INLINE_COMMENT_PREFIXES "%"
#include "ini.c"
// Parameters from header file that are necessary for this parser
typedef struct
{
int NUM_TRANSFERS; // This is the number of transfers you are hoping to save.
int WAVEFORM;
int DAC_DELAY;
int ADC_DELAY;
int SAMPLES_PER_PRI;
int NEXT_VARIABLE;
} configuration;
// Handler used by the parser to assign values to variables.
// Variables are declared in the configuration struct
static int handler(void* user, const char* section, const char* name,
const char* value)
{
configuration* pconfig = (configuration*)user;
//#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
//got rid of above line since sections are not necessary here. They are
//necessary for the Rhino
#define MATCH(n) strcmp(name, n) == 0
if (MATCH("NUM_PRIS")) {
pconfig->NUM_TRANSFERS = atoi(value);
} else if (MATCH("WAVEFORM_INDEX")) {
pconfig->WAVEFORM = atoi(value);
} else if (MATCH("DAC_DELAY")) {
pconfig->DAC_DELAY = atoi(value);
} else if (MATCH("ADC_DELAY")) {
pconfig->ADC_DELAY = atoi(value);
} else if (MATCH("SAMPLES_PER_PRI")) {
pconfig->SAMPLES_PER_PRI = atoi(value);
} else if (MATCH("NEXT_VARIABLE")) {
pconfig->NEXT_VARIABLE = atoi(value);
} else {
return 0; // unknown section/name, error
}
return 1;
}
/**************************************************************************
Parser setup END
**************************************************************************/
/**************************************************************************
Function: dmaIntHandler()
Description: This routine serves as the User Mode interrupt handler for
this example.
Parameters: hDev - 716x Device Handle
dmaChannel - DMA channel generating the interrupt(0-3)
pData - Pointer to user defined data
pIntResults - Pointer to the interrupt results structure
Return: none
**************************************************************************/
static void dmaIntHandler(PVOID hDev,
LONG dmaChannel,
PVOID pData,
PTK716X_INT_RESULT *pIntResult)
{
IFC_ARGS *ifcArgs = (IFC_ARGS *)pData;
#if DEBUG
intrCount++;
#endif
PTKIFC_SemaphorePost (ifcArgs, (4 + dmaChannel));
}
/**************************************************************************
Function: main
Description: Multi-channel 716x DDC data acquition example.
main() initializes the board and starts the channel threads.
The threads set up the individual channel, arms the trigger
and sets up the channel's DMA engine for receipt of the
trigger signal. Once all channels are ready, main()
generates the trigger and waits for all threads to signal
that their DMA transfer has completed.
Parameters: none
Return: 0 - program completed successfully
1 - Error: driver library init failed
2 - Error: device failed to open
3 - Error: invalid command line argument(s)
4 - Error: invalid maximum number of channels
5 - Error: buffer allocation failed
6 - Error: requested channel not available
7 - Error: filter table load failed
8 - Error: semaphore creation failed
9 - Error: thread start failed
10 - internal thread failure
11 - invalid Signal Analyzer parameter
12 - cannot connect to Signal Analyzer
13 - sending data to Signal Analyzer failed
14 - Thread Error
15 - Failure writing to file
16 - Failure Enabling interrupt
17 - DMA channel failed to open
18 - DMA complete timeout
**************************************************************************/
int main (int argc, char *argv[])
{
IFC_ARGS ifcArgs;
MODULE_RESRC *moduleResrc = NULL;
int *IDTable = (int *)&P716xValidIdTable;
DWORD numDevices;
ADC12D1800_PARAMS adc12d1800Params;
DWORD dataSrc = DATA_SOURCE;
DWORD chan;
DWORD bufSize; /* in bytes */
DWORD ddcBufSize; /* in bytes */
DWORD ducBufSize; /* in bytes */
DWORD numChans;
double tuningFreq;
DWORD decimation;
DWORD libStat = PTK716X_STATUS_UNDEFINED;
DWORD intrStat = PTK716X_STATUS_OK;
DMA_THREAD_PARAMS dmaThreadParams[MAX_CHANNELS];
DWORD dwStatus;
DWORD calcRet;
DWORD actualDec;
unsigned int pulseCount = 0;
int status;
unsigned int i;
#if DAC
P716x_DAC_DMA_DESCRIPT_CWORD_PARAMS dacDmaCword;
P716x_DAC_DMA_LLIST_DESCRIPTOR dacDmaDescriptor;
P716x_DAC_OCTRL_LLIST_DEFINITION dacOutLlistDef;
DWORD dacChan = ACTIVE_CHANNEL;
PTK716X_DMA_HANDLE *dmaHandle = NULL;
PTK716X_DMA_BUFFER dmaBuf;
DWORD bufStat = PTK716X_STATUS_OK;
DWORD memType;
DWORD acqType;
#endif
/* Signal Analyzer variables and structures */
DWORD useViewer[MAX_CHANNELS] = {0,0,0,0}; /* 0 = no; 1 = yes */
int sockFd;
int newSockFd;
P716x_VIEW_CONTROL viewCtrlParams;
DWORD dispChannel;
EXIT_HANDLE_RESRC exitHdlResrc =
{
{0, 0, 0, 0, 0},
NULL, /* modResrcBase pointer */
&libStat,
&intrStat,
{&(dmaThreadParams[0].dmaHandle),
&(dmaThreadParams[1].dmaHandle),
&(dmaThreadParams[2].dmaHandle),
&(dmaThreadParams[3].dmaHandle)},
/* Will be initialized later, based on the value of NUM_DMA_BUFS */
{&(dmaThreadParams[0].dmaBuf[0])},
{&(dmaThreadParams[0].dataBuf),
&(dmaThreadParams[1].dataBuf),
&(dmaThreadParams[2].dataBuf),
&(dmaThreadParams[3].dataBuf)},
&numChans,
&ifcArgs
};
/* Program entry ------------------------------------------------------
*
* Initialize library access, identify board, allocate buffers, etc.
*/
printf ("\n[%s] Entry\n", PROGRAM_ID);
/* initialize OS-dependent resources */
PTKIFC_Init(&ifcArgs);
PTKIFC_MutexCreate (&ifcArgs, 0);
/* initialize the PTK716X library */
libStat = PTK716X_LibInit();
if (libStat != PTK716X_STATUS_OK)
{
exitHdlResrc.exitCode[0] = 1;
return (exitHandler (&exitHdlResrc));
}
printf (" Scanning for modules\n");
moduleResrc = PTKHLL_DeviceFindAndOpen(IDTable, &numDevices);
if (numDevices == 0) /* no module found */
{
(exitHdlResrc.exitCode[0]) = 2;
return (exitHandler(&exitHdlResrc));
}
/* save module resource base address to exit handler */
exitHdlResrc.modResrcBase = moduleResrc;
/* more than one module found? */
if (numDevices > 1)
moduleResrc = PTKHLL_DeviceSelect(moduleResrc);
PTKHLL_DisplayBarAddresses (PROGRAM_ID, moduleResrc);
/* process command line arguments */
status = PTKHLL_ParseArgs(&(argc), argv, &(moduleResrc->progParams),
&(moduleResrc->p716xBrdResrc));
if (status != 0)
{
if (status == P716x_CMDLINE_BAD_ARG)
exitHdlResrc.exitCode[0] = 3; /* invalid argument */
else
exitHdlResrc.exitCode[0] = 0; /* user usage query */
return (exitHandler(&exitHdlResrc));
}
/* use command line param to set program parameters */
bufSize = moduleResrc->progParams.xferSize * 4; /* size in bytes */
//ddcBufSize = DDC_XFER_WORD_SIZE * 4; /* size in bytes */
tuningFreq = moduleResrc->progParams.tuneFreq; /* same for all channels */
decimation = moduleResrc->progParams.decimation; /* same for all channels */
dispChannel = moduleResrc->progParams.channel - 1 ;
numChans = moduleResrc->p716xBrdResrc.numADC;
/* We need to match the Data source to its corresponding channel */
if ((moduleResrc->moduleId != P71641_MODULE_ID) &&
(moduleResrc->moduleId != P71741_MODULE_ID))
{
if (dispChannel == P716x_ADC1 )
{
dataSrc = DDC_DATA_SRC_ADC_1;
}
else if (dispChannel == P716x_ADC2)
{
dataSrc = DDC_DATA_SRC_ADC_2;
}
else if (dispChannel == P716x_ADC3)
{
dataSrc = DDC_DATA_SRC_ADC_3;
}
else if (dispChannel == P716x_ADC4)
{
dataSrc = DDC_DATA_SRC_ADC_4;
}
}
/* verify the specified channel exists */
if (dispChannel > moduleResrc->p716xBrdResrc.numDDC)
{
exitHdlResrc.exitCode[0] = 6;
return (exitHandler(&exitHdlResrc));
}
/* set useViewer parameter based on command line parameters */
if (((moduleResrc->progParams.viewPort) != P716x_CMDLINE_UNSUPPORTED_ARG) &&
((moduleResrc->progParams.viewPort) != P716x_CMDLINE_BAD_ARG) )
{
useViewer[dispChannel] = 1; /* use viewer */
}
// DP
#if 0
/* Open a DMA Channel */
status = PTK716X_DMAOpen(moduleResrc->hDev, dacChan, &(dmaHandle));
if (status != PTK716X_STATUS_OK)
{
printf("DMA Open problem\n");
exit(0);
}
/* allocate DMA data buffer */
bufStat = PTK716X_DMAAllocMem(dmaHandle, (moduleResrc->progParams.xferSize << 2),
&(dmaBuf), TRUE);
if (bufStat != PTK716X_STATUS_OK)
{
printf("DMA alloc problem\n");
exit(0);
}
/* set buffer to a value, for debug only */
memset (dmaBuf.usrBuf, 0x5a, (moduleResrc->progParams.xferSize) << 2);
#endif
// DP
#if DAC
/* Open a DMA Channel */
status = PTK716X_DMAOpen(moduleResrc->hDev, dacChan, &(dmaHandle));
if (status != PTK716X_STATUS_OK)
{
printf("DMA Open problem\n");
exit(0);
}
/* allocate DMA data buffer */
bufStat = PTK716X_DMAAllocMem(dmaHandle, (XFER_WORD_SIZE_DAC_DMA << 2),
&(dmaBuf), TRUE);
if (bufStat != PTK716X_STATUS_OK)
{
printf("DMA alloc problem\n");
exit(0);
}
/* set buffer to a value, for debug only */
memset (dmaBuf.usrBuf, 0x5a, XFER_WORD_SIZE_DAC_DMA << 2);
#endif
#if !ARB_WAVEFORM
/* Generate a waveform and store in the dacData buffer */
status = P716xDacWaveformGen(DATA_MODE, (unsigned int *)dmaBuf.usrBuf,
moduleResrc->progParams.xferSize, 32);
if (status != 0)
{
printf("DAC Waveform Gen problem\n");
exit(0);
}
#endif
#if ARB_WAVEFORM
{ // OPEN BLOCK
int wdCount;
int wdTemp;
int *ptrTemp;
int wdSize;
char sbBuffer[20+1];
FILE * ptrFile;
// DP
//wdSize = XFER_WORD_SIZE; // Long enough to cover the entire buffer.
wdSize = XFER_WORD_SIZE_DAC_DMA; // Long enough to cover the entire buffer.
printf("LOADING CUSTOM WAVEFORM \n");
printf("funcLoadChirpWaveform\n wdSize = %i\n", wdSize);
//ptrFile = fopen("C:\\Waveforms\\MultiWaveformVector.dat", "r");
//ptrFile = fopen("C:\\Waveforms\\10MHzSine.dat", "r");
//ptrFile = fopen("C:\\Waveforms\\5p625MHzSine.dat", "r");
//ptrFile = fopen("./Waveforms/WaveformDataTable.dat", "r");
//ptrFile = fopen("///smbtest/WaveformsRandy17Nov2017/WaveGenFiles/0p25usPulse.dat", "r");
ptrFile = fopen("///smbtest/Waveforms/WaveformTable.dat", "r");
//ptrFile = fopen("./Waveforms/B50LFMChirp.dat", "r");
ptrTemp = (unsigned int *)dmaBuf.usrBuf;
//*****************************
if (ptrTemp == NULL || ptrFile == NULL)
{
if (ptrTemp == NULL) printf("ptrTemp == NULL");
if (ptrFile == NULL) printf("ptrFile == NULL");
printf("ARB Waveform Gen problem\n");
/* Generate a waveform and store in the dacData buffer */
/* // DP
status = P716xDacWaveformGen(DATA_MODE, (unsigned int *)dmaBuf.usrBuf,
moduleResrc->progParams.xferSize, 32);
*/
status = P716xDacWaveformGen(DATA_MODE, (unsigned int *)dmaBuf.usrBuf,
XFER_WORD_SIZE_DAC_DMA, 32);
if (status != 0)
{
printf("DAC Waveform Gen problem\n");
exit(0);
}
}
for (wdCount=0; wdCount < wdSize; wdCount++)
{
//if((fgets(sbBuffer, 20, ptrFile))<=0)
if((fgets(sbBuffer, 20, ptrFile))==NULL)
break;
wdTemp = atoi(sbBuffer);
ptrTemp[wdCount] = wdTemp;
}
//******************************
fclose(ptrFile);
} // CLOSE BLOCKolumns 1 through 6:
#endif
#if DAC
/* Flush the CPU caches (see documentation of WDC_DMASyncCpu()) */
PTK716X_DMASyncCpu(&(dmaBuf));
moduleResrc->p716xGlobalParams.sbusParams.gateBRecSource = \
P716x_SBUS_CTRL2_GATEB_RCV_SRC_TRIG_IN;
// moduleResrc->p716xGlobalParams.sbusParams.sbusGateBInputTapDelay = 0x1F;
/* DAC Data Control register */
moduleResrc->p716xDacParams[dacChan].dataSource = \
P716x_DAC_DATA_CTRL_DATA_SRC_DMA_RAM;
/* DAC Rate Divider register */
moduleResrc->p716xDacParams[dacChan].rateDivide = moduleResrc->progParams.rateDiv;
/* DAC Gate/Trigger Control register */
moduleResrc->p716xDacParams[dacChan].triggerMode = \
P716x_DAC_GATE_TRIG_CTRL_TRIG_MODE_TRIG;
moduleResrc->p716xDacParams[dacChan].gateTrigEnable = \
P716x_DAC_GATE_TRIG_CTRL_GATE_TRIG_ENABLE;
/* Output Control Linked List Start Pointer register */
moduleResrc->p716xDacParams[dacChan].llistStartIndex = 0;
moduleResrc->p716xDacParams[dacChan].syncOutEnable = P716x_DAC_DATA_CTRL_SYNC_OUT_ENABLE;
moduleResrc->p716xDacParams[dacChan].syncSelect = P716x_DAC_DATA_CTRL_SYNC_SEL_SYNCB;
moduleResrc->p716xDacParams[dacChan].outputGateDelay= 0x6f;
/** Set up Dac5688 Parameters **/
/* DAC5688 parameters (By now, the DAC5688 has been reset and enabled) */
moduleResrc->dac5688Params.interpValue = \
DAC5688ConvertInterp(moduleResrc->progParams.interpolation);
moduleResrc->dac5688Params.interpValue = \
DAC5688ConvertInterp(DAC_INTERPOLATION);
if (DATA_MODE == P716x_DAC_WAVEFORM_16BIT_CHAN_PACKED)
moduleResrc->dac5688Params.inselMode = \
DAC5688_CONFIG1_INSELMODE_NORMAL;
else /* (DATA_MODE = P716x_DAC_WAVEFORM_16BIT_TIME_PACKED) */
moduleResrc->dac5688Params.inselMode = \
DAC5688_CONFIG1_INSELMODE_HALFRATE_DATA_AB;
moduleResrc->dac5688Params.diffClkEna = \
DAC5688_CONFIG2_DIFFCLK_DISABLE;
moduleResrc->dac5688Params.clk1InEna = \
DAC5688_CONFIG2_CLK1_IN_DISABLE;
moduleResrc->dac5688Params.clk1cInEna = \
DAC5688_CONFIG2_CLK1C_IN_DISABLE;
moduleResrc->dac5688Params.fir4Ena = \
DAC5688_CONFIG2_FIR4_DISABLE;
moduleResrc->dac5688Params.mixerEna = \
DAC5688_CONFIG2_MIXER_ENABLE;
/* Set NCO Frequency to 10 Mhz */
//moduleResrc->dac5688Params.ncoFrequency = 20000000.00;
moduleResrc->dac5688Params.ncoFrequency = DAC_NCO_FREQ;
/* use software sync for all functions */
moduleResrc->dac5688Params.ncoSel = \
DAC5688_CONFIG22_SYNC_SIF_SIG;
moduleResrc->dac5688Params.ncoRegSel = \
DAC5688_CONFIG22_SYNC_SIF_SIG;
moduleResrc->dac5688Params.qmCorrRegSel = \
DAC5688_CONFIG22_SYNC_SIF_SIG;
moduleResrc->dac5688Params.qmOffsetRegSel = \
DAC5688_CONFIG22_SYNC_SIF_SIG;
moduleResrc->dac5688Params.fifoSel = \
DAC5688_CONFIG23_SYNC_SIF_SIG; /* Software sync */
moduleResrc->dac5688Params.pllEna = \
DAC5688_CONFIG26_PLL_DISABLE; /* Not using PLL */
moduleResrc->dac5688Params.io1p83p3 = \
DAC5688_CONFIG26_IO_1P8_3P3_SET;
/* Config register 22 */
moduleResrc->dac5688Params.ncoSel = DAC5688_CONFIG22_SYNC_FROM_FIFO_OUTPUT;
moduleResrc->dac5688Params.ncoRegSel = DAC5688_CONFIG22_SYNC_FROM_FIFO_OUTPUT; // The FIFO_OUTPUT is driven by the DAC5688 PIN is driven by the SYNC B signal, which is driven by GATE B, which is driven by the LVTTL external trigger.
moduleResrc->dac5688Params.qmCorrRegSel = DAC5688_CONFIG22_SYNC_FROM_FIFO_OUTPUT;
moduleResrc->dac5688Params.qmOffsetRegSel = DAC5688_CONFIG22_SYNC_FROM_FIFO_OUTPUT;
/* Enable this for inverse sinc on DAC */
moduleResrc->dac5688Params.fir4Ena = DAC5688_CONFIG2_FIR4_ENABLE;
/* Config registers 5 and 23 */
moduleResrc->dac5688Params.clkDivSyncEna = DAC5688_CONFIG5_CLK_SYNC_DIV_ENABLE; printf("DAC5688_CONFIG5_CLK_SYNC_DIV_ENABLE %i \n", DAC5688_CONFIG5_CLK_SYNC_DIV_ENABLE);
// moduleResrc->dac5688Params.clkDivSyncSel = DAC5688_CONFIG5_CLK_SYNC_DIV_SEL_CLEAR; printf("DAC5688_CONFIG5_CLK_SYNC_DIV_SEL_CLEAR %i \n", DAC5688_CONFIG5_CLK_SYNC_DIV_SEL_CLEAR);
moduleResrc->dac5688Params.clkDivSyncSel = DAC5688_CONFIG5_CLK_SYNC_DIV_SEL_SET; // DPP
moduleResrc->dac5688Params.fifoSel = DAC5688_CONFIG23_SYNC_FROM_PIN; // The DAC5688 PIN is driven by the SYNC B signal, which is driven by GATE B, which is driven by the LVTTL external trigger.
moduleResrc->p716xGlobalParams.sbusParams.syncBRecSource = \
P716x_SBUS_CTRL2_SYNCB_RCV_SRC_POS_GATE;
#endif
/* Initialize DMA handles and allocate data buffers ---------------- */
/* set all DMA handles and DMA buffers to NULL */
for (chan = P716x_ADC1; chan < MAX_CHANNELS; chan++)
{
*(exitHdlResrc.dmaHandlePtr[chan]) = NULL;
for (i = 0; i < NUM_DMA_BUFS; i++)
{
(exitHdlResrc.dmaBufPtr[chan][i]) = &(dmaThreadParams[chan].dmaBuf[i]);
(dmaThreadParams[chan].dmaBuf[i]).usrBuf = NULL;
}
}
/* initialize the module using library routines -----------------------
*
* set parameters for this program; parameter defaults are set when
* PTKHLL_DeviceFindAndOpen() is called.
*/
puts ("[ddc_multichan] initialization");
if ((moduleResrc->moduleId == P71641_MODULE_ID) ||
(moduleResrc->moduleId == P71741_MODULE_ID))
ADC12D1800SetParamsDefaults(&adc12d1800Params);
/* set parameters -------------------------------------------------- */
/* Global Parameters - the program uses internal clock A and internal
* gate A register for the gate signal but obtains them from the front
* panel sync bus. Therefore, the module is set up as bus master.
*/
#if !DANE_CHANGED_TRIG_SOURCE
moduleResrc->p716xGlobalParams.sbusParams.clockMaster =
P716x_SBUS_CTRL1_CLK_MASTER_ENABLE;
moduleResrc->p716xGlobalParams.sbusParams.gateASyncAMaster =
P716x_SBUS_CTRL1_GATEA_SYNCA_MASTER_ENABLE;
moduleResrc->p716xGlobalParams.sbusParams.gateARecSource =
P716x_SBUS_CTRL2_GATEA_RCV_SRC_GATE_REG;
moduleResrc->p716xGlobalParams.sbusParams.syncARecSource =
P716x_SBUS_CTRL2_SYNCA_RCV_SRC_SYNC_REG;
#endif
#if DANE_CHANGED_TRIG_SOURCE
moduleResrc->p716xGlobalParams.sbusParams.clockMaster =
P716x_SBUS_CTRL1_CLK_MASTER_ENABLE;
moduleResrc->p716xGlobalParams.sbusParams.gateASyncAMaster =
P716x_SBUS_CTRL1_GATEA_SYNCA_MASTER_ENABLE;
moduleResrc->p716xGlobalParams.sbusParams.gateARecSource =
P716x_SBUS_CTRL2_GATEA_RCV_SRC_GATE_REG;
moduleResrc->p716xGlobalParams.sbusParams.syncARecSource =
P716x_SBUS_CTRL2_SYNCA_RCV_SRC_SYNC_REG;
#endif
#if DAC
moduleResrc->p716xGlobalParams.sbusParams.clockBSource = \
P716x_CLK_CTRL_STAT_FPGA_CLKB_SRC_SEL_DAC;
//moduleResrc->p716xGlobalParams.sbusParams.clockBSource = \
//P716x_CLK_CTRL_STAT_FPGA_CLKB_SRC_SEL_CDC;
#endif
moduleResrc->p716xGlobalParams.sbusParams.clockSelect =
P716x_SBUS_CTRL1_CLK_SEL_VCXO_EXT_CLK_REF;
// P716x_SBUS_CTRL1_CLK_SEL_EXT_CLK;
#if EXT_TRIG
moduleResrc->p716xGlobalParams.sbusParams.gateARecSource = \
P716x_SBUS_CTRL2_GATEA_RCV_SRC_TRIG_IN;
moduleResrc->p716xGlobalParams.sbusParams.syncARecSource = \
P716x_SBUS_CTRL2_SYNCA_RCV_SRC_POS_GATE;
moduleResrc->p716xGlobalParams.sbusParams.sbusGateADriveSource = \
P716x_SBUS_CTRL1_SBUS_GATEA_SRC_FP_TRIG;
#endif
/* Internal Test Generator (if in use) */
if ((dataSrc == DDC_DATA_SRC_TEST_GEN_REAL) ||
(dataSrc == DDC_DATA_SRC_TEST_GEN_CMPLX) )
{
/* enable the generator */
moduleResrc->p716xGlobalParams.testSigParams.testSigEnable =
P716x_TEST_SIG_TS_CTRL_TEST_SIG_RUN;
/* set the frequency to 1.0MHz */
moduleResrc->p716xGlobalParams.testSigParams.testAFreq =
TEST_GEN_FREQ;
}
if ((moduleResrc->moduleId == P71641_MODULE_ID) ||
(moduleResrc->moduleId == P71741_MODULE_ID))
{
if( (P71640DetectAdcClkFreq(&(moduleResrc->p716xRegs),
&(moduleResrc->progParams.clockFreq))) != 0 )
puts (" Clock not detected!\n");
}
/* set the ADC sampling clock frequency - This is actually the DAC sampling frequency. The ADC gets its clock from this. */
moduleResrc->p716xGlobalParams.brdClkFreq = BRDCLK; //moduleResrc->progParams.clockFreq;
printf("[ddc_multichan] BRDCLK is now set to %.2f\n", BRDCLK);
printf("numchans = %d\n",numChans);
/* ADC Channel Parameters - for this program, the only non-default
* channel parameter is the data source.
*/
for (chan = P716x_ADC1; chan < numChans; chan++)
{
/* enable the gate signal input for the channel */
moduleResrc->p716xAdcParams[chan].gateTrigEnable =
P716x_ADC_GATE_TRIG_CTRL_GATE_TRIG_IN_ENABLE;
#if EXT_TRIG
/* ADC Gate/Trigger Control register */
moduleResrc->p716xAdcParams[chan].triggerMode = \
P716x_DAC_GATE_TRIG_CTRL_TRIG_MODE_TRIG;
#endif
/* set ADC channel data packing mode */
moduleResrc->p716xAdcParams[chan].dataPackMode =
P716x_ADC_DATA_CTRL_PACK_MODE_IQ_DATA_PACK;
/* set ADC rate divider to 1 */
moduleResrc->p716xAdcParams[chan].rateDivide = 1;
/* set ADC channel data source */
moduleResrc->p716xAdcParams[chan].dataSource = dataSrc;
/* verify availability of on-board RAM, enable it if found */
status = PTKHLL_VerifyRamPath (chan, &(moduleResrc->p716xRegs),
&(moduleResrc->p716xAdcParams[chan]));
if (status == 0)
puts (" no onboard RAM available");
}
/* DDC Parameters - setup both Dolumns 1 through 6: DC and DDC stage parameters. This
* block of code also sets two ADC parameters that switch in and enable
* the DDC core. Only parameters necessary for this program are set.
*/
for (chan = P716x_ADC1; chan < numChans; chan++)
{
/* insert DDC into the set ADC channel data path */
moduleResrc->p716xAdcParams[chan].dataSelect =
P716x_ADC_DATA_CTRL_USR_DATA_SEL_USER;
moduleResrc->p716xAdcParams[chan].userDataValidEnable =
P716x_ADC_GATE_TRIG_CTRL_USER_DVAL_ENABLE;
/* set DDC general paramters */
moduleResrc->p716xDdcParams[chan].tuningFreq =
tuningFreq;
moduleResrc->p716xDdcParams[chan].accSync =
P716x_DDC_CH_CTRL1_ACC_SYNC_ENABLE;
moduleResrc->p716xDdcParams[chan].fmtrSync =
P716x_DDC_CH_CTRL2_FMTR_SYNC_ENABLE;
moduleResrc->p716xDdcParams[chan].coreSync =
P716x_DDC_CORE_CTRL_CORE_SYNC_ENABLE;
moduleResrc->p716xDdcParams[chan].ddcOut =
P716x_DDC_CH_CTRL2_DDC_OUT_ENABLE;
if ((moduleResrc->moduleId == P71641_MODULE_ID) ||
(moduleResrc->moduleId == P71741_MODULE_ID))
{
moduleResrc->p716xDdcParams[chan].inverseSpectrum = \
P716x_DDC_CH_CTRL2_INVRS_SPEC_ENABLE;
}
else
moduleResrc->p716xDdcParams[chan].inverseSpectrum = \
P716x_DDC_CH_CTRL2_INVRS_SPEC_DISABLE;
/* Select DDC data input source (using local function) */
selectDdcInput(chan, chan,
&moduleResrc->p716xDdcParams[chan].iDataInputSel,
&moduleResrc->p716xDdcParams[chan].qDataInputSel,
&moduleResrc->p716xDdcParams[chan].cmplxInput);
if ((moduleResrc->moduleId != P71641_MODULE_ID) &&
(moduleResrc->moduleId != P71741_MODULE_ID))
{
/* calculate stage decimation based on desired total decimation.
* The library function calculates FIR stage decimation and
* enables FIR Stage 2, if required.
*/
calcRet = P716xCalcDdcStageDecimation(
decimation,
&moduleResrc->p716xDdcParams[chan].stage[P716x_DDC_STAGE1].decimation,
&moduleResrc->p716xDdcParams[chan].stage[P716x_DDC_STAGE2].decimation,
&actualDec,
&moduleResrc->p716xDdcParams[chan].firStage2,
&moduleResrc->p716xBrdResrc);
if (calcRet == 1)
{
printf ("[ddc_multichan] ");
printf ("Desired DDC decimation cannot be achieved\n");
printf (" ");
printf ("Actual decimation = %d\n", actualDec);
}
/* enable FIR sync for both stages */
moduleResrc->p716xDdcParams[chan].stage[P716x_DDC_STAGE1].firSync =
P716x_DDC_CH_CTRL2_ST1_FIR_SYNC_ENABLE;
moduleResrc->p716xDdcParams[chan].stage[P716x_DDC_STAGE2].firSync =
P716x_DDC_CH_CTRL2_ST2_FIR_SYNC_ENABLE;
}
}
/* apply parameter tables to registers --------------------------------
*
* P716xInitAdcRegs() returns a zero if the channel exists; if the
* desired channel doesn't exist, exit program.
*/
//moduleResrc->p716xGlobalParams.cdcParams.cdc7005Params.sbusClockBMuxSelect =
// CDC7005_WORD1_MUX2_SEL_DIV_BY_1;
//moduleResrc->p716xGlobalParams.cdcParams.cdc7005Params.sbusClockBMuxSelect =
// CDC7005_WORD1_MUX3_SEL_DIV_BY_1;
P716xInitGlobalRegs(&moduleResrc->p716xGlobalParams,
&moduleResrc->p716xRegs);
#if DAC
status = P716xInitDacRegs(&(moduleResrc->p716xDacParams[dacChan]),
&(moduleResrc->p716xRegs),
dacChan);
if (status != PTK716X_STATUS_OK)
{
printf("DAC Init problem\n");
exit(0);
}
DAC5688InitDac5688Regs(
(unsigned int *)(moduleResrc->p716xRegs.dacRegs[dacChan].serialAddr),
&(moduleResrc->dac5688Params),
moduleResrc->p716xGlobalParams.brdClkFreq);
/* Issue a DAC5688 software sync (default is using the Software sync)
* Ie., DAC5688_CONFIG23_SYNC_SIF_SIG
*/
DAC5688GenerateSifSync(
(unsigned int *)(moduleResrc->p716xRegs.dacRegs[dacChan].serialAddr));
#if 0
DAC5688RegDump(