# HG changeset patch # User Paul Boddie # Date 1363217619 0 # Node ID 1d47c41fd48758a0f906d2c35788c9e529572512 # Parent f33f9c21ca2f6aa5f4fdb44810d2e95e2014e7fd Introduced a timeout for failed control requests and a delay upon retrying. diff -r f33f9c21ca2f -r 1d47c41fd487 test.c --- a/test.c Wed Mar 13 17:11:10 2013 +0000 +++ b/test.c Wed Mar 13 23:33:39 2013 +0000 @@ -426,9 +426,9 @@ /** * Send a control request consisting of the given setup data. */ -uint8_t max_control(uint8_t *setup) +bool max_control(uint8_t *setup) { - uint8_t status, hrsl; + uint8_t status, hrsl, timer = 255; max_write_fifo(0, setup, 8); @@ -440,9 +440,9 @@ status = max_wait_transfer(status); hrsl = max_read(MAX_REG_HRSL, &status); } - while (hrsl & MAX_HRSL_HRSLT); + while ((hrsl & MAX_HRSL_HRSLT) && (--timer)); - return status; + return !(hrsl & MAX_HRSL_HRSLT); } bool max_control_input(uint8_t *data, uint8_t *len, max_device *device) @@ -618,7 +618,9 @@ setup_packet(setup, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, usb_descriptor_type(type) | value, index, initial ? 8 : 64); - max_control(setup); + if (!max_control(setup)) + return NULL; + if (!max_control_input(data, &len, device)) { printf("Failed.\n"); @@ -968,7 +970,10 @@ else if ((devstate == MAX_DEVSTATE_RESET) && frame_event && !(--framecount)) { if (!max_init_device(&device)) + { printf("FAILED: RESET -> INSPECTED\n"); + framecount = 200; + } else { devstate = MAX_DEVSTATE_INSPECTED;