Exemplo n.º 1
0
int tuning_set_freq(struct bladerf *dev, bladerf_module module,
                    unsigned int frequency)
{
    int status;
    const bladerf_xb attached = dev->xb;
    int16_t dc_i, dc_q;
    const struct dc_cal_tbl *dc_cal =
        (module == BLADERF_MODULE_RX) ? dev->cal.dc_rx : dev->cal.dc_tx;

    log_debug("Setting %s frequency to %u\n", module2str(module), frequency);

    if (attached == BLADERF_XB_200) {

        if (frequency < BLADERF_FREQUENCY_MIN) {

            status = xb200_set_path(dev, module, BLADERF_XB200_MIX);
            if (status) {
                return status;
            }

            status = xb200_auto_filter_selection(dev, module, frequency);
            if (status) {
                return status;
            }

            frequency = 1248000000 - frequency;

        } else {
            status = xb200_set_path(dev, module, BLADERF_XB200_BYPASS);
            if (status)
                return status;
        }
    }

    switch (dev->tuning_mode) {
        case BLADERF_TUNING_MODE_HOST:
            status = lms_set_frequency(dev, module, frequency);
            if (status != 0) {
                return status;
            }

            status = band_select(dev, module, frequency < BLADERF_BAND_HIGH);
            break;

        case BLADERF_TUNING_MODE_FPGA: {
            struct lms_freq f;

            status = lms_calculate_tuning_params(frequency, &f);
            if (status == 0) {
                /* The band selection will occur in the NIOS II */
                status = tuning_schedule(dev, module, BLADERF_RETUNE_NOW, &f);
            }
            break;
        }

        default:
            log_debug("Invalid tuning mode: %d\n", dev->tuning_mode);
            status = BLADERF_ERR_INVAL;
            break;
    }

    if (status != 0) {
        return status;
    }

    if (dc_cal != NULL) {
        dc_cal_tbl_vals(dc_cal, frequency, &dc_i, &dc_q);

        status = lms_set_dc_offset_i(dev, module, dc_i);
        if (status != 0) {
            return status;
        }

        status = lms_set_dc_offset_q(dev, module, dc_q);
        if (status != 0) {
            return status;
        }

        log_verbose("Set %s DC offset cal (I, Q) to: (%d, %d)\n",
                    (module == BLADERF_MODULE_RX) ? "RX" : "TX", dc_i, dc_q);
    }

    return status;
}
Exemplo n.º 2
0
int tuning_set_freq(struct bladerf *dev, bladerf_module module,
                    unsigned int frequency)
{
    int status;
    bladerf_xb attached;
    int16_t dc_i, dc_q;
    const struct dc_cal_tbl *dc_cal =
        (module == BLADERF_MODULE_RX) ? dev->cal.dc_rx : dev->cal.dc_tx;

    status = xb_get_attached(dev, &attached);
    if (status) {
        return status;
    }

    if (attached == BLADERF_XB_200) {

        if (frequency < BLADERF_FREQUENCY_MIN) {

            status = xb200_set_path(dev, module, BLADERF_XB200_MIX);
            if (status) {
                return status;
            }

            status = xb200_auto_filter_selection(dev, module, frequency);
            if (status) {
                return status;
            }

            frequency = 1248000000 - frequency;

        } else {
            status = xb200_set_path(dev, module, BLADERF_XB200_BYPASS);
            if (status)
                return status;
        }
    }

    status = lms_set_frequency(dev, module, frequency);
    if (status != 0) {
        return status;
    }

    status = tuning_select_band(dev, module, frequency);
    if (status != 0) {
        return status;
    }

    if (dc_cal != NULL) {
        dc_cal_tbl_vals(dc_cal, frequency, &dc_i, &dc_q);

        status = dev->fn->set_correction(dev, module,
                                         BLADERF_CORR_LMS_DCOFF_I, dc_i);
        if (status != 0) {
            return status;
        }

        status = dev->fn->set_correction(dev, module,
                                         BLADERF_CORR_LMS_DCOFF_Q, dc_q);
        if (status != 0) {
            return status;
        }

        log_verbose("Set %s DC offset cal (I, Q) to: (%d, %d)\n",
                    (module == BLADERF_MODULE_RX) ? "RX" : "TX", dc_i, dc_q);
    }

    return status;
}