-
Notifications
You must be signed in to change notification settings - Fork 28
/
LimeSuite_Build_Thunk.h
1262 lines (1145 loc) · 44.6 KB
/
LimeSuite_Build_Thunk.h
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 lime/LimeSuite.h
*
* @brief LMS API library
*
* Copyright (C) 2016 Lime Microsystems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LMS7_API_H
#define LMS7_API_H
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#else
/* stdbool.h is not applicable for C++ programs, as the language inherently
* provides the bool type.
*
* Users of Visual Studio 2012 and earlier will need to supply a stdbool.h
* implementation, as it is not included with the toolchain. Visual Studio 2013
* onward supplies this header.
*/
#include <stdbool.h>
#endif
#if defined _WIN32 || defined __CYGWIN__
# include <windows.h>
# define CALL_CONV __cdecl
# ifdef __GNUC__
# define API_EXPORT __attribute__ ((dllexport))
# else
# define API_EXPORT __declspec(dllexport)
# endif
#elif defined _DOXYGEN_ONLY_
/** Marks an API routine to be made visible to the dynamic loader.
* This is OS and/or compiler-specific. */
# define API_EXPORT
/** Specifies calling convention, if necessary.
* This is OS and/or compiler-specific. */
# define CALL_CONV
#else
# define API_EXPORT __attribute__ ((visibility ("default")))
# define CALL_CONV
#endif
///Floating point data type
typedef double float_type;
///convenience constant for good return code
static const int LMS_SUCCESS = 0;
/**
* @defgroup FN_INIT Initialization/deinitialization
*
* The functions in this section provide the ability to query available devices,
* initialize them, and deinitialize them.
* @{
*/
///LMS Device handle
typedef void lms_device_t;
///Convenience type for fixed length LMS Device information string
typedef char lms_info_str_t[256];
/**
* Obtain a list of LMS devices attached to the system
*
* @param[out] dev_list List of available devices
*
* @return number of devices in the list on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetDeviceList(lms_info_str_t *dev_list);
/**
* Opens device specified by the provided ::lms_info_str_t string
* This function should be used to open a device based upon the results of
* LMS_GetDeviceList()
*
* @pre device should be initialized to NULL
*
* @param[out] device Updated with device handle on success
* @param[in] info Device information string. If NULL, the first
* available device will be opened.
* @param[in] args additional arguments. Can be NULL.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_Open(lms_device_t **device, const lms_info_str_t info,
void* args);
/**
* Close device
*
* @post device is deallocated and may no longer be used.
*
* @param device Device handle previously obtained by LMS_Open().
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_Close(lms_device_t *device);
/**
* Disconnect device but keep configuration cache (device is not deallocated).
*
* @param device Device handle previously obtained by LMS_Open().
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_Disconnect(lms_device_t *device);
/**
* Check if device port is opened
*
* @param device Device handle previously obtained by LMS_Open().
* @param port port index (ignored if device has only 1 port)
*
* @return true(1) if port is open, false (0) if - closed
*/
API_EXPORT bool CALL_CONV LMS_IsOpen(lms_device_t *device, int port);
/** @} (End FN_INIT) */
/**
* @defgroup FN_HIGH_LVL High-level control functions
*
* The functions in this section provide the ability to easily configure the
* device for operation.
*
* @{
*/
static const bool LMS_CH_TX = true; ///<Convenience constants for TX selection
static const bool LMS_CH_RX = false; ///<Convenience constants for RX selection
/** Convenience type for fixed length name string*/
typedef char lms_name_t[16];
/**Structure used to represent the allowed value range of various parameters*/
typedef struct
{
float_type min; ///<Minimum allowed value
float_type max; ///<Minimum allowed value
float_type step; ///<Minimum value step
}lms_range_t;
/**Enumeration of LMS7 TEST signal types*/
typedef enum
{
LMS_TESTSIG_NONE=0, ///<Disable test signals. Return to normal operation
LMS_TESTSIG_NCODIV8, ///<Test signal from NCO half scale
LMS_TESTSIG_NCODIV4, ///<Test signal from NCO half scale
LMS_TESTSIG_NCODIV8F, ///<Test signal from NCO full scale
LMS_TESTSIG_NCODIV4F, ///<Test signal from NCO full scale
LMS_TESTSIG_DC ///<DC test signal
}lms_testsig_t;
/**
* Configure LMS chip with settings that make it ready for operation.
*
* @note This configuration differs from default LMS chip configuration which is
* described in chip datasheet. In order to load default chip configuration use
* LMS_Reset().
*
* @param[in] device Device handle previously obtained by LMS_Open().
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_Init(lms_device_t *device);
/**
* Obtain number of RX or TX channels. Use this to determine the maximum
* channel index (specifying channel index is required by most API functions).
* The maximum channel index is N-1, where N is number returned by this function
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
*
* @return Number of channels on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetNumChannels(lms_device_t *device, bool dir_tx);
/**
* Enable or disable specified RX channel.
*
* @param[in] device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param enabled true(1) to enable, false(0) to disable.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_EnableChannel(lms_device_t *device, bool dir_tx,
size_t chan, bool enabled);
/**
* Set sampling rate for all RX/TX channels. Sample rate is in complex samples
* (1 sample = I + Q). The function sets sampling rate that is used for data
* exchange with the host. It also allows to specify higher sampling rate to be
* used in RF by setting oversampling ratio. Valid oversampling values are 1, 2,
* 4, 8, 16, 32 or 0 (use device default oversampling value).
*
* @param[in] device Device handle previously obtained by LMS_Open().
* @param rate sampling rate in Hz to set
* @param oversample RF oversampling ratio.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetSampleRate(lms_device_t *device, float_type rate,
size_t oversample);
/**
* Get the sampling rate of the specified RX or TX channel.
* The function obtains the sample rate used in data interface with the host and
* the RF sample rate used by DAC/ADC.
*
* @param[in] device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param[out] host_Hz sampling rate used for data exchange with the host
* @param[out] rf_Hz RF sampling rate in Hz
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetSampleRate(lms_device_t *device, bool dir_tx,
size_t chan, float_type *host_Hz, float_type *rf_Hz);
/**
* Get the range of supported sampling rates.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param[out] range Allowed sample rate range in Hz.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetSampleRateRange(lms_device_t *device, bool dir_tx,
lms_range_t *range);
/**
* Set RF center frequency in Hz.
*
* @note setting different frequencies for A and B channels is not supported by
* LMS7 chip. Changing frequency for one (A or B) channel will result in
* frequency being changed for both (A and B) channels.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param frequency Desired RF center frequency in Hz
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetLOFrequency(lms_device_t *device, bool dir_tx,
size_t chan, float_type frequency);
/**
* Obtain the current RF center frequency in Hz.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param[out] frequency Current RF center frequency in Hz
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetLOFrequency(lms_device_t *device, bool dir_tx,
size_t chan, float_type *frequency);
/**
* Obtain the supported RF center frequency range in Hz.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param[out] range Supported RF center frequency in Hz
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetLOFrequencyRange(lms_device_t *device, bool dir_tx,
lms_range_t *range);
/**
* Obtain antenna list with names. First item in the list is the name of antenna
* index 0.
*
* @param dev Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan channel index
* @param[out] list List of antenna names (can be NULL)
*
* @return number of available antennae, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetAntennaList(lms_device_t *dev, bool dir_tx,
size_t chan, lms_name_t *list);
/**
* Select the antenna for the specified RX or TX channel.
*
* @param dev Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan channel index
* @param index Index of antenna to select
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetAntenna(lms_device_t *dev, bool dir_tx,
size_t chan, size_t index);
/**
* Obtain currently selected antenna of the the specified RX or TX channel.
*
* @param dev Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan channel index
*
* @return Index of selected antenna on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetAntenna(lms_device_t *dev, bool dir_tx,
size_t chan);
/**
* Obtains bandwidth (lower and upper frequency) of the specified antenna
*
* @param dev Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan channel index
* @param index Antenna index
* @param[out] range Antenna bandwidth
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetAntennaBW(lms_device_t *dev, bool dir_tx,
size_t chan, size_t index, lms_range_t *range);
/**
* Set the combined gain value
* This function computes and sets the optimal gain values of various amplifiers
* that are present in the device based on desired normalized gain value.
*
* @note actual gain depends on LO frequency and analog LPF configuration and
* resulting output signal level may be different when those values are changed
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param gain Desired gain, range [0, 1.0], where 1.0 represents the
* maximum gain
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetNormalizedGain(lms_device_t *device, bool dir_tx,
size_t chan,float_type gain);
/**
* Set the combined gain value in dB
* This function computes and sets the optimal gain values of various amplifiers
* that are present in the device based on desired gain value in dB.
*
* @note actual gain depends on LO frequency and analog LPF configuration and
* resulting output signal levle may be different when those values are changed
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param gain Desired gain, range [0, 70] for RX, [0, 60] for TX
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetGaindB(lms_device_t *device, bool dir_tx,
size_t chan, unsigned gain);
/**
* Obtain the current combined gain value
*
* @note actual gain depends on LO frequency and analog LPF configuration and
* resulting output signal level may be different when those values are changed
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param[out] gain Current gain, range [0, 1.0], where 1.0 represents
* the maximum gain
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetNormalizedGain(lms_device_t *device, bool dir_tx,
size_t chan, float_type *gain);
/**
* Obtain the current combined gain value in dB
*
* @note actual gain depends on LO frequency and analog LPF configuration and
* resulting output signal level may be different when those values are changed
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param[out] gain Current gain, range [0, 70], [0, 60] for TX
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetGaindB(lms_device_t *device, bool dir_tx,
size_t chan, unsigned *gain);
/**
* Configure analog LPF of the LMS chip for the desired RF bandwidth.
* This function automatically enables LPF.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param bandwidth LPF bandwidth in Hz
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetLPFBW(lms_device_t *device, bool dir_tx,
size_t chan, float_type bandwidth);
/**
* Get the currently configured analog LPF RF bandwidth.
* @note readback from board is currently not supported, only returns last set
* value cached by software.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param[out] bandwidth Current LPF bandwidth in Hz
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetLPFBW(lms_device_t *device, bool dir_tx,
size_t chan, float_type *bandwidth);
/**
* Get the RF bandwidth setting range supported by the analog LPF of LMS chip.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param[out] range Supported RF bandwidth range in Hz
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetLPFBWRange(lms_device_t *device, bool dir_tx,
lms_range_t *range);
/**
* Disables or enables the analog LPF of LMS chip without reconfiguring it.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param enable true(1) to enable, false(0) to disable
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetLPF(lms_device_t *device, bool dir_tx,
size_t chan, bool enable);
/**
* Set up digital LPF using LMS chip GFIRS. This is a convenience function to
* quickly configure GFIRS as LPF with desired RF bandwidth.
*
* @pre sampling rate must be set
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan channel index
* @param enabled Disable (false) or enable (true) GFIRS.
* @param bandwidth LPF bandwidth in Hz. Has no effect if enabled is false.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetGFIRLPF(lms_device_t *device, bool dir_tx,
size_t chan, bool enabled, float_type bandwidth);
/**
* Perform the automatic calibration of specified RX/TX channel. The automatic
* calibration must be run after device configuration is finished because
* calibration values are dependant on various configuration settings.
*
* @pre Device should be configured
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan channel index
* @param bw bandwidth
* @param flags additional calibration flags (normally should be 0)
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_Calibrate(lms_device_t *device, bool dir_tx,
size_t chan, double bw, unsigned flags);
/**
* Load LMS chip configuration from a file
*
* @note this only loads LMS chip configuration, in oder for streaming to work
* properly FPGA has also to be configured. Use LMS_SetSampleRate() to configure
* LMS and FPGA for streaming.
*
* @param device Device handle
* @param filename path to file
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_LoadConfig(lms_device_t *device, const char *filename);
/**
* Save LMS chip configuration to a file
*
* @param device Device handle
* @param filename path to file with LMS chip configuration
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SaveConfig(lms_device_t *device, const char *filename);
/**
* Apply the specified test signal
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX.
* @param chan Channel index.
* @param sig Test signal. LMS_TESTSIG_NONE disables test signal.
* @param dc_i DC I value for LMS_TESTSIG_DC mode. Ignored in other modes.
* @param dc_q DC Q value for LMS_TESTSIG_DC mode. Ignored in other modes.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetTestSignal(lms_device_t *device, bool dir_tx,
size_t chan, lms_testsig_t sig, int16_t dc_i, int16_t dc_q);
/**
* Get the currently active test signal
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param sig Currently active test signal
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetTestSignal(lms_device_t *device, bool dir_tx,
size_t chan, lms_testsig_t *sig);
/** @} (End FN_HIGH_LVL) */
/**
* @defgroup FN_ADVANCED Advanced control functions
*
* The functions in this section provides some additional control compared to
* High-Level functions. They are labeled advanced because they require better
* understanding of hardware and provide functionality that may conflict with
* certain High-Level functions.
* @{
*/
///Enumeration of LMS7 GFIRS
typedef enum
{
LMS_GFIR1 = 0,
LMS_GFIR2,
LMS_GFIR3
}lms_gfir_t;
///Number of NCO frequency/phase offset values
static const int LMS_NCO_VAL_COUNT = 16;
/**
* Set sampling rate for all RX or TX channels. Sample rate is in complex
* samples (1 sample = I + Q). The function sets sampling rate that is used for
* data exchange with the host. It also allows to specify higher sampling rate
* to be used in RF by setting oversampling ratio. Valid oversampling values are
* 1, 2, 4, 8, 16, 32 or 0 (use device default oversampling value).
*
* @note RX and TX rates sampling are closely tied in LMS7 chip. Changing RX or
* TX will often result in change of both (RX and TX). RX/TX ratio can only be
* power of 2 and is also limited by other factors. Use LMS_GetSampleRate() to
* obtain actual sample rate values. The function returns success if it is able
* to achieve desired sample rate and oversampling for the specified direction
* (RX or TX) ignoring possible value changes in other direction channels.
*
* @param[in] device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param rate Sampling rate in Hz to set
* @param oversample RF oversampling ratio.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetSampleRateDir(lms_device_t *device, bool dir_tx,
float_type rate, size_t oversample);
/**
* Configure NCO to operate in FCW mode. Configures NCO with up to 16
* frequencies that can be quickly switched between.
* Automatically starts NCO with frequency at index 0
* Use LMS_SetNCOindex() to switch between NCO frequencies.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param[in] freq List of NCO frequencies. Values cannot be negative.
* Must be at least ::LMS_NCO_VAL_COUNT length;
* @param pho NCO phase offset in deg
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetNCOFrequency(lms_device_t *device, bool dir_tx,
size_t chan, const float_type *freq, float_type pho);
/**
* Get the current NCO FCW mode configuration.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param[out] freq List of NCO frequencies. Must be at least
* ::LMS_NCO_VAL_COUNT length;
* @param[out] pho Phase offset in deg
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetNCOFrequency(lms_device_t *device, bool dir_tx,
size_t chan, float_type *freq, float_type *pho);
/**
* Configure NCO to operate in PHO mode. Configures NCO with up to 16
* phase offsets that can be quickly switched between.
* Automatically starts NCO with phase at index 0
* Use LMS_SetNCOindex() to switch between NCO phases.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param[in] phases List of NCO phases. Values cannot be negative.
* Must be at least ::LMS_NCO_VAL_COUNT length;
* @param fcw NCO frequency in Hz
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetNCOPhase(lms_device_t *device, bool dir_tx,
size_t chan, const float_type *phases, float_type fcw);
/**
* Get the current NCO PHO mode configuration.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan channel index
* @param[out] phases List of configured NCO phases
* Must be at least ::LMS_NCO_VAL_COUNT length;
* @param[out] fcw Current NCO frequency
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetNCOPhase(lms_device_t *device, bool dir_tx,
size_t chan, float_type *phases, float_type *fcw);
/**
* Switches between configured list of NCO frequencies/phase offsets. Also
* Allows to switch CMIX mode to either downconvert or upconvert.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan channel index
* @param index NCO frequency/phase index to activate or (-1) to disable NCO
* @param downconv true(1) CMIX downconvert, false(0) CMIX upconvert
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetNCOIndex(lms_device_t *device, bool dir_tx,
size_t chan, int index, bool downconv);
/**
* Get the currently active NCO frequency/phase offset index
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
*
* @return Current NCO frequency/phase index on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetNCOIndex(lms_device_t *device, bool dir_tx,
size_t chan);
/**
* Configure LMS GFIR using specified filter coefficients. Maximum number of
* coefficients is 40 for GFIR1 and GFIR2, and 120 for GFIR3.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param filt GFIR to configure
* @param[in] coef Array of filter coefficients. Coeff range [-1.0, 1.0].
* @param count number of filter coefficients.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetGFIRCoeff(lms_device_t * device, bool dir_tx,
size_t chan, lms_gfir_t filt, const float_type* coef,size_t count);
/**
* Get currently set GFIR coefficients.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param filt GFIR to configure
* @param[out] coef Current GFIR coefficients. Array must be big enough to
* hold 40 (GFIR1, GFIR2) or 120 (GFIR3) values.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetGFIRCoeff(lms_device_t * device, bool dir_tx,
size_t chan, lms_gfir_t filt, float_type* coef);
/**
* Enables or disables specified GFIR.
*
* @param device Device handle previously obtained by LMS_Open().
* @param dir_tx Select RX or TX
* @param chan Channel index
* @param filt GFIR to configure
* @param enabled true(1) enable, false(0) disable.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetGFIR(lms_device_t * device, bool dir_tx,
size_t chan, lms_gfir_t filt, bool enabled);
/**
* Write value to VCTCXO trim DAC. Used to adjust/calibrate reference clock
* generated by voltage controlled oscillator.
* @note calling this functions switches clock source to VCTCXO
*
* @param dev Device handle previously obtained by LMS_Open().
* @param val Value to write to VCTCXO trim DAC, range 0-255
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_VCTCXOWrite(lms_device_t * dev, uint16_t val);
/**
* Read value from VCTCXO trim DAC.
*
* @param[in] dev Device handle previously obtained by LMS_Open().
* @param[out] val Value to read from VCTCXO trim DAC
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_VCTCXORead(lms_device_t * dev, uint16_t *val);
/** @} (End FN_ADVANCED) */
/**
* @defgroup FN_LOW_LVL Low-Level control functions
* @{
*/
/**
* Send Reset signal to LMS chip. This initializes LMS chip with default
* configuration as described in LMS chip datasheet.
*
* @param device Device handle previously obtained by LMS_Open().
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_Reset(lms_device_t *device);
/**
* Read device LMS chip register
*
* @param device Device handle previously obtained by LMS_Open().
* @param address Register address
* @param val Current register value
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_ReadLMSReg(lms_device_t *device, uint32_t address,
uint16_t *val);
/**
* Write device LMS chip register
*
* @param device Device handle previously obtained by LMS_Open().
* @param address Register address
* @param val Value to write
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_WriteLMSReg(lms_device_t *device, uint32_t address,
uint16_t val);
/**
* Read device FPGA register
*
* @param device Device handle previously obtained by LMS_Open().
* @param address Register address
* @param val Current register value
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_ReadFPGAReg(lms_device_t *device, uint32_t address,
uint16_t *val);
/**
* Write device FPGA register
*
* @param device Device handle previously obtained by LMS_Open().
* @param address Register address
* @param val Value to write
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_WriteFPGAReg(lms_device_t *device, uint32_t address,
uint16_t val);
/**
* Read custom parameter from board
*
* @param device Device handle previously obtained by LMS_Open().
* @param id Parameter identifier
* @param val Current register value
* @param units [optional] measurement units of parameter if available
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_ReadCustomBoardParam(lms_device_t *device,
uint8_t id, float_type *val, lms_name_t units);
/**
* Write custom parameter from board
*
* @param device Device handle previously obtained by LMS_Open().
* @param id Parameter identifier
* @param val Value to write
* @param units [optional] measurement units of parameter if available
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_WriteCustomBoardParam(lms_device_t *device,
uint8_t id, float_type val, const lms_name_t units);
/**
* @defgroup LMS_CLOCK_ID Clock definitions
*
* Clock definitions for accessing specific internal clocks
* @{
*/
#define LMS_CLOCK_REF 0x0000 ///<Chip reference clock
#define LMS_CLOCK_SXR 0x0001 ///<RX LO clock
#define LMS_CLOCK_SXT 0x0002 ///<TX LO clock
#define LMS_CLOCK_CGEN 0x0003 ///<CGEN clock
#define LMS_CLOCK_RXTSP 0x0004 ///<RXTSP reference clock
#define LMS_CLOCK_TXTSP 0x0005 ///<TXTSP reference clock
#define LMS_CLOCK_EXTREF 0x0006 ///<External reference clock
/** @} (End LMS_CLOCK_ID) */
/**
* Get frequency of the specified clock.
*
* @param dev Device handle previously obtained by LMS_Open().
* @param clk_id Clock identifier
* @param freq Clock frequency in Hz
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetClockFreq(lms_device_t *dev, size_t clk_id,
float_type *freq);
/**
* Set frequency of the specified clock
*
* @note setting ::LMS_CLOCK_EXTREF changes clock source to external, use
* ::LMS_VCTCXOWrite() to change back to VCTCXO
*
* @param dev Device handle previously obtained by LMS_Open().
* @param clk_id Clock identifier
* @param freq Clock frequency in Hz. Pass zero or negative value to only
* perform tune (if supported) without recalculating values
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_SetClockFreq(lms_device_t *dev, size_t clk_id,
float_type freq);
/**
* Synchronizes register values between API cache and chip
*
* @param dev Device handle previously obtained by LMS_Open().
* @param toChip if true copies values from API cache to chip.
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_Synchronize(lms_device_t *dev, bool toChip);
/**
* @param dev Device handle previously obtained by LMS_Open().
* @param[in] buffer read values (8 GPIO values per byte, LSB first)
* @param len number of bytes to read
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GPIORead(lms_device_t *dev, uint8_t* buffer, size_t len);
/**
* @param dev Device handle previously obtained by LMS_Open().
* @param[out] buffer values to write (8 GPIO values per byte, LSB first)
* @param len number of bytes to write
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GPIOWrite(lms_device_t *dev, const uint8_t* buffer, size_t len);
/**
* @param dev Device handle previously obtained by LMS_Open().
* @param[out] buffer GPIO direction configuration(8 GPIO per byte, LSB first; 0 input, 1 output)
* @param len number of bytes to read
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GPIODirRead(lms_device_t *dev, uint8_t* buffer, size_t len);
/**
* @param dev Device handle previously obtained by LMS_Open().
* @param[in] buffer GPIO direction configuration(8 GPIO per byte, LSB first; 0 input, 1 output)
* @param len number of bytes to write
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GPIODirWrite(lms_device_t *dev, const uint8_t* buffer, size_t len);
/**
* Enables or disable caching of calibration values.
*
* @param dev Device handle previously obtained by LMS_Open().
* @param enable true to enable cache
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_EnableCalibCache(lms_device_t *dev, bool enable);
/**
* Read LMS7 chip internal temperature sensor
*
* @param dev Device handle previously obtained by LMS_Open().
* @param ind chip index
* @param temp temperature value
*
* @return 0 on success, (-1) on failure
*/
API_EXPORT int CALL_CONV LMS_GetChipTemperature(lms_device_t *dev, size_t ind,
float_type *temp);
/** @} (End FN_LOW_LVL) */
/**
* @defgroup FN_STREAM Sample Streaming functions
* The functions in this section provides support for sending and receiving
* IQ data samples.
* @{
*/
/**Metadata structure used in sample transfers*/
typedef struct
{
/**
* Timestamp is a value of HW counter with a tick based on sample rate.
* In RX: time when the first sample in the returned buffer was received
* In TX: time when the first sample in the submitted buffer should be send
*/
uint64_t timestamp;
/**In TX: wait for the specified HW timestamp before broadcasting data over
* the air
* In RX: wait for the specified HW timestamp before starting to receive
* samples
*/
bool waitForTimestamp;
/**Indicates the end of send/receive transaction. Currently has no effect
* @todo force send samples to HW (ignore transfer size) when selected
*/
bool flushPartialPacket;
}lms_stream_meta_t;
/**Stream structure*/
typedef struct
{
/**
* Stream handle. Should not be modified manually.