cdef(""" typedef enum { BLADERF_MODULE_RX, /**< Receive Module */ BLADERF_MODULE_TX /**< Transmit Module */ } bladerf_module; 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; 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; typedef enum { BLADERF_LPF_NORMAL, /**< LPF connected and enabled */ BLADERF_LPF_BYPASSED, /**< LPF bypassed */ BLADERF_LPF_DISABLED /**< LPF disabled */ } bladerf_lpf_mode; /** Minimum RXVGA1 gain, in dB */ #define BLADERF_RXVGA1_GAIN_MIN ... /** Maximum RXVGA1 gain, in dB */ #define BLADERF_RXVGA1_GAIN_MAX ... /** Minimum RXVGA2 gain, in dB */ #define BLADERF_RXVGA2_GAIN_MIN ... /** Maximum RXVGA2 gain, in dB */ #define BLADERF_RXVGA2_GAIN_MAX ... /** Minimum TXVGA1 gain, in dB */ #define BLADERF_TXVGA1_GAIN_MIN ... /** Maximum TXVGA1 gain, in dB */ #define BLADERF_TXVGA1_GAIN_MAX ... /** Minimum TXVGA2 gain, in dB */ #define BLADERF_TXVGA2_GAIN_MIN ... /** Maximum TXVGA2 gain, in dB */ #define BLADERF_TXVGA2_GAIN_MAX ... /** Minimum sample rate, in Hz */ #define BLADERF_SAMPLERATE_MIN ... /** Maximum recommended sample rate, in Hz */ #define BLADERF_SAMPLERATE_REC_MAX ... /** Minimum bandwidth, in Hz */ #define BLADERF_BANDWIDTH_MIN ... /** Maximum bandwidth, in Hz */ #define BLADERF_BANDWIDTH_MAX ... /** Minimum tunable frequency (without an XB-200 attached), in Hz */ #define BLADERF_FREQUENCY_MIN ... /** Maximum tunable frequency, in Hz */ #define BLADERF_FREQUENCY_MAX ... """)
cdef(""" typedef enum { BLADERF_FORMAT_SC16_Q11, /**< Signed, Complex 16-bit Q11. * This is the native format of the DAC data. * * Samples are interleaved IQ value pairs, where * each value in the pair is an int16_t. For each * value, the data in the lower bits. The upper * bits are reserved. * * When using this format, note that buffers * must be at least * 2 * num_samples * sizeof(int16_t) * bytes large */ } bladerf_format; /** * For both RX and TX, the stream callback receives: * dev: Device structure * stream: The associated stream * metadata: TBD * user_data: User data provided when initializing stream * * <br> * * For TX callbacks: * samples: Pointer fo buffer of samples that was sent * num_samples: Number of sent in last transfer and to send in next transfer * * Return value: The user specifies the address of the next buffer to send * * For RX callbacks: * samples: Buffer filled with received data * num_samples: Number of samples received and size of next buffers * * Return value: The user specifies the next buffer to fill with RX data, * which should be num_samples in size. * */ typedef void *(*bladerf_stream_cb)(struct bladerf *dev, struct bladerf_stream *stream, struct bladerf_metadata *meta, void *samples, size_t num_samples, void *user_data); struct bladerf_metadata { uint64_t timestamp; /**< Timestamp (TODO format TBD) */ uint32_t flags; /**< Metadata format flags */ uint32_t status; /**< Metadata format status */ unsigned int actual_count; /**< number of contiguous received samples */ uint8_t reserved[32]; /**< reserved */ }; """)
import bladeRF from bladeRF import _cffi from bladeRF._cffi import ffi, cdef, ptop cdef(""" typedef enum { BLADERF_FPGA_UNKNOWN = 0, /**< Unable to determine FPGA variant */ BLADERF_FPGA_40KLE = 40, /**< 40 kLE FPGA */ BLADERF_FPGA_115KLE = 115 /**< 115 kLE FPGA */ } bladerf_fpga_size; """) @cdef('int bladerf_get_fpga_size(struct bladerf *dev, bladerf_fpga_size *size);') def get_fpga_size(dev): size = ffi.new('bladerf_fpga_size *') err = _cffi.lib.bladerf_get_fpga_size(dev, size) bladeRF.errors.check_retcode(err) return int(size[0])
import bladeRF from bladeRF import _cffi from bladeRF._cffi import ffi, cdef, ptop cdef(""" typedef enum { BLADERF_LOG_LEVEL_VERBOSE, /**< Verbose level logging */ BLADERF_LOG_LEVEL_DEBUG, /**< Debug level logging */ BLADERF_LOG_LEVEL_INFO, /**< Information level logging */ BLADERF_LOG_LEVEL_WARNING, /**< Warning level logging */ BLADERF_LOG_LEVEL_ERROR, /**< Error level logging */ BLADERF_LOG_LEVEL_CRITICAL, /**< Fatal error level logging */ BLADERF_LOG_LEVEL_SILENT /**< No output */ } bladerf_log_level; """) @cdef('void bladerf_log_set_verbosity(bladerf_log_level level);') def log_set_verbosity(level): _cffi.lib.bladerf_log_set_verbosity(level)
cdef(""" /** * 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; /** * 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, BLADERF_XB_100, BLADERF_XB_200 } bladerf_xb ; /** * XB 200 filterbanks */ typedef enum { BLADERF_XB200_50M = 0, BLADERF_XB200_144M, BLADERF_XB200_222M, BLADERF_XB200_CUSTOM } bladerf_xb200_filter; /** * XB 200 signal paths */ typedef enum { BLADERF_XB200_BYPASS = 0, BLADERF_XB200_MIX } 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; """)
from bladeRF._cffi import ffi, cdef, ptop cdef(""" typedef enum { BLADERF_MODULE_RX, /**< Receive Module */ BLADERF_MODULE_TX /**< Transmit Module */ } bladerf_module; 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; 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; typedef enum { BLADERF_LPF_NORMAL, /**< LPF connected and enabled */ BLADERF_LPF_BYPASSED, /**< LPF bypassed */ BLADERF_LPF_DISABLED /**< LPF disabled */ } bladerf_lpf_mode; """) @cdef('int bladerf_enable_module(struct bladerf *dev, '
cdef(""" typedef enum { /** * Signed, Complex 16-bit Q11. This is the native format of the DAC data. * * Values in the range [-2048, 2048) are used to represent [-1.0, 1.0). * Note that the lower bound here is inclusive, and the upper bound is * exclusive. Ensure that provided samples stay within [-2048, 2047]. * * Samples consist of interleaved IQ value pairs, with I being the first * value in the pair. Each value in the pair is a right-aligned, * little-endian int16_t. The FPGA ensures that these values are * sign-extended. * * When using this format the minimum required buffer size, in bytes, is: * <pre> * buffer_size_min = [ 2 * num_samples * sizeof(int16_t) ] * </pre> * * For example, to hold 2048 samples, a buffer must be at least 8192 bytes * large. */ BLADERF_FORMAT_SC16_Q11, /** * This format is the same as the ::BLADERF_FORMAT_SC16_Q11 format, except the * first 4 samples (16 bytes) in every block of 1024 samples are replaced * with metadata, organized as follows, with all fields being little endian * byte order: * * <pre> * 0x00 [uint32_t: Reserved] * 0x04 [uint64_t: 64-bit Timestamp] * 0x0c [uint32_t: BLADERF_META_FLAG_* flags] * </pre> * * When using the bladerf_sync_rx() and bladerf_sync_tx() functions, * this detail is transparent to caller. These functions take care of * packing/unpacking the metadata into/from the data, via the * bladerf_metadata structure. * * Currently, when using the asynchronous data transfer interface, the user * is responsible for manually packing/unpacking this metadata into/from * their sample data. */ BLADERF_FORMAT_SC16_Q11_META, } bladerf_format; /** * For both RX and TX, the stream callback receives: * dev: Device structure * stream: The associated stream * metadata: TBD * user_data: User data provided when initializing stream * * <br> * * For TX callbacks: * samples: Pointer fo buffer of samples that was sent * num_samples: Number of sent in last transfer and to send in next transfer * * Return value: The user specifies the address of the next buffer to send * * For RX callbacks: * samples: Buffer filled with received data * num_samples: Number of samples received and size of next buffers * * Return value: The user specifies the next buffer to fill with RX data, * which should be num_samples in size. * */ typedef void *(*bladerf_stream_cb)(struct bladerf *dev, struct bladerf_stream *stream, struct bladerf_metadata *meta, void *samples, size_t num_samples, void *user_data); // Updated metadata struct, as of 2015-08-15 struct bladerf_metadata { uint64_t timestamp; /**< Timestamp (TODO format TBD) */ uint32_t flags; /**< Metadata format flags */ uint32_t status; /**< Metadata format status */ unsigned int actual_count; uint8_t reserved[32]; }; """)