Newer
Older
#include <vector>
AWG::AWG() noexcept {
this->pCardHandle = nullptr;
this->cardIdx = -1;
this->serialNumber = -1;
this->instMemSize = -1;
this->bytesPerSample = -1;
this->maxSampleRate = -1;
}
if (this->isOpen()) { this->close(); }
this->pCardHandle = nullptr;
return;
}
void AWG::checkError() {
/**
* printout error if detected.
*
*/
if (this->pCardHandle == nullptr) { return; }
char errorMsg[ERRORTEXTLEN];
if (
spcm_dwGetErrorInfo_i32(this->pCardHandle, NULL, NULL, errorMsg)
!= ERR_OK
) {
//std::cout << "AWG error" << std::string(errorMsg)
// << "\ncard closed\n";
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
//void* AWG::getPageAlignedMem(uint64 memSize) {
// /**
// * returns a pointer to a page aligned mem location.
// *
// * @param memSize size of memory to allocate, bytes
// * @return pointer to start of a page aligned mem location
// */
//
// // for unknown reasons VirtualAlloc/VirtualFree leaks memory if memSize < 4096 (page size)
// // therefore use _aligned_malloc () to get small amounts of page aligned memory
// if (memSize >= 4096)
// return VirtualAlloc(NULL, (size_t)memSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
// else {
// void* pMem = _aligned_malloc((size_t)memSize, 4096);
// if (pMem == NULL)
// return NULL;
// memset(pMem, 0, (size_t)memSize);
// return pMem;
// }
//}
//
//void AWG::freePageAlignedMem(void* pMem, uint64 memSize) {
// /**
// * frees a page aligned memory space.
// *
// * @param pMem pointer to a page aligned memory location
// * @param memSize memory size in bytes to deallocate
// */
// if (memSize >= 4096)
// VirtualFree(pMem, 0, MEM_RELEASE);
// else
// _aligned_free(pMem);
//}
//
void AWG::open(int openIndex) {
/**
* opens a connection to AWG by index.
*
* @param openIndex card index, 0 or 1
*/
if (!this->isOpen()) {
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
return;
}
auto openMsg = "/dev/spcm" + std::to_string(openIndex);
this->pCardHandle = spcm_hOpen(openMsg.c_str());
if (pCardHandle == nullptr) {
std::cout << "card open failed" << std::endl;
return;
}
this->cardIdx = openIndex;
spcm_dwGetParam_i32(
this->pCardHandle,
SPC_PCISERIALNO,
&this->serialNumber
);
spcm_dwGetParam_i64(
this->pCardHandle,
SPC_PCISAMPLERATE,
&this->maxSampleRate
);
spcm_dwGetParam_i64(
this->pCardHandle,
SPC_PCIMEMSIZE,
&this->instMemSize
);
spcm_dwGetParam_i32(
this->pCardHandle,
SPC_MIINST_BYTESPERSAMPLE,
&this->bytesPerSample
);
this->checkError();
}
bool AWG::isOpen() {
/**
* check if a connection to AWG exists.
*
* @return true or false
*/
if (this->pCardHandle == nullptr) { return false; }
return true;
this->checkError();
}
void AWG::close() {
/**
* close the connection to AWG.
*
*/
if (!this->isOpen()) { return; }
spcm_vClose(this->pCardHandle);
this->pCardHandle = nullptr;
}
void AWG::reset() {
/**
* resets the AWG card, equivalent to a power reset.
*
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_CARD_RESET
);
this->checkError();
}
int AWG::getCardIdx() {
return this->cardIdx;
}
int AWG::getSerialNumber() {
return this->serialNumber;
}
int64 AWG::getInstMemSize() {
return this->instMemSize;
}
int AWG::getBytesPerSample() {
return this->bytesPerSample;
}
int64 AWG::getMaxSampleRate() {
return this->maxSampleRate;
}
void AWG::setSampleRate(int64 sampleRate) {
if (!this->isOpen()) { return; }
if (sampleRate < 0 or sampleRate > this->maxSampleRate) {
std::cout << sampleRate << "exceeds max sample rate" << std::endl;
return;
}
spcm_dwSetParam_i64(
this->pCardHandle,
SPC_SAMPLERATE,
sampleRate
);
}
int64 AWG::getSampleRate() {
if (!this->isOpen()) { return 0; }
int64 sr;
spcm_dwGetParam_i64(
this->pCardHandle,
SPC_SAMPLERATE,
&sr
);
this->checkError();
return sr;
}
void AWG::setActiveChannels(std::set<int> channels) {
/**
* activate channels for next run, resets last set.
*
* @param channels vector of channel index (0-3)
*/
if (!this->isOpen()) { return; }
int64 chMask = 0;
for (auto ch : channels) {
chMask = chMask | int64(pow(2,ch));
}
spcm_dwSetParam_i64(
this->pCardHandle,
SPC_CHENABLE,
chMask
);
this->checkError();
this->activeChannels = channels;
}
void AWG::setChannelAmp(int ch, int amp) {
/**
* set channel amplitude.
*
* @param ch channel index
* @param amp amplitude (mV)
*/
if (!this->isOpen()) { return; }
const auto regStep = SPC_AMP1 - SPC_AMP0;
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_AMP0 + ch * regStep,
amp
);
this->checkError();
}
void AWG::setChannelStopLvl(int ch, CHANNEL_STOPLVL stopLvl) {
/**
* set channel stop level.
*
* @param ch channel index
* @param stopLvl options: ZERO,LOW,HIGH,HOLDLAST
*/
if (!this->isOpen()) { return; }
const auto regStep = SPC_CH1_STOPLEVEL - SPC_CH0_STOPLEVEL;
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_CH0_STOPLEVEL + ch * regStep,
int32(stopLvl)
);
this->checkError();
}
void AWG::toggleChannelOutput(int ch, bool enable) {
/**
* toggle channel output.
*
* @param ch channel index
* @param enable true or false
*/
if (!this->isOpen()) { return; }
if (ch < 0 or ch > 3) {
std::cout << ch << "is not an allowed channel index"
<< std::endl;
return;
}
const auto regStep = SPC_ENABLEOUT1 - SPC_ENABLEOUT0;
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_ENABLEOUT0 + ch * regStep,
enable
);
this->checkError();
}
void AWG::setChannel(int ch, int amp, CHANNEL_STOPLVL stopLvl, bool enable) {
/**
* channel macro set amplitude, stop level, and enables output.
*
* @param ch channel index
* @param amp amplitude (mV)
* @param stopLvl options: ZERO, LOW, HIGH, HOLDLAST
*/
this->setChannelAmp(ch, amp);
this->setChannelStopLvl(ch, stopLvl);
this->toggleChannelOutput(ch, enable);
}
int AWG::getChannelCount() {
if (!this->isOpen()) { return 0; }
int32 numCh;
spcm_dwGetParam_i32(
this->pCardHandle,
SPC_CHCOUNT,
&numCh
);
this->checkError();
return numCh;
}
std::set<int> AWG::getChannelActivated() {
return this->activeChannels;
}
void AWG::setChannelDiffMode(int chPair, bool enable) {
/**
* set channel 0(2) and channel 1(3) to differential output mode.
*
* @param chPair 0 for channel 0,1, 1 for channel 2,3
* @param enable true or false
*/
if (!this->isOpen()) { return; }
if (chPair != 0 && chPair != 1) {
std::cout << "unable to parse input chPair: "
<< chPair << std::endl;
return;
}
if (enable) {
if (chPair == 0 && this->activeChannels.contains(1)) {
std::cout << "channel 1 must disabled for chPair=0"
"in differential output mode" << std::endl;
return;
}
if (chPair == 1 && this->activeChannels.contains(3)) {
std::cout << "channel 3 must disabled for chPair=1"
"in differential output mode" << std::endl;
return;
}
}
const auto regStep = SPC_DIFF2 - SPC_DIFF0;
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_DIFF0 + chPair * regStep,
enable
);
this->checkError();
}
void AWG::setChannelDoubleMode(int chPair, bool enable) {
/**
* set channel 0(2) and channel 1(3) to differential output mode.
*
* @param chPair 0 for channel 0,1, 1 for channel 2,3
* @param enable true or false
*/
if (!this->isOpen()) { return; }
if (chPair != 0 && chPair != 1) {
std::cout << "unable to parse input chPair: "
<< chPair << std::endl;
return;
}
if (enable) {
if (chPair == 0 && this->activeChannels.contains(1)) {
std::cout << "channel 1 must disabled for chPair=0"
"in double output mode" << std::endl;
return;
}
if (chPair == 1 && this->activeChannels.contains(3)) {
std::cout << "channel 3 must disabled for chPair=1"
"in double output mode" << std::endl;
return;
}
}
const auto regStep = SPC_DOUBLEOUT2 - SPC_DOUBLEOUT0;
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_DOUBLEOUT0 + chPair * regStep,
enable
);
this->checkError();
}
void AWG::writeSetup() {
/**
* write current setup to card without starting hardware,
* some settings may not be changed while card is running.
*
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_CARD_WRITESETUP
);
this->checkError();
}
void AWG::cardRun() {
/**
* starts the card with all selected settings.
*
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_CARD_START
);
this->checkError();
}
void AWG::cardStop() {
/**
* stops the card, no effect if not running.
*
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_CARD_STOP
);
this->checkError();
}
void AWG::waitReady() {
/**
* wait until card finished current output run.
* TODO: check if this blocks.
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_CARD_WAITREADY
);
this->checkError();
}
void AWG::setTimeOut(int time) {
/**
* set a timeout time in ms, 0 to disable.
*
* @param time
*/
if (!this->isOpen()) { return; }
if (time < 0) {
std::cout << time << "is an invalid timeout time" << std::endl;
}
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_TIMEOUT,
time
);
this->checkError();
}
int AWG::getTimeOut() {
if (!this->isOpen()) { return 0; }
int32 time;
spcm_dwGetParam_i32(
this->pCardHandle,
SPC_TIMEOUT,
&time
);
return time;
}
void AWG::printCardStatus() {
if (!this->isOpen()) { return; }
int32 status;
spcm_dwGetParam_i32(
this->pCardHandle,
SPC_M2STATUS,
&status
);
std::cout << STATUS_NAMES.at(status) << std::endl;
}
void AWG::toggleTrigger(bool enable) {
/**
* toggle the trigger detection.
*
* @param enable
*/
if (!this->isOpen()) { return; }
auto command = enable
? M2CMD_CARD_ENABLETRIGGER
: M2CMD_CARD_DISABLETRIGGER;
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
command
);
this->checkError();
}
void AWG::forceTrigger() {
/**
* sends a software trigger, equivalent to an actual trigger.
*
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_CARD_FORCETRIGGER
);
this->checkError();
}
void AWG::waitTrigger() {
/**
* wait until trigger event.
* TODO: check if this blocks.
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_CARD_WAITTRIGGER
);
this->checkError();
}
void AWG::setTrigMaskOr(std::initializer_list<TRIGGER_MASK> trigMasks) {
/**
* program the OR trigger mask.
*
* @param trigMasks 1 or more TRIGGER_MASK
*/
if (!this->isOpen()) { return; }
auto mask = 0;
for (auto m : trigMasks) {
mask = mask | int32(m);
}
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_TRIG_ORMASK,
mask
);
this->checkError();
}
void AWG::setTrigMaskOr(std::vector<TRIGGER_MASK> trigMasks) {
/**
* program the OR trigger mask.
*
* @param trigMasks 1 or more TRIGGER_MASK
*/
if (!this->isOpen()) { return; }
auto mask = 0;
for (auto m : trigMasks) {
mask = mask | int32(m);
}
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_TRIG_ORMASK,
mask
);
this->checkError();
}
void AWG::setTrigMaskAnd(std::initializer_list<TRIGGER_MASK> trigMasks) {
/**
* program the AND trigger mask.
*
* @param trigMasks 1 or more TRIGGER_MASK
*/
if (!this->isOpen()) { return; }
int mask = 0;
for (auto m : trigMasks) {
mask = mask | int32(m);
}
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_TRIG_ANDMASK,
mask
);
this->checkError();
}
void AWG::setTrigMaskAnd(std::vector<TRIGGER_MASK> trigMasks) {
/**
* program the AND trigger mask.
*
* @param trigMasks 1 or more TRIGGER_MASK
*/
if (!this->isOpen()) { return; }
int mask = 0;
for (auto m : trigMasks) {
mask = mask | int32(m);
}
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_TRIG_ANDMASK,
mask
);
this->checkError();
}
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
void AWG::setTrigMode(int trigChannel, TRIGGER_MODE trigMode) {
/**
* sets the trigger mode of trigger channel.
*
* @param trigChannel 0 or 1 (labeled EXT0 and EXT1 on board)
* @param trigMode see TRIGGER_MODE for options
*/
if (!this->isOpen()) { return; }
if (trigChannel != 0 and trigChannel != 1) {
std::cout << "invalid trigger channel: "
<< trigChannel << std::endl;
return;
}
auto trigRegister = trigChannel
? SPC_TRIG_EXT1_MODE
: SPC_TRIG_EXT0_MODE;
spcm_dwSetParam_i32(
this->pCardHandle,
trigRegister,
int32(trigMode)
);
this->checkError();
}
void AWG::setTrigTerm(int term) {
/**
* sets the trigger input termination.
*
* \param term 0 for high impedance, 1 for 50 Ohm.
*/
if (!this->isOpen()) { return; }
if (term != 0) {
std::cout << "invalid trigger input termination setting: "
<< term << std::endl;
return;
}
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_TRIG_TERM,
term
);
this->checkError();
}
int AWG::getTrigTerm() {
if (!this->isOpen()) { return -1; }
int32 term;
spcm_dwGetParam_i32(
this->pCardHandle,
SPC_TRIG_TERM,
&term
);
this->checkError();
return term;
}
void AWG::setTrigCoupling(int channel, int coupling) {
/**
* sets trigger coupling to DC or AC.
*
* @param coupling 1 for AC, 0 for DC
*/
if (!this->isOpen()) { return; }
if (coupling != 0 and coupling != 1) {
std::cout << "invalid trigger coupling setting :" << coupling
<< std::endl;
return;
}
auto trigChannelReg = channel ?
SPC_TRIG_EXT1_ACDC : SPC_TRIG_EXT0_ACDC;
spcm_dwSetParam_i32(
this->pCardHandle,
trigChannelReg,
coupling
);
this->checkError();
}
int AWG::getTrigCoupling(int channel) {
if (!this->isOpen()) { return -1; }
auto trigChannelReg = channel ?
SPC_TRIG_EXT1_ACDC : SPC_TRIG_EXT0_ACDC;
int32 coupling;
spcm_dwGetParam_i32(
this->pCardHandle,
trigChannelReg,
&coupling
);
this->checkError();
return coupling;
}
void AWG::setTrigLvl(int channel, int level) {
/**
* set trigger level.
*
* @param channel trigger channel
* @param level -10000mV to 10000mV
*/
if (!this->isOpen()) { return; }
if (level < -10000 or level > 10000) {
std::cout << "invalid trigger level: " << level << std::endl;
return;
}
auto trigChannelReg = channel ?
SPC_TRIG_EXT1_LEVEL0 : SPC_TRIG_EXT0_LEVEL0;
spcm_dwSetParam_i64(
this->pCardHandle,
trigChannelReg,
level
);
this->checkError();
}
int AWG::getTrigLvl(int channel) {
if (!this->isOpen()) { return 0; }
auto trigChannelReg = channel ?
SPC_TRIG_EXT1_LEVEL0 : SPC_TRIG_EXT0_LEVEL0;
int32 level;
spcm_dwGetParam_i32(
this->pCardHandle,
trigChannelReg,
&level
);
this->checkError();
return level;
}
void AWG::setTrigRearmLvl(int channel, int level) {
/**
* sets rearm trigger level.
*
* @param channel trigger channel
* @param level -10000mV to +10000mV
*/
if (!this->isOpen()) { return; }
auto trigChannelReg = channel ?
SPC_TRIG_EXT1_LEVEL1 : SPC_TRIG_EXT0_LEVEL1;
spcm_dwSetParam_i64(
this->pCardHandle,
trigChannelReg,
level
);
this->checkError();
}
int64 AWG::getTrigRearmLvl(int channel) {
if (!this->isOpen()) { return 0; }
auto trigChannelReg = channel ?
SPC_TRIG_EXT1_LEVEL1 : SPC_TRIG_EXT0_LEVEL1;
int64 level;
spcm_dwGetParam_i64(
this->pCardHandle,
trigChannelReg,
&level
);
return level;
}
//void AWG::setReplayMode(REPLAY_MODE mode) {
// /**
// * set the data replay mode.
// *
// * a macro for sequence replay mode is setup in
// * initReplayModeSeq(), if you wish to use other modes, you must
// * consult the manual for mode specific settings.
// *
// * @param mode SINGLE, MULTI, GATE, SINGLERESTART, SEQUENCE,
// * FIFO_{SINGLE, MULTI, GATE}.
// *
// */
// if (!this->isOpen()) { return; }
// spcm_dwSetParam_i32(
// this->pCardHandle,
// SPC_CARDMODE,
// mode
// );
// this->checkError();
//}
//
//void AWG::setMemSize(int64 sampleSize) {
// /**
// * set memory size in samples in SINGLE, SINGLE_RESTART,
// * MULTI, and GATE mode.
// * Please consult the manual for # of channel dependent
// * minimum/maximum sample size considerations.
// *
// * @param sampleSize size of sample
// *
// */
// if (!this->isOpen()) { return; }
// if (sampleSize < 0 or sampleSize > 2e9) {
// std::cout << "invalid sampleSize: " << sampleSize << std::endl;
// return;
// }
// spcm_dwSetParam_i64(
// this->pCardHandle,
// SPC_MEMSIZE,
// sampleSize
// );
// this->checkError();
//}
//
//int64 AWG::getMemsize() {
// int64 ms;
// spcm_dwGetParam_i64(
// this->pCardHandle,
// SPC_MEMSIZE,
// &ms
// );
// this->checkError();
// return ms;
//}
//
//void AWG::setLoop(int nLoop) {
// /**
// * set number of replay loops in SINGLE, SINGLE_RESTART,
// * MULTI, and GATE mode.
// *
// * @param nLoop
// */
// if (!this->isOpen()) { return; }
// if (nLoop < 0) {
// std::cout << "invalid number of loop: " << nLoop << std::endl;
// return;
// }
// spcm_dwSetParam_i32(
// this->pCardHandle,
// SPC_LOOPS,
// nLoop
// );
//}
//
//int64 AWG::getLoop() {
// if (!this->isOpen()) { return -1; }
// int64 nl;
// spcm_dwGetParam_i64(
// this->pCardHandle,
// SPC_LOOPS,
// &nl
// );
// return nl;
//}
void AWG::initReplayModeSeq(int nSeg) {
/**
* initialize sequence replay mode.
*
* @param nSeg number of segments memory is divided into
*/
if (!this->isOpen()) { return; }
if (nSeg % 2 != 0) {
std::cout << "invalid number of segments for SEQUENCE mode: "
<< nSeg << std::endl;
return;
}
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_CARDMODE,
int32(REPLAY_MODE::SEQUENCE)
);
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_SEQMODE_MAXSEGMENTS,
nSeg
);
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_SEQMODE_STARTSTEP,
0
);
this->checkError();
}
void AWG::setSeqModeStep(
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
uint64 segment,
uint64 nextStep,
uint64 nLoop,
SEQ_LOOPCONDITION condition) {
/**
* configure a step in sequence replay mode.
*
* @param step step to configure
* @param segment memory segment step is associated with
* @param nextStep index of next step after end loop condition is met
* @param condition end loop condition
*/
if (!this->isOpen()) { return; }
int64 mask =
(uint64(condition) << 32)
| (nLoop << 32)
| (nextStep << 16)
| segment;
spcm_dwSetParam_i64(
this->pCardHandle,
SPC_SEQMODE_STEPMEM0 + step,
mask
);
}
void AWG::writeSeqModeSegment(
void* pDataBuffer,
int size,
int segment) {
/**
* write buffered data into a memory segment in sequence replay mode.
*
* @param pDataBuffer pointer to data memory, must be page aligned
* @param size size of data buffer in number of samples
* @param segment memory segment to write to
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_SEQMODE_WRITESEGMENT,
segment
);
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_SEQMODE_SEGMENTSIZE,
size
);
this->prepDataTransfer(pDataBuffer, size);
this->startDataTransfer();
this->checkError();
}
void AWG::prepDataTransfer(
void* dataBuffer,
uint64 bufferLen,
BUFFER_TYPE bufType,
TRANSFER_DIR dir,
uint32 notifySize,
uint64 brdMemOffs
) {
/**
* prepares the board for data transfer.
*
* @param dataBuffer pointer to the data buffer
* @param bufferLen length of data buffer, bytes
* @param bufType buffer type, use only DATA for replay
* @param dir direction of data transfer
* @param notifySize number of bytes after which an event is sent
* @param brdMemOffs offset for transfer in board memory
*/
if (!this->isOpen()) { return; }
spcm_dwDefTransfer_i64(
this->pCardHandle,
int32(bufType),
int32(dir),
notifySize,
dataBuffer,
brdMemOffs,
bufferLen
);
this->checkError();
}
void AWG::startDataTransfer() {
/**
* starts data transfer for a defined buffer.
*
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_DATA_STARTDMA
);
this->checkError();
}
void AWG::waitDataTransfer() {
/**
* wait for data transfer to complete, blocks,
* timeout is considered.
*
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_DATA_WAITDMA
);
this->checkError();
}
void AWG::stopDataTransfer() {
/**
* stops a running data transfer.
*
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(
this->pCardHandle,
SPC_M2CMD,
M2CMD_DATA_STOPDMA
);
this->checkError();
}
void AWG::setClockMode(CLOCK_MODE cm) {
/**
* set the clock mode.
*
* @param cm INTPLL or EXTREFCLK
*/
if (!this->isOpen()) { return; }
spcm_dwSetParam_i32(