Make USB timeouts a parameter
This commit is contained in:
parent
78f780aef8
commit
f7ebea5db8
@ -31,16 +31,16 @@ void awoo_usbCommsExit(void);
|
||||
void awoo_usbCommsSetErrorHandling(bool flag);
|
||||
|
||||
/// Read data with the default interface.
|
||||
size_t awoo_usbCommsRead(void* buffer, size_t size);
|
||||
size_t awoo_usbCommsRead(void* buffer, size_t size, u64 timeout);
|
||||
|
||||
/// Write data with the default interface.
|
||||
size_t awoo_usbCommsWrite(const void* buffer, size_t size);
|
||||
size_t awoo_usbCommsWrite(const void* buffer, size_t size, u64 timeout);
|
||||
|
||||
/// Same as usbCommsRead except with the specified interface.
|
||||
size_t awoo_usbCommsReadEx(void* buffer, size_t size, u32 interface);
|
||||
size_t awoo_usbCommsReadEx(void* buffer, size_t size, u32 interface, u64 timeout);
|
||||
|
||||
/// Same as usbCommsWrite except with the specified interface.
|
||||
size_t awoo_usbCommsWriteEx(const void* buffer, size_t size, u32 interface);
|
||||
size_t awoo_usbCommsWriteEx(const void* buffer, size_t size, u32 interface, u64 timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -54,6 +54,6 @@ namespace tin::util
|
||||
static USBCmdHeader SendFileRangeCmd(std::string nspName, u64 offset, u64 size);
|
||||
};
|
||||
|
||||
size_t USBRead(void* out, size_t len);
|
||||
size_t USBWrite(const void* in, size_t len);
|
||||
size_t USBRead(void* out, size_t len, u64 timeout = 5000000000);
|
||||
size_t USBWrite(const void* in, size_t len, u64 timeout = 5000000000);
|
||||
}
|
@ -69,7 +69,7 @@ namespace tin::install::nsp
|
||||
{
|
||||
while (sizeRemaining && !stopThreadsUsbNsp)
|
||||
{
|
||||
tmpSizeRead = awoo_usbCommsRead(buf, std::min(sizeRemaining, (u64)0x800000));
|
||||
tmpSizeRead = awoo_usbCommsRead(buf, std::min(sizeRemaining, (u64)0x800000), 5000000000);
|
||||
if (tmpSizeRead == 0) THROW_FORMAT(("inst.usb.error"_lang).c_str());
|
||||
sizeRemaining -= tmpSizeRead;
|
||||
|
||||
|
@ -68,7 +68,7 @@ namespace tin::install::xci
|
||||
{
|
||||
while (sizeRemaining && !stopThreadsUsbXci)
|
||||
{
|
||||
tmpSizeRead = awoo_usbCommsRead(buf, std::min(sizeRemaining, (u64)0x800000));
|
||||
tmpSizeRead = awoo_usbCommsRead(buf, std::min(sizeRemaining, (u64)0x800000), 5000000000);
|
||||
if (tmpSizeRead == 0) THROW_FORMAT(("inst.usb.error"_lang).c_str());
|
||||
sizeRemaining -= tmpSizeRead;
|
||||
|
||||
|
@ -51,7 +51,7 @@ namespace usbInstStuff {
|
||||
std::vector<std::string> OnSelected() {
|
||||
TUSHeader header;
|
||||
while(true) {
|
||||
if (tin::util::USBRead(&header, sizeof(TUSHeader)) != 0) break;
|
||||
if (tin::util::USBRead(&header, sizeof(TUSHeader), 500000000) != 0) break;
|
||||
hidScanInput();
|
||||
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
if (kDown & KEY_B) return {};
|
||||
|
@ -33,7 +33,7 @@ static Result _usbCommsInterfaceInit1x(u32 intf_ind, const awoo_UsbCommsInterfac
|
||||
static Result _usbCommsInterfaceInit5x(u32 intf_ind, const awoo_UsbCommsInterfaceInfo *info);
|
||||
static Result _usbCommsInterfaceInit(u32 intf_ind, const awoo_UsbCommsInterfaceInfo *info);
|
||||
|
||||
static Result _usbCommsWrite(usbCommsInterface *interface, const void* buffer, size_t size, size_t *transferredSize);
|
||||
static Result _usbCommsWrite(usbCommsInterface *interface, const void* buffer, size_t size, size_t *transferredSize, u64 timeout);
|
||||
|
||||
static void _usbCommsUpdateInterfaceDescriptor(struct usb_interface_descriptor *desc, const awoo_UsbCommsInterfaceInfo *info) {
|
||||
if (info != NULL) {
|
||||
@ -397,7 +397,7 @@ void awoo_usbCommsSetErrorHandling(bool flag) {
|
||||
g_usbCommsErrorHandling = flag;
|
||||
}
|
||||
|
||||
static Result _usbCommsRead(usbCommsInterface *interface, void* buffer, size_t size, size_t *transferredSize)
|
||||
static Result _usbCommsRead(usbCommsInterface *interface, void* buffer, size_t size, size_t *transferredSize, u64 timeout)
|
||||
{
|
||||
Result rc=0;
|
||||
u32 urbId=0;
|
||||
@ -410,7 +410,7 @@ static Result _usbCommsRead(usbCommsInterface *interface, void* buffer, size_t s
|
||||
UsbDsReportData reportdata;
|
||||
|
||||
//Makes sure endpoints are ready for data-transfer / wait for init if needed.
|
||||
rc = usbDsWaitReady(5000000000);
|
||||
rc = usbDsWaitReady(timeout);
|
||||
if (R_FAILED(rc)) return rc;
|
||||
|
||||
while(size)
|
||||
@ -438,8 +438,7 @@ static Result _usbCommsRead(usbCommsInterface *interface, void* buffer, size_t s
|
||||
rc = usbDsEndpoint_PostBufferAsync(interface->endpoint_out, transfer_buffer, chunksize, &urbId);
|
||||
if (R_FAILED(rc)) return rc;
|
||||
//Wait for the transfer to finish.
|
||||
if (size < 0x1000) rc = eventWait(&interface->endpoint_out->CompletionEvent, 2000000000);
|
||||
else rc = eventWait(&interface->endpoint_out->CompletionEvent, 5000000000);
|
||||
rc = eventWait(&interface->endpoint_out->CompletionEvent, timeout);
|
||||
if (R_FAILED(rc))
|
||||
{
|
||||
usbDsEndpoint_Cancel(interface->endpoint_out);
|
||||
@ -470,7 +469,7 @@ static Result _usbCommsRead(usbCommsInterface *interface, void* buffer, size_t s
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result _usbCommsWrite(usbCommsInterface *interface, const void* buffer, size_t size, size_t *transferredSize)
|
||||
static Result _usbCommsWrite(usbCommsInterface *interface, const void* buffer, size_t size, size_t *transferredSize, u64 timeout)
|
||||
{
|
||||
Result rc=0;
|
||||
u32 urbId=0;
|
||||
@ -482,7 +481,7 @@ static Result _usbCommsWrite(usbCommsInterface *interface, const void* buffer, s
|
||||
UsbDsReportData reportdata;
|
||||
|
||||
//Makes sure endpoints are ready for data-transfer / wait for init if needed.
|
||||
rc = usbDsWaitReady(5000000000);
|
||||
rc = usbDsWaitReady(timeout);
|
||||
if (R_FAILED(rc)) return rc;
|
||||
|
||||
while(size)
|
||||
@ -509,8 +508,7 @@ static Result _usbCommsWrite(usbCommsInterface *interface, const void* buffer, s
|
||||
if(R_FAILED(rc))return rc;
|
||||
|
||||
//Wait for the transfer to finish.
|
||||
if (size < 0x1000) rc = eventWait(&interface->endpoint_in->CompletionEvent, 2000000000);
|
||||
else rc = eventWait(&interface->endpoint_in->CompletionEvent, 5000000000);
|
||||
rc = eventWait(&interface->endpoint_in->CompletionEvent, timeout);
|
||||
if (R_FAILED(rc))
|
||||
{
|
||||
usbDsEndpoint_Cancel(interface->endpoint_in);
|
||||
@ -541,7 +539,7 @@ static Result _usbCommsWrite(usbCommsInterface *interface, const void* buffer, s
|
||||
return rc;
|
||||
}
|
||||
|
||||
size_t awoo_usbCommsReadEx(void* buffer, size_t size, u32 interface)
|
||||
size_t awoo_usbCommsReadEx(void* buffer, size_t size, u32 interface, u64 timeout)
|
||||
{
|
||||
size_t transferredSize=0;
|
||||
Result rc;
|
||||
@ -556,19 +554,19 @@ size_t awoo_usbCommsReadEx(void* buffer, size_t size, u32 interface)
|
||||
if (!initialized) return 0;
|
||||
|
||||
rwlockWriteLock(&inter->lock_in);
|
||||
rc = _usbCommsRead(&g_usbCommsInterfaces[interface], buffer, size, &transferredSize);
|
||||
rc = _usbCommsRead(&g_usbCommsInterfaces[interface], buffer, size, &transferredSize, timeout);
|
||||
rwlockWriteUnlock(&inter->lock_in);
|
||||
if (R_SUCCEEDED(rc)) return transferredSize;
|
||||
else if (R_FAILED(rc)) return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t awoo_usbCommsRead(void* buffer, size_t size)
|
||||
size_t awoo_usbCommsRead(void* buffer, size_t size, u64 timeout)
|
||||
{
|
||||
return awoo_usbCommsReadEx(buffer, size, 0);
|
||||
return awoo_usbCommsReadEx(buffer, size, 0, timeout);
|
||||
}
|
||||
|
||||
size_t awoo_usbCommsWriteEx(const void* buffer, size_t size, u32 interface)
|
||||
size_t awoo_usbCommsWriteEx(const void* buffer, size_t size, u32 interface, u64 timeout)
|
||||
{
|
||||
size_t transferredSize=0;
|
||||
Result rc;
|
||||
@ -583,15 +581,15 @@ size_t awoo_usbCommsWriteEx(const void* buffer, size_t size, u32 interface)
|
||||
if (!initialized) return 0;
|
||||
|
||||
rwlockWriteLock(&inter->lock_in);
|
||||
rc = _usbCommsWrite(&g_usbCommsInterfaces[interface], buffer, size, &transferredSize);
|
||||
rc = _usbCommsWrite(&g_usbCommsInterfaces[interface], buffer, size, &transferredSize, timeout);
|
||||
rwlockWriteUnlock(&inter->lock_in);
|
||||
if (R_SUCCEEDED(rc)) return transferredSize;
|
||||
else if (R_FAILED(rc)) return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t awoo_usbCommsWrite(const void* buffer, size_t size)
|
||||
size_t awoo_usbCommsWrite(const void* buffer, size_t size, u64 timeout)
|
||||
{
|
||||
return awoo_usbCommsWriteEx(buffer, size, 0);
|
||||
return awoo_usbCommsWriteEx(buffer, size, 0, timeout);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ namespace tin::util
|
||||
return responseHeader;
|
||||
}
|
||||
|
||||
size_t USBRead(void* out, size_t len)
|
||||
size_t USBRead(void* out, size_t len, u64 timeout)
|
||||
{
|
||||
u8* tmpBuf = (u8*)out;
|
||||
size_t sizeRemaining = len;
|
||||
@ -77,7 +77,7 @@ namespace tin::util
|
||||
|
||||
while (sizeRemaining)
|
||||
{
|
||||
tmpSizeRead = awoo_usbCommsRead(tmpBuf, sizeRemaining);
|
||||
tmpSizeRead = awoo_usbCommsRead(tmpBuf, sizeRemaining, timeout);
|
||||
if (tmpSizeRead == 0) return 0;
|
||||
tmpBuf += tmpSizeRead;
|
||||
sizeRemaining -= tmpSizeRead;
|
||||
@ -86,7 +86,7 @@ namespace tin::util
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t USBWrite(const void* in, size_t len)
|
||||
size_t USBWrite(const void* in, size_t len, u64 timeout)
|
||||
{
|
||||
const u8 *bufptr = (const u8 *)in;
|
||||
size_t cursize = len;
|
||||
@ -94,7 +94,7 @@ namespace tin::util
|
||||
|
||||
while (cursize)
|
||||
{
|
||||
tmpsize = awoo_usbCommsWrite(bufptr, cursize);
|
||||
tmpsize = awoo_usbCommsWrite(bufptr, cursize, timeout);
|
||||
if (tmpsize == 0) return 0;
|
||||
bufptr += tmpsize;
|
||||
cursize -= tmpsize;
|
||||
|
Reference in New Issue
Block a user