Exemple #1
0
static int linux_probe(struct bladerf_devinfo_list *info_list)
{
    int status = 0;
    struct dirent **matches;
    int num_matches, i;
    struct bladerf *dev;
    struct bladerf_devinfo devinfo;

    num_matches = scandir(BLADERF_DEV_DIR, &matches, device_filter, alphasort);
    if (num_matches > 0) {

        for (i = 0; i < num_matches; i++) {
            status = 0;

            /* Open this specific instance. */
            bladerf_init_devinfo(&devinfo);
            devinfo.instance = str2instance(matches[i]->d_name);

            status = linux_open(&dev, &devinfo);

            if (status < 0) {
                log_error("Failed to open instance=%d\n", devinfo.instance);
            } else {
                /* Since this device was opened by instance, it will have
                 * had it's device info (dev->ident) filled out already */
                bladerf_devinfo_list_add(info_list, &dev->ident);
                linux_close(dev);
            }
        }
    }

    free_dirents(matches, num_matches);

    return (!status &&  num_matches > 0) ? status : BLADERF_ERR_NODEV;
}
static bladerf_devinfo kwargs_to_devinfo(const SoapySDR::Kwargs &args)
{
    std::stringstream ss;

    if (args.count("backend") != 0)
    {
        ss << args.at("backend") << ":";
    }
    else ss << "*:";

    if (args.count("device") != 0)
    {
        ss << "device=" << args.at("device") << " ";
    }

    if (args.count("instance") != 0)
    {
        ss << "instance=" << args.at("instance") << " ";
    }

    if (args.count("serial") != 0)
    {
        ss << "serial=" << args.at("serial") << " ";
    }

    bladerf_devinfo info;
    bladerf_init_devinfo(&info);
    bladerf_get_devinfo_from_str(ss.str().c_str(), &info);
    return info;
}
int str2devinfo(const char *dev_id_const, struct bladerf_devinfo *d)
{
    char *dev_id, *token, *arg, *val, *saveptr;
    int status, arg_status;

    assert(d);

    /* Prep our device info before we begin manpulating it, defaulting to
     * a "wildcard" device indentification */
    bladerf_init_devinfo(d);

    /* No device indentifier -- pick anything we can find */
    if ( dev_id_const == NULL || strlen(dev_id_const) == 0) {
        return 0;
    }

    /* Copy the string so we can butcher it a bit while parsing */
    dev_id = strdup(dev_id_const);
    if (!dev_id) {
        return BLADERF_ERR_MEM;
    }

    /* Extract backend */
    token = strtok_r(dev_id, ":", &saveptr);

    /* We require a valid backend -- args only is not supported */
    if (token) {
        status = handle_backend(token, d);

        /* Loop over remainder of string, gathering up args */
        arg_status = 1;
        while (arg_status == 1 && status == 0) {
            arg_status = next_arg(&saveptr, &arg, &val);
            if (arg_status == 1) {

                /* Handle argument if we can */
                if (!strcasecmp("device", arg)) {
                    status = handle_device(d, val);
                } else if (!strcasecmp("instance", arg)) {
                    status = handle_instance(d, val);
                } else if (!strcasecmp("serial", arg)) {
                    status = handle_serial(d, val);
                } else {
                    arg_status = BLADERF_ERR_INVAL;
                }
            }
        };

        if (arg_status < 0) {
            status = arg_status;
        }

    } else {
        status = BLADERF_ERR_INVAL;
    }

    free(dev_id);
    return status;
}
Exemple #4
0
int cyapi_open_bootloader(void **driver, uint8_t bus, uint8_t addr)
{
    struct bladerf_devinfo info;

    bladerf_init_devinfo(&info);
    info.backend = BLADERF_BACKEND_CYPRESS;
    info.usb_bus = bus;
    info.usb_addr = addr;

    return open_via_info(driver, BACKEND_PROBE_FX3_BOOTLOADER, &info, NULL);
}
Exemple #5
0
int main(int argc, char *argv[])
{
    int status = 0;

    struct bladerf *dev = NULL;
    struct bladerf_devinfo dev_info;

    /* Initialize the information used to identify the desired device
     * to all wildcard (i.e., "any device") values */
    bladerf_init_devinfo(&dev_info);

    /* Request a device with the provided serial number.
     * Invalid strings should simply fail to match a device. */
    if (argc >= 2) {
        fprintf(stdout, "dev_info.serial: %s", dev_info.serial);
        strncpy(dev_info.serial, argv[1], sizeof(dev_info.serial) - 1);
    }

    status = bladerf_open_with_devinfo(&dev, &dev_info);
    if (status != 0) {
        fprintf(stderr, "Unable to open device: %s\n",
                bladerf_strerror(status));
        return 1;
    }

    /* A quick check that this works is to watch LO leakage on a VSA */

    status = bladerf_enable_module(dev, BLADERF_MODULE_TX, true);
    if (status != 0) {
        fprintf(stderr, "Failed to enable TX module: %s\n",
                bladerf_strerror(status));
        return status;
    }

    status = example(dev, BLADERF_MODULE_TX);

    bladerf_enable_module(dev, BLADERF_MODULE_TX, false);
    bladerf_close(dev);
    return status;
}
Exemple #6
0
/* Usage:
 *   libbladeRF_example_boilerplate [serial #]
 *
 * If a serial number is supplied, the program will attempt to open the
 * device with the provided serial number.
 *
 * Otherwise, the first available device will be used.
 */
