freemyipod r950 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r949‎ | r950 | r951 >
Date:12:58, 16 June 2014
Author:theseven
Status:new
Tags:
Comment:
emCORE: Fix USB debugger bulk interface
Modified paths:
  • /emcore/trunk/usb/usb.c (modified) (history)
  • /emcore/trunk/usb/usb.h (modified) (history)
  • /emcore/trunk/usb/usbdebug.c (modified) (history)
  • /emcore/trunk/usb/usbdebug.h (modified) (history)

Diff [purge]

Index: emcore/trunk/usb/usb.h
@@ -4,21 +4,21 @@
55 #include "../global.h"
66
77 #ifndef IN_APPLICATION_CODE
8 -#if USB_ENDPOINTS & 0b00000000000000000000000000000010
 8+#if USB_ENDPOINTS & 0b00000000000000000000000000000010
99 #define USBDEBUG_ENDPOINT_OUT 1
10 -#elif USB_ENDPOINTS & 0b00000000000000000000000000000010
 10+#elif USB_ENDPOINTS & 0b00000000000000000000000000000100
1111 #define USBDEBUG_ENDPOINT_OUT 2
12 -#elif USB_ENDPOINTS & 0b00000000000000000000000000000100
 12+#elif USB_ENDPOINTS & 0b00000000000000000000000000001000
1313 #define USBDEBUG_ENDPOINT_OUT 3
14 -#elif USB_ENDPOINTS & 0b00000000000000000000000000001000
 14+#elif USB_ENDPOINTS & 0b00000000000000000000000000010000
1515 #define USBDEBUG_ENDPOINT_OUT 4
16 -#elif USB_ENDPOINTS & 0b00000000000000000000000000010000
 16+#elif USB_ENDPOINTS & 0b00000000000000000000000000100000
1717 #define USBDEBUG_ENDPOINT_OUT 5
18 -#elif USB_ENDPOINTS & 0b00000000000000000000000000100000
 18+#elif USB_ENDPOINTS & 0b00000000000000000000000001000000
1919 #define USBDEBUG_ENDPOINT_OUT 6
20 -#elif USB_ENDPOINTS & 0b00000000000000000000000001000000
 20+#elif USB_ENDPOINTS & 0b00000000000000000000000010000000
2121 #define USBDEBUG_ENDPOINT_OUT 7
22 -#elif USB_ENDPOINTS & 0b00000000000000000000000010000000
 22+#elif USB_ENDPOINTS & 0b00000000000000000000000100000000
2323 #define USBDEBUG_ENDPOINT_OUT 8
2424 #elif USB_ENDPOINTS & 0b00000000000000000000001000000000
2525 #define USBDEBUG_ENDPOINT_OUT 9
@@ -37,21 +37,21 @@
3838 #else
3939 #error USBDEBUG: No OUT endpoints available!
4040 #endif
41 -#if USB_ENDPOINTS & 0b00000000000000100000000000000000
 41+#if USB_ENDPOINTS & 0b00000000000000100000000000000000
4242 #define USBDEBUG_ENDPOINT_IN 1
43 -#elif USB_ENDPOINTS & 0b00000000000000100000000000000000
 43+#elif USB_ENDPOINTS & 0b00000000000001000000000000000000
4444 #define USBDEBUG_ENDPOINT_IN 2
45 -#elif USB_ENDPOINTS & 0b00000000000001000000000000000000
 45+#elif USB_ENDPOINTS & 0b00000000000010000000000000000000
4646 #define USBDEBUG_ENDPOINT_IN 3
47 -#elif USB_ENDPOINTS & 0b00000000000010000000000000000000
 47+#elif USB_ENDPOINTS & 0b00000000000100000000000000000000
4848 #define USBDEBUG_ENDPOINT_IN 4
49 -#elif USB_ENDPOINTS & 0b00000000000100000000000000000000
 49+#elif USB_ENDPOINTS & 0b00000000001000000000000000000000
5050 #define USBDEBUG_ENDPOINT_IN 5
51 -#elif USB_ENDPOINTS & 0b00000000001000000000000000000000
 51+#elif USB_ENDPOINTS & 0b00000000010000000000000000000000
