Added TARGET_DISCO_F469NI in USBHOST\USBHost\TARGET_STM\USBHALHost_STM_TARGET.h

Dependents:   DISCO-F469NI_USB_Disk STM32F4xx_USB_Memory

Fork of USBHOST by ST

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Wed Apr 26 18:11:37 2017 +0200
Revision:
5:fc157e6bd5a5
Parent:
1:ab240722d7ef
Child:
8:3e7a33f81048
update for hub support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1 /* mbed USBHost Library
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 2 * Copyright (c) 2006-2013 ARM Limited
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 3 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 4 * Licensed under the Apache License, Version 2.0 (the "License");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 5 * you may not use this file except in compliance with the License.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 6 * You may obtain a copy of the License at
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 7 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 8 * http://www.apache.org/licenses/LICENSE-2.0
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 9 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 10 * Unless required by applicable law or agreed to in writing, software
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 11 * distributed under the License is distributed on an "AS IS" BASIS,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 13 * See the License for the specific language governing permissions and
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 14 * limitations under the License.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 15 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 16
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 17
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 18 #include "USBHost.h"
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 19 #include "USBHostHub.h"
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 20
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 21 USBHost * USBHost::instHost = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 22
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 23 #define DEVICE_CONNECTED_EVENT (1 << 0)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 24 #define DEVICE_DISCONNECTED_EVENT (1 << 1)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 25 #define TD_PROCESSED_EVENT (1 << 2)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 26
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 27 #define MAX_TRY_ENUMERATE_HUB 3
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 28
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 29 #define MIN(a, b) ((a > b) ? b : a)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 30
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 31 /**
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 32 * How interrupts are processed:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 33 * - new device connected:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 34 * - a message is queued in queue_usb_event with the id DEVICE_CONNECTED_EVENT
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 35 * - when the usb_thread receives the event, it:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 36 * - resets the device
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 37 * - reads the device descriptor
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 38 * - sets the address of the device
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 39 * - if it is a hub, enumerates it
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 40 * - device disconnected:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 41 * - a message is queued in queue_usb_event with the id DEVICE_DISCONNECTED_EVENT
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 42 * - when the usb_thread receives the event, it:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 43 * - free the device and all its children (hub)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 44 * - td processed
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 45 * - a message is queued in queue_usb_event with the id TD_PROCESSED_EVENT
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 46 * - when the usb_thread receives the event, it:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 47 * - call the callback attached to the endpoint where the td is attached
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 48 */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 49 void USBHost::usb_process()
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 50 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 51
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 52 bool controlListState;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 53 bool bulkListState;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 54 bool interruptListState;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 55 USBEndpoint * ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 56 uint8_t i, j, res, timeout_set_addr = 10;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 57 uint8_t buf[8];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 58 bool too_many_hub;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 59 int idx;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 60
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 61 #if DEBUG_TRANSFER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 62 uint8_t * buf_transfer;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 63 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 64
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 65 #if MAX_HUB_NB
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 66 uint8_t k;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 67 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 68
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 69 while(1) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 70 osEvent evt = mail_usb_event.get();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 71
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 72 if (evt.status == osEventMail) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 73
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 74 message_t * usb_msg = (message_t*)evt.value.p;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 75
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 76 switch (usb_msg->event_id) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 77
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 78 // a new device has been connected
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 79 case DEVICE_CONNECTED_EVENT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 80 too_many_hub = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 81 buf[4] = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 82
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 83 do {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 84 Lock lock(this);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 85 bool hub_unplugged = true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 86
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 87 int idx = findDevice(usb_msg->hub, usb_msg->port, (USBHostHub *)(usb_msg->hub_parent));
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 88 /* check that hub is connected to root port */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 89 if (usb_msg->hub_parent) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 90 /* a hub device must be present */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 91 for (k = 0; k < MAX_HUB_NB; k++) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 92 if ((&hubs[k] == usb_msg->hub_parent) && (hub_in_use[k]))
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 93 hub_unplugged=false;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 94 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 95 } else hub_unplugged = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 96
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 97 if (((idx!=-1) && deviceInUse[idx] ) || ((idx == -1) && hub_unplugged))
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 98 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 99
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 100 for (i =0 ; i < MAX_DEVICE_CONNECTED; i++) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 101 if (!deviceInUse[i]) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 102 USB_DBG_EVENT("new device connected: %p\r\n", &devices[i]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 103 devices[i].init(usb_msg->hub, usb_msg->port, usb_msg->lowSpeed);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 104 deviceReset[i] = false;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 105 deviceInited[i] = true;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 106 break;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 107 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 108 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 109
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 110 if (i == MAX_DEVICE_CONNECTED) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 111 USB_ERR("Too many device connected!!\r\n");
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 112 continue;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 113 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 114
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 115 if (!controlEndpointAllocated) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 116 control = newEndpoint(CONTROL_ENDPOINT, OUT, 0x08, 0x00);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 117 addEndpoint(NULL, 0, (USBEndpoint*)control);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 118 controlEndpointAllocated = true;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 119 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 120
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 121 #if MAX_HUB_NB
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 122 if (usb_msg->hub_parent)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 123 devices[i].setHubParent((USBHostHub *)(usb_msg->hub_parent));
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 124 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 125
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 126 for (j = 0; j < timeout_set_addr; j++) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 127
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 128 resetDevice(&devices[i]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 129
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 130 // set size of control endpoint
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 131 devices[i].setSizeControlEndpoint(8);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 132
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 133 devices[i].activeAddress(false);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 134
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 135 // get first 8 bit of device descriptor
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 136 // and check if we deal with a hub
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 137 USB_DBG("usb_thread read device descriptor on dev: %p\r\n", &devices[i]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 138 res = getDeviceDescriptor(&devices[i], buf, 8);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 139
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 140 if (res != USB_TYPE_OK) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 141 USB_ERR("usb_thread could not read dev descr");
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 142 continue;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 143 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 144
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 145 // set size of control endpoint
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 146 devices[i].setSizeControlEndpoint(buf[7]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 147
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 148 // second step: set an address to the device
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 149 res = setAddress(&devices[i], devices[i].getAddress());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 150
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 151 if (res != USB_TYPE_OK) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 152 USB_ERR("SET ADDR FAILED");
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 153 continue;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 154 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 155 devices[i].activeAddress(true);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 156 USB_DBG("Address of %p: %d", &devices[i], devices[i].getAddress());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 157
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 158 // try to read again the device descriptor to check if the device
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 159 // answers to its new address
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 160 res = getDeviceDescriptor(&devices[i], buf, 8);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 161
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 162 if (res == USB_TYPE_OK) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 163 break;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 164 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 165
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 166 Thread::wait(100);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 167 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 168
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 169 USB_INFO("New device connected: %p [hub: %d - port: %d]", &devices[i], usb_msg->hub, usb_msg->port);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 170
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 171 #if MAX_HUB_NB
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 172 if (buf[4] == HUB_CLASS) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 173 for (k = 0; k < MAX_HUB_NB; k++) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 174 if (hub_in_use[k] == false) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 175 for (uint8_t j = 0; j < MAX_TRY_ENUMERATE_HUB; j++) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 176 if (hubs[k].connect(&devices[i])) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 177 devices[i].hub = &hubs[k];
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 178 hub_in_use[k] = true;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 179 break;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 180 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 181 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 182 if (hub_in_use[k] == true)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 183 break;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 184 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 185 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 186
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 187 if (k == MAX_HUB_NB) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 188 USB_ERR("Too many hubs connected!!\r\n");
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 189 too_many_hub = true;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 190 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 191 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 192
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 193 if (usb_msg->hub_parent)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 194 ((USBHostHub *)(usb_msg->hub_parent))->deviceConnected(&devices[i]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 195 #endif
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 196
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 197 if ((i < MAX_DEVICE_CONNECTED) && !too_many_hub) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 198 deviceInUse[i] = true;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 199 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 200
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 201 } while(0);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 202
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 203 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 204
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 205 // a device has been disconnected
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 206 case DEVICE_DISCONNECTED_EVENT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 207
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 208 do {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 209 Lock lock(this);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 210
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 211 controlListState = disableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 212 bulkListState = disableList(BULK_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 213 interruptListState = disableList(INTERRUPT_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 214
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 215 idx = findDevice(usb_msg->hub, usb_msg->port, (USBHostHub *)(usb_msg->hub_parent));
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 216 if (idx != -1) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 217 freeDevice((USBDeviceConnected*)&devices[idx]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 218 deviceInited[idx]=false;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 219 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 220
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 221 if (controlListState) enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 222 if (bulkListState) enableList(BULK_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 223 if (interruptListState) enableList(INTERRUPT_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 224
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 225 } while(0);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 226
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 227 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 228
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 229 // a td has been processed
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 230 // call callback on the ed associated to the td
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 231 // we are not in ISR -> users can use printf in their callback method
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 232 case TD_PROCESSED_EVENT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 233 ep = (USBEndpoint *) ((HCTD *)usb_msg->td_addr)->ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 234 if (usb_msg->td_state == USB_TYPE_IDLE) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 235 USB_DBG_EVENT("call callback on td %p [ep: %p state: %s - dev: %p - %s]", usb_msg->td_addr, ep, ep->getStateString(), ep->dev, ep->dev->getName(ep->getIntfNb()));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 236
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 237 #if DEBUG_TRANSFER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 238 if (ep->getDir() == IN) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 239 buf_transfer = ep->getBufStart();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 240 printf("READ SUCCESS [%d bytes transferred - td: 0x%08X] on ep: [%p - addr: %02X]: ", ep->getLengthTransferred(), usb_msg->td_addr, ep, ep->getAddress());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 241 for (int i = 0; i < ep->getLengthTransferred(); i++)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 242 printf("%02X ", buf_transfer[i]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 243 printf("\r\n\r\n");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 244 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 245 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 246 ep->call();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 247 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 248 idx = findDevice(ep->dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 249 if (idx != -1) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 250 if (deviceInUse[idx]) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 251 USB_WARN("td %p processed but not in idle state: %s [ep: %p - dev: %p - %s]", usb_msg->td_addr, ep->getStateString(), ep, ep->dev, ep->dev->getName(ep->getIntfNb()));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 252 ep->setState(USB_TYPE_IDLE);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 253 /* as error, on interrupt endpoint can be
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 254 * reported, call the call back registered ,
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 255 * if device still in use, this call back
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 256 * shall ask again an interrupt request.
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 257 */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 258 ep->call();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 259 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 260 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 261 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 262 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 263 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 264
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 265 mail_usb_event.free(usb_msg);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 266 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 267 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 268 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 269
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 270 USBHost::USBHost() : usbThread(osPriorityNormal, USB_THREAD_STACK)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 271 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 272 #ifndef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 273 headControlEndpoint = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 274 headBulkEndpoint = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 275 headInterruptEndpoint = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 276 tailControlEndpoint = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 277 tailBulkEndpoint = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 278 tailInterruptEndpoint = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 279 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 280 lenReportDescr = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 281
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 282 controlEndpointAllocated = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 283
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 284 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 285 deviceInUse[i] = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 286 devices[i].setAddress(i + 1);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 287 deviceReset[i] = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 288 deviceInited[i] = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 289 for (uint8_t j = 0; j < MAX_INTF; j++)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 290 deviceAttachedDriver[i][j] = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 291 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 292
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 293 #if MAX_HUB_NB
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 294 for (uint8_t i = 0; i < MAX_HUB_NB; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 295 hubs[i].setHost(this);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 296 hub_in_use[i] = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 297 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 298 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 299
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 300 usbThread.start(this, &USBHost::usb_process);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 301 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 302
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 303 USBHost::Lock::Lock(USBHost* pHost) : m_pHost(pHost)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 304 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 305 m_pHost->usb_mutex.lock();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 306 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 307
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 308 USBHost::Lock::~Lock()
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 309 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 310 m_pHost->usb_mutex.unlock();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 311 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 312
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 313 void USBHost::transferCompleted(volatile uint32_t addr)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 314 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 315 uint8_t state;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 316
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 317 if(addr == 0)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 318 return;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 319
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 320 volatile HCTD* tdList = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 321
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 322 //First we must reverse the list order and dequeue each TD
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 323 do {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 324 volatile HCTD* td = (volatile HCTD*)addr;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 325 addr = (uint32_t)td->nextTD; //Dequeue from physical list
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 326 td->nextTD = (hcTd*)tdList; //Enqueue into reversed list
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 327 tdList = td;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 328 } while(addr);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 329
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 330 while(tdList != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 331 volatile HCTD* td = tdList;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 332 tdList = (volatile HCTD*)td->nextTD; //Dequeue element now as it could be modified below
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 333 if (td->ep != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 334 USBEndpoint * ep = (USBEndpoint *)(td->ep);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 335
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 336 #ifdef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 337 state = ((HCTD *)td)->state;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 338 if (state == USB_TYPE_IDLE)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 339 ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 340
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 341 #else
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 342 if (((HCTD *)td)->control >> 28) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 343 state = ((HCTD *)td)->control >> 28;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 344 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 345 if (td->currBufPtr)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 346 ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 347 state = 16 /*USB_TYPE_IDLE*/;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 348 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 349 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 350 if (state == USB_TYPE_IDLE)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 351 ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 352
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 353 ep->unqueueTransfer(td);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 354
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 355 if (ep->getType() != CONTROL_ENDPOINT) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 356 // callback on the processed td will be called from the usb_thread (not in ISR)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 357 message_t * usb_msg = mail_usb_event.alloc();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 358 usb_msg->event_id = TD_PROCESSED_EVENT;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 359 usb_msg->td_addr = (void *)td;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 360 usb_msg->td_state = state;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 361 mail_usb_event.put(usb_msg);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 362 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 363 ep->setState((USB_TYPE)state);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 364 ep->ep_queue.put((uint8_t*)1);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 365 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 366 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 367 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 368
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 369 USBHost * USBHost::getHostInst()
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 370 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 371 if (instHost == NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 372 instHost = new USBHost();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 373 instHost->init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 374 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 375 return instHost;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 376 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 377
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 378
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 379 /*
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 380 * Called when a device has been connected
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 381 * Called in ISR!!!! (no printf)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 382 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 383 /* virtual */ void USBHost::deviceConnected(int hub, int port, bool lowSpeed, USBHostHub * hub_parent)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 384 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 385 // be sure that the new device connected is not already connected...
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 386 disableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 387
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 388 int idx = findDevice(hub, port, hub_parent);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 389 if (idx != -1) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 390 if (deviceInited[idx]) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 391 enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 392
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 393 return;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 394 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 395 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 396 message_t * usb_msg = mail_usb_event.alloc();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 397 usb_msg->event_id = DEVICE_CONNECTED_EVENT;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 398 usb_msg->hub = hub;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 399 usb_msg->port = port;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 400 usb_msg->lowSpeed = lowSpeed;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 401 usb_msg->hub_parent = hub_parent;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 402 mail_usb_event.put(usb_msg);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 403 enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 404
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 405
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 406 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 407
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 408 /*
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 409 * Called when a device has been disconnected
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 410 * Called in ISR!!!! (no printf)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 411 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 412 /* virtual */ void USBHost::deviceDisconnected(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 413 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 414 // be sure that the device disconnected is connected...
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 415
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 416 disableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 417
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 418 int idx = findDevice(hub, port, hub_parent);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 419 if (idx != -1) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 420 if (!deviceInUse[idx]) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 421 enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 422 return;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 423 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 424 } else {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 425 enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 426 return;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 427 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 428
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 429 message_t * usb_msg = mail_usb_event.alloc();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 430 usb_msg->event_id = DEVICE_DISCONNECTED_EVENT;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 431 usb_msg->hub = hub;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 432 usb_msg->port = port;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 433 usb_msg->hub_parent = hub_parent;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 434 mail_usb_event.put(usb_msg);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 435 enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 436
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 437
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 438 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 439
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 440 void USBHost::freeDevice(USBDeviceConnected * dev)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 441 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 442 USBEndpoint * ep = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 443 HCED * ed = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 444
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 445 #if MAX_HUB_NB
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 446 if (dev->getClass() == HUB_CLASS) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 447 if (dev->hub == NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 448 USB_ERR("HUB NULL!!!!!\r\n");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 449 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 450 dev->hub->hubDisconnected();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 451 for (uint8_t i = 0; i < MAX_HUB_NB; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 452 if (dev->hub == &hubs[i]) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 453 hub_in_use[i] = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 454 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 455 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 456 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 457 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 458 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 459
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 460 // notify hub parent that this device has been disconnected
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 461 if (dev->getHubParent())
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 462 dev->getHubParent()->deviceDisconnected(dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 463
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 464 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 465
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 466 int idx = findDevice(dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 467 if (idx != -1) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 468 deviceInUse[idx] = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 469 deviceReset[idx] = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 470
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 471 for (uint8_t j = 0; j < MAX_INTF; j++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 472 deviceAttachedDriver[idx][j] = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 473 if (dev->getInterface(j) != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 474 USB_DBG("FREE INTF %d on dev: %p, %p, nb_endpot: %d, %s", j, (void *)dev->getInterface(j), dev, dev->getInterface(j)->nb_endpoint, dev->getName(j));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 475 for (int i = 0; i < dev->getInterface(j)->nb_endpoint; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 476 if ((ep = dev->getEndpoint(j, i)) != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 477 #ifndef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 478 ed = (HCED *)ep->getHCED();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 479 ed->control |= (1 << 14); //sKip bit
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 480 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 481 unqueueEndpoint(ep);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 482
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 483 freeTD((volatile uint8_t*)ep->getTDList()[0]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 484 freeTD((volatile uint8_t*)ep->getTDList()[1]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 485
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 486 freeED((uint8_t *)ep->getHCED());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 487 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 488 printList(BULK_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 489 printList(INTERRUPT_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 490 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 491 USB_INFO("Device disconnected [%p - %s - hub: %d - port: %d]", dev, dev->getName(j), dev->getHub(), dev->getPort());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 492 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 493 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 494 dev->disconnect();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 495 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 496 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 497
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 498
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 499 void USBHost::unqueueEndpoint(USBEndpoint * ep)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 500 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 501 #ifdef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 502 ep->setState(USB_TYPE_FREE);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 503 #else
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 504 USBEndpoint * prec = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 505 USBEndpoint * current = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 506
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 507 for (int i = 0; i < 2; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 508 current = (i == 0) ? (USBEndpoint*)headBulkEndpoint : (USBEndpoint*)headInterruptEndpoint;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 509 prec = current;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 510 while (current != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 511 if (current == ep) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 512 if (current->nextEndpoint() != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 513 prec->queueEndpoint(current->nextEndpoint());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 514 if (current == headBulkEndpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 515 updateBulkHeadED((uint32_t)current->nextEndpoint()->getHCED());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 516 headBulkEndpoint = current->nextEndpoint();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 517 } else if (current == headInterruptEndpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 518 updateInterruptHeadED((uint32_t)current->nextEndpoint()->getHCED());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 519 headInterruptEndpoint = current->nextEndpoint();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 520 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 521 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 522 // here we are dequeuing the queue of ed
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 523 // we need to update the tail pointer
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 524 else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 525 prec->queueEndpoint(NULL);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 526 if (current == headBulkEndpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 527 updateBulkHeadED(0);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 528 headBulkEndpoint = current->nextEndpoint();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 529 } else if (current == headInterruptEndpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 530 updateInterruptHeadED(0);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 531 headInterruptEndpoint = current->nextEndpoint();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 532 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 533
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 534 // modify tail
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 535 switch (current->getType()) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 536 case BULK_ENDPOINT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 537 tailBulkEndpoint = prec;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 538 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 539 case INTERRUPT_ENDPOINT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 540 tailInterruptEndpoint = prec;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 541 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 542 default:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 543 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 544 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 545 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 546 current->setState(USB_TYPE_FREE);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 547 return;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 548 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 549 prec = current;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 550 current = current->nextEndpoint();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 551 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 552 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 553 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 554 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 555
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 556
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 557 USBDeviceConnected * USBHost::getDevice(uint8_t index)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 558 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 559 if ((index >= MAX_DEVICE_CONNECTED) || (!deviceInUse[index])) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 560 return NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 561 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 562 return (USBDeviceConnected*)&devices[index];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 563 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 564
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 565 // create an USBEndpoint descriptor. the USBEndpoint is not linked
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 566 USBEndpoint * USBHost::newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 567 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 568 int i = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 569 HCED * ed = (HCED *)getED();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 570 HCTD* td_list[2] = { (HCTD*)getTD(), (HCTD*)getTD() };
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 571
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 572 memset((void *)td_list[0], 0x00, sizeof(HCTD));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 573 memset((void *)td_list[1], 0x00, sizeof(HCTD));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 574
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 575 // search a free USBEndpoint
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 576 for (i = 0; i < MAX_ENDPOINT; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 577 if (endpoints[i].getState() == USB_TYPE_FREE) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 578 endpoints[i].init(ed, type, dir, size, addr, td_list);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 579 USB_DBG("USBEndpoint created (%p): type: %d, dir: %d, size: %d, addr: %d, state: %s", &endpoints[i], type, dir, size, addr, endpoints[i].getStateString());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 580 return &endpoints[i];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 581 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 582 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 583 USB_ERR("could not allocate more endpoints!!!!");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 584 return NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 585 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 586
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 587
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 588 USB_TYPE USBHost::resetDevice(USBDeviceConnected * dev)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 589 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 590 int index = findDevice(dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 591 if (index != -1) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 592 USB_DBG("Resetting hub %d, port %d\n", dev->getHub(), dev->getPort());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 593 Thread::wait(100);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 594 if (dev->getHub() == 0) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 595 resetRootHub();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 596 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 597 #if MAX_HUB_NB
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 598 else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 599 dev->getHubParent()->portReset(dev->getPort());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 600 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 601 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 602 Thread::wait(100);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 603 deviceReset[index] = true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 604 return USB_TYPE_OK;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 605 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 606
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 607 return USB_TYPE_ERROR;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 608 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 609
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 610 // link the USBEndpoint to the linked list and attach an USBEndpoint to a device
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 611 bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint * ep)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 612 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 613
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 614 if (ep == NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 615 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 616 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 617
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 618 #ifndef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 619 HCED * prevEd;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 620
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 621 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 622 // set device address in the USBEndpoint descriptor
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 623 if (dev == NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 624 ep->setDeviceAddress(0);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 625 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 626 ep->setDeviceAddress(dev->getAddress());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 627 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 628
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 629 if ((dev != NULL) && dev->getSpeed()) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 630 ep->setSpeed(dev->getSpeed());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 631 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 632
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 633 ep->setIntfNb(intf_nb);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 634
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 635 #ifndef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 636 // queue the new USBEndpoint on the ED list
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 637 switch (ep->getType()) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 638
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 639 case CONTROL_ENDPOINT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 640 prevEd = ( HCED*) controlHeadED();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 641 if (!prevEd) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 642 updateControlHeadED((uint32_t) ep->getHCED());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 643 USB_DBG_TRANSFER("First control USBEndpoint: %08X", (uint32_t) ep->getHCED());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 644 headControlEndpoint = ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 645 tailControlEndpoint = ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 646 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 647 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 648 tailControlEndpoint->queueEndpoint(ep);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 649 tailControlEndpoint = ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 650 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 651
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 652 case BULK_ENDPOINT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 653 prevEd = ( HCED*) bulkHeadED();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 654 if (!prevEd) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 655 updateBulkHeadED((uint32_t) ep->getHCED());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 656 USB_DBG_TRANSFER("First bulk USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 657 headBulkEndpoint = ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 658 tailBulkEndpoint = ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 659 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 660 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 661 USB_DBG_TRANSFER("Queue BULK Ed %p after %p\r\n",ep->getHCED(), prevEd);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 662 tailBulkEndpoint->queueEndpoint(ep);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 663 tailBulkEndpoint = ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 664 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 665
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 666 case INTERRUPT_ENDPOINT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 667 prevEd = ( HCED*) interruptHeadED();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 668 if (!prevEd) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 669 updateInterruptHeadED((uint32_t) ep->getHCED());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 670 USB_DBG_TRANSFER("First interrupt USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 671 headInterruptEndpoint = ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 672 tailInterruptEndpoint = ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 673 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 674 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 675 USB_DBG_TRANSFER("Queue INTERRUPT Ed %p after %p\r\n",ep->getHCED(), prevEd);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 676 tailInterruptEndpoint->queueEndpoint(ep);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 677 tailInterruptEndpoint = ep;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 678 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 679 default:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 680 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 681 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 682
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 683 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 684 ep->dev = dev;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 685 dev->addEndpoint(intf_nb, ep);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 686
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 687 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 688 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 689
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 690
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 691 int USBHost::findDevice(USBDeviceConnected * dev)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 692 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 693 for (int i = 0; i < MAX_DEVICE_CONNECTED; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 694 if (dev == &devices[i]) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 695 return i;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 696 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 697 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 698 return -1;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 699 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 700
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 701 int USBHost::findDevice(uint8_t hub, uint8_t port, USBHostHub * hub_parent)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 702 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 703 for (int i = 0; i < MAX_DEVICE_CONNECTED; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 704 if (devices[i].getHub() == hub && devices[i].getPort() == port) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 705 if (hub_parent != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 706 if (hub_parent == devices[i].getHubParent())
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 707 return i;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 708 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 709 return i;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 710 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 711 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 712 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 713 return -1;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 714 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 715
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 716 void USBHost::printList(ENDPOINT_TYPE type)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 717 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 718 #if defined(DEBUG_EP_STATE) && !defined(USBHOST_OTHER)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 719 volatile HCED * hced;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 720 switch(type) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 721 case CONTROL_ENDPOINT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 722 hced = (HCED *)controlHeadED();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 723 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 724 case BULK_ENDPOINT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 725 hced = (HCED *)bulkHeadED();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 726 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 727 case INTERRUPT_ENDPOINT:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 728 hced = (HCED *)interruptHeadED();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 729 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 730 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 731 volatile HCTD * hctd = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 732 const char * type_str = (type == BULK_ENDPOINT) ? "BULK" :
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 733 ((type == INTERRUPT_ENDPOINT) ? "INTERRUPT" :
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 734 ((type == CONTROL_ENDPOINT) ? "CONTROL" : "ISOCHRONOUS"));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 735 printf("State of %s:\r\n", type_str);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 736 while (hced != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 737 uint8_t dir = ((hced->control & (3 << 11)) >> 11);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 738 printf("hced: %p [ADDR: %d, DIR: %s, EP_NB: 0x%X]\r\n", hced,
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 739 hced->control & 0x7f,
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 740 (dir == 1) ? "OUT" : ((dir == 0) ? "FROM_TD":"IN"),
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 741 (hced->control & (0xf << 7)) >> 7);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 742 hctd = (HCTD *)((uint32_t)(hced->headTD) & ~(0xf));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 743 while (hctd != hced->tailTD) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 744 printf("\thctd: %p [DIR: %s]\r\n", hctd, ((hctd->control & (3 << 19)) >> 19) == 1 ? "OUT" : "IN");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 745 hctd = hctd->nextTD;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 746 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 747 printf("\thctd: %p\r\n", hctd);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 748 hced = hced->nextED;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 749 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 750 printf("\r\n\r\n");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 751 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 752 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 753
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 754
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 755 // add a transfer on the TD linked list
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 756 USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 757 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 758 USB_TYPE ret=USB_TYPE_PROCESSING;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 759 td_mutex.lock();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 760
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 761 // allocate a TD which will be freed in TDcompletion
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 762 volatile HCTD * td = ed->getNextTD();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 763 if (td == NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 764 return USB_TYPE_ERROR;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 765 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 766
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 767 #ifndef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 768 uint32_t token = (ed->isSetup() ? TD_SETUP : ( (ed->getDir() == IN) ? TD_IN : TD_OUT ));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 769
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 770 uint32_t td_toggle;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 771
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 772 if (ed->getType() == CONTROL_ENDPOINT) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 773 if (ed->isSetup()) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 774 td_toggle = TD_TOGGLE_0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 775 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 776 td_toggle = TD_TOGGLE_1;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 777 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 778 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 779 td_toggle = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 780 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 781
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 782 td->control = (TD_ROUNDING | token | TD_DELAY_INT(0) | td_toggle | TD_CC);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 783 td->currBufPtr = buf;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 784 td->bufEnd = (buf + (len - 1));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 785
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 786 ENDPOINT_TYPE type = ed->getType();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 787
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 788 disableList(type);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 789 ed->queueTransfer();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 790 printList(type);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 791 enableList(type);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 792 #else
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 793 /* call method specific for endpoint */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 794 td->currBufPtr = buf;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 795 td->size = len;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 796 ret = ed->queueTransfer();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 797 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 798
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 799 td_mutex.unlock();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 800
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 801 return ret;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 802 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 803
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 804
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 805
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 806 USB_TYPE USBHost::getDeviceDescriptor(USBDeviceConnected * dev, uint8_t * buf, uint16_t max_len_buf, uint16_t * len_dev_descr)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 807 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 808 USB_TYPE t = controlRead( dev,
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 809 USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE,
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 810 GET_DESCRIPTOR,
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 811 (DEVICE_DESCRIPTOR << 8) | (0),
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 812 0, buf, MIN(DEVICE_DESCRIPTOR_LENGTH, max_len_buf));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 813 if (len_dev_descr)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 814 *len_dev_descr = MIN(DEVICE_DESCRIPTOR_LENGTH, max_len_buf);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 815
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 816 return t;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 817 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 818
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 819 USB_TYPE USBHost::getConfigurationDescriptor(USBDeviceConnected * dev, uint8_t * buf, uint16_t max_len_buf, uint16_t * len_conf_descr)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 820 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 821 USB_TYPE res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 822 uint16_t total_conf_descr_length = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 823
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 824 // fourth step: get the beginning of the configuration descriptor to have the total length of the conf descr
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 825 res = controlRead( dev,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 826 USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 827 GET_DESCRIPTOR,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 828 (CONFIGURATION_DESCRIPTOR << 8) | (0),
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 829 0, buf, CONFIGURATION_DESCRIPTOR_LENGTH);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 830
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 831 if (res != USB_TYPE_OK) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 832 USB_ERR("GET CONF 1 DESCR FAILED");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 833 return res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 834 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 835 total_conf_descr_length = buf[2] | (buf[3] << 8);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 836 total_conf_descr_length = MIN(max_len_buf, total_conf_descr_length);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 837
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 838 if (len_conf_descr)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 839 *len_conf_descr = total_conf_descr_length;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 840
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 841 USB_DBG("TOTAL_LENGTH: %d \t NUM_INTERF: %d", total_conf_descr_length, buf[4]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 842
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 843 return controlRead( dev,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 844 USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 845 GET_DESCRIPTOR,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 846 (CONFIGURATION_DESCRIPTOR << 8) | (0),
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 847 0, buf, total_conf_descr_length);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 848 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 849
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 850
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 851 USB_TYPE USBHost::setAddress(USBDeviceConnected * dev, uint8_t address)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 852 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 853 return controlWrite( dev,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 854 USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 855 SET_ADDRESS,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 856 address,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 857 0, NULL, 0);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 858
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 859 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 860
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 861 USB_TYPE USBHost::setConfiguration(USBDeviceConnected * dev, uint8_t conf)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 862 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 863 return controlWrite( dev,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 864 USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 865 SET_CONFIGURATION,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 866 conf,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 867 0, NULL, 0);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 868 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 869
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 870 uint8_t USBHost::numberDriverAttached(USBDeviceConnected * dev)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 871 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 872 int index = findDevice(dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 873 uint8_t cnt = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 874 if (index == -1)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 875 return 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 876 for (uint8_t i = 0; i < MAX_INTF; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 877 if (deviceAttachedDriver[index][i])
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 878 cnt++;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 879 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 880 return cnt;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 881 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 882
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 883 // enumerate a device with the control USBEndpoint
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 884 USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 885 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 886 uint16_t total_conf_descr_length = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 887 USB_TYPE res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 888
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 889 do {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 890 Lock lock(this);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 891
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 892 // don't enumerate a device which all interfaces are registered to a specific driver
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 893 int index = findDevice(dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 894
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 895 if (index == -1) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 896 return USB_TYPE_ERROR;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 897 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 898
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 899 uint8_t nb_intf_attached = numberDriverAttached(dev);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 900 USB_DBG("dev: %p nb_intf: %d", dev, dev->getNbIntf());
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 901 USB_DBG("dev: %p nb_intf_attached: %d", dev, nb_intf_attached);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 902 if ((nb_intf_attached != 0) && (dev->getNbIntf() == nb_intf_attached)) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 903 USB_DBG("Don't enumerate dev: %p because all intf are registered with a driver", dev);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 904 return USB_TYPE_OK;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 905 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 906
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 907 USB_DBG("Enumerate dev: %p", dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 908
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 909 // third step: get the whole device descriptor to see vid, pid
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 910 res = getDeviceDescriptor(dev, data, DEVICE_DESCRIPTOR_LENGTH);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 911
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 912 if (res != USB_TYPE_OK) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 913 USB_DBG("GET DEV DESCR FAILED");
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 914 return res;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 915 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 916
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 917 dev->setClass(data[4]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 918 dev->setSubClass(data[5]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 919 dev->setProtocol(data[6]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 920 dev->setVid(data[8] | (data[9] << 8));
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 921 dev->setPid(data[10] | (data[11] << 8));
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 922 USB_DBG("CLASS: %02X \t VID: %04X \t PID: %04X", data[4], data[8] | (data[9] << 8), data[10] | (data[11] << 8));
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 923
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 924 pEnumerator->setVidPid( data[8] | (data[9] << 8), data[10] | (data[11] << 8) );
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 925
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 926 res = getConfigurationDescriptor(dev, data, sizeof(data), &total_conf_descr_length);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 927 if (res != USB_TYPE_OK) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 928 return res;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 929 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 930
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 931 #if (DEBUG > 3)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 932 USB_DBG("CONFIGURATION DESCRIPTOR:\r\n");
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 933 for (int i = 0; i < total_conf_descr_length; i++)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 934 printf("%02X ", data[i]);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 935 printf("\r\n\r\n");
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 936 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 937
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 938 // Parse the configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 939 parseConfDescr(dev, data, total_conf_descr_length, pEnumerator);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 940
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 941 // only set configuration if not enumerated before
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 942 if (!dev->isEnumerated()) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 943
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 944 USB_DBG("Set configuration 1 on dev: %p", dev);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 945 // sixth step: set configuration (only 1 supported)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 946 res = setConfiguration(dev, 1);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 947
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 948 if (res != USB_TYPE_OK) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 949 USB_DBG("SET CONF FAILED");
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 950 return res;
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 951 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 952 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 953
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 954 dev->setEnumerated();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 955
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 956 // Now the device is enumerated!
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 957 USB_DBG("dev %p is enumerated\r\n", dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 958
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 959 } while(0);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 960
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 961 // Some devices may require this delay
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 962 Thread::wait(100);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 963
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 964 return USB_TYPE_OK;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 965 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 966 // this method fills the USBDeviceConnected object: class,.... . It also add endpoints found in the descriptor.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 967 void USBHost::parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uint32_t len, IUSBEnumerator* pEnumerator)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 968 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 969 uint32_t index = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 970 uint32_t len_desc = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 971 uint8_t id = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 972 int nb_endpoints_used = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 973 USBEndpoint * ep = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 974 uint8_t intf_nb = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 975 bool parsing_intf = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 976 uint8_t current_intf = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 977
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 978 while (index < len) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 979 len_desc = conf_descr[index];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 980 id = conf_descr[index+1];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 981 switch (id) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 982 case CONFIGURATION_DESCRIPTOR:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 983 USB_DBG("dev: %p has %d intf", dev, conf_descr[4]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 984 dev->setNbIntf(conf_descr[4]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 985 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 986 case INTERFACE_DESCRIPTOR:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 987 if(pEnumerator->parseInterface(conf_descr[index + 2], conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7])) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 988 if (intf_nb++ <= MAX_INTF) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 989 current_intf = conf_descr[index + 2];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 990 dev->addInterface(current_intf, conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 991 nb_endpoints_used = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 992 USB_DBG("ADD INTF %d on device %p: class: %d, subclass: %d, proto: %d", current_intf, dev, conf_descr[index + 5],conf_descr[index + 6],conf_descr[index + 7]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 993 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 994 USB_DBG("Drop intf...");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 995 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 996 parsing_intf = true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 997 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 998 parsing_intf = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 999 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1000 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1001 case ENDPOINT_DESCRIPTOR:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1002 if (parsing_intf && (intf_nb <= MAX_INTF) ) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1003 if (nb_endpoints_used < MAX_ENDPOINT_PER_INTERFACE) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1004 if( pEnumerator->useEndpoint(current_intf, (ENDPOINT_TYPE)(conf_descr[index + 3] & 0x03), (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1)) ) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1005 // if the USBEndpoint is isochronous -> skip it (TODO: fix this)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1006 if ((conf_descr[index + 3] & 0x03) != ISOCHRONOUS_ENDPOINT) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1007 ep = newEndpoint((ENDPOINT_TYPE)(conf_descr[index+3] & 0x03),
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1008 (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1),
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1009 conf_descr[index + 4] | (conf_descr[index + 5] << 8),
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1010 conf_descr[index + 2] & 0x0f);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1011 USB_DBG("ADD USBEndpoint %p, on interf %d on device %p", ep, current_intf, dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1012 if (ep != NULL && dev != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1013 addEndpoint(dev, current_intf, ep);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1014 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1015 USB_DBG("EP NULL");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1016 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1017 nb_endpoints_used++;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1018 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1019 USB_DBG("ISO USBEndpoint NOT SUPPORTED");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1020 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1021 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1022 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1023 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1024 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1025 case HID_DESCRIPTOR:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1026 lenReportDescr = conf_descr[index + 7] | (conf_descr[index + 8] << 8);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1027 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1028 default:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1029 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1030 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1031 index += len_desc;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1032 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1033 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1034
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1035
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1036 USB_TYPE USBHost::bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1037 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1038 return generalTransfer(dev, ep, buf, len, blocking, BULK_ENDPOINT, true);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1039 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1040
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1041 USB_TYPE USBHost::bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1042 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1043 return generalTransfer(dev, ep, buf, len, blocking, BULK_ENDPOINT, false);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1044 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1045
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1046 USB_TYPE USBHost::interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1047 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1048 return generalTransfer(dev, ep, buf, len, blocking, INTERRUPT_ENDPOINT, true);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1049 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1050
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1051 USB_TYPE USBHost::interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1052 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1053 return generalTransfer(dev, ep, buf, len, blocking, INTERRUPT_ENDPOINT, false);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1054 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1055
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1056 USB_TYPE USBHost::generalTransfer(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking, ENDPOINT_TYPE type, bool write)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1057 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1058
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1059 #if DEBUG_TRANSFER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1060 const char * type_str = (type == BULK_ENDPOINT) ? "BULK" : ((type == INTERRUPT_ENDPOINT) ? "INTERRUPT" : "ISOCHRONOUS");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1061 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());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1062 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1063
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1064 Lock lock(this);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1065
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1066 USB_TYPE res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1067 ENDPOINT_DIRECTION dir = (write) ? OUT : IN;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1068
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1069 if (dev == NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1070 USB_ERR("dev NULL");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1071 return USB_TYPE_ERROR;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1072 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1073
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1074 if (ep == NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1075 USB_ERR("ep NULL");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1076 return USB_TYPE_ERROR;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1077 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1078
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1079 if (ep->getState() != USB_TYPE_IDLE) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1080 USB_WARN("[ep: %p - dev: %p - %s] NOT IDLE: %s", ep, ep->dev, ep->dev->getName(ep->getIntfNb()), ep->getStateString());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1081 return ep->getState();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1082 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1083
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1084 if ((ep->getDir() != dir) || (ep->getType() != type)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1085 USB_ERR("[ep: %p - dev: %p] wrong dir or bad USBEndpoint type", ep, ep->dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1086 return USB_TYPE_ERROR;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1087 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1088
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1089 if (dev->getAddress() != ep->getDeviceAddress()) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1090 USB_ERR("[ep: %p - dev: %p] USBEndpoint addr and device addr don't match", ep, ep->dev);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1091 return USB_TYPE_ERROR;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1092 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1093
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1094 #if DEBUG_TRANSFER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1095 if (write) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1096 USB_DBG_TRANSFER("%s WRITE buffer", type_str);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1097 for (int i = 0; i < ep->getLengthTransferred(); i++)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1098 printf("%02X ", buf[i]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1099 printf("\r\n\r\n");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1100 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1101 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1102 res = addTransfer(ep, buf, len);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1103
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1104 if ((blocking)&& (res == USB_TYPE_PROCESSING)) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1105 #ifdef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1106 osEvent event = ep->ep_queue.get(TD_TIMEOUT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1107 if (event.status == osEventTimeout)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1108 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1109 /* control endpoint is confusing for merge on b */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1110 disableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1111 ep->setState(USB_TYPE_ERROR);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1112 ep->ep_queue.get(0);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1113 ep->unqueueTransfer(ep->getProcessedTD());
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1114 enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1115 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1116 #else
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1117 ep->ep_queue.get();
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1118 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1119 res = ep->getState();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1120
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1121 USB_DBG_TRANSFER("%s TRANSFER res: %s on ep: %p\r\n", type_str, ep->getStateString(), ep);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1122
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1123 if (res != USB_TYPE_IDLE) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1124 return res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1125 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1126
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1127 return USB_TYPE_OK;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1128 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1129
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1130 return res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1131
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1132 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1133
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1134
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1135 USB_TYPE USBHost::controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1136 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1137 return controlTransfer(dev, requestType, request, value, index, buf, len, false);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1138 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1139
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1140 USB_TYPE USBHost::controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1141 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1142 return controlTransfer(dev, requestType, request, value, index, buf, len, true);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1143 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1144
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1145 USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len, bool write)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1146 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1147 Lock lock(this);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1148 USB_DBG_TRANSFER("----- CONTROL %s [dev: %p - hub: %d - port: %d] ------", (write) ? "WRITE" : "READ", dev, dev->getHub(), dev->getPort());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1149
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1150 int length_transfer = len;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1151 USB_TYPE res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1152 uint32_t token;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1153
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1154 control->setSpeed(dev->getSpeed());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1155 control->setSize(dev->getSizeControlEndpoint());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1156 if (dev->isActiveAddress()) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1157 control->setDeviceAddress(dev->getAddress());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1158 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1159 control->setDeviceAddress(0);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1160 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1161
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1162 USB_DBG_TRANSFER("Control transfer on device: %d\r\n", control->getDeviceAddress());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1163 fillControlBuf(requestType, request, value, index, len);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1164
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1165 #if DEBUG_TRANSFER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1166 USB_DBG_TRANSFER("SETUP PACKET: ");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1167 for (int i = 0; i < 8; i++)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1168 printf("%01X ", setupPacket[i]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1169 printf("\r\n");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1170 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1171
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1172 control->setNextToken(TD_SETUP);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1173 res = addTransfer(control, (uint8_t*)setupPacket, 8);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1174
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1175 if (res == USB_TYPE_PROCESSING)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1176 #ifdef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1177 { osEvent event = control->ep_queue.get(TD_TIMEOUT_CTRL);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1178 if (event.status == osEventTimeout) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1179 disableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1180 control->setState(USB_TYPE_ERROR);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1181 control->ep_queue.get(0);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1182 control->unqueueTransfer(control->getProcessedTD());
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1183 enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1184 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1185 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1186 #else
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1187 control->ep_queue.get();
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1188 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1189 res = control->getState();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1190
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1191 USB_DBG_TRANSFER("CONTROL setup stage %s", control->getStateString());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1192
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1193 if (res != USB_TYPE_IDLE) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1194 return res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1195 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1196
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1197 if (length_transfer) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1198 token = (write) ? TD_OUT : TD_IN;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1199 control->setNextToken(token);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1200 res = addTransfer(control, (uint8_t *)buf, length_transfer);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1201
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1202 if (res == USB_TYPE_PROCESSING)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1203 #ifdef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1204 { osEvent event = control->ep_queue.get(TD_TIMEOUT_CTRL);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1205 if (event.status == osEventTimeout)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1206 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1207 disableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1208 control->setState(USB_TYPE_ERROR);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1209 control->ep_queue.get(0);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1210 control->unqueueTransfer(control->getProcessedTD());
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1211 enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1212 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1213 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1214 #else
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1215 control->ep_queue.get();
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1216 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1217 res = control->getState();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1218
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1219 #if DEBUG_TRANSFER
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1220 USB_DBG_TRANSFER("CONTROL %s stage %s", (write) ? "WRITE" : "READ", control->getStateString());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1221 if (write) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1222 USB_DBG_TRANSFER("CONTROL WRITE buffer");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1223 for (int i = 0; i < control->getLengthTransferred(); i++)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1224 printf("%02X ", buf[i]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1225 printf("\r\n\r\n");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1226 } else {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1227 USB_DBG_TRANSFER("CONTROL READ SUCCESS [%d bytes transferred]", control->getLengthTransferred());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1228 for (int i = 0; i < control->getLengthTransferred(); i++)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1229 printf("%02X ", buf[i]);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1230 printf("\r\n\r\n");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1231 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1232 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1233
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1234 if (res != USB_TYPE_IDLE) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1235 return res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1236 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1237 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1238
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1239 token = (write) ? TD_IN : TD_OUT;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1240 control->setNextToken(token);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1241 res = addTransfer(control, NULL, 0);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1242 if (res == USB_TYPE_PROCESSING)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1243 #ifdef USBHOST_OTHER
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1244 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1245 osEvent event = control->ep_queue.get(TD_TIMEOUT_CTRL);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1246 if (event.status == osEventTimeout)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1247 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1248 disableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1249 control->setState(USB_TYPE_ERROR);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1250 control->ep_queue.get(0);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1251 control->unqueueTransfer(control->getProcessedTD());
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1252 enableList(CONTROL_ENDPOINT);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1253 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1254 }
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1255 #else
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1256 control->ep_queue.get();
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 1257 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1258 res = control->getState();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1259
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1260 USB_DBG_TRANSFER("CONTROL ack stage %s", control->getStateString());
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1261
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1262 if (res != USB_TYPE_IDLE)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1263 return res;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1264
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1265 return USB_TYPE_OK;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1266 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1267
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1268
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1269 void USBHost::fillControlBuf(uint8_t requestType, uint8_t request, uint16_t value, uint16_t index, int len)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1270 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1271 setupPacket[0] = requestType;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1272 setupPacket[1] = request;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1273 setupPacket[2] = (uint8_t) value;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1274 setupPacket[3] = (uint8_t) (value >> 8);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1275 setupPacket[4] = (uint8_t) index;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1276 setupPacket[5] = (uint8_t) (index >> 8);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1277 setupPacket[6] = (uint8_t) len;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1278 setupPacket[7] = (uint8_t) (len >> 8);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1279 }