Skip to content

Commit

Permalink
fx3_firmware, libbladeRF: Packed FW version structure, moved serial #…
Browse files Browse the repository at this point in the history
… init

The bladerf_fx3_version structure is transferred as-is. Currently this
likely doesn't pose any isseus for most machines, since it contains only
two uint32_t's. It's now marked to be packed, just to be safe.

The serial number initialization (ExtracSerial()) has been moved before
the CyU3PConnectState() call to remove a potential race condition.

Macro definitions are now provided for string descriptors.
  • Loading branch information
jynik committed Oct 4, 2013
1 parent f6dda44 commit 58c13c6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
21 changes: 19 additions & 2 deletions firmware_common/bladeRF.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,32 @@
#define BLADE_USB_CMD_INVALIDATE_CAL_CACHE 111
#define BLADE_USB_CMD_REFRESH_CAL_CACHE 112

#define BLADE_USB_STR_INDEX_DEV_VER 4
/* String descriptor indices */
#define BLADE_USB_STR_INDEX_MFR 1 /* Manufacturer */
#define BLADE_USB_STR_INDEX_PRODUCT 2 /* Product */
#define BLADE_USB_STR_INDEX_SERIAL 3 /* Serial number */
#define BLADE_USB_STR_INDEX_FW_VER 4 /* Firmware version */

#define CAL_BUFFER_SIZE 256
#define CAL_PAGE 768

#ifdef _MSC_VER
# define PACK(decl_to_pack_) \
__pragma(pack(push,1)) \
decl_to_pack_ \
__pragma(pack(pop))
#elif defined(__GNUC__)
# define PACK(decl_to_pack_) \
decl_to_pack_ __attribute__((__packed__))
#else
#error "Unexpected compiler/environment"
#endif

PACK(
struct bladerf_fx3_version {
unsigned short major;
unsigned short minor;
};
});

struct bladeRF_firmware {
unsigned int len;
Expand Down
2 changes: 1 addition & 1 deletion fx3_firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.3)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../host/cmake/modules)
set(VERSION_INFO_MAJOR 1)
set(VERSION_INFO_MINOR 5)
set(VERSION_INFO_PATCH 0)
set(VERSION_INFO_PATCH 1)
set(VERSION_INFO_EXTRA "git")
include(Version)

Expand Down
31 changes: 22 additions & 9 deletions fx3_firmware/bladeRF.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,28 +809,43 @@ void bladeRFInit(void)
CyFxAppErrorHandler(apiRetStatus);
}

/* String descriptor 1 */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 1, (uint8_t *)CyFxUSBManufactureDscr);
/* Manufacturer string descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR,
BLADE_USB_STR_INDEX_MFR,
(uint8_t *)CyFxUSBManufactureDscr);

if (apiRetStatus != CY_U3P_SUCCESS) {
CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}

/* String descriptor 2 */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 2, (uint8_t *)CyFxUSBProductDscr);
/* Product string descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR,
BLADE_USB_STR_INDEX_PRODUCT,
(uint8_t *)CyFxUSBProductDscr);

if (apiRetStatus != CY_U3P_SUCCESS) {
CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}

/* String descriptor 3 */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 3, (uint8_t *)CyFxUSBSerial);
/* Fetch serial number from flash and configure the serial number
* string descriptor */
ExtractSerial();
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR,
BLADE_USB_STR_INDEX_PRODUCT,
(uint8_t *)CyFxUSBSerial);

if (apiRetStatus != CY_U3P_SUCCESS) {
CyU3PDebugPrint (4, "USB set string descriptor failed, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
}

apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR, 4, (uint8_t *)CyFxUSBVersion);
/* Firmware version string descriptor */
apiRetStatus = CyU3PUsbSetDesc(CY_U3P_USB_SET_STRING_DESCR,
BLADE_USB_STR_INDEX_FW_VER,
(uint8_t *)CyFxUSBVersion);

if (apiRetStatus != CY_U3P_SUCCESS) {
CyU3PDebugPrint (4, "USB set descriptor failed for version string, Error code = %d\n", apiRetStatus);
CyFxAppErrorHandler(apiRetStatus);
Expand Down Expand Up @@ -883,8 +898,6 @@ void bladeRFAppThread_Entry( uint32_t input)

bladeRFInit();

ExtractSerial();

FpgaBeginProgram();
for (;;) {
CyU3PThreadSleep (100);
Expand Down
2 changes: 1 addition & 1 deletion host/libraries/libbladeRF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ project(libbladeRF C)

set(VERSION_INFO_MAJOR 0)
set(VERSION_INFO_MINOR 6)
set(VERSION_INFO_PATCH 0)
set(VERSION_INFO_PATCH 1)
set(VERSION_INFO_EXTRA "git")
include(Version)

Expand Down
2 changes: 1 addition & 1 deletion host/libraries/libbladeRF/src/backend/libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ static int lusb_fw_version(struct bladerf *dev,
struct bladerf_lusb *lusb = dev->backend;

status = libusb_get_string_descriptor_ascii(lusb->handle,
BLADE_USB_STR_INDEX_DEV_VER,
BLADE_USB_STR_INDEX_FW_VER,
(unsigned char *)dev->fw_version_str,
BLADERF_VERSION_STR_MAX);

Expand Down

0 comments on commit 58c13c6

Please sign in to comment.