summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorGrissiom <[email protected]>2013-05-12 14:48:46 +0800
committerGrissiom <[email protected]>2013-05-12 15:43:29 +0800
commitf0d50a7b3634044b4bddad39fde01d474b5c6e9d (patch)
tree26233be0c25e8e7e519ed3a99cc4c36264b047ed /components
parentf1e34eef113791bcade4befaa60b347e8cbc4ba7 (diff)
usbdevice/core: use static thread instead of dynamic thread
It also add two configurations for the USB device even loop thread: RT_USBD_THREAD_STACK_SZ to set the stack size, default to 2048 RT_USBD_THREAD_PRIO to set the priority, default to 8 You can overwrite the default values in rtconfig.h
Diffstat (limited to 'components')
-rw-r--r--components/drivers/include/drivers/usb_common.h14
-rw-r--r--components/drivers/usb/usbdevice/core/core.c23
2 files changed, 25 insertions, 12 deletions
diff --git a/components/drivers/include/drivers/usb_common.h b/components/drivers/include/drivers/usb_common.h
index 5881e11dc6..9b7f3873e1 100644
--- a/components/drivers/include/drivers/usb_common.h
+++ b/components/drivers/include/drivers/usb_common.h
@@ -374,6 +374,20 @@ typedef struct ustorage_csw* ustorage_csw_t;
#pragma pack()
+/*
+ * USB device event loop thread configurations
+ */
+/* the stack size of USB thread */
+#ifndef RT_USBD_THREAD_STACK_SZ
+#define RT_USBD_THREAD_STACK_SZ 2048
+#endif
+
+/* the priority of USB thread */
+#ifndef RT_USBD_THREAD_PRIO
+#define RT_USBD_THREAD_PRIO 8
+#endif
+
+
#ifdef __cplusplus
}
#endif
diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c
index 0717414635..58753d202e 100644
--- a/components/drivers/usb/usbdevice/core/core.c
+++ b/components/drivers/usb/usbdevice/core/core.c
@@ -1344,6 +1344,11 @@ rt_err_t rt_usbd_post_event(struct udev_msg* msg, rt_size_t size)
return rt_mq_send(usb_mq, (void*)msg, size);
}
+
+ALIGN(RT_ALIGN_SIZE)
+static rt_uint8_t usb_thread_stack[RT_USBD_THREAD_STACK_SZ];
+static struct rt_thread usb_thread;
+
/**
* This function will initialize usb device thread.
*
@@ -1352,21 +1357,15 @@ rt_err_t rt_usbd_post_event(struct udev_msg* msg, rt_size_t size)
*/
rt_err_t rt_usbd_core_init(void)
{
- rt_thread_t thread;
-
rt_list_init(&device_list);
/* create an usb message queue */
usb_mq = rt_mq_create("usbd", 32, 16, RT_IPC_FLAG_FIFO);
- /* create usb device thread */
- thread = rt_thread_create("usbd", rt_usbd_thread_entry, RT_NULL,
- 2048, 8, 20);
- if(thread != RT_NULL)
- {
- /* startup usb device thread */
- rt_thread_startup(thread);
- }
-
- return RT_EOK;
+ /* init usb device thread */
+ rt_thread_init(&usb_thread, "usbd", rt_usbd_thread_entry, RT_NULL,
+ usb_thread_stack, RT_USBD_THREAD_STACK_SZ, RT_USBD_THREAD_PRIO, 20);
+ /* rt_thread_init should always be OK, so start the thread without further
+ * checking. */
+ return rt_thread_startup(&usb_thread);
}