2018.07.26
Dependencies: FATFileSystem3 mbed-rtos
Fork of USBHost by
Diff: USBHost/USBHost.cpp
- Revision:
- 9:7671b6a8c363
- Parent:
- 8:93da8ea2708b
- Child:
- 10:0c11cf1cc218
--- a/USBHost/USBHost.cpp Thu Mar 14 11:49:53 2013 +0000 +++ b/USBHost/USBHost.cpp Thu Mar 14 14:20:03 2013 +0000 @@ -68,9 +68,9 @@ #endif while(1) { - osEvent evt = queue_usb_event.get(); + osEvent evt = mail_usb_event.get(); - if (evt.status == osEventMessage) { + if (evt.status == osEventMail) { l4 = !l4; message_t * usb_msg = (message_t*)evt.value.p; @@ -96,6 +96,7 @@ if (i == MAX_DEVICE_CONNECTED) { USB_ERR("Too many device connected!!\r\n"); + deviceInited[i] = false; usb_mutex.unlock(); continue; } @@ -242,7 +243,7 @@ break; } - mpool_usb_event.free(usb_msg); + mail_usb_event.free(usb_msg); } } } @@ -317,13 +318,14 @@ if (ep->getType() != CONTROL_ENDPOINT) { // callback on the processed td will be called from the usb_thread (not in ISR) - message_t * usb_msg = mpool_usb_event.alloc(); + message_t * usb_msg = mail_usb_event.alloc(); usb_msg->event_id = TD_PROCESSED_EVENT; usb_msg->td_addr = (void *)td; usb_msg->td_state = state; - queue_usb_event.put(usb_msg); + mail_usb_event.put(usb_msg); } ep->setState(state); + ep->ep_queue.put((uint8_t*)1); } } } @@ -351,13 +353,13 @@ return; } - message_t * usb_msg = mpool_usb_event.alloc(); + message_t * usb_msg = mail_usb_event.alloc(); usb_msg->event_id = DEVICE_CONNECTED_EVENT; usb_msg->hub = hub; usb_msg->port = port; usb_msg->lowSpeed = lowSpeed; usb_msg->hub_parent = hub_parent; - queue_usb_event.put(usb_msg); + mail_usb_event.put(usb_msg); } /* @@ -375,12 +377,12 @@ return; } - message_t * usb_msg = mpool_usb_event.alloc(); + message_t * usb_msg = mail_usb_event.alloc(); usb_msg->event_id = DEVICE_DISCONNECTED_EVENT; usb_msg->hub = hub; usb_msg->port = port; usb_msg->hub_parent = hub_parent; - queue_usb_event.put(usb_msg); + mail_usb_event.put(usb_msg); } void USBHost::freeDevice(USBDeviceConnected * dev) @@ -528,7 +530,7 @@ int index = findDevice(dev); if (index != -1) { USB_DBG("Resetting hub %d, port %d\n", dev->getHub(), dev->getPort()); - wait_ms(100); + Thread::wait(100); if (dev->getHub() == 0) { resetRootHub(); } @@ -537,7 +539,7 @@ dev->getHubParent()->portReset(dev->getPort()); } #endif - wait_ms(100); + Thread::wait(100); deviceReset[index] = true; return USB_TYPE_OK; } @@ -689,6 +691,7 @@ // add a transfer on the TD linked list USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) { + td_mutex.lock(); // allocate a TD which will be freed in TDcompletion volatile HCTD * td = ed->getNextTD(); @@ -720,6 +723,8 @@ ed->queueTransfer(); printList(type); enableList(type); + + td_mutex.unlock(); return USB_TYPE_PROCESSING; } @@ -887,7 +892,6 @@ return USB_TYPE_OK; } - // this method fills the USBDeviceConnected object: class,.... . It also add endpoints found in the descriptor. void USBHost::parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uint32_t len, IUSBEnumerator* pEnumerator) { @@ -985,11 +989,11 @@ USB_DBG_TRANSFER("----- %s %s [dev: %p - %s - hub: %d - port: %d - addr: %d - ep: %02X]------", type_str, (write) ? "WRITE" : "READ", dev, dev->getName(ep->getIntfNb()), dev->getHub(), dev->getPort(), dev->getAddress(), ep->getAddress()); #endif + usb_mutex.lock(); + USB_TYPE res; ENDPOINT_DIRECTION dir = (write) ? OUT : IN; - usb_mutex.lock(); - if (dev == NULL) { USB_ERR("dev NULL"); usb_mutex.unlock(); @@ -1032,7 +1036,8 @@ if (blocking) { - while((res = ep->getState()) == USB_TYPE_PROCESSING); + ep->ep_queue.get(); + res = ep->getState(); USB_DBG_TRANSFER("%s TRANSFER res: %s on ep: %p\r\n", type_str, ep->getStateString(), ep); @@ -1089,7 +1094,8 @@ control->setNextToken(TD_SETUP); addTransfer(control, (uint8_t*)setupPacket, 8); - while((res = control->getState()) == USB_TYPE_PROCESSING); + control->ep_queue.get(); + res = control->getState(); USB_DBG_TRANSFER("CONTROL setup stage %s", control->getStateString()); @@ -1103,7 +1109,8 @@ control->setNextToken(token); addTransfer(control, (uint8_t *)buf, length_transfer); - while((res = control->getState()) == USB_TYPE_PROCESSING); + control->ep_queue.get(); + res = control->getState(); #if DEBUG_TRANSFER USB_DBG_TRANSFER("CONTROL %s stage %s", (write) ? "WRITE" : "READ", control->getStateString()); @@ -1130,7 +1137,8 @@ control->setNextToken(token); addTransfer(control, NULL, 0); - while((res = control->getState()) == USB_TYPE_PROCESSING); + control->ep_queue.get(); + res = control->getState(); USB_DBG_TRANSFER("CONTROL ack stage %s", control->getStateString()); usb_mutex.unlock();