fx3_firmware, libbladeRF: Packed FW version structure, moved serial # 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.
This commit is contained in:
Jon Szymaniak 2013-10-04 19:17:30 -04:00
commit 58c13c65a8
5 changed files with 44 additions and 14 deletions

View file

@ -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;

View file

@ -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)

View file

@ -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);
@ -883,8 +898,6 @@ void bladeRFAppThread_Entry( uint32_t input)
bladeRFInit();
ExtractSerial();
FpgaBeginProgram();
for (;;) {
CyU3PThreadSleep (100);

View file

@ -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)

View file

@ -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);