Merge pull request #313 from dominicgs/reset
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_operacake_get_boards,
|
||||
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 =
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <hackrf_core.h>
|
||||
#include <rom_iap.h>
|
||||
#include <usb_queue.h>
|
||||
#include <libopencm3/lpc43xx/wwdt.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@ -91,3 +92,13 @@ usb_request_status_t usb_vendor_request_read_partid_serialno(
|
||||
}
|
||||
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_request_status_t usb_vendor_request_read_partid_serialno(
|
||||
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__ */
|
||||
|
@ -91,6 +91,7 @@ static void usage()
|
||||
printf("\t-r <filename>: Read data into 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-R: Reset HackRF after other operations.\n");
|
||||
printf("\t-v: Verbose output.\n");
|
||||
}
|
||||
|
||||
@ -112,8 +113,9 @@ int main(int argc, char** argv)
|
||||
bool read = false;
|
||||
bool write = 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) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
@ -142,8 +144,16 @@ int main(int argc, char** argv)
|
||||
verbose = true;
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
reset = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "opt error: %d\n", opt);
|
||||
fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@ -156,28 +166,24 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (write == read) {
|
||||
if (write == true) {
|
||||
fprintf(stderr, "Read and write options are mutually exclusive.\n");
|
||||
} else {
|
||||
fprintf(stderr, "Specify either read or write option.\n");
|
||||
}
|
||||
if(write && read) {
|
||||
fprintf(stderr, "Read and write options are mutually exclusive.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (path == NULL) {
|
||||
fprintf(stderr, "Specify a path to a file.\n");
|
||||
|
||||
if(!(write || read || reset)) {
|
||||
fprintf(stderr, "Specify either read, write, or reset option.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if( write )
|
||||
{
|
||||
fd = fopen(path, "rb");
|
||||
if(fd == NULL)
|
||||
{
|
||||
printf("Error to open file %s\n", path);
|
||||
printf("Error opening file %s\n", path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/* Get size of the file */
|
||||
@ -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);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@ -233,8 +239,7 @@ int main(int argc, char** argv)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (read)
|
||||
{
|
||||
if(read) {
|
||||
ssize_t bytes_written;
|
||||
tmp_length = length;
|
||||
while (tmp_length)
|
||||
@ -261,7 +266,9 @@ int main(int argc, char** argv)
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if(write) {
|
||||
ssize_t bytes_read = fread(data, 1, length, fd);
|
||||
if (bytes_read != length) {
|
||||
fprintf(stderr, "Failed read file (read %d bytes).\n",
|
||||
@ -297,6 +304,17 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
if(reset) {
|
||||
result = hackrf_reset(device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_reset() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
result = hackrf_close(device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_close() failed: %s (%d)\n",
|
||||
|
@ -673,6 +673,10 @@ int main(int argc, char** argv) {
|
||||
result = parse_u32(optarg, &crystal_correct_ppm);
|
||||
break;
|
||||
|
||||
case '?':
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg);
|
||||
usage();
|
||||
|
@ -77,6 +77,7 @@ typedef enum {
|
||||
HACKRF_VENDOR_REQUEST_OPERACAKE_GET_BOARDS = 27,
|
||||
HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS = 28,
|
||||
HACKRF_VENDOR_REQUEST_SET_HW_SYNC_MODE = 29,
|
||||
HACKRF_VENDOR_REQUEST_RESET = 30,
|
||||
} hackrf_vendor_request;
|
||||
|
||||
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
|
||||
} // __cplusplus defined.
|
||||
#endif
|
||||
|
@ -222,6 +222,8 @@ extern ADDAPI int ADDCALL hackrf_set_operacake_ports(hackrf_device* device,
|
||||
uint8_t port_a,
|
||||
uint8_t port_b);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_reset(hackrf_device* device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // __cplusplus defined.
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user