firmware version string

This commit is contained in:
Michael Ossmann
2013-02-23 10:22:58 -07:00
parent c703b380cf
commit d2b35517b3
5 changed files with 56 additions and 4 deletions

View File

@ -34,12 +34,15 @@ HACKRF_OPTS = -D$(BOARD)
# comment to disable RF transmission
HACKRF_OPTS += -DTX_ENABLE
# automatic git version when working out of git
VERSION_STRING ?= -D'VERSION_STRING="git-$(shell git log -n 1 --format=%h)"'
HACKRF_OPTS += $(VERSION_STRING)
LDSCRIPT ?= ../common/LPC4330_M4.ld
LIBOPENCM3 ?= /usr/local/arm-none-eabi
PREFIX ?= arm-none-eabi
#PREFIX ?= arm-elf
CC = $(PREFIX)-gcc
LD = $(PREFIX)-gcc
OBJCOPY = $(PREFIX)-objcopy
@ -51,7 +54,6 @@ CFLAGS += -std=c99 -Os -g3 -Wall -Wextra -I$(LIBOPENCM3)/include -I../common \
-fno-common -mcpu=cortex-m4 -mthumb -MD \
-mfloat-abi=hard -mfpu=fpv4-sp-d16 \
$(HACKRF_OPTS)
#LDSCRIPT ?= $(BINARY).ld
LDFLAGS += -L$(TOOLCHAIN_DIR)/lib/armv7e-m/fpu \
-L../common \
-L$(LIBOPENCM3)/lib -L$(LIBOPENCM3)/lib/lpc43xx \

View File

@ -51,6 +51,7 @@ usb_transfer_descriptor_t usb_td_bulk[2] ATTR_ALIGNED(64);
const uint_fast8_t usb_td_bulk_count = sizeof(usb_td_bulk) / sizeof(usb_td_bulk[0]);
uint8_t spiflash_buffer[W25Q80BV_PAGE_LEN];
char version_string[] = VERSION_STRING;
static void usb_init_buffers_bulk() {
usb_td_bulk[0].next_dtd_pointer = USB_TD_NEXT_DTD_POINTER_TERMINATE;
@ -470,6 +471,19 @@ usb_request_status_t usb_vendor_request_read_board_id(
return USB_REQUEST_STATUS_OK;
}
usb_request_status_t usb_vendor_request_read_version_string(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
uint8_t length;
if (stage == USB_TRANSFER_STAGE_SETUP) {
length = (uint8_t)strlen(version_string);
usb_endpoint_schedule(endpoint->in, version_string, length);
usb_endpoint_schedule_ack(endpoint->out);
}
return USB_REQUEST_STATUS_OK;
}
static const usb_request_handler_fn vendor_request_handler[] = {
NULL,
usb_vendor_request_set_transceiver_mode,
@ -485,7 +499,8 @@ static const usb_request_handler_fn vendor_request_handler[] = {
usb_vendor_request_write_spiflash,
usb_vendor_request_read_spiflash,
usb_vendor_request_write_cpld,
usb_vendor_request_read_board_id
usb_vendor_request_read_board_id,
usb_vendor_request_read_version_string
};
static const uint32_t vendor_request_handler_count =

View File

@ -31,6 +31,7 @@ int main(int argc, char** argv)
hackrf_device* device = NULL;
int result = HACKRF_SUCCESS;
uint8_t board_id = BOARD_ID_INVALID;
char version[255 + 1];
result = hackrf_init();
if (result != HACKRF_SUCCESS) {
@ -58,6 +59,15 @@ int main(int argc, char** argv)
printf("Board ID Number: %d (%s)\n", board_id,
hackrf_board_id_name(board_id));
result = hackrf_version_string_read(device, &version[0], 255);
if (result != HACKRF_SUCCESS) {
fprintf(stderr, "hackrf_version_string_read() failed: %s (%d)\n",
hackrf_error_name(result), result);
return EXIT_FAILURE;
}
printf("Firmware Version: %s\n", version);
result = hackrf_close(device);
if (result != HACKRF_SUCCESS) {
fprintf(stderr, "hackrf_close() failed: %s (%d)\n",

View File

@ -43,7 +43,8 @@ typedef enum {
HACKRF_VENDOR_REQUEST_SPIFLASH_WRITE = 11,
HACKRF_VENDOR_REQUEST_SPIFLASH_READ = 12,
HACKRF_VENDOR_REQUEST_CPLD_WRITE = 13,
HACKRF_VENDOR_REQUEST_BOARD_ID_READ = 14
HACKRF_VENDOR_REQUEST_BOARD_ID_READ = 14,
HACKRF_VENDOR_REQUEST_VERSION_STRING_READ = 15
} hackrf_vendor_request;
typedef enum {
@ -545,6 +546,28 @@ int hackrf_board_id_read(hackrf_device* device, uint8_t* value) {
}
}
int hackrf_version_string_read(hackrf_device* device, char* version,
uint8_t length)
{
int result = libusb_control_transfer(
device->usb_device,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
HACKRF_VENDOR_REQUEST_VERSION_STRING_READ,
0,
0,
(unsigned char*)version,
length,
0
);
if (result < 0) {
return HACKRF_ERROR_LIBUSB;
} else {
version[result] = '\0';
return HACKRF_SUCCESS;
}
}
static void* transfer_threadproc(void* arg) {
hackrf_device* device = (hackrf_device*)arg;

View File

@ -90,6 +90,8 @@ int hackrf_cpld_write(hackrf_device* device, const uint16_t length,
unsigned char* const data);
int hackrf_board_id_read(hackrf_device* device, uint8_t* value);
int hackrf_version_string_read(hackrf_device* device, char* version,
uint8_t length);
const char* hackrf_error_name(enum hackrf_error errcode);
const char* hackrf_board_id_name(enum hackrf_board_id board_id);