1
0
Fork 0
mirror of https://github.com/DarkMatterCore/nxdumptool.git synced 2024-11-22 18:26:39 +00:00

USB optimizations.

This commit is contained in:
Pablo Curiel 2020-05-11 08:11:06 -04:00
parent a02c806b60
commit d6179f77fb
2 changed files with 28 additions and 8 deletions

View file

@ -366,7 +366,7 @@ int main(int argc, char *argv[])
consolePrint("lrOpenLocationResolver succeeded\n");
rc = lrLrResolveProgramPath(&resolver, (u64)0x01006F8002326000, path); // ACNH 0x01006F8002326000 | Smash 0x01006A800016E000 | Dark Souls 0x01004AB00A260000
rc = lrLrResolveProgramPath(&resolver, (u64)0x01007EF00011E000, path); // ACNH 0x01006F8002326000 | Smash 0x01006A800016E000 | Dark Souls 0x01004AB00A260000 | BotW 0x01007EF00011E000
if (R_FAILED(rc))
{
consolePrint("lrLrResolveProgramPath failed\n");
@ -494,9 +494,9 @@ int main(int argc, char *argv[])
consolePrint("\nwaiting for threads to join\n");
thrd_join(read_thread, NULL);
consolePrint("read_thread done: %lu\n", time(NULL));
thrd_join(write_thread, NULL);
usbEndSession();
consolePrint("write_thread done: %lu\n", time(NULL));
if (shared_data.read_error || shared_data.write_error)
{
@ -510,6 +510,10 @@ int main(int argc, char *argv[])
goto out2;
}
consolePrint("ending usb session... ");
usbEndSession();
consolePrint("done\n");
consolePrint("process completed in %lu seconds\n", start);

View file

@ -31,6 +31,7 @@
#define USB_SESSION_START_TIMEOUT 10 /* 10 seconds */
#define USB_TRANSFER_ALIGNMENT 0x1000 /* 4 KiB */
#define USB_TRANSFER_TIMEOUT 5 /* 5 seconds */
/* Type definitions. */
@ -169,6 +170,10 @@ void usbExit(void)
/* Free USB transfer buffer */
usbFreeTransferBuffer();
/* Reset global variables */
g_usbTransferRemainingSize = 0;
g_usbSessionStarted = false;
rwlockWriteUnlock(&g_usbDeviceLock);
}
@ -195,7 +200,7 @@ bool usbStartSession(void)
{
/* Once the console has been connected to a host device, there's no need to keep running this loop */
/* usbTransferData() implements its own timeout */
ret = g_usbSessionStarted = _usbStartSession();
ret = _usbStartSession();
break;
}
@ -204,6 +209,8 @@ bool usbStartSession(void)
now = time(NULL);
}
if (ret) g_usbSessionStarted = true;
exit:
rwlockWriteUnlock(&(g_usbDeviceInterface.lock));
rwlockWriteUnlock(&g_usbDeviceLock);
@ -460,8 +467,6 @@ NX_INLINE void usbFreeTransferBuffer(void)
if (!g_usbTransferBuffer) return;
free(g_usbTransferBuffer);
g_usbTransferBuffer = NULL;
g_usbTransferRemainingSize = 0;
g_usbSessionStarted = false;
}
static bool usbInitializeComms(void)
@ -898,7 +903,9 @@ NX_INLINE bool usbIsHostAvailable(void)
{
u32 state = 0;
Result rc = usbDsGetState(&state);
return (R_SUCCEEDED(rc) && state == 5);
bool ret = (R_SUCCEEDED(rc) && state == 5);
if (!ret) g_usbSessionStarted = false;
return ret;
}
NX_INLINE bool usbRead(void *buf, u64 size)
@ -945,9 +952,18 @@ static bool usbTransferData(void *buf, u64 size, UsbDsEndpoint *endpoint)
}
/* Wait for the transfer to finish */
eventWait(&(endpoint->CompletionEvent), UINT64_MAX);
/* If we're starting an USB transfer session, use an infinite timeout value to let the user start the companion app */
u64 timeout = (g_usbSessionStarted ? (USB_TRANSFER_TIMEOUT * (u64)1000000000) : UINT64_MAX);
rc = eventWait(&(endpoint->CompletionEvent), timeout);
eventClear(&(endpoint->CompletionEvent));
if (R_FAILED(rc))
{
usbDsEndpoint_Cancel(endpoint);
LOGFILE("eventWait failed! (0x%08X)", rc);
return false;
}
rc = usbDsEndpoint_GetReportData(endpoint, &report_data);
if (R_FAILED(rc))
{