change endpoint and class handler

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2477 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
sc943313837@gmail.com 2012-12-12 16:37:38 +00:00
parent 53efe928d6
commit d8796d9639
1 changed files with 16 additions and 10 deletions

View File

@ -10,6 +10,7 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2012-10-01 Yi Qiu first version * 2012-10-01 Yi Qiu first version
* 2012-12-12 heyuanjie87 change endpoint and class handler
*/ */
#include <rtthread.h> #include <rtthread.h>
@ -318,7 +319,8 @@ static rt_err_t _set_config(struct udevice* device, ureq_t setup)
} }
} }
/* after running all endpoints, then run class */ /* after running all endpoints, then run class */
if(cls->ops->run != RT_NULL) cls->ops->run(device); if(cls->ops->run != RT_NULL)
cls->ops->run(device, cls);
} }
/* issue status stage */ /* issue status stage */
@ -557,7 +559,7 @@ rt_err_t _sof_notify(udevice_t device)
{ {
cls = (uclass_t)rt_list_entry(i, struct uclass, list); cls = (uclass_t)rt_list_entry(i, struct uclass, list);
if(cls->ops->sof_handler != RT_NULL) if(cls->ops->sof_handler != RT_NULL)
cls->ops->sof_handler(device); cls->ops->sof_handler(device, cls);
} }
return RT_EOK; return RT_EOK;
@ -793,8 +795,7 @@ uclass_t rt_usbd_class_create(udevice_t device, udev_desc_t dev_desc,
* *
* @return an usb endpoint object on success, RT_NULL on fail. * @return an usb endpoint object on success, RT_NULL on fail.
*/ */
uep_t rt_usbd_endpoint_create(uep_desc_t ep_desc, uep_t rt_usbd_endpoint_create(uep_desc_t ep_desc, udep_handler_t handler)
rt_err_t (*handler)(struct udevice*, rt_size_t size))
{ {
uep_t ep; uep_t ep;
@ -957,7 +958,7 @@ ualtsetting_t rt_usbd_find_altsetting(uintf_t intf, rt_uint8_t value)
* *
* @return an usb endpoint object on found or RT_NULL on not found. * @return an usb endpoint object on found or RT_NULL on not found.
*/ */
uep_t rt_usbd_find_endpoint(udevice_t device, rt_uint8_t ep_addr) uep_t rt_usbd_find_endpoint(udevice_t device, uclass_t* pcls, rt_uint8_t ep_addr)
{ {
uep_t ep; uep_t ep;
struct rt_list_node *i, *j, *k; struct rt_list_node *i, *j, *k;
@ -980,10 +981,14 @@ uep_t rt_usbd_find_endpoint(udevice_t device, rt_uint8_t ep_addr)
{ {
ep = (uep_t)rt_list_entry(k, struct uendpoint, list); ep = (uep_t)rt_list_entry(k, struct uendpoint, list);
if(ep->ep_desc->bEndpointAddress == ep_addr) if(ep->ep_desc->bEndpointAddress == ep_addr)
{
if (pcls != RT_NULL)
*pcls = cls;
return ep; return ep;
} }
} }
} }
}
rt_kprintf("can't find endpoint 0x%x\n", ep_addr); rt_kprintf("can't find endpoint 0x%x\n", ep_addr);
return RT_NULL; return RT_NULL;
@ -1228,6 +1233,7 @@ static void rt_usbd_thread_entry(void* parameter)
{ {
struct udev_msg msg; struct udev_msg msg;
udevice_t device; udevice_t device;
uclass_t cls;
uep_t ep; uep_t ep;
/* receive message */ /* receive message */
@ -1244,9 +1250,9 @@ static void rt_usbd_thread_entry(void* parameter)
rt_kprintf("invalid usb device\n"); rt_kprintf("invalid usb device\n");
break; break;
case USB_MSG_DATA_NOTIFY: case USB_MSG_DATA_NOTIFY:
ep = rt_usbd_find_endpoint(device, msg.content.ep_msg.ep_addr); ep = rt_usbd_find_endpoint(device, &cls, msg.content.ep_msg.ep_addr);
if(ep != RT_NULL) if(ep != RT_NULL)
ep->handler(device, msg.content.ep_msg.size); ep->handler(device, cls, msg.content.ep_msg.size);
else else
rt_kprintf("invalid endpoint\n"); rt_kprintf("invalid endpoint\n");
break; break;