1 //
2 // Copyright 2017 Ettus Research, a National Instruments Company
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #include "ad937x_config_t.hpp"
8 #include "ad937x_default_config.hpp"
9 
10 const int16_t ad937x_config_t::DEFAULT_TX_FIR[DEFAULT_TX_FIR_SIZE] = {-94,
11     -26,
12     282,
13     177,
14     -438,
15     -368,
16     756,
17     732,
18     -1170,
19     -1337,
20     1758,
21     2479,
22     -2648,
23     -5088,
24     4064,
25     16760,
26     16759,
27     4110,
28     -4881,
29     -2247,
30     2888,
31     1917,
32     -1440,
33     -1296,
34     745,
35     828,
36     -358,
37     -474,
38     164,
39     298,
40     -16,
41     -94};
42 
43 const int16_t ad937x_config_t::DEFAULT_TX_FIR_15366[DEFAULT_TX_FIR_SIZE] = {4,
44     -16,
45     -5,
46     75,
47     -13,
48     -229,
49     85,
50     547,
51     -293,
52     -1158,
53     738,
54     2290,
55     -1640,
56     -4805,
57     3687,
58     17108,
59     17108,
60     3687,
61     -4805,
62     -1640,
63     2290,
64     738,
65     -1158,
66     -293,
67     547,
68     85,
69     -229,
70     -13,
71     75,
72     -5,
73     -16,
74     4};
75 
76 const int16_t ad937x_config_t::DEFAULT_RX_FIR[DEFAULT_RX_FIR_SIZE] = {-20,
77     6,
78     66,
79     22,
80     -128,
81     -54,
82     240,
83     126,
84     -402,
85     -248,
86     634,
87     444,
88     -956,
89     -756,
90     1400,
91     1244,
92     -2028,
93     -2050,
94     2978,
95     3538,
96     -4646,
97     -7046,
98     9536,
99     30880,
100     30880,
101     9536,
102     -7046,
103     -4646,
104     3538,
105     2978,
106     -2050,
107     -2028,
108     1244,
109     1400,
110     -756,
111     -956,
112     444,
113     634,
114     -248,
115     -402,
116     126,
117     240,
118     -54,
119     -128,
120     22,
121     66,
122     6,
123     -20};
124 
125 const int16_t ad937x_config_t::DEFAULT_RX_FIR_15366[DEFAULT_RX_FIR_SIZE] = {-16,
126     -22,
127     18,
128     74,
129     24,
130     -132,
131     -152,
132     132,
133     372,
134     38,
135     -598,
136     -474,
137     638,
138     1178,
139     -206,
140     -1952,
141     -984,
142     2362,
143     3152,
144     -1612,
145     -6544,
146     -2164,
147     12806,
148     26836,
149     26836,
150     12806,
151     -2164,
152     -6544,
153     -1612,
154     3152,
155     2362,
156     -984,
157     -1952,
158     -206,
159     1178,
160     638,
161     -474,
162     -598,
163     38,
164     372,
165     132,
166     -152,
167     -132,
168     24,
169     74,
170     18,
171     -22,
172     -16};
173 
174 const int16_t ad937x_config_t::DEFAULT_OBSRX_FIR[DEFAULT_RX_FIR_SIZE] = {-14,
175     -19,
176     44,
177     41,
178     -89,
179     -95,
180     175,
181     178,
182     -303,
183     -317,
184     499,
185     527,
186     -779,
187     -843,
188     1184,
189     1317,
190     -1781,
191     -2059,
192     2760,
193     3350,
194     -4962,
195     -7433,
196     9822,
197     32154,
198     32154,
199     9822,
200     -7433,
201     -4962,
202     3350,
203     2760,
204     -2059,
205     -1781,
206     1317,
207     1184,
208     -843,
209     -779,
210     527,
211     499,
212     -317,
213     -303,
214     178,
215     175,
216     -95,
217     -89,
218     41,
219     44,
220     -19,
221     -14};
222 
223 const int16_t ad937x_config_t::DEFAULT_OBSRX_FIR_15366[DEFAULT_RX_FIR_SIZE] = {-2,
224     3,
225     12,
226     -19,
227     -28,
228     44,
229     74,
230     -92,
231     -169,
232     150,
233     353,
234     -203,
235     -671,
236     203,
237     1179,
238     -66,
239     -1952,
240     -347,
241     3153,
242     1307,
243     -5595,
244     -4820,
245     11323,
246     29525,
247     29525,
248     11323,
249     -4820,
250     -5595,
251     1307,
252     3153,
253     -347,
254     -1952,
255     -66,
256     1179,
257     203,
258     -671,
259     -203,
260     353,
261     150,
262     -169,
263     -92,
264     74,
265     44,
266     -28,
267     -19,
268     12,
269     3,
270     -2};
271 
272 const int16_t ad937x_config_t::DEFAULT_SNIFFER_FIR[DEFAULT_RX_FIR_SIZE] = {-1,
273     -5,
274     -14,
275     -23,
276     -16,
277     24,
278     92,
279     137,
280     80,
281     -120,
282     -378,
283     -471,
284     -174,
285     507,
286     1174,
287     1183,
288     98,
289     -1771,
290     -3216,
291     -2641,
292     942,
293     7027,
294     13533,
295     17738,
296     17738,
297     13533,
298     7027,
299     942,
300     -2641,
301     -3216,
302     -1771,
303     98,
304     1183,
305     1174,
306     507,
307     -174,
308     -471,
309     -378,
310     -120,
311     80,
312     137,
313     92,
314     24,
315     -16,
316     -23,
317     -14,
318     -5,
319     -1};
320 
321 const int16_t ad937x_config_t::DEFAULT_SNIFFER_FIR_15366[DEFAULT_RX_FIR_SIZE] = {10,
322     31,
323     59,
324     71,
325     30,
326     -92,
327     -283,
328     -456,
329     -466,
330     -175,
331     440,
332     1192,
333     1683,
334     1444,
335     198,
336     -1871,
337     -3988,
338     -4942,
339     -3512,
340     958,
341     8118,
342     16519,
343     23993,
344     28395,
345     28395,
346     23993,
347     16519,
348     8118,
349     958,
350     -3512,
351     -4942,
352     -3988,
353     -1871,
354     198,
355     1444,
356     1683,
357     1192,
358     440,
359     -175,
360     -466,
361     -456,
362     -283,
363     -92,
364     30,
365     71,
366     59,
367     31,
368     10};
369 
ad937x_config_t(spiSettings_t * sps,const size_t deserializer_lane_xbar)370 ad937x_config_t::ad937x_config_t(spiSettings_t* sps, const size_t deserializer_lane_xbar)
371     : _rx(DEFAULT_RX_SETTINGS)
372     , _rxProfile(DEFAULT_RX_PROFILE)
373     , _framer(DEFAULT_FRAMER)
374     , _rxGainCtrl(DEFAULT_RX_GAIN)
375     , _rxPeakAgc(DEFAULT_RX_PEAK_AGC)
376     , _rxPowerAgc(DEFAULT_RX_POWER_AGC)
377     , _rxAgcCtrl(DEFAULT_RX_AGC_CTRL)
378     ,
379 
380     _tx(DEFAULT_TX_SETTINGS)
381     , _txProfile(DEFAULT_TX_PROFILE)
382     , _deframer(DEFAULT_DEFRAMER)
383     ,
384     // TODO: Remove if ADI ever fixes this
385     // The TX bring up requires a valid ORX profile
386     // https://github.com/EttusResearch/uhddev/blob/f0f8f58471c3fed94279c32f00e9f8da7db40efd/mpm/lib/mykonos/adi/mykonos.c#L16590
387 
388     _obsRx(DEFAULT_ORX_SETTINGS)
389     , _orxFramer(DEFAULT_ORX_FRAMER)
390     , _orxProfile(DEFAULT_ORX_PROFILE)
391     , _orxGainCtrl(DEFAULT_ORX_GAIN)
392     , _orxPeakAgc(DEFAULT_ORX_PEAK_AGC)
393     , _orxPowerAgc(DEFAULT_ORX_POWER_AGC)
394     , _orxAgcCtrl(DEFAULT_ORX_AGC_CTRL)
395     ,
396 
397     // TODO: Remove if ADI ever fixes this
398     // ORX bring up requires a valid sniffer gain control struct
399     // https://github.com/EttusResearch/uhddev/blob/f0f8f58471c3fed94279c32f00e9f8da7db40efd/mpm/lib/mykonos/adi/mykonos.c#L5752
400 
401     _snifferGainCtrl(DEFAULT_SNIFFER_GAIN)
402     ,
403 
404     _armGpio(DEFAULT_ARM_GPIO)
405     , _gpio3v3(DEFAULT_GPIO_3V3)
406     , _gpio(DEFAULT_GPIO)
407     ,
408 
409     _auxIo(DEFAULT_AUX_IO)
410     , _clocks(DEFAULT_CLOCKS)
411     ,
412 
413     tx_fir_config(DEFAULT_TX_FIR_GAIN,
414         std::vector<int16_t>(DEFAULT_TX_FIR, DEFAULT_TX_FIR + DEFAULT_TX_FIR_SIZE))
415     , rx_fir_config(DEFAULT_RX_FIR_GAIN,
416           std::vector<int16_t>(DEFAULT_RX_FIR, DEFAULT_RX_FIR + DEFAULT_RX_FIR_SIZE))
417     , _orx_fir_config(DEFAULT_RX_FIR_GAIN,
418           std::vector<int16_t>(
419               DEFAULT_OBSRX_FIR, DEFAULT_OBSRX_FIR + DEFAULT_RX_FIR_SIZE))
420     , _sniffer_rx_fir_config(DEFAULT_RX_FIR_GAIN,
421           std::vector<int16_t>(
422               DEFAULT_SNIFFER_FIR, DEFAULT_SNIFFER_FIR + DEFAULT_RX_FIR_SIZE))
423 {
424     _device.spiSettings                = sps;
425     _deframer.deserializerLaneCrossbar = deserializer_lane_xbar;
426 
427     _init_pointers();
428 
429     device = &_device;
430 }
431 
432 // This function sets up all the pointers in all of our local members that represent the
433 // device struct This function should only be called during construction.
_init_pointers()434 void ad937x_config_t::_init_pointers()
435 {
436     _device.rx     = &_rx;
437     _device.tx     = &_tx;
438     _device.obsRx  = &_obsRx;
439     _device.auxIo  = &_auxIo;
440     _device.clocks = &_clocks;
441 
442     _rx.rxProfile               = &_rxProfile;
443     _rx.framer                  = &_framer;
444     _rx.rxGainCtrl              = &_rxGainCtrl;
445     _rx.rxAgcCtrl               = &_rxAgcCtrl;
446     _rxProfile.rxFir            = rx_fir_config.fir;
447     _rxProfile.customAdcProfile = nullptr;
448     _rxAgcCtrl.peakAgc          = &_rxPeakAgc;
449     _rxAgcCtrl.powerAgc         = &_rxPowerAgc;
450 
451     _tx.txProfile    = &_txProfile;
452     _txProfile.txFir = tx_fir_config.fir;
453     _tx.deframer     = &_deframer;
454 
455     // AD9373
456     _tx.dpdConfig  = nullptr;
457     _tx.clgcConfig = nullptr;
458     _tx.vswrConfig = nullptr;
459 
460     // TODO: ideally we set none of this information and leave the profile as nullptr
461     // Check that the API supports this
462     _obsRx.orxProfile            = &_orxProfile;
463     _obsRx.orxGainCtrl           = &_orxGainCtrl;
464     _obsRx.orxAgcCtrl            = &_orxAgcCtrl;
465     _orxProfile.rxFir            = _orx_fir_config.fir;
466     _orxProfile.customAdcProfile = nullptr;
467     _orxAgcCtrl.peakAgc          = &_orxPeakAgc;
468     _orxAgcCtrl.powerAgc         = &_orxPowerAgc;
469 
470     _obsRx.snifferProfile  = &_snifferProfile;
471     _snifferProfile.rxFir  = _sniffer_rx_fir_config.fir;
472     _obsRx.snifferGainCtrl = &_snifferGainCtrl;
473     // sniffer has no AGC ctrl, so leave as null
474     _obsRx.framer = &_orxFramer;
475 
476     _auxIo.gpio3v3 = &_gpio3v3;
477     _auxIo.gpio    = &_gpio;
478     _auxIo.armGpio = &_armGpio;
479 }
480