# HG changeset patch # User Paul Boddie # Date 1360715358 0 # Node ID 2da6d7a3fe1b19a3b4d0d1d8d2750ddf0a76d279 # Parent 7a07c599c9e9b78e6842072e4c6db49990b5e714 Introduced a specific control request function since the data involved in such requests appears to be handled separately from other outgoing data, as are the transactions associated with such setup data. diff -r 7a07c599c9e9 -r 2da6d7a3fe1b test.c --- a/test.c Wed Feb 13 00:06:17 2013 +0000 +++ b/test.c Wed Feb 13 00:29:18 2013 +0000 @@ -309,6 +309,33 @@ } /** + * Send a control request to the given address consisting of the given setup + * data. + */ +uint8_t max_control(uint8_t address, uint8_t *setup) +{ + uint8_t status, hrsl = 0; + + max_write_fifo(0, setup, 8); + + /* Set the address. */ + + max_write(MAX_REG_PERADDR, address); + + /* Initiate the transfer. */ + + do + { + status = max_write(MAX_REG_HXFR, MAX_HXFR_SETUP); + status = max_wait_transfer(status); + hrsl = max_read(MAX_REG_HRSL, &status); + } + while ((hrsl & MAX_HRSL_HRSLT) != 0); + + return status; +} + +/** * Send a request to the given address and endpoint, using the supplied data * payload with the given length, indicating the preserved toggle state of the * endpoint (which will be updated). @@ -319,7 +346,8 @@ max_write_fifo(endpoint, data, len); - max_set_send_toggle(*toggle); + if (endpoint) + max_set_send_toggle(*toggle); /* Set the address. */ @@ -329,7 +357,7 @@ do { - status = max_write(MAX_REG_HXFR, endpoint | MAX_HXFR_OUTNIN | (endpoint ? 0 : MAX_HXFR_SETUP)); + status = max_write(MAX_REG_HXFR, endpoint | MAX_HXFR_OUTNIN); status = max_wait_transfer(status); /* Test for usable data. */ @@ -341,7 +369,8 @@ } while ((hrsl & MAX_HRSL_HRSLT) != 0); - *toggle = max_get_send_toggle(); + if (endpoint) + *toggle = max_get_send_toggle(); return status; } @@ -349,21 +378,16 @@ /** * Make a request for data from the given address and endpoint, collecting it in * the supplied buffer with the given length, indicating the preserved toggle - * state of the endpoint (which will be updated), and providing optional setup - * data (for control transfers). The length will be updated to indicate the - * total length of the received data. + * state of the endpoint (which will be updated) The length will be updated to + * indicate the total length of the received data. */ -uint8_t max_recv(uint8_t address, uint8_t endpoint, uint8_t *data, uint8_t *len, bool *toggle, uint8_t *setup) +uint8_t max_recv(uint8_t address, uint8_t endpoint, uint8_t *data, uint8_t *len, bool *toggle) { uint8_t *datalimit = data + *len; uint8_t status, hrsl = 0; - /* Write control transfer information, if appropriate. */ - - if (!endpoint) - max_write_fifo(endpoint, setup, 8); - - max_set_send_toggle(*toggle); + if (endpoint) + max_set_send_toggle(*toggle); /* Set the address. */ @@ -395,7 +419,8 @@ } while (status & MAX_HIRQ_RCVDAVIRQ); - *toggle = max_get_send_toggle(); + if (endpoint) + *toggle = max_get_send_toggle(); return status; } @@ -599,7 +624,8 @@ { printf("Sending control request to address 0, endpoint 0...\n"); setup_packet(setup, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, USB_DT_DEVICE, 0, USB_DT_DEVICE_SIZE); - max_recv(0, 0, data, &len, &in_toggle, setup); + max_control(0, setup); + max_recv(0, 0, data, &len, &in_toggle); } if (status & MAX_HIRQ_SUSDNIRQ) printf("Suspend done.\n");