5252 #define USBDEBUG_ENDPOINT_IN 6
53 -#elif USB_ENDPOINTS & 0b00000000010000000000000000000000
 53+#elif USB_ENDPOINTS & 0b00000000100000000000000000000000
5454 #define USBDEBUG_ENDPOINT_IN 7
55 -#elif USB_ENDPOINTS & 0b00000000100000000000000000000000
 55+#elif USB_ENDPOINTS & 0b00000001000000000000000000000000
5656 #define USBDEBUG_ENDPOINT_IN 8
5757 #elif USB_ENDPOINTS & 0b00000010000000000000000000000000
5858 #define USBDEBUG_ENDPOINT_IN 9
Index: emcore/trunk/usb/usbdebug.c
@@ -117,7 +117,7 @@
118118 dbgstate = DBGSTATE_IDLE;
119119 }
120120
121 -void usbdebug_bus_reset(const struct usb_instance* data, int highspeed)
 121+void usbdebug_bus_reset(const struct usb_instance* data, int configuration, int interface, int highspeed)
122122 {
123123 maxpacket = highspeed ? 512 : 64;
124124 }
@@ -150,13 +150,13 @@
151151 {
152152 union usb_endpoint_number ep = { .number = USBDEBUG_ENDPOINT_IN, .direction = USB_ENDPOINT_DIRECTION_IN };
153153 size = MIN(state->size, maxpacket * usb_get_max_transfer_size(data, ep));
154 - usb_start_rx(data, ep, state->addr, size);
 154+ usb_start_tx(data, ep, state->addr, size);
155155 }
156156 else
157157 {
158158 union usb_endpoint_number ep = { .number = USBDEBUG_ENDPOINT_OUT, .direction = USB_ENDPOINT_DIRECTION_OUT };
159159 size = MIN(state->size, maxpacket * usb_get_max_transfer_size(data, ep));
160 - usb_start_tx(data, ep, state->addr, size);
 160+ usb_start_rx(data, ep, state->addr, size);
161161 }
162162 state->addr += size;
163163 state->size -= size;
@@ -166,7 +166,6 @@
167167 bool usbdebug_bulk_handle_data(const struct usb_instance* data, union usb_endpoint_number epnum, int bytesleft)
168168 {
169169 uint32_t* buf = (uint32_t*)data->buffer->raw;
170 - int len = 64 - bytesleft;
171170 union usb_endpoint_number ep0out = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_OUT };
172171 union usb_endpoint_number ep0in = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_IN };
173172 usb_ep0_start_rx(data, false, 0, NULL);
@@ -173,8 +172,6 @@
174173 switch (buf[0])
175174 {
176175 case 1: // START MEMORY TRANSFER
177 - if (len == 12)
178 - {
179176 bulk_state[bulk_ctrlreq_ep].addr = (void*)buf[1];
180177 bulk_state[bulk_ctrlreq_ep].size = buf[2];
181178 usbdebug_bulk_xfer_complete(data, 0, bulk_ctrlreq_ep, 0); // Convenient way to start a transfer.
@@ -181,7 +178,6 @@
182179 usb_set_stall(data, ep0out, true);
183180 usb_ep0_start_tx(data, NULL, 0, NULL);
184181 break;
185 - }
186182 default:
187183 usb_set_stall(data, ep0out, true);
188184 usb_set_stall(data, ep0in, true);
@@ -206,8 +202,7 @@
207203 bulk_ctrlreq_ep = endpoint;
208204 usb_ep0_start_rx(data, true, 64, usbdebug_bulk_handle_data);
209205 return -3;
210 - case USB_SETUP_BMREQUESTTYPE_DIRECTION_IN:
211 - return -2;
 206+ default: break;
212207 }
213208 break;
214209 default: break;
Index: emcore/trunk/usb/usbdebug.h
@@ -36,7 +36,7 @@
3737 extern int usbdebug_handle_setup(const struct usb_instance* data, int interface, union usb_ep0_buffer* request, const void** response);
3838 extern void usbdebug_bulk_xfer_complete(const struct usb_instance* data, int interface, int endpoint, int bytesleft);
3939 extern int usbdebug_bulk_ctrl_request(const struct usb_instance* data, int interface, int endpoint, union usb_ep0_buffer* request, const void** response);
40 -extern void usbdebug_bus_reset(const struct usb_instance* data, int highspeed);
 40+extern void usbdebug_bus_reset(const struct usb_instance* data, int configuration, int interface, int highspeed);
