Add software controlled reset
This commit is contained in:
@ -80,7 +80,8 @@ static const usb_request_handler_fn vendor_request_handler[] = {
|
|||||||
usb_vendor_request_init_sweep,
|
usb_vendor_request_init_sweep,
|
||||||
usb_vendor_request_operacake_get_boards,
|
usb_vendor_request_operacake_get_boards,
|
||||||
usb_vendor_request_operacake_set_ports,
|
usb_vendor_request_operacake_set_ports,
|
||||||
usb_vendor_request_set_hw_sync_mode
|
usb_vendor_request_set_hw_sync_mode,
|
||||||
|
usb_vendor_request_reset
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t vendor_request_handler_count =
|
static const uint32_t vendor_request_handler_count =
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <hackrf_core.h>
|
#include <hackrf_core.h>
|
||||||
#include <rom_iap.h>
|
#include <rom_iap.h>
|
||||||
#include <usb_queue.h>
|
#include <usb_queue.h>
|
||||||
|
#include <libopencm3/lpc43xx/wwdt.h>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -91,3 +92,13 @@ usb_request_status_t usb_vendor_request_read_partid_serialno(
|
|||||||
}
|
}
|
||||||
return USB_REQUEST_STATUS_OK;
|
return USB_REQUEST_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usb_request_status_t usb_vendor_request_reset(
|
||||||
|
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
|
||||||
|
{
|
||||||
|
if (stage == USB_TRANSFER_STAGE_SETUP) {
|
||||||
|
wwdt_reset(100000);
|
||||||
|
usb_transfer_schedule_ack(endpoint->in);
|
||||||
|
}
|
||||||
|
return USB_REQUEST_STATUS_OK;
|
||||||
|
}
|
@ -39,5 +39,7 @@ usb_request_status_t usb_vendor_request_read_version_string(
|
|||||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||||
usb_request_status_t usb_vendor_request_read_partid_serialno(
|
usb_request_status_t usb_vendor_request_read_partid_serialno(
|
||||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||||
|
usb_request_status_t usb_vendor_request_reset(
|
||||||
|
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||||
|
|
||||||
#endif /* end of include guard: __USB_API_BOARD_INFO_H__ */
|
#endif /* end of include guard: __USB_API_BOARD_INFO_H__ */
|
||||||
|
Submodule firmware/libopencm3 updated: 0ca8913944...d3d6f3e74b
@ -91,6 +91,7 @@ static void usage()
|
|||||||
printf("\t-r <filename>: Read data into file.\n");
|
printf("\t-r <filename>: Read data into file.\n");
|
||||||
printf("\t-w <filename>: Write data from file.\n");
|
printf("\t-w <filename>: Write data from file.\n");
|
||||||
printf("\t-d <serialnumber>: Serial number of device, if multiple devices\n");
|
printf("\t-d <serialnumber>: Serial number of device, if multiple devices\n");
|
||||||
|
printf("\t-R: Reset HackRF after other operations.\n");
|
||||||
printf("\t-v: Verbose output.\n");
|
printf("\t-v: Verbose output.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,8 +113,9 @@ int main(int argc, char** argv)
|
|||||||
bool read = false;
|
bool read = false;
|
||||||
bool write = false;
|
bool write = false;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
|
bool reset = false;
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, "a:l:r:w:d:v", long_options,
|
while ((opt = getopt_long(argc, argv, "a:l:r:w:d:vR", long_options,
|
||||||
&option_index)) != EOF) {
|
&option_index)) != EOF) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a':
|
case 'a':
|
||||||
@ -142,6 +144,10 @@ int main(int argc, char** argv)
|
|||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'R':
|
||||||
|
reset = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "opt error: %d\n", opt);
|
fprintf(stderr, "opt error: %d\n", opt);
|
||||||
usage();
|
usage();
|
||||||
@ -156,17 +162,17 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write == read) {
|
if((write == read) && (write == reset)) {
|
||||||
if (write == true) {
|
if(write && read) {
|
||||||
fprintf(stderr, "Read and write options are mutually exclusive.\n");
|
fprintf(stderr, "Read and write options are mutually exclusive.\n");
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Specify either read or write option.\n");
|
fprintf(stderr, "Specify either read, write, or reset option.\n");
|
||||||
}
|
}
|
||||||
usage();
|
usage();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path == NULL) {
|
if((read || write) && (path == NULL)) {
|
||||||
fprintf(stderr, "Specify a path to a file.\n");
|
fprintf(stderr, "Specify a path to a file.\n");
|
||||||
usage();
|
usage();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -214,7 +220,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd == NULL) {
|
if((read || write) && (fd == NULL)) {
|
||||||
fprintf(stderr, "Failed to open file: %s\n", path);
|
fprintf(stderr, "Failed to open file: %s\n", path);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
@ -233,8 +239,7 @@ int main(int argc, char** argv)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read)
|
if(read) {
|
||||||
{
|
|
||||||
ssize_t bytes_written;
|
ssize_t bytes_written;
|
||||||
tmp_length = length;
|
tmp_length = length;
|
||||||
while (tmp_length)
|
while (tmp_length)
|
||||||
@ -261,7 +266,9 @@ int main(int argc, char** argv)
|
|||||||
fd = NULL;
|
fd = NULL;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if(write) {
|
||||||
ssize_t bytes_read = fread(data, 1, length, fd);
|
ssize_t bytes_read = fread(data, 1, length, fd);
|
||||||
if (bytes_read != length) {
|
if (bytes_read != length) {
|
||||||
fprintf(stderr, "Failed read file (read %d bytes).\n",
|
fprintf(stderr, "Failed read file (read %d bytes).\n",
|
||||||
@ -297,13 +304,24 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = hackrf_close(device);
|
if(reset) {
|
||||||
if (result != HACKRF_SUCCESS) {
|
result = hackrf_reset(device);
|
||||||
fprintf(stderr, "hackrf_close() failed: %s (%d)\n",
|
if (result != HACKRF_SUCCESS) {
|
||||||
hackrf_error_name(result), result);
|
fprintf(stderr, "hackrf_reset() failed: %s (%d)\n",
|
||||||
fclose(fd);
|
hackrf_error_name(result), result);
|
||||||
fd = NULL;
|
fclose(fd);
|
||||||
return EXIT_FAILURE;
|
fd = NULL;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = hackrf_close(device);
|
||||||
|
if (result != HACKRF_SUCCESS) {
|
||||||
|
fprintf(stderr, "hackrf_close() failed: %s (%d)\n",
|
||||||
|
hackrf_error_name(result), result);
|
||||||
|
fclose(fd);
|
||||||
|
fd = NULL;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hackrf_exit();
|
hackrf_exit();
|
||||||
|
@ -77,6 +77,7 @@ typedef enum {
|
|||||||
HACKRF_VENDOR_REQUEST_OPERACAKE_GET_BOARDS = 27,
|
HACKRF_VENDOR_REQUEST_OPERACAKE_GET_BOARDS = 27,
|
||||||
HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS = 28,
|
HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS = 28,
|
||||||
HACKRF_VENDOR_REQUEST_SET_HW_SYNC_MODE = 29,
|
HACKRF_VENDOR_REQUEST_SET_HW_SYNC_MODE = 29,
|
||||||
|
HACKRF_VENDOR_REQUEST_RESET = 30,
|
||||||
} hackrf_vendor_request;
|
} hackrf_vendor_request;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -1829,6 +1830,25 @@ int ADDCALL hackrf_set_operacake_ports(hackrf_device* device,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ADDCALL hackrf_reset(hackrf_device* device) {
|
||||||
|
int result = libusb_control_transfer(
|
||||||
|
device->usb_device,
|
||||||
|
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
|
||||||
|
HACKRF_VENDOR_REQUEST_RESET,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
if( result != 0 ) {
|
||||||
|
return HACKRF_ERROR_LIBUSB;
|
||||||
|
} else {
|
||||||
|
return HACKRF_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // __cplusplus defined.
|
} // __cplusplus defined.
|
||||||
#endif
|
#endif
|
||||||
|
@ -222,6 +222,8 @@ extern ADDAPI int ADDCALL hackrf_set_operacake_ports(hackrf_device* device,
|
|||||||
uint8_t port_a,
|
uint8_t port_a,
|
||||||
uint8_t port_b);
|
uint8_t port_b);
|
||||||
|
|
||||||
|
extern ADDAPI int ADDCALL hackrf_reset(hackrf_device* device);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // __cplusplus defined.
|
} // __cplusplus defined.
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user