static int load_fpga(struct cli_state *s, char *file) { char *expanded_path; int cmd_status = 0; int lib_status; if ((expanded_path = interactive_expand_path(file)) == NULL) { cli_err(s, "Unable to expand FPGA file path: \"%s\"", file); cmd_status = CMD_RET_INVPARAM; } else { printf("Loading fpga from %s...\n", expanded_path); lib_status = bladerf_load_fpga(s->dev, expanded_path); if (lib_status < 0) { s->last_lib_error = lib_status; cmd_status = CMD_RET_LIBBLADERF; } else { printf("Done.\n"); } free(expanded_path); } return cmd_status; }
static int load_fpga(struct rc_config *rc, struct cli_state *state, int status) { if (!status && rc->fpga_file) { if (!state->dev) { print_error_need_devarg(); status = -1; } else { printf("Loading fpga...\n"); status = bladerf_load_fpga(state->dev, rc->fpga_file); if (status) { fprintf(stderr, "Error: failed to load FPGA: %s\n", bladerf_strerror(status)); } else { printf("Done.\n"); } } } return status; }
//! Do any initialization required void BladeRfTxComponent::initialize() { // Set up the input DataBuffer inBuf_ = castToType< complex<float> >(inputBuffers.at(0)); // Initialize raw sample vector to some multiple of block size rawSampleBuffer_.data.resize(128 * BLADERF_SAMPLE_BLOCK_SIZE); // Set up the BladeRF try { // Create the device LOG(LINFO) << "Trying to open device " << deviceName_x; int ret = bladerf_open(&device_, deviceName_x.c_str()); if (ret != 0) { throw IrisException("Failed to open bladeRF device!"); } // Check whether FPGA is configured yet if (bladerf_is_fpga_configured(device_) != 1 ) { // try to load FPGA image if (not fpgaImage_x.empty()) { ret = bladerf_load_fpga(device_, fpgaImage_x.c_str()); if (ret != 0) { throw IrisException("Failed to load FPGA to bladeRF!"); } else { LOG(LINFO) << "FPGA image successfully loaded."; } } else { throw IrisException("BladeRF FPGA is not configured and no FPGA image given!"); } } // Print some information about device struct bladerf_version version; if (bladerf_fw_version(device_, &version) == 0) { LOG(LINFO) << "Using FW " << version.describe; } if (bladerf_fpga_version(device_, &version) == 0) { LOG(LINFO) << "Using FPGA " << version.describe; } if (bladerf_is_fpga_configured(device_) != 1 ) { throw IrisException("BladeRF FPGA is not configured!"); } // setting up sync config ret = bladerf_sync_config(device_, BLADERF_MODULE_TX, BLADERF_FORMAT_SC16_Q11, BLADERF_DEFAULT_STREAM_BUFFERS, BLADERF_DEFAULT_STREAM_SAMPLES, BLADERF_DEFAULT_STREAM_XFERS, BLADERF_SYNC_TIMEOUT_MS); if (ret != 0) { throw IrisException("Couldn't enable BladeRF Tx sync handle!"); LOG(LERROR) << bladerf_strerror(ret); } // Turn on transmitter ret = bladerf_enable_module(device_, BLADERF_MODULE_TX, true); if ( ret != 0 ) { throw IrisException("Couldn't enable BladeRF Tx module!"); } // Set sample rate uint32_t actualValue; ret = bladerf_set_sample_rate(device_, BLADERF_MODULE_TX, (uint32_t)rate_x, &actualValue); if (ret != 0) { throw IrisException("Failed to set sample rate!"); } LOG(LINFO) << "Actual Tx sample rate is: " << actualValue << " Hz"; // Set center frequency ret = bladerf_set_frequency(device_, BLADERF_MODULE_TX, frequency_x); if (ret != 0) { throw IrisException("Failed to set center frequency!"); } bladerf_get_frequency(device_, BLADERF_MODULE_TX, &actualValue); LOG(LINFO) << "Actual Tx center frequency is: " << actualValue << " Hz"; // Set bandwidth ret = bladerf_set_bandwidth(device_, BLADERF_MODULE_TX, bw_x, &actualValue); if (ret != 0) { throw IrisException("Failed to set receive bandwidth!"); } LOG(LINFO) << "Actual Tx bandwidth is " << actualValue << " Hz"; // Set VGA1 gain int actualGain; ret = bladerf_set_txvga1(device_, vga1Gain_x); if (ret != 0) { throw IrisException("Failed to set VGA1 gain!"); } bladerf_get_txvga1(device_, &actualGain); LOG(LINFO) << "Actual VGA1 gain is " << actualGain << " dB"; // Set VGA2 gain ret = bladerf_set_txvga2(device_, vga2Gain_x); if (ret != 0) { throw IrisException("Failed to set VGA2 gain!"); } bladerf_get_txvga2(device_, &actualGain); LOG(LINFO) << "Actual VGA2 gain is " << actualGain << " dB"; } catch(const boost::exception &e) { throw IrisException(boost::diagnostic_information(e)); } catch(std::exception& e) { throw IrisException(e.what()); } }