diff options
| author | Meco Jianting Man <[email protected]> | 2021-03-03 10:46:17 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-03-03 10:46:17 -0600 |
| commit | 034046c32ecf8e94f36fc25eb35ec78f6e549da1 (patch) | |
| tree | d99d68d92e76f6b9df8d841462086a107317cb41 /components | |
| parent | fab4c5ebb13fd92273de8727c0f18d53716295ff (diff) | |
| parent | 4a40ba95358139aed460369a91ff995cad2f8ce5 (diff) | |
Merge pull request #23 from RT-Thread/master
pr
Diffstat (limited to 'components')
| -rwxr-xr-x | components/drivers/Kconfig | 8 | ||||
| -rw-r--r-- | components/drivers/include/ipc/workqueue.h | 2 | ||||
| -rw-r--r-- | components/drivers/src/workqueue.c | 289 | ||||
| -rw-r--r-- | components/drivers/usb/usbhost/class/hid.c | 131 | ||||
| -rw-r--r-- | components/drivers/usb/usbhost/class/hid.h | 12 | ||||
| -rw-r--r-- | components/drivers/usb/usbhost/class/umouse.c | 25 | ||||
| -rw-r--r-- | components/net/at/src/at_client.c | 22 | ||||
| -rw-r--r-- | components/utilities/ulog/ulog.c | 35 |
8 files changed, 273 insertions, 251 deletions
diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index 006497519f..b0caabc73c 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -642,6 +642,14 @@ menu "Using USB" string "Udisk mount dir" default "/" endif + config RT_USBH_HID + bool "Enable HID Drivers" + default n + if RT_USBH_HID + config RT_USBH_HID_MOUSE + bool "Enable HID mouse protocol" + default n + endif endif config RT_USING_USB_DEVICE bool "Using USB device" diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index 23e256c420..11fee489bd 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -29,6 +29,7 @@ enum struct rt_workqueue { rt_list_t work_list; + rt_list_t delayed_list; struct rt_work *work_current; /* current work */ struct rt_semaphore sem; @@ -62,6 +63,7 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work); rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time); rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work); rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work); +rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue); #ifdef RT_USING_SYSTEM_WORKQUEUE rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time); diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index 2b5630d8d0..7aea647703 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -58,15 +58,17 @@ static void _workqueue_thread_entry(void *parameter) while (1) { + level = rt_hw_interrupt_disable(); if (rt_list_isempty(&(queue->work_list))) { /* no software timer exist, suspend self. */ rt_thread_suspend(rt_thread_self()); + rt_hw_interrupt_enable(level); rt_schedule(); + continue; } /* we have work to do with. */ - level = rt_hw_interrupt_disable(); work = rt_list_entry(queue->work_list.next, struct rt_work, list); rt_list_remove(&(work->list)); queue->work_current = work; @@ -76,175 +78,134 @@ static void _workqueue_thread_entry(void *parameter) /* do work */ work->work_func(work, work->work_data); - level = rt_hw_interrupt_disable(); /* clean current work */ queue->work_current = RT_NULL; - rt_hw_interrupt_enable(level); /* ack work completion */ _workqueue_work_completion(queue); } } -static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work) +static rt_err_t _workqueue_submit_work(struct rt_workqueue *queue, + struct rt_work *work, rt_tick_t ticks) { rt_base_t level; + rt_err_t err; level = rt_hw_interrupt_disable(); - if (work->flags & RT_WORK_STATE_PENDING) - { - rt_hw_interrupt_enable(level); - return -RT_EBUSY; - } - - if (queue->work_current == work) - { - rt_hw_interrupt_enable(level); - return -RT_EBUSY; - } - - /* NOTE: the work MUST be initialized firstly */ + /* remove list */ rt_list_remove(&(work->list)); - - rt_list_insert_after(queue->work_list.prev, &(work->list)); - work->flags |= RT_WORK_STATE_PENDING; - - /* whether the workqueue is doing work */ - if (queue->work_current == RT_NULL) + work->flags &= ~RT_WORK_STATE_PENDING; + /* */ + if (ticks == 0) { - rt_hw_interrupt_enable(level); - /* resume work thread */ - rt_thread_resume(queue->work_thread); - rt_schedule(); + if (queue->work_current != work) + { + rt_list_insert_after(queue->work_list.prev, &(work->list)); + work->flags |= RT_WORK_STATE_PENDING; + work->workqueue = queue; + err = RT_EOK; + } + else + { + err = -RT_EBUSY; + } + + /* whether the workqueue is doing work */ + if (queue->work_current == RT_NULL && + ((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) + { + /* resume work thread */ + rt_thread_resume(queue->work_thread); + rt_hw_interrupt_enable(level); + rt_schedule(); + } + else + { + rt_hw_interrupt_enable(level); + } + return err; } - else + else if (ticks < RT_TICK_MAX / 2) { + /* Timer started */ + if (work->flags & RT_WORK_STATE_SUBMITTING) + { + rt_timer_stop(&work->timer); + rt_timer_control(&work->timer, RT_TIMER_CTRL_SET_TIME, &ticks); + } + else + { + rt_timer_init(&(work->timer), "work", _delayed_work_timeout_handler, + work, ticks, RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER); + work->flags |= RT_WORK_STATE_SUBMITTING; + } + work->workqueue = queue; + /* insert delay work list */ + rt_list_insert_after(queue->delayed_list.prev, &(work->list)); rt_hw_interrupt_enable(level); + rt_timer_start(&(work->timer)); + return RT_EOK; } - - return RT_EOK; + rt_hw_interrupt_enable(level); + return -RT_ERROR; } static rt_err_t _workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work) { rt_base_t level; + rt_err_t err; level = rt_hw_interrupt_disable(); - if (queue->work_current == work) - { - rt_hw_interrupt_enable(level); - return -RT_EBUSY; - } rt_list_remove(&(work->list)); work->flags &= ~RT_WORK_STATE_PENDING; - rt_hw_interrupt_enable(level); - - return RT_EOK; -} - -static rt_err_t _workqueue_cancel_delayed_work(struct rt_work *work) -{ - rt_base_t level; - int ret = RT_EOK; - - if (!work->workqueue) - { - ret = -EINVAL; - goto __exit; - } - - if (work->flags & RT_WORK_STATE_PENDING) - { - /* Remove from the queue if already submitted */ - ret = _workqueue_cancel_work(work->workqueue, work); - if (ret) - { - goto __exit; - } - } - else + /* Timer started */ + if (work->flags & RT_WORK_STATE_SUBMITTING) { - if (work->flags & RT_WORK_STATE_SUBMITTING) - { - level = rt_hw_interrupt_disable(); - rt_timer_stop(&(work->timer)); - rt_timer_detach(&(work->timer)); - work->flags &= ~RT_WORK_STATE_SUBMITTING; - rt_hw_interrupt_enable(level); - } + rt_timer_stop(&(work->timer)); + rt_timer_detach(&(work->timer)); + work->flags &= ~RT_WORK_STATE_SUBMITTING; } - - level = rt_hw_interrupt_disable(); - /* Detach from workqueue */ + err = queue->work_current != work ? RT_EOK : -RT_EBUSY; work->workqueue = RT_NULL; - work->flags &= ~(RT_WORK_STATE_PENDING); rt_hw_interrupt_enable(level); - -__exit: - return ret; + return err; } -static rt_err_t _workqueue_submit_delayed_work(struct rt_workqueue *queue, - struct rt_work *work, rt_tick_t ticks) +static void _delayed_work_timeout_handler(void *parameter) { + struct rt_work *work; + struct rt_workqueue *queue; rt_base_t level; - rt_err_t ret = RT_EOK; - /* Work cannot be active in multiple queues */ - if (work->workqueue && work->workqueue != queue) - { - ret = -RT_EINVAL; - goto __exit; - } + work = (struct rt_work *)parameter; + queue = work->workqueue; + RT_ASSERT(queue != RT_NULL); - /* Cancel if work has been submitted */ - if (work->workqueue == queue) + level = rt_hw_interrupt_disable(); + rt_timer_detach(&(work->timer)); + work->flags &= ~RT_WORK_STATE_SUBMITTING; + /* remove delay list */ + rt_list_remove(&(work->list)); + /* insert work queue */ + if (queue->work_current != work) { - ret = _workqueue_cancel_delayed_work(work); - if (ret < 0) - { - goto __exit; - } + rt_list_insert_after(queue->work_list.prev, &(work->list)); + work->flags |= RT_WORK_STATE_PENDING; } - - level = rt_hw_interrupt_disable(); - /* Attach workqueue so the timeout callback can submit it */ - work->workqueue = queue; - rt_hw_interrupt_enable(level); - - if (!ticks) + /* whether the workqueue is doing work */ + if (queue->work_current == RT_NULL && + ((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) { - /* Submit work if no ticks is 0 */ - ret = _workqueue_submit_work(work->workqueue, work); + /* resume work thread */ + rt_thread_resume(queue->work_thread); + rt_hw_interrupt_enable(level); + rt_schedule(); } else { - level = rt_hw_interrupt_disable(); - /* Add timeout */ - work->flags |= RT_WORK_STATE_SUBMITTING; - rt_timer_init(&(work->timer), "work", _delayed_work_timeout_handler, work, ticks, - RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER); rt_hw_interrupt_enable(level); - rt_timer_start(&(work->timer)); } - -__exit: - return ret; -} - -static void _delayed_work_timeout_handler(void *parameter) -{ - struct rt_work *delayed_work; - rt_base_t level; - - delayed_work = (struct rt_work *)parameter; - level = rt_hw_interrupt_disable(); - rt_timer_stop(&(delayed_work->timer)); - rt_timer_detach(&(delayed_work->timer)); - delayed_work->flags &= ~RT_WORK_STATE_SUBMITTING; - delayed_work->type &= ~RT_WORK_TYPE_DELAYED; - rt_hw_interrupt_enable(level); - _workqueue_submit_work(delayed_work->workqueue, delayed_work); } struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority) @@ -256,6 +217,7 @@ struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_siz { /* initialize work list */ rt_list_init(&(queue->work_list)); + rt_list_init(&(queue->delayed_list)); queue->work_current = RT_NULL; rt_sem_init(&(queue->sem), "wqueue", 0, RT_IPC_FLAG_FIFO); @@ -277,7 +239,9 @@ rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue) { RT_ASSERT(queue != RT_NULL); + rt_workqueue_cancel_all_work(queue); rt_thread_delete(queue->work_thread); + rt_sem_detach(&(queue->sem)); RT_KERNEL_FREE(queue); return RT_EOK; @@ -288,7 +252,7 @@ rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work) RT_ASSERT(queue != RT_NULL); RT_ASSERT(work != RT_NULL); - return _workqueue_submit_work(queue, work); + return _workqueue_submit_work(queue, work, 0); } rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t time) @@ -296,19 +260,7 @@ rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *wo RT_ASSERT(queue != RT_NULL); RT_ASSERT(work != RT_NULL); - if (time > 0) - { - work->type |= RT_WORK_TYPE_DELAYED; - } - - if (work->type & RT_WORK_TYPE_DELAYED) - { - return _workqueue_submit_delayed_work(queue, work, time); - } - else - { - return _workqueue_submit_work(queue, work); - } + return _workqueue_submit_work(queue, work, time); } rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work *work) @@ -318,51 +270,38 @@ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work * RT_ASSERT(work != RT_NULL); level = rt_hw_interrupt_disable(); - if (queue->work_current == work) - { - rt_hw_interrupt_enable(level); - return -RT_EBUSY; - } - /* NOTE: the work MUST be initialized firstly */ rt_list_remove(&(work->list)); - - rt_list_insert_after(queue->work_list.prev, &(work->list)); - if (queue->work_current == RT_NULL) + rt_list_insert_after(&queue->work_list, &(work->list)); + /* whether the workqueue is doing work */ + if (queue->work_current == RT_NULL && + ((queue->work_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)) { - rt_hw_interrupt_enable(level); /* resume work thread */ rt_thread_resume(queue->work_thread); + rt_hw_interrupt_enable(level); rt_schedule(); } - else rt_hw_interrupt_enable(level); + else + { + rt_hw_interrupt_enable(level); + } return RT_EOK; } rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work) { - RT_ASSERT(queue != RT_NULL); RT_ASSERT(work != RT_NULL); - - if (work->type & RT_WORK_TYPE_DELAYED) - { - return _workqueue_cancel_delayed_work(work); - } - else - { - return _workqueue_cancel_work(queue, work); - } + RT_ASSERT(queue != RT_NULL); + return _workqueue_cancel_work(queue, work); } rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work) { - rt_base_t level; - RT_ASSERT(queue != RT_NULL); RT_ASSERT(work != RT_NULL); - level = rt_hw_interrupt_disable(); if (queue->work_current == work) /* it's current work in the queue */ { /* wait for work completion */ @@ -370,24 +309,30 @@ rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_wor } else { - rt_list_remove(&(work->list)); + _workqueue_cancel_work(queue, work); } - work->flags &= ~RT_WORK_STATE_PENDING; - rt_hw_interrupt_enable(level); return RT_EOK; } rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue) { - struct rt_list_node *node, *next; + struct rt_work *work; + RT_ASSERT(queue != RT_NULL); + /* cancel work */ rt_enter_critical(); - for (node = queue->work_list.next; node != &(queue->work_list); node = next) + while (rt_list_isempty(&queue->work_list) == RT_FALSE) + { + work = rt_list_first_entry(&queue->work_list, struct rt_work, list); + _workqueue_cancel_work(queue, work); + } + /* cancel delay work */ + while (rt_list_isempty(&queue->delayed_list) == RT_FALSE) { - next = node->next; - rt_list_remove(node); + work = rt_list_first_entry(&queue->delayed_list, struct rt_work, list); + _workqueue_cancel_work(queue, work); } rt_exit_critical(); @@ -416,14 +361,14 @@ rt_err_t rt_work_cancel(struct rt_work *work) int rt_work_sys_workqueue_init(void) { if (sys_workq != RT_NULL) - return 0; + return RT_EOK; sys_workq = rt_workqueue_create("sys_work", RT_SYSTEM_WORKQUEUE_STACKSIZE, RT_SYSTEM_WORKQUEUE_PRIORITY); + RT_ASSERT(sys_workq != RT_NULL); return RT_EOK; } - INIT_PREV_EXPORT(rt_work_sys_workqueue_init); #endif #endif diff --git a/components/drivers/usb/usbhost/class/hid.c b/components/drivers/usb/usbhost/class/hid.c index e16096877f..b097b01679 100644 --- a/components/drivers/usb/usbhost/class/hid.c +++ b/components/drivers/usb/usbhost/class/hid.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2011-12-12 Yi Qiu first version + * 2021-02-23 Leslie Lee update with current usb api */ #include <rtthread.h> @@ -26,7 +27,7 @@ static rt_list_t _protocal_list; * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id) +rt_err_t rt_usbh_hid_set_idle(struct uhintf* intf, int duration, int report_id) { struct urequest setup; struct uinstance* device; @@ -40,14 +41,15 @@ rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id) setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE; - setup.request = USB_REQ_SET_IDLE; - setup.index = 0; - setup.length = 0; - setup.value = (duration << 8 )| report_id; + setup.bRequest = USB_REQ_SET_IDLE; + setup.wIndex = 0; + setup.wLength = 0; + setup.wValue = (duration << 8 )| report_id; - if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0, - timeout) == 0) return RT_EOK; - else return -RT_FALSE; + if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) + return RT_EOK; + else + return -RT_FALSE; } /** @@ -59,7 +61,7 @@ rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id) * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type, +rt_err_t rt_usbh_hid_get_report(struct uhintf* intf, rt_uint8_t type, rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size) { struct urequest setup; @@ -74,14 +76,24 @@ rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type, setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE; - setup.request = USB_REQ_GET_REPORT; - setup.index = intf->intf_desc->bInterfaceNumber; - setup.length = size; - setup.value = (type << 8 ) + id; + setup.bRequest = USB_REQ_GET_REPORT; + setup.wIndex = intf->intf_desc->bInterfaceNumber; + setup.wLength = size; + setup.wValue = (type << 8 ) + id; - if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, size, - timeout) == size) return RT_EOK; - else return -RT_FALSE; + if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) + { + if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_in, buffer, size, timeout) == size) + { + if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_out, RT_NULL, 0, timeout) == 0) + { + return RT_EOK; + } + } + } + else + return -RT_FALSE; + return -RT_FALSE; } /** @@ -93,7 +105,7 @@ rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type, * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size) +rt_err_t rt_usbh_hid_set_report(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size) { struct urequest setup; struct uinstance* device; @@ -107,14 +119,15 @@ rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_ setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE; - setup.request = USB_REQ_SET_REPORT; - setup.index = intf->intf_desc->bInterfaceNumber; - setup.length = size; - setup.value = 0x02 << 8; + setup.bRequest = USB_REQ_SET_REPORT; + setup.wIndex = intf->intf_desc->bInterfaceNumber; + setup.wLength = size; + setup.wValue = 0x02 << 8; - if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, size, - timeout) == size) return RT_EOK; - else return -RT_FALSE; + if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) + return RT_EOK; + else + return -RT_FALSE; } /** @@ -125,7 +138,7 @@ rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_ * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol) +rt_err_t rt_usbh_hid_set_protocal(struct uhintf* intf, int protocol) { struct urequest setup; struct uinstance* device; @@ -139,14 +152,15 @@ rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol) setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE; - setup.request = USB_REQ_SET_PROTOCOL; - setup.index = 0; - setup.length = 0; - setup.value = protocol; + setup.bRequest = USB_REQ_SET_PROTOCOL; + setup.wIndex = 0; + setup.wLength = 0; + setup.wValue = protocol; - if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, RT_NULL, 0, - timeout) == 0) return RT_EOK; - else return -RT_FALSE; + if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) + return RT_EOK; + else + return -RT_FALSE; } /** @@ -159,7 +173,7 @@ rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol) * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_hid_get_report_descriptor(struct uintf* intf, +rt_err_t rt_usbh_hid_get_report_descriptor(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size) { struct urequest setup; @@ -174,14 +188,24 @@ rt_err_t rt_usbh_hid_get_report_descriptor(struct uintf* intf, setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_STANDARD| USB_REQ_TYPE_INTERFACE; - setup.request = USB_REQ_GET_DESCRIPTOR; - setup.index = 0; - setup.length = size; - setup.value = USB_DESC_TYPE_REPORT << 8; + setup.bRequest = USB_REQ_GET_DESCRIPTOR; + setup.wIndex = 0; + setup.wLength = size; + setup.wValue = USB_DESC_TYPE_REPORT << 8; - if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, buffer, size, - timeout) == size) return RT_EOK; - else return -RT_FALSE; + if (rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8) + { + if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_in, buffer, size, timeout) == size) + { + if (rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_out, RT_NULL, 0, timeout) == 0) + { + return RT_EOK; + } + } + } + else + return -RT_FALSE; + return -RT_FALSE; } /** @@ -220,16 +244,16 @@ static void rt_usbh_hid_callback(void* context) RT_ASSERT(context != RT_NULL); pipe = (upipe_t)context; - hid = (struct uhid*)pipe->intf->user_data; + hid = (struct uhid*)((struct uhintf*)pipe->inst)->user_data; /* invoke protocal callback function */ hid->protocal->callback((void*)hid); /* parameter check */ - RT_ASSERT(pipe->intf->device->hcd != RT_NULL); + RT_ASSERT(((struct uhintf*)pipe->inst)->device->hcd != RT_NULL); - rt_usb_hcd_int_xfer(pipe->intf->device->hcd, pipe, hid->buffer, - pipe->ep.wMaxPacketSize, timeout); + rt_usb_hcd_pipe_xfer(((struct uhintf*)pipe->inst)->device->hcd, pipe, + hid->buffer, pipe->ep.wMaxPacketSize, timeout); } /** @@ -268,9 +292,7 @@ static rt_err_t rt_usbh_hid_enable(void* arg) int i = 0, pro_id; uprotocal_t protocal; struct uhid* hid; - struct uintf* intf = (struct uintf*)arg; - int timeout = USB_TIMEOUT_BASIC; - upipe_t pipe; + struct uhintf* intf = (struct uhintf*)arg; /* parameter check */ if(intf == RT_NULL) @@ -319,19 +341,13 @@ static rt_err_t rt_usbh_hid_enable(void* arg) if(!(ep_desc->bEndpointAddress & USB_DIR_IN)) continue; ret = rt_usb_hcd_alloc_pipe(intf->device->hcd, &hid->pipe_in, - intf, ep_desc, rt_usbh_hid_callback); + intf, ep_desc); if(ret != RT_EOK) return ret; } /* initialize hid protocal */ - hid->protocal->init((void*)intf); - pipe = hid->pipe_in; + hid->protocal->init((void*)intf); - /* parameter check */ - RT_ASSERT(pipe->intf->device->hcd != RT_NULL); - - rt_usb_hcd_int_xfer(pipe->intf->device->hcd, hid->pipe_in, - hid->buffer, hid->pipe_in->ep.wMaxPacketSize, timeout); return RT_EOK; } @@ -346,7 +362,7 @@ static rt_err_t rt_usbh_hid_enable(void* arg) static rt_err_t rt_usbh_hid_disable(void* arg) { struct uhid* hid; - struct uintf* intf = (struct uintf*)arg; + struct uhintf* intf = (struct uhintf*)arg; RT_ASSERT(intf != RT_NULL); @@ -364,9 +380,6 @@ static rt_err_t rt_usbh_hid_disable(void* arg) /* free the hid instance */ rt_free(hid); } - - /* free the instance */ - rt_free(intf); return RT_EOK; } diff --git a/components/drivers/usb/usbhost/class/hid.h b/components/drivers/usb/usbhost/class/hid.h index 8e446c8cea..dbef84abbe 100644 --- a/components/drivers/usb/usbhost/class/hid.h +++ b/components/drivers/usb/usbhost/class/hid.h @@ -31,11 +31,11 @@ typedef struct uhid uhid_t; #define USB_HID_KEYBOARD 1 #define USB_HID_MOUSE 2 -rt_err_t rt_usbh_hid_set_idle(struct uintf* intf, int duration, int report_id); -rt_err_t rt_usbh_hid_get_report(struct uintf* intf, rt_uint8_t type, rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size); -rt_err_t rt_usbh_hid_set_report(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size); -rt_err_t rt_usbh_hid_set_protocal(struct uintf* intf, int protocol); -rt_err_t rt_usbh_hid_get_report_descriptor(struct uintf* intf, rt_uint8_t *buffer, rt_size_t size); +rt_err_t rt_usbh_hid_set_idle(struct uhintf* intf, int duration, int report_id); +rt_err_t rt_usbh_hid_get_report(struct uhintf* intf, rt_uint8_t type, rt_uint8_t id, rt_uint8_t *buffer, rt_size_t size); +rt_err_t rt_usbh_hid_set_report(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size); +rt_err_t rt_usbh_hid_set_protocal(struct uhintf* intf, int protocol); +rt_err_t rt_usbh_hid_get_report_descriptor(struct uhintf* intf, rt_uint8_t *buffer, rt_size_t size); rt_err_t rt_usbh_hid_protocal_register(uprotocal_t protocal); -#endif +#endif
\ No newline at end of file diff --git a/components/drivers/usb/usbhost/class/umouse.c b/components/drivers/usb/usbhost/class/umouse.c index e769475a98..7f50c0451f 100644 --- a/components/drivers/usb/usbhost/class/umouse.c +++ b/components/drivers/usb/usbhost/class/umouse.c @@ -126,15 +126,36 @@ static rt_err_t rt_usbh_hid_mouse_callback(void* arg) return RT_EOK; } +rt_thread_t mouse_thread; +void mouse_task(void* param) +{ + struct uhintf* intf = (struct uhintf*)param; + while (1) + { + if (rt_usb_hcd_pipe_xfer(intf->device->hcd, ((struct uhid*)intf->user_data)->pipe_in, + ((struct uhid*)intf->user_data)->buffer, ((struct uhid*)intf->user_data)->pipe_in->ep.wMaxPacketSize, + USB_TIMEOUT_BASIC) == 0) + { + break; + } + + rt_usbh_hid_mouse_callback(intf->user_data); + } +} + + static rt_err_t rt_usbh_hid_mouse_init(void* arg) { - struct uintf* intf = (struct uintf*)arg; + struct uhintf* intf = (struct uhintf*)arg; RT_ASSERT(intf != RT_NULL); rt_usbh_hid_set_protocal(intf, 0); - rt_usbh_hid_set_idle(intf, 10, 0); + rt_usbh_hid_set_idle(intf, 0, 0); + + mouse_thread = rt_thread_create("mouse0", mouse_task, intf, 500, 8, 100); + rt_thread_startup(mouse_thread); RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb mouse\n")); #ifdef RT_USING_RTGUI diff --git a/components/net/at/src/at_client.c b/components/net/at/src/at_client.c index b9d0ee89cb..f46abd5cd4 100644 --- a/components/net/at/src/at_client.c +++ b/components/net/at/src/at_client.c @@ -434,20 +434,18 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo { rt_err_t result = RT_EOK; -__retry: - result = rt_sem_take(client->rx_notice, rt_tick_from_millisecond(timeout)); - if (result != RT_EOK) - { - return result; - } - if(rt_device_read(client->device, 0, ch, 1) == 1) - { - return RT_EOK; - } - else + while (rt_device_read(client->device, 0, ch, 1) == 0) { - goto __retry; + result = rt_sem_take(client->rx_notice, rt_tick_from_millisecond(timeout)); + if (result != RT_EOK) + { + return result; + } + + rt_sem_control(client->rx_notice, RT_IPC_CMD_RESET, RT_NULL); } + + return RT_EOK; } /** diff --git a/components/utilities/ulog/ulog.c b/components/utilities/ulog/ulog.c index 7b4cb80c3a..b4571f4920 100644 --- a/components/utilities/ulog/ulog.c +++ b/components/utilities/ulog/ulog.c @@ -667,6 +667,9 @@ void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t s rt_size_t i, j; rt_size_t log_len = 0, name_len = rt_strlen(tag); +#ifdef ULOG_OUTPUT_TIME + rt_size_t time_head_len = 0; +#endif char *log_buf = NULL, dump_string[8]; int fmt_result; @@ -703,6 +706,35 @@ void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t s /* package header */ if (i == 0) { +#ifdef ULOG_OUTPUT_TIME + /* add time info */ +#ifdef ULOG_TIME_USING_TIMESTAMP + static time_t now; + static struct tm *tm, tm_tmp; + + now = time(NULL); + tm = gmtime_r(&now, &tm_tmp); + +#ifdef RT_USING_SOFT_RTC + rt_snprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, "%02d-%02d %02d:%02d:%02d.%03d ", tm->tm_mon + 1, + tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, rt_tick_get() % 1000); +#else + rt_snprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, "%02d-%02d %02d:%02d:%02d ", tm->tm_mon + 1, + tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); +#endif /* RT_USING_SOFT_RTC */ + +#else + static rt_size_t tick_len = 0; + + log_buf[log_len] = '['; + tick_len = ulog_ultoa(log_buf + log_len + 1, rt_tick_get()); + log_buf[log_len + 1 + tick_len] = ']'; + log_buf[log_len + 2 + tick_len] = ' '; + log_buf[log_len + 3 + tick_len] = '\0'; +#endif /* ULOG_TIME_USING_TIMESTAMP */ + time_head_len = rt_strlen(log_buf + log_len); + log_len += time_head_len; +#endif /* ULOG_OUTPUT_TIME */ log_len += ulog_strcpy(log_len, log_buf + log_len, "D/HEX "); log_len += ulog_strcpy(log_len, log_buf + log_len, tag); log_len += ulog_strcpy(log_len, log_buf + log_len, ": "); @@ -710,6 +742,9 @@ void ulog_hexdump(const char *tag, rt_size_t width, rt_uint8_t *buf, rt_size_t s else { log_len = 6 + name_len + 2; +#ifdef ULOG_OUTPUT_TIME + log_len += time_head_len; +#endif rt_memset(log_buf, ' ', log_len); } fmt_result = rt_snprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE, "%04X-%04X: ", i, i + width - 1); |
