libhackrf: Rework hackrf_cpld_write to use new firmware interface
We now use a separate USB configuration for CPLD updates. To avoid misuse of the interface, hackrf_cpld_write is now a one-shot call, expecting the entire CPLD buffer. The library will then take care that the device is placed in the CPLD update configuration and the entire buffer uploaded. Unfortunately, this means that users of the interface will have substantially fewer opportunities to provide status updates to the user.
This commit is contained in:
@ -55,7 +55,6 @@ typedef enum {
|
|||||||
HACKRF_VENDOR_REQUEST_SPIFLASH_ERASE = 10,
|
HACKRF_VENDOR_REQUEST_SPIFLASH_ERASE = 10,
|
||||||
HACKRF_VENDOR_REQUEST_SPIFLASH_WRITE = 11,
|
HACKRF_VENDOR_REQUEST_SPIFLASH_WRITE = 11,
|
||||||
HACKRF_VENDOR_REQUEST_SPIFLASH_READ = 12,
|
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_VERSION_STRING_READ = 15,
|
||||||
HACKRF_VENDOR_REQUEST_SET_FREQ = 16,
|
HACKRF_VENDOR_REQUEST_SET_FREQ = 16,
|
||||||
@ -632,25 +631,44 @@ int ADDCALL hackrf_spiflash_read(hackrf_device* device, const uint32_t address,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ADDCALL hackrf_cpld_write(hackrf_device* device, const uint16_t length,
|
int ADDCALL hackrf_cpld_write(hackrf_device* device,
|
||||||
unsigned char* const data, const uint16_t total_length)
|
unsigned char* const data, const unsigned int total_length)
|
||||||
{
|
{
|
||||||
int result = libusb_control_transfer(
|
int result = libusb_release_interface(device->usb_device, 0);
|
||||||
device->usb_device,
|
if (result != LIBUSB_SUCCESS) {
|
||||||
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
|
|
||||||
HACKRF_VENDOR_REQUEST_CPLD_WRITE,
|
|
||||||
total_length,
|
|
||||||
0,
|
|
||||||
data,
|
|
||||||
length,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result < length) {
|
|
||||||
return HACKRF_ERROR_LIBUSB;
|
return HACKRF_ERROR_LIBUSB;
|
||||||
} else {
|
|
||||||
return HACKRF_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = libusb_set_configuration(device->usb_device, 2);
|
||||||
|
if (result != LIBUSB_SUCCESS) {
|
||||||
|
return HACKRF_ERROR_LIBUSB;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = libusb_claim_interface(device->usb_device, 0);
|
||||||
|
if (result != LIBUSB_SUCCESS) {
|
||||||
|
return HACKRF_ERROR_LIBUSB;
|
||||||
|
}
|
||||||
|
|
||||||
|
const unsigned int chunk_size = 512;
|
||||||
|
unsigned int i;
|
||||||
|
int transferred = 0;
|
||||||
|
for (i = 0; i < total_length; i += chunk_size)
|
||||||
|
{
|
||||||
|
result = libusb_bulk_transfer(
|
||||||
|
device->usb_device,
|
||||||
|
LIBUSB_ENDPOINT_OUT | 2,
|
||||||
|
&data[i],
|
||||||
|
chunk_size,
|
||||||
|
&transferred,
|
||||||
|
10000 // long timeout to allow for CPLD programming
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result != LIBUSB_SUCCESS) {
|
||||||
|
return HACKRF_ERROR_LIBUSB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return HACKRF_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ADDCALL hackrf_board_id_read(hackrf_device* device, uint8_t* value)
|
int ADDCALL hackrf_board_id_read(hackrf_device* device, uint8_t* value)
|
||||||
|
@ -121,8 +121,9 @@ extern ADDAPI int ADDCALL hackrf_spiflash_erase(hackrf_device* device);
|
|||||||
extern ADDAPI int ADDCALL hackrf_spiflash_write(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* const data);
|
extern ADDAPI int ADDCALL hackrf_spiflash_write(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* const data);
|
||||||
extern ADDAPI int ADDCALL hackrf_spiflash_read(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* data);
|
extern ADDAPI int ADDCALL hackrf_spiflash_read(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* data);
|
||||||
|
|
||||||
extern ADDAPI int ADDCALL hackrf_cpld_write(hackrf_device* device, const uint16_t length,
|
/* device will need to be reset after hackrf_cpld_write */
|
||||||
unsigned char* const data, const uint16_t total_length);
|
extern ADDAPI int ADDCALL hackrf_cpld_write(hackrf_device* device,
|
||||||
|
unsigned char* const data, const unsigned int total_length);
|
||||||
|
|
||||||
extern ADDAPI int ADDCALL hackrf_board_id_read(hackrf_device* device, uint8_t* value);
|
extern ADDAPI int ADDCALL hackrf_board_id_read(hackrf_device* device, uint8_t* value);
|
||||||
extern ADDAPI int ADDCALL hackrf_version_string_read(hackrf_device* device, char* version, uint8_t length);
|
extern ADDAPI int ADDCALL hackrf_version_string_read(hackrf_device* device, char* version, uint8_t length);
|
||||||
|
Reference in New Issue
Block a user