Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions protocol/dfu_hostcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ int libhoth_dfu_update(struct libhoth_device* dev, const uint8_t* image,
}

// TODO: Wait for chip to come back and confirm version
usleep(LIBHOTH_REBOOT_DELAY_MS * 1000);
return libhoth_device_reconnect(dev);
}
1 change: 1 addition & 0 deletions transports/libhoth_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern "C" {
#endif

#define LIBHOTH_MAILBOX_SIZE 1024
#define LIBHOTH_REBOOT_DELAY_MS 1000

typedef enum {
LIBHOTH_OK = 0,
Expand Down
13 changes: 11 additions & 2 deletions transports/libhoth_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@ static int libhoth_usb_reconnect(struct libhoth_device* dev) {
}

libhoth_usb_close(dev);
libusb_handle_events_completed(usb_ctx, NULL);

uint64_t start_time_ms = libhoth_get_monotonic_ms();

while (1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of waiting in a loop, could an event handler be installed to check for USB discovery events? Based on a quick look at the documentation, I see that libusb_hotplug_register_callback can be used for registering callbacks when events occur. But I haven't used it as of now, so I can't say how well it would work here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using hotplug discovery could work, assuming that all of the platforms we want to support have support for hotplug, which the libusb docs have called out as not necessarily being true.

One tricky thing is that if we register for hotplug events during reconnect, the eROT might have already started rebooting and we will miss the disconnect. The eROT might also have already rebooted, meaning we will miss the reconnect event.

The current API for reconnect right now is to delay for a second to be certain that the eROT has at least gone down for reboot, then to poll for discovery since this seems to be the most straight-forward way to have support for all transports.

int ret = libhoth_usb_get_device(usb_ctx, &usb_loc, &libusb_dev);
libusb_exit(usb_ctx);
int ret = libusb_init(&usb_ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to init libusb again? If there is one, would it be possible to call this in the loop instead of once after libhoth_usb_close outside the loop above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to re-init, because otherwise, from my testing, libusb cannot find the device and we get a timeout

if (ret != 0) {
fprintf(
stderr,
"libusb_init_context failed while reconnecting (error: %d (%s))\n",
ret, libusb_strerror(ret));
}

ret = libhoth_usb_get_device(usb_ctx, &usb_loc, &libusb_dev);
if (ret == 0) {
// Found the device
break;
Expand All @@ -123,6 +131,7 @@ static int libhoth_usb_reconnect(struct libhoth_device* dev) {
stderr,
"libhoth_usb_open timed out while reconnecting (error: %d (%s))\n",
ret, libusb_strerror(ret));
libusb_exit(usb_ctx);
return ret; // Timeout
}

Expand Down
Loading