提交 b3e38f53 编写于 作者: G Grissiom

usbdevice/core: use static message queue

Although currently the only message send to the queue is struct
udev_msg, in order to keep backward compacity and for extention in the
future, we set the size of message to 32.
上级 f0d50a7b
...@@ -1274,7 +1274,7 @@ rt_err_t rt_usbd_set_config(udevice_t device, rt_uint8_t value) ...@@ -1274,7 +1274,7 @@ rt_err_t rt_usbd_set_config(udevice_t device, rt_uint8_t value)
return RT_TRUE; return RT_TRUE;
} }
static struct rt_messagequeue *usb_mq; static struct rt_messagequeue usb_mq;
/** /**
* This function is the main entry of usb device thread, it is in charge of * This function is the main entry of usb device thread, it is in charge of
...@@ -1294,7 +1294,7 @@ static void rt_usbd_thread_entry(void* parameter) ...@@ -1294,7 +1294,7 @@ static void rt_usbd_thread_entry(void* parameter)
uep_t ep; uep_t ep;
/* receive message */ /* receive message */
if(rt_mq_recv(usb_mq, if(rt_mq_recv(&usb_mq,
&msg, sizeof(struct udev_msg), &msg, sizeof(struct udev_msg),
RT_WAITING_FOREVER) != RT_EOK ) RT_WAITING_FOREVER) != RT_EOK )
continue; continue;
...@@ -1341,13 +1341,19 @@ rt_err_t rt_usbd_post_event(struct udev_msg* msg, rt_size_t size) ...@@ -1341,13 +1341,19 @@ rt_err_t rt_usbd_post_event(struct udev_msg* msg, rt_size_t size)
RT_ASSERT(msg != RT_NULL); RT_ASSERT(msg != RT_NULL);
/* send message to usb message queue */ /* send message to usb message queue */
return rt_mq_send(usb_mq, (void*)msg, size); return rt_mq_send(&usb_mq, (void*)msg, size);
} }
ALIGN(RT_ALIGN_SIZE) ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t usb_thread_stack[RT_USBD_THREAD_STACK_SZ]; static rt_uint8_t usb_thread_stack[RT_USBD_THREAD_STACK_SZ];
static struct rt_thread usb_thread; static struct rt_thread usb_thread;
#define USBD_MQ_MSG_SZ 32
#define USBD_MQ_MAX_MSG 16
/* internal of the message queue: every message is associated with a pointer,
* so in order to recveive USBD_MQ_MAX_MSG messages, we have to allocate more
* than USBD_MQ_MSG_SZ*USBD_MQ_MAX_MSG memery. */
static rt_uint8_t usb_mq_pool[(USBD_MQ_MSG_SZ+sizeof(void*))*USBD_MQ_MAX_MSG];
/** /**
* This function will initialize usb device thread. * This function will initialize usb device thread.
...@@ -1360,7 +1366,8 @@ rt_err_t rt_usbd_core_init(void) ...@@ -1360,7 +1366,8 @@ rt_err_t rt_usbd_core_init(void)
rt_list_init(&device_list); rt_list_init(&device_list);
/* create an usb message queue */ /* create an usb message queue */
usb_mq = rt_mq_create("usbd", 32, 16, RT_IPC_FLAG_FIFO); rt_mq_init(&usb_mq, "usbd", usb_mq_pool, USBD_MQ_MSG_SZ,
sizeof(usb_mq_pool), RT_IPC_FLAG_FIFO);
/* init usb device thread */ /* init usb device thread */
rt_thread_init(&usb_thread, "usbd", rt_usbd_thread_entry, RT_NULL, rt_thread_init(&usb_thread, "usbd", rt_usbd_thread_entry, RT_NULL,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册