Exemple #1
0
double rf_blade_set_rx_gain(void *h, double gain)
{
  int status; 
  rf_blade_handler_t *handler = (rf_blade_handler_t*) h;  
  status = bladerf_set_rxvga2(handler->dev, (int) gain);
  if (status != 0) {
    fprintf(stderr, "Failed to set RX VGA2 gain: %s\n", bladerf_strerror(status));
    return -1;
  }
  return rf_blade_get_rx_gain(h);
}
Exemple #2
0
static int load_gains(struct rx_cal *cal, struct gain_mode *gain) {
    int status;

    status = bladerf_set_lna_gain(cal->dev, gain->lna_gain);
    if (status != 0) {
        return status;
    }

    status = bladerf_set_rxvga1(cal->dev, gain->rxvga1);
    if (status != 0) {
        return status;
    }

    status = bladerf_set_rxvga2(cal->dev, gain->rxvga2);
    if (status != 0) {
        return status;
    }

    return status;
}
static inline int setup_device(struct test *t)
{
    int status;
    struct bladerf *dev = t->dev;

#if !DISABLE_RX_LOOPBACK
    status = bladerf_set_loopback(dev, BLADERF_LB_BB_TXVGA1_RXVGA2);
    if (status != 0) {
        fprintf(stderr, "Failed to set loopback mode: %s\n",
                bladerf_strerror(status));
        return status;
    }
#endif

    status = bladerf_set_lna_gain(dev, BLADERF_LNA_GAIN_MAX);
    if (status != 0) {
        fprintf(stderr, "Failed to set LNA gain value: %s\n",
                bladerf_strerror(status));
        return status;
    }

    status = bladerf_set_rxvga1(dev, 30);
    if (status != 0) {
        fprintf(stderr, "Failed to set RXVGA1 value: %s\n",
                bladerf_strerror(status));
        return status;
    }

    status = bladerf_set_rxvga2(dev, 10);
    if (status != 0) {
        fprintf(stderr, "Failed to set RXVGA2 value: %s\n",
                bladerf_strerror(status));
        return status;
    }

    status = bladerf_set_txvga1(dev, -10);
    if (status != 0) {
        fprintf(stderr, "Failed to set TXVGA1 value: %s\n",
                bladerf_strerror(status));
        return status;
    }

    status = bladerf_set_txvga2(dev, BLADERF_TXVGA2_GAIN_MIN);
    if (status != 0) {
        fprintf(stderr, "Failed to set TXVGA2 value: %s\n",
                bladerf_strerror(status));
        return status;
    }


    status = bladerf_sync_config(t->dev, BLADERF_MODULE_RX,
                                 BLADERF_FORMAT_SC16_Q11_META,
                                 t->params->num_buffers,
                                 t->params->buf_size,
                                 t->params->num_xfers,
                                 t->params->timeout_ms);
    if (status != 0) {
        fprintf(stderr, "Failed to configure RX stream: %s\n",
                bladerf_strerror(status));
        return status;
    }

    status = bladerf_enable_module(t->dev, BLADERF_MODULE_RX, true);
    if (status != 0) {
        fprintf(stderr, "Failed to enable RX module: %s\n",
                bladerf_strerror(status));
        return status;

    }

    status = bladerf_sync_config(t->dev, BLADERF_MODULE_TX,
                                 BLADERF_FORMAT_SC16_Q11_META,
                                 t->params->num_buffers,
                                 t->params->buf_size,
                                 t->params->num_xfers,
                                 t->params->timeout_ms);
    if (status != 0) {
        fprintf(stderr, "Failed to configure TX stream: %s\n",
                bladerf_strerror(status));
        return status;
    }

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

    }


    return status;
}
Exemple #4
0
int configure_bladerf(struct bladerf** dev, struct bladerf_config* config)
{
    unsigned int abw, asr;
    int status;

    setlocale(LC_NUMERIC, "");

    printf("%-50s", "Connecting to device... ");
    fflush(stdout);
    status = bladerf_open(dev, NULL);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-50s", "Checking FPGA status... ");
    fflush(stdout);
    status = bladerf_is_fpga_configured(*dev);
    if(status < 0) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    } else if(status == 0) {
        printf(KRED "Failed: FPGA not loaded" KNRM "\n");
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %'13uHz... ", "Tuning TX to:", config->tx_freq);
    fflush(stdout);
    status = bladerf_set_frequency(*dev, BLADERF_MODULE_TX, config->tx_freq);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %'13uHz... ", "Tuning RX to:", config->rx_freq);
    fflush(stdout);
    status = bladerf_set_frequency(*dev, BLADERF_MODULE_RX, config->rx_freq);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %'13uHz... ", "Setting TX bandwidth to:", config->tx_bw);
    fflush(stdout);
    status = bladerf_set_bandwidth(*dev, BLADERF_MODULE_TX,
                                   config->tx_bw, &abw);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %'13uHz\n", "Actual bandwidth:", abw);
    if(abw != config->tx_bw) {
        printf("Actual bandwidth not equal to desired bandwidth, quitting.\n");
        return 1;
    }

    printf("%-30s %'13uHz... ", "Setting RX bandwidth to:", config->rx_bw);
    fflush(stdout);
    status = bladerf_set_bandwidth(*dev, BLADERF_MODULE_RX,
                                   config->rx_bw, &abw);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %'13uHz\n", "Actual bandwidth:", abw);
    if(abw != config->rx_bw) {
        printf("Actual bandwidth not equal to desired bandwidth, quitting.\n");
        return 1;
    }

    printf("%-30s %'12usps... ", "Setting TX sampling rate to:",
           config->tx_sr);
    fflush(stdout);
    status = bladerf_set_sample_rate(*dev, BLADERF_MODULE_TX,
                                     config->tx_sr, &asr);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %'12usps\n", "Actual sampling rate:", asr);
    if(asr != config->tx_sr) {
        printf("Actual sampling rate not equal to desired sampling rate, "
               "quitting.\n");
        return 1;
    }

    printf("%-30s %'12usps... ", "Setting RX sampling rate to:",
           config->rx_sr);
    fflush(stdout);
    status = bladerf_set_sample_rate(*dev, BLADERF_MODULE_RX,
                                     config->rx_sr, &asr);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %'12usps\n", "Actual sampling rate:", asr);
    if(asr != config->rx_sr) {
        printf("Actual sampling rate not equal to desired sampling rate, "
               "quitting.\n");
        return 1;
    }

    printf("%-30s %+13ddB... ", "Setting TXVGA1 gain to:", config->txvga1);
    fflush(stdout);
    status = bladerf_set_txvga1(*dev, config->txvga1);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %+13ddB... ", "Setting TXVGA2 gain to:", config->txvga2);
    fflush(stdout);
    status = bladerf_set_txvga2(*dev, config->txvga2);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %+13ddB... ", "Setting RXVGA1 gain to:", config->rxvga1);
    fflush(stdout);
    status = bladerf_set_rxvga1(*dev, config->rxvga1);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %+13ddB... ", "Setting RXVGA2 gain to:", config->rxvga2);
    fflush(stdout);
    status = bladerf_set_rxvga2(*dev, config->rxvga2);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("%-30s %15d... ", "Setting LNA gain to:", config->lna);
    fflush(stdout);
    status = bladerf_set_lna_gain(*dev, config->lna);
    if(status) {
        printf(KRED "Failed: %s" KNRM "\n", bladerf_strerror(status));
        bladerf_close(*dev);
        return 1;
    }
    printf(KGRN "OK" KNRM "\n");

    printf("All set up.\n");

    return 0;
}
Exemple #5
0
/**
 * Configure RX/TX module
 */
