Merge remote-tracking branch 'origin/master' into tx-transfer-sizing

This commit is contained in:
Martin Ling
2022-09-15 15:32:20 +01:00
14 changed files with 591 additions and 81 deletions

View File

@ -42,23 +42,6 @@ extern "C" {
#include "rf_path.h"
#include "cpld_jtag.h"
/* hardware identification number */
#define BOARD_ID_JAWBREAKER 1
#define BOARD_ID_HACKRF_ONE 2
#define BOARD_ID_RAD1O 3
#ifdef JAWBREAKER
#define BOARD_ID BOARD_ID_JAWBREAKER
#endif
#ifdef HACKRF_ONE
#define BOARD_ID BOARD_ID_HACKRF_ONE
#endif
#ifdef RAD1O
#define BOARD_ID BOARD_ID_RAD1O
#endif
/*
* SCU PinMux
*/

View File

@ -0,0 +1,231 @@
/*
* Copyright 2022 Great Scott Gadgets
*
* This file is part of HackRF.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "platform_detect.h"
#include "gpio_lpc.h"
#include "hackrf_core.h"
#include <libopencm3/lpc43xx/scu.h>
#include <libopencm3/lpc43xx/adc.h>
static board_id_t platform = BOARD_ID_UNDETECTED;
static board_rev_t revision = BOARD_REV_UNDETECTED;
static struct gpio_t gpio2_9_on_P5_0 = GPIO(2, 9);
static struct gpio_t gpio3_6_on_P6_10 = GPIO(3, 6);
#define P5_0_PUP (1 << 0)
#define P5_0_PDN (1 << 1)
#define P6_10_PUP (1 << 2)
#define P6_10_PDN (1 << 3)
/*
* Jawbreaker has a pull-down on P6_10 and nothing on P5_0.
* rad1o has a pull-down on P6_10 and a pull-down on P5_0.
* HackRF One OG has a pull-down on P6_10 and a pull-up on P5_0.
* HackRF One r9 has a pull-up on P6_10 and a pull-down on P5_0.
*/
#define JAWBREAKER_RESISTORS (P6_10_PDN)
#define RAD1O_RESISTORS (P6_10_PDN | P5_0_PDN)
#define HACKRF1_OG_RESISTORS (P6_10_PDN | P5_0_PUP)
#define HACKRF1_R9_RESISTORS (P6_10_PUP | P5_0_PDN)
/*
* LEDs are configured so that they flash if the detected hardware platform is
* not supported by the firmware binary. Only two LEDs are flashed for a
* hardware detection failure, but three LEDs are flashed if CPLD configuration
* fails.
*/
static struct gpio_t gpio_led1 = GPIO(2, 1);
static struct gpio_t gpio_led2 = GPIO(2, 2);
static struct gpio_t gpio_led3 = GPIO(2, 8);
uint8_t adc_read(uint8_t pin)
{
pin &= 0x7;
uint8_t pin_mask = (1 << pin);
ADC0_CR = ADC_CR_SEL(pin_mask) | ADC_CR_CLKDIV(45) | ADC_CR_CLKS(2) | ADC_CR_PDN |
ADC_CR_START(1);
while (!(ADC0_GDR & ADC_DR_DONE) || (((ADC0_GDR >> 24) & 0x7) != pin)) {}
return (ADC0_GDR >> 6) & 0x03FF;
}
void adc_off(void)
{
ADC0_CR = 0;
}
/*
* Starting with r6, HackRF One has pin straps on ADC pins that indicate
* hardware revision. Those pins were unconnected prior to r6, so we test for
* the unconnected state by averaging several ADC readings.
*/
#define NUM_SAMPLES (10)
#define LOW_THRESHOLD (2 * NUM_SAMPLES)
#define HIGH_THRESHOLD (253 * NUM_SAMPLES)
typedef enum {
PIN_STRAP_HIGH,
PIN_STRAP_LOW,
PIN_STRAP_ABSENT,
} pin_strap_t;
pin_strap_t check_pin_strap(uint8_t pin)
{
int i;
uint32_t sum = 0;
for (i = 0; i < NUM_SAMPLES; i++) {
sum += adc_read(pin);
}
adc_off();
if (sum > HIGH_THRESHOLD) {
return PIN_STRAP_HIGH;
} else if (sum < LOW_THRESHOLD) {
return PIN_STRAP_LOW;
} else {
return PIN_STRAP_ABSENT;
}
}
void detect_hardware_platform(void)
{
uint8_t detected_resistors = 0;
scu_pinmux(SCU_PINMUX_LED2, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
scu_pinmux(SCU_PINMUX_LED3, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
gpio_input(&gpio_led1);
gpio_output(&gpio_led2);
gpio_output(&gpio_led3);
gpio_input(&gpio2_9_on_P5_0);
gpio_input(&gpio3_6_on_P6_10);
scu_pinmux(P5_0, SCU_GPIO_PUP | SCU_CONF_FUNCTION0);
scu_pinmux(P6_10, SCU_GPIO_PUP | SCU_CONF_FUNCTION0);
delay(20);
scu_pinmux(P5_0, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
scu_pinmux(P6_10, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
delay(20);
detected_resistors |= (gpio_read(&gpio2_9_on_P5_0)) ? P5_0_PUP : 0;
detected_resistors |= (gpio_read(&gpio3_6_on_P6_10)) ? P6_10_PUP : 0;
scu_pinmux(P5_0, SCU_GPIO_PUP | SCU_CONF_FUNCTION0);
scu_pinmux(P6_10, SCU_GPIO_PUP | SCU_CONF_FUNCTION0);
delay(20);
detected_resistors |= (gpio_read(&gpio2_9_on_P5_0)) ? 0 : P5_0_PDN;
detected_resistors |= (gpio_read(&gpio3_6_on_P6_10)) ? 0 : P6_10_PDN;
scu_pinmux(P5_0, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
scu_pinmux(P6_10, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
switch (detected_resistors) {
case JAWBREAKER_RESISTORS:
if (!(supported_platform() & PLATFORM_JAWBREAKER)) {
halt_and_flash(3000000);
}
platform = BOARD_ID_JAWBREAKER;
return;
case RAD1O_RESISTORS:
if (!(supported_platform() & PLATFORM_RAD1O)) {
halt_and_flash(3000000);
}
platform = BOARD_ID_RAD1O;
return;
case HACKRF1_OG_RESISTORS:
if (!(supported_platform() & PLATFORM_HACKRF1_OG)) {
halt_and_flash(3000000);
}
platform = BOARD_ID_HACKRF1_OG;
break;
case HACKRF1_R9_RESISTORS:
if (!(supported_platform() & PLATFORM_HACKRF1_R9)) {
halt_and_flash(3000000);
}
platform = BOARD_ID_HACKRF1_R9;
break;
default:
platform = BOARD_ID_UNRECOGNIZED;
halt_and_flash(1000000);
}
pin_strap_t adc0_3 = check_pin_strap(3);
pin_strap_t adc0_4 = check_pin_strap(4);
pin_strap_t adc0_7 = check_pin_strap(7);
if ((adc0_3 == PIN_STRAP_ABSENT) && (adc0_4 == PIN_STRAP_ABSENT) &&
(adc0_7 == PIN_STRAP_ABSENT) && (platform == BOARD_ID_HACKRF1_OG)) {
revision = BOARD_REV_HACKRF1_OLD;
} else if (
(adc0_3 == PIN_STRAP_HIGH) && (adc0_4 == PIN_STRAP_HIGH) &&
(platform == BOARD_ID_HACKRF1_OG)) {
revision = BOARD_REV_HACKRF1_R6;
} else if (
(adc0_3 == PIN_STRAP_LOW) && (adc0_4 == PIN_STRAP_HIGH) &&
(platform == BOARD_ID_HACKRF1_OG)) {
revision = BOARD_REV_HACKRF1_R7;
} else if (
(adc0_3 == PIN_STRAP_HIGH) && (adc0_4 == PIN_STRAP_LOW) &&
(platform == BOARD_ID_HACKRF1_OG)) {
revision = BOARD_REV_HACKRF1_R8;
} else if (
(adc0_3 == PIN_STRAP_LOW) && (adc0_4 == PIN_STRAP_LOW) &&
(platform == BOARD_ID_HACKRF1_R9)) {
revision = BOARD_REV_HACKRF1_R9;
} else {
revision = BOARD_REV_UNRECOGNIZED;
}
if ((revision > BOARD_REV_HACKRF1_OLD) && (adc0_7 == PIN_STRAP_LOW)) {
revision |= BOARD_REV_GSG;
}
}
board_id_t detected_platform(void)
{
return platform;
}
board_rev_t detected_revision(void)
{
return revision;
}
uint32_t supported_platform(void)
{
uint32_t binary_platform = 0;
#ifdef JAWBREAKER
binary_platform = PLATFORM_JAWBREAKER;
#endif
#ifdef HACKRF_ONE
binary_platform = PLATFORM_HACKRF1_OG;
#endif
#ifdef RAD1O
binary_platform = PLATFORM_RAD1O;
#endif
return binary_platform;
}

View File

@ -0,0 +1,64 @@
/*
* Copyright 2022 Great Scott Gadgets
*
* This file is part of HackRF.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __PLATFORM_DETECT_H__
#define __PLATFORM_DETECT_H__
#include <stdint.h>
#define BOARD_REV_GSG (0x80)
#define PLATFORM_JAWBREAKER (1 << 0)
#define PLATFORM_HACKRF1_OG (1 << 1)
#define PLATFORM_RAD1O (1 << 2)
#define PLATFORM_HACKRF1_R9 (1 << 3)
typedef enum {
BOARD_ID_JELLYBEAN = 0,
BOARD_ID_JAWBREAKER = 1,
BOARD_ID_HACKRF1_OG = 2, /* HackRF One prior to r9 */
BOARD_ID_RAD1O = 3,
BOARD_ID_HACKRF1_R9 = 4,
BOARD_ID_UNRECOGNIZED = 0xFE, /* tried detection but did not recognize board */
BOARD_ID_UNDETECTED = 0xFF, /* detection not yet attempted */
} board_id_t;
typedef enum {
BOARD_REV_HACKRF1_OLD = 0,
BOARD_REV_HACKRF1_R6 = 1,
BOARD_REV_HACKRF1_R7 = 2,
BOARD_REV_HACKRF1_R8 = 3,
BOARD_REV_HACKRF1_R9 = 4,
BOARD_REV_GSG_HACKRF1_R6 = 0x81,
BOARD_REV_GSG_HACKRF1_R7 = 0x82,
BOARD_REV_GSG_HACKRF1_R8 = 0x83,
BOARD_REV_GSG_HACKRF1_R9 = 0x84,
BOARD_REV_UNRECOGNIZED =
0xFE, /* tried detection but did not recognize revision */
BOARD_REV_UNDETECTED = 0xFF, /* detection not yet attempted */
} board_rev_t;
void detect_hardware_platform(void);
board_id_t detected_platform(void);
board_rev_t detected_revision(void);
uint32_t supported_platform(void);
#endif //__PLATFORM_DETECT_H__

View File

@ -22,9 +22,11 @@
#include "si5351c.h"
enum pll_sources active_clock_source = PLL_SOURCE_UNINITIALIZED;
#include <stdbool.h>
static enum pll_sources active_clock_source = PLL_SOURCE_UNINITIALIZED;
/* External clock output default is deactivated as it creates noise */
uint8_t clk3_ctrl = SI5351C_CLK_POWERDOWN | SI5351C_CLK_INT_MODE;
static bool clkout_enabled = false;
/* write to single register */
void si5351c_write_single(si5351c_driver_t* const drv, uint8_t reg, uint8_t val)
@ -177,6 +179,8 @@ void si5351c_configure_clock_control(
const enum pll_sources source)
{
uint8_t pll;
uint8_t clk3_ctrl;
#ifdef RAD1O
(void) source;
/* PLLA on XTAL */
@ -192,6 +196,14 @@ void si5351c_configure_clock_control(
pll = SI5351C_CLK_PLL_SRC_A;
}
#endif
if (clkout_enabled) {
clk3_ctrl = SI5351C_CLK_INT_MODE | SI5351C_CLK_PLL_SRC(pll) |
SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) |
SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_8MA);
} else {
clk3_ctrl = SI5351C_CLK_POWERDOWN | SI5351C_CLK_INT_MODE;
}
/* Clock to CPU is deactivated as it is not used and creates noise */
/* External clock output is kept in current state */
uint8_t data[] = {
@ -231,13 +243,12 @@ void si5351c_enable_clock_outputs(si5351c_driver_t* const drv)
/* Enable CLK outputs 0, 1, 2, 4, 5 only. */
/* 7: Clock to CPU is deactivated as it is not used and creates noise */
/* 3: External clock output is deactivated by default */
// uint8_t data[] = { 3, ~((1 << 0) | (1 << 1) | (1 << 2) | (1 << 4) | (1 << 5))};
uint8_t data[] = {
SI5351C_REG_OUTPUT_EN,
SI5351C_CLK_ENABLE(0) | SI5351C_CLK_ENABLE(1) | SI5351C_CLK_ENABLE(2) |
SI5351C_CLK_DISABLE(3) | SI5351C_CLK_ENABLE(4) |
SI5351C_CLK_ENABLE(5) | SI5351C_CLK_DISABLE(6) |
SI5351C_CLK_DISABLE(7)};
uint8_t value = SI5351C_CLK_ENABLE(0) | SI5351C_CLK_ENABLE(1) |
SI5351C_CLK_ENABLE(2) | SI5351C_CLK_ENABLE(4) | SI5351C_CLK_ENABLE(5) |
SI5351C_CLK_DISABLE(6) | SI5351C_CLK_DISABLE(7);
value |= (clkout_enabled) ? SI5351C_CLK_ENABLE(3) : SI5351C_CLK_DISABLE(3);
uint8_t data[] = {SI5351C_REG_OUTPUT_EN, value};
si5351c_write(drv, data, sizeof(data));
}
@ -277,43 +288,11 @@ bool si5351c_clkin_signal_valid(si5351c_driver_t* const drv)
void si5351c_clkout_enable(si5351c_driver_t* const drv, uint8_t enable)
{
/* Set optput in output enable register */
uint8_t output_enable = si5351c_read_single(drv, 3);
output_enable = output_enable & !SI5351C_CLK_DISABLE(3);
if (enable) {
output_enable = output_enable | SI5351C_CLK_ENABLE(3);
} else {
output_enable = output_enable | SI5351C_CLK_DISABLE(3);
}
uint8_t oe_data[] = {SI5351C_REG_OUTPUT_EN, output_enable};
si5351c_write(drv, oe_data, 2);
clkout_enabled = (enable > 0);
/* Configure clock to 10MHz (TODO customisable?) */
/* Configure clock to 10MHz */
si5351c_configure_multisynth(drv, 3, 80 * 128 - 512, 0, 1, 0);
/* Set power up/doen in CLK3 control register*/
uint8_t pll;
#ifdef RAD1O
/* PLLA on XTAL */
pll = SI5351C_CLK_PLL_SRC_A;
#endif
#if (defined JAWBREAKER || defined HACKRF_ONE)
if (active_clock_source == PLL_SOURCE_CLKIN) {
/* PLLB on CLKIN */
pll = SI5351C_CLK_PLL_SRC_B;
} else {
/* PLLA on XTAL */
pll = SI5351C_CLK_PLL_SRC_A;
}
#endif
if (enable) {
clk3_ctrl = SI5351C_CLK_INT_MODE | SI5351C_CLK_PLL_SRC(pll) |
SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) |
SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_8MA);
} else {
clk3_ctrl = SI5351C_CLK_POWERDOWN | SI5351C_CLK_INT_MODE;
}
uint8_t clk3_data[] = {SI5351C_REG_CLK3_CTRL, clk3_ctrl};
si5351c_write(drv, clk3_data, 2);
si5351c_configure_clock_control(drv, active_clock_source);
si5351c_enable_clock_outputs(drv);
}

View File

@ -184,6 +184,7 @@ macro(DeclareTargets)
${PATH_HACKRF_FIRMWARE_COMMON}/spi_ssp.c
${PATH_HACKRF_FIRMWARE_COMMON}/gpio_lpc.c
${PATH_HACKRF_FIRMWARE_COMMON}/hackrf_ui.c
${PATH_HACKRF_FIRMWARE_COMMON}/platform_detect.c
)
if(BOARD STREQUAL "RAD1O")

View File

@ -52,8 +52,8 @@
#include "usb_api_m0_state.h"
#include "cpld_xc2c.h"
#include "portapack.h"
#include "hackrf_ui.h"
#include "platform_detect.h"
extern uint32_t __m0_start__;
extern uint32_t __m0_end__;
@ -119,6 +119,8 @@ static usb_request_handler_fn vendor_request_handler[] = {
usb_vendor_request_set_tx_underrun_limit,
usb_vendor_request_set_rx_overrun_limit,
usb_vendor_request_get_clkin_status,
usb_vendor_request_read_board_rev,
usb_vendor_request_read_supported_platform,
};
static const uint32_t vendor_request_handler_count =
@ -224,6 +226,7 @@ int main(void)
// Copy M0 image from ROM before SPIFI is disabled
m0_rom_to_ram();
detect_hardware_platform();
pin_setup();
enable_1v8_power();
#if (defined HACKRF_ONE || defined RAD1O)

View File

@ -21,6 +21,7 @@
*/
#include "usb_api_board_info.h"
#include "platform_detect.h"
#include <hackrf_core.h>
#include <rom_iap.h>
@ -37,7 +38,7 @@ usb_request_status_t usb_vendor_request_read_board_id(
const usb_transfer_stage_t stage)
{
if (stage == USB_TRANSFER_STAGE_SETUP) {
endpoint->buffer[0] = BOARD_ID;
endpoint->buffer[0] = detected_platform();
usb_transfer_schedule_block(
endpoint->in,
&endpoint->buffer,
@ -122,3 +123,41 @@ usb_request_status_t usb_vendor_request_reset(
}
return USB_REQUEST_STATUS_OK;
}
usb_request_status_t usb_vendor_request_read_board_rev(
usb_endpoint_t* const endpoint,
const usb_transfer_stage_t stage)
{
if (stage == USB_TRANSFER_STAGE_SETUP) {
endpoint->buffer[0] = detected_revision();
usb_transfer_schedule_block(
endpoint->in,
&endpoint->buffer,
1,
NULL,
NULL);
usb_transfer_schedule_ack(endpoint->out);
}
return USB_REQUEST_STATUS_OK;
}
usb_request_status_t usb_vendor_request_read_supported_platform(
usb_endpoint_t* const endpoint,
const usb_transfer_stage_t stage)
{
if (stage == USB_TRANSFER_STAGE_SETUP) {
uint32_t platform = supported_platform();
endpoint->buffer[0] = (platform >> 24) & 0xff;
endpoint->buffer[1] = (platform >> 16) & 0xff;
endpoint->buffer[2] = (platform >> 8) & 0xff;
endpoint->buffer[3] = platform & 0xff;
usb_transfer_schedule_block(
endpoint->in,
&endpoint->buffer,
4,
NULL,
NULL);
usb_transfer_schedule_ack(endpoint->out);
}
return USB_REQUEST_STATUS_OK;
}

View File

@ -45,5 +45,11 @@ usb_request_status_t usb_vendor_request_read_partid_serialno(
usb_request_status_t usb_vendor_request_reset(
usb_endpoint_t* const endpoint,
const usb_transfer_stage_t stage);
usb_request_status_t usb_vendor_request_read_board_rev(
usb_endpoint_t* const endpoint,
const usb_transfer_stage_t stage);
usb_request_status_t usb_vendor_request_read_supported_platform(
usb_endpoint_t* const endpoint,
const usb_transfer_stage_t stage);
#endif /* end of include guard: __USB_API_BOARD_INFO_H__ */

View File

@ -26,10 +26,68 @@
#include <stdio.h>
#include <stdlib.h>
void print_board_rev(uint8_t board_rev)
{
switch (board_rev) {
case BOARD_REV_UNDETECTED:
printf("Error: Hardware revision not yet detected by firmware.\n");
return;
case BOARD_REV_UNRECOGNIZED:
printf("Warning: Hardware revision not recognized by firmware.\n");
return;
}
printf("Hardware Revision: %s\n", hackrf_board_rev_name(board_rev));
if (board_rev > BOARD_REV_HACKRF1_OLD) {
if (board_rev & HACKRF_BOARD_REV_GSG) {
printf("Hardware appears to have been manufactured by Great Scott Gadgets.\n");
} else {
printf("Hardware does not appear to have been manufactured by Great Scott Gadgets.\n");
}
}
}
void print_supported_platform(uint32_t platform, uint8_t board_id)
{
printf("Hardware supported by installed firmware:\n");
if (platform & HACKRF_PLATFORM_JAWBREAKER) {
printf(" Jawbreaker\n");
}
if (platform & HACKRF_PLATFORM_RAD1O) {
printf(" rad1o\n");
}
if ((platform & HACKRF_PLATFORM_HACKRF1_OG) ||
(platform & HACKRF_PLATFORM_HACKRF1_R9)) {
printf(" HackRF One\n");
}
switch (board_id) {
case BOARD_ID_HACKRF1_OG:
if (!(platform & HACKRF_PLATFORM_HACKRF1_OG)) {
printf("Error: Firmware does not support HackRF One revisions older than r9.\n");
}
break;
case BOARD_ID_HACKRF1_R9:
if (!(platform & HACKRF_PLATFORM_HACKRF1_R9)) {
printf("Error: Firmware does not support HackRF One r9.\n");
}
break;
case BOARD_ID_JAWBREAKER:
if (platform & HACKRF_PLATFORM_JAWBREAKER) {
break;
}
case BOARD_ID_RAD1O:
if (platform & HACKRF_PLATFORM_RAD1O) {
break;
}
printf("Error: Firmware does not support hardware platform.\n");
}
}
int main(void)
{
int result = HACKRF_SUCCESS;
uint8_t board_id = BOARD_ID_INVALID;
uint8_t board_id = BOARD_ID_UNDETECTED;
uint8_t board_rev = BOARD_REV_UNDETECTED;
uint32_t supported_platform = 0;
char version[255 + 1];
uint16_t usb_version;
read_partid_serialno_t read_partid_serialno;
@ -130,6 +188,31 @@ int main(void)
read_partid_serialno.part_id[0],
read_partid_serialno.part_id[1]);
if ((usb_version >= 0x0106) && ((board_id == 2) || (board_id == 4))) {
result = hackrf_board_rev_read(device, &board_rev);
if (result != HACKRF_SUCCESS) {
fprintf(stderr,
"hackrf_board_rev_read() failed: %s (%d)\n",
hackrf_error_name(result),
result);
return EXIT_FAILURE;
}
print_board_rev(board_rev);
}
if (usb_version >= 0x0106) {
result = hackrf_supported_platform_read(
device,
&supported_platform);
if (result != HACKRF_SUCCESS) {
fprintf(stderr,
"hackrf_supported_platform_read() failed: %s (%d)\n",
hackrf_error_name(result),
result);
return EXIT_FAILURE;
}
print_supported_platform(supported_platform, board_id);
}
result = hackrf_get_operacake_boards(device, &operacakes[0]);
if ((result != HACKRF_SUCCESS) &&
(result != HACKRF_ERROR_USB_API_VERSION)) {

View File

@ -78,7 +78,7 @@ int compatibility_check(uint8_t* data, int length, hackrf_device* device)
dev_str = "HackRF Jawbreaker";
str_len = 17;
break;
case BOARD_ID_HACKRF_ONE:
case BOARD_ID_HACKRF1_OG:
dev_str = "HackRF One";
str_len = 10;
break;
@ -87,7 +87,7 @@ int compatibility_check(uint8_t* data, int length, hackrf_device* device)
str_len = 5;
break;
default:
printf("Unknown Board ID");
printf("Unsupported Board ID");
return 1;
}
// Search for dev_str in uint8_t array of bytes that we're flashing

View File

@ -516,8 +516,10 @@ int tx_callback(hackrf_transfer* transfer)
/* Fill the buffer. */
if (file == NULL) {
/* Transmit continuous wave with specific amplitude */
for (i = 0; i < bytes_to_read; i++)
transfer->buffer[i] = -(uint8_t) amplitude;
for (i = 0; i < bytes_to_read; i += 2) {
transfer->buffer[i] = amplitude;
transfer->buffer[i + 1] = 0;
}
bytes_read = bytes_to_read;
} else {
/* Read samples from file. */
@ -632,7 +634,7 @@ static void usage()
printf("\t[-S buf_size] # Enable receive streaming with buffer size buf_size.\n");
#endif
printf("\t[-B] # Print buffer statistics during transfer\n");
printf("\t[-c amplitude] # CW signal source mode, amplitude 0-128 (DC value to DAC).\n");
printf("\t[-c amplitude] # CW signal source mode, amplitude 0-127 (DC value to DAC).\n");
printf("\t[-R] # Repeat TX mode (default is off) \n");
printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in Hz.\n");
printf("\tPossible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz, default <= 0.75 * sample_rate_hz.\n");
@ -1022,9 +1024,9 @@ int main(int argc, char** argv)
if (signalsource) {
transceiver_mode = TRANSCEIVER_MODE_SS;
if (amplitude > 128) {
if (amplitude > 127) {
fprintf(stderr,
"argument error: amplitude must be between 0 and 128.\n");
"argument error: amplitude must be between 0 and 127.\n");
usage();
return EXIT_FAILURE;
}
@ -1359,8 +1361,8 @@ int main(int argc, char** argv)
fprintf(stderr, "Waiting for sync...\n");
} else {
double full_scale_ratio = (double) stream_power_now /
(byte_count_now * 128 * 128);
double dB_full_scale = 10 * log10(full_scale_ratio);
(byte_count_now * 127 * 127);
double dB_full_scale = 10 * log10(full_scale_ratio) + 3.0;
fprintf(stderr,
"%4.1f MiB / %5.3f sec = %4.1f MiB/second, average power %3.1f dBfs",
(byte_count_now / 1e6f),

View File

@ -100,6 +100,8 @@ typedef enum {
HACKRF_VENDOR_REQUEST_SET_TX_UNDERRUN_LIMIT = 42,
HACKRF_VENDOR_REQUEST_SET_RX_OVERRUN_LIMIT = 43,
HACKRF_VENDOR_REQUEST_GET_CLKIN_STATUS = 44,
HACKRF_VENDOR_REQUEST_BOARD_REV_READ = 45,
HACKRF_VENDOR_REQUEST_SUPPORTED_PLATFORM_READ = 46,
} hackrf_vendor_request;
#define USB_CONFIG_STANDARD 0x1
@ -2156,17 +2158,23 @@ const char* ADDCALL hackrf_board_id_name(enum hackrf_board_id board_id)
case BOARD_ID_JAWBREAKER:
return "Jawbreaker";
case BOARD_ID_HACKRF_ONE:
case BOARD_ID_HACKRF1_OG:
return "HackRF One";
case BOARD_ID_RAD1O:
return "rad1o";
case BOARD_ID_INVALID:
return "Invalid Board ID";
case BOARD_ID_HACKRF1_R9:
return "HackRF One";
case BOARD_ID_UNRECOGNIZED:
return "unrecognized";
case BOARD_ID_UNDETECTED:
return "undetected";
default:
return "Unknown Board ID";
return "unknown";
}
}
@ -2799,6 +2807,85 @@ uint32_t ADDCALL hackrf_get_transfer_queue_depth(hackrf_device* device)
return TRANSFER_COUNT;
}
int ADDCALL hackrf_board_rev_read(hackrf_device* device, uint8_t* value)
{
USB_API_REQUIRED(device, 0x0106)
int result;
result = libusb_control_transfer(
device->usb_device,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
HACKRF_VENDOR_REQUEST_BOARD_REV_READ,
0,
0,
value,
1,
0);
if (result < 1) {
last_libusb_error = result;
return HACKRF_ERROR_LIBUSB;
} else {
return HACKRF_SUCCESS;
}
}
extern ADDAPI const char* ADDCALL hackrf_board_rev_name(enum hackrf_board_rev board_rev)
{
switch (board_rev) {
case BOARD_REV_HACKRF1_OLD:
return "older than r6";
case BOARD_REV_HACKRF1_R6:
case BOARD_REV_GSG_HACKRF1_R6:
return "r6";
case BOARD_REV_HACKRF1_R7:
case BOARD_REV_GSG_HACKRF1_R7:
return "r7";
case BOARD_REV_HACKRF1_R8:
case BOARD_REV_GSG_HACKRF1_R8:
return "r8";
case BOARD_REV_HACKRF1_R9:
case BOARD_REV_GSG_HACKRF1_R9:
return "r9";
case BOARD_ID_UNRECOGNIZED:
return "unrecognized";
case BOARD_ID_UNDETECTED:
return "undetected";
default:
return "unknown";
}
}
int ADDCALL hackrf_supported_platform_read(hackrf_device* device, uint32_t* value)
{
unsigned char data[4];
USB_API_REQUIRED(device, 0x0106)
int result;
result = libusb_control_transfer(
device->usb_device,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
HACKRF_VENDOR_REQUEST_SUPPORTED_PLATFORM_READ,
0,
0,
&data[0],
4,
0);
if (result < 1) {
last_libusb_error = result;
return HACKRF_ERROR_LIBUSB;
} else {
*value = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
return HACKRF_SUCCESS;
}
}
#ifdef __cplusplus
} // __cplusplus defined.
#endif

View File

@ -74,12 +74,36 @@ enum hackrf_error {
HACKRF_ERROR_OTHER = -9999,
};
#define HACKRF_BOARD_REV_GSG (0x80)
#define HACKRF_PLATFORM_JAWBREAKER (1 << 0)
#define HACKRF_PLATFORM_HACKRF1_OG (1 << 1)
#define HACKRF_PLATFORM_RAD1O (1 << 2)
#define HACKRF_PLATFORM_HACKRF1_R9 (1 << 3)
enum hackrf_board_id {
BOARD_ID_JELLYBEAN = 0,
BOARD_ID_JAWBREAKER = 1,
BOARD_ID_HACKRF_ONE = 2,
BOARD_ID_HACKRF1_OG = 2, /* HackRF One prior to r9 */
BOARD_ID_RAD1O = 3,
BOARD_ID_INVALID = 0xFF,
BOARD_ID_HACKRF1_R9 = 4,
BOARD_ID_UNRECOGNIZED = 0xFE, /* tried detection but did not recognize board */
BOARD_ID_UNDETECTED = 0xFF, /* detection not yet attempted */
};
enum hackrf_board_rev {
BOARD_REV_HACKRF1_OLD = 0,
BOARD_REV_HACKRF1_R6 = 1,
BOARD_REV_HACKRF1_R7 = 2,
BOARD_REV_HACKRF1_R8 = 3,
BOARD_REV_HACKRF1_R9 = 4,
BOARD_REV_GSG_HACKRF1_R6 = 0x81,
BOARD_REV_GSG_HACKRF1_R7 = 0x82,
BOARD_REV_GSG_HACKRF1_R8 = 0x83,
BOARD_REV_GSG_HACKRF1_R9 = 0x84,
BOARD_REV_UNRECOGNIZED =
0xFE, /* tried detection but did not recognize revision */
BOARD_REV_UNDETECTED = 0xFF, /* detection not yet attempted */
};
enum hackrf_usb_board_id {
@ -466,6 +490,14 @@ extern ADDAPI size_t ADDCALL hackrf_get_transfer_buffer_size(hackrf_device* devi
extern ADDAPI uint32_t ADDCALL hackrf_get_transfer_queue_depth(hackrf_device* device);
extern ADDAPI int ADDCALL hackrf_board_rev_read(hackrf_device* device, uint8_t* value);
extern ADDAPI const char* ADDCALL hackrf_board_rev_name(enum hackrf_board_rev board_rev);
extern ADDAPI int ADDCALL hackrf_supported_platform_read(
hackrf_device* device,
uint32_t* value);
#ifdef __cplusplus
} // __cplusplus defined.
#endif