# HG changeset patch # User Paul Boddie # Date 1361646659 0 # Node ID b88b2b0c03668ec961faed93913b3e59f94b528d # Parent 4920c2e6e019f4164a7f913f66bf5c91f81bea16 Added a status payload transfer after the initial control message transfer. Removed various diagnostic statements. diff -r 4920c2e6e019 -r b88b2b0c0366 test.c --- a/test.c Sun Feb 17 01:07:49 2013 +0000 +++ b/test.c Sat Feb 23 19:10:59 2013 +0000 @@ -284,15 +284,6 @@ } /** - * Send HS payload for control transfers. - */ -uint8_t max_send_hs() -{ - uint8_t status = max_write(MAX_REG_HXFR, MAX_HXFR_HS); - return max_wait_transfer(status); -} - -/** * Write the given data to the FIFO. */ void max_write_fifo(uint8_t endpoint, uint8_t *data, uint8_t len) @@ -329,9 +320,8 @@ */ uint8_t max_control(uint8_t address, uint8_t *setup) { - uint8_t status, hrsl = 0; + uint8_t status, hrsl; - printf("Writing FIFO with setup...\n"); max_write_fifo(0, setup, 8); /* Set the address. */ @@ -342,12 +332,29 @@ do { - printf("Initiating transfer...\n"); status = max_write(MAX_REG_HXFR, MAX_HXFR_SETUP); status = max_wait_transfer(status); hrsl = max_read(MAX_REG_HRSL, &status); - printf("HRSL = %x\n", hrsl); - sleep(1); + } + while (hrsl & MAX_HRSL_HRSLT); + + return status; +} + +/** + * Perform a status transaction as part of a larger control transaction. + * The out parameter is used to indicate the kind of status transfer to be + * performed and should be the inverse of the control transfer direction. + */ +uint8_t max_control_status(bool out) +{ + uint8_t status, hrsl; + + do + { + status = max_write(MAX_REG_HXFR, MAX_HXFR_HS | (out ? MAX_HXFR_OUTNIN : 0)); + status = max_wait_transfer(status); + hrsl = max_read(MAX_REG_HRSL, &status); } while (hrsl & MAX_HRSL_HRSLT); @@ -564,6 +571,7 @@ setup_packet(setup, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, USB_DT_DEVICE, 0, USB_DT_DEVICE_SIZE); max_control(0, setup); max_recv(0, 0, data, &len, in_toggle); + max_control_status(true); if (len >= sizeof(struct usb_device_descriptor)) {