static int radio_configure_module(struct bladerf *dev, struct module_config *c)
{
    int status;
    status = bladerf_set_frequency(dev, c->module, c->frequency);
    if (status != 0) {
        fprintf(stderr, "Failed to set frequency = %u: %s\n",
                c->frequency, bladerf_strerror(status));
        return status;
    }
    status = bladerf_set_sample_rate(dev, c->module, c->samplerate, NULL);
    if (status != 0) {
        fprintf(stderr, "Failed to set samplerate = %u: %s\n",
                c->samplerate, bladerf_strerror(status));
        return status;
    }
    status = bladerf_set_bandwidth(dev, c->module, c->bandwidth, NULL);
    if (status != 0) {
        fprintf(stderr, "Failed to set bandwidth = %u: %s\n",
                c->bandwidth, bladerf_strerror(status));
        return status;
    }
    switch (c->module) {
        case BLADERF_MODULE_RX:
            /* Configure the gains of the RX LNA, RX VGA1, and RX VGA2  */
            status = bladerf_set_lna_gain(dev, c->rx_lna);
            if (status != 0) {
                fprintf(stderr, "Failed to set RX LNA gain: %s\n",
                        bladerf_strerror(status));
                return status;
            }
            status = bladerf_set_rxvga1(dev, c->vga1);
            if (status != 0) {
                fprintf(stderr, "Failed to set RX VGA1 gain: %s\n",
                        bladerf_strerror(status));
                return status;
            }
            status = bladerf_set_rxvga2(dev, c->vga2);
            if (status != 0) {
                fprintf(stderr, "Failed to set RX VGA2 gain: %s\n",
                        bladerf_strerror(status));
                return status;
            }
            break;
        case BLADERF_MODULE_TX:
            /* Configure the TX VGA1 and TX VGA2 gains */
            status = bladerf_set_txvga1(dev, c->vga1);
            if (status != 0) {
                fprintf(stderr, "Failed to set TX VGA1 gain: %s\n",
                        bladerf_strerror(status));
                return status;
            }
            status = bladerf_set_txvga2(dev, c->vga2);
            if (status != 0) {
                fprintf(stderr, "Failed to set TX VGA2 gain: %s\n",
                        bladerf_strerror(status));
                return status;
            }
            break;
        default:
            status = BLADERF_ERR_INVAL;
            fprintf(stderr, "%s: Invalid module specified (%d)\n",
                    __FUNCTION__, c->module);
    }
    return status;
}
Exemple #6
0
// Configure RTL-SDR tuner and prepare for streaming.
bool BladeRFSource::configure(uint32_t changeFlags,
        uint32_t sample_rate,
        uint32_t frequency,
        uint32_t bandwidth,
        int lna_gainIndex,
        int vga1_gain,
        int vga2_gain)
{
    m_frequency = frequency;
    m_vga1Gain = vga1_gain;
    m_vga2Gain = vga2_gain;
    m_lnaGain = m_lnaGains[lna_gainIndex-1];

    if (changeFlags & 0x1)
    {
        if (bladerf_set_sample_rate(m_dev, BLADERF_MODULE_RX, sample_rate, &m_actualSampleRate) < 0)
        {
            m_error = "Cannot set sample rate";
            return false;
        }
    }

    if (changeFlags & 0x2)
    {
        if (bladerf_set_frequency( m_dev, BLADERF_MODULE_RX, frequency ) != 0)
        {
            m_error = "Cannot set Rx frequency";
            return false;
        }
    }

    if (changeFlags & 0x4)
    {
        if (bladerf_set_bandwidth(m_dev, BLADERF_MODULE_RX, bandwidth, &m_actualBandwidth) < 0)
        {
            m_error = "Cannot set Rx bandwidth";
            return false;
        }
    }

    if (changeFlags & 0x8)
    {
        if (bladerf_set_lna_gain(m_dev, static_cast<bladerf_lna_gain>(lna_gainIndex)) != 0)
        {
            m_error = "Cannot set LNA gain";
            return false;
        }
    }

    if (changeFlags & 0x10)
    {
        if (bladerf_set_rxvga1(m_dev, vga1_gain) != 0)
        {
            m_error = "Cannot set VGA1 gain";
            return false;
        }
    }

    if (changeFlags & 0x20)
    {
        if (bladerf_set_rxvga2(m_dev, vga2_gain) != 0)
        {
            m_error = "Cannot set VGA2 gain";
            return false;
        }
    }

    return true;
}
Exemple #7
0
static int repeater_handle_key(struct repeater *repeater, char key)
{
    int status = 0;

    switch (key) {
        case KEY_DEC_TXVGA1:
            if (repeater->gain_txvga1 > GAIN_TXVGA1_MIN) {
                status = bladerf_set_txvga1(repeater->device,
                                            --repeater->gain_txvga1);

                if (status < 0) {
                    repeater->gain_txvga1++;
                    fprintf(stderr, "Failed to increase TXVGA1 gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("TXVGA1 gain decreased to: %d\r\n",
                            repeater->gain_txvga1);
                }
            }
            break;

        case KEY_INC_TXVGA1:
            if (repeater->gain_txvga1 < GAIN_TXVGA1_MAX) {
                status = bladerf_set_txvga1(repeater->device,
                                            ++repeater->gain_txvga1);

                if (status < 0) {
                    repeater->gain_txvga1--;
                    fprintf(stderr, "Failed to increase TXVGA1 gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("TXVGA1 gain increased to: %d\r\n",
                            repeater->gain_txvga1);
                }
            }
            break;

        case KEY_DEC_TXVGA2:
            if (repeater->gain_txvga2 > GAIN_TXVGA2_MIN) {
                status = bladerf_set_txvga2(repeater->device,
                                            --repeater->gain_txvga2);

                if (status < 0) {
                    repeater->gain_txvga2++;
                    fprintf(stderr, "Failed to decrease TXVGA2 gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("TXVGA2 gain decreased to: %d\r\n",
                            repeater->gain_txvga2);
                }
            }
            break;

        case KEY_INC_TXVGA2:
            if (repeater->gain_txvga2 < GAIN_TXVGA2_MAX) {
                status = bladerf_set_txvga2(repeater->device,
                                            ++repeater->gain_txvga2);

                if (status < 0) {
                    repeater->gain_txvga2--;
                    fprintf(stderr, "Failed to increase TXVGA2 gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("TXVGA2 gain increased to: %d\r\n",
                            repeater->gain_txvga2);
                }
            }
            break;

        case KEY_DEC_RXVGA1:
            if (repeater->gain_rxvga1 > GAIN_RXVGA1_MIN) {
                status = bladerf_set_rxvga1(repeater->device,
                        --repeater->gain_rxvga1);

                if (status < 0) {
                    repeater->gain_rxvga1++;
                    fprintf(stderr, "Failed to decrease RXVGA1 gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("RXVGA1 gain decreased to %d\r\n",
                            repeater->gain_rxvga1);
                }
            }
            break;

        case KEY_INC_RXVGA1:
            if (repeater->gain_rxvga1 < GAIN_RXVGA1_MAX) {
                status = bladerf_set_rxvga1(repeater->device,
                        ++repeater->gain_rxvga1);

                if (status < 0) {
                    repeater->gain_rxvga1--;
                    fprintf(stderr, "Failed to increase RXVGA1 gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("RXVGA1 gain increased to %d\r\n",
                            repeater->gain_rxvga1);
                }
            }
            break;

        case KEY_DEC_RXVGA2:
            if (repeater->gain_rxvga2 > GAIN_RXVGA2_MIN) {
                status = bladerf_set_rxvga2(repeater->device,
                        --repeater->gain_rxvga2);

                if (status < 0) {
                    repeater->gain_rxvga2++;
                    fprintf(stderr, "Failed to decrease RXVGA2 gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("RXVGA2 gain decreased to %d\r\n",
                            repeater->gain_rxvga2);
                }
            }
            break;

        case KEY_INC_RXVGA2:
            if (repeater->gain_rxvga2 < GAIN_RXVGA2_MAX)
            {
                status = bladerf_set_rxvga2(repeater->device,
                        ++repeater->gain_rxvga2);

                if (status < 0) {
                    repeater->gain_rxvga2--;
                    fprintf(stderr, "Failed to increase RXVGA2 gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("RXVGA2 gain increased to %d\r\n",
                            repeater->gain_rxvga2);
                }
            }
            break;

        case KEY_DEC_LNAGAIN:
            if (repeater->gain_lna > BLADERF_LNA_GAIN_BYPASS)
            {
                status = bladerf_set_lna_gain(repeater->device,
                                              --repeater->gain_lna);

                if (status < 0) {
                    repeater->gain_lna++;
                    fprintf(stderr, "Failed to decrease LNA gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("LNA gain decreased to %s\r\n",
                           lnagain2str(repeater->gain_lna));
                }
            }
            break;

        case KEY_INC_LNAGAIN:
            if (repeater->gain_lna < BLADERF_LNA_GAIN_MAX)
            {
                status = bladerf_set_lna_gain(repeater->device,
                                              ++repeater->gain_lna);

                if (status < 0) {
                    repeater->gain_lna--;
                    fprintf(stderr, "Failed to increase LNA gain: %s\r\n",
                            bladerf_strerror(status));
                } else {
                    printf("LNA gain increased to %s\r\n",
                           lnagain2str(repeater->gain_lna));
                }
            }
            break;

        case KEY_HELP:
            repeater_help();
            break;

        default:
            break;
    }

    return status;
}