summaryrefslogtreecommitdiff
path: root/firmware/usbstack/usb_core.c
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2007-11-30 00:13:00 +0000
committerChristian Gmeiner <christian.gmeiner@gmail.com>2007-11-30 00:13:00 +0000
commit94be71eab5e7a4c2e5407f7c4c38dc84237f4044 (patch)
treef89c0cdaf1922fb091aa43073ab0a59ee55ef0b2 /firmware/usbstack/usb_core.c
parentbf2a33485fc99d83ef74c261d092f6b95e040a37 (diff)
downloadrockbox-94be71eab5e7a4c2e5407f7c4c38dc84237f4044.zip
rockbox-94be71eab5e7a4c2e5407f7c4c38dc84237f4044.tar.gz
rockbox-94be71eab5e7a4c2e5407f7c4c38dc84237f4044.tar.bz2
rockbox-94be71eab5e7a4c2e5407f7c4c38dc84237f4044.tar.xz
Add a working serial driver to usb stack. At the moment it simply echos back what it gets. You can test it on linux by
0) change relevant defines in usb_core.c 1) modprobe usbserial vendor=0x0781 product=0x7421 debug=1 2) picocom /dev/ttyUSB0 3) look at your logf screen if you build with logf support and enabled LOGF_ENABLE define in usb_serial.c I also modified usb_core so that storage and serial both can make use the the 'usb_core'-thread. More will come :) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15850 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/usbstack/usb_core.c')
-rw-r--r--firmware/usbstack/usb_core.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c
index 27d545d..7e86086 100644
--- a/firmware/usbstack/usb_core.c
+++ b/firmware/usbstack/usb_core.c
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id: $
*
- * Copyright (C) 2007 by Björn Stenberg
+ * Copyright (C) 2007 by Bj�rn Stenberg
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
@@ -24,6 +24,7 @@
#include "logf.h"
//#define USB_STORAGE
+//#define USB_SERIAL
//#define USB_BENCHMARK
#define USB_CHARGING_ONLY
@@ -33,6 +34,10 @@
#if defined(USB_STORAGE)
#include "usb_storage.h"
+#define USB_THREAD
+#elif defined(USB_SERIAL)
+#define USB_THREAD
+#include "usb_serial.h"
#elif defined(USB_BENCHMARK)
#include "usb_benchmark.h"
#endif
@@ -79,7 +84,7 @@ static const struct {
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
.bMaxPower = 250, /* 500mA in 2mA units */
},
-
+
#ifdef USB_CHARGING_ONLY
/* dummy interface for charging-only */
{
@@ -163,7 +168,7 @@ static const struct {
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = EP_TX | USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
- .wMaxPacketSize = 512,
+ .wMaxPacketSize = 64,
.bInterval = 0
},
{
@@ -171,7 +176,7 @@ static const struct {
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = EP_RX | USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
- .wMaxPacketSize = 512,
+ .wMaxPacketSize = 64,
.bInterval = 0
}
#endif
@@ -296,7 +301,7 @@ static bool data_connection = false;
static struct event_queue usbcore_queue;
static enum { DEFAULT, ADDRESS, CONFIGURED } usb_state;
-#ifdef USB_STORAGE
+#ifdef USB_THREAD
static const char usbcore_thread_name[] = "usb_core";
static struct thread_entry* usbcore_thread;
static long usbcore_stack[DEFAULT_STACK_SIZE];
@@ -314,6 +319,13 @@ void usb_core_init(void)
usb_drv_init();
#ifdef USB_STORAGE
usb_storage_init();
+#endif
+
+#ifdef USB_SERIAL
+ usb_serial_init();
+#endif
+
+#ifdef USB_THREAD
usbcore_thread =
create_thread(usb_core_thread, usbcore_stack, sizeof(usbcore_stack), 0,
usbcore_thread_name
@@ -334,7 +346,7 @@ void usb_core_exit(void)
if (initialized) {
usb_drv_exit();
queue_delete(&usbcore_queue);
-#ifdef USB_STORAGE
+#ifdef USB_THREAD
remove_thread(usbcore_thread);
#endif
}
@@ -348,15 +360,22 @@ bool usb_core_data_connection(void)
return data_connection;
}
-#ifdef USB_STORAGE
+#ifdef USB_THREAD
void usb_core_thread(void)
{
while (1) {
struct queue_event ev;
-
+
queue_wait(&usbcore_queue, &ev);
+#ifdef USB_STORAGE
usb_storage_transfer_complete(ev.id);
+#endif
+
+#ifdef USB_SERIAL
+ usb_serial_transfer_complete(ev.id);
+#endif
+
}
}
#endif
@@ -380,6 +399,10 @@ void usb_core_control_request(struct usb_ctrlrequest* req)
#ifdef USB_STORAGE
usb_storage_control_request(req);
#endif
+
+#ifdef USB_SERIAL
+ usb_serial_control_request(req);
+#endif
ack_control(req);
if (req->wValue)
usb_state = CONFIGURED;
@@ -399,7 +422,7 @@ void usb_core_control_request(struct usb_ctrlrequest* req)
ack_control(req);
break;
}
-
+
case USB_REQ_SET_INTERFACE:
logf("usb_core: SET_INTERFACE");
ack_control(req);
@@ -517,6 +540,11 @@ void usb_core_control_request(struct usb_ctrlrequest* req)
/* does usb_storage know this request? */
if (!usb_storage_control_request(req))
#endif
+
+#ifdef USB_SERIAL
+ /* does usb_serial know this request? */
+ if (!usb_serial_control_request(req))
+#endif
{
/* nope. flag error */
logf("usb bad req %d", req->bRequest);
@@ -551,11 +579,11 @@ void usb_core_transfer_complete(int endpoint, bool in)
case EP_TX:
#if defined(USB_BENCHMARK)
usb_benchmark_transfer_complete(endpoint, in);
-#elif defined(USB_STORAGE)
+#elif defined(USB_STORAGE) || defined(USB_SERIAL)
queue_post(&usbcore_queue, endpoint, 0);
#endif
break;
-
+
default:
break;
}