4141 extern void dbgconsole_putc(char string) ICODE_ATTR;
4242 extern void dbgconsole_puts(const char* string) ICODE_ATTR;
4343 extern void dbgconsole_write(const char* string, size_t length) ICODE_ATTR;
Index: emcore/trunk/usb/usb.c
@@ -277,50 +277,50 @@
278278 default: break;
279279 }
280280 break;
281 - default: break;
 281+ default: break;
282282 }
283283 break;
284 - case USB_SETUP_BMREQUESTTYPE_RECIPIENT_ENDPOINT:
 284+ }
 285+ case USB_SETUP_BMREQUESTTYPE_RECIPIENT_ENDPOINT:
 286+ {
 287+ if (!data->state->current_configuration) break;
 288+ union usb_endpoint_number ep = { .byte = buffer->setup.wIndex };
 289+ int intfid;
 290+ int epid;
 291+ const struct usb_endpoint* endpoint = usb_find_endpoint(data, ep, &intfid, &epid);
 292+ if (!endpoint) break;
 293+ if (endpoint->ctrl_request) size = endpoint->ctrl_request(data, intfid, epid, buffer, &addr);
 294+ if (size != -1) break;
 295+ switch (buffer->setup.bmRequestType.type)
285296 {
286 - if (!data->state->current_configuration) break;
287 - union usb_endpoint_number ep = { .byte = buffer->setup.wIndex };
288 - int intfid;
289 - int epid;
290 - const struct usb_endpoint* endpoint = usb_find_endpoint(data, ep, &intfid, &epid);
291 - if (!endpoint) break;
292 - if (endpoint->ctrl_request) size = endpoint->ctrl_request(data, intfid, epid, buffer, &addr);
293 - if (size != -1) break;
294 - switch (buffer->setup.bmRequestType.type)
 297+ case USB_SETUP_BMREQUESTTYPE_TYPE_STANDARD:
 298+ switch (buffer->setup.bRequest.req)
295299 {
296 - case USB_SETUP_BMREQUESTTYPE_TYPE_STANDARD:
297 - switch (buffer->setup.bRequest.req)
298 - {
299 - case USB_SETUP_BREQUEST_GET_STATUS:
300 - if (buffer->setup.wLength != 2 || buffer->setup.wValue) break;
301 - data->buffer->raw[0] = 0;
302 - data->buffer->raw[1] = data->driver->get_stall(data, ep);
303 - addr = data->buffer;
304 - size = 2;
305 - break;
306 - case USB_SETUP_BREQUEST_CLEAR_FEATURE:
307 - if (buffer->setup.wLength || buffer->setup.wValue) break;
308 - usb_set_stall(data, ep, false);
309 - size = 0;
310 - break;
311 - case USB_SETUP_BREQUEST_SET_FEATURE:
312 - if (buffer->setup.wLength || buffer->setup.wValue) break;
313 - usb_set_stall(data, ep, true);
314 - size = 0;
315 - break;
316 - default: break;
317 - }
 300+ case USB_SETUP_BREQUEST_GET_STATUS:
 301+ if (buffer->setup.wLength != 2 || buffer->setup.wValue) break;
 302+ data->buffer->raw[0] = 0;
 303+ data->buffer->raw[1] = data->driver->get_stall(data, ep);
 304+ addr = data->buffer;
 305+ size = 2;
318306 break;
319 - default: break;
 307+ case USB_SETUP_BREQUEST_CLEAR_FEATURE:
 308+ if (buffer->setup.wLength || buffer->setup.wValue) break;
 309+ usb_set_stall(data, ep, false);
 310+ size = 0;
 311+ break;
 312+ case USB_SETUP_BREQUEST_SET_FEATURE:
 313+ if (buffer->setup.wLength || buffer->setup.wValue) break;
 314+ usb_set_stall(data, ep, true);
 315+ size = 0;
 316+ break;
 317+ default: break;
320318 }
321319 break;
 320+ default: break;
322321 }
323 - default: break;
 322+ break;
324323 }
 324+ default: break;
325325 }
326326 union usb_endpoint_number ep0in = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_IN };
327327 union usb_endpoint_number ep0out = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_OUT };