summaryrefslogtreecommitdiff
path: root/components/drivers/usb/usbdevice
diff options
context:
space:
mode:
authorGrissiom <[email protected]>2013-06-06 15:21:40 +0800
committerGrissiom <[email protected]>2013-06-06 15:21:40 +0800
commited19483cb4f026c40e7c6a6bc09583e054ef0c5e (patch)
tree3b4b61b512546e0fc1b2cc80be0992446729ff96 /components/drivers/usb/usbdevice
parent03e8d24688ae56c6c53db81e42d40109026d1aac (diff)
usb: add USB_MSG_PLUG_OUT event
When the core received an USB_MSG_PLUG_OUT event, it will stop all the classes. This make a chance that the classes could get rid off doing useless stuff while the USB cable is plugged out.
Diffstat (limited to 'components/drivers/usb/usbdevice')
-rw-r--r--components/drivers/usb/usbdevice/core/core.c56
1 files changed, 52 insertions, 4 deletions
diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c
index 45264033a9..c2965d6bb2 100644
--- a/components/drivers/usb/usbdevice/core/core.c
+++ b/components/drivers/usb/usbdevice/core/core.c
@@ -667,13 +667,13 @@ rt_err_t _sof_notify(udevice_t device)
}
/**
- * This function will reset all class.
+ * This function will stop all class.
*
* @param device the usb device object.
*
* @return RT_EOK.
*/
-rt_err_t _reset_notify(udevice_t device)
+rt_err_t _stop_notify(udevice_t device)
{
struct rt_list_node *i;
uclass_t cls;
@@ -681,13 +681,38 @@ rt_err_t _reset_notify(udevice_t device)
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)
+ 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->stop != RT_NULL)
cls->ops->stop(device, cls);
+ }
+ return RT_EOK;
+}
+
+/**
+ * This function will run all class.
+ *
+ * @param device the usb device object.
+ *
+ * @return RT_EOK.
+ */
+rt_err_t _run_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->run != RT_NULL)
cls->ops->run(device, cls);
}
@@ -696,6 +721,26 @@ rt_err_t _reset_notify(udevice_t device)
}
/**
+ * This function will reset all class.
+ *
+ * @param device the usb device object.
+ *
+ * @return RT_EOK.
+ */
+rt_err_t _reset_notify(udevice_t device)
+{
+ struct rt_list_node *i;
+ uclass_t cls;
+
+ RT_ASSERT(device != RT_NULL);
+
+ _stop_notify();
+ _run_notify();
+
+ return RT_EOK;
+}
+
+/**
* This function will create an usb device object.
*
* @param ustring the usb string array to contain string descriptor.
@@ -1415,6 +1460,9 @@ static void rt_usbd_thread_entry(void* parameter)
if (device->state == USB_STATE_ADDRESS)
_reset_notify(device);
break;
+ case USB_MSG_PLUG_OUT:
+ _stop_notify(device);
+ break;
default:
rt_kprintf("unknown msg type\n");
break;