forked from petermilne/ACQ420FMC
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ads5294.cpp
718 lines (623 loc) · 15.7 KB
/
ads5294.cpp
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
/*
* ads5294.cpp
*
* Created on: 15 Feb 2015
* Author: pgm
*/
#include "ads5294.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void die(const char *fmt)
{
fprintf(stderr, "%s\n", fmt);
exit(1);
}
int Ads5294::setGain(Chan chan, Gain gain)
{
if (!isValidChan(chan)) die("channel not valid");
if (!isValidGain(gain)) die("gain not valid");
if (chan <= 4){
Reg& reg = regs->regs[Ads5294Regs::RA_GAIN_14];
reg &= ~(RA_GAIN_CH_MASK << RA_GAIN_14_CH(chan));
reg |= gain << RA_GAIN_14_CH(chan);
}else{
Reg& reg = regs->regs[Ads5294Regs::RA_GAIN_58];
reg &= ~(RA_GAIN_CH_MASK << RA_GAIN_58_CH(chan));
reg |= gain << RA_GAIN_58_CH(chan);
}
return 0;
}
Ads5294::Gain Ads5294::getGain(Chan chan)
{
if (!isValidChan(chan)) die("channel not valid");
Reg reg;
if (chan <= 4){
reg = regs->regs[Ads5294Regs::RA_GAIN_14];
reg >>= RA_GAIN_14_CH(chan);
}else{
reg = regs->regs[Ads5294Regs::RA_GAIN_58];
reg >>= RA_GAIN_58_CH(chan);
}
return static_cast<Gain>(reg&RA_GAIN_CH_MASK);
}
int Ads5294::setCustomCoefficients(Chan chan, short* coeffs)
{
if (!isValidChan(chan)) die("channel not valid");
Reg* dst = ®s->regs[RA_CUSTOM_COEFF(chan, 0)];
if (coeffs){
memcpy(dst, coeffs, NTAPS*sizeof(Reg));
}
for (int tap = 0; tap < NTAPS; ++tap){
if (coeffs){
dst[tap] |= 1<<RA_CUSTOM_COEFF_EN_BIT;
}else{
dst[tap] = 0;
}
}
return 0;
}
short* Ads5294::getCustomCoefficients(Chan chan)
{
if (!isValidChan(chan)) die("channel not valid");
return reinterpret_cast<short*>(®s->regs[RA_CUSTOM_COEFF(chan, 0)]);
}
int Ads5294::_setDecimationFilter(
Reg& freg, bool enable, bool odd_tap, FilterCoeffSelect fcs, FilterRate rate)
{
unsigned genbit = 1<<RA_GLOBAL_EN_FILTER_EN_BIT;
if (enable){
regs->regs[Ads5294Regs::RA_GLOBAL_EN_FILTER] |= genbit;
freg |= (1<<RA_FILTER_ENABLE);
}else{
regs->regs[Ads5294Regs::RA_GLOBAL_EN_FILTER] &= ~genbit;
freg &= ~ (1<<RA_FILTER_ENABLE);
}
if (odd_tap){
freg |= (1<<RA_FILTER_ODD_TAP_BIT);
}else{
freg &= ~(1<<RA_FILTER_ODD_TAP_BIT);
}
freg &= ~(RA_FILTER_COEFF_MASK << RA_FILTER_COEFF_SHL);
freg |= fcs << RA_FILTER_COEFF_SHL;
freg &= ~(RA_FILTER_RATE_MASK << RA_FILTER_RATE_SHL);
freg |= rate << RA_FILTER_RATE_SHL;
return 0;
}
int Ads5294::setDecimationFilter(Chan chan, Filter filter, bool odd_tap)
{
if (!isValidChan(chan)) die("channel not valid");
if (!isValidFilter(filter)) die("filer not valid");
const bool filen = true;
const bool odd = true;
const bool even = false;
Reg& freg = regs->regs[Ads5294Regs::RA_FILTER_1+CHIX(chan)];
switch(filter){
case F_DISABLE:
case F_CUSTOM_D1:
regs->regs[Ads5294Regs::RA_DATA_RATE] = RA_DATA_RATE_DIV_1;
break;
case F_LP_ODD_D2:
case F_HP_ODD_D2:
case F_CUSTOM_D2:
regs->regs[Ads5294Regs::RA_DATA_RATE] = RA_DATA_RATE_DIV_2;
break;
case F_LP_EVEN_D4:
case F_BP1_EVEN_D4:
case F_BP2_EVEN_D4:
case F_HP_ODD_D4:
case F_CUSTOM_D4:
regs->regs[Ads5294Regs::RA_DATA_RATE] = RA_DATA_RATE_DIV_4;
break;
case F_CUSTOM_D8:
regs->regs[Ads5294Regs::RA_DATA_RATE] = RA_DATA_RATE_DIV_8;
break;
}
switch(filter){
case F_DISABLE:
return _setDecimationFilter(freg, !filen, even, FCS_DISABLE, FR_D2);
case F_LP_ODD_D2:
return _setDecimationFilter(freg, filen, odd, FCS_LP_ODD, FR_D2);
case F_HP_ODD_D2:
return _setDecimationFilter(freg, filen, odd, FCS_HP_ODD, FR_D2);
case F_LP_EVEN_D4:
return _setDecimationFilter(freg, filen, even, FCS_LP_EVEN, FR_D4);
case F_BP1_EVEN_D4:
return _setDecimationFilter(freg, filen, even, FCS_BP1_EVEN, FR_D4);
case F_BP2_EVEN_D4:
return _setDecimationFilter(freg, filen, even, FCS_BP2_EVEN, FR_D4);
case F_HP_ODD_D4:
return _setDecimationFilter(freg, filen, odd, FCS_HP_ODD2, FR_D4);
case F_CUSTOM_D2:
return _setDecimationFilter(freg, filen, odd_tap, FCS_CUSTOM, FR_D2);
case F_CUSTOM_D4:
return _setDecimationFilter(freg, filen, odd_tap, FCS_CUSTOM, FR_D4);
case F_CUSTOM_D8:
return _setDecimationFilter(freg, filen, odd_tap, FCS_CUSTOM, FR_D8);
case F_CUSTOM_D1:
return _setDecimationFilter(freg, filen, odd_tap, FCS_CUSTOM, FR_D1);
}
die("should not get here ..");
return 0;
}
Ads5294::Filter Ads5294::getDecimationFilter(Chan chan)
{
return F_DISABLE;
}
int Ads5294::setHiPassFilter(Chan chan, bool enable, unsigned hpfun)
{
if (!isValidChan(chan)) die("channel not valid");
Reg& freg = regs->regs[Ads5294Regs::RA_FILTER_1+CHIX(chan)];
const unsigned en = 1<<RA_FILTER_HPF_EN_BIT;
if (enable){
freg &= ~(RA_FILTER_HPF_CRNR_MASK << RA_FILTER_HPF_CRNR_SHL);
freg |= en | (hpfun << RA_FILTER_HPF_CRNR_SHL);
}else{
freg &= ~en;
}
return 0;
}
unsigned Ads5294::getHiPassFilter(Chan chan)
{
if (!isValidChan(chan)) die("channel not valid");
Reg& freg = regs->regs[Ads5294Regs::RA_FILTER_1+CHIX(chan)];
return (freg >> RA_FILTER_HPF_CRNR_SHL)&RA_FILTER_HPF_CRNR_MASK;
}
int Ads5294::setDataRate(DataRate dr)
{
Reg& freg = regs->regs[Ads5294Regs::RA_DATA_RATE];
freg = dr;
return 0;
}
Ads5294::DataRate Ads5294::getDataRate()
{
return static_cast<DataRate>(regs->regs[Ads5294Regs::RA_DATA_RATE]);
}
int Ads5294::setAverageSelect(Chan bin, bool enable, unsigned avsel)
{
if (!isValidChan(bin)) die("bin not valid");
unsigned chav = 1<<RA_GLOBAL_EN_FILTER_CHAVG_BIT;
if (enable){
regs->regs[Ads5294Regs::RA_GLOBAL_EN_FILTER] |= chav;
if (bin <= 4){
Reg& freg = regs->regs[Ads5294Regs::RA_AVG_14];
freg &= ~(RA_AVG_MASK << RA_AVG_14(bin));
freg |= (avsel&RA_AVG_MASK) << RA_AVG_14(bin);
}else{
Reg& freg = regs->regs[Ads5294Regs::RA_AVG_58];
freg &= ~(RA_AVG_MASK << RA_AVG_58(bin));
freg |= (avsel&RA_AVG_MASK) << RA_AVG_58(bin);
}
}else{
regs->regs[Ads5294Regs::RA_GLOBAL_EN_FILTER] &= ~chav;
}
return 0;
}
unsigned Ads5294::Ads5294::getAverageSelect(Chan bin)
{
if (!isValidChan(bin)) die("bin not valid");
unsigned chav = 1<<RA_GLOBAL_EN_FILTER_CHAVG_BIT;
if (regs->regs[Ads5294Regs::RA_GLOBAL_EN_FILTER]&chav){
if (bin <= 4){
Reg freg = regs->regs[Ads5294Regs::RA_AVG_14];
return (freg >> RA_AVG_14(bin)) & RA_AVG_MASK;
}else{
Reg freg = regs->regs[Ads5294Regs::RA_AVG_58];
return (freg >> RA_AVG_58(bin)) & RA_AVG_MASK;
}
}else{
return 0xffffffff;
}
}
int Ads5294::setInvert(Chan chan, bool invert)
{
if (!isValidChan(chan)) die("chan not valid");
Reg& freg = regs->regs[Ads5294Regs::RA_INVERT_CH];
if (invert){
freg |= CHAN2BIT(chan);
}else{
freg &= ~CHAN2BIT(chan);
}
return 0;
}
unsigned Ads5294::getInvert(Chan chan)
{
if (!isValidChan(chan)) die("chan not valid");
return (regs->regs[Ads5294Regs::RA_INVERT_CH]&CHAN2BIT(chan)) != 0;
}
int Ads5294::setLFNS(Chan chan, bool enable)
{
if (!isValidChan(chan)) die("chan not valid");
Reg& freg = regs->regs[Ads5294Regs::RA_LFNS];
if (enable){
freg |= CHAN2BIT(chan);
}else{
freg &= ~CHAN2BIT(chan);
}
return 0;
}
bool Ads5294::getLFNS(Chan chan)
{
if (!isValidChan(chan)) die("chan not valid");
return (regs->regs[Ads5294Regs::RA_LFNS]&CHAN2BIT(chan)) != 0;
}
int Ads5294::SetLvdsTestPatRamp(bool enable)
{
Reg& reg = regs->regs[Ads5294Regs::RA_TEST25];
reg &= ~0x70;
if (enable){
reg |= 0x40;
SetLvdsTestPatDeskew(false);
}
return 1;
}
int Ads5294::SetLvdsTestPatDeskew(bool enable)
{
Reg& reg = regs->regs[Ads5294Regs::RA_TEST25];
reg &= ~0x03;
if (enable){
reg |= 0x01;
SetLvdsTestPatRamp(false);
}
return 1;
}
int Ads5294::setPatDeskew(bool enable)
{
Reg& reg = regs->regs[Ads5294Regs::RA_PAT];
Reg& frame = regs->regs[Ads5294Regs::RA_EN_FRAME];
reg &= ~0x03;
if (enable){
reg |= 0x01;
frame = (1<<RA_EN_FRAME_BIT)|0x1555;
}else{
frame = 0;
}
return 1;
}
int Ads5294::setPatSync(bool enable)
{
Reg& reg = regs->regs[Ads5294Regs::RA_PAT];
reg &= ~0x03;
if (enable){
reg |= 0x02;
}
return 1;
}
int Ads5294::setDataPattern(unsigned short regval)
{
Reg& reg = regs->regs[Ads5294Regs::RA_WIRE_MODE];
reg = regval;
return 1;
}
#define WIRE_MODE_2WIRE (1<<0)
struct KeyLut {
const char* key;
unsigned short pat;
unsigned short pat_field;
};
KeyLut keyLut[] = {
{ "EN_2WIRE", 1<<0 },
{ "BTC_MODE", 1<<2 },
{ "MSB_FIRST", 1<<3 },
{ "EN_SDR", 1<<4 },
{ "EN_14BIT", 0x40, 0xf0 },
{ "EN_16BIT", 0x80, 0xf0 },
{ "FALL_SDR", 1<<13 },
};
#define NKEYS (sizeof(keyLut)/sizeof(KeyLut))
int _help() {
printf("_help() NKEYS %d\n", NKEYS);
for (unsigned ikey = 0; ikey < NKEYS; ++ikey){
const char* k = keyLut[ikey].key;
printf("%s ", k);
}
printf("\n");
return 0;
}
int Ads5294::setDataPattern(int argc, char* argv[])
{
int ii;
for (ii = 0; ii < argc; ++ii){
const char* tok = argv[ii];
if (strcmp(tok, "help") == 0){
return _help();
}else{
Reg& reg = regs->regs[Ads5294Regs::RA_WIRE_MODE];
bool negate = false;
if (tok[0] == '-'){
negate = true;
tok += 1;
}
for (unsigned ikey = 0; ikey < NKEYS; ++ikey){
const char* k = keyLut[ikey].key;
unsigned short bv = keyLut[ikey].pat;
unsigned clr = ~keyLut[ikey].pat_field;
if (strcmp(k, tok) == 0){
reg &= clr;
if (negate){
reg &= ~bv;
}else{
reg |= bv;
}
goto next_arg;
}
}
printf("Ads5294::setDataPattern() ERROR: \"%s\" not supported\n", tok);
return 0;
}
next_arg:
;
}
printf("\n");
return 0;
}
int Ads5294::getDataPattern()
{
Reg& reg = regs->regs[Ads5294Regs::RA_WIRE_MODE];
for (unsigned ikey = 0; ikey < NKEYS; ++ikey){
unsigned rv = reg;
if (keyLut[ikey].pat_field){
rv &= keyLut[ikey].pat_field;
if (rv == keyLut[ikey].pat){
printf("%s ", keyLut[ikey].key);
}
}else{
const char* k = keyLut[ikey].key;
unsigned short bv = keyLut[ikey].pat;
printf("%c%s ", (rv&bv) == bv? ' ':'-', k);
}
}
printf("\n");
return 0;
}
int Ads5294::setReg(unsigned reg, unsigned pattern)
{
printf("setReg() %02x %04x\n", reg, pattern);
if (reg > 0 && reg < 255){
Reg& _reg = regs->regs[reg];
_reg = pattern;
return 1;
}else{
printf("ERROR reg not in range 0 .. 255\n");
return 0;
}
}
int Ads5294::getReg(unsigned reg, unsigned& pattern)
{
printf("getReg() %02x\n", reg);
if (reg > 0 && reg < 255){
Reg& _reg = regs->regs[reg];
pattern = _reg;
return 0;
}else{
printf("ERROR reg not in range 0 .. 255\n");
return 0;
}
}
Ads5294::MapLut Ads5294::maplut[] = {
{ "MAP_CH1234_TO_OUT1A", Ads5294Regs::RA_MAP_50, 0, false },
{ "MAP_CH1234_TO_OUT1B", Ads5294Regs::RA_MAP_50, 4, false },
{ "MAP_CH1234_TO_OUT2A", Ads5294Regs::RA_MAP_50, 8, false },
{ "MAP_CH1234_TO_OUT2B", Ads5294Regs::RA_MAP_51, 0, false },
{ "MAP_CH1234_TO_OUT3A", Ads5294Regs::RA_MAP_51, 4, false },
{ "MAP_CH1234_TO_OUT3B", Ads5294Regs::RA_MAP_51, 8, false },
{ "MAP_CH1234_TO_OUT4A", Ads5294Regs::RA_MAP_52, 0, false },
{ "MAP_CH1234_TO_OUT4B", Ads5294Regs::RA_MAP_52, 4, false },
{ "MAP_CH5678_TO_OUT5A", Ads5294Regs::RA_MAP_53, 4, true },
{ "MAP_CH5678_TO_OUT5B", Ads5294Regs::RA_MAP_53, 0, true },
{ "MAP_CH5678_TO_OUT6A", Ads5294Regs::RA_MAP_54, 0, true },
{ "MAP_CH5678_TO_OUT6B", Ads5294Regs::RA_MAP_53, 8, true },
{ "MAP_CH5678_TO_OUT7A", Ads5294Regs::RA_MAP_54, 8, true },
{ "MAP_CH5678_TO_OUT7B", Ads5294Regs::RA_MAP_54, 4, true },
{ "MAP_CH5678_TO_OUT8A", Ads5294Regs::RA_MAP_55, 4, true },
{ "MAP_CH5678_TO_OUT8B", Ads5294Regs::RA_MAP_55, 0, true }
};
#define NMAPLUT (sizeof(maplut)/sizeof(MapLut))
struct ChannelMapEncoding {
int chan;
int two_bit;
unsigned pattern;
};
ChannelMapEncoding cme[] = {
{ 0, 0, 0x8 }, // power down
{ 1, 0, 0x0 }, { 1, 2, 0x1 }, // channel 1
{ 2, 0, 0x2 }, { 2, 2, 0x3 },
{ 3, 0, 0x4 }, { 3, 2, 0x5 },
{ 4, 0, 0x6 }, { 4, 2, 0x7 },
{ 5, 0, 0x6 }, { 5, 2, 0x7 },
{ 6, 0, 0x4 }, { 6, 2, 0x5 },
{ 7, 0, 0x2 }, { 7, 2, 0x3 },
{ 8, 0, 0x0 }, { 8, 2, 0x1 }
};
#define NCME (sizeof(cme)/sizeof(ChannelMapEncoding))
const Ads5294::MapLut& Ads5294::lookupMap(const char* key){
for (unsigned ik = 0; ik < NMAPLUT; ++ik){
if (strcmp(key, maplut[ik].key) == 0){
return maplut[ik];
}
}
fprintf(stderr, "ERROR: key \"%s\" NOT VALID\n", key);
exit(1);
return maplut[0];
}
void Ads5294::printMapHelp(const char* pfx)
{
for (unsigned ik = 0; ik < NMAPLUT; ++ik){
MapLut& map = maplut[ik];
printf("%s %s %s %s # %s %s\n",
pfx, map.key,
map.hi_chan? "5": "1",
"0",
map.hi_chan? "5678": "1234",
"02");
}
printf("%s ALL 0\n", pfx);
}
void Ads5294::printMap(const Ads5294::MapLut& map)
{
Reg& _reg = regs->regs[map.reg];
unsigned pat = (_reg >> map.shl) & 0x0f;
printf("%s ", map.key);
for (unsigned ix = 0; ix < NCME; ++ix){
if (pat == cme[ix].pattern && isValidChx(map, cme[ix].chan)){
if (cme[ix].chan!=0){
printf("%d", cme[ix].chan);
if (cme[ix].chan!=0 && cme[ix].two_bit==2){
printf(" 2");
}
}
printf("\n");
return;
}
}
printf("ERROR: illegal pattern %x\n", pat);
}
void Ads5294::printMap(int imap)
{
printMap(maplut[imap]);
}
bool Ads5294::isValidChx(const Ads5294::MapLut& map, int chx, bool warn)
{
if (chx == 0) return true;
bool ok = false;
if (map.hi_chan){
ok = chx >= 5 && chx <= 8;
}else{
ok = chx >= 1 && chx <= 4;
}
if (!ok && warn){
printf("WARNING: \"%s\" and %d not a valid combo\n", map.key, chx);
}
return ok;
}
int Ads5294::setMap(const char* mapping, int chx, int two_bits)
{
if (strcmp(mapping, MAP_ALL) == 0 || strncmp(mapping, "ALL", 3) == 0 ){
int im0 = 0;
int im1 = NMAPLUT;
// else all regs .. value for 0,0,0,0 only
for (int imap = im0; imap < im1; ++imap){
setMap(maplut[imap].key, chx, two_bits);
}
return 1;
}else{
const MapLut& map = lookupMap(mapping);
if (!isValidChx(map, chx, true)){
return 0;
}
for (unsigned ix = 0; ix < NCME; ++ix){
if (chx == cme[ix].chan && two_bits == cme[ix].two_bit){
Reg& _reg = regs->regs[map.reg];
_reg &= ~ (0xf << map.shl);
_reg |= cme[ix].pattern << map.shl;
_reg |= 1 << MAP_EN_BIT;
return 1;
}
}
printf("WARNING: unable to match %s %d %d\n", mapping, chx, two_bits);
return 0;
}
}
int Ads5294::getMap(const char* mapping)
{
if (strcmp(mapping, MAP_ALL) == 0){
for (unsigned imap = 0; imap < NMAPLUT; ++imap){
printMap(imap);
}
}else{
printMap(lookupMap(mapping));
}
return 0;
}
Ads5294::PllRange Ads5294::pllRanges[4][4] = {
/* Decimation 1 */
{
{ 28, 9999, 0x0240 },
{ 18, 42, 0x0140 },
{ 9, 24, 0x00C0 },
{ 0, 12, 0x0040 },
},
/* Decimation 2 */
{
{ 56, 9999, 0x0240 },
{ 36, 80, 0x0140 },
{ 18, 48, 0x00C0 },
{ 0, 24, 0x0040 },
},
/* Decimation 4 */
{
{ 72, 9999, 0x0140 },
{ 36, 8, 0x00C0 },
{ 0, 48, 0x0040 },
},
/* Decimation 8 */
{
{ 72, 80, 0x00C0 },
{ 0, 80, 0x0040 },
},
};
int Ads5294::setPLL(struct PllRange range[], int Fs)
{
for (int ii = 0; ; ++ii){
if (Fs >= range[ii].fmin && Fs <= range[ii].fmax){
Reg& _reg = regs->regs[Ads5294Regs::RA_PLL];
_reg = range[ii].pat;
return 1;
}
if (range[ii].fmin == 0){
break;
}
}
printf("ERROR: range match NOT FOUND\n");
return 0;
}
int Ads5294::setPLL(int Fs, int decimation)
{
switch(decimation){
case 8:
return setPLL(pllRanges[3], Fs);
case 4:
return setPLL(pllRanges[2], Fs);
case 2:
return setPLL(pllRanges[1], Fs);
case 1:
default:
return setPLL(pllRanges[0], Fs);
}
}
int Ads5294::getPLL()
{
Reg& _reg = regs->regs[Ads5294Regs::RA_PLL];
printf("getPLL() %02x = %04x\n", Ads5294Regs::RA_PLL, _reg);
return 0;
}
int Ads5294::setTwoWireMode(bool enable)
{
Reg& _bitorder = regs->regs[Ads5294Regs::RA_BITORDER];
Reg& _wiremode = regs->regs[Ads5294Regs::RA_WIRE_MODE];
if (enable){
_bitorder = 0x8000;
_wiremode |= WIRE_MODE_2WIRE;
} else {
_bitorder = 0x0000;
_wiremode &= ~WIRE_MODE_2WIRE;
}
return 0;
}
/*
EN_SYNC = Bit 13 in register 02h
TP_HARD_SYNC = Bit 15 in register 25
*/
int Ads5294::setClkHardSync(bool enable)
{
Reg& s1 = regs->regs[Ads5294Regs::RA_EN_2];
Reg& s2 = regs->regs[Ads5294Regs::RA_TEST25];
if (enable){
s1 |= RA_2_EN_SYNC;
s2 |= TP_HARD_SYNC;
} else {
s1 &= ~RA_2_EN_SYNC;
s2 &= ~TP_HARD_SYNC;
}
return 0;
}