diff options
| author | [email protected] <[email protected]> | 2012-10-11 17:06:30 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-10-11 17:06:30 +0000 |
| commit | c752d9b09510b62e4ecc76f4fd0343eeba5c1358 (patch) | |
| tree | a2dc012f19925f765441dec1442f0a1745100f90 /components/drivers/usb/usbdevice/core | |
| parent | 051fd8eca9fb3714cafe927d093d9348b31c39a1 (diff) | |
submit the first version usb device stack.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2344 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/drivers/usb/usbdevice/core')
| -rw-r--r-- | components/drivers/usb/usbdevice/core/core.c | 65 | ||||
| -rw-r--r-- | components/drivers/usb/usbdevice/core/usbdevice.c | 86 |
2 files changed, 133 insertions, 18 deletions
diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c index 17875f18cb..7cc4ea4a0b 100644 --- a/components/drivers/usb/usbdevice/core/core.c +++ b/components/drivers/usb/usbdevice/core/core.c @@ -101,7 +101,7 @@ static rt_err_t _get_string_descriptor(struct udevice* device, ureq_t setup) if(index > USB_STRING_INTERFACE_INDEX)
{
rt_kprintf("unknown string index\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
return -RT_ERROR;
}
if(index == 0)
@@ -158,14 +158,14 @@ static rt_err_t _get_descriptor(struct udevice* device, ureq_t setup) break;
default:
rt_kprintf("unknown descriptor\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
break;
}
}
else
{
rt_kprintf("request direction error\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
}
return RT_EOK;
@@ -388,7 +388,7 @@ static rt_err_t _standard_request(struct udevice* device, ureq_t setup) _get_descriptor(device, setup);
break;
case USB_REQ_SET_DESCRIPTOR:
- dcd_ep0_stall(dcd);
+ dcd_ep_stall(dcd, 0);
break;
case USB_REQ_GET_CONFIGURATION:
_get_config(device, setup);
@@ -398,7 +398,7 @@ static rt_err_t _standard_request(struct udevice* device, ureq_t setup) break;
default:
rt_kprintf("unknown device request\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
break;
}
break;
@@ -413,7 +413,7 @@ static rt_err_t _standard_request(struct udevice* device, ureq_t setup) break;
default:
rt_kprintf("unknown interface request\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
break;
}
break;
@@ -434,17 +434,17 @@ static rt_err_t _standard_request(struct udevice* device, ureq_t setup) break;
default:
rt_kprintf("unknown endpoint request\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
break;
}
break;
case USB_REQ_TYPE_OTHER:
rt_kprintf("unknown other type request\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
break;
default:
rt_kprintf("unknown type request\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
break;
}
@@ -470,7 +470,7 @@ static rt_err_t _class_request(udevice_t device, ureq_t setup) /* verify request value */
if(setup->index > device->curr_cfg->cfg_desc.bNumInterfaces)
{
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
return -RT_ERROR;
}
@@ -484,7 +484,7 @@ static rt_err_t _class_request(udevice_t device, ureq_t setup) break;
default:
rt_kprintf("unknown class request type\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
break;
}
@@ -526,7 +526,7 @@ static rt_err_t _setup_request(udevice_t device, ureq_t setup) break;
default:
rt_kprintf("unknown setup request type\n");
- dcd_ep0_stall(device->dcd);
+ dcd_ep_stall(device->dcd, 0);
return -RT_ERROR;
}
@@ -534,6 +534,32 @@ static rt_err_t _setup_request(udevice_t device, ureq_t setup) }
/**
+ * This function will notity sof event to all of class.
+ *
+ * @param device the usb device object.
+ *
+ * @return RT_EOK.
+ */
+rt_err_t _sof_notify(udevice_t device)
+{
+ struct rt_list_node *i;
+ uclass_t cls;
+
+ RT_ASSERT(device != RT_NULL);
+
+ /* to notity every class that sof event comes */
+ for (i=device->curr_cfg->cls_list.next;
+ i!=&device->curr_cfg->cls_list; i=i->next)
+ {
+ cls = (uclass_t)rt_list_entry(i, struct uclass, list);
+ if(cls->ops->sof_handler != RT_NULL)
+ cls->ops->sof_handler(device);
+ }
+
+ return RT_EOK;
+}
+
+/**
* This function will create an usb device object.
*
* @param ustring the usb string array to contain string descriptor.
@@ -797,8 +823,6 @@ udevice_t rt_usbd_find_device(udcd_t dcd) {
struct rt_list_node* node;
udevice_t device;
-
- RT_DEBUG_LOG(RT_DEBUG_USB, ("rt_usbd_find_device\n"));
/* parameter check */
RT_ASSERT(dcd != RT_NULL);
@@ -1180,15 +1204,13 @@ static void rt_usbd_thread_entry(void* parameter) /* receive message */
if(rt_mq_recv(usb_mq, &msg, sizeof(struct udev_msg), RT_WAITING_FOREVER)
!= RT_EOK ) continue;
-
- //RT_DEBUG_LOG(RT_DEBUG_USB, ("msg type %d\n", msg.type));
switch (msg.type)
{
case USB_MSG_SETUP_NOTIFY:
- device = rt_usbd_find_device(msg.content.setup_msg.dcd);
+ device = rt_usbd_find_device(msg.dcd);
if(device != RT_NULL)
- _setup_request(device, (ureq_t)msg.content.setup_msg.packet);
+ _setup_request(device, (ureq_t)msg.content.setup_msg.packet);
else
rt_kprintf("invalid usb device\n");
break;
@@ -1199,6 +1221,13 @@ static void rt_usbd_thread_entry(void* parameter) else
rt_kprintf("invalid endpoint\n");
break;
+ case USB_MSG_SOF:
+ device = rt_usbd_find_device(msg.dcd);
+ if(device != RT_NULL)
+ _sof_notify(device);
+ else
+ rt_kprintf("invalid usb device\n");
+ break;
default:
break;
}
diff --git a/components/drivers/usb/usbdevice/core/usbdevice.c b/components/drivers/usb/usbdevice/core/usbdevice.c new file mode 100644 index 0000000000..97e370194e --- /dev/null +++ b/components/drivers/usb/usbdevice/core/usbdevice.c @@ -0,0 +1,86 @@ +/*
+ * File : usbdevice.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2012, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2012-10-02 Yi Qiu first version
+ */
+
+#include <rtthread.h>
+#include <rtdevice.h>
+#include <rtservice.h>
+
+#define RT_USB_DEVICE_CDC
+
+const static char* ustring[] =
+{
+ "Language",
+ "RT-Thread Team.",
+ "UDISK",
+ "12345678",
+ "Config",
+ "Interface",
+};
+
+rt_err_t rt_usb_device_init(const char* udc_name)
+{
+ rt_device_t udc;
+ udevice_t udevice;
+ uconfig_t cfg;
+ uclass_t cls;
+
+ RT_ASSERT(udc_name != RT_NULL);
+
+ udc = rt_device_find(udc_name);
+ if(udc == RT_NULL)
+ {
+ rt_kprintf("can't find usb device controller %s\n", udc_name);
+ return -RT_ERROR;
+ }
+
+ /* create and startup usb device thread */
+ rt_usbd_core_init();
+
+ /* create a device object */
+ udevice = rt_usbd_device_create(ustring);
+
+ /* set usb controller driver to the device */
+ rt_usbd_device_set_controller(udevice, (udcd_t)udc);
+
+ /* create a configuration object */
+ cfg = rt_usbd_config_create();
+
+#if defined RT_USB_DEVICE_MASS_STORAGE
+ /* create a mass storage class object */
+ cls = rt_usbd_class_mass_storage_create(udevice);
+#elif defined RT_USB_DEVICE_CDC
+ /* create a cdc class object */
+ cls = rt_usbd_class_cdc_create(udevice);
+#else
+ #error
+#endif
+
+ /* set device descriptor to the device */
+ rt_usbd_device_set_descriptor(udevice, cls->dev_desc);
+
+ /* add the mass storage class to the configuration */
+ rt_usbd_config_add_class(cfg, cls);
+
+ /* add the configuration to the device */
+ rt_usbd_device_add_config(udevice, cfg);
+
+ /* set default configuration to 1 */
+ rt_usbd_set_config(udevice, 1);
+
+ /* initialize usb device controller */
+ rt_device_init(udc);
+
+ return RT_EOK;
+}
+
|
