Skip to content
Permalink
Browse files

libuuu: usb hotplug: configurable usb polling period (-pp)

When upgrading the software on a closed device (tested on imx7ulp) the
USB device times out when trying to access OCRAM.

Allowing the client to customize the usb polling frequency allows the
upgrade script to complete without errors on all scenarios.

Signed-off-by: Jorge Ramirez-Ortiz <jorge@foundries.io>
  • Loading branch information
ldts authored and nxpfrankli committed Nov 25, 2019
1 parent 003b6cb commit 5a790eae0a0f424e145171681e1a3a4f3fa47904
Showing with 18 additions and 2 deletions.
  1. +2 −0 libuuu/libuuu.h
  2. +10 −2 libuuu/usbhotplug.cpp
  3. +6 −0 uuu/uuu.cpp
@@ -129,6 +129,8 @@ int uuu_add_usbpath_filter(const char *path);

/*Set timeout wait for known devices appeared*/
int uuu_set_wait_timeout(int second);
/*Set usb device polling period */
void uuu_set_poll_period(int msecond);
/*
* bit 0:15 for libusb
* bit 16:31 for uuu
@@ -50,6 +50,7 @@ static vector<thread> g_running_thread;
static vector<string> g_filter_usbpath;

static int g_wait_usb_timeout = -1;
static int g_usb_poll_period = 0;

static int g_known_device_appeared;

@@ -153,7 +154,8 @@ static int usb_add(libusb_device *dev)
return -1;

ConfigItem *item = get_config()->find(desc.idVendor, desc.idProduct, desc.bcdDevice);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
int poll = g_usb_poll_period ? g_usb_poll_period : 200;
std::this_thread::sleep_for(std::chrono::milliseconds(poll));

if (item)
{
@@ -245,7 +247,8 @@ int polling_usb(std::atomic<int>& bexit)

oldlist = newlist;

std::this_thread::sleep_for(std::chrono::milliseconds(200));
int poll = g_usb_poll_period ? g_usb_poll_period : 200;
std::this_thread::sleep_for(std::chrono::milliseconds(poll));

if (g_wait_usb_timeout >= 0 && !g_known_device_appeared)
{
@@ -409,3 +412,8 @@ int uuu_set_wait_timeout(int second)
g_wait_usb_timeout = second;
return 0;
}

void uuu_set_poll_period(int msecond)
{
g_usb_poll_period = msecond;
}
@@ -136,6 +136,7 @@ void print_help(bool detail = false)
" -m USBPATH Only monitor these paths.\n"
" -m 1:2 -m 1:3\n\n"
" -t Timeout second for wait known usb device appeared\n"
" -pp usb polling period in milliseconds\n"
"uuu -s Enter shell mode. uuu.inputlog record all input commands\n"
" you can use \"uuu uuu.inputlog\" next time to run all commands\n\n"
"uuu -udev linux: show udev rule to avoid sudo each time \n"
@@ -875,6 +876,11 @@ int main(int argc, char **argv)
i++;
uuu_set_wait_timeout(atoll(argv[i]));
}
else if (s == "-pp")
{
i++;
uuu_set_poll_period(atoll(argv[i]));
}
else if (s == "-lsusb")
{
print_lsusb();

0 comments on commit 5a790ea

Please sign in to comment.
You can’t perform that action at this time.