static inline void repeater_init(struct repeater *repeater, struct repeater_config *config) { memset(repeater, 0, sizeof(*repeater)); pthread_mutex_init(&repeater->stderr_lock, NULL); pthread_mutex_init(&repeater->buf_mgmt.lock, NULL); pthread_cond_init(&repeater->buf_mgmt.samples_available, NULL); repeater->buf_mgmt.num_filled = 0; repeater->buf_mgmt.num_buffers = config->num_buffers; /* We must prefill, at a minimum, 1 + the number of TX transfers, * since the intial set of TX callbacks will look to populate each * transfer. Below, we try to set the prefill count halfway between * the number of buffers and the number of transfers. */ repeater->buf_mgmt.prefill_count = config->num_transfers; repeater->buf_mgmt.prefill_count += (repeater->buf_mgmt.num_buffers - config->num_transfers) / 2; assert(repeater->buf_mgmt.prefill_count != 0); bladerf_log_set_verbosity(config->verbosity); }
int main(int argc, char *argv[]) { int status = 0; struct rc_config rc; struct cli_state *state; bool exit_immediately = false; /* If no actions are specified, just show the usage text and exit */ if (argc == 1) { usage(argv[0]); return 0; } init_rc_config(&rc); if (get_rc_config(argc, argv, &rc)) { return 1; } state = cli_state_create(); if (!state) { fprintf(stderr, "Failed to create state object\n"); return 1; } bladerf_log_set_verbosity(rc.verbosity); if (rc.show_help) { usage(argv[0]); exit_immediately = true; } else if (rc.show_version) { printf(BLADERF_CLI_VERSION "\n"); exit_immediately = true; } else if (rc.show_lib_version) { struct bladerf_version version; bladerf_version(&version); printf("%s\n", version.describe); exit_immediately = true; } else if (rc.probe) { status = cmd_handle(state, "probe"); exit_immediately = true; } if (!exit_immediately) { /* Conditionally performed items, depending on runtime config */ status = open_device(&rc, state, status); if (status) { fprintf(stderr, "Could not open device\n"); goto main__issues ; } status = flash_fw(&rc, state, status); if (status) { fprintf(stderr, "Could not flash firmware\n"); goto main__issues ; } status = flash_fpga(&rc, state, status); if (status) { fprintf(stderr, "Could not flash fpga\n"); goto main__issues ; } status = load_fpga(&rc, state, status); if (status) { fprintf(stderr, "Could not load fpga\n"); goto main__issues ; } status = open_script(&rc, state, status); if (status) { fprintf(stderr, "Could not load scripts\n"); goto main__issues ; } main__issues: /* These items are no longer needed */ free(rc.device); rc.device = NULL; free(rc.fw_file); rc.fw_file = NULL; free(rc.fpga_file); rc.fpga_file = NULL; free(rc.script_file); rc.script_file = NULL; /* Drop into interactive mode or begin executing commands * from a script. If we're not requested to do either, exit cleanly */ if (rc.interactive_mode || state->script != NULL) { status = interactive(state, !rc.interactive_mode); } } cli_state_destroy(state); return status; }
static int handle_args(int argc, char *argv[], struct app_params *p) { int c, idx; bool ok; bladerf_log_level log_level; /* Print help */ if (argc == 1) { return 1; } while ((c = getopt_long(argc, argv, OPTSTR, long_options, &idx)) >= 0) { switch (c) { case 'v': log_level = str2loglevel(optarg, &ok); if (!ok) { fprintf(stderr, "Invalid log level: %s\n", optarg); return -1; } else { bladerf_log_set_verbosity(log_level); } break; case 'h': return 1; case 'd': if (p->device_str != NULL) { fprintf(stderr, "Device already specified: %s\n", p->device_str); return -1; } else { p->device_str = strdup(optarg); if (p->device_str == NULL) { perror("strdup"); return -1; } } break; case 's': p->samplerate = str2uint_suffix(optarg, BLADERF_SAMPLERATE_MIN, BLADERF_SAMPLERATE_REC_MAX, freq_suffixes, ARRAY_SIZE(freq_suffixes), &ok); if (!ok) { fprintf(stderr, "Invalid sample rate: %s\n", optarg); return -1; } break; case 'B': p->buf_size = str2uint_suffix(optarg, 1024, UINT_MAX, len_suffixes, ARRAY_SIZE(len_suffixes), &ok); if (!ok || (p->buf_size % 1024) != 0) { fprintf(stderr, "Invalid buffer length: %s\n", optarg); return -1; } break; case 't': p->test_name = strdup(optarg); if (p->test_name == NULL) { perror("strdup"); return -1; } break; case 'S': p->prng_seed = str2uint64(optarg, 1, UINT64_MAX, &ok); if (!ok) { fprintf(stderr, "Invalid seed value: %s\n", optarg); return -1; } break; default: return -1; } } return 0; }
int handle_cmdline(int argc, char *argv[], struct test_params *p) { int c; int idx; bool ok; bladerf_log_level level; test_init_params(p); while ((c = getopt_long(argc, argv, OPTSTR, long_options, &idx)) >= 0) { switch (c) { case 1: level = str2loglevel(optarg, &ok); if (!ok) { log_error("Invalid log level provided: %s\n", optarg); return -1; } else { log_set_verbosity(level); } break; case 2: level = str2loglevel(optarg, &ok); if (!ok) { log_error("Invalid log level provided: %s\n", optarg); return -1; } else { bladerf_log_set_verbosity(level); } break; case 'h': return 1; case 'd': if (p->device_str != NULL) { log_error("Device was already specified.\n"); return -1; } p->device_str = strdup(optarg); if (p->device_str == NULL) { perror("strdup"); return -1; } break; case 's': p->samplerate = str2uint_suffix(optarg, BLADERF_SAMPLERATE_MIN, BLADERF_SAMPLERATE_REC_MAX, freq_suffixes, num_freq_suffixes, &ok); if (!ok) { log_error("Invalid sample rate: %s\n", optarg); return -1; } break; case 'f': p->frequency = str2uint_suffix(optarg, BLADERF_FREQUENCY_MIN, BLADERF_FREQUENCY_MAX, freq_suffixes, num_freq_suffixes, &ok); if (!ok) { log_error("Invalid frequency: %s\n", optarg); return -1; } break; case 'l': if (str2loopback(optarg, &p->loopback) != 0) { log_error("Invalid loopback mode: %s\n", optarg); return -1; } break; case 'i': if (p->in_file) { log_error("Input file already provided.\n"); return -1; } p->in_file = fopen(optarg, "rb"); if (p->in_file == NULL) { log_error("Failed to open input file - %s\n", strerror(errno)); return -1; } break; case 'o': if (p->out_file) { log_error("Output file already provided.\n"); return -1; } p->out_file = fopen(optarg, "wb"); if (p->out_file == NULL) { log_error("Failed to open output file - %s\n", strerror(errno)); return -1; } break; case 'r': p->tx_repetitions = str2uint_suffix(optarg, 1, UINT_MAX, count_suffixes, num_count_suffixes, &ok); if (!ok) { log_error("Invalid TX repetition value: %s\n", optarg); return -1; } break; case 'c': p->rx_count = str2uint_suffix(optarg, 1, UINT_MAX, count_suffixes, num_count_suffixes, &ok); if (!ok) { log_error("Invalid RX count: %s\n", optarg); return -1; } break; case 'b': p->block_size = str2uint_suffix(optarg, 1, UINT_MAX, size_suffixes, num_size_suffixes, &ok); if (!ok) { log_error("Invalid block size: %s\n", optarg); return -1; } break; case 'X': p->num_xfers = str2uint(optarg, 1, UINT_MAX, &ok); if (!ok) { log_error("Invalid stream transfer count: %s\n", optarg); return -1; } break; case 'B': p->stream_buffer_size = str2uint(optarg, 1, UINT_MAX, &ok); if (!ok) { log_error("Invalid stream buffer size: %s\n", optarg); return -1; } break; case 'C': p->stream_buffer_count = str2uint(optarg, 1, UINT_MAX, &ok); if (!ok) { log_error("Invalid stream buffer count: %s\n", optarg); return -1; } break; case 'T': p->timeout_ms = str2uint(optarg, 0, UINT_MAX, &ok); if (!ok) { log_error("Invalid stream timeout: %s\n", optarg); return -1; } break; } } if (p->in_file == NULL && p->out_file == NULL) { log_error("An input or output file is required.\n"); return -1; } if (p->frequency == 0) { p->frequency = DEFAULT_FREQUENCY; } if (p->samplerate == 0) { p->samplerate = DEFAULT_SAMPLERATE; } if (p->tx_repetitions == 0) { p->tx_repetitions = DEFAULT_TX_REPETITIONS; } if (p->rx_count == 0) { p->rx_count = DEFAULT_RX_COUNT; } if (p->block_size == 0) { p->block_size = DEFAULT_BLOCK_SIZE; } return 0; }
int get_params(int argc, char *argv[], struct app_params *p) { int c, idx; bool ok; bladerf_log_level level; memset(p, 0, sizeof(p[0])); p->randval_seed = 1; while((c = getopt_long(argc, argv, OPTARG, long_options, &idx)) != -1) { switch (c) { case 'd': if (p->device_str) { fprintf(stderr, "Device already specified!\n"); return -1; } else { p->device_str = strdup(optarg); if (p->device_str == NULL) { perror("strdup"); return -1; } } break; case 't': if (p->test_name) { fprintf(stderr, "Test already specified!\n"); return -1; } else { p->test_name = strdup(optarg); if (p->test_name == NULL) { perror("strdup"); return -1; } } break; case 's': p->randval_seed = str2uint64(optarg, 1, UINT64_MAX, &ok); if (!ok) { fprintf(stderr, "Invalid seed value: %s\n", optarg); return -1; } break; case 'h': usage(argv[0]); return 1; case 1: p->use_xb200 = true; break; case 'L': list_tests(); return 1; case 'v': level = str2loglevel(optarg, &ok); if (ok) { bladerf_log_set_verbosity(level); } else { fprintf(stderr, "Invalid log level: %s\n", optarg); return -1; } break; default: return -1; } } return 0; }
void rf_blade_suppress_stdout(void *h) { bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_SILENT); }
int main(int argc, char *argv[]) { int status = 0; struct rc_config rc; struct cli_state *state; bool exit_immediately = false; struct str_queue exec_list; /* If no actions are specified, just show the usage text and exit */ if (argc == 1) { usage(argv[0]); return 0; } str_queue_init(&exec_list); init_rc_config(&rc); if (get_rc_config(argc, argv, &rc, &exec_list)) { return 1; } state = cli_state_create(); if (!state) { fprintf(stderr, "Failed to create state object\n"); return 1; } state->exec_list = &exec_list; bladerf_log_set_verbosity(rc.verbosity); if (rc.show_help) { usage(argv[0]); exit_immediately = true; } else if (rc.show_help_interactive) { printf("Interactive Commands:\n\n"); cmd_show_help_all(); exit_immediately = true; } else if (rc.show_version) { printf(BLADERF_CLI_VERSION "\n"); exit_immediately = true; } else if (rc.show_lib_version) { struct bladerf_version version; bladerf_version(&version); printf("%s\n", version.describe); exit_immediately = true; } else if (rc.probe) { status = cmd_handle(state, "probe strict"); exit_immediately = true; } if (!exit_immediately) { check_for_bootloader_devs(); /* Conditionally performed items, depending on runtime config */ status = open_device(&rc, state, status); if (status) { goto main_issues; } status = flash_fw(&rc, state, status); if (status) { goto main_issues; } status = flash_fpga(&rc, state, status); if (status) { goto main_issues; } status = load_fpga(&rc, state, status); if (status) { goto main_issues; } if (rc.script_file) { status = cli_open_script(&state->scripts, rc.script_file); if (status != 0) { fprintf(stderr, "Failed to open script file \"%s\": %s\n", rc.script_file, strerror(-status)); goto main_issues; } } /* Drop into interactive mode or begin executing commands from a a * command-line list or a script. If we're not requested to do either, * exit cleanly */ if (!str_queue_empty(&exec_list) || rc.interactive_mode || cli_script_loaded(state->scripts)) { status = cli_start_tasks(state); if (status == 0) { status = input_loop(state, rc.interactive_mode); } } } main_issues: cli_state_destroy(state); str_queue_deinit(&exec_list); deinit_rc_config(&rc); return status; }
int radio_init_and_configure(struct bladerf *dev, struct radio_params *params) { struct module_config config; int status; #ifdef DEBUG_MODE bladerf_log_set_verbosity(BLADERF_LOG_LEVEL_DEBUG); #endif //Configure TX parameters config.module = BLADERF_MODULE_TX; config.frequency = params->tx_freq; config.bandwidth = BLADERF_BANDWIDTH; config.samplerate = BLADERF_SAMPLE_RATE; config.vga1 = params->tx_vga1_gain; config.vga2 = params->tx_vga2_gain; status = radio_configure_module(dev, &config); if (status != 0){ fprintf(stderr, "Couldn't configure TX module: %s\n", bladerf_strerror(status)); return status; } //Configure RX parameters config.module = BLADERF_MODULE_RX; config.frequency = params->rx_freq; config.bandwidth = BLADERF_BANDWIDTH; config.samplerate = BLADERF_SAMPLE_RATE; config.rx_lna = params->rx_lna_gain; config.vga1 = params->rx_vga1_gain; config.vga2 = params->rx_vga2_gain; status = radio_configure_module(dev, &config); if (status != 0){ fprintf(stderr, "Couldn't configure RX module: %s\n", bladerf_strerror(status)); return status; } //Unset loopback status = bladerf_set_loopback(dev, BLADERF_LB_NONE); if (status != 0){ fprintf(stderr, "Couldn't set loopback: %s", bladerf_strerror(status)); return status; } //Initialize synchronous interface status = radio_init_sync(dev); if (status != 0){ fprintf(stderr, "Couldn't initialize synchronous interface: %s\n", bladerf_strerror(status)); return status; } //Enable tx module status = bladerf_enable_module(dev, BLADERF_MODULE_TX, true); if (status != 0){ fprintf(stderr, "Couldn't enable TX module: %s\n", bladerf_strerror(status)); return status; } //Enable rx module status = bladerf_enable_module(dev, BLADERF_MODULE_RX, true); if (status != 0){ fprintf(stderr, "Couldn't enable RX module: %s\n", bladerf_strerror(status)); return status; } return 0; }