int main(int argc, char *argv[])
{
    int status;
    struct channel_config config;

    /** [Opening a device] */
    struct bladerf *dev = NULL;
    struct bladerf_devinfo dev_info;

    /* Initialize the information used to identify the desired device
     * to all wildcard (i.e., "any device") values */
    bladerf_init_devinfo(&dev_info);

    /* Request a device with the provided serial number.
     * Invalid strings should simply fail to match a device. */
    if (argc >= 2) {
        strncpy(dev_info.serial, argv[1], sizeof(dev_info.serial) - 1);
    }

    status = bladerf_open_with_devinfo(&dev, &dev_info);
    if (status != 0) {
        fprintf(stderr, "Unable to open device: %s\n",
                bladerf_strerror(status));

        return 1;
    }

    /** [Opening a device] */

    /* Set up RX channel parameters */
    config.channel    = BLADERF_CHANNEL_RX(0);
    config.frequency  = 910000000;
    config.bandwidth  = 2000000;
    config.samplerate = 300000;
    config.gain       = 39;

    status = configure_channel(dev, &config);
    if (status != 0) {
        fprintf(stderr, "Failed to configure RX channel. Exiting.\n");
        goto out;
    }

    /* Set up TX channel parameters */
    config.channel    = BLADERF_CHANNEL_TX(0);
    config.frequency  = 918000000;
    config.bandwidth  = 1500000;
    config.samplerate = 250000;
    config.gain       = -14;

    status = configure_channel(dev, &config);
    if (status != 0) {
        fprintf(stderr, "Failed to configure TX channel. Exiting.\n");
        goto out;
    }

    /* Application code goes here.
     *
     * Don't forget to call bladerf_enable_module() before attempting to
     * transmit or receive samples!
     */
    printf("Hello world\n");

out:
    bladerf_close(dev);
    return status;
}
Exemple #7
0
// Open BladeRF device.
BladeRFSource::BladeRFSource(const char *serial) :
    m_dev(0),
    m_sampleRate(1000000),
    m_actualSampleRate(1000000),
    m_frequency(300000000),
    m_minFrequency(300000000),
    m_bandwidth(1500000),
    m_actualBandwidth(1500000),
    m_lnaGain(3),
    m_vga1Gain(6),
    m_vga2Gain(5),
    m_thread(0)
{
    int status;
    struct bladerf_devinfo info;

    bladerf_init_devinfo(&info);

    if (serial != 0)
    {
        strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1);
        info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0';
    }

    status = bladerf_open_with_devinfo(&m_dev, &info);

    if (status == BLADERF_ERR_NODEV)
    {
        std::ostringstream err_ostr;
        err_ostr << "No devices available with serial=" << serial;
        m_error = err_ostr.str();
        m_dev = 0;
    }
    else if (status != 0)
    {
        std::ostringstream err_ostr;
        err_ostr << "Failed to open device with serial=" << serial;
        m_error = err_ostr.str();
        m_dev = 0;
    }
    else
    {
        int fpga_loaded = bladerf_is_fpga_configured(m_dev);

        if (fpga_loaded < 0)
        {
            std::ostringstream err_ostr;
            err_ostr << "Failed to check FPGA state: " << bladerf_strerror(fpga_loaded);
            m_error = err_ostr.str();
            m_dev = 0;
        }
        else if (fpga_loaded == 0)
        {
            m_error = "The device's FPGA is not loaded.";
            m_dev = 0;
        }
        else
        {
            if ((status = bladerf_sync_config(m_dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
            {
                std::ostringstream err_ostr;
                err_ostr << "bladerf_sync_config failed with return code " << status;
                m_error = err_ostr.str();
                m_dev = 0;
            }
            else
            {
                if ((status = bladerf_enable_module(m_dev, BLADERF_MODULE_RX, true)) < 0)
                {
                    std::ostringstream err_ostr;
                    err_ostr << "bladerf_enable_module failed with return code " << status;
                    m_error = err_ostr.str();
                    m_dev = 0;
                }
                else
                {
                    if (bladerf_expansion_attach(m_dev, BLADERF_XB_200) == 0)
                    {
                        std::cerr << "BladeRFSource::BladeRFSource: Attached XB200 extension" << std::endl;

                        if ((status = bladerf_xb200_set_path(m_dev, BLADERF_MODULE_RX, BLADERF_XB200_MIX)) != 0)
                        {
                            std::cerr << "BladeRFSource::BladeRFSource: bladerf_xb200_set_path failed with return code " << status << std::endl;
                        }
                        else
                        {
                            if ((status = bladerf_xb200_set_filterbank(m_dev, BLADERF_MODULE_RX, BLADERF_XB200_AUTO_1DB)) != 0)
                            {
                                std::cerr << "BladeRFSource::BladeRFSource: bladerf_xb200_set_filterbank failed with return code " << status << std::endl;
                            }
                            else
                            {
                                std::cerr << "BladeRFSource::BladeRFSource: XB200 configured. Min freq set to 100kHz" << std::endl;
                                m_minFrequency = 100000;
                            }
                        }
                    }
                }
            }
        }
    }

    std::ostringstream lgains_ostr;

    for (int g: m_lnaGains) {
        lgains_ostr << g << " ";
    }

    m_lnaGainsStr = lgains_ostr.str();

    std::ostringstream v1gains_ostr;

    for (int g: m_vga1Gains) {
        v1gains_ostr << g << " ";
    }

    m_vga1GainsStr = v1gains_ostr.str();

    std::ostringstream v2gains_ostr;

    for (int g: m_vga2Gains) {
        v2gains_ostr << g << " ";
    }

    m_vga2GainsStr = v2gains_ostr.str();

    std::ostringstream bw_ostr;

    for (int b: m_halfbw) {
        bw_ostr << 2*b << " ";
    }

    m_bwfiltStr = bw_ostr.str();

    m_this = this;
}