Beispiel #1
0
static int set_and_check_rational(struct bladerf *dev, bladerf_module m,
                                  struct bladerf_rational_rate *rate)
{
    int status;
    struct bladerf_rational_rate actual, readback;

    status = bladerf_set_rational_sample_rate(dev, m, rate, &actual);
    if (status != 0) {
        PR_ERROR("Failed to set rational sample rate: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    status = bladerf_get_rational_sample_rate(dev, m, &readback);
    if (status != 0) {
        PR_ERROR("Failed to read back rational sample rate: %s\n",
                 bladerf_strerror(status));
        return status;
    }

    if (actual.integer != readback.integer  ||
        actual.num != readback.num          ||
        actual.den != readback.den          ) {

        PR_ERROR("Readback mismatch:\n"
                 " actual:   int=%"PRIu64" num=%"PRIu64" den=%"PRIu64"\n"
                 "  readback: int=%"PRIu64" num=%"PRIu64" den=%"PRIu64"\n",
                 actual.integer, actual.num, actual.den,
                 readback.integer, readback.num, readback.den);

        return status;
    }

    return 0;
}
Beispiel #2
0
static inline int restore_settings(struct bladerf *dev, bladerf_module module,
                                   struct settings *settings)
{
    int status;

    status = bladerf_set_bandwidth(dev, module, settings->bandwidth, NULL);
    if (status != 0) {
        return status;
    }

    status = bladerf_set_frequency(dev, module, settings->frequency);
    if (status != 0) {
        return status;
    }

    status = bladerf_set_rational_sample_rate(dev, module,
                                              &settings->samplerate, NULL);

    return status;
}
Beispiel #3
0
static int set_rx_cal_backup(struct bladerf *dev, struct rx_cal_backup *b)
{
    int status;
    int retval = 0;

    status = bladerf_set_rational_sample_rate(dev, BLADERF_MODULE_RX,
                                              &b->rational_sample_rate, NULL);
    if (status != 0 && retval == 0) {
        retval = status;
    }

    status = bladerf_set_bandwidth(dev, BLADERF_MODULE_RX, b->bandwidth, NULL);
    if (status != 0 && retval == 0) {
        retval = status;
    }

    status = bladerf_set_frequency(dev, BLADERF_MODULE_TX, b->tx_freq);
    if (status != 0 && retval == 0) {
        retval = status;
    }

    return retval;
}
Beispiel #4
0
/* We've found that running samples through the LMS6 tends to be required
 * for the TX LPF calibration to converge */
static inline int tx_lpf_dummy_tx(struct bladerf *dev)
{
    int status;
    int retval = 0;
    struct bladerf_metadata meta;
    int16_t zero_sample[] = { 0, 0 };

    bladerf_loopback loopback_backup;
    struct bladerf_rational_rate sample_rate_backup;

    memset(&meta, 0, sizeof(meta));

    status = bladerf_get_loopback(dev, &loopback_backup);
    if (status != 0) {
        return status;
    }

    status = bladerf_get_rational_sample_rate(dev, BLADERF_MODULE_TX,
                                              &sample_rate_backup);
    if (status != 0) {
        return status;
    }

    status = bladerf_set_loopback(dev, BLADERF_LB_BB_TXVGA1_RXVGA2);
    if (status != 0) {
        goto out;
    }

    status = bladerf_set_sample_rate(dev, BLADERF_MODULE_TX, 3000000, NULL);
    if (status != 0) {
        goto out;
    }

    status = bladerf_sync_config(dev, BLADERF_MODULE_TX,
                                 BLADERF_FORMAT_SC16_Q11_META,
                                 64, 16384, 16, 1000);
    if (status != 0) {
        goto out;
    }

    status = bladerf_enable_module(dev, BLADERF_MODULE_TX, true);
    if (status != 0) {
        goto out;
    }

    meta.flags = BLADERF_META_FLAG_TX_BURST_START |
                 BLADERF_META_FLAG_TX_BURST_END   |
                 BLADERF_META_FLAG_TX_NOW;

    status = bladerf_sync_tx(dev, zero_sample, 1, &meta, 2000);
    if (status != 0) {
        goto out;
    }

out:
    status = bladerf_enable_module(dev, BLADERF_MODULE_TX, false);
    if (status != 0 && retval == 0) {
        retval = status;
    }

    status = bladerf_set_rational_sample_rate(dev, BLADERF_MODULE_TX,
                                              &sample_rate_backup, NULL);
    if (status != 0 && retval == 0) {
        retval = status;
    }

    status = bladerf_set_loopback(dev, loopback_backup);
    if (status != 0 && retval == 0) {
        retval = status;
    }

    return retval;
}