/
libbladeRF.h
2695 lines (2417 loc) · 87 KB
/
libbladeRF.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 libbladeRF.h
*
* @brief bladeRF library
*
* Copyright (C) 2013 Nuand LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef BLADERF_H_
#define BLADERF_H_
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#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
/**
* @defgroup RETCODES Error codes
*
* bladeRF library routines return negative values to indicate errors.
* Values >= 0 are used to indicate success.
*
* @code
* int status = bladerf_set_txvga1(dev, 2);
*
* if (status < 0)
* handle_error();
* @endcode
*
* @{
*/
#define BLADERF_ERR_UNEXPECTED (-1) /**< An unexpected failure occurred */
#define BLADERF_ERR_RANGE (-2) /**< Provided parameter is out of range */
#define BLADERF_ERR_INVAL (-3) /**< Invalid operation/parameter */
#define BLADERF_ERR_MEM (-4) /**< Memory allocation error */
#define BLADERF_ERR_IO (-5) /**< File/Device I/O error */
#define BLADERF_ERR_TIMEOUT (-6) /**< Operation timed out */
#define BLADERF_ERR_NODEV (-7) /**< No device(s) available */
#define BLADERF_ERR_UNSUPPORTED (-8) /**< Operation not supported */
#define BLADERF_ERR_MISALIGNED (-9) /**< Misaligned flash access */
#define BLADERF_ERR_CHECKSUM (-10) /**< Invalid checksum */
#define BLADERF_ERR_NO_FILE (-11) /**< File not found */
#define BLADERF_ERR_UPDATE_FPGA (-12) /**< An FPGA update is required */
#define BLADERF_ERR_UPDATE_FW (-13) /**< A firmware update is requied */
/** @} (End RETCODES) */
/**
* @defgroup FN_INIT Initialization/deinitialization
*
* The functions in this section provide the ability query available devices,
* initialize them, and deinitialize them. They are not guaranteed to be
* thread-safe; the caller is responsible for ensuring they are executed
* atomically.
*
* @{
*/
/** This structure is an opaque device handle */
struct bladerf;
/**
* Backend by which the host communicates with the device
*/
typedef enum {
BLADERF_BACKEND_ANY, /**< "Don't Care" -- use any available backend */
BLADERF_BACKEND_LINUX, /**< Linux kernel driver */
BLADERF_BACKEND_LIBUSB, /**< libusb */
BLADERF_BACKEND_DUMMY = 100, /**< Dummy used for development purposes */
} bladerf_backend;
/**
* This enum describes the USB Speed at which the bladeRF is connected.
* Speeds not listed here are not supported.
*/
typedef enum {
BLADERF_DEVICE_SPEED_UNKNOWN,
BLADERF_DEVICE_SPEED_HIGH,
BLADERF_DEVICE_SPEED_SUPER,
} bladerf_dev_speed;
/** Length of device serial number string, including NUL-terminator */
#define BLADERF_SERIAL_LENGTH 33
/**
* Information about a bladeRF attached to the system
*
* See the \ref FN_DEVINFO section for information on populating and comparing
* these structures.
*/
struct bladerf_devinfo {
bladerf_backend backend; /**< Backend to use when connecting to device */
char serial[BLADERF_SERIAL_LENGTH]; /**< Device serial number string */
uint8_t usb_bus; /**< Bus # device is attached to */
uint8_t usb_addr; /**< Device address on bus */
unsigned int instance; /**< Device instance or ID */
};
/**
* Obtain a list of bladeRF devices attached to the system
*
* @param[out] devices
*
* @return number of items in returned device list, or value from
* \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_get_device_list(struct bladerf_devinfo **devices);
/**
* Free device list returned by bladerf_get_device_list()
*
* @param devices List of available devices
*/
API_EXPORT
void CALL_CONV bladerf_free_device_list(struct bladerf_devinfo *devices);
/**
* Opens device specified by provided bladerf_devinfo structure
*
* @pre devinfo has been populated via a call to bladerf_get_device_list
*
* @param[out] device Update with device handle on success
* @param[in] devinfo Device specification
*
* @return 0 on success, or value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_open_with_devinfo(struct bladerf **device,
struct bladerf_devinfo *devinfo);
/**
* Open specified device using a device identifier string
*
* The general form of the device identifier string is;
* @code
* <backend>:[device=<bus>:<addr>] [instance=<n>] [serial=<serial>]
* @endcode
*
* An empty ("") or NULL device identifier will result in the first
* encountered device being opened (using the first discovered backend)
*
* The 'backend' describes the mechanism used to communicate with the device,
* and may be one of the following:
* - libusb: libusb (See libusb changelog notes for required version, given
* your OS and controller)
* - linux: Linux Kernel Driver
*
* If no arguments are provided after the backend, the first encountered
* device on the specified backend will be opened. Note that a backend is
* required, if any arguments are to be provided.
*
* Next, any provided arguments are provide as used to find the desired device.
* Be sure not to over constrain the search. Generally, only one of the above
* is required -- providing all of these may over constrain the search for the
* desired device (e.g., if a serial number matches, but not on the specified
* bus and address.)
*
* - device=\<bus\>:\<addr\>
* - Specifies USB bus and address. Decimal or hex prefixed by '0x' is
* permitted.
* - instance=\<n\>
* - Nth instance encountered, 0-indexed (libusb)
* - Device node N, such as /dev/bladerfN (linux)
* - serial=\<serial\>
* - Device's serial number.
*
* @param[out] device Update with device handle on success
* @param[in] device_identifier Device identifier, formatted as described
* above
*
* @return 0 on success, or value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_open(struct bladerf **device,
const char *device_identifier);
/**
* Close device
*
* @note Failing to close a device will result in memory leaks.
*
* @post device is deallocated and may no longer be used.
*
* @param device Device handle previously obtained by bladerf_open(). This
* function does nothing if device is NULL.
*/
API_EXPORT
void CALL_CONV bladerf_close(struct bladerf *device);
/** @} (End FN_INIT) */
/**
* @defgroup FN_DEVINFO Device identifier information functions
*
* As the functions in this section do not operate on a device, there are no
* internal thread-safety concerns. The caller only needs to ensure the
* function parameters are not modified while these functions are executing.
*
* @{
*/
/**
* Initialize a device identifier information structure to a "wildcard" state.
* The values in each field will match any value for that field.
*
* Passing a bladerf_devinfo initialized with this function to
* bladerf_open_with_devinfo() will match the first device found.
*/
API_EXPORT
void CALL_CONV bladerf_init_devinfo(struct bladerf_devinfo *info);
/**
* Fill out a provided bladerf_devinfo structure, given an open device handle.
* This function is thread-safe.
*
* @pre dev must be a valid device handle.
*
* @param[in] dev Device handle previously obtained with bladerf_open()
* @param[out] info Device information populated by this function
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_get_devinfo(struct bladerf *dev,
struct bladerf_devinfo *info);
/**
* Populate a device identifier information structure using the provided
* device identifier string.
*
* @param[in] devstr Device identifier string, formated as described
* in the bladerf_open() documentation
*
* @param[out] info Upon success, this will be filled out according to the
* provided device identifier string, with wildcards for
* any fields that were not provided.
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_get_devinfo_from_str(const char *devstr,
struct bladerf_devinfo *info);
/**
* Test whether two device identifier information structures match, taking
* wildcard values into account.
*/
API_EXPORT
bool CALL_CONV bladerf_devinfo_matches(const struct bladerf_devinfo *a,
const struct bladerf_devinfo *b);
/**
* Test whether a provided device string matches a device described by
* the provided bladerf_devinfo structure
*
* @param[in] dev_str Devices string, formated as described in the
* the documentation of bladerf_open
*
* @param[in] info Device info to compare with
*
* @return true upon a match, false otherwise
*/
API_EXPORT
bool CALL_CONV bladerf_devstr_matches(const char *dev_str,
struct bladerf_devinfo *info);
/**
* Retrieve the backend string associated with the specified
* backend enumeration value.
*
* @warning Do not attempt to modify or free() the returned string.
*
* @return A string that can used to specify the `backend` portion of a device
* identifier string. (See bladerf_open().)
*/
API_EXPORT
const char * CALL_CONV bladerf_backend_str(bladerf_backend backend);
/** @} (End of FN_DEVINFO) */
/**
* @defgroup FN_CTRL Device control and configuration
*
* This section provides functions pertaining to accessing, controlling, and
* configuring various device options and parameters.
*
* @{
*/
/** Minimum RXVGA1 gain, in dB */
#define BLADERF_RXVGA1_GAIN_MIN 5
/** Maximum RXVGA1 gain, in dB */
#define BLADERF_RXVGA1_GAIN_MAX 30
/** Minimum RXVGA2 gain, in dB */
#define BLADERF_RXVGA2_GAIN_MIN 0
/** Maximum RXVGA2 gain, in dB */
#define BLADERF_RXVGA2_GAIN_MAX 30
/** Minimum TXVGA1 gain, in dB */
#define BLADERF_TXVGA1_GAIN_MIN (-35)
/** Maximum TXVGA1 gain, in dB */
#define BLADERF_TXVGA1_GAIN_MAX (-4)
/** Minimum TXVGA2 gain, in dB */
#define BLADERF_TXVGA2_GAIN_MIN 0
/** Maximum TXVGA2 gain, in dB */
#define BLADERF_TXVGA2_GAIN_MAX 25
/** Minimum sample rate, in Hz */
#define BLADERF_SAMPLERATE_MIN 80000u
/** Maximum recommended sample rate, in Hz */
#define BLADERF_SAMPLERATE_REC_MAX 40000000u
/** Minimum bandwidth, in Hz */
#define BLADERF_BANDWIDTH_MIN 1500000u
/** Maximum bandwidth, in Hz */
#define BLADERF_BANDWIDTH_MAX 28000000u
/** Minimum tunable frequency (without an XB-200 attached), in Hz */
#define BLADERF_FREQUENCY_MIN 232500000u
/**
* Minimum tunable frequency (with an XB-200 attached), in HZ.
*
* While this value is the lowest permitted, note that the components on the
* XB-200 are only rated down to 50 MHz. Be aware that performance will likely
* degrade as you tune to lower frequencies.
*/
#define BLADERF_FREQUENCY_MIN_XB200 0u
/** Maximum tunable frequency, in Hz */
#define BLADERF_FREQUENCY_MAX 3800000000u
/**
* Loopback options
*/
typedef enum {
/**
* Firmware loopback inside of the FX3
*/
BLADERF_LB_FIRMWARE = 1,
/**
* Baseband loopback. TXLPF output is connected to the RXVGA2 input.
*/
BLADERF_LB_BB_TXLPF_RXVGA2,
/**
* Baseband loopback. TXVGA1 output is connected to the RXVGA2 input.
*/
BLADERF_LB_BB_TXVGA1_RXVGA2,
/**
* Baseband loopback. TXLPF output is connected to the RXLPF input.
*/
BLADERF_LB_BB_TXLPF_RXLPF,
/**
* Baseband loopback. TXVGA1 output is connected to RXLPF input.
*/
BLADERF_LB_BB_TXVGA1_RXLPF,
/**
* RF loopback. The TXMIX output, through the AUX PA, is connected to the
* output of LNA1.
*/
BLADERF_LB_RF_LNA1,
/**
* RF loopback. The TXMIX output, through the AUX PA, is connected to the
* output of LNA2.
*/
BLADERF_LB_RF_LNA2,
/**
* RF loopback. The TXMIX output, through the AUX PA, is connected to the
* output of LNA3.
*/
BLADERF_LB_RF_LNA3,
/**
* Disables loopback and returns to normal operation.
*/
BLADERF_LB_NONE
} bladerf_loopback;
/**
* Rational sample rate representation
*/
struct bladerf_rational_rate {
uint64_t integer; /**< Integer portion */
uint64_t num; /**< Numerator in fractional portion */
uint64_t den; /**< Denominator in fractional portion. This
must be > 0. */
};
/**
* Sampling connection
*/
typedef enum {
BLADERF_SAMPLING_UNKNOWN, /**< Unable to determine connection type */
BLADERF_SAMPLING_INTERNAL, /**< Sample from RX/TX connector */
BLADERF_SAMPLING_EXTERNAL /**< Sample from J60 or J61 */
} bladerf_sampling;
/**
* LNA gain options
*/
typedef enum {
BLADERF_LNA_GAIN_UNKNOWN, /**< Invalid LNA gain */
BLADERF_LNA_GAIN_BYPASS, /**< LNA bypassed - 0dB gain */
BLADERF_LNA_GAIN_MID, /**< LNA Mid Gain (MAX-6dB) */
BLADERF_LNA_GAIN_MAX /**< LNA Max Gain */
} bladerf_lna_gain;
#define BLADERF_LNA_GAIN_MID_DB 3 /**< Gain in dB of the LNA at mid setting */
#define BLADERF_LNA_GAIN_MAX_DB 6 /**< Gain in db of the LNA at max setting */
/**
* LPF mode
*/
typedef enum {
BLADERF_LPF_NORMAL, /**< LPF connected and enabled */
BLADERF_LPF_BYPASSED, /**< LPF bypassed */
BLADERF_LPF_DISABLED /**< LPF disabled */
} bladerf_lpf_mode;
/**
* Module selection for those which have both RX and TX constituents
*/
typedef enum
{
BLADERF_MODULE_RX, /**< Receive Module */
BLADERF_MODULE_TX /**< Transmit Module */
} bladerf_module;
/**
* Expansion boards
*/
typedef enum {
BLADERF_XB_NONE = 0, /**< No expansion boards attached */
BLADERF_XB_100, /**< XB-100 GPIO expansion board.
* This device is not yet supported in
* libbladeRF, and is here as a placeholder
* for future support. */
BLADERF_XB_200 /**< XB-200 Transverter board */
} bladerf_xb;
/**
* XB-200 filter selection options
*/
typedef enum {
/** 50-54 MHz (6 meter band) filterbank */
BLADERF_XB200_50M = 0,
/** 144-148 MHz (2 meter band) filterbank */
BLADERF_XB200_144M,
/**
* 222-225 MHz (1.25 meter band) filterbank.
*
* Note that this filter option is technically wider, covering 206-235 MHz.
*/
BLADERF_XB200_222M,
/**
* This option enables the RX/TX module's custom filter bank path across the
* associated FILT and FILT-ANT SMA connectors on the XB-200 board.
*
* For reception, it is often possible to simply connect the RXFILT and
* RXFILT-ANT connectors with an SMA cable (effectively, "no filter"). This
* allows for reception of signals outside of the frequency range of the
* on-board filters, with some potential trade-off in signal quality.
*
* For transmission, <b>always</b> use an appropriate filter on the custom
* filter path to avoid spurious emissions.
*
*/
BLADERF_XB200_CUSTOM,
/**
* When this option is selected, the other filter options are automatically
* selected depending on the RX or TX module's current frequency, based upon
* the 1dB points of the on-board filters. For frequencies outside the
* range of the on-board filters, the custom path is selected.
*/
BLADERF_XB200_AUTO_1DB,
/**
* When this option is selected, the other filter options are automatically
* selected depending on the RX or TX module's current frequency, based upon
* the 3dB points of the on-board filters. For frequencies outside the
* range of the on-board filters, the custom path is selected.
*/
BLADERF_XB200_AUTO_3DB
} bladerf_xb200_filter;
/**
* XB-200 signal paths
*/
typedef enum {
BLADERF_XB200_BYPASS = 0, /**< Bypass the XB-200 mixer */
BLADERF_XB200_MIX /**< Pass signals through the XB-200 mixer */
} bladerf_xb200_path;
/**
* DC Calibration Modules
*/
typedef enum
{
BLADERF_DC_CAL_LPF_TUNING,
BLADERF_DC_CAL_TX_LPF,
BLADERF_DC_CAL_RX_LPF,
BLADERF_DC_CAL_RXVGA2
} bladerf_cal_module;
/**
* Correction parameter selection
*
* These values specify the correction parameter to modify or query when
* calling bladerf_set_correction() or bladerf_get_correction(). Note that the
* meaning of the `value` parameter to these functions depends upon the
* correction parameter.
*
*/
typedef enum
{
/**
* Adjusts the in-phase DC offset via controls provided by the LMS6002D
* front end. Valid values are [-2048, 2048], which are scaled to the
* available control bits in the LMS device.
*/
BLADERF_CORR_LMS_DCOFF_I,
/**
* Adjusts the quadrature DC offset via controls provided the LMS6002D
* front end. Valid values are [-2048, 2048], which are scaled to the
* available control bits.
*/
BLADERF_CORR_LMS_DCOFF_Q,
/**
* Adjusts FPGA-based phase correction of [-10, 10] degrees, via a provided
* count value of [-4096, 4096].
*/
BLADERF_CORR_FPGA_PHASE,
/**
* Adjusts FPGA-based gain correction of [0.0, 2.0], via provided
* values in the range of [-4096, 4096], where a value of 0 corresponds to
* a gain of 1.0.
*/
BLADERF_CORR_FPGA_GAIN
} bladerf_correction;
/**
* Enable or disable the specified RX/TX module.
*
* When a synchronous stream is associated with the specified module, this
* will shut down the underlying asynchronous stream when `enable` = false.
*
* When transmitting samples with the sync interface, be sure to provide ample
* time for TX samples reach the FPGA and be transmitted before calling this
* function with `enable` = false.
*
* @param dev Device handle
* @param m Device module
* @param enable true to enable, false to disable
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_enable_module(struct bladerf *dev,
bladerf_module m, bool enable);
/**
* Apply specified loopback mode
*
* @param dev Device handle
* @param l Loopback mode. Note that BLADERF_LB_NONE disables the
* use of loopback functionality.
*
* @note Loopback modes should only be enabled or disabled while the RX and TX
* modules are both disabled (and therefore, when no samples are being
* actively streamed). Otherwise, unexpected behavior may occur.
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_loopback(struct bladerf *dev, bladerf_loopback l);
/**
* Get current loopback mode
*
* @param[in] dev Device handle
* @param[out] l Current loopback mode
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_get_loopback(struct bladerf *dev, bladerf_loopback *l);
/**
* Configure the device's sample rate, in Hz. Note this requires the sample
* rate is an integer value of Hz. Use bladerf_set_rational_sample_rate()
* for more arbitrary values.
*
* The sample rate must be greater than or equal to \ref BLADERF_SAMPLERATE_MIN.
* Values above \ref BLADERF_SAMPLERATE_REC_MAX are allowed, but not
* recommended. Setting the sample rates higher than recommended max may yield
* errors and unexpected results.
*
* @param[in] dev Device handle
* @param[in] module Module to change
* @param[in] rate Sample rate
* @param[out] actual If non-NULL. this is written with the actual
* sample rate achieved.
*
* @return 0 on success,
* BLADERF_ERR_INVAL for an invalid sample rate,
* or a value from \ref RETCODES list on other failures
*/
API_EXPORT
int CALL_CONV bladerf_set_sample_rate(struct bladerf *dev,
bladerf_module module,
unsigned int rate,
unsigned int *actual);
/**
* Configure the device's sample rate as a rational fraction of Hz.
* Sample rates are in the form of integer + num/denom.
*
* @param[in] dev Device handle
* @param[in] module Module to change
* @param[in] rate Rational sample rate
* @param[out] actual If non-NULL, this is written with the actual
* rational sample rate achieved.
*
* The sample rate must be greater than or equal to \ref BLADERF_SAMPLERATE_MIN.
* Values above \ref BLADERF_SAMPLERATE_REC_MAX are allowed, but not
* recommended. Setting the sample rates higher than recommended max may yield
* errors and unexpected results.
*
* @return 0 on success,
* BLADERF_ERR_INVAL for an invalid sample rate,
* or a value from \ref RETCODES list on other failures
*/
API_EXPORT
int CALL_CONV bladerf_set_rational_sample_rate(
struct bladerf *dev,
bladerf_module module,
struct bladerf_rational_rate *rate,
struct bladerf_rational_rate *actual);
/**
* Configure the sampling of the LMS6002D to be either internal or
* external. Internal sampling will read from the RXVGA2 driver internal
* to the chip. External sampling will connect the ADC inputs to the
* external inputs for direct sampling.
*
* @param[in] dev Device handle
* @param[in] sampling Sampling connection
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_sampling(struct bladerf *dev,
bladerf_sampling sampling);
/**
* Read the device's current state of RXVGA2 and ADC pin connection
* to figure out which sampling mode it is currently configured in.
*
* @param[in] dev Device handle
* @param[out] sampling Sampling connection
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_get_sampling(struct bladerf *dev,
bladerf_sampling *sampling);
/**
* Read the device's sample rate in Hz
*
* @param[in] dev Device handle
* @param[in] module Module to query
* @param[out] rate Pointer to returned sample rate
*
* @return 0 on success, value from \ref RETCODES list upon failure
*/
API_EXPORT
int CALL_CONV bladerf_get_sample_rate(struct bladerf *dev,
bladerf_module module,
unsigned int *rate);
/**
* Read the device's sample rate in rational Hz
*
* @param[in] dev Device handle
* @param[in] module Module to query
* @param[out] rate Pointer to returned rational sample rate
*
* @return 0 on success, value from \ref RETCODES list upon failure
*/
API_EXPORT
int CALL_CONV bladerf_get_rational_sample_rate(
struct bladerf *dev,
bladerf_module module,
struct bladerf_rational_rate *rate);
/**
* Set the value of the specified configuration parameter
*
* See the ::bladerf_correction description for the valid ranges of the
* `value` parameter.
*
* @param dev Device handle
* @param module Module to apply correction to
* @param corr Correction type
* @param value Value to apply
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_correction(struct bladerf *dev, bladerf_module module,
bladerf_correction corr, int16_t value);
/**
* Obtain the current value of the specified configuration parameter
*
* @param[in] dev Device handle
* @param[in] module Module to retrieve correction information from
* @param[in] corr Correction type
* @param[out] value Current value
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_get_correction(struct bladerf *dev, bladerf_module module,
bladerf_correction corr, int16_t *value);
/**
* Set the PA gain in dB
*
* Values outside the range of
* [ \ref BLADERF_TXVGA2_GAIN_MIN, \ref BLADERF_TXVGA2_GAIN_MAX ]
* will be clamped.
*
* @param dev Device handle
* @param gain Desired gain
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_txvga2(struct bladerf *dev, int gain);
/**
* Get the PA gain in dB
*
* @param dev Device handle
* @param gain Pointer to returned gain
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT int
CALL_CONV bladerf_get_txvga2(struct bladerf *dev, int *gain);
/**
* Set the post-LPF gain in dB
*
* Values outside the range of
* [ \ref BLADERF_TXVGA1_GAIN_MIN, \ref BLADERF_TXVGA1_GAIN_MAX ]
* will be clamped.
*
* @param dev Device handle
* @param gain Desired gain
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_txvga1(struct bladerf *dev, int gain);
/**
* Get the post-LPF gain in dB
*
* @param dev Device handle
* @param gain Pointer to returned gain
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_get_txvga1(struct bladerf *dev, int *gain);
/**
* Set a combined VGA TX gain
*
* This function computes the optimal TXVGA1 and TXVGA2 gains for a requested
* amount of gain
*
* @param dev Device handle
* @param gain Desired gain
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_tx_gain(struct bladerf *dev, int gain);
/**
* Set the LNA gain
*
* @param dev Device handle
* @param gain Desired gain level
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_lna_gain(struct bladerf *dev, bladerf_lna_gain gain);
/**
* Get the LNA gain
*
* @param dev Device handle
* @param gain Pointer to the set gain level
*/
API_EXPORT
int CALL_CONV bladerf_get_lna_gain(struct bladerf *dev, bladerf_lna_gain *gain);
/**
* Set the pre-LPF VGA gain
*
* Values outside the range of
* [ \ref BLADERF_RXVGA1_GAIN_MIN, \ref BLADERF_RXVGA1_GAIN_MAX ]
* will be clamped.
*
* @param dev Device handle
* @param gain Desired gain
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_rxvga1(struct bladerf *dev, int gain);
/**
* Get the pre-LPF VGA gain
*
* @param dev Device handle
* @param gain Pointer to the set gain level
*/
API_EXPORT
int CALL_CONV bladerf_get_rxvga1(struct bladerf *dev, int *gain);
/**
* Set the post-LPF VGA gain
*
* Values outside the range of
* [ \ref BLADERF_RXVGA2_GAIN_MIN, \ref BLADERF_RXVGA2_GAIN_MAX ]
* will be clamped.
*
* @param dev Device handle
* @param gain Desired gain
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_rxvga2(struct bladerf *dev, int gain);
/**
* Get the post-LPF VGA gain
*
* @param dev Device handle
* @param gain Pointer to the set gain level
*/
API_EXPORT
int CALL_CONV bladerf_get_rxvga2(struct bladerf *dev, int *gain);
/**
* Set a combined pre and post LPF RX gain
*
* This function computes the optimal LNA, RXVGA1, and RVGA2 gains for a
* requested amount of RX gain, and computes the optimal TXVGA1 and TXVGA2 gains
* for a requested amount of TX gain
*
* @param dev Device handle
* @param mod Module
* @param gain Desired gain
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_gain(struct bladerf *dev, bladerf_module mod, int gain);
/**
* Set the bandwidth of the LMS LPF to specified value in Hz
*
* The underlying device is capable of a discrete set of bandwidth values. The
* caller should check the `actual` parameter to determine which of these
* discrete bandwidth values is actually used for the requested bandwidth.
*
* Values outside the range of
* [ \ref BLADERF_BANDWIDTH_MIN, \ref BLADERF_BANDWIDTH_MAX ]
* will be clamped.
*
* @param[in] dev Device handle
* @param[in] module Module for bandwidth request
* @param[in] bandwidth Desired bandwidth
* @param[out] actual If non-NULL, written with the actual
* bandwidth that the device was able to
* achieve.
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_bandwidth(struct bladerf *dev, bladerf_module module,
unsigned int bandwidth,
unsigned int *actual);
/**
* Get the bandwidth of the LMS LPF
*
* @param dev Device Handle
* @param module Module for bandwidth request
* @param bandwidth Actual bandwidth in Hz
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_get_bandwidth(struct bladerf *dev, bladerf_module module,
unsigned int *bandwidth);
/**
* Set the LMS LPF mode to bypass or disable it
*
* @param dev Device handle
* @param module Module for mode request
* @param mode Mode to be set
*
* @return 0 on success, value from \ref RETCODES list on failure
*/
API_EXPORT
int CALL_CONV bladerf_set_lpf_mode(struct bladerf *dev, bladerf_module module,
bladerf_lpf_mode mode);
/**
* Get the current mode of the LMS LPF
*
* @param dev Device handle