* implement strstr

* clean up usb_arcotg_dcd_enable


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14740 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Christian Gmeiner 2007-09-17 23:06:23 +00:00
parent 689d5fd446
commit 2077cebca0
3 changed files with 142 additions and 100 deletions

View file

@ -53,6 +53,7 @@ common/strncmp.c
common/strncpy.c common/strncpy.c
common/strrchr.c common/strrchr.c
common/strtok.c common/strtok.c
common/strstr.c
common/structec.c common/structec.c
common/timefuncs.c common/timefuncs.c
common/unicode.c common/unicode.c

45
firmware/common/strstr.c Normal file
View file

@ -0,0 +1,45 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id: $
*
* Copyright (C) 2007 by Christian Gmeiner
*
****************************************************************************/
#include <string.h>
/**
* Locate substring.
* @param search c string to be scanned.
* @param find c string containing the sequence of characters to match.
* @return a pointer to the first occurrence in search of any of the
* entire sequence of characters specified in find, or a
* null pointer if the sequence is not present in search.
*/
char *strstr(const char *search, const char *find)
{
char *hend;
char *a, *b;
if (*find == 0) return (char*)search;
hend = (char *)search + strlen(search) - strlen(find) + 1;
while (search < hend) {
if (*search == *find) {
a = (char *)search;
b = (char *)find;
for (;;) {
if (*b == 0) return (char*)search;
if (*a++ != *b++) {
break;
}
}
}
search++;
}
return 0;
}

View file

@ -523,29 +523,11 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep,
max = desc->wMaxPacketSize; max = desc->wMaxPacketSize;
retval = -EINVAL; retval = -EINVAL;
/* check the max package size validate for this endpoint */ /* check the max package size validate for this endpoint
/* Refer to USB2.0 spec table 9-13. */ * Refer to USB2.0 spec table 9-13, */
switch (desc->bmAttributes & 0x03) { switch (desc->bmAttributes & 0x03) {
case USB_ENDPOINT_XFER_BULK: case USB_ENDPOINT_XFER_BULK:
zlt = 1; if (strstr(ep->name, "-iso") || strstr(ep->name, "-int")) {
break;
case USB_ENDPOINT_XFER_INT:
zlt = 1;
break;
case USB_ENDPOINT_XFER_ISOC:
break;
case USB_ENDPOINT_XFER_CONTROL:
zlt = 1;
break;
}
#if 0
switch (ep->desc->bmAttributes & 0x03) {
case USB_ENDPOINT_XFER_BULK:
if (strstr(ep->ep.name, "-iso") || strstr(ep->ep.name, "-int")) {
goto en_done; goto en_done;
} }
mult = 0; mult = 0;
@ -565,85 +547,98 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep,
case 64: case 64:
break; break;
default: default:
+ case USB_SPEED_LOW: case USB_SPEED_LOW:
+ goto en_done; goto en_done;
+ } }
+ } }
+ break; break;
+ case USB_ENDPOINT_XFER_INT:
+ if (strstr(ep->ep.name, "-iso")) /* bulk is ok */ case USB_ENDPOINT_XFER_INT:
+ goto en_done; if (strstr(ep->name, "-iso")) { /* bulk is ok */
+ mult = 0; goto en_done;
+ zlt = 1; }
+ switch (udc->gadget.speed) { mult = 0;
+ case USB_SPEED_HIGH: zlt = 1;
+ if (max <= 1024)
+ break; switch (arcotg_dcd.speed) {
+ case USB_SPEED_FULL: case USB_SPEED_HIGH:
+ if (max <= 64) if (max <= 1024) {
+ break; break;
+ default: }
+ if (max <= 8) case USB_SPEED_FULL:
+ break; if (max <= 64) {
+ goto en_done; break;
+ } }
+ break; default:
+ case USB_ENDPOINT_XFER_ISOC: if (max <= 8) {
+ if (strstr(ep->ep.name, "-bulk") || strstr(ep->ep.name, "-int")) break;
+ goto en_done; }
+ mult = (unsigned char) goto en_done;
+ (1 + ((le16_to_cpu(desc->wMaxPacketSize) >> 11) & 0x03)); }
+ zlt = 0; break;
+ switch (udc->gadget.speed) {
+ case USB_SPEED_HIGH: case USB_ENDPOINT_XFER_ISOC:
+ if (max <= 1024) if (strstr(ep->name, "-bulk") || strstr(ep->name, "-int")) {
+ break; goto en_done;
+ case USB_SPEED_FULL: }
+ if (max <= 1023) mult = (unsigned char) (1 +((desc->wMaxPacketSize >> 11) & 0x03));
+ break; zlt = 0;
+ default:
+ goto en_done; switch (arcotg_dcd.speed) {
+ } case USB_SPEED_HIGH:
+ break; if (max <= 1024) {
+ case USB_ENDPOINT_XFER_CONTROL: break;
+ if (strstr(ep->ep.name, "-iso") || strstr(ep->ep.name, "-int")) }
+ goto en_done; case USB_SPEED_FULL:
+ mult = 0; if (max <= 1023) {
+ zlt = 1; break;
+ switch (udc->gadget.speed) { }
+ case USB_SPEED_HIGH: default:
+ case USB_SPEED_FULL: goto en_done;
+ switch (max) { }
+ case 1: break;
+ case 2:
+ case 4: case USB_ENDPOINT_XFER_CONTROL:
+ case 8: if (strstr(ep->name, "-iso") || strstr(ep->name, "-int")) {
+ case 16: goto en_done;
+ case 32: }
+ case 64: mult = 0;
+ break; zlt = 1;
+ default:
+ goto en_done; switch (arcotg_dcd.speed) {
+ } case USB_SPEED_HIGH:
+ case USB_SPEED_LOW: case USB_SPEED_FULL:
+ switch (max) { switch (max) {
+ case 1: case 1:
+ case 2: case 2:
+ case 4: case 4:
+ case 8: case 8:
+ break; case 16:
+ default: case 32:
+ goto en_done; case 64:
+ } break;
+ default: default:
+ goto en_done; goto en_done;
+ } }
+ break; case USB_SPEED_LOW:
+ switch (max) {
+ default: case 1:
+ goto en_done; case 2:
+ } case 4:
#endif case 8:
break;
default:
goto en_done;
}
default:
goto en_done;
}
break;
default:
goto en_done;
}
/* here initialize variable of ep */ /* here initialize variable of ep */
ep->maxpacket = max; ep->maxpacket = max;
@ -690,6 +685,7 @@ int usb_arcotg_dcd_enable(struct usb_ep* ep,
(desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", val); (desc->bEndpointAddress & USB_DIR_IN) ? "in" : "out", val);
logf(" maxpacket %d", max); logf(" maxpacket %d", max);
en_done:
return retval; return retval